jspaint icon indicating copy to clipboard operation
jspaint copied to clipboard

Pixel data offset field from the BMP header is ignored

Open adzierzanowski opened this issue 1 year ago • 0 comments

The problem

This is somewhat of an edge case. Unlike in mspaint, the field in the header which tells the offset to the pixel data is ignored which results in rendering the data from the usual offset of 54 bytes. (EDIT: Or as I see now, rather the first position of the cursor after parsing all headers).

As you can see, the offset is already parsed:

https://github.com/1j01/jspaint/blob/12a90c6bb9d36f495dc6a07114f9667c82ee5228/lib/bmp.js#L325

Example

This is a BMP file which is purposefully deceitful as it contains two images. When the offset is ignored, the "hidden" text appears in the image. Otherwise it displays just a photo of ice. Opening it in mspaint looks like below. Opening it in jspaint shows the text.

Possible solution

Set location to the offset in the BMPDecoder class, scanImage function:

scanImage(padding = 0, width = this.width, processPixel) {
		this.pos = this.offset

adzierzanowski avatar Aug 04 '23 22:08 adzierzanowski