1j01 / jspaint

🎨 Classic MS Paint, REVIVED + ✨Extras
https://jspaint.app/about
MIT License
7.16k stars 562 forks source link

Pixel data offset field from the BMP header is ignored #323

Open adzierzanowski opened 11 months ago

adzierzanowski commented 11 months ago

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