[go] image/jpeg: add support for non-standard chroma subsampling ratios

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Mar 4, 2026, 11:28:39 AM (yesterday) Mar 4
to Taichi Maeda, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Dmitri Shuralyov, Nigel Tao, Dmitri Shuralyov, Nigel Tao, Rob Pike, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
image/jpeg: add support for non-standard chroma subsampling ratios

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 <kovid...@gmail.com>
Change-Id: Ic7353ce6a0b229cb6aa775bb05044d6bcded7ab2
Auto-Submit: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Nigel Tao <nige...@golang.org>
Reviewed-by: Nigel Tao <nige...@google.com>
Files:
  • M src/image/jpeg/reader.go
  • M src/image/jpeg/reader_test.go
  • M src/image/jpeg/scan.go
  • A src/image/testdata/video-001.q50.121121.jpeg
  • A src/image/testdata/video-001.q50.211211.jpeg
  • A src/image/testdata/video-001.q50.221122.jpeg
  • A src/image/testdata/video-001.q50.222112.jpeg
Change size: M
Delta: 7 files changed, 138 insertions(+), 66 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Dmitri Shuralyov, +2 by Nigel Tao, +1 by Nigel Tao
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ic7353ce6a0b229cb6aa775bb05044d6bcded7ab2
Gerrit-Change-Number: 738280
Gerrit-PatchSet: 4
Gerrit-Owner: Taichi Maeda <taichi....@gmail.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Nigel Tao <nige...@golang.org>
Gerrit-Reviewer: Nigel Tao <nige...@google.com>
Gerrit-CC: Rob Pike <r...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages