@huh-david/bmp-js 0.5.0 → 0.7.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 +52 -1
- package/dist/chunk-YH5DJH4H.js +832 -0
- package/dist/chunk-YH5DJH4H.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -47
- package/dist/index.d.ts +3 -47
- package/dist/index.js +6 -824
- package/dist/index.js.map +1 -1
- package/dist/sharp/index.cjs +1088 -0
- package/dist/sharp/index.cjs.map +1 -0
- package/dist/sharp/index.d.cts +82 -0
- package/dist/sharp/index.d.ts +82 -0
- package/dist/sharp/index.js +235 -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,7 +10,8 @@ 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
|
|
|
@@ -98,6 +102,53 @@ If `toRGBA: true` is provided to `decode`, output is returned in `RGBA`.
|
|
|
98
102
|
|
|
99
103
|
Input/output binary types use `Uint8Array` (Node `Buffer` is fully compatible because it extends `Uint8Array`).
|
|
100
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
|
+
- Inputs are `Uint8Array`-first and accept `Buffer`/`ArrayBuffer`/typed-array views.
|
|
143
|
+
- `sharpFromBmp` supports both forms:
|
|
144
|
+
- `sharpFromBmp(input, sharp?)`
|
|
145
|
+
- `sharpFromBmp({ input, sharp })`
|
|
146
|
+
- `encodeFromSharp` supports:
|
|
147
|
+
- `encodeFromSharp({ data, info }, options?)`
|
|
148
|
+
- `encodeFromSharp({ data, width, height, channels }, options?)`
|
|
149
|
+
- `encodeFromSharp(data, info, options?)`
|
|
150
|
+
- `toSharpInput` is kept as a compatibility alias for `decodeForSharp`.
|
|
151
|
+
|
|
101
152
|
## Development
|
|
102
153
|
|
|
103
154
|
```bash
|