aboutsummaryrefslogtreecommitdiff
path: root/src/image/decode_example_test.go
AgeCommit message (Collapse)Author
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>
2018-05-29image: add an example that shows how to get the metadata of an imageAarti Parikh
This is a simple but everyday use case in image libraries. Currently, there is one example in this library and it is lengthy and involved. This PR will be imported into Gerrit with the title and first comment (this text) used to generate the subject and body of the Gerrit change. Change-Id: Idca527d97c095af88755446e1548fa2b8ace7eb0 GitHub-Last-Rev: f5743c8ef337a8b7a5126db21d784593f4f53c8a GitHub-Pull-Request: golang/go#25616 Reviewed-on: https://go-review.googlesource.com/114939 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-15image/color: tweak the YCbCr to RGBA conversion formula.Nigel Tao
Before, calling the RGBA method of YCbCr color would return red values in the range [0x0080, 0xff80]. After, the range is [0x0000, 0xffff] and is consistent with what Gray colors' RGBA method returns. In particular, pure black, pure white and every Gray color in between are now exactly representable as a YCbCr color. This fixes a regression from Go 1.4 (where YCbCr{0x00, 0x80, 0x80} was no longer equivalent to pure black), introduced by golang.org/cl/8073 in the Go 1.5 development cycle. In Go 1.4, the +0x80 rounding was not noticable when Cb == 0x80 && Cr == 0x80, because the YCbCr to RGBA conversion truncated to 8 bits before multiplying by 0x101, so the output range was [0x0000, 0xffff]. The TestYCbCrRoundtrip fuzzy-match tolerance grows from 1 to 2 because the YCbCr to RGB conversion now maps to an ever-so-slightly larger range, along with the usual imprecision of accumulating rounding errors. Also s/int/int32/ in ycbcr.go. The conversion shouldn't overflow either way, as int is always at least 32 bits, but it does make it clearer that the computation doesn't depend on sizeof(int). Fixes #11691 Change-Id: I538ca0adf7e040fa96c5bc8b3aef4454535126b9 Reviewed-on: https://go-review.googlesource.com/12220 Reviewed-by: Rob Pike <r@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.