Skip to content

bmp: Add decoder - #1376

Open
ChrisJr404 wants to merge 1 commit into
wader:masterfrom
ChrisJr404:bmp
Open

bmp: Add decoder#1376
ChrisJr404 wants to merge 1 commit into
wader:masterfrom
ChrisJr404:bmp

Conversation

@ChrisJr404

Copy link
Copy Markdown

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 rest field), 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.

@wader wader left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start. Added some comments and thoughts

Comment thread format/bmp/bmp.go
})
}

if gap := int64(bitmapOffset)*8 - d.Pos(); gap > 0 {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try remove this, gaps will be added a fields automatically

Comment thread format/bmp/bmp.go
var colorsUsed uint64

d.FieldStruct("file_header", func(d *decode.D) {
d.FieldUTF8("type", 2, d.StrAssert("BM"))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe have one test that don't use -d to test probe

Comment thread format/bmp/bmp.go
compressionRLE8: "rle8",
compressionRLE4: "rle4",
compressionBitfields: "bitfields",
compressionJPEG: "jpeg",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jpeg and png could be decoded as subformats but maybe should be done in a separate PR

Comment thread format/bmp/bmp.go
d.FieldRawLen("gap", gap)
}

d.FieldRawLen("pixels", d.BitsLeft())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Support image/bmp

2 participants