aboutsummaryrefslogtreecommitdiff
path: root/src/image
AgeCommit message (Collapse)Author
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>
2021-02-24image: resolve the TODO of doc comment styleAndy Pan
Change-Id: Ic7701a9e4635fe1a331c9a1df776ed580759eb9d Reviewed-on: https://go-review.googlesource.com/c/go/+/268758 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Rob Pike <r@golang.org> Trust: Nigel Tao <nigeltao@golang.org> Trust: Alberto Donizetti <alb.donizetti@gmail.com> Trust: Rob Pike <r@golang.org>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-03image/gif: have BenchmarkEncodeRealisticRGBA convert to RGBANigel Tao
Change-Id: I98f5d987b92a29dcff06ae23b92f293cc7d6c02f Reviewed-on: https://go-review.googlesource.com/c/go/+/252597 Reviewed-by: David Symonds <dsymonds@golang.org>
2020-08-17image/gif: add more writer benchmarksNigel Tao
The two existing benchmarks encode randomized pixels, which isn't very representative. The two new benchmarks encode a PNG photo as a GIF. Also rename the benchmarks for consistency. Also fix the bytes-per-op measure for paletted images, which are 1 (not 4) bytes per pixel. Also simplify BenchmarkEncodeRandomPaletted (formerly just called BenchmarkEncode). It doesn't need to generate a random palette (and the GIF encoder largely doesn't care about the palette's RGBA values). Use palette.Plan9 instead, a pre-existing 256-element color palette. Change-Id: I10a6ea4e9590bb0d9f76e8cc0f4a88d43b1d650d Reviewed-on: https://go-review.googlesource.com/c/go/+/248218 Reviewed-by: David Symonds <dsymonds@golang.org>
2020-06-14image/gif: speed up initializing test imageNigel Tao
The benchmark throughput numbers don't change, but the set-up time (the time taken before the b.ResetTimer() call) drops from 460ms to 4ms. Change-Id: I5a6756643dff6127f6d902455d83459c084834fc Reviewed-on: https://go-review.googlesource.com/c/go/+/237757 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-08image/png: remove too early declaration of "n"Ayan George
Before this commit, the code declares and assigns "n" with the result of io.ReadFull() -- but the value is not used. The variable is then reused later in the function. This commit removes the first declaration of "n" and declares it closer to where it is used. Change-Id: I7ffe19a10f2a563c306bb6fe6562493435b9dc5a Reviewed-on: https://go-review.googlesource.com/c/go/+/232917 Reviewed-by: Rob Pike <r@golang.org>