@huh-david/bmp-js 0.4.1 → 0.6.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/README.md +47 -3
- package/dist/chunk-YH5DJH4H.js +832 -0
- package/dist/chunk-YH5DJH4H.js.map +1 -0
- package/dist/index.cjs +231 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -46
- package/dist/index.d.ts +24 -46
- package/dist/index.js +6 -615
- package/dist/index.js.map +1 -1
- package/dist/sharp/index.cjs +1025 -0
- package/dist/sharp/index.cjs.map +1 -0
- package/dist/sharp/index.d.cts +58 -0
- package/dist/sharp/index.d.ts +58 -0
- package/dist/sharp/index.js +172 -0
- package/dist/sharp/index.js.map +1 -0
- package/dist/types-CzYgOtEn.d.cts +48 -0
- package/dist/types-CzYgOtEn.d.ts +48 -0
- package/package.json +25 -2
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @huh-david/bmp-js
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@huh-david/bmp-js)
|
|
4
|
+
[](https://huh-david.github.io/bmp-js/)
|
|
5
|
+
|
|
3
6
|
A pure TypeScript BMP encoder/decoder for Node.js.
|
|
4
7
|
|
|
5
8
|
## Maintenance
|
|
@@ -7,14 +10,15 @@ A pure TypeScript BMP encoder/decoder for Node.js.
|
|
|
7
10
|
This fork is actively maintained and tracks unresolved upstream `shaozilee/bmp-js` issues and PRs.
|
|
8
11
|
|
|
9
12
|
- Repository: https://github.com/Huh-David/bmp-js
|
|
10
|
-
-
|
|
13
|
+
- Releases: https://github.com/Huh-David/bmp-js/releases
|
|
14
|
+
- Documentation: https://huh-david.github.io/bmp-js/
|
|
11
15
|
|
|
12
16
|
## Features
|
|
13
17
|
|
|
14
18
|
- Decoding for BMP bit depths: 1, 4, 8, 15, 16, 24, 32
|
|
15
19
|
- Decoding support for RLE-4 and RLE-8 compressed BMPs
|
|
16
20
|
- Robust DIB handling for CORE/INFO/V4/V5 headers
|
|
17
|
-
- Encoding output
|
|
21
|
+
- Encoding output bit depths: 1, 4, 8, 16, 24, 32
|
|
18
22
|
- Dual package output: ESM + CommonJS
|
|
19
23
|
- First-class TypeScript types
|
|
20
24
|
|
|
@@ -57,7 +61,9 @@ const encoded = encode(
|
|
|
57
61
|
},
|
|
58
62
|
{
|
|
59
63
|
orientation: "bottom-up", // default: "top-down"
|
|
60
|
-
bitPP:
|
|
64
|
+
bitPP: 32, // supported: 1, 4, 8, 16, 24, 32
|
|
65
|
+
// palette is required for 4/8-bit and optional for 1-bit
|
|
66
|
+
// palette: [{ red: 0, green: 0, blue: 0, quad: 0 }, ...],
|
|
61
67
|
},
|
|
62
68
|
);
|
|
63
69
|
```
|
|
@@ -96,6 +102,44 @@ If `toRGBA: true` is provided to `decode`, output is returned in `RGBA`.
|
|
|
96
102
|
|
|
97
103
|
Input/output binary types use `Uint8Array` (Node `Buffer` is fully compatible because it extends `Uint8Array`).
|
|
98
104
|
|
|
105
|
+
## Sharp adapter (optional subexport)
|
|
106
|
+
|
|
107
|
+
The package ships an optional Sharp adapter at `@huh-david/bmp-js/sharp`.
|
|
108
|
+
Core usage does not require `sharp`.
|
|
109
|
+
|
|
110
|
+
Install Sharp only when using the adapter:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pnpm add sharp
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### BMP -> Sharp -> PNG
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import sharp from "sharp";
|
|
120
|
+
import { sharpFromBmp } from "@huh-david/bmp-js/sharp";
|
|
121
|
+
|
|
122
|
+
const png = await sharpFromBmp(bmpBytes, sharp).resize(800).png().toBuffer();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Sharp raw -> BMP
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import sharp from "sharp";
|
|
129
|
+
import { encodeFromSharp } from "@huh-david/bmp-js/sharp";
|
|
130
|
+
|
|
131
|
+
const { data, info } = await sharp(input).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
132
|
+
|
|
133
|
+
const bmp = encodeFromSharp({ data, info }, { bitDepth: 32 });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Adapter behavior:
|
|
137
|
+
|
|
138
|
+
- `decodeForSharp` and `sharpFromBmp` require BMP input and throw on non-BMP bytes.
|
|
139
|
+
- Sharp-bound decode output is normalized to `RGBA` + `{ raw: { width, height, channels: 4 } }`.
|
|
140
|
+
- `encodeFromSharp` supports `channels` 3 and 4 only; other values throw.
|
|
141
|
+
- Default encode depth is data-preserving: RGB -> 24-bit, RGBA -> 32-bit.
|
|
142
|
+
|
|
99
143
|
## Development
|
|
100
144
|
|
|
101
145
|
```bash
|