Add per Pixel Quantize Methods
This commit is contained in:
parent
56994771f0
commit
0cc15e9b4f
1 changed files with 21 additions and 7 deletions
|
@ -21,16 +21,23 @@ class Pixed {
|
|||
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);
|
||||
pxArr.setPixel( _quantizePixel(pxArr.getPixel(x, y)) );
|
||||
}
|
||||
}
|
||||
return pxArr;
|
||||
}
|
||||
|
||||
static PixelArray calcQuantizeError(PixelArray original, PixelArray quantized) {
|
||||
static Pixel _quantizePixel(Pixel pixel, [int steps=1]) {
|
||||
return new Pixel(
|
||||
pixel.x,
|
||||
pixel.y,
|
||||
(steps * pixel.r / 255).round() * (255 ~/ steps),
|
||||
(steps * pixel.g / 255).round() * (255 ~/ steps),
|
||||
(steps * pixel.b / 255).round() * (255 ~/ steps),
|
||||
pixel.a);
|
||||
}
|
||||
|
||||
static PixelArray quantizeError(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++) {
|
||||
|
@ -43,6 +50,14 @@ class Pixed {
|
|||
}
|
||||
return pxArr;
|
||||
}
|
||||
|
||||
static Pixel _quantizeErrorPixel(Pixel original, Pixel quantized) {
|
||||
return new Pixel(original.x, original.y,
|
||||
original.r - quantized.r,
|
||||
original.g - quantized.g,
|
||||
original.b - quantized.b,
|
||||
original.a);
|
||||
}
|
||||
}
|
||||
|
||||
class Pixel {
|
||||
|
@ -92,7 +107,6 @@ class PixelArray {
|
|||
int y = 0;
|
||||
int x = 0;
|
||||
pixels[y] = new List(imageWidth);
|
||||
print(pixels[0].length.toString() + ","+ pixels.length.toString());
|
||||
for (var pos = 0; pos < array.length; pos = pos + 4) {
|
||||
if (x >= imageWidth) {
|
||||
x = 0;
|
||||
|
@ -107,7 +121,7 @@ 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);
|
||||
pixels = pixelArray.clone().pixels;
|
||||
}
|
||||
|
||||
Uint8ClampedList toByteArray() {
|
||||
|
|
Loading…
Reference in a new issue