diff --git a/lib/Dither.dart b/lib/Dither.dart index 8579376..7f1cdb9 100644 --- a/lib/Dither.dart +++ b/lib/Dither.dart @@ -14,7 +14,33 @@ class Pixed { px.b = average; } } + return pxArr; + } + static PixelArray quantize(PixelArray image, [int steps=1]) { + PixelArray pxArr = new PixelArray.fromPixelArray(image); + for (var y = 0; y < pxArr.getHeight(); y++) { + for (var x = 0; x < pxArr.getWidth(); x++) { + var px = pxArr.getPixel(x, y); + px.r = (steps * px.r / 255).round() * (255 ~/ steps); + px.g = (steps * px.g / 255).round() * (255 ~/ steps); + px.b = (steps * px.b / 255).round() * (255 ~/ steps); + } + } + return pxArr; + } + + static PixelArray calcQuantizeError(PixelArray original, PixelArray quantized) { + PixelArray pxArr = new PixelArray.fromPixelArray(original); + for (var y = 0; y < pxArr.getHeight(); y++) { + for (var x = 0; x < pxArr.getWidth(); x++) { + Pixel px = pxArr.getPixel(x, y); + Pixel quant = quantized.getPixel(x, y); + px.r = px.r - quant.r; + px.g = px.g - quant.g; + px.b = px.b - quant.b; + } + } return pxArr; } }