Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't properly decode bmp #39

Open
kugiyasan opened this issue Apr 5, 2023 · 2 comments
Open

Doesn't properly decode bmp #39

kugiyasan opened this issue Apr 5, 2023 · 2 comments

Comments

@kugiyasan
Copy link

Hi, I realized that bmp-js doesn't seem to handle correctly any bmp generated by Gimp.

const bmp = require("bmp-js");
const fs = require("fs")

const bmpBuffer = fs.readFileSync("input.bmp");
const bmpData = bmp.decode(bmpBuffer);

fs.writeFileSync("output.bmp", bmp.encode(bmpData).data);
$ file input.bmp output.bmp
input.bmp:  PC bitmap, Windows 98/2000 and newer format, 640 x 480 x 24, cbSize 921738, bits offset 138
output.bmp: PC bitmap, Windows 3.x format, 640 x -480 x 24, image size 921600, cbSize 921654, bits offset 54

Top: input.bmp, Bottom: output.bmp

diff

Steps to reproduce:

  • Export a bmp image from gimp (exporting with 24 bits seems to offset horizontally the image like in my case, using any 32 bits format seems to taint output.bmp in red or aqua on top of that)
    image
  • Run the above script
@meszaros-lajos-gyorgy
Copy link

meszaros-lajos-gyorgy commented Jun 8, 2023

In Gimp when exporting open the Compatibility Options and make sure to check the Do not write color space information checkbox. That should fix the offset.

bmp-js doesn't deal with the ICC color profile in the header

( on the left side of the image there is the extra color space information, which is missing from the right side )
image
image

This issue only occures with Gimp exports as Gimp is the only program that adds the BITMAPV5HEADER to the file according to wikipedia

@banool
Copy link

banool commented Jul 28, 2023

I had success with this:

mogrify -format bmp -define bmp:format=bmp3 image.bmp

bmp4 has issues.

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

No branches or pull requests

3 participants