Repository navigation
BMP layouts, Huffman 1D and normalized segment integrity handling - #3284
Merged
Merged
Conversation
BMP - The encoder writes 16-bit 5-6-5 pixels with BI_BITFIELDS. BmpBit16Layout selects the layout. BmpEncoder.Bit16Layout overrides BmpMetadata.Bit16Layout, and the decoder records the layout. A V3 header gets the 12-byte mask block. - BmpEncoder.Quantizer defaults to null. Without a quantizer, an indexed output reuses the decoded color table when it fits the depth. - The transparent color mode of the encoder applies to every quantizer. Icons - ICO, CUR and ANI metadata record the decoded 16-bit layout. The icon encoders still write 5-5-5, because the format permits only BI_RGB. - ANI raw bitmap frames record their color table, and the encoder reuses the palette of each frame, as the icon encoder does. Pixel formats - Bgr565 is a common pixel type: IPixel.FromBgr565, generated bulk conversions, and integer UNORM conversions through ColorNumerics.ScaleUnorm. - PixelConverter packs and unpacks Bgr565 and Bgra5551 with one SIMD kernel, through the IPacked16Layout and IChannelOrder operators. Quantizers - Decoded palettes are reused with exact color matching. The PNG, BMP, icon and ANI encoders use EncodingUtilities.CreateDecodedPaletteQuantizer. - The first GIF frame uses the options of the decoded global palette. - The 1-, 2- and 4-bit BMP paths keep the options of the quantizer. Tests - The GIF ICC test allows one 8-bit code per channel against the independent decoder, because a value near a rounding boundary can round either way. - The Issue2866 reference frames are updated. The new output has less error against the source on each compared frame.
BmpEncoder now takes a BmpColorType and a BitsPerPixel, and resolves them as the PNG encoder does: encoder options take precedence over metadata, and a depth that does not fit the color type uses the default depth of that color type. The color type selects the info header and the masks. This replaces BitsPerPixel with Bit16Layout and SupportTransparency. The color type names give the channels in storage order: Bgr, Bgra, Bgr565 and Bgra5551. BMP and TGA metadata now report BGR, and 16-bit TGA reports four components.
A V5 header with PROFILE_LINKED holds the file name of the profile at the profile offset, not ICC data. The decoder now reads the profile only when CsType is PROFILE_EMBEDDED. The profile-size test now declares an embedded profile, so its profile fields apply.
# Conflicts: # src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
…nd TGA - BmpRleEncoder writes RLE8 and RLE4 rows. A run splits an absolute run only when the split makes the row smaller. - New public BmpCompression option on BmpEncoder and BmpMetadata. The header enum is now the internal BmpInfoCompression. - TgaEncoder.Compression is nullable and falls back to TgaMetadata.Compression. Both decoders set the metadata value. - ICO and ANI bitmaps always write BI_RGB, as the icon format requires. - TgaImageType and its extensions are internal. Remove the unused public BmpFileMarkerType. - The icon AND mask uses pooled buffers and PackIndices.
…lidate icon metadata - ANI: the ACON specification defines each frame as an embedded .CUR file. The encoder now writes ICO and CUR frames only and always sets AF_ICON. The decoder reads raw-bitmap frames in the layout that ReactOS reads, and reports them as CUR frames. AniFrameFormat.Bmp and the reserved AniMetadata header properties are removed. - ANI: SequenceNumber now identifies the stored frame. The encoder stores each stored frame once and writes a 'seq ' chunk when a step plays a stored frame again. - Metadata: icon and ANI frame color tables hold at most 256 entries, TGA alpha channel bits at most 15, TGA color tables at most 65535 entries, and the ANI name and artist are ASCII. - BMP encoder: the alpha mask loop honors cancellation.
- Move the CCITT T.4, T.6 and Modified Huffman code to Compression/Ccitt. TIFF and BMP use the same bit reader, bit writer, code tables and row coders. - Make the CCITT row decoders and encoders faster with a 64-bit bit window, lookup tables and packed row writes. - Add BmpCompression.Huffman1D. Read and write OS/2 BITMAPINFOHEADER2 bitmaps with Huffman 1D data. - Rename the BmpInfoCompression members to .NET casing and fix their docs. - Map 16-bit BMP bit fields to exact layouts only. Write zero unused alpha for 32-bit Bgr. Ignore the fourth byte of V3 32-bit RGB bitmaps. - Report the 16-bit icon layout correctly in ICO, CUR and ANI metadata. - TIFF: fix BlackIsZero polarity for CCITT data, planar strip and tile counts, and damaged fax blocks. - Fix docs, comments and spec citations.
…amaged data - Add SegmentIntegrityHandlingExtensions as the single owner of the integrity policy: mode checks, ancillary and image-data reports with cold throws, catch filters, and segment actions. Remove the duplicate helpers from ImageDecoderCore and HeifDecoderCore and the WebP delegate plumbing. - Report every error that segment code detects through the owner, and keep original exceptions in Strict. - AV1/HEIF: keep decoded frames when data ends inside an OBU header, size field, layered item, extent or sample; stop appending extents after a truncated one. - JXL: read the container structure before image data, as HEIF does; a truncated codestream box follows the image-data policy. - GIF: make the LZW end of data sticky and stop the frame at an invalid code. - JPEG: fill zero bits at end of stream; report truncated arithmetic scans; apply the ancillary policy to truncated APPn and COM segments. - PNG: fix Adam7 passes without columns in the decoder and encoder; skip IDAT chunks after the zlib stream ends. - EXR, PBM, QOI, TIFF, BMP, ICO, CCITT and WebP integrity fixes from review. - Tests compare whole images with exact, structure-derived expectations. - Replace the Issue2859 GIF reference images, which recorded rows decoded after a bad LZW code.
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.
BMP
EncodingUtilities.PackIndices) between BMP, PNG and TIFF. Write each BMP row with one stream write.Compression/Ccittand is shared.ANI, ICO, CUR
Segment integrity handling
SegmentIntegrityHandlingExtensionsowns the policy for all decoders: the mode checks, the ancillary and image-data reports with cold throws, the catch filters and the segment actions.Tests
ImageCompareragainst exact expectations from the file structure.Issue2859GIF reference images are replaced. The old images held rows decoded after a bad LZW code.Performance
The results comments in
DecodeBmp,EncodeBmpandEncodeBmpMultipleare updated.