UNPKG

image-in-browser

Version:

Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)

66 lines 2.05 kB
import { OutputBuffer } from '../common/output-buffer.js'; import { LibError } from '../error/lib-error.js'; import { PngEncoder } from './png-encoder.js'; export class WinEncoder { constructor() { this._type = 0; this._supportsAnimation = true; } get type() { return this._type; } get supportsAnimation() { return this._supportsAnimation; } colorPlanesOrXHotSpot(_index) { return 0; } bitsPerPixelOrYHotSpot(_index) { return 0; } encode(opt) { var _a; const image = opt.image; const singleFrame = (_a = opt.singleFrame) !== null && _a !== void 0 ? _a : false; if (image.hasAnimation && !singleFrame) { return this.encodeImages(image.frames); } else { return this.encodeImages([image]); } } encodeImages(images) { const count = images.length; const out = new OutputBuffer(); out.writeUint16(0); out.writeUint16(this._type); out.writeUint16(count); let offset = 6 + count * 16; const imageDataList = []; let i = 0; for (const img of images) { if (img.width > 256 || img.height > 256) { throw new LibError('ICO and CUR support only sizes until 256'); } out.writeByte(img.width); out.writeByte(img.height); out.writeByte(0); out.writeByte(0); out.writeUint16(this.colorPlanesOrXHotSpot(i)); out.writeUint16(this.bitsPerPixelOrYHotSpot(i)); const data = new PngEncoder().encode({ image: img, }); out.writeUint32(data.length); out.writeUint32(offset); offset += data.length; i++; imageDataList.push(data); } for (const imageData of imageDataList) { out.writeBytes(imageData); } return out.getBytes(); } } //# sourceMappingURL=win-encoder.js.map