Skip to content

Commit fbba930

Browse files
rscgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Nigel Tao <[email protected]>
1 parent 92e0934 commit fbba930

File tree

5 files changed

+538
-403
lines changed

5 files changed

+538
-403
lines changed

src/image/decode_example_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ func Example() {
7070
}
7171
// Output:
7272
// bin red green blue alpha
73-
// 0x0000-0x0fff: 364 790 7242 0
74-
// 0x1000-0x1fff: 645 2967 1039 0
75-
// 0x2000-0x2fff: 1072 2299 979 0
76-
// 0x3000-0x3fff: 820 2266 980 0
77-
// 0x4000-0x4fff: 537 1305 541 0
78-
// 0x5000-0x5fff: 319 962 261 0
79-
// 0x6000-0x6fff: 322 375 177 0
80-
// 0x7000-0x7fff: 601 279 214 0
81-
// 0x8000-0x8fff: 3478 227 273 0
82-
// 0x9000-0x9fff: 2260 234 329 0
83-
// 0xa000-0xafff: 921 282 373 0
84-
// 0xb000-0xbfff: 321 335 397 0
85-
// 0xc000-0xcfff: 229 388 298 0
86-
// 0xd000-0xdfff: 260 414 277 0
87-
// 0xe000-0xefff: 516 428 298 0
88-
// 0xf000-0xffff: 2785 1899 1772 15450
73+
// 0x0000-0x0fff: 362 793 7245 0
74+
// 0x1000-0x1fff: 648 2963 1036 0
75+
// 0x2000-0x2fff: 1072 2301 977 0
76+
// 0x3000-0x3fff: 819 2266 982 0
77+
// 0x4000-0x4fff: 537 1303 541 0
78+
// 0x5000-0x5fff: 321 964 261 0
79+
// 0x6000-0x6fff: 321 375 177 0
80+
// 0x7000-0x7fff: 599 278 213 0
81+
// 0x8000-0x8fff: 3478 228 275 0
82+
// 0x9000-0x9fff: 2260 233 328 0
83+
// 0xa000-0xafff: 921 282 374 0
84+
// 0xb000-0xbfff: 322 335 395 0
85+
// 0xc000-0xcfff: 228 388 299 0
86+
// 0xd000-0xdfff: 261 415 277 0
87+
// 0xe000-0xefff: 516 423 297 0
88+
// 0xf000-0xffff: 2785 1903 1773 15450
8989
}
9090

9191
const data = `

0 commit comments

Comments
 (0)