aboutsummaryrefslogtreecommitdiff
path: root/src/image
AgeCommit message (Collapse)Author
2026-03-31image/jpeg: reject RGB and non-standard chroma subsamplingNigel Tao
This fixes a possible panic introduced a few months ago by "image/jpeg: add support for non-standard chroma subsampling ratios" (CL 738280). Fixes #78368 Change-Id: I1f181582b7dc1e2955e3ec26c3aa24bc0f4159df Reviewed-on: https://go-review.googlesource.com/c/go/+/760701 Auto-Submit: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Nigel Tao <nigeltao@google.com>
2026-03-05image/jpeg: make decoder.receiveExtend branchlessNigel Tao
On linux/amd64: name old speed new speed delta DecodeBaseline-8 76.4MB/s ± 0% 84.3MB/s ± 0% +10.38% (p=0.008 n=5+5) DecodeProgressive-8 51.0MB/s ± 1% 52.6MB/s ± 0% +3.20% (p=0.008 n=5+5) Thanks to David Le Corfec for the suggestion. Updates #24499 Change-Id: I749102ff0b50044dfd6a73172a1aa03f89ad97bd Reviewed-on: https://go-review.googlesource.com/c/go/+/750900 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Nigel Tao <nigeltao@google.com>
2026-03-04image/jpeg: add support for non-standard chroma subsampling ratiosTaichi Maeda
Add "flex mode" decoding for JPEG images with non-standard YCbCr subsampling ratios that do not match the predefined YCbCrSubsampleRatio values. This includes cases where: 1. Cb and Cr components have different sampling factors 2. The Y component does not have the maximum sampling factors Such images were previously rejected with "unsupported luma/chroma subsampling ratio" but should be valid according to the JPEG specification: https://www.w3.org/Graphics/JPEG/itu-t81.pdf Flex mode allocates a YCbCr444 backing buffer and manually expands pixels according to each component's sampling factors relative to the maximum. This approach mirrors the implementation in kovidgoyal/imaging. Fixes #2362 goos: darwin goarch: arm64 pkg: image/jpeg cpu: Apple M4 Max │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ FDCT-16 576.9n ± 1% 578.9n ± 1% ~ (p=0.565 n=10) IDCT-16 550.1n ± 0% 573.6n ± 3% +4.27% (p=0.000 n=10) DecodeBaseline-16 520.6µ ± 4% 523.8µ ± 2% ~ (p=0.796 n=10) DecodeProgressive-16 767.9µ ± 3% 747.0µ ± 10% ~ (p=0.123 n=10) EncodeRGBA-16 7.869m ± 3% 8.485m ± 6% +7.82% (p=0.001 n=10) EncodeYCbCr-16 8.761m ± 6% 8.021m ± 2% -8.45% (p=0.001 n=10) geomean 143.5µ 143.8µ +0.18% │ old.txt │ new.txt │ │ B/s │ B/s vs base │ DecodeBaseline-16 113.2Mi ± 4% 112.5Mi ± 2% ~ (p=0.796 n=10) DecodeProgressive-16 76.75Mi ± 3% 78.90Mi ± 10% ~ (p=0.123 n=10) EncodeRGBA-16 148.9Mi ± 3% 138.1Mi ± 7% -7.25% (p=0.001 n=10) EncodeYCbCr-16 100.3Mi ± 7% 109.6Mi ± 2% +9.23% (p=0.001 n=10) geomean 106.7Mi 107.7Mi +0.86% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ DecodeBaseline-16 61.55Ki ± 0% 61.55Ki ± 0% ~ (p=1.000 n=10) ¹ DecodeProgressive-16 253.6Ki ± 0% 253.6Ki ± 0% ~ (p=0.124 n=10) EncodeRGBA-16 4.438Ki ± 0% 4.438Ki ± 0% ~ (p=1.000 n=10) ¹ EncodeYCbCr-16 4.438Ki ± 0% 4.438Ki ± 0% ~ (p=1.000 n=10) ¹ geomean 23.55Ki 23.55Ki +0.00% ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ DecodeBaseline-16 5.000 ± 0% 5.000 ± 0% ~ (p=1.000 n=10) ¹ DecodeProgressive-16 13.00 ± 0% 13.00 ± 0% ~ (p=1.000 n=10) ¹ EncodeRGBA-16 7.000 ± 0% 7.000 ± 0% ~ (p=1.000 n=10) ¹ EncodeYCbCr-16 7.000 ± 0% 7.000 ± 0% ~ (p=1.000 n=10) ¹ geomean 7.512 7.512 +0.00% ¹ all samples are equal Co-authored-by: Kovid Goyal <kovidgoyal@gmail.com> Change-Id: Ic7353ce6a0b229cb6aa775bb05044d6bcded7ab2 Reviewed-on: https://go-review.googlesource.com/c/go/+/738280 Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao <nigeltao@google.com>
2025-11-23cmd/internal/obj/arm64, image/gif, runtime, sort: use math/bits to calculate ↵Axel Wagner
log2 In several places the integer log2 is calculated using loops or similar mechanisms. math/bits.Len* provide a simpler and more efficient mechanisms for this. Annoyingly, every usage has slightly different ideas of what "log2" means and how non-positive inputs should be handled. I verified the replacements in each case by comparing the result for inputs from 0 to 1<<16. Change-Id: Ie962a74674802da363e0038d34c06979ccb41cf3 Reviewed-on: https://go-review.googlesource.com/c/go/+/721880 Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-09-25image/jpeg: replace fdct.go and idct.go with new implementation in dct.goRuss Cox
The fdct.go and idct.go files were derived from the MPEG-SSG and JPEG-IJG reference code and therefore carry licenses specific to those groups. Various license checkers flag these files as potentially problematic. The code is also not terribly well documented. This CL fixes the license problem by adding a new, from-scratch implementation using a different algorithm. As a bonus, the new code is both faster and more accurate than the old encumbered code. On speed, the new code is up to 20% faster; benchmarks below. On accuracy, in the set of blocks used in the test, we can measure the number of output values that are off-by-one from the exact rounded answer. The old FDCT was off in 8.6% of values; the new one is off in 2.5%. The old IDCT was off in 1.4% of values; the new one is off in 1.2%. goos: darwin goarch: arm64 pkg: image/jpeg cpu: Apple M3 Pro │ old │ new │ │ sec/op │ sec/op vs base │ FDCT-12 619.6n ± 3% 586.5n ± 1% -5.34% (p=0.000 n=10) IDCT-12 752.4n ± 4% 628.0n ± 1% -16.54% (p=0.000 n=10) goos: linux goarch: amd64 cpu: Intel(R) Xeon(R) CPU @ 2.30GHz │ old │ new │ │ sec/op │ sec/op vs base │ FDCT-16 1.817µ ± 0% 1.542µ ± 0% -15.11% (p=0.000 n=10) IDCT-16 1.897µ ± 0% 1.514µ ± 0% -20.22% (p=0.000 n=10) goos: linux goarch: arm64 cpu: whatever gotip-linux-arm64 has │ old │ new │ │ sec/op │ sec/op vs base │ FDCT-8 1.844µ ± 0% 1.847µ ± 0% +0.14% (p=0.000 n=10) IDCT-8 2.127µ ± 0% 1.973µ ± 0% -7.26% (p=0.000 n=10) Change-Id: Ie6d14103c8478ba5a779f234da84f345828eb925 Reviewed-on: https://go-review.googlesource.com/c/go/+/705518 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Nigel Tao <nigeltao@google.com>
2025-09-25image/jpeg: correct and test reference slowFDCT and slowIDCTRuss Cox
The reference implementations slowFDCT and slowIDCT were not rounding correctly, making the test not as good as it could be. Before, the real implementations were required to always produce values within ±2 of the reference; now, with no changes, the real implementations produce values within ±1 of the (corrected) reference. Also tighten the test to return an error not just on a single value exceeding tolerance but also on too many values at exactly that tolerance. Change-Id: I3dd6ca7582178fef972fb812d848f7a0158a6ed8 Reviewed-on: https://go-review.googlesource.com/c/go/+/705517 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-09-25image/jpeg: prepare for new FDCT/IDCT implementationsRuss Cox
Preparation for a new unencumbered implementation of fdct.go and idct.go. - Change benchmark not to allocate O(b.N) storage. - Make tests point out where differences are. - Parameterize differ tolerance. Change-Id: Id5dfee40f86de894bad72dd6178ba61ec81ea2da Reviewed-on: https://go-review.googlesource.com/c/go/+/705516 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-07-29image: fix formatting of godoc linkOlivier Mengué
Change-Id: I8fa8741e0db174f0c32af0a393ee1b037d5b7e51 Reviewed-on: https://go-review.googlesource.com/c/go/+/680455 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Mark Freeman <mark@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
2024-11-20internal/byteorder: use canonical Go casing in namesRuss Cox
If Be and Le stand for big-endian and little-endian, then they should be BE and LE. Change-Id: I723e3962b8918da84791783d3c547638f1c9e8a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/627376 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-12image/color/palette: add godoc link to generator programIan Lance Taylor
CL 535196 accidentally changed a generated file without changing the generator program. This updates the generator program to generate the current file. Change-Id: I06513c9b29c7ca4084ac3768229ef8793efe0218 Reviewed-on: https://go-review.googlesource.com/c/go/+/625901 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2024-11-06image/jpeg: initialize dct_test constants at compile timeNigel Tao
Doing so is slightly more accurate than calculating at run time (because of float64 rounding errors): https://go.dev/play/p/hrOzHDLjd5K Having these more accurate values isn't necessary for tests to pass, but it's helpful if doing printf-debugging or stepping through the code. Change-Id: I07a65678936e4db05b11f9d8d952b32b2acd51a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/624716 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Nigel Tao <nigeltao@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-03image/jpeg: add more theHuffmanSpec commentsNigel Tao
Change-Id: I2c68dde6e968e0643109161e52a76189e48b4d19 Reviewed-on: https://go-review.googlesource.com/c/go/+/624715 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao <nigeltao@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2024-09-01image: use Rectangle{} instead of ZRtomocy
ZR is deprecated, so replace it with the literal Rectangle to represent the zero value. Change-Id: I68c0ffec808eaed1e8c352bf364d295c0041594e GitHub-Last-Rev: 850472888d3d0f5e68feb9ec09f0b544fe1f9446 GitHub-Pull-Request: golang/go#69136 Reviewed-on: https://go-review.googlesource.com/c/go/+/609516 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao <nigeltao@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-06-03all: make function comments match function namescuishuang
Change-Id: Ideb9ef00e7bc660b005fc080973fd9f3d36c5a1f Reviewed-on: https://go-review.googlesource.com/c/go/+/589536 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-13image/gif: use internal/byteorderapocelipes
Change-Id: Ic00e63aa35bcea4c97a5885d61edb8fc37d84e22 GitHub-Last-Rev: 1ad3a5d0edebbd0f0b98ce68ad81ea4c36f5a63d GitHub-Pull-Request: golang/go#67324 Reviewed-on: https://go-review.googlesource.com/c/go/+/584997 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-05-06image/png: remove go-fuzz testJorropo
An identical go1.18 test exists at `src/image/png/fuzz_test.go`. Change-Id: I3e4db46296fb6a56655f849da8c0689aa5a1c28c Reviewed-on: https://go-review.googlesource.com/c/go/+/576795 Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2024-04-25image/jpeg: ignore garbage bytes before a RST markerNigel Tao
Well-formed JPEG images will not have garbage bytes. However, for corrupted JPEG images, the RST (restart) mechanism is specifically designed so that a decoder can re-synchronize to an upcoming restartable MCU (Minimum Coded Unit, e.g. 16x16 block of pixels) boundary and resume decoding. Even if the resultant image isn't perfect, a 98%-good image is better than a fatal error. Every JPEG marker is encoded in two bytes, the first of which is 0xFF. There are 8 possible RST markers, cycling as "0xFF 0xD0", "0xFF 0xD1", ..., "0xFF 0xD7". Suppose that, our decoder is expecting "0xFF 0xD1". Before this commit, Go's image/jpeg package would accept only two possible inputs: a well-formed "0xFF 0xD1" or one very specific pattern of spec non-compliance, "0xFF 0x00 0xFF 0xD1". After this commit, it is more lenient, similar to libjpeg's jdmarker.c's next_marker function. https://github.com/libjpeg-turbo/libjpeg-turbo/blob/2dfe6c0fe9e18671105e94f7cbf044d4a1d157e6/jdmarker.c#L892-L935 The new testdata file was created by: $ convert video-001.png a.ppm $ cjpeg -restart 2 a.ppm > video-001.restart2.jpeg $ rm a.ppm Fixes #40130 Change-Id: Ic598a5f489f110d6bd63e0735200fb6acac3aca3 Reviewed-on: https://go-review.googlesource.com/c/go/+/580755 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Joedian Reid <joedian@google.com>
2024-04-11image/gif: revert incorrect usage of clearRoland Shoemaker
CL 570555 replaced a loop which added empty color.RGBA elements with a call to clear. color.Palette is a slice of interfaces, so using clear results in a slice of nil elements, rather than what we previously had which was empty color.RGBA elements. This could cause a panic when attempting to re-encode a GIF which had an extended color palette because of the weird transparency hack. This was discovered by OSS-Fuzz. I've added a test case using their reproducer in order to prevent future regressions. Change-Id: I00a89257d90b6cca68672173eecdaa0a24f18d9c Reviewed-on: https://go-review.googlesource.com/c/go/+/577555 Reviewed-by: Nigel Tao <nigeltao@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2024-03-11image: use built-in clear to simplify codeapocelipes
Change-Id: Id34936a115baaf61e4268582c6d9a2027494c385 GitHub-Last-Rev: 5fe455b7d24e3e3b871c8999c5bb534f3e1e3ab5 GitHub-Pull-Request: golang/go#66244 Reviewed-on: https://go-review.googlesource.com/c/go/+/570555 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2023-10-19image: add available godoc linkcui fliter
Change-Id: I2839ecb091c4f0b30d0dcee708bf9e9a55e3672a Reviewed-on: https://go-review.googlesource.com/c/go/+/535196 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com>
2023-09-25all: use the indefinite article an in commentsJes Cok
Change-Id: I8787458f9ccd3b5cdcdda820d8a45deb4f77eade GitHub-Last-Rev: be865d67ef68815b8c1c2a9ad222fff594620e66 GitHub-Pull-Request: golang/go#63165 Reviewed-on: https://go-review.googlesource.com/c/go/+/530120 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-08-29image: add a security considerations section to package docRoland Shoemaker
Internally the security model for the image package has always been, if you don't call DecodeConfig before Decode, you cannot complain if Decode attempts to create an arbitrarily large image (with the assumption that DecodeConfig would've told you this information). This should be explicitly documented. Change-Id: I5c37b91131d6352637e725fe415f37a28f12f66d Reviewed-on: https://go-review.googlesource.com/c/go/+/523578 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-07encoding/xml, image/jpeg, image/png: use the builtin min functionapocelipes
Change-Id: I9bafc7aa4e20e7cd994b75e7576156ca68f4fc8b GitHub-Last-Rev: e037f689bddd0ef03a6ad38982fe98b4c26aaede GitHub-Pull-Request: golang/go#61746 Reviewed-on: https://go-review.googlesource.com/c/go/+/515855 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-03image/jpeg, image/png: replace Fatal with Error in testsHiro
Replaced t.Fatalf with t.Errorf for non-critical errors to footprint more failing test cases for better analysis of the error. Change-Id: I6f51d21e37a4ddb95d239d8afed2154f3ef52d31 GitHub-Last-Rev: d56aa49bced80c80f1177ae4b9ce038265ead551 GitHub-Pull-Request: golang/go#60524 Reviewed-on: https://go-review.googlesource.com/c/go/+/499336 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
2023-07-20image/draw: replace deprecated image.ZP and image.ZR in xx_test.goryomak
Change-Id: I87545a46e5871452075152b4c99ba85089ef86b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/506735 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-24image/jpeg: return io.ErrUnexpectedEOF on truncated dataAlexander Yastrebov
Decoder calls fill from readFull, ignore and readByte and readByte did not check returned io.EOF. This change moves io.EOF translation inside fill. name old speed new speed delta DecodeBaseline-8 67.4MB/s ± 0% 67.3MB/s ± 0% -0.20% (p=0.000 n=16+19) DecodeProgressive-8 43.7MB/s ± 0% 43.6MB/s ± 0% -0.06% (p=0.013 n=17+19) Fixes #56724 Change-Id: Ia0d5cc561f3c2050e25ec3f2b5e6866c3b4941c7 GitHub-Last-Rev: 470154373bc1452dffc5293d9a840e972749a76d GitHub-Pull-Request: golang/go#56863 Reviewed-on: https://go-review.googlesource.com/c/go/+/452335 Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-03all: fix a few function names on commentscui fliter
Change-Id: Ida7e756f01a2c115ac58bf10aa13b2f8fd57b6a1 GitHub-Last-Rev: 4694d397bd3ad488fd05ed2cc6ad97909f09e707 GitHub-Pull-Request: golang/go#56537 Reviewed-on: https://go-review.googlesource.com/c/go/+/447436 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-14image/png: optimise RGBA encodingAlexander Efremov
Optimised RGBA image encoding to PNG. Improved test coverage. Reworked benchmark. Performance improvement with both old and new versions of the benchmark: name old speed new speed delta EncodeRGBA_OriginalVersion-10 115MB/s ± 1% 308MB/s ± 1% +166.70% (p=0.000 n=19+17) EncodeRGBA_NewVersion-10 40.3MB/s ± 1% 51.1MB/s ± 2% +26.93% (p=0.000 n=18+20) name old allocs/op new allocs/op delta EncodeRGBA_OriginalVersion-10 614k ± 0% 0k ± 0% -99.99% (p=0.000 n=20+20) EncodeRGBA_NewVersion-10 614k ± 0% 0k ± 0% -99.99% (p=0.000 n=20+20) Change-Id: I450013909c2410b043cd9c1239facd5bd6e3f3f9 GitHub-Last-Rev: 329d6ac011b08efcba5c1d737ba5395b0a66a6ea GitHub-Pull-Request: golang/go#55119 Reviewed-on: https://go-review.googlesource.com/c/go/+/431575 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Nigel Tao <nigeltao@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
2022-09-27image/gif,image/jpeg,image/png: skip FuzzDecode in testing short modeJoel Sing
The image/gif.FuzzDecode takes an excessive amount of time to run on various builders - skip these in testing short mode. Likewise for image/jpeg and image/png. Fixes #55839 Change-Id: I1049d06b9dcbbc7dbc4f53d3c49b64e2254eabbd Reviewed-on: https://go-review.googlesource.com/c/go/+/435175 Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-06image/jpeg: use strings.Buildercuiweixie
Change-Id: I0a51aa9e7800689c123ce3eaf74742a4641b7681 Reviewed-on: https://go-review.googlesource.com/c/go/+/428261 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-29image/png: allow both PLTE and tRNS chunks for TrueColorNigel Tao
Prior to this commit, png.Decode would allow TrueColor PNG images that have one but not both of PLTE and tRNS chunks. Fixes #54142 Change-Id: I259c1fff86a0aa5640dbadf7ad834e05fbd1430c Reviewed-on: https://go-review.googlesource.com/c/go/+/424916 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
2022-08-24image/png: have DecodeConfig read tRNS chunksNigel Tao
Fixes #54325 Change-Id: Ie468180c4d6f21db7672dd71bd2a40f3a5881b7d Reviewed-on: https://go-review.googlesource.com/c/go/+/424917 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-08-22image/gif: avoid decoding past the first frame in decode()Chris Gillis
The existing decode() method offers the ability to keep just one frame of the GIF image, however it will read and decompress all subsequent frames regardless. Fixes #41142 Change-Id: I0c3c11f9c11cd487b6c365e9a8b98e617d555db0 GitHub-Last-Rev: 03ebc8ee7bb19ee80c62d0c935b783d7bc75c2e9 GitHub-Pull-Request: golang/go#46813 Reviewed-on: https://go-review.googlesource.com/c/go/+/329329 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Paul Tyng <paul@paultyng.net> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
2022-07-12image/jpeg: increase TestLargeImageWithShortData timeout by an order of ↵Bryan C. Mills
magnitude Also dump goroutines on failure. The original bug report in #10413 reported a hang of “several minutes”. An apparently-spurious failure was observed in https://build.golang.org/log/e5ac3ce3fb7d04ec13e5bbfadea8bb5869a4dd1e, with a delay of only 3.64s. Moreover, if the test does fail due to a regression, we will want a goroutine dump to diagnose where it got stuck. The current call to t.Fatalf does not produce such a dump, so is not nearly as useful if the failure only occasionally reproduces. Updates #10413. Change-Id: I6ab9d112f14f438a0c54e02ec95934627acdc64b Reviewed-on: https://go-review.googlesource.com/c/go/+/408355 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17all: fix spellingJohn Bampton
Change-Id: Iee18987c495d1d4bde9da888d454eea8079d3ebc GitHub-Last-Rev: ff5e01599ddf7deb3ab6ce190ba92eb02ae2cb15 GitHub-Pull-Request: golang/go#52949 Reviewed-on: https://go-review.googlesource.com/c/go/+/406915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-07image/draw: have draw.Src preserve NRGBA colorsNigel Tao
This reverts a behavior change introduced in Go 1.18 (commit 9f69a443; CL 340049). In Go 1.17 and earlier, draw.Draw(etc, draw.Src) with image.NRGBA dst and src images would pass through a (heap allocated) color.Color interface value holding a color.NRGBA concrete value. Threading that color.NRGBA value all the way through preserves non-premultiplied alpha transparency information (distinguishing e.g. transparent blue from transparent red). CL 340049 optimized out that heap allocation (per pixel), calling new SetRGBA64At and RGBA64At methods instead. However, these methods (like the existing image/color Color.RGBA method) work in premultiplied alpha, so any distinction between transparent colors is lost. This commit re-introduces the preservation of distinct transparencies, when dst and src are both *image.NRGBA (or both *image.NRGBA64) and the op is draw.Src. Fixes #51893 Change-Id: Id9c64bfeeaecc458586f169f50b99d6c8aa52a7f Reviewed-on: https://go-review.googlesource.com/c/go/+/396795 Trust: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2022-01-13all: add a handful of fuzz targetsRoland Shoemaker
Adds simple fuzz targets to archive/tar, archive/zip, compress/gzip, encoding/json, image/jpeg, image/gif, and image/png. Second attempt, this time we don't use the archives in testdata when fuzzing archive/tar, since those are rather memory intensive, and were crashing a number of builders. Change-Id: I4828d64fa4763c0d8c980392a6578e4dfd956e13 Reviewed-on: https://go-review.googlesource.com/c/go/+/378174 Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-12Revert "all: add a handful of fuzz targets"Bryan Mills
This reverts CL 352109. Reason for revert: causing OOM failures on several builders, and may cause OOMs for end users with small machines as well. Change-Id: I58308d09919969d5a6512ee5cee6aa5c4af6769b Reviewed-on: https://go-review.googlesource.com/c/go/+/377934 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Katie Hockman <katie@golang.org>
2022-01-12all: add a handful of fuzz targetsRoland Shoemaker
Adds simple fuzz targets to archive/tar, archive/zip, compress/gzip, encoding/json, image/jpeg, image/gif, and image/png. Change-Id: Ide1a8de88a9421e786eeeaea3bb93f41e0bae347 Reviewed-on: https://go-review.googlesource.com/c/go/+/352109 Trust: Katie Hockman <katie@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-31image/draw: rename and reorder some benchmarksNigel Tao
The intention is for BenchmarkFooBar functions to map 1:1 to drawFooBar functions. Recent draw.go changes have added more drawFooBar functions and have further modified the mapping, as fallback drawFooBar functions aren't invoked as often as they used to. This commit restores the 1:1 mapping and reorganizes the BenchmarkFooBar functions in the same order as the matching drawFooBar functions appear. Also modify a TestDraw test case from vgradGreen(255) = {0, 136, 0, 255} to vgradGreen(90) = {0, 48, 0, 90}. Doing so matches the existing "The source pixel is {0, 48, 0, 90}" comment but also makes for a more interesting test case, as the source pixel is no longer fully opaque. Fully opaque is already covered by the vgradGray() test case on the next line. Also fix a "variable source" comment copy-pasto when the source image is actually uniform, not variable. Also add a func DrawMask type switch comment about interface types. Change-Id: I828e71f2ee8ec617f523c8aafb118fb7ba166876 Reviewed-on: https://go-review.googlesource.com/c/go/+/358974 Trust: Nigel Tao <nigeltao@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-28all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox
When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-10-25image/draw: improve performances if mask is *image.AlphaOlivier Wulveryck
The existing DrawMask method is generic and is therefore calling the At().RGBA() method for every pixel of the mask and the source. Do a specific implementation when the mask is *image.Alpha (which is common) and use use the PixOffset method to increase performances. name old time/op new time/op delta RGBA2-12 1.60ms ± 0% 1.13ms ± 1% -29.16% (p=0.008 n=5+5) GenericMaskOver-12 915µs ± 4% 926µs ± 1% ~ (p=0.190 n=5+4) RGBA64Over-12 1.53ms ± 3% 1.21ms ± 2% -20.74% (p=0.008 n=5+5) GrayOver-12 1.36ms ± 2% 1.01ms ± 7% -26.27% (p=0.008 n=5+5) Fixes: #46395 Change-Id: Iaeaa8cfcc6a3fe93eb19b361f3bf076e41cac5b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/323749 Reviewed-by: Nigel Tao <nigeltao@golang.org> Trust: Nigel Tao <nigeltao@golang.org> Trust: Andrew Gerrand <adg@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org>
2021-10-08image/png: fix interlaced palette out-of-boundsNigel Tao
PNG images can be paletted, where each pixel value (a uint8) indexes a slice of colors. In terms of wire format, the PLTE chunk explicitly contains the palette length. However, in practice, some arguably malformed images contain pixel values greater than or equal to the explicit PLTE length. Go's image/png decoder accomodates such images by lengthening the decoded image's palette if the implicit maximum is larger than the explicit maximum. This was already done, prior to this commit, by the "if len(paletted.Palette) <= int(idx)" lines in decoder.readImagePass. Separately, PNG images can also be interlaced, where the final image is the result of merging multiple partial images, also called passes. Prior to this commit, we applied the palette lengthening to the pass images but not the final image. This commit fixes that. Fixes #48612 Change-Id: I77606538cc9a504fbd726071756ebcd10c9da73f Reviewed-on: https://go-review.googlesource.com/c/go/+/354709 Trust: Nigel Tao <nigeltao@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2021-09-27image/draw: add RGBA64Image fast path for RGBA dstNigel Tao
This should have been part of https://golang.org/cl/340049 but I overlooked it. That commit added fast path code when the destination image was *not* an *image.RGBA. This commit edits func drawRGBA. name old time/op new time/op delta RGBA1-4 5.11ms ± 1% 1.12ms ± 1% -78.01% (p=0.008 n=5+5) RGBA2-4 8.69ms ± 1% 2.98ms ± 1% -65.77% (p=0.008 n=5+5) Updates #44808. Updates #46395. Change-Id: I899d46d985634fc81ea47ff4f0d436630e8a961c Reviewed-on: https://go-review.googlesource.com/c/go/+/351852 Trust: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-09-03image/draw: add RGBA64Image fast pathNigel Tao
name old time/op new time/op delta GenericOver-4 15.0ms ± 1% 2.9ms ± 1% -80.56% (p=0.008 n=5+5) GenericMaskOver-4 7.82ms ± 4% 1.69ms ± 2% -78.38% (p=0.008 n=5+5) GenericSrc-4 6.13ms ± 3% 1.66ms ± 1% -72.90% (p=0.008 n=5+5) GenericMaskSrc-4 11.5ms ± 1% 2.0ms ± 0% -82.77% (p=0.008 n=5+5) Updates #44808. Change-Id: I131cf6fad01708540390a8012d8f2a21e849fe9d Reviewed-on: https://go-review.googlesource.com/c/go/+/340049 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Trust: Nigel Tao <nigeltao@golang.org>
2021-06-30image/gif: fix typo in the comment (io.ReadByte -> io.ByteReader)uji
Fixes #46967 Change-Id: I66e69c70b74e904623e8ca854562d255692b2143 Reviewed-on: https://go-review.googlesource.com/c/go/+/331649 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Carlos Amedee <carlos@golang.org>
2021-06-30image: add Uniform.RGBA64At and Rectangle.RGBA64AtNigel Tao
These types already implemented the Image interface. They should also implement the RGBA64Image interface (new in Go 1.17) Updates #44808 Change-Id: I9a2b13e305997088ae874efb95ad9e1648f94812 Reviewed-on: https://go-review.googlesource.com/c/go/+/331570 Trust: Nigel Tao <nigeltao@golang.org> Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-06-18image: add RGBA64Image interfaceNigel Tao
The new RGBA64At method is equivalent to the existing At method (and the new SetRGBA64 method is equivalent to the existing Set method in the image/draw package), but they can avoid allocations from converting concrete color types to the color.Color interface type. Also update api/go1.17.txt and doc/go1.17.html Fixes #44808 Change-Id: I8671f3144512b1200fa373840ed6729a5d61bc35 Reviewed-on: https://go-review.googlesource.com/c/go/+/311129 Trust: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Rob Pike <r@golang.org>