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)

125 lines 3.38 kB
import { TgaImageType, TgaImageTypeLength } from './tga-image-type.js'; export class TgaInfo { constructor() { this._numFrames = 1; this._backgroundColor = undefined; this._idLength = 0; this._colorMapType = 0; this._imageType = TgaImageType.none; this._colorMapOrigin = 0; this._colorMapLength = 0; this._colorMapDepth = 0; this._offsetX = 0; this._offsetY = 0; this._width = 0; this._height = 0; this._pixelDepth = 0; this._flags = 0; this._screenOrigin = 0; this._imageOffset = 0; } get numFrames() { return this._numFrames; } get backgroundColor() { return this._backgroundColor; } get idLength() { return this._idLength; } get colorMapType() { return this._colorMapType; } get imageType() { return this._imageType; } get colorMapOrigin() { return this._colorMapOrigin; } get colorMapLength() { return this._colorMapLength; } get colorMapDepth() { return this._colorMapDepth; } get offsetX() { return this._offsetX; } get offsetY() { return this._offsetY; } get width() { return this._width; } get height() { return this._height; } get pixelDepth() { return this._pixelDepth; } get flags() { return this._flags; } get colorMap() { return this._colorMap; } set colorMap(v) { this._colorMap = v; } get screenOrigin() { return this._screenOrigin; } get imageOffset() { return this._imageOffset; } set imageOffset(v) { this._imageOffset = v; } get hasColorMap() { return (this._imageType === TgaImageType.palette || this._imageType === TgaImageType.paletteRle); } read(header) { if (header.length < 18) { return; } this._idLength = header.read(); this._colorMapType = header.read(); const it = header.read(); this._imageType = it < TgaImageTypeLength ? it : TgaImageType.none; this._colorMapOrigin = header.readUint16(); this._colorMapLength = header.readUint16(); this._colorMapDepth = header.read(); this._offsetX = header.readUint16(); this._offsetY = header.readUint16(); this._width = header.readUint16(); this._height = header.readUint16(); this._pixelDepth = header.read(); this._flags = header.read(); this._screenOrigin = (this._flags & 0x30) >>> 4; } isValid() { if (this._pixelDepth !== 8 && this._pixelDepth !== 16 && this._pixelDepth !== 24 && this._pixelDepth !== 32) { return false; } if (this.hasColorMap) { if (this._colorMapLength > 256 || this._colorMapType !== 1) { return false; } if (this._colorMapDepth !== 16 && this._colorMapDepth !== 24 && this._colorMapDepth !== 32) { return false; } } else if (this._colorMapType === 1) { return false; } return true; } } //# sourceMappingURL=tga-info.js.map