@jimp/js-bmp 1.0.2--canary.4e85de0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +5 -0
- package/.tshy/build.json +9 -0
- package/.tshy/commonjs.json +15 -0
- package/.tshy/esm.json +14 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test$colon$browser.log +23 -0
- package/.turbo/turbo-test.log +50 -0
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/dist/commonjs/index.d.ts +22 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +74 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +7 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +45 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +7 -0
- package/package.json +63 -0
- package/src/images/windows95.bmp +0 -0
- package/src/images/windows95.png +0 -0
- package/src/index.node.test.ts +17 -0
- package/src/index.test.ts +32 -0
- package/src/index.ts +95 -0
- package/tsconfig.json +6 -0
- package/vitest.config.browser.mjs +3 -0
package/.eslintrc.cjs
ADDED
package/.tshy/build.json
ADDED
package/.tshy/esm.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
> @jimp/js-bmp@1.0.0 test:browser /Users/andrewlisowski/Documents/jimp/plugins/js-bmp
|
|
3
|
+
> vitest --config vitest.config.browser.mjs "--watch=false"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.4.0[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/js-bmp[39m
|
|
7
|
+
[2m[32m Browser runner started at http://localhost:5174/[39m[22m
|
|
8
|
+
|
|
9
|
+
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
10
|
+
[90m·[39m BMP[2m (2)[22m
|
|
11
|
+
[90m·[39m load BMP
|
|
12
|
+
[90m·[39m export BMP
|
|
13
|
+
[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
14
|
+
[32m✓[39m BMP[2m (2)[22m
|
|
15
|
+
[32m✓[39m load BMP
|
|
16
|
+
[32m✓[39m export BMP
|
|
17
|
+
|
|
18
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
19
|
+
[2m Tests [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
20
|
+
[2m Start at [22m 14:34:32
|
|
21
|
+
[2m Duration [22m 1.43s[2m (transform 0ms, setup 0ms, collect 298ms, tests 12ms, environment 0ms, prepare 0ms)[22m
|
|
22
|
+
|
|
23
|
+
[?25h[?25h
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
> @jimp/js-bmp@1.0.0 test /Users/andrewlisowski/Documents/jimp/plugins/js-bmp
|
|
3
|
+
> vitest "--watch=false" "--no-cache"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.4.0[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/js-bmp[39m
|
|
7
|
+
|
|
8
|
+
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
9
|
+
[90m·[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
10
|
+
[?25l[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
11
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
12
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
13
|
+
[33m⠙[39m uses correct colors for BMP
|
|
14
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
15
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
16
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
17
|
+
[33m⠹[39m uses correct colors for BMP
|
|
18
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
19
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
20
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
21
|
+
[33m⠸[39m uses correct colors for BMP
|
|
22
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
23
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
24
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
25
|
+
[33m⠼[39m uses correct colors for BMP
|
|
26
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
27
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
28
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
29
|
+
[33m⠴[39m uses correct colors for BMP
|
|
30
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
31
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
32
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
33
|
+
[33m⠦[39m uses correct colors for BMP
|
|
34
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
35
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
36
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
37
|
+
[33m⠧[39m uses correct colors for BMP
|
|
38
|
+
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
39
|
+
[33m❯[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
40
|
+
[33m❯[39m BMP[2m (1)[22m
|
|
41
|
+
[33m⠇[39m uses correct colors for BMP
|
|
42
|
+
[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
|
43
|
+
[32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
|
44
|
+
|
|
45
|
+
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
46
|
+
[2m Tests [22m [1m[32m3 passed[39m[22m[90m (3)[39m
|
|
47
|
+
[2m Start at [22m 14:26:10
|
|
48
|
+
[2m Duration [22m 989ms[2m (transform 300ms, setup 0ms, collect 641ms, tests 183ms, environment 0ms, prepare 373ms)[22m
|
|
49
|
+
|
|
50
|
+
[?25h[?25h
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Oliver Moran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as BMP from "bmp-ts";
|
|
3
|
+
import { Bitmap } from "@jimp/types";
|
|
4
|
+
export type { BmpColor } from "bmp-ts";
|
|
5
|
+
export { BmpCompression } from "bmp-ts";
|
|
6
|
+
type Pretty<T> = {
|
|
7
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : T[K] extends object ? Pretty<T[K]> : T[K];
|
|
8
|
+
};
|
|
9
|
+
export type EncodeOptions = Pretty<Partial<Pick<BMP.BmpImage, "palette" | "colors" | "importantColors" | "hr" | "vr" | "reserved1" | "reserved2">>>;
|
|
10
|
+
declare function encode(image: Bitmap, options?: EncodeOptions): Buffer;
|
|
11
|
+
declare function decode(data: Buffer): Bitmap;
|
|
12
|
+
export declare function msBmp(): {
|
|
13
|
+
mime: "image/x-ms-bmp";
|
|
14
|
+
encode: typeof encode;
|
|
15
|
+
decode: typeof decode;
|
|
16
|
+
};
|
|
17
|
+
export default function bmp(): {
|
|
18
|
+
mime: "image/bmp";
|
|
19
|
+
encode: typeof encode;
|
|
20
|
+
decode: typeof decode;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAE7C,YAAY,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,KAAK,MAAM,CAAC,CAAC,IAAI;KAEd,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAChD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACZ,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAChC,OAAO,CACL,IAAI,CACF,GAAG,CAAC,QAAQ,EACV,SAAS,GACT,QAAQ,GACR,iBAAiB,GACjB,IAAI,GACJ,IAAI,GACJ,WAAW,GACX,WAAW,CACd,CACF,CACF,CAAC;AAEF,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,UAqBzD;AAED,iBAAS,MAAM,CAAC,IAAI,EAAE,MAAM,UAuB3B;AAED,wBAAgB,KAAK;;;;EAMpB;AAED,MAAM,CAAC,OAAO,UAAU,GAAG;;;;EAM1B"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.msBmp = exports.BmpCompression = void 0;
|
|
27
|
+
const BMP = __importStar(require("bmp-ts"));
|
|
28
|
+
const utils_1 = require("@jimp/utils");
|
|
29
|
+
var bmp_ts_1 = require("bmp-ts");
|
|
30
|
+
Object.defineProperty(exports, "BmpCompression", { enumerable: true, get: function () { return bmp_ts_1.BmpCompression; } });
|
|
31
|
+
function encode(image, options = {}) {
|
|
32
|
+
(0, utils_1.scan)({ bitmap: image }, 0, 0, image.width, image.height, function (_, __, index) {
|
|
33
|
+
const red = image.data[index + 0];
|
|
34
|
+
const green = image.data[index + 1];
|
|
35
|
+
const blue = image.data[index + 2];
|
|
36
|
+
const alpha = image.data[index + 3];
|
|
37
|
+
image.data[index + 0] = alpha;
|
|
38
|
+
image.data[index + 1] = blue;
|
|
39
|
+
image.data[index + 2] = green;
|
|
40
|
+
image.data[index + 3] = red;
|
|
41
|
+
});
|
|
42
|
+
return BMP.encode({ ...image, ...options }).data;
|
|
43
|
+
}
|
|
44
|
+
function decode(data) {
|
|
45
|
+
const result = BMP.decode(data);
|
|
46
|
+
(0, utils_1.scan)({ bitmap: result }, 0, 0, result.width, result.height, function (_, __, index) {
|
|
47
|
+
// const alpha = result.data[index + 0]!;
|
|
48
|
+
const blue = result.data[index + 1];
|
|
49
|
+
const green = result.data[index + 2];
|
|
50
|
+
const red = result.data[index + 3];
|
|
51
|
+
result.data[index + 0] = red;
|
|
52
|
+
result.data[index + 1] = green;
|
|
53
|
+
result.data[index + 2] = blue;
|
|
54
|
+
result.data[index + 3] = 0xff;
|
|
55
|
+
});
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function msBmp() {
|
|
59
|
+
return {
|
|
60
|
+
mime: "image/x-ms-bmp",
|
|
61
|
+
encode,
|
|
62
|
+
decode,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.msBmp = msBmp;
|
|
66
|
+
function bmp() {
|
|
67
|
+
return {
|
|
68
|
+
mime: "image/bmp",
|
|
69
|
+
encode,
|
|
70
|
+
decode,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.default = bmp;
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAE9B,uCAAmC;AAInC,iCAAwC;AAA/B,wGAAA,cAAc,OAAA;AA0BvB,SAAS,MAAM,CAAC,KAAa,EAAE,UAAyB,EAAE;IACxD,IAAA,YAAI,EACF,EAAE,MAAM,EAAE,KAAK,EAAE,EACjB,CAAC,EACD,CAAC,EACD,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,MAAM,EACZ,UAAU,CAAC,EAAE,EAAE,EAAE,KAAK;QACpB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC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CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAChC,CAAC,CACF,CAAC;IAEF,OAAO,MAAgB,CAAC;AAC1B,CAAC;AAED,SAAgB,KAAK;IACnB,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,MAAM;QACN,MAAM;KAC4B,CAAC;AACvC,CAAC;AAND,sBAMC;AAED,SAAwB,GAAG;IACzB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,MAAM;QACN,MAAM;KACuB,CAAC;AAClC,CAAC;AAND,sBAMC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import * as BMP from "bmp-ts";
|
|
3
|
+
import { Bitmap } from "@jimp/types";
|
|
4
|
+
export type { BmpColor } from "bmp-ts";
|
|
5
|
+
export { BmpCompression } from "bmp-ts";
|
|
6
|
+
type Pretty<T> = {
|
|
7
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : T[K] extends object ? Pretty<T[K]> : T[K];
|
|
8
|
+
};
|
|
9
|
+
export type EncodeOptions = Pretty<Partial<Pick<BMP.BmpImage, "palette" | "colors" | "importantColors" | "hr" | "vr" | "reserved1" | "reserved2">>>;
|
|
10
|
+
declare function encode(image: Bitmap, options?: EncodeOptions): Buffer;
|
|
11
|
+
declare function decode(data: Buffer): Bitmap;
|
|
12
|
+
export declare function msBmp(): {
|
|
13
|
+
mime: "image/x-ms-bmp";
|
|
14
|
+
encode: typeof encode;
|
|
15
|
+
decode: typeof decode;
|
|
16
|
+
};
|
|
17
|
+
export default function bmp(): {
|
|
18
|
+
mime: "image/bmp";
|
|
19
|
+
encode: typeof encode;
|
|
20
|
+
decode: typeof decode;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAE7C,YAAY,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,KAAK,MAAM,CAAC,CAAC,IAAI;KAEd,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAChD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACZ,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAChC,OAAO,CACL,IAAI,CACF,GAAG,CAAC,QAAQ,EACV,SAAS,GACT,QAAQ,GACR,iBAAiB,GACjB,IAAI,GACJ,IAAI,GACJ,WAAW,GACX,WAAW,CACd,CACF,CACF,CAAC;AAEF,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,UAqBzD;AAED,iBAAS,MAAM,CAAC,IAAI,EAAE,MAAM,UAuB3B;AAED,wBAAgB,KAAK;;;;EAMpB;AAED,MAAM,CAAC,OAAO,UAAU,GAAG;;;;EAM1B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as BMP from "bmp-ts";
|
|
2
|
+
import { scan } from "@jimp/utils";
|
|
3
|
+
export { BmpCompression } from "bmp-ts";
|
|
4
|
+
function encode(image, options = {}) {
|
|
5
|
+
scan({ bitmap: image }, 0, 0, image.width, image.height, function (_, __, index) {
|
|
6
|
+
const red = image.data[index + 0];
|
|
7
|
+
const green = image.data[index + 1];
|
|
8
|
+
const blue = image.data[index + 2];
|
|
9
|
+
const alpha = image.data[index + 3];
|
|
10
|
+
image.data[index + 0] = alpha;
|
|
11
|
+
image.data[index + 1] = blue;
|
|
12
|
+
image.data[index + 2] = green;
|
|
13
|
+
image.data[index + 3] = red;
|
|
14
|
+
});
|
|
15
|
+
return BMP.encode({ ...image, ...options }).data;
|
|
16
|
+
}
|
|
17
|
+
function decode(data) {
|
|
18
|
+
const result = BMP.decode(data);
|
|
19
|
+
scan({ bitmap: result }, 0, 0, result.width, result.height, function (_, __, index) {
|
|
20
|
+
// const alpha = result.data[index + 0]!;
|
|
21
|
+
const blue = result.data[index + 1];
|
|
22
|
+
const green = result.data[index + 2];
|
|
23
|
+
const red = result.data[index + 3];
|
|
24
|
+
result.data[index + 0] = red;
|
|
25
|
+
result.data[index + 1] = green;
|
|
26
|
+
result.data[index + 2] = blue;
|
|
27
|
+
result.data[index + 3] = 0xff;
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
export function msBmp() {
|
|
32
|
+
return {
|
|
33
|
+
mime: "image/x-ms-bmp",
|
|
34
|
+
encode,
|
|
35
|
+
decode,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export default function bmp() {
|
|
39
|
+
return {
|
|
40
|
+
mime: "image/bmp",
|
|
41
|
+
encode,
|
|
42
|
+
decode,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;A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EAAE,EAAE,EAAE,KAAK;QACpB,yCAAyC;QACzC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC;QACtC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC;QAEpC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAChC,CAAC,CACF,CAAC;IAEF,OAAO,MAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,MAAM;QACN,MAAM;KAC4B,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,GAAG;IACzB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,MAAM;QACN,MAAM;KACuB,CAAC;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jimp/js-bmp",
|
|
3
|
+
"version": "1.0.2--canary.4e85de0.0",
|
|
4
|
+
"repository": "jimp-dev/jimp",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"lint": "eslint .",
|
|
7
|
+
"test": "vitest",
|
|
8
|
+
"test:browser": "vitest --config vitest.config.browser.mjs",
|
|
9
|
+
"build": "tshy",
|
|
10
|
+
"dev": "tshy --watch"
|
|
11
|
+
},
|
|
12
|
+
"author": "Andrew Lisowski <lisowski54@gmail.com>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@jimp/config-eslint": "1.0.2--canary.4e85de0.0",
|
|
16
|
+
"@jimp/config-typescript": "1.0.2--canary.4e85de0.0",
|
|
17
|
+
"@jimp/config-vitest": "1.0.2--canary.4e85de0.0",
|
|
18
|
+
"@jimp/js-png": "1.0.2--canary.4e85de0.0",
|
|
19
|
+
"@jimp/test-utils": "1.0.2--canary.4e85de0.0",
|
|
20
|
+
"@vitest/browser": "^1.4.0",
|
|
21
|
+
"eslint": "^8.57.0",
|
|
22
|
+
"tshy": "^1.12.0",
|
|
23
|
+
"typescript": "^5.4.2",
|
|
24
|
+
"vite-plugin-node-polyfills": "^0.21.0",
|
|
25
|
+
"vitest": "^1.4.0"
|
|
26
|
+
},
|
|
27
|
+
"tshy": {
|
|
28
|
+
"exclude": [
|
|
29
|
+
"**/*.test.ts"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
"./package.json": "./package.json",
|
|
33
|
+
".": "./src/index.ts"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/esm/index.d.ts",
|
|
41
|
+
"default": "./dist/esm/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
45
|
+
"default": "./dist/commonjs/index.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"main": "./dist/commonjs/index.js",
|
|
50
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
51
|
+
"type": "module",
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@jimp/core": "1.0.2--canary.4e85de0.0",
|
|
54
|
+
"@jimp/types": "1.0.2--canary.4e85de0.0",
|
|
55
|
+
"@jimp/utils": "1.0.2--canary.4e85de0.0",
|
|
56
|
+
"bmp-ts": "^1.0.9"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"gitHead": "4e85de0027857bbc7b06ecfd8b98e5d6898fbb94"
|
|
63
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { createJimp } from "@jimp/core";
|
|
3
|
+
import { getTestImagePath } from "@jimp/test-utils";
|
|
4
|
+
|
|
5
|
+
import png from "@jimp/js-png";
|
|
6
|
+
import bmp from "./index.js";
|
|
7
|
+
|
|
8
|
+
const jimp = createJimp({ formats: [bmp, png] });
|
|
9
|
+
|
|
10
|
+
describe("BMP", () => {
|
|
11
|
+
test("uses correct colors for BMP", async function () {
|
|
12
|
+
const expectedImg = await jimp.read(getTestImagePath("windows95.png"));
|
|
13
|
+
const image = await jimp.read(getTestImagePath("windows95.bmp"));
|
|
14
|
+
|
|
15
|
+
expect(image.bitmap.data).toEqual(expectedImg.bitmap.data);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { createJimp } from "@jimp/core";
|
|
3
|
+
import { getTestImagePath } from "@jimp/test-utils";
|
|
4
|
+
|
|
5
|
+
import png from "@jimp/js-png";
|
|
6
|
+
import bmp from "./index.js";
|
|
7
|
+
|
|
8
|
+
const jimp = createJimp({ formats: [bmp, png] });
|
|
9
|
+
|
|
10
|
+
describe("BMP", () => {
|
|
11
|
+
test("load BMP", async () => {
|
|
12
|
+
const image = await jimp.read(getTestImagePath("windows95.bmp"));
|
|
13
|
+
|
|
14
|
+
expect(image.getPixelColor(10, 10)).toBe(0xeff7f7ff);
|
|
15
|
+
expect(image.getPixelColor(150, 80)).toBe(0x73add6ff);
|
|
16
|
+
expect(image.getPixelColor(190, 200)).toBe(0xf7c300ff);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("export BMP", async () => {
|
|
20
|
+
const image = jimp.fromBitmap({
|
|
21
|
+
width: 3,
|
|
22
|
+
height: 3,
|
|
23
|
+
data: [
|
|
24
|
+
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
|
|
25
|
+
0xff00ffff, 0x8000ffff, 0x0000ffff,
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
const buffer = await image.getBuffer("image/bmp");
|
|
29
|
+
|
|
30
|
+
expect(buffer.toString()).toMatch(/^BM/);
|
|
31
|
+
});
|
|
32
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as BMP from "bmp-ts";
|
|
2
|
+
|
|
3
|
+
import { scan } from "@jimp/utils";
|
|
4
|
+
import { Bitmap, Format } from "@jimp/types";
|
|
5
|
+
|
|
6
|
+
export type { BmpColor } from "bmp-ts";
|
|
7
|
+
export { BmpCompression } from "bmp-ts";
|
|
8
|
+
|
|
9
|
+
type Pretty<T> = {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any
|
|
12
|
+
? T[K]
|
|
13
|
+
: T[K] extends object
|
|
14
|
+
? Pretty<T[K]>
|
|
15
|
+
: T[K];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type EncodeOptions = Pretty<
|
|
19
|
+
Partial<
|
|
20
|
+
Pick<
|
|
21
|
+
BMP.BmpImage,
|
|
22
|
+
| "palette"
|
|
23
|
+
| "colors"
|
|
24
|
+
| "importantColors"
|
|
25
|
+
| "hr"
|
|
26
|
+
| "vr"
|
|
27
|
+
| "reserved1"
|
|
28
|
+
| "reserved2"
|
|
29
|
+
>
|
|
30
|
+
>
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
function encode(image: Bitmap, options: EncodeOptions = {}) {
|
|
34
|
+
scan(
|
|
35
|
+
{ bitmap: image },
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
image.width,
|
|
39
|
+
image.height,
|
|
40
|
+
function (_, __, index) {
|
|
41
|
+
const red = image.data[index + 0]!;
|
|
42
|
+
const green = image.data[index + 1]!;
|
|
43
|
+
const blue = image.data[index + 2]!;
|
|
44
|
+
const alpha = image.data[index + 3]!;
|
|
45
|
+
|
|
46
|
+
image.data[index + 0] = alpha;
|
|
47
|
+
image.data[index + 1] = blue;
|
|
48
|
+
image.data[index + 2] = green;
|
|
49
|
+
image.data[index + 3] = red;
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return BMP.encode({ ...image, ...options }).data;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function decode(data: Buffer) {
|
|
57
|
+
const result = BMP.decode(data);
|
|
58
|
+
|
|
59
|
+
scan(
|
|
60
|
+
{ bitmap: result },
|
|
61
|
+
0,
|
|
62
|
+
0,
|
|
63
|
+
result.width,
|
|
64
|
+
result.height,
|
|
65
|
+
function (_, __, index) {
|
|
66
|
+
// const alpha = result.data[index + 0]!;
|
|
67
|
+
const blue = result.data[index + 1]!;
|
|
68
|
+
const green = result.data[index + 2]!;
|
|
69
|
+
const red = result.data[index + 3]!;
|
|
70
|
+
|
|
71
|
+
result.data[index + 0] = red;
|
|
72
|
+
result.data[index + 1] = green;
|
|
73
|
+
result.data[index + 2] = blue;
|
|
74
|
+
result.data[index + 3] = 0xff;
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return result as Bitmap;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function msBmp() {
|
|
82
|
+
return {
|
|
83
|
+
mime: "image/x-ms-bmp",
|
|
84
|
+
encode,
|
|
85
|
+
decode,
|
|
86
|
+
} satisfies Format<"image/x-ms-bmp">;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default function bmp() {
|
|
90
|
+
return {
|
|
91
|
+
mime: "image/bmp",
|
|
92
|
+
encode,
|
|
93
|
+
decode,
|
|
94
|
+
} satisfies Format<"image/bmp">;
|
|
95
|
+
}
|
package/tsconfig.json
ADDED