Repository navigation
Imaging: WicFrameInfo.HasResolution and palettes for Encode - #83
Merged
Merged
Conversation
HasResolution tells a resolution stored in the file apart from the default of the decoder, with the rules per container in ResolutionProbe. WicEncodeOptions.Palette and Dither, indexed pixel formats, and GIF with the exact colors when the pixels have at most 256. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017qu4NGxUZizEKzrG8d2DGY
The WIC format converter picked a neighbor of exact palette colors, the pixels are now mapped by WicIndexingPixelSource. The JPEG decoder ignores the EXIF resolution, DpiX/DpiY take it when the file stores only that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017qu4NGxUZizEKzrG8d2DGY
|
|
Coverage Report for CI Build 41463335738Coverage increased (+0.7%) to 54.961%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WicFrameInfo.HasResolution: true when the file itself stores a resolution, false whenDpiX/DpiYare only the default of the decoder. The rules per container are inInternal/ResolutionProbe.cs:/pHYs/UnitSpecifierthrough the query reader, otherwise a scan of the chunk headers up to IDAT; unit 1 (meter) → true, unit 0 or no pHYs → false/app0/{ushort=1}1 or 2, or EXIF/app1/ifd/{ushort=282}with{ushort=296}not 1 (missing = inch)/ifd/{ushort=282}with 296 not 1It's filled by
GetFrameInfoand everyDecodeoverload from the frame that is open anyway. The stream position is restored after the few byte reads.Found on CI: the WIC JPEG decoder ignores the EXIF resolution. It reported 96 for a JPEG with only EXIF XResolution 72. When the resolution comes only from EXIF (JPEG without JFIF density, and the "others" rule),
DpiX/DpiYnow carry the EXIF values (unit cm converted), soHasResolution == truealways comes with the file's own DPI.Palette for
EncodeWicEncodeOptions.Palette(≤ 256 colors as 0xAARRGGBB, alpha 0 = transparent),WicEncodeOptions.Dither(error diffusion), andWicPixelFormats.Format1bppIndexedtoFormat8bppIndexed.CopyPalette). Other pixels with a palette ask the encoder for 8bpp indexed and get the nearest color.InitializeFromBitmapas before.WicIndexingPixelSource(exact match, otherwise nearest RGB, alpha < 128 → transparent entry). The WIC converter is only used for dithering.Docs (resolution table, palette), changelog
[3.19.0]and version 3.19.Tests
WicResolutionTests: the files are made in the test (WIC encode, then the PNG/JPEG/BMP resolution fields are patched in the bytes, PNG with CRC). It covers PNG pHYs 72 / none / unit 0, JPEG JFIF inch / units 0 / EXIF-only 72 / EXIF unit none, TIFF, BMP 3780 and 0, GIF, JPEG XR, WebP (a 1x1 VP8L, skipped without the WebP codec), the Decode overloads, a stream at an offset, the GIF round trip with 256 colors, indexed 8bpp with a palette to GIF/PNG/BMP, nearest color, and > 256 colors with and without dither.CI: net10 634 passed / 4 skipped, net48 636 passed / 4 skipped. The skips are HEIF, JPEG XL, WebP and a UI Automation test.
Generated by Claude Code