From 881da038251566b2dbbedcc19c18e3dc6a2ce2ab Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 14 Feb 2018 15:54:28 +0100 Subject: [PATCH] Add Helper Functions create PixelArray from another PixelArray create empty PixelArray convert PixelArray to ImageData --- lib/Dither.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Dither.dart b/lib/Dither.dart index 839fe79..ce0032c 100644 --- a/lib/Dither.dart +++ b/lib/Dither.dart @@ -32,6 +32,10 @@ class Pixel { class PixelArray { List> 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>.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]; }