Add Helper Functions

create PixelArray from another PixelArray
create empty PixelArray
convert PixelArray to ImageData
This commit is contained in:
Unknown 2018-02-14 15:54:28 +01:00
parent fb7776feac
commit 881da03825
1 changed files with 12 additions and 0 deletions

View File

@ -32,6 +32,10 @@ class Pixel {
class PixelArray {
List<List<Pixel>> pixels;
PixelArray(int width, int height) {
pixels = new List.filled(height, new List(width));
}
PixelArray.fromByteArray(Uint8ClampedList array, int imageWidth) {
pixels = new List(array.length~/imageWidth~/4);
int y = 0;
@ -51,6 +55,10 @@ class PixelArray {
PixelArray.fromImageData(ImageData imagedata, int imageWidth): this.fromByteArray(imagedata.data, imageWidth);
PixelArray.fromPixelArray(PixelArray pixelArray) {
pixels = new List<List<Pixel>>.from(pixelArray.pixels);
}
Uint8ClampedList toByteArray() {
//TODO: look for longest array, or each line separately. Only gets width from line 1 currently.
Uint8ClampedList result = new Uint8ClampedList(getHeight()*getWidth()*4);
@ -72,6 +80,10 @@ class PixelArray {
return result;
}
ImageData toImageData() {
return new ImageData(this.toByteArray(), this.getWidth(), this.getHeight());
}
Pixel getPixel(int x, int y) {
return pixels[y][x];
}