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)
263 lines (262 loc) • 9.66 kB
TypeScript
/** @format */
import { Color } from '../../color/color.js';
import { InputBuffer } from '../../common/input-buffer.js';
import { MemoryImage } from '../../image/image.js';
import { DecodeInfo } from '../decode-info.js';
import { PsdChannel } from './psd-channel.js';
import { PsdColorMode } from './psd-color-mode.js';
import { PsdImageResource } from './psd-image-resource.js';
import { PsdLayer } from './psd-layer.js';
/**
* Represents a PSD image and provides methods to decode and render it.
*/
export declare class PsdImage implements DecodeInfo {
/**
* PSD file signature '8BPS'.
*/
static readonly psdSignature: number;
/**
* Resource block signature '8BIM'.
*/
static readonly resourceBlockSignature: number;
private _input;
get input(): InputBuffer<Uint8Array> | undefined;
private _imageData;
private _imageResourceData;
private _layerAndMaskData;
private _width;
get width(): number;
private _height;
get height(): number;
private readonly _backgroundColor;
get backgroundColor(): Color | undefined;
/**
* The number of frames that can be decoded.
*/
private readonly _numFrames;
get numFrames(): number;
private _signature;
get signature(): number | undefined;
private _version;
get version(): number | undefined;
private _channels;
get channels(): number;
private _depth;
get depth(): number;
private _colorMode;
get colorMode(): PsdColorMode | undefined;
private _layers;
get layers(): PsdLayer[];
private _mergeImageChannels;
get mergeImageChannels(): PsdChannel[];
private _mergedImage;
get mergedImage(): MemoryImage | undefined;
private readonly _imageResources;
get imageResources(): Map<number, PsdImageResource>;
private _hasAlpha;
get hasAlpha(): boolean;
get isValid(): boolean;
/**
* Constructs a PsdImage instance from the given byte array.
* @param {Uint8Array} bytes - The byte array representing the PSD file.
*/
constructor(bytes: Uint8Array);
/**
* Blends two values using the lighten blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendLighten;
/**
* Blends two values using the darken blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendDarken;
/**
* Blends two values using the multiply blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendMultiply;
/**
* Blends two values using the overlay blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @param {number} aAlpha - The alpha value of the first value.
* @param {number} bAlpha - The alpha value of the second value.
* @returns {number} The blended value.
*/
private static blendOverlay;
/**
* Blends two values using the color burn blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendColorBurn;
/**
* Blends two values using the linear burn blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendLinearBurn;
/**
* Blends two values using the screen blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendScreen;
/**
* Blends two values using the color dodge blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendColorDodge;
/**
* Blends two values using the linear dodge blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendLinearDodge;
/**
* Blends two values using the soft light blend mode.
* @param {number} a - The first value.
* @param {number} b - The second value.
* @returns {number} The blended value.
*/
private static blendSoftLight;
/**
* Blends two values using the hard light blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendHardLight;
/**
* Blends two values using the vivid light blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendVividLight;
/**
* Blends two values using the linear light blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendLinearLight;
/**
* Blends two values using the pin light blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendPinLight;
/**
* Blends two values using the hard mix blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendHardMix;
/**
* Blends two values using the difference blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendDifference;
/**
* Blends two values using the exclusion blend mode.
* @param {number} bottom - The bottom value.
* @param {number} top - The top value.
* @returns {number} The blended value.
*/
private static blendExclusion;
/**
* Reads a channel value from the data.
* @param {Uint8Array} data - The data array.
* @param {number} si - The start index.
* @param {number} ns - The number of samples.
* @returns {number} The channel value.
*/
private static ch;
/**
* Creates an image from the given channels.
* @param {number} width - The width of the image.
* @param {number} height - The height of the image.
* @param {PsdChannel[]} channelList - The list of channels.
* @param {PsdColorMode} [colorMode] - The color mode.
* @param {number} [bitDepth] - The bit depth.
* @returns {MemoryImage} The created image.
* @throws {LibError} If the bit depth is unsupported or the color mode is unhandled.
*/
static createImageFromChannels(width: number, height: number, channelList: PsdChannel[], colorMode?: PsdColorMode, bitDepth?: number): MemoryImage;
/**
* Blends two pixels using the specified blend mode and opacity.
*
* @param {number} ar - The red component of the first pixel.
* @param {number} ag - The green component of the first pixel.
* @param {number} ab - The blue component of the first pixel.
* @param {number} aa - The alpha component of the first pixel.
* @param {number} br - The red component of the second pixel.
* @param {number} bg - The green component of the second pixel.
* @param {number} bb - The blue component of the second pixel.
* @param {number} ba - The alpha component of the second pixel.
* @param {number} blendMode - The blend mode to use.
* @param {number} opacity - The opacity to use.
* @param {Pixel} p - The pixel to store the result.
*/
private blend;
/**
* Reads the header information from the input stream and initializes
* the corresponding properties of the class. This includes reading
* the signature, version, channels, dimensions, depth, and color mode.
* If the version is not 1 or the padding is not all zeros, the signature
* is set to 0 to indicate an invalid header.
*/
private readHeader;
/**
* Reads the color mode data.
*
* This method currently does not support indexed and duotone images.
* TODO: Add support for indexed and duotone images.
*/
private readColorModeData;
private readImageResources;
private readLayerAndMaskData;
/**
* Reads and merges image data.
* This method handles different compression types and constructs the merged image.
*/
private readMergeImageData;
/**
* Decode the raw psd structure without rendering the output image.
* Use renderImage to render the output image.
*
* @returns {boolean} Returns true if the decoding is successful, otherwise false.
*/
decode(): boolean;
/**
* Decodes an image and returns a MemoryImage object.
* If the decoding process fails, it returns undefined.
*
* @returns {MemoryImage | undefined} The decoded MemoryImage object or undefined if decoding fails.
*/
decodeImage(): MemoryImage | undefined;
/**
* Renders the composite image by blending all visible layers.
*
* @returns {MemoryImage} The final merged image.
*/
renderImage(): MemoryImage;
}