diff options
| author | Russ Cox <rsc@golang.org> | 2025-09-18 12:27:06 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-25 07:54:32 -0700 |
| commit | fbba93027174956a57c8b4493cbf0d0521b65774 (patch) | |
| tree | 7ce0764f6a30e1c0e9853f357e37581ec3bec7ff /src/image/decode_example_test.go | |
| parent | 92e093467f3ca3e348b2c933c24d1803efe4c006 (diff) | |
| download | go-fbba93027174956a57c8b4493cbf0d0521b65774.tar.xz | |
image/jpeg: replace fdct.go and idct.go with new implementation in dct.go
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>
Diffstat (limited to 'src/image/decode_example_test.go')
| -rw-r--r-- | src/image/decode_example_test.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/image/decode_example_test.go b/src/image/decode_example_test.go index 526c03f3c1..252ac868c0 100644 --- a/src/image/decode_example_test.go +++ b/src/image/decode_example_test.go @@ -70,22 +70,22 @@ func Example() { } // Output: // bin red green blue alpha - // 0x0000-0x0fff: 364 790 7242 0 - // 0x1000-0x1fff: 645 2967 1039 0 - // 0x2000-0x2fff: 1072 2299 979 0 - // 0x3000-0x3fff: 820 2266 980 0 - // 0x4000-0x4fff: 537 1305 541 0 - // 0x5000-0x5fff: 319 962 261 0 - // 0x6000-0x6fff: 322 375 177 0 - // 0x7000-0x7fff: 601 279 214 0 - // 0x8000-0x8fff: 3478 227 273 0 - // 0x9000-0x9fff: 2260 234 329 0 - // 0xa000-0xafff: 921 282 373 0 - // 0xb000-0xbfff: 321 335 397 0 - // 0xc000-0xcfff: 229 388 298 0 - // 0xd000-0xdfff: 260 414 277 0 - // 0xe000-0xefff: 516 428 298 0 - // 0xf000-0xffff: 2785 1899 1772 15450 + // 0x0000-0x0fff: 362 793 7245 0 + // 0x1000-0x1fff: 648 2963 1036 0 + // 0x2000-0x2fff: 1072 2301 977 0 + // 0x3000-0x3fff: 819 2266 982 0 + // 0x4000-0x4fff: 537 1303 541 0 + // 0x5000-0x5fff: 321 964 261 0 + // 0x6000-0x6fff: 321 375 177 0 + // 0x7000-0x7fff: 599 278 213 0 + // 0x8000-0x8fff: 3478 228 275 0 + // 0x9000-0x9fff: 2260 233 328 0 + // 0xa000-0xafff: 921 282 374 0 + // 0xb000-0xbfff: 322 335 395 0 + // 0xc000-0xcfff: 228 388 299 0 + // 0xd000-0xdfff: 261 415 277 0 + // 0xe000-0xefff: 516 423 297 0 + // 0xf000-0xffff: 2785 1903 1773 15450 } const data = ` |
