81 lines
1.4 KiB
TypeScript
81 lines
1.4 KiB
TypeScript
|
/**
|
||
|
* Wrapper for pixel data of an image
|
||
|
*/
|
||
|
class PAImage {
|
||
|
/**
|
||
|
* Constructor
|
||
|
* @param width width in pixel
|
||
|
* @param height height in pixel
|
||
|
* @param channels number of channels
|
||
|
*/
|
||
|
constructor(width:number, height:number, channels: number) {
|
||
|
this.width = width;
|
||
|
this.height = height;
|
||
|
this.channels = channels;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Allocate memory for image data
|
||
|
*/
|
||
|
allocateMemory() {
|
||
|
this.pixels = new Uint8ClampedArray(this.width * this. height * this.channels);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Set pixel data
|
||
|
* @param pixels pixel data
|
||
|
*/
|
||
|
setPixels(pixels : Uint8ClampedArray) {
|
||
|
this.pixels = pixels;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get pixel data
|
||
|
* @return pixel data
|
||
|
*/
|
||
|
getPixels8() : Uint8ClampedArray {
|
||
|
return this.pixels;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get width of image
|
||
|
* @return width of image
|
||
|
*/
|
||
|
getWidth() : number {
|
||
|
return this.width;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get height of image
|
||
|
* @return height of image
|
||
|
*/
|
||
|
getHeight() : number {
|
||
|
return this.height;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get number of channels
|
||
|
* @return number of channels
|
||
|
*/
|
||
|
getNumChannels() : number {
|
||
|
return this.channels;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Image width
|
||
|
*/
|
||
|
private width: number;
|
||
|
/**
|
||
|
* Image height
|
||
|
*/
|
||
|
private height: number;
|
||
|
/**
|
||
|
* Number of channels
|
||
|
*/
|
||
|
private channels: number;
|
||
|
/**
|
||
|
* Image data as RGBA 8 bit per channel
|
||
|
*/
|
||
|
private pixels: Uint8ClampedArray;
|
||
|
};
|