UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

36 lines 1.03 kB
import { decode } from 'fast-bmp'; import { Image } from "../Image.js"; import { Mask } from "../Mask.js"; /** * Decode a BMP. See the fast-bmp npm module. * @param data - The data to decode. * @returns The decoded image or mask. */ export function decodeBmp(data) { const decodedData = decode(data); if (decodedData.bitsPerPixel === 1) { const mask = new Mask(decodedData.width, decodedData.height, { data: decodedData.data, }); return mask.convertColor('GREY'); } else { let colorModel; switch (decodedData.channels) { case 1: colorModel = 'GREY'; break; case 3: colorModel = 'RGB'; break; default: colorModel = 'RGBA'; break; } return new Image(decodedData.width, decodedData.height, { colorModel, data: decodedData.data, }); } } //# sourceMappingURL=decodeBmp.js.map