shaozilee / bmp-js

A pure javascript BMP encoder and decoder for node.js
MIT License
86 stars 45 forks source link

Doesn't properly decode bmp #39

Open kugiyasan opened 1 year ago

kugiyasan commented 1 year ago

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:

meszaros-lajos-gyorgy commented 1 year ago

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 commented 1 year ago

I had success with this:

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

bmp4 has issues.