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)
57 lines • 1.75 kB
JavaScript
import { FrameType } from '../image/frame-type.js';
import { ImageFormat } from './image-format.js';
import { PsdImage } from './psd/psd-image.js';
export class PsdDecoder {
get info() {
return this._info;
}
get format() {
return ImageFormat.psd;
}
get numFrames() {
var _a, _b;
return (_b = (_a = this._info) === null || _a === void 0 ? void 0 : _a.numFrames) !== null && _b !== void 0 ? _b : 0;
}
decodePsd(bytes) {
const psd = new PsdImage(bytes);
return psd.decode() ? psd : undefined;
}
isValidFile(bytes) {
const image = new PsdImage(bytes);
return image.isValid;
}
startDecode(bytes) {
this._info = new PsdImage(bytes);
return this._info;
}
decode(opt) {
var _a;
if (this.startDecode(opt.bytes) === undefined) {
return undefined;
}
const len = this.numFrames;
if (len === 1 || opt.frameIndex !== undefined) {
return this.decodeFrame((_a = opt.frameIndex) !== null && _a !== void 0 ? _a : 0);
}
let firstImage = undefined;
for (let i = 0; i < len; ++i) {
const frame = this.decodeFrame(i);
if (frame === undefined) {
continue;
}
if (firstImage === undefined) {
firstImage = frame;
frame.frameType = FrameType.page;
}
else {
firstImage.addFrame(frame);
}
}
return firstImage;
}
decodeFrame(_frameIndex) {
var _a;
return (_a = this._info) === null || _a === void 0 ? void 0 : _a.decodeImage();
}
}
//# sourceMappingURL=psd-decoder.js.map