ImageData stores data as one-dimensional array of 8-bit values(RGBA color takes 4 positions for each component), I found this not comfortable for me, so created Pixels class to
- Retrieve/Store color information by X/Y coordinates in image.
- Retrieve/Store color information as single value(RGBA) by position in one-dimensional array of pixels(length = with*height)
via npm
npm install gist:1788a9282f111476e966aea118100eac --save
via git
git clone https://gist.github.com/burdiuz/1788a9282f111476e966aea118100eac Pixels
- new Pixels(imageData:ImageData) - create instance of Pixels to wrap ImageData.
- setImage(imageData:ImageData) - set new source of image color data.
- getPixelPosition(x:uint, y:uint):uint - get pixel position in one-dimensional array of pixels by its X/Y coordinates.
- getPixelPositionRaw(x:uint, y:uint):uint - get pixel's red component position in one-dimensional array of color components(length = with*height*4) by its X/Y coordinates.
- getPixel(x:uint, y:uint):uint - get RGBA color value by its X/Y coordinates.
- getPixelAlpha(x:uint, y:uint):uint - get alpha/opacity value by its X/Y coordinates. Value between 0 and 255.
- getPixelByPosition(pos:uint):uint - get RGBA color value by its position in one-dimensional array of pixels.
- get length:uint - get length of image data one-dimensional array of pixels.
- get width:uint - get image width.
- get height:uint - get image height.
- setPixel(x:uint, y:uint, color:uint) - set RGBA color value to pixel by its X/Y coordinates.
- setPixelByPosition(pos:uint, color:uint) - set RGBA color value to pixel by its position in one-dimensional array of pixels.
- valueOf():ImageData - returns ImageData object.
- [@@iterator]:Generator - generator for for..of cycle. Goes through RGBA color values for each pixel in one-dimensional array of pixels.