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)
44 lines • 1.33 kB
JavaScript
import { InputBuffer } from '../common/input-buffer.js';
import { LibError } from '../error/lib-error.js';
import { ImageFormat } from './image-format.js';
import { JpegData } from './jpeg/jpeg-data.js';
export class JpegDecoder {
get format() {
return ImageFormat.jpg;
}
get numFrames() {
return this._info !== undefined ? this._info.numFrames : 0;
}
isValidFile(bytes) {
return new JpegData().validate(bytes);
}
startDecode(bytes) {
this._input = new InputBuffer({
buffer: bytes,
bigEndian: true,
});
this._info = new JpegData().readInfo(bytes);
return this._info;
}
decodeFrame(_) {
if (this._input === undefined) {
return undefined;
}
const jpeg = new JpegData();
jpeg.read(this._input.buffer);
if (jpeg.frames.length !== 1) {
throw new LibError('Only single frame JPEGs supported.');
}
return jpeg.getImage();
}
decode(opt) {
const bytes = opt.bytes;
const jpeg = new JpegData();
jpeg.read(bytes);
if (jpeg.frames.length !== 1) {
throw new LibError('Only single frame JPEGs supported.');
}
return jpeg.getImage();
}
}
//# sourceMappingURL=jpeg-decoder.js.map