Repository navigation
fix(images): cap Q8 output depth at 8 bits - #1681
Open
mohamedelghazali wants to merge 5 commits into
Open
mohamedelghazali wants to merge 5 commits into
mohamedelghazali wants to merge 5 commits into
Conversation
Ensure image depth is set to 8 bits for images with higher depth to prevent issues with file writing.
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
Fixes #1547.
Problem
Filee bundles
Magick.NET-Q8(IMagickImage<byte>), which holds 8 bits per channel in memory. When reading a 16-bit source (e.g., 16-bit PNG/TIFF or Camera RAW), ImageMagick keepsimage.Depth == 16. BecauseImageEncodernever loweredDepth, coders that honor image depth (TIFF, PSD, PSB, PPM, PAM, MIFF, JXL, JP2, and 12-bit AVIF) wrote 16-bit (or 12-bit) output files filled with duplicated 8-bit samples, unnecessarily inflating file sizes.Root Cause
ImageEncoder.ApplyOptions,ImageEncoder.Write, andImageEncoder.WriteImagepassedimage.Depthunchanged to ImageMagick writers.Changes
src/Filee.Engines/Magick/ImageEncoder.cs: Clampimage.Depthto8wheneverimage.Depth > 8inApplyOptions,Write(both single-frame and multi-frame paths), andWriteImage.< 8-bit sources (such as 1-bit monochrome images).FITS → TIFF, which bypassesImageEncoderviaFitsRendering.WriteTiffinMagickImageConverter.ConvertAsync.tests/Filee.Engines.Tests/ImageFormatTests.cs: Add regression tests covering 16-bit source conversion acrosstiff,psd,psb,ppm,pam,miff,jxl,jp2, andavif, plus a unit test verifyingApplyOptionscaps 16-bit depth to 8 while preserving 1-bit depth.Verification
dotnet format --verify-no-changes, Windows x64/ARM64 build & tests, Linux build & tests).