-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbmp.js
More file actions
33 lines (25 loc) · 688 Bytes
/
bmp.js
File metadata and controls
33 lines (25 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// decode bmp buffer
'use strict'
var bmp = require('bmp-js')
module.exports = function read (data, o) {
var bmpData = bmp.decode(Buffer.from(data))
var width = bmpData.width
var height = bmpData.height
var pixels = new Uint8Array(width * height * 4)
// bmp stores stuff as ABGR seq
for (var i = 0; i < pixels.length; i+=4) {
var alpha = bmpData.data[i + 0];
var blue = bmpData.data[i + 1];
var green = bmpData.data[i + 2];
var red = bmpData.data[i + 3];
pixels[i + 0] = red;
pixels[i + 1] = green;
pixels[i + 2] = blue;
pixels[i + 3] = bmpData.is_with_alpha ? alpha : 0xff;
}
return {
data: pixels,
width: bmpData.width,
height: bmpData.height
}
}