Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/parse_stream/bmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = function () {
}

parser.push({
width: data.readUInt16LE(18),
height: data.readUInt16LE(22),
width: data.readInt32LE(18),
height: Math.abs(data.readInt32LE(22)),
type: 'bmp',
mime: 'image/bmp',
wUnits: 'px',
Expand Down
6 changes: 3 additions & 3 deletions lib/parse_sync/bmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var str2arr = require('../common').str2arr;
var sliceEq = require('../common').sliceEq;
var readUInt16LE = require('../common').readUInt16LE;
var readUInt32LE = require('../common').readUInt32LE;

var SIG_BM = str2arr('BM');

Expand All @@ -15,8 +15,8 @@ module.exports = function (data) {
if (!sliceEq(data, 0, SIG_BM)) return;

return {
width: readUInt16LE(data, 18),
height: readUInt16LE(data, 22),
width: readUInt32LE(data, 18),
height: Math.abs(readUInt32LE(data, 22)),
type: 'bmp',
mime: 'image/bmp',
wUnits: 'px',
Expand Down
Binary file added test/fixtures/iojs_logo_flip_row_order.bmp
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test_formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ describe('File formats', function () {

assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' });
});


it('should get correct size on flip row order BMP', async function () {
let file = path.join(__dirname, 'fixtures', 'iojs_logo_flip_row_order.bmp');

let size = await probe(fs.createReadStream(file));

assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' });
});
});


Expand All @@ -31,6 +40,14 @@ describe('File formats', function () {

assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' });
});


it('should get correct size on flip row order BMP', function () {
let file = path.join(__dirname, 'fixtures', 'iojs_logo_flip_row_order.bmp');
let size = probe.sync(fs.readFileSync(file));

assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' });
});
});


Expand Down