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

Add support for various BMP headers and color depths #1435

Merged
merged 12 commits into from
Jun 10, 2019
Prev Previous commit
Next Next commit
V5 header and sRGB color space
  • Loading branch information
Hakerh400 committed Jun 6, 2019
commit e2de21f34c9745aa1613c8760919c9770cbe2075
11 changes: 7 additions & 4 deletions src/bmp/BMPParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ void Parser::parse(uint8_t *buf, int bufSize, uint8_t *format){
temp = "DIB header";
EU(dibSize == 64, temp + " \"OS22XBITMAPHEADER\"");
EU(dibSize == 16, temp + " \"OS22XBITMAPHEADER\"");
EU(dibSize == 124, temp + " \"BITMAPV5HEADER\"");

uint32_t infoHeader = dibSize == 40 ? 1 : dibSize == 52 ? 2 : dibSize == 56 ? 3 : dibSize == 108 ? 4 : 0;
uint32_t infoHeader = dibSize == 40 ? 1 :
dibSize == 52 ? 2 :
dibSize == 56 ? 3 :
dibSize == 108 ? 4 :
dibSize == 124 ? 5 : 0;

// BITMAPCOREHEADER, BITMAP*INFOHEADER, BITMAPV4HEADER
// BITMAPCOREHEADER, BITMAP*INFOHEADER, BITMAP*HEADER
auto isDibValid = dibSize == 12 || infoHeader;
EX(!isDibValid, temp);

Expand Down Expand Up @@ -174,7 +177,7 @@ void Parser::parse(uint8_t *buf, int bufSize, uint8_t *format){
if(!palColNum){
// Ensure that the color space is LCS_WINDOWS_COLOR_SPACE
string colSpace = getStr(4, 1);
EU(colSpace != "Win ", "color space \"" + colSpace + "\"");
EU(colSpace != "Win " && colSpace != "sRGB", "color space \"" + colSpace + "\"");
}else{
skip(4);
}
Expand Down
Binary file added test/fixtures/bmp/v5-header.bmp
Binary file not shown.
13 changes: 13 additions & 0 deletions test/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ describe('Image', function () {
img.src = path.join(bmp_dir, 'v3-header.bmp');
});

it('V5 header', function (done) {
let img = new Image();

img.onload = () => {
assert.strictEqual(img.width, 256);
assert.strictEqual(img.height, 192);
done();
};

img.onerror = err => { throw err; };
img.src = path.join(bmp_dir, 'v5-header.bmp');
});

it('catches BMP errors', function (done) {
let img = new Image();

Expand Down