bmp: Add decoder - #1376
Conversation
wader
left a comment
There was a problem hiding this comment.
Good start. Added some comments and thoughts
| }) | ||
| } | ||
|
|
||
| if gap := int64(bitmapOffset)*8 - d.Pos(); gap > 0 { |
There was a problem hiding this comment.
You can try remove this, gaps will be added a fields automatically
| var colorsUsed uint64 | ||
|
|
||
| d.FieldStruct("file_header", func(d *decode.D) { | ||
| d.FieldUTF8("type", 2, d.StrAssert("BM")) |
There was a problem hiding this comment.
Being in the probe group require that it can be detected without high risk of false positives and not doing much reading. Maybe check for "BM" and make sure file length is at least size big? anything else?
| @@ -0,0 +1,29 @@ | |||
| # BITMAPV4HEADER (108 byte) 2x2 32-bit BGRA image, generated by hand | |||
| $ fq -d bmp dv v4.bmp | |||
There was a problem hiding this comment.
maybe have one test that don't use -d to test probe
| compressionRLE8: "rle8", | ||
| compressionRLE4: "rle4", | ||
| compressionBitfields: "bitfields", | ||
| compressionJPEG: "jpeg", |
There was a problem hiding this comment.
jpeg and png could be decoded as subformats but maybe should be done in a separate PR
| d.FieldRawLen("gap", gap) | ||
| } | ||
|
|
||
| d.FieldRawLen("pixels", d.BitsLeft()) |
There was a problem hiding this comment.
Could we know the size of pixels data instead of assuming all remaining? derive from image_size but specs seems to be a bit unclear if there are special values like 0 that has to be handled
Adds a decoder for BMP images, closes #745.
It decodes the file header and the BITMAPINFOHEADER family of DIB headers (the common 40 byte one plus the v4/v5 extensions, whose extra bytes go into a
restfield), the color table for palettized images, and the rest as raw pixel data. Endian is little as usual for BMP.Tests cover a 24 bit image, a 1 bit palettized image and a BITMAPV4HEADER image. I left the old 12 byte BITMAPCOREHEADER out since I've never run into one, happy to add it if you want.