@huh-david/bmp-js 0.6.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 +9 -0
- package/dist/sharp/index.cjs +77 -14
- package/dist/sharp/index.cjs.map +1 -1
- package/dist/sharp/index.d.cts +33 -9
- package/dist/sharp/index.d.ts +33 -9
- package/dist/sharp/index.js +77 -14
- package/dist/sharp/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,15 @@ Adapter behavior:
|
|
|
139
139
|
- Sharp-bound decode output is normalized to `RGBA` + `{ raw: { width, height, channels: 4 } }`.
|
|
140
140
|
- `encodeFromSharp` supports `channels` 3 and 4 only; other values throw.
|
|
141
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`.
|
|
142
151
|
|
|
143
152
|
## Development
|
|
144
153
|
|
package/dist/sharp/index.cjs
CHANGED
|
@@ -889,8 +889,8 @@ var require2 = (0, import_node_module.createRequire)(
|
|
|
889
889
|
typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`
|
|
890
890
|
);
|
|
891
891
|
function toUint8Array2(input) {
|
|
892
|
-
if (input
|
|
893
|
-
return input;
|
|
892
|
+
if (ArrayBuffer.isView(input)) {
|
|
893
|
+
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
894
894
|
}
|
|
895
895
|
return new Uint8Array(input);
|
|
896
896
|
}
|
|
@@ -940,6 +940,66 @@ function normalizeBitDepth(channels, bitDepth) {
|
|
|
940
940
|
}
|
|
941
941
|
return channels === 4 ? 32 : 24;
|
|
942
942
|
}
|
|
943
|
+
function normalizeSharpFromBmpArgs(inputOrOptions, sharpModule) {
|
|
944
|
+
if (typeof inputOrOptions === "object" && inputOrOptions !== null && "input" in inputOrOptions) {
|
|
945
|
+
const options = inputOrOptions;
|
|
946
|
+
const resolvedSharpModule = sharpModule ?? options.sharp;
|
|
947
|
+
if (resolvedSharpModule) {
|
|
948
|
+
return {
|
|
949
|
+
input: options.input,
|
|
950
|
+
sharpModule: resolvedSharpModule
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
return {
|
|
954
|
+
input: options.input
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
if (sharpModule) {
|
|
958
|
+
return {
|
|
959
|
+
input: inputOrOptions,
|
|
960
|
+
sharpModule
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
return {
|
|
964
|
+
input: inputOrOptions
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions) {
|
|
968
|
+
if (typeof inputOrData === "object" && inputOrData !== null && "data" in inputOrData && "info" in inputOrData) {
|
|
969
|
+
const payload = inputOrData;
|
|
970
|
+
return {
|
|
971
|
+
data: toUint8Array2(payload.data),
|
|
972
|
+
info: payload.info,
|
|
973
|
+
options: infoOrOptions ?? {}
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
if (typeof inputOrData === "object" && inputOrData !== null && "data" in inputOrData && "width" in inputOrData && "height" in inputOrData && "channels" in inputOrData) {
|
|
977
|
+
const payload = inputOrData;
|
|
978
|
+
const info = {
|
|
979
|
+
width: payload.width,
|
|
980
|
+
height: payload.height,
|
|
981
|
+
channels: payload.channels
|
|
982
|
+
};
|
|
983
|
+
if (payload.premultiplied !== void 0) {
|
|
984
|
+
info.premultiplied = payload.premultiplied;
|
|
985
|
+
}
|
|
986
|
+
return {
|
|
987
|
+
data: toUint8Array2(payload.data),
|
|
988
|
+
info,
|
|
989
|
+
options: infoOrOptions ?? {}
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
if (typeof infoOrOptions === "object" && infoOrOptions !== null && "width" in infoOrOptions && "height" in infoOrOptions && "channels" in infoOrOptions) {
|
|
993
|
+
return {
|
|
994
|
+
data: toUint8Array2(inputOrData),
|
|
995
|
+
info: infoOrOptions,
|
|
996
|
+
options: maybeOptions ?? {}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
throw new InvalidSharpRawInputError(
|
|
1000
|
+
"Invalid encodeFromSharp input. Expected { data, info }, { data, width, height, channels }, or (data, info)."
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
943
1003
|
function isBmp(input) {
|
|
944
1004
|
try {
|
|
945
1005
|
const bytes = toUint8Array2(input);
|
|
@@ -962,6 +1022,7 @@ function decodeForSharp(input) {
|
|
|
962
1022
|
return {
|
|
963
1023
|
data: decoded.data,
|
|
964
1024
|
raw,
|
|
1025
|
+
info: raw,
|
|
965
1026
|
width: decoded.width,
|
|
966
1027
|
height: decoded.height,
|
|
967
1028
|
channels: 4
|
|
@@ -970,16 +1031,18 @@ function decodeForSharp(input) {
|
|
|
970
1031
|
function toSharpInput(input) {
|
|
971
1032
|
return decodeForSharp(input);
|
|
972
1033
|
}
|
|
973
|
-
function sharpFromBmp(
|
|
974
|
-
const
|
|
975
|
-
const
|
|
1034
|
+
function sharpFromBmp(inputOrOptions, sharpModule) {
|
|
1035
|
+
const normalized = normalizeSharpFromBmpArgs(inputOrOptions, sharpModule);
|
|
1036
|
+
const decoded = decodeForSharp(normalized.input);
|
|
1037
|
+
const sharp = loadSharpModule(normalized.sharpModule);
|
|
976
1038
|
return sharp(decoded.data, { raw: decoded.raw });
|
|
977
1039
|
}
|
|
978
|
-
function encodeFromSharp(
|
|
979
|
-
const
|
|
980
|
-
const
|
|
981
|
-
const
|
|
982
|
-
const
|
|
1040
|
+
function encodeFromSharp(inputOrData, infoOrOptions, maybeOptions) {
|
|
1041
|
+
const normalized = normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions);
|
|
1042
|
+
const data = normalized.data;
|
|
1043
|
+
const width = normalized.info.width;
|
|
1044
|
+
const height = normalized.info.height;
|
|
1045
|
+
const channels = normalized.info.channels;
|
|
983
1046
|
assertPositiveInteger("info.width", width);
|
|
984
1047
|
assertPositiveInteger("info.height", height);
|
|
985
1048
|
if (channels !== 3 && channels !== 4) {
|
|
@@ -993,13 +1056,13 @@ function encodeFromSharp(input, options = {}) {
|
|
|
993
1056
|
`Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`
|
|
994
1057
|
);
|
|
995
1058
|
}
|
|
996
|
-
const bitDepth = normalizeBitDepth(channels, options.bitDepth);
|
|
1059
|
+
const bitDepth = normalizeBitDepth(channels, normalized.options.bitDepth);
|
|
997
1060
|
const encodeOptions = {
|
|
998
1061
|
bitPP: bitDepth,
|
|
999
|
-
orientation: options.topDown ? "top-down" : "bottom-up"
|
|
1062
|
+
orientation: normalized.options.topDown ? "top-down" : "bottom-up"
|
|
1000
1063
|
};
|
|
1001
|
-
if (options.palette) {
|
|
1002
|
-
encodeOptions.palette = options.palette;
|
|
1064
|
+
if (normalized.options.palette) {
|
|
1065
|
+
encodeOptions.palette = normalized.options.palette;
|
|
1003
1066
|
}
|
|
1004
1067
|
return encode(
|
|
1005
1068
|
{
|
package/dist/sharp/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sharp/index.ts","../../src/binary.ts","../../src/decoder.ts","../../src/encoder.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: DecodeForSharpInput | BmpSharpInput): Uint8Array {\n if (input instanceof Uint8Array) {\n return input;\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nexport function isBmp(input: BmpSharpInput): boolean {\n try {\n const bytes = toUint8Array(input);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance {\n const decoded = decodeForSharp(input);\n const sharp = loadSharpModule(sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options: EncodeBmpOptions = {}): Uint8Array {\n const data = toUint8Array(input.data);\n const width = input.info.width;\n const height = input.info.height;\n const channels = input.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (options.palette) {\n encodeOptions.palette = options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","import type { BmpBinaryInput } from \"./types\";\n\nexport function toUint8Array(input: BmpBinaryInput): Uint8Array {\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input);\n }\n\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n\nexport function assertInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n}\n","import { toUint8Array } from \"./binary\";\nimport type { BmpBinaryInput, BmpPaletteColor, DecodeOptions, DecodedBmp } from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_MIN = 40;\nconst CORE_HEADER_SIZE = 12;\n\nfunction rowStride(width: number, bitPP: number): number {\n return Math.floor((bitPP * width + 31) / 32) * 4;\n}\n\nclass BmpDecoder implements DecodedBmp {\n private pos = 0;\n private readonly bytes: Uint8Array;\n private readonly view: DataView;\n private readonly options: Required<DecodeOptions>;\n private bottomUp = true;\n private dibStart = FILE_HEADER_SIZE;\n private paletteEntrySize = 4;\n private externalMaskOffset = 0;\n\n private maskRed = 0;\n private maskGreen = 0;\n private maskBlue = 0;\n private maskAlpha = 0;\n\n fileSize!: number;\n reserved!: number;\n offset!: number;\n headerSize!: number;\n width!: number;\n height!: number;\n planes!: number;\n bitPP!: number;\n compress!: number;\n rawSize!: number;\n hr!: number;\n vr!: number;\n colors!: number;\n importantColors!: number;\n palette?: BmpPaletteColor[];\n data!: Uint8Array;\n\n constructor(input: BmpBinaryInput, options: DecodeOptions = {}) {\n this.bytes = toUint8Array(input);\n this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);\n this.options = {\n treat16BitAs15BitAlpha: options.treat16BitAs15BitAlpha ?? false,\n toRGBA: options.toRGBA ?? false,\n };\n\n this.parseFileHeader();\n this.parseDibHeader();\n this.parsePalette();\n this.pos = this.offset;\n this.parseRGBA();\n this.transformToRgbaIfNeeded();\n }\n\n private ensureReadable(offset: number, size: number, context: string): void {\n if (offset < 0 || size < 0 || offset + size > this.bytes.length) {\n throw new Error(`BMP decode out-of-range while reading ${context}`);\n }\n }\n\n private readUInt8(offset = this.pos): number {\n this.ensureReadable(offset, 1, \"uint8\");\n if (offset === this.pos) this.pos += 1;\n return this.view.getUint8(offset);\n }\n\n private readUInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"uint16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getUint16(offset, true);\n }\n\n private readInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"int16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getInt16(offset, true);\n }\n\n private readUInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"uint32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getUint32(offset, true);\n }\n\n private readInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"int32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getInt32(offset, true);\n }\n\n private parseFileHeader(): void {\n this.ensureReadable(0, FILE_HEADER_SIZE, \"file header\");\n if (this.bytes[0] !== 0x42 || this.bytes[1] !== 0x4d) {\n throw new Error(\"Invalid BMP file signature\");\n }\n\n this.pos = 2;\n this.fileSize = this.readUInt32LE();\n this.reserved = this.readUInt32LE();\n this.offset = this.readUInt32LE();\n\n if (this.offset < FILE_HEADER_SIZE || this.offset > this.bytes.length) {\n throw new Error(`Invalid pixel data offset: ${this.offset}`);\n }\n }\n\n private parseDibHeader(): void {\n this.pos = this.dibStart;\n this.headerSize = this.readUInt32LE();\n if (this.headerSize < CORE_HEADER_SIZE) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n this.ensureReadable(this.dibStart, this.headerSize, \"DIB header\");\n\n if (this.headerSize === CORE_HEADER_SIZE) {\n this.parseCoreHeader();\n return;\n }\n\n if (this.headerSize < INFO_HEADER_MIN) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n\n this.parseInfoHeader();\n }\n\n private parseCoreHeader(): void {\n const width = this.readUInt16LE(this.dibStart + 4);\n const height = this.readUInt16LE(this.dibStart + 6);\n\n this.width = width;\n this.height = height;\n this.planes = this.readUInt16LE(this.dibStart + 8);\n this.bitPP = this.readUInt16LE(this.dibStart + 10);\n this.compress = 0;\n this.rawSize = 0;\n this.hr = 0;\n this.vr = 0;\n this.colors = 0;\n this.importantColors = 0;\n this.bottomUp = true;\n this.paletteEntrySize = 3;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n this.validateDimensions();\n }\n\n private parseInfoHeader(): void {\n const rawWidth = this.readInt32LE(this.dibStart + 4);\n const rawHeight = this.readInt32LE(this.dibStart + 8);\n\n this.width = rawWidth;\n this.height = rawHeight;\n this.planes = this.readUInt16LE(this.dibStart + 12);\n this.bitPP = this.readUInt16LE(this.dibStart + 14);\n this.compress = this.readUInt32LE(this.dibStart + 16);\n this.rawSize = this.readUInt32LE(this.dibStart + 20);\n this.hr = this.readUInt32LE(this.dibStart + 24);\n this.vr = this.readUInt32LE(this.dibStart + 28);\n this.colors = this.readUInt32LE(this.dibStart + 32);\n this.importantColors = this.readUInt32LE(this.dibStart + 36);\n this.paletteEntrySize = 4;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n if (this.height < 0) {\n this.height *= -1;\n this.bottomUp = false;\n }\n\n if (this.width < 0) {\n this.width *= -1;\n }\n\n if (this.bitPP === 16 && this.options.treat16BitAs15BitAlpha) {\n this.bitPP = 15;\n }\n\n this.validateDimensions();\n this.parseBitMasks();\n }\n\n private validateDimensions(): void {\n if (\n !Number.isInteger(this.width) ||\n !Number.isInteger(this.height) ||\n this.width <= 0 ||\n this.height <= 0\n ) {\n throw new Error(`Invalid BMP dimensions: ${this.width}x${this.height}`);\n }\n }\n\n private parseBitMasks(): void {\n if (\n !(this.bitPP === 16 || this.bitPP === 32) ||\n !(this.compress === 3 || this.compress === 6)\n ) {\n return;\n }\n\n const inHeaderMaskStart = this.dibStart + 40;\n const hasMasksInHeader = this.headerSize >= 52;\n const maskStart = hasMasksInHeader ? inHeaderMaskStart : this.externalMaskOffset;\n const maskCount = this.compress === 6 || this.headerSize >= 56 ? 4 : 3;\n this.ensureReadable(maskStart, maskCount * 4, \"bit masks\");\n\n this.maskRed = this.readUInt32LE(maskStart);\n this.maskGreen = this.readUInt32LE(maskStart + 4);\n this.maskBlue = this.readUInt32LE(maskStart + 8);\n this.maskAlpha = maskCount >= 4 ? this.readUInt32LE(maskStart + 12) : 0;\n\n if (!hasMasksInHeader) {\n this.externalMaskOffset += maskCount * 4;\n }\n }\n\n private parsePalette(): void {\n if (this.bitPP >= 16) {\n return;\n }\n\n const colorCount = this.colors === 0 ? 1 << this.bitPP : this.colors;\n if (colorCount <= 0) {\n return;\n }\n\n const paletteStart = this.externalMaskOffset;\n const paletteSize = colorCount * this.paletteEntrySize;\n if (paletteStart + paletteSize > this.offset) {\n throw new Error(\"Palette data overlaps or exceeds pixel data offset\");\n }\n\n this.palette = new Array(colorCount);\n for (let i = 0; i < colorCount; i += 1) {\n const base = paletteStart + i * this.paletteEntrySize;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const quad = this.paletteEntrySize === 4 ? this.readUInt8(base + 3) : 0;\n this.palette[i] = { red, green, blue, quad };\n }\n }\n\n private parseRGBA(): void {\n const pixelCount = this.width * this.height;\n const len = pixelCount * 4;\n this.data = new Uint8Array(len);\n\n switch (this.bitPP) {\n case 1:\n this.bit1();\n return;\n case 4:\n this.bit4();\n return;\n case 8:\n this.bit8();\n return;\n case 15:\n this.bit15();\n return;\n case 16:\n this.bit16();\n return;\n case 24:\n this.bit24();\n return;\n case 32:\n this.bit32();\n return;\n default:\n throw new Error(`Unsupported BMP bit depth: ${this.bitPP}`);\n }\n }\n\n private transformToRgbaIfNeeded(): void {\n if (!this.options.toRGBA) {\n return;\n }\n\n for (let i = 0; i < this.data.length; i += 4) {\n const alpha = this.data[i] ?? 0;\n const blue = this.data[i + 1] ?? 0;\n const green = this.data[i + 2] ?? 0;\n const red = this.data[i + 3] ?? 0;\n\n this.data[i] = red;\n this.data[i + 1] = green;\n this.data[i + 2] = blue;\n this.data[i + 3] = alpha;\n }\n }\n\n private getPaletteColor(index: number): BmpPaletteColor {\n const color = this.palette?.[index];\n if (color) {\n return color;\n }\n\n return { red: 0xff, green: 0xff, blue: 0xff, quad: 0x00 };\n }\n\n private setPixel(\n destY: number,\n x: number,\n alpha: number,\n blue: number,\n green: number,\n red: number,\n ): void {\n const base = (destY * this.width + x) * 4;\n this.data[base] = alpha;\n this.data[base + 1] = blue;\n this.data[base + 2] = green;\n this.data[base + 3] = red;\n }\n\n private bit1(): void {\n const stride = rowStride(this.width, 1);\n const bytesPerRow = Math.ceil(this.width / 8);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"1-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 8));\n const bit = (packed >> (7 - (x % 8))) & 0x01;\n const rgb = this.getPaletteColor(bit);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit4(): void {\n if (this.compress === 2) {\n this.bit4Rle();\n return;\n }\n\n const stride = rowStride(this.width, 4);\n const bytesPerRow = Math.ceil(this.width / 2);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"4-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 2));\n const idx = x % 2 === 0 ? (packed & 0xf0) >> 4 : packed & 0x0f;\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit8(): void {\n if (this.compress === 1) {\n this.bit8Rle();\n return;\n }\n\n const stride = rowStride(this.width, 8);\n const bytesPerRow = this.width;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"8-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const idx = this.readUInt8(rowStart + x);\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit15(): void {\n const stride = rowStride(this.width, 16);\n const max = 0b11111;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"15-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = (((value >> 0) & max) / max) * 255;\n const green = (((value >> 5) & max) / max) * 255;\n const red = (((value >> 10) & max) / max) * 255;\n const alpha = (value & 0x8000) !== 0 ? 0xff : 0x00;\n\n this.setPixel(destY, x, alpha, blue | 0, green | 0, red | 0);\n }\n }\n }\n\n private scaleMasked(value: number, mask: number): number {\n if (mask === 0) return 0;\n let shift = 0;\n let bits = 0;\n let m = mask;\n while ((m & 1) === 0) {\n shift += 1;\n m >>>= 1;\n }\n while ((m & 1) === 1) {\n bits += 1;\n m >>>= 1;\n }\n\n const component = (value & mask) >>> shift;\n if (bits >= 8) {\n return component >>> (bits - 8);\n }\n\n return (component << (8 - bits)) & 0xff;\n }\n\n private bit16(): void {\n if (this.maskRed === 0 && this.maskGreen === 0 && this.maskBlue === 0) {\n this.maskRed = 0x7c00;\n this.maskGreen = 0x03e0;\n this.maskBlue = 0x001f;\n }\n\n const stride = rowStride(this.width, 16);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"16-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = this.scaleMasked(value, this.maskBlue);\n const green = this.scaleMasked(value, this.maskGreen);\n const red = this.scaleMasked(value, this.maskRed);\n const alpha = this.maskAlpha !== 0 ? this.scaleMasked(value, this.maskAlpha) : 0xff;\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n\n private bit24(): void {\n const stride = rowStride(this.width, 24);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 3, \"24-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 3;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n this.setPixel(destY, x, 0xff, blue, green, red);\n }\n }\n }\n\n private bit32(): void {\n const stride = rowStride(this.width, 32);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 4, \"32-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 4;\n if (this.compress === 3 || this.compress === 6) {\n const pixel = this.readUInt32LE(base);\n const red = this.scaleMasked(pixel, this.maskRed || 0x00ff0000);\n const green = this.scaleMasked(pixel, this.maskGreen || 0x0000ff00);\n const blue = this.scaleMasked(pixel, this.maskBlue || 0x000000ff);\n const alpha = this.maskAlpha === 0 ? 0xff : this.scaleMasked(pixel, this.maskAlpha);\n this.setPixel(destY, x, alpha, blue, green, red);\n } else {\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const alpha = this.readUInt8(base + 3);\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n }\n\n private bit8Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n for (let i = 0; i < value; i += 1) {\n const idx = this.readUInt8();\n const rgb = this.getPaletteColor(idx);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n if ((value & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n const rgb = this.getPaletteColor(value);\n for (let i = 0; i < count; i += 1) {\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n private bit4Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n let current = this.readUInt8();\n for (let i = 0; i < value; i += 1) {\n const nibble = i % 2 === 0 ? (current & 0xf0) >> 4 : current & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n if (i % 2 === 1 && i + 1 < value) {\n current = this.readUInt8();\n }\n }\n if ((((value + 1) >> 1) & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n for (let i = 0; i < count; i += 1) {\n const nibble = i % 2 === 0 ? (value & 0xf0) >> 4 : value & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n getData(): Uint8Array {\n return this.data;\n }\n}\n\nexport function decode(bmpData: BmpBinaryInput, options?: DecodeOptions): DecodedBmp {\n return new BmpDecoder(bmpData, options);\n}\n\nexport { BmpDecoder };\n","import { assertInteger } from \"./binary\";\nimport type {\n BmpImageData,\n BmpPaletteColor,\n EncodeBitDepth,\n EncodeOptions,\n EncodedBmp,\n} from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_SIZE = 40;\nconst BYTES_PER_PIXEL_ABGR = 4;\nconst SUPPORTED_BIT_DEPTHS = [1, 4, 8, 16, 24, 32] as const;\n\ntype SupportedBitDepth = (typeof SUPPORTED_BIT_DEPTHS)[number];\ntype ResolvedEncodeOptions = Required<Pick<EncodeOptions, \"orientation\" | \"bitPP\">> & {\n palette: BmpPaletteColor[];\n};\n\nfunction isSupportedBitDepth(value: number): value is SupportedBitDepth {\n return (SUPPORTED_BIT_DEPTHS as readonly number[]).includes(value);\n}\n\nfunction normalizeEncodeOptions(qualityOrOptions?: number | EncodeOptions): ResolvedEncodeOptions {\n if (typeof qualityOrOptions === \"number\" || typeof qualityOrOptions === \"undefined\") {\n return {\n orientation: \"top-down\",\n bitPP: 24,\n palette: [],\n };\n }\n\n return {\n orientation: qualityOrOptions.orientation ?? \"top-down\",\n bitPP: qualityOrOptions.bitPP ?? 24,\n palette: qualityOrOptions.palette ?? [],\n };\n}\n\nclass BmpEncoder {\n private readonly pixelData: Uint8Array;\n private readonly width: number;\n private readonly height: number;\n private readonly options: ResolvedEncodeOptions;\n private readonly palette: BmpPaletteColor[];\n private readonly exactPaletteIndex = new Map<number, number>();\n\n constructor(imgData: BmpImageData, options: ResolvedEncodeOptions) {\n this.pixelData = imgData.data;\n this.width = imgData.width;\n this.height = imgData.height;\n this.options = options;\n this.palette = this.normalizePalette(options);\n\n assertInteger(\"width\", this.width);\n assertInteger(\"height\", this.height);\n\n if (!isSupportedBitDepth(this.options.bitPP)) {\n throw new Error(\n `Unsupported encode bit depth: ${this.options.bitPP}. Supported: 1, 4, 8, 16, 24, 32.`,\n );\n }\n\n const minLength = this.width * this.height * BYTES_PER_PIXEL_ABGR;\n if (this.pixelData.length < minLength) {\n throw new Error(\n `Image data is too short: expected at least ${minLength} bytes for ${this.width}x${this.height} ABGR data.`,\n );\n }\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const key = this.paletteKey(color.quad, color.blue, color.green, color.red);\n if (!this.exactPaletteIndex.has(key)) {\n this.exactPaletteIndex.set(key, i);\n }\n }\n }\n\n private normalizePalette(options: ResolvedEncodeOptions): BmpPaletteColor[] {\n if (options.bitPP === 1) {\n const palette = options.palette.length\n ? options.palette\n : [\n { red: 255, green: 255, blue: 255, quad: 0 },\n { red: 0, green: 0, blue: 0, quad: 0 },\n ];\n this.validatePalette(options.bitPP, palette);\n return palette;\n }\n\n if (options.bitPP === 4 || options.bitPP === 8) {\n if (options.palette.length === 0) {\n throw new Error(`Encoding ${options.bitPP}-bit BMP requires a non-empty palette.`);\n }\n this.validatePalette(options.bitPP, options.palette);\n return options.palette;\n }\n\n return [];\n }\n\n private validatePalette(bitPP: 1 | 4 | 8, palette: BmpPaletteColor[]): void {\n const maxSize = 1 << bitPP;\n if (palette.length === 0 || palette.length > maxSize) {\n throw new Error(\n `Palette size ${palette.length} is invalid for ${bitPP}-bit BMP. Expected 1..${maxSize}.`,\n );\n }\n\n for (const color of palette) {\n this.validateChannel(\"palette.red\", color.red);\n this.validateChannel(\"palette.green\", color.green);\n this.validateChannel(\"palette.blue\", color.blue);\n this.validateChannel(\"palette.quad\", color.quad);\n }\n }\n\n private validateChannel(name: string, value: number): void {\n if (!Number.isInteger(value) || value < 0 || value > 255) {\n throw new Error(`${name} must be an integer between 0 and 255.`);\n }\n }\n\n private rowStride(): number {\n return Math.floor((this.options.bitPP * this.width + 31) / 32) * 4;\n }\n\n private sourceY(fileRow: number): number {\n return this.options.orientation === \"top-down\" ? fileRow : this.height - 1 - fileRow;\n }\n\n private sourceOffset(x: number, y: number): number {\n return (y * this.width + x) * BYTES_PER_PIXEL_ABGR;\n }\n\n private paletteKey(alpha: number, blue: number, green: number, red: number): number {\n return (\n (((alpha & 0xff) << 24) | ((blue & 0xff) << 16) | ((green & 0xff) << 8) | (red & 0xff)) >>> 0\n );\n }\n\n private findPaletteIndex(a: number, b: number, g: number, r: number): number {\n const exact = this.exactPaletteIndex.get(this.paletteKey(a, b, g, r));\n if (exact !== undefined) {\n return exact;\n }\n\n let bestIndex = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const dr = color.red - r;\n const dg = color.green - g;\n const db = color.blue - b;\n const da = color.quad - a;\n const distance = dr * dr + dg * dg + db * db + da * da;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestIndex = i;\n }\n }\n\n return bestIndex;\n }\n\n private writePalette(output: Uint8Array, paletteOffset: number): void {\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const base = paletteOffset + i * 4;\n output[base] = color.blue;\n output[base + 1] = color.green;\n output[base + 2] = color.red;\n output[base + 3] = color.quad;\n }\n }\n\n private encode1Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 8) {\n let packed = 0;\n for (let bit = 0; bit < 8; bit += 1) {\n const px = x + bit;\n if (px >= this.width) {\n break;\n }\n const source = this.sourceOffset(px, srcY);\n const a = this.pixelData[source] ?? 0xff;\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n const idx = this.findPaletteIndex(a, b, g, r) & 0x01;\n packed |= idx << (7 - bit);\n }\n output[rowStart + Math.floor(x / 8)] = packed;\n }\n }\n }\n\n private encode4Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 2) {\n const sourceA = this.sourceOffset(x, srcY);\n const idxA = this.findPaletteIndex(\n this.pixelData[sourceA] ?? 0xff,\n this.pixelData[sourceA + 1] ?? 0,\n this.pixelData[sourceA + 2] ?? 0,\n this.pixelData[sourceA + 3] ?? 0,\n );\n\n let idxB = 0;\n if (x + 1 < this.width) {\n const sourceB = this.sourceOffset(x + 1, srcY);\n idxB = this.findPaletteIndex(\n this.pixelData[sourceB] ?? 0xff,\n this.pixelData[sourceB + 1] ?? 0,\n this.pixelData[sourceB + 2] ?? 0,\n this.pixelData[sourceB + 3] ?? 0,\n );\n }\n\n output[rowStart + Math.floor(x / 2)] = ((idxA & 0x0f) << 4) | (idxB & 0x0f);\n }\n }\n }\n\n private encode8Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n output[rowStart + x] = this.findPaletteIndex(\n this.pixelData[source] ?? 0xff,\n this.pixelData[source + 1] ?? 0,\n this.pixelData[source + 2] ?? 0,\n this.pixelData[source + 3] ?? 0,\n );\n }\n }\n }\n\n private encode16Bit(\n output: Uint8Array,\n view: DataView,\n pixelOffset: number,\n stride: number,\n ): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n\n const value = (((r >> 3) & 0x1f) << 10) | (((g >> 3) & 0x1f) << 5) | ((b >> 3) & 0x1f);\n view.setUint16(rowStart + x * 2, value, true);\n }\n }\n }\n\n private encode24Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 3;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n }\n }\n }\n\n private encode32Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 4;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n output[target + 3] = this.pixelData[source] ?? 0xff;\n }\n }\n }\n\n encode(): Uint8Array {\n const stride = this.rowStride();\n const imageSize = stride * this.height;\n const paletteSize = this.palette.length * 4;\n const offset = FILE_HEADER_SIZE + INFO_HEADER_SIZE + paletteSize;\n const totalSize = offset + imageSize;\n const output = new Uint8Array(totalSize);\n const view = new DataView(output.buffer, output.byteOffset, output.byteLength);\n\n // BITMAPFILEHEADER\n output[0] = 0x42; // B\n output[1] = 0x4d; // M\n view.setUint32(2, totalSize, true);\n view.setUint32(6, 0, true);\n view.setUint32(10, offset, true);\n\n // BITMAPINFOHEADER\n view.setUint32(14, INFO_HEADER_SIZE, true);\n view.setInt32(18, this.width, true);\n const signedHeight = this.options.orientation === \"top-down\" ? -this.height : this.height;\n view.setInt32(22, signedHeight, true);\n view.setUint16(26, 1, true);\n view.setUint16(28, this.options.bitPP, true);\n view.setUint32(30, 0, true);\n view.setUint32(34, imageSize, true);\n view.setUint32(38, 0, true);\n view.setUint32(42, 0, true);\n view.setUint32(46, this.palette.length, true);\n view.setUint32(50, 0, true);\n\n if (this.palette.length > 0) {\n this.writePalette(output, FILE_HEADER_SIZE + INFO_HEADER_SIZE);\n }\n\n switch (this.options.bitPP as EncodeBitDepth) {\n case 1:\n this.encode1Bit(output, offset, stride);\n break;\n case 4:\n this.encode4Bit(output, offset, stride);\n break;\n case 8:\n this.encode8Bit(output, offset, stride);\n break;\n case 16:\n this.encode16Bit(output, view, offset, stride);\n break;\n case 24:\n this.encode24Bit(output, offset, stride);\n break;\n case 32:\n this.encode32Bit(output, offset, stride);\n break;\n }\n\n return output;\n }\n}\n\nexport function encode(\n imgData: BmpImageData,\n qualityOrOptions?: number | EncodeOptions,\n): EncodedBmp {\n const options = normalizeEncodeOptions(qualityOrOptions);\n const encoder = new BmpEncoder(imgData, options);\n const data = encoder.encode();\n\n return {\n data,\n width: imgData.width,\n height: imgData.height,\n };\n}\n\nexport { BmpEncoder };\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8B;;;ACEvB,SAAS,aAAa,OAAmC;AAC9D,MAAI,iBAAiB,aAAa;AAChC,WAAO,IAAI,WAAW,KAAK;AAAA,EAC7B;AAEA,SAAO,IAAI,WAAW,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;AACxE;AAEO,SAAS,cAAc,MAAc,OAAqB;AAC/D,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG;AAC1C,UAAM,IAAI,MAAM,GAAG,IAAI,6BAA6B;AAAA,EACtD;AACF;;;ACXA,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAEzB,SAAS,UAAU,OAAe,OAAuB;AACvD,SAAO,KAAK,OAAO,QAAQ,QAAQ,MAAM,EAAE,IAAI;AACjD;AAEA,IAAM,aAAN,MAAuC;AAAA,EAC7B,MAAM;AAAA,EACG;AAAA,EACA;AAAA,EACA;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EAErB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AAAA,EAEpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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zC,wBAAsB,eAAe,MAAM;AAE3C,MAAI,aAAa,KAAK,aAAa,GAAG;AACpC,UAAM,IAAI;AAAA,MACR,8BAA8B,QAAQ;AAAA,IACxC;AAAA,EACF;AAEA,QAAM,iBAAiB,QAAQ,SAAS;AACxC,MAAI,KAAK,WAAW,gBAAgB;AAClC,UAAM,IAAI;AAAA,MACR,wCAAwC,cAAc,cAAc,KAAK,MAAM;AAAA,IACjF;AAAA,EACF;AAEA,QAAM,WAAW,kBAAkB,UAAU,QAAQ,QAAQ;AAC7D,QAAM,gBAA+B;AAAA,IACnC,OAAO;AAAA,IACP,aAAa,QAAQ,UAAU,aAAa;AAAA,EAC9C;AAEA,MAAI,QAAQ,SAAS;AACnB,kBAAc,UAAU,QAAQ;AAAA,EAClC;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM,WAAW,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF,EAAE;AACJ;","names":["rgb","FILE_HEADER_SIZE","require","toUint8Array"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sharp/index.ts","../../src/binary.ts","../../src/decoder.ts","../../src/encoder.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n PixelSource,\n SharpInstance,\n SharpFromBmpOptions,\n SharpModule,\n SharpRawDescriptor,\n SharpRawFlatLike,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: PixelSource): Uint8Array {\n if (ArrayBuffer.isView(input)) {\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nfunction normalizeSharpFromBmpArgs(\n inputOrOptions: DecodeForSharpInput | SharpFromBmpOptions,\n sharpModule?: SharpModule,\n): { input: DecodeForSharpInput; sharpModule?: SharpModule } {\n if (typeof inputOrOptions === \"object\" && inputOrOptions !== null && \"input\" in inputOrOptions) {\n const options = inputOrOptions as SharpFromBmpOptions;\n const resolvedSharpModule = sharpModule ?? options.sharp;\n\n if (resolvedSharpModule) {\n return {\n input: options.input,\n sharpModule: resolvedSharpModule,\n };\n }\n\n return {\n input: options.input,\n };\n }\n\n if (sharpModule) {\n return {\n input: inputOrOptions as DecodeForSharpInput,\n sharpModule,\n };\n }\n\n return {\n input: inputOrOptions as DecodeForSharpInput,\n };\n}\n\nfunction normalizeEncodeFromSharpArgs(\n inputOrData: SharpRawLike | SharpRawFlatLike | PixelSource,\n infoOrOptions?: SharpRawInfo | EncodeBmpOptions,\n maybeOptions?: EncodeBmpOptions,\n): { data: Uint8Array; info: SharpRawInfo; options: EncodeBmpOptions } {\n if (\n typeof inputOrData === \"object\" &&\n inputOrData !== null &&\n \"data\" in inputOrData &&\n \"info\" in inputOrData\n ) {\n const payload = inputOrData as SharpRawLike;\n return {\n data: toUint8Array(payload.data),\n info: payload.info,\n options: (infoOrOptions as EncodeBmpOptions | undefined) ?? {},\n };\n }\n\n if (\n typeof inputOrData === \"object\" &&\n inputOrData !== null &&\n \"data\" in inputOrData &&\n \"width\" in inputOrData &&\n \"height\" in inputOrData &&\n \"channels\" in inputOrData\n ) {\n const payload = inputOrData as SharpRawFlatLike;\n const info: SharpRawInfo = {\n width: payload.width,\n height: payload.height,\n channels: payload.channels,\n };\n\n if (payload.premultiplied !== undefined) {\n info.premultiplied = payload.premultiplied;\n }\n\n return {\n data: toUint8Array(payload.data),\n info,\n options: (infoOrOptions as EncodeBmpOptions | undefined) ?? {},\n };\n }\n\n if (\n typeof infoOrOptions === \"object\" &&\n infoOrOptions !== null &&\n \"width\" in infoOrOptions &&\n \"height\" in infoOrOptions &&\n \"channels\" in infoOrOptions\n ) {\n return {\n data: toUint8Array(inputOrData as PixelSource),\n info: infoOrOptions as SharpRawInfo,\n options: maybeOptions ?? {},\n };\n }\n\n throw new InvalidSharpRawInputError(\n \"Invalid encodeFromSharp input. Expected { data, info }, { data, width, height, channels }, or (data, info).\",\n );\n}\n\nexport function isBmp(input: unknown): input is BmpSharpInput {\n try {\n const bytes = toUint8Array(input as BmpSharpInput);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n info: raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\n/**\n * @deprecated Use decodeForSharp instead.\n */\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;\nexport function sharpFromBmp(options: SharpFromBmpOptions): SharpInstance;\nexport function sharpFromBmp(\n inputOrOptions: DecodeForSharpInput | SharpFromBmpOptions,\n sharpModule?: SharpModule,\n): SharpInstance {\n const normalized = normalizeSharpFromBmpArgs(inputOrOptions, sharpModule);\n const decoded = decodeForSharp(normalized.input);\n const sharp = loadSharpModule(normalized.sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;\nexport function encodeFromSharp(input: SharpRawFlatLike, options?: EncodeBmpOptions): Uint8Array;\nexport function encodeFromSharp(\n data: PixelSource,\n info: SharpRawInfo,\n options?: EncodeBmpOptions,\n): Uint8Array;\nexport function encodeFromSharp(\n inputOrData: SharpRawLike | SharpRawFlatLike | PixelSource,\n infoOrOptions?: SharpRawInfo | EncodeBmpOptions,\n maybeOptions?: EncodeBmpOptions,\n): Uint8Array {\n const normalized = normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions);\n const data = normalized.data;\n const width = normalized.info.width;\n const height = normalized.info.height;\n const channels = normalized.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, normalized.options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: normalized.options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (normalized.options.palette) {\n encodeOptions.palette = normalized.options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n PixelSource,\n SharpInstance,\n SharpFromBmpOptions,\n SharpModule,\n SharpRawFlatLike,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","import type { BmpBinaryInput } from \"./types\";\n\nexport function toUint8Array(input: BmpBinaryInput): Uint8Array {\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input);\n }\n\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n}\n\nexport function assertInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n}\n","import { toUint8Array } from \"./binary\";\nimport type { BmpBinaryInput, BmpPaletteColor, DecodeOptions, DecodedBmp } from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_MIN = 40;\nconst CORE_HEADER_SIZE = 12;\n\nfunction rowStride(width: number, bitPP: number): number {\n return Math.floor((bitPP * width + 31) / 32) * 4;\n}\n\nclass BmpDecoder implements DecodedBmp {\n private pos = 0;\n private readonly bytes: Uint8Array;\n private readonly view: DataView;\n private readonly options: Required<DecodeOptions>;\n private bottomUp = true;\n private dibStart = FILE_HEADER_SIZE;\n private paletteEntrySize = 4;\n private externalMaskOffset = 0;\n\n private maskRed = 0;\n private maskGreen = 0;\n private maskBlue = 0;\n private maskAlpha = 0;\n\n fileSize!: number;\n reserved!: number;\n offset!: number;\n headerSize!: number;\n width!: number;\n height!: number;\n planes!: number;\n bitPP!: number;\n compress!: number;\n rawSize!: number;\n hr!: number;\n vr!: number;\n colors!: number;\n importantColors!: number;\n palette?: BmpPaletteColor[];\n data!: Uint8Array;\n\n constructor(input: BmpBinaryInput, options: DecodeOptions = {}) {\n this.bytes = toUint8Array(input);\n this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);\n this.options = {\n treat16BitAs15BitAlpha: options.treat16BitAs15BitAlpha ?? false,\n toRGBA: options.toRGBA ?? false,\n };\n\n this.parseFileHeader();\n this.parseDibHeader();\n this.parsePalette();\n this.pos = this.offset;\n this.parseRGBA();\n this.transformToRgbaIfNeeded();\n }\n\n private ensureReadable(offset: number, size: number, context: string): void {\n if (offset < 0 || size < 0 || offset + size > this.bytes.length) {\n throw new Error(`BMP decode out-of-range while reading ${context}`);\n }\n }\n\n private readUInt8(offset = this.pos): number {\n this.ensureReadable(offset, 1, \"uint8\");\n if (offset === this.pos) this.pos += 1;\n return this.view.getUint8(offset);\n }\n\n private readUInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"uint16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getUint16(offset, true);\n }\n\n private readInt16LE(offset = this.pos): number {\n this.ensureReadable(offset, 2, \"int16\");\n if (offset === this.pos) this.pos += 2;\n return this.view.getInt16(offset, true);\n }\n\n private readUInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"uint32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getUint32(offset, true);\n }\n\n private readInt32LE(offset = this.pos): number {\n this.ensureReadable(offset, 4, \"int32\");\n if (offset === this.pos) this.pos += 4;\n return this.view.getInt32(offset, true);\n }\n\n private parseFileHeader(): void {\n this.ensureReadable(0, FILE_HEADER_SIZE, \"file header\");\n if (this.bytes[0] !== 0x42 || this.bytes[1] !== 0x4d) {\n throw new Error(\"Invalid BMP file signature\");\n }\n\n this.pos = 2;\n this.fileSize = this.readUInt32LE();\n this.reserved = this.readUInt32LE();\n this.offset = this.readUInt32LE();\n\n if (this.offset < FILE_HEADER_SIZE || this.offset > this.bytes.length) {\n throw new Error(`Invalid pixel data offset: ${this.offset}`);\n }\n }\n\n private parseDibHeader(): void {\n this.pos = this.dibStart;\n this.headerSize = this.readUInt32LE();\n if (this.headerSize < CORE_HEADER_SIZE) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n this.ensureReadable(this.dibStart, this.headerSize, \"DIB header\");\n\n if (this.headerSize === CORE_HEADER_SIZE) {\n this.parseCoreHeader();\n return;\n }\n\n if (this.headerSize < INFO_HEADER_MIN) {\n throw new Error(`Unsupported DIB header size: ${this.headerSize}`);\n }\n\n this.parseInfoHeader();\n }\n\n private parseCoreHeader(): void {\n const width = this.readUInt16LE(this.dibStart + 4);\n const height = this.readUInt16LE(this.dibStart + 6);\n\n this.width = width;\n this.height = height;\n this.planes = this.readUInt16LE(this.dibStart + 8);\n this.bitPP = this.readUInt16LE(this.dibStart + 10);\n this.compress = 0;\n this.rawSize = 0;\n this.hr = 0;\n this.vr = 0;\n this.colors = 0;\n this.importantColors = 0;\n this.bottomUp = true;\n this.paletteEntrySize = 3;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n this.validateDimensions();\n }\n\n private parseInfoHeader(): void {\n const rawWidth = this.readInt32LE(this.dibStart + 4);\n const rawHeight = this.readInt32LE(this.dibStart + 8);\n\n this.width = rawWidth;\n this.height = rawHeight;\n this.planes = this.readUInt16LE(this.dibStart + 12);\n this.bitPP = this.readUInt16LE(this.dibStart + 14);\n this.compress = this.readUInt32LE(this.dibStart + 16);\n this.rawSize = this.readUInt32LE(this.dibStart + 20);\n this.hr = this.readUInt32LE(this.dibStart + 24);\n this.vr = this.readUInt32LE(this.dibStart + 28);\n this.colors = this.readUInt32LE(this.dibStart + 32);\n this.importantColors = this.readUInt32LE(this.dibStart + 36);\n this.paletteEntrySize = 4;\n this.externalMaskOffset = this.dibStart + this.headerSize;\n\n if (this.height < 0) {\n this.height *= -1;\n this.bottomUp = false;\n }\n\n if (this.width < 0) {\n this.width *= -1;\n }\n\n if (this.bitPP === 16 && this.options.treat16BitAs15BitAlpha) {\n this.bitPP = 15;\n }\n\n this.validateDimensions();\n this.parseBitMasks();\n }\n\n private validateDimensions(): void {\n if (\n !Number.isInteger(this.width) ||\n !Number.isInteger(this.height) ||\n this.width <= 0 ||\n this.height <= 0\n ) {\n throw new Error(`Invalid BMP dimensions: ${this.width}x${this.height}`);\n }\n }\n\n private parseBitMasks(): void {\n if (\n !(this.bitPP === 16 || this.bitPP === 32) ||\n !(this.compress === 3 || this.compress === 6)\n ) {\n return;\n }\n\n const inHeaderMaskStart = this.dibStart + 40;\n const hasMasksInHeader = this.headerSize >= 52;\n const maskStart = hasMasksInHeader ? inHeaderMaskStart : this.externalMaskOffset;\n const maskCount = this.compress === 6 || this.headerSize >= 56 ? 4 : 3;\n this.ensureReadable(maskStart, maskCount * 4, \"bit masks\");\n\n this.maskRed = this.readUInt32LE(maskStart);\n this.maskGreen = this.readUInt32LE(maskStart + 4);\n this.maskBlue = this.readUInt32LE(maskStart + 8);\n this.maskAlpha = maskCount >= 4 ? this.readUInt32LE(maskStart + 12) : 0;\n\n if (!hasMasksInHeader) {\n this.externalMaskOffset += maskCount * 4;\n }\n }\n\n private parsePalette(): void {\n if (this.bitPP >= 16) {\n return;\n }\n\n const colorCount = this.colors === 0 ? 1 << this.bitPP : this.colors;\n if (colorCount <= 0) {\n return;\n }\n\n const paletteStart = this.externalMaskOffset;\n const paletteSize = colorCount * this.paletteEntrySize;\n if (paletteStart + paletteSize > this.offset) {\n throw new Error(\"Palette data overlaps or exceeds pixel data offset\");\n }\n\n this.palette = new Array(colorCount);\n for (let i = 0; i < colorCount; i += 1) {\n const base = paletteStart + i * this.paletteEntrySize;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const quad = this.paletteEntrySize === 4 ? this.readUInt8(base + 3) : 0;\n this.palette[i] = { red, green, blue, quad };\n }\n }\n\n private parseRGBA(): void {\n const pixelCount = this.width * this.height;\n const len = pixelCount * 4;\n this.data = new Uint8Array(len);\n\n switch (this.bitPP) {\n case 1:\n this.bit1();\n return;\n case 4:\n this.bit4();\n return;\n case 8:\n this.bit8();\n return;\n case 15:\n this.bit15();\n return;\n case 16:\n this.bit16();\n return;\n case 24:\n this.bit24();\n return;\n case 32:\n this.bit32();\n return;\n default:\n throw new Error(`Unsupported BMP bit depth: ${this.bitPP}`);\n }\n }\n\n private transformToRgbaIfNeeded(): void {\n if (!this.options.toRGBA) {\n return;\n }\n\n for (let i = 0; i < this.data.length; i += 4) {\n const alpha = this.data[i] ?? 0;\n const blue = this.data[i + 1] ?? 0;\n const green = this.data[i + 2] ?? 0;\n const red = this.data[i + 3] ?? 0;\n\n this.data[i] = red;\n this.data[i + 1] = green;\n this.data[i + 2] = blue;\n this.data[i + 3] = alpha;\n }\n }\n\n private getPaletteColor(index: number): BmpPaletteColor {\n const color = this.palette?.[index];\n if (color) {\n return color;\n }\n\n return { red: 0xff, green: 0xff, blue: 0xff, quad: 0x00 };\n }\n\n private setPixel(\n destY: number,\n x: number,\n alpha: number,\n blue: number,\n green: number,\n red: number,\n ): void {\n const base = (destY * this.width + x) * 4;\n this.data[base] = alpha;\n this.data[base + 1] = blue;\n this.data[base + 2] = green;\n this.data[base + 3] = red;\n }\n\n private bit1(): void {\n const stride = rowStride(this.width, 1);\n const bytesPerRow = Math.ceil(this.width / 8);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"1-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 8));\n const bit = (packed >> (7 - (x % 8))) & 0x01;\n const rgb = this.getPaletteColor(bit);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit4(): void {\n if (this.compress === 2) {\n this.bit4Rle();\n return;\n }\n\n const stride = rowStride(this.width, 4);\n const bytesPerRow = Math.ceil(this.width / 2);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"4-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const packed = this.readUInt8(rowStart + Math.floor(x / 2));\n const idx = x % 2 === 0 ? (packed & 0xf0) >> 4 : packed & 0x0f;\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit8(): void {\n if (this.compress === 1) {\n this.bit8Rle();\n return;\n }\n\n const stride = rowStride(this.width, 8);\n const bytesPerRow = this.width;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, bytesPerRow, \"8-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const idx = this.readUInt8(rowStart + x);\n const rgb = this.getPaletteColor(idx);\n this.setPixel(destY, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n }\n }\n\n private bit15(): void {\n const stride = rowStride(this.width, 16);\n const max = 0b11111;\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"15-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = (((value >> 0) & max) / max) * 255;\n const green = (((value >> 5) & max) / max) * 255;\n const red = (((value >> 10) & max) / max) * 255;\n const alpha = (value & 0x8000) !== 0 ? 0xff : 0x00;\n\n this.setPixel(destY, x, alpha, blue | 0, green | 0, red | 0);\n }\n }\n }\n\n private scaleMasked(value: number, mask: number): number {\n if (mask === 0) return 0;\n let shift = 0;\n let bits = 0;\n let m = mask;\n while ((m & 1) === 0) {\n shift += 1;\n m >>>= 1;\n }\n while ((m & 1) === 1) {\n bits += 1;\n m >>>= 1;\n }\n\n const component = (value & mask) >>> shift;\n if (bits >= 8) {\n return component >>> (bits - 8);\n }\n\n return (component << (8 - bits)) & 0xff;\n }\n\n private bit16(): void {\n if (this.maskRed === 0 && this.maskGreen === 0 && this.maskBlue === 0) {\n this.maskRed = 0x7c00;\n this.maskGreen = 0x03e0;\n this.maskBlue = 0x001f;\n }\n\n const stride = rowStride(this.width, 16);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 2, \"16-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const value = this.readUInt16LE(rowStart + x * 2);\n const blue = this.scaleMasked(value, this.maskBlue);\n const green = this.scaleMasked(value, this.maskGreen);\n const red = this.scaleMasked(value, this.maskRed);\n const alpha = this.maskAlpha !== 0 ? this.scaleMasked(value, this.maskAlpha) : 0xff;\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n\n private bit24(): void {\n const stride = rowStride(this.width, 24);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 3, \"24-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 3;\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n this.setPixel(destY, x, 0xff, blue, green, red);\n }\n }\n }\n\n private bit32(): void {\n const stride = rowStride(this.width, 32);\n\n for (let srcRow = 0; srcRow < this.height; srcRow += 1) {\n const rowStart = this.offset + srcRow * stride;\n this.ensureReadable(rowStart, this.width * 4, \"32-bit row\");\n const destY = this.bottomUp ? this.height - 1 - srcRow : srcRow;\n\n for (let x = 0; x < this.width; x += 1) {\n const base = rowStart + x * 4;\n if (this.compress === 3 || this.compress === 6) {\n const pixel = this.readUInt32LE(base);\n const red = this.scaleMasked(pixel, this.maskRed || 0x00ff0000);\n const green = this.scaleMasked(pixel, this.maskGreen || 0x0000ff00);\n const blue = this.scaleMasked(pixel, this.maskBlue || 0x000000ff);\n const alpha = this.maskAlpha === 0 ? 0xff : this.scaleMasked(pixel, this.maskAlpha);\n this.setPixel(destY, x, alpha, blue, green, red);\n } else {\n const blue = this.readUInt8(base);\n const green = this.readUInt8(base + 1);\n const red = this.readUInt8(base + 2);\n const alpha = this.readUInt8(base + 3);\n this.setPixel(destY, x, alpha, blue, green, red);\n }\n }\n }\n }\n\n private bit8Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n for (let i = 0; i < value; i += 1) {\n const idx = this.readUInt8();\n const rgb = this.getPaletteColor(idx);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n if ((value & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n const rgb = this.getPaletteColor(value);\n for (let i = 0; i < count; i += 1) {\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n private bit4Rle(): void {\n this.data.fill(0xff);\n this.pos = this.offset;\n let x = 0;\n let y = this.bottomUp ? this.height - 1 : 0;\n\n while (this.pos < this.bytes.length) {\n const count = this.readUInt8();\n const value = this.readUInt8();\n\n if (count === 0) {\n if (value === 0) {\n x = 0;\n y += this.bottomUp ? -1 : 1;\n continue;\n }\n if (value === 1) {\n break;\n }\n if (value === 2) {\n x += this.readUInt8();\n y += this.bottomUp ? -this.readUInt8() : this.readUInt8();\n continue;\n }\n\n let current = this.readUInt8();\n for (let i = 0; i < value; i += 1) {\n const nibble = i % 2 === 0 ? (current & 0xf0) >> 4 : current & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n if (i % 2 === 1 && i + 1 < value) {\n current = this.readUInt8();\n }\n }\n if ((((value + 1) >> 1) & 1) === 1) {\n this.pos += 1;\n }\n continue;\n }\n\n for (let i = 0; i < count; i += 1) {\n const nibble = i % 2 === 0 ? (value & 0xf0) >> 4 : value & 0x0f;\n const rgb = this.getPaletteColor(nibble);\n if (x < this.width && y >= 0 && y < this.height) {\n this.setPixel(y, x, 0xff, rgb.blue, rgb.green, rgb.red);\n }\n x += 1;\n }\n }\n }\n\n getData(): Uint8Array {\n return this.data;\n }\n}\n\nexport function decode(bmpData: BmpBinaryInput, options?: DecodeOptions): DecodedBmp {\n return new BmpDecoder(bmpData, options);\n}\n\nexport { BmpDecoder };\n","import { assertInteger } from \"./binary\";\nimport type {\n BmpImageData,\n BmpPaletteColor,\n EncodeBitDepth,\n EncodeOptions,\n EncodedBmp,\n} from \"./types\";\n\nconst FILE_HEADER_SIZE = 14;\nconst INFO_HEADER_SIZE = 40;\nconst BYTES_PER_PIXEL_ABGR = 4;\nconst SUPPORTED_BIT_DEPTHS = [1, 4, 8, 16, 24, 32] as const;\n\ntype SupportedBitDepth = (typeof SUPPORTED_BIT_DEPTHS)[number];\ntype ResolvedEncodeOptions = Required<Pick<EncodeOptions, \"orientation\" | \"bitPP\">> & {\n palette: BmpPaletteColor[];\n};\n\nfunction isSupportedBitDepth(value: number): value is SupportedBitDepth {\n return (SUPPORTED_BIT_DEPTHS as readonly number[]).includes(value);\n}\n\nfunction normalizeEncodeOptions(qualityOrOptions?: number | EncodeOptions): ResolvedEncodeOptions {\n if (typeof qualityOrOptions === \"number\" || typeof qualityOrOptions === \"undefined\") {\n return {\n orientation: \"top-down\",\n bitPP: 24,\n palette: [],\n };\n }\n\n return {\n orientation: qualityOrOptions.orientation ?? \"top-down\",\n bitPP: qualityOrOptions.bitPP ?? 24,\n palette: qualityOrOptions.palette ?? [],\n };\n}\n\nclass BmpEncoder {\n private readonly pixelData: Uint8Array;\n private readonly width: number;\n private readonly height: number;\n private readonly options: ResolvedEncodeOptions;\n private readonly palette: BmpPaletteColor[];\n private readonly exactPaletteIndex = new Map<number, number>();\n\n constructor(imgData: BmpImageData, options: ResolvedEncodeOptions) {\n this.pixelData = imgData.data;\n this.width = imgData.width;\n this.height = imgData.height;\n this.options = options;\n this.palette = this.normalizePalette(options);\n\n assertInteger(\"width\", this.width);\n assertInteger(\"height\", this.height);\n\n if (!isSupportedBitDepth(this.options.bitPP)) {\n throw new Error(\n `Unsupported encode bit depth: ${this.options.bitPP}. Supported: 1, 4, 8, 16, 24, 32.`,\n );\n }\n\n const minLength = this.width * this.height * BYTES_PER_PIXEL_ABGR;\n if (this.pixelData.length < minLength) {\n throw new Error(\n `Image data is too short: expected at least ${minLength} bytes for ${this.width}x${this.height} ABGR data.`,\n );\n }\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const key = this.paletteKey(color.quad, color.blue, color.green, color.red);\n if (!this.exactPaletteIndex.has(key)) {\n this.exactPaletteIndex.set(key, i);\n }\n }\n }\n\n private normalizePalette(options: ResolvedEncodeOptions): BmpPaletteColor[] {\n if (options.bitPP === 1) {\n const palette = options.palette.length\n ? options.palette\n : [\n { red: 255, green: 255, blue: 255, quad: 0 },\n { red: 0, green: 0, blue: 0, quad: 0 },\n ];\n this.validatePalette(options.bitPP, palette);\n return palette;\n }\n\n if (options.bitPP === 4 || options.bitPP === 8) {\n if (options.palette.length === 0) {\n throw new Error(`Encoding ${options.bitPP}-bit BMP requires a non-empty palette.`);\n }\n this.validatePalette(options.bitPP, options.palette);\n return options.palette;\n }\n\n return [];\n }\n\n private validatePalette(bitPP: 1 | 4 | 8, palette: BmpPaletteColor[]): void {\n const maxSize = 1 << bitPP;\n if (palette.length === 0 || palette.length > maxSize) {\n throw new Error(\n `Palette size ${palette.length} is invalid for ${bitPP}-bit BMP. Expected 1..${maxSize}.`,\n );\n }\n\n for (const color of palette) {\n this.validateChannel(\"palette.red\", color.red);\n this.validateChannel(\"palette.green\", color.green);\n this.validateChannel(\"palette.blue\", color.blue);\n this.validateChannel(\"palette.quad\", color.quad);\n }\n }\n\n private validateChannel(name: string, value: number): void {\n if (!Number.isInteger(value) || value < 0 || value > 255) {\n throw new Error(`${name} must be an integer between 0 and 255.`);\n }\n }\n\n private rowStride(): number {\n return Math.floor((this.options.bitPP * this.width + 31) / 32) * 4;\n }\n\n private sourceY(fileRow: number): number {\n return this.options.orientation === \"top-down\" ? fileRow : this.height - 1 - fileRow;\n }\n\n private sourceOffset(x: number, y: number): number {\n return (y * this.width + x) * BYTES_PER_PIXEL_ABGR;\n }\n\n private paletteKey(alpha: number, blue: number, green: number, red: number): number {\n return (\n (((alpha & 0xff) << 24) | ((blue & 0xff) << 16) | ((green & 0xff) << 8) | (red & 0xff)) >>> 0\n );\n }\n\n private findPaletteIndex(a: number, b: number, g: number, r: number): number {\n const exact = this.exactPaletteIndex.get(this.paletteKey(a, b, g, r));\n if (exact !== undefined) {\n return exact;\n }\n\n let bestIndex = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const dr = color.red - r;\n const dg = color.green - g;\n const db = color.blue - b;\n const da = color.quad - a;\n const distance = dr * dr + dg * dg + db * db + da * da;\n if (distance < bestDistance) {\n bestDistance = distance;\n bestIndex = i;\n }\n }\n\n return bestIndex;\n }\n\n private writePalette(output: Uint8Array, paletteOffset: number): void {\n for (let i = 0; i < this.palette.length; i += 1) {\n const color = this.palette[i]!;\n const base = paletteOffset + i * 4;\n output[base] = color.blue;\n output[base + 1] = color.green;\n output[base + 2] = color.red;\n output[base + 3] = color.quad;\n }\n }\n\n private encode1Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 8) {\n let packed = 0;\n for (let bit = 0; bit < 8; bit += 1) {\n const px = x + bit;\n if (px >= this.width) {\n break;\n }\n const source = this.sourceOffset(px, srcY);\n const a = this.pixelData[source] ?? 0xff;\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n const idx = this.findPaletteIndex(a, b, g, r) & 0x01;\n packed |= idx << (7 - bit);\n }\n output[rowStart + Math.floor(x / 8)] = packed;\n }\n }\n }\n\n private encode4Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 2) {\n const sourceA = this.sourceOffset(x, srcY);\n const idxA = this.findPaletteIndex(\n this.pixelData[sourceA] ?? 0xff,\n this.pixelData[sourceA + 1] ?? 0,\n this.pixelData[sourceA + 2] ?? 0,\n this.pixelData[sourceA + 3] ?? 0,\n );\n\n let idxB = 0;\n if (x + 1 < this.width) {\n const sourceB = this.sourceOffset(x + 1, srcY);\n idxB = this.findPaletteIndex(\n this.pixelData[sourceB] ?? 0xff,\n this.pixelData[sourceB + 1] ?? 0,\n this.pixelData[sourceB + 2] ?? 0,\n this.pixelData[sourceB + 3] ?? 0,\n );\n }\n\n output[rowStart + Math.floor(x / 2)] = ((idxA & 0x0f) << 4) | (idxB & 0x0f);\n }\n }\n }\n\n private encode8Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n output[rowStart + x] = this.findPaletteIndex(\n this.pixelData[source] ?? 0xff,\n this.pixelData[source + 1] ?? 0,\n this.pixelData[source + 2] ?? 0,\n this.pixelData[source + 3] ?? 0,\n );\n }\n }\n }\n\n private encode16Bit(\n output: Uint8Array,\n view: DataView,\n pixelOffset: number,\n stride: number,\n ): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const b = this.pixelData[source + 1] ?? 0;\n const g = this.pixelData[source + 2] ?? 0;\n const r = this.pixelData[source + 3] ?? 0;\n\n const value = (((r >> 3) & 0x1f) << 10) | (((g >> 3) & 0x1f) << 5) | ((b >> 3) & 0x1f);\n view.setUint16(rowStart + x * 2, value, true);\n }\n }\n }\n\n private encode24Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 3;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n }\n }\n }\n\n private encode32Bit(output: Uint8Array, pixelOffset: number, stride: number): void {\n for (let fileRow = 0; fileRow < this.height; fileRow += 1) {\n const srcY = this.sourceY(fileRow);\n const rowStart = pixelOffset + fileRow * stride;\n\n for (let x = 0; x < this.width; x += 1) {\n const source = this.sourceOffset(x, srcY);\n const target = rowStart + x * 4;\n\n output[target] = this.pixelData[source + 1] ?? 0;\n output[target + 1] = this.pixelData[source + 2] ?? 0;\n output[target + 2] = this.pixelData[source + 3] ?? 0;\n output[target + 3] = this.pixelData[source] ?? 0xff;\n }\n }\n }\n\n encode(): Uint8Array {\n const stride = this.rowStride();\n const imageSize = stride * this.height;\n const paletteSize = this.palette.length * 4;\n const offset = FILE_HEADER_SIZE + INFO_HEADER_SIZE + paletteSize;\n const totalSize = offset + imageSize;\n const output = new Uint8Array(totalSize);\n const view = new DataView(output.buffer, output.byteOffset, output.byteLength);\n\n // BITMAPFILEHEADER\n output[0] = 0x42; // B\n output[1] = 0x4d; // M\n view.setUint32(2, totalSize, true);\n view.setUint32(6, 0, true);\n view.setUint32(10, offset, true);\n\n // BITMAPINFOHEADER\n view.setUint32(14, INFO_HEADER_SIZE, true);\n view.setInt32(18, this.width, true);\n const signedHeight = this.options.orientation === \"top-down\" ? -this.height : this.height;\n view.setInt32(22, signedHeight, true);\n view.setUint16(26, 1, true);\n view.setUint16(28, this.options.bitPP, true);\n view.setUint32(30, 0, true);\n view.setUint32(34, imageSize, true);\n view.setUint32(38, 0, true);\n view.setUint32(42, 0, true);\n view.setUint32(46, this.palette.length, true);\n view.setUint32(50, 0, true);\n\n if (this.palette.length > 0) {\n this.writePalette(output, FILE_HEADER_SIZE + INFO_HEADER_SIZE);\n }\n\n switch (this.options.bitPP as EncodeBitDepth) {\n case 1:\n this.encode1Bit(output, offset, stride);\n break;\n case 4:\n this.encode4Bit(output, offset, stride);\n break;\n case 8:\n this.encode8Bit(output, offset, stride);\n break;\n case 16:\n this.encode16Bit(output, view, offset, stride);\n break;\n case 24:\n this.encode24Bit(output, offset, stride);\n break;\n case 32:\n this.encode32Bit(output, offset, stride);\n break;\n }\n\n return output;\n }\n}\n\nexport function encode(\n imgData: BmpImageData,\n qualityOrOptions?: number | EncodeOptions,\n): EncodedBmp {\n const options = normalizeEncodeOptions(qualityOrOptions);\n const encoder = new BmpEncoder(imgData, options);\n const data = encoder.encode();\n\n return {\n data,\n width: imgData.width,\n height: imgData.height,\n };\n}\n\nexport { BmpEncoder };\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8B;;;ACEvB,SAAS,aAAa,OAAmC;AAC9D,MAAI,iBAAiB,aAAa;AAChC,WAAO,IAAI,WAAW,KAAK;AAAA,EAC7B;AAEA,SAAO,IAAI,WAAW,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;AACxE;AAEO,SAAS,cAAc,MAAc,OAAqB;AAC/D,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS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AC7C;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM,WAAW,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF,EAAE;AACJ;","names":["rgb","FILE_HEADER_SIZE","require","toUint8Array"]}
|
package/dist/sharp/index.d.cts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import * as sharp from 'sharp';
|
|
2
2
|
import { e as EncodeBitDepth, B as BmpPaletteColor } from '../types-CzYgOtEn.cjs';
|
|
3
3
|
|
|
4
|
+
type PixelSource = Uint8Array | ArrayBufferLike | ArrayBufferView;
|
|
5
|
+
type SharpRawChannels = 3 | 4;
|
|
4
6
|
interface SharpRawDescriptor {
|
|
5
7
|
width: number;
|
|
6
8
|
height: number;
|
|
7
|
-
channels:
|
|
9
|
+
channels: SharpRawChannels;
|
|
10
|
+
premultiplied?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SharpRgbaInfo {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
channels: 4;
|
|
8
16
|
premultiplied?: boolean;
|
|
9
17
|
}
|
|
10
18
|
interface DecodedSharpInput {
|
|
11
19
|
data: Uint8Array;
|
|
12
|
-
raw:
|
|
13
|
-
|
|
14
|
-
};
|
|
20
|
+
raw: SharpRgbaInfo;
|
|
21
|
+
info: SharpRgbaInfo;
|
|
15
22
|
width: number;
|
|
16
23
|
height: number;
|
|
17
24
|
channels: 4;
|
|
@@ -23,16 +30,27 @@ interface SharpRawInfo {
|
|
|
23
30
|
premultiplied?: boolean;
|
|
24
31
|
}
|
|
25
32
|
interface SharpRawLike {
|
|
26
|
-
data:
|
|
33
|
+
data: PixelSource;
|
|
27
34
|
info: SharpRawInfo;
|
|
28
35
|
}
|
|
36
|
+
interface SharpRawFlatLike {
|
|
37
|
+
data: PixelSource;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
channels: number;
|
|
41
|
+
premultiplied?: boolean;
|
|
42
|
+
}
|
|
29
43
|
interface EncodeBmpOptions {
|
|
30
44
|
bitDepth?: EncodeBitDepth;
|
|
31
45
|
topDown?: boolean;
|
|
32
46
|
palette?: BmpPaletteColor[];
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
interface SharpFromBmpOptions {
|
|
49
|
+
input: PixelSource;
|
|
50
|
+
sharp?: SharpModule;
|
|
51
|
+
}
|
|
52
|
+
type BmpSharpInput = PixelSource;
|
|
53
|
+
type DecodeForSharpInput = PixelSource;
|
|
36
54
|
type SharpModule = typeof sharp;
|
|
37
55
|
type SharpInstance = sharp.Sharp;
|
|
38
56
|
|
|
@@ -49,10 +67,16 @@ declare class InvalidSharpRawInputError extends SharpAdapterError {
|
|
|
49
67
|
constructor(message: string);
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
declare function isBmp(input:
|
|
70
|
+
declare function isBmp(input: unknown): input is BmpSharpInput;
|
|
53
71
|
declare function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use decodeForSharp instead.
|
|
74
|
+
*/
|
|
54
75
|
declare function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput;
|
|
55
76
|
declare function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;
|
|
77
|
+
declare function sharpFromBmp(options: SharpFromBmpOptions): SharpInstance;
|
|
56
78
|
declare function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;
|
|
79
|
+
declare function encodeFromSharp(input: SharpRawFlatLike, options?: EncodeBmpOptions): Uint8Array;
|
|
80
|
+
declare function encodeFromSharp(data: PixelSource, info: SharpRawInfo, options?: EncodeBmpOptions): Uint8Array;
|
|
57
81
|
|
|
58
|
-
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, SharpAdapterError, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
|
82
|
+
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, type PixelSource, SharpAdapterError, type SharpFromBmpOptions, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawFlatLike, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
package/dist/sharp/index.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import * as sharp from 'sharp';
|
|
2
2
|
import { e as EncodeBitDepth, B as BmpPaletteColor } from '../types-CzYgOtEn.js';
|
|
3
3
|
|
|
4
|
+
type PixelSource = Uint8Array | ArrayBufferLike | ArrayBufferView;
|
|
5
|
+
type SharpRawChannels = 3 | 4;
|
|
4
6
|
interface SharpRawDescriptor {
|
|
5
7
|
width: number;
|
|
6
8
|
height: number;
|
|
7
|
-
channels:
|
|
9
|
+
channels: SharpRawChannels;
|
|
10
|
+
premultiplied?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SharpRgbaInfo {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
channels: 4;
|
|
8
16
|
premultiplied?: boolean;
|
|
9
17
|
}
|
|
10
18
|
interface DecodedSharpInput {
|
|
11
19
|
data: Uint8Array;
|
|
12
|
-
raw:
|
|
13
|
-
|
|
14
|
-
};
|
|
20
|
+
raw: SharpRgbaInfo;
|
|
21
|
+
info: SharpRgbaInfo;
|
|
15
22
|
width: number;
|
|
16
23
|
height: number;
|
|
17
24
|
channels: 4;
|
|
@@ -23,16 +30,27 @@ interface SharpRawInfo {
|
|
|
23
30
|
premultiplied?: boolean;
|
|
24
31
|
}
|
|
25
32
|
interface SharpRawLike {
|
|
26
|
-
data:
|
|
33
|
+
data: PixelSource;
|
|
27
34
|
info: SharpRawInfo;
|
|
28
35
|
}
|
|
36
|
+
interface SharpRawFlatLike {
|
|
37
|
+
data: PixelSource;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
channels: number;
|
|
41
|
+
premultiplied?: boolean;
|
|
42
|
+
}
|
|
29
43
|
interface EncodeBmpOptions {
|
|
30
44
|
bitDepth?: EncodeBitDepth;
|
|
31
45
|
topDown?: boolean;
|
|
32
46
|
palette?: BmpPaletteColor[];
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
interface SharpFromBmpOptions {
|
|
49
|
+
input: PixelSource;
|
|
50
|
+
sharp?: SharpModule;
|
|
51
|
+
}
|
|
52
|
+
type BmpSharpInput = PixelSource;
|
|
53
|
+
type DecodeForSharpInput = PixelSource;
|
|
36
54
|
type SharpModule = typeof sharp;
|
|
37
55
|
type SharpInstance = sharp.Sharp;
|
|
38
56
|
|
|
@@ -49,10 +67,16 @@ declare class InvalidSharpRawInputError extends SharpAdapterError {
|
|
|
49
67
|
constructor(message: string);
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
declare function isBmp(input:
|
|
70
|
+
declare function isBmp(input: unknown): input is BmpSharpInput;
|
|
53
71
|
declare function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use decodeForSharp instead.
|
|
74
|
+
*/
|
|
54
75
|
declare function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput;
|
|
55
76
|
declare function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;
|
|
77
|
+
declare function sharpFromBmp(options: SharpFromBmpOptions): SharpInstance;
|
|
56
78
|
declare function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;
|
|
79
|
+
declare function encodeFromSharp(input: SharpRawFlatLike, options?: EncodeBmpOptions): Uint8Array;
|
|
80
|
+
declare function encodeFromSharp(data: PixelSource, info: SharpRawInfo, options?: EncodeBmpOptions): Uint8Array;
|
|
57
81
|
|
|
58
|
-
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, SharpAdapterError, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
|
82
|
+
export { type BmpSharpInput, type DecodeForSharpInput, type DecodedSharpInput, type EncodeBmpOptions, InvalidSharpRawInputError, NotBmpInputError, type PixelSource, SharpAdapterError, type SharpFromBmpOptions, type SharpInstance, type SharpModule, SharpModuleLoadError, type SharpRawDescriptor, type SharpRawFlatLike, type SharpRawInfo, type SharpRawLike, decodeForSharp, encodeFromSharp, isBmp, sharpFromBmp, toSharpInput };
|
package/dist/sharp/index.js
CHANGED
|
@@ -37,8 +37,8 @@ var require2 = createRequire(
|
|
|
37
37
|
typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`
|
|
38
38
|
);
|
|
39
39
|
function toUint8Array(input) {
|
|
40
|
-
if (input
|
|
41
|
-
return input;
|
|
40
|
+
if (ArrayBuffer.isView(input)) {
|
|
41
|
+
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
42
42
|
}
|
|
43
43
|
return new Uint8Array(input);
|
|
44
44
|
}
|
|
@@ -88,6 +88,66 @@ function normalizeBitDepth(channels, bitDepth) {
|
|
|
88
88
|
}
|
|
89
89
|
return channels === 4 ? 32 : 24;
|
|
90
90
|
}
|
|
91
|
+
function normalizeSharpFromBmpArgs(inputOrOptions, sharpModule) {
|
|
92
|
+
if (typeof inputOrOptions === "object" && inputOrOptions !== null && "input" in inputOrOptions) {
|
|
93
|
+
const options = inputOrOptions;
|
|
94
|
+
const resolvedSharpModule = sharpModule ?? options.sharp;
|
|
95
|
+
if (resolvedSharpModule) {
|
|
96
|
+
return {
|
|
97
|
+
input: options.input,
|
|
98
|
+
sharpModule: resolvedSharpModule
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
input: options.input
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (sharpModule) {
|
|
106
|
+
return {
|
|
107
|
+
input: inputOrOptions,
|
|
108
|
+
sharpModule
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
input: inputOrOptions
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions) {
|
|
116
|
+
if (typeof inputOrData === "object" && inputOrData !== null && "data" in inputOrData && "info" in inputOrData) {
|
|
117
|
+
const payload = inputOrData;
|
|
118
|
+
return {
|
|
119
|
+
data: toUint8Array(payload.data),
|
|
120
|
+
info: payload.info,
|
|
121
|
+
options: infoOrOptions ?? {}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (typeof inputOrData === "object" && inputOrData !== null && "data" in inputOrData && "width" in inputOrData && "height" in inputOrData && "channels" in inputOrData) {
|
|
125
|
+
const payload = inputOrData;
|
|
126
|
+
const info = {
|
|
127
|
+
width: payload.width,
|
|
128
|
+
height: payload.height,
|
|
129
|
+
channels: payload.channels
|
|
130
|
+
};
|
|
131
|
+
if (payload.premultiplied !== void 0) {
|
|
132
|
+
info.premultiplied = payload.premultiplied;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
data: toUint8Array(payload.data),
|
|
136
|
+
info,
|
|
137
|
+
options: infoOrOptions ?? {}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (typeof infoOrOptions === "object" && infoOrOptions !== null && "width" in infoOrOptions && "height" in infoOrOptions && "channels" in infoOrOptions) {
|
|
141
|
+
return {
|
|
142
|
+
data: toUint8Array(inputOrData),
|
|
143
|
+
info: infoOrOptions,
|
|
144
|
+
options: maybeOptions ?? {}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
throw new InvalidSharpRawInputError(
|
|
148
|
+
"Invalid encodeFromSharp input. Expected { data, info }, { data, width, height, channels }, or (data, info)."
|
|
149
|
+
);
|
|
150
|
+
}
|
|
91
151
|
function isBmp(input) {
|
|
92
152
|
try {
|
|
93
153
|
const bytes = toUint8Array(input);
|
|
@@ -110,6 +170,7 @@ function decodeForSharp(input) {
|
|
|
110
170
|
return {
|
|
111
171
|
data: decoded.data,
|
|
112
172
|
raw,
|
|
173
|
+
info: raw,
|
|
113
174
|
width: decoded.width,
|
|
114
175
|
height: decoded.height,
|
|
115
176
|
channels: 4
|
|
@@ -118,16 +179,18 @@ function decodeForSharp(input) {
|
|
|
118
179
|
function toSharpInput(input) {
|
|
119
180
|
return decodeForSharp(input);
|
|
120
181
|
}
|
|
121
|
-
function sharpFromBmp(
|
|
122
|
-
const
|
|
123
|
-
const
|
|
182
|
+
function sharpFromBmp(inputOrOptions, sharpModule) {
|
|
183
|
+
const normalized = normalizeSharpFromBmpArgs(inputOrOptions, sharpModule);
|
|
184
|
+
const decoded = decodeForSharp(normalized.input);
|
|
185
|
+
const sharp = loadSharpModule(normalized.sharpModule);
|
|
124
186
|
return sharp(decoded.data, { raw: decoded.raw });
|
|
125
187
|
}
|
|
126
|
-
function encodeFromSharp(
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const
|
|
188
|
+
function encodeFromSharp(inputOrData, infoOrOptions, maybeOptions) {
|
|
189
|
+
const normalized = normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions);
|
|
190
|
+
const data = normalized.data;
|
|
191
|
+
const width = normalized.info.width;
|
|
192
|
+
const height = normalized.info.height;
|
|
193
|
+
const channels = normalized.info.channels;
|
|
131
194
|
assertPositiveInteger("info.width", width);
|
|
132
195
|
assertPositiveInteger("info.height", height);
|
|
133
196
|
if (channels !== 3 && channels !== 4) {
|
|
@@ -141,13 +204,13 @@ function encodeFromSharp(input, options = {}) {
|
|
|
141
204
|
`Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`
|
|
142
205
|
);
|
|
143
206
|
}
|
|
144
|
-
const bitDepth = normalizeBitDepth(channels, options.bitDepth);
|
|
207
|
+
const bitDepth = normalizeBitDepth(channels, normalized.options.bitDepth);
|
|
145
208
|
const encodeOptions = {
|
|
146
209
|
bitPP: bitDepth,
|
|
147
|
-
orientation: options.topDown ? "top-down" : "bottom-up"
|
|
210
|
+
orientation: normalized.options.topDown ? "top-down" : "bottom-up"
|
|
148
211
|
};
|
|
149
|
-
if (options.palette) {
|
|
150
|
-
encodeOptions.palette = options.palette;
|
|
212
|
+
if (normalized.options.palette) {
|
|
213
|
+
encodeOptions.palette = normalized.options.palette;
|
|
151
214
|
}
|
|
152
215
|
return encode(
|
|
153
216
|
{
|
package/dist/sharp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sharp/index.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: DecodeForSharpInput | BmpSharpInput): Uint8Array {\n if (input instanceof Uint8Array) {\n return input;\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nexport function isBmp(input: BmpSharpInput): boolean {\n try {\n const bytes = toUint8Array(input);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance {\n const decoded = decodeForSharp(input);\n const sharp = loadSharpModule(sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options: EncodeBmpOptions = {}): Uint8Array {\n const data = toUint8Array(input.data);\n const width = input.info.width;\n const height = input.info.height;\n const channels = input.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (options.palette) {\n encodeOptions.palette = options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n SharpInstance,\n SharpModule,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,qBAAqB;;;ACAvB,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,kBAAkB;AAAA,EACtD,cAAc;AACZ,UAAM,0BAA0B;AAChC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,uBAAN,cAAmC,kBAAkB;AAAA,EAC1D,YACE,UAAU,0FACV;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,4BAAN,cAAwC,kBAAkB;AAAA,EAC/D,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADVA,IAAMA,WAAU;AAAA,EACd,OAAO,eAAe,WAAW,aAAa,GAAG,QAAQ,IAAI,CAAC;AAChE;AAEA,SAAS,aAAa,OAAwD;AAC5E,MAAI,iBAAiB,YAAY;AAC/B,WAAO;AAAA,EACT;AAEA,SAAO,IAAI,WAAW,KAAK;AAC7B;AAEA,SAAS,WAAW,OAAmB,UAA6B;AAClE,QAAM,aAAa,KAAK,MAAM,MAAM,SAAS,QAAQ;AACrD,QAAM,SAAS,IAAI,WAAW,aAAa,CAAC;AAE5C,WAAS,MAAM,GAAG,MAAM,GAAG,MAAM,MAAM,QAAQ,OAAO,UAAU,OAAO,GAAG;AACxE,UAAM,MAAM,MAAM,GAAG,KAAK;AAC1B,UAAM,QAAQ,MAAM,MAAM,CAAC,KAAK;AAChC,UAAM,OAAO,MAAM,MAAM,CAAC,KAAK;AAC/B,UAAM,QAAQ,aAAa,IAAK,MAAM,MAAM,CAAC,KAAK,MAAQ;AAE1D,WAAO,GAAG,IAAI;AACd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../../src/sharp/index.ts","../../src/sharp/errors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { decode } from \"../decoder\";\nimport { encode } from \"../encoder\";\nimport type { EncodeOptions } from \"../types\";\nimport { InvalidSharpRawInputError, NotBmpInputError, SharpModuleLoadError } from \"./errors\";\nimport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n PixelSource,\n SharpInstance,\n SharpFromBmpOptions,\n SharpModule,\n SharpRawDescriptor,\n SharpRawFlatLike,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n\nconst require = createRequire(\n typeof __filename === \"string\" ? __filename : `${process.cwd()}/package.json`,\n);\n\nfunction toUint8Array(input: PixelSource): Uint8Array {\n if (ArrayBuffer.isView(input)) {\n return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n }\n\n return new Uint8Array(input);\n}\n\nfunction toAbgrData(input: Uint8Array, channels: 3 | 4): Uint8Array {\n const pixelCount = Math.floor(input.length / channels);\n const output = new Uint8Array(pixelCount * 4);\n\n for (let src = 0, dst = 0; src < input.length; src += channels, dst += 4) {\n const red = input[src] ?? 0;\n const green = input[src + 1] ?? 0;\n const blue = input[src + 2] ?? 0;\n const alpha = channels === 4 ? (input[src + 3] ?? 0xff) : 0xff;\n\n output[dst] = alpha;\n output[dst + 1] = blue;\n output[dst + 2] = green;\n output[dst + 3] = red;\n }\n\n return output;\n}\n\nfunction loadSharpModule(sharpModule?: SharpModule): SharpModule {\n if (sharpModule) {\n return sharpModule;\n }\n\n try {\n const loaded = require(\"sharp\") as SharpModule | { default?: SharpModule };\n\n if (typeof loaded === \"function\") {\n return loaded;\n }\n\n if (loaded.default && typeof loaded.default === \"function\") {\n return loaded.default;\n }\n\n throw new SharpModuleLoadError(\"Loaded 'sharp' module has an unexpected shape.\");\n } catch (error) {\n if (error instanceof SharpModuleLoadError) {\n throw error;\n }\n\n throw new SharpModuleLoadError();\n }\n}\n\nfunction assertPositiveInteger(name: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n throw new InvalidSharpRawInputError(`${name} must be a positive integer.`);\n }\n}\n\nfunction normalizeBitDepth(\n channels: 3 | 4,\n bitDepth?: EncodeBmpOptions[\"bitDepth\"],\n): 1 | 4 | 8 | 16 | 24 | 32 {\n if (bitDepth !== undefined) {\n return bitDepth;\n }\n\n return channels === 4 ? 32 : 24;\n}\n\nfunction normalizeSharpFromBmpArgs(\n inputOrOptions: DecodeForSharpInput | SharpFromBmpOptions,\n sharpModule?: SharpModule,\n): { input: DecodeForSharpInput; sharpModule?: SharpModule } {\n if (typeof inputOrOptions === \"object\" && inputOrOptions !== null && \"input\" in inputOrOptions) {\n const options = inputOrOptions as SharpFromBmpOptions;\n const resolvedSharpModule = sharpModule ?? options.sharp;\n\n if (resolvedSharpModule) {\n return {\n input: options.input,\n sharpModule: resolvedSharpModule,\n };\n }\n\n return {\n input: options.input,\n };\n }\n\n if (sharpModule) {\n return {\n input: inputOrOptions as DecodeForSharpInput,\n sharpModule,\n };\n }\n\n return {\n input: inputOrOptions as DecodeForSharpInput,\n };\n}\n\nfunction normalizeEncodeFromSharpArgs(\n inputOrData: SharpRawLike | SharpRawFlatLike | PixelSource,\n infoOrOptions?: SharpRawInfo | EncodeBmpOptions,\n maybeOptions?: EncodeBmpOptions,\n): { data: Uint8Array; info: SharpRawInfo; options: EncodeBmpOptions } {\n if (\n typeof inputOrData === \"object\" &&\n inputOrData !== null &&\n \"data\" in inputOrData &&\n \"info\" in inputOrData\n ) {\n const payload = inputOrData as SharpRawLike;\n return {\n data: toUint8Array(payload.data),\n info: payload.info,\n options: (infoOrOptions as EncodeBmpOptions | undefined) ?? {},\n };\n }\n\n if (\n typeof inputOrData === \"object\" &&\n inputOrData !== null &&\n \"data\" in inputOrData &&\n \"width\" in inputOrData &&\n \"height\" in inputOrData &&\n \"channels\" in inputOrData\n ) {\n const payload = inputOrData as SharpRawFlatLike;\n const info: SharpRawInfo = {\n width: payload.width,\n height: payload.height,\n channels: payload.channels,\n };\n\n if (payload.premultiplied !== undefined) {\n info.premultiplied = payload.premultiplied;\n }\n\n return {\n data: toUint8Array(payload.data),\n info,\n options: (infoOrOptions as EncodeBmpOptions | undefined) ?? {},\n };\n }\n\n if (\n typeof infoOrOptions === \"object\" &&\n infoOrOptions !== null &&\n \"width\" in infoOrOptions &&\n \"height\" in infoOrOptions &&\n \"channels\" in infoOrOptions\n ) {\n return {\n data: toUint8Array(inputOrData as PixelSource),\n info: infoOrOptions as SharpRawInfo,\n options: maybeOptions ?? {},\n };\n }\n\n throw new InvalidSharpRawInputError(\n \"Invalid encodeFromSharp input. Expected { data, info }, { data, width, height, channels }, or (data, info).\",\n );\n}\n\nexport function isBmp(input: unknown): input is BmpSharpInput {\n try {\n const bytes = toUint8Array(input as BmpSharpInput);\n return bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d;\n } catch {\n return false;\n }\n}\n\nexport function decodeForSharp(input: DecodeForSharpInput): DecodedSharpInput {\n const bytes = toUint8Array(input);\n\n if (!isBmp(bytes)) {\n throw new NotBmpInputError();\n }\n\n const decoded = decode(bytes, { toRGBA: true });\n const raw: SharpRawDescriptor & { channels: 4 } = {\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n\n return {\n data: decoded.data,\n raw,\n info: raw,\n width: decoded.width,\n height: decoded.height,\n channels: 4,\n };\n}\n\n/**\n * @deprecated Use decodeForSharp instead.\n */\nexport function toSharpInput(input: DecodeForSharpInput): DecodedSharpInput {\n return decodeForSharp(input);\n}\n\nexport function sharpFromBmp(input: DecodeForSharpInput, sharpModule?: SharpModule): SharpInstance;\nexport function sharpFromBmp(options: SharpFromBmpOptions): SharpInstance;\nexport function sharpFromBmp(\n inputOrOptions: DecodeForSharpInput | SharpFromBmpOptions,\n sharpModule?: SharpModule,\n): SharpInstance {\n const normalized = normalizeSharpFromBmpArgs(inputOrOptions, sharpModule);\n const decoded = decodeForSharp(normalized.input);\n const sharp = loadSharpModule(normalized.sharpModule) as unknown as (\n inputData: Uint8Array,\n options: { raw: SharpRawDescriptor },\n ) => SharpInstance;\n\n return sharp(decoded.data, { raw: decoded.raw });\n}\n\nexport function encodeFromSharp(input: SharpRawLike, options?: EncodeBmpOptions): Uint8Array;\nexport function encodeFromSharp(input: SharpRawFlatLike, options?: EncodeBmpOptions): Uint8Array;\nexport function encodeFromSharp(\n data: PixelSource,\n info: SharpRawInfo,\n options?: EncodeBmpOptions,\n): Uint8Array;\nexport function encodeFromSharp(\n inputOrData: SharpRawLike | SharpRawFlatLike | PixelSource,\n infoOrOptions?: SharpRawInfo | EncodeBmpOptions,\n maybeOptions?: EncodeBmpOptions,\n): Uint8Array {\n const normalized = normalizeEncodeFromSharpArgs(inputOrData, infoOrOptions, maybeOptions);\n const data = normalized.data;\n const width = normalized.info.width;\n const height = normalized.info.height;\n const channels = normalized.info.channels;\n\n assertPositiveInteger(\"info.width\", width);\n assertPositiveInteger(\"info.height\", height);\n\n if (channels !== 3 && channels !== 4) {\n throw new InvalidSharpRawInputError(\n `Unsupported channel count: ${channels}. Expected channels to be 3 or 4.`,\n );\n }\n\n const expectedLength = width * height * channels;\n if (data.length !== expectedLength) {\n throw new InvalidSharpRawInputError(\n `Raw buffer length mismatch: expected ${expectedLength}, received ${data.length}.`,\n );\n }\n\n const bitDepth = normalizeBitDepth(channels, normalized.options.bitDepth);\n const encodeOptions: EncodeOptions = {\n bitPP: bitDepth,\n orientation: normalized.options.topDown ? \"top-down\" : \"bottom-up\",\n };\n\n if (normalized.options.palette) {\n encodeOptions.palette = normalized.options.palette;\n }\n\n return encode(\n {\n data: toAbgrData(data, channels),\n width,\n height,\n },\n encodeOptions,\n ).data;\n}\n\nexport {\n InvalidSharpRawInputError,\n NotBmpInputError,\n SharpAdapterError,\n SharpModuleLoadError,\n} from \"./errors\";\nexport type {\n BmpSharpInput,\n DecodeForSharpInput,\n DecodedSharpInput,\n EncodeBmpOptions,\n PixelSource,\n SharpInstance,\n SharpFromBmpOptions,\n SharpModule,\n SharpRawFlatLike,\n SharpRawDescriptor,\n SharpRawInfo,\n SharpRawLike,\n} from \"./types\";\n","export class SharpAdapterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SharpAdapterError\";\n }\n}\n\nexport class NotBmpInputError extends SharpAdapterError {\n constructor() {\n super(\"Input is not a BMP file.\");\n this.name = \"NotBmpInputError\";\n }\n}\n\nexport class SharpModuleLoadError extends SharpAdapterError {\n constructor(\n message = \"Unable to load optional peer dependency 'sharp'. Install it or pass a module instance.\",\n ) {\n super(message);\n this.name = \"SharpModuleLoadError\";\n }\n}\n\nexport class InvalidSharpRawInputError extends SharpAdapterError {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidSharpRawInputError\";\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,qBAAqB;;;ACAvB,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,kBAAkB;AAAA,EACtD,cAAc;AACZ,UAAM,0BAA0B;AAChC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,uBAAN,cAAmC,kBAAkB;AAAA,EAC1D,YACE,UAAU,0FACV;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,4BAAN,cAAwC,kBAAkB;AAAA,EAC/D,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADPA,IAAMA,WAAU;AAAA,EACd,OAAO,eAAe,WAAW,aAAa,GAAG,QAAQ,IAAI,CAAC;AAChE;AAEA,SAAS,aAAa,OAAgC;AACpD,MAAI,YAAY,OAAO,KAAK,GAAG;AAC7B,WAAO,IAAI,WAAW,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;AAAA,EACxE;AAEA,SAAO,IAAI,WAAW,KAAK;AAC7B;AAEA,SAAS,WAAW,OAAmB,UA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