Repository navigation
Map preview image offsets through page file offsets and wrap bare bitmaps - #45
Merged
Merged
Conversation
…maps AcDb:Preview directory entries store absolute file offsets. ReadSection now reports each page's section position and payload file offset, and PreviewParser converts directory offsets to section positions through that layout, range-checking every candidate. Bitmap previews are stored as a bare DIB, so a 14-byte BMP file header with a computed pixel offset is added. ImageKind is derived from the bytes actually found instead of the directory slot, and invalid bytes no longer produce a Bmp preview.
Keep the image kind found in its directory slot instead of re-detecting (which dropped WMF), include WMF in DetectKind, account BI_BITFIELDS masks in bfOffBits, and extract images whose bytes span consecutive uncompressed pages.
BI_ALPHABITFIELDS carries red, green, blue and alpha masks after the 40-byte header; BI_BITFIELDS carries three. Add a 32bpp regression test expecting bfOffBits 70.
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.
Fixes #10
Problem
The image directory in
AcDb:Previewstores absolute file offsets, butPreviewParserread them as section-relative offsets. AC1024 previews therefore resolved to nothing, AC1027/AC1032 PNGs were only recovered by the byte-pattern fallback, and a BMP slot holding arbitrary bytes was still labelledBmp.Change
R2004Container.ReadSectioncan now report each page's section offset, decompressed length and payload file offset. Only uncompressed pages are eligible for absolute-offset mapping.PreviewParserconverts each directory start to a section position through the page layout and range-checks the result before reading. Section-relative offsets remain a fallback for writers that stored them that way.BM) is wrapped in a 14-byteBITMAPFILEHEADER.bfOffBitsis computed from the DIB header size, bit depth, compression and palette size.ImageKindis now derived from the bytes actually extracted (PNG, BMP or WMF); bytes that match no format produceImageKind.NoneandHasImage == false.Preview_HasImageWhenSectionPresentnow describes the real reason a preview section can lack an image.Tests
bfOffBits.ImageKind.Noneand no bytes.Verification
dotnet build DwgIO.slnx -c Release: succeeded.dotnet test DwgIO.slnx -c Release --no-build: 73 passed, 7 fixture tests skipped, 0 failed on net8.0 and net10.0.DWGIO_TEST_FILES=<AC1024 sample folder>on net10.0: 80 passed, 0 skipped, 0 failed.Bmpwith 86,070 bytes; the file starts withBM,bfSize86,070,bfOffBits1,078, 329x256 at 8 bpp.Png2,022 bytes, SHA256 identical to the pre-change export (F547...C515).IEND; the old fallback returned 1,720 bytes because it scanned to the last sentinel and included a second, undeclared preview block after the first end sentinel. The new result is the 1,448-byte image described by the directory.