Skip to content

Upsample subsampled JPEG chroma with libjpeg's 3:1 filter - #28

Merged
MPCoreDeveloper merged 1 commit into
mainfrom
feat/jpeg-fancy-upsampling
Nov 15, 2026
Merged

MPCoreDeveloper merged 1 commit into
mainfrom
feat/jpeg-fancy-upsampling

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Summary

JpegDecoder.Sample now upsamples a subsampled component with the 3:1 triangular filter libjpeg calls fancy, instead of nearest-neighbour:

  • even output position → three parts of its sample + one of the neighbour before it;
  • odd output position → three parts + one of the neighbour after it;
  • the same integer rounding as libjpeg (+1 / +2 before >> 2), with clamped edges;
  • handles 4:2:2 (horizontal only) and 4:2:0 (both), and leaves 4:4:4 direct.

Effect

jpeg-420.jpg now matches Pillow within two levels instead of the six nearest-neighbour needed, and the test's tolerance tightens from 6 to 2. All other fixtures are unchanged.

Evidence

  • dotnet build -c Release → 0 warnings, 0 errors; dotnet test → 1250 passed, 0 failed on net10.0 and net11.0.
  • ADR-005 and the changelog record the change; SOF2 (progressive) is the next slice.

Next

SOF2: spectral selection, successive approximation and the EOB run, against a progressive Pillow fixture.

JpegDecoder.Sample replaces nearest-neighbour sampling with the triangular filter libjpeg calls fancy: an
even output position is three parts of its sample and one of the neighbour before it, an odd one three
parts and one of the neighbour after it, with the same rounding. A 4:2:0 fixture now matches Pillow
within two levels rather than the six the nearest filter needed, and the test tolerance tightens to two.
@MPCoreDeveloper
MPCoreDeveloper merged commit f192351 into main Nov 15, 2026
8 checks passed
@MPCoreDeveloper
MPCoreDeveloper deleted the feat/jpeg-fancy-upsampling branch November 15, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant