Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/bmp/src/index.js
1126 views
1
import BMP from 'bmp-js';
2
import { scan } from '@jimp/utils';
3
4
const MIME_TYPE = 'image/bmp';
5
const MIME_TYPE_SECOND = 'image/x-ms-bmp';
6
7
function toAGBR(image) {
8
return scan(image, 0, 0, image.bitmap.width, image.bitmap.height, function(
9
x,
10
y,
11
index
12
) {
13
const red = this.bitmap.data[index + 0];
14
const green = this.bitmap.data[index + 1];
15
const blue = this.bitmap.data[index + 2];
16
const alpha = this.bitmap.data[index + 3];
17
18
this.bitmap.data[index + 0] = alpha;
19
this.bitmap.data[index + 1] = blue;
20
this.bitmap.data[index + 2] = green;
21
this.bitmap.data[index + 3] = red;
22
}).bitmap;
23
}
24
25
function fromAGBR(bitmap) {
26
return scan({ bitmap }, 0, 0, bitmap.width, bitmap.height, function(
27
x,
28
y,
29
index
30
) {
31
const alpha = this.bitmap.data[index + 0];
32
const blue = this.bitmap.data[index + 1];
33
const green = this.bitmap.data[index + 2];
34
const red = this.bitmap.data[index + 3];
35
36
this.bitmap.data[index + 0] = red;
37
this.bitmap.data[index + 1] = green;
38
this.bitmap.data[index + 2] = blue;
39
this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff;
40
}).bitmap;
41
}
42
43
const decode = data => fromAGBR(BMP.decode(data));
44
const encode = image => BMP.encode(toAGBR(image)).data;
45
46
export default () => ({
47
mime: { [MIME_TYPE]: ['bmp'] },
48
49
constants: {
50
MIME_BMP: MIME_TYPE,
51
MIME_X_MS_BMP: MIME_TYPE_SECOND
52
},
53
54
decoders: {
55
[MIME_TYPE]: decode,
56
[MIME_TYPE_SECOND]: decode
57
},
58
59
encoders: {
60
[MIME_TYPE]: encode,
61
[MIME_TYPE_SECOND]: encode
62
}
63
});
64
65