Skip to content

Commit

Permalink
dither update
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed May 11, 2024
1 parent 3651e65 commit 2c652ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/src/filter/dither_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,16 @@ Image ditherImage(Image image,

final imageCopy = image.clone();

final pIter = imageCopy.iterator..moveNext();

for (var y = 0; y < height; y++) {
if (serpentine) {
direction = direction * -1;
}

final x0 = direction == 1 ? 0 : width - 1;
final x1 = direction == 1 ? width : 0;
for (var x = x0; x != x1; x += direction, pIter.moveNext()) {
for (var x = x0; x != x1; x += direction) {
// Get original color
final pc = pIter.current;
final pc = imageCopy.getPixel(x, y);
final r1 = pc[0].toInt();
final g1 = pc[1].toInt();
final b1 = pc[2].toInt();
Expand All @@ -118,7 +116,8 @@ Image ditherImage(Image image,
for (var i = i0; i != i1; i += direction) {
final x1 = ds[i][1].toInt();
final y1 = ds[i][2].toInt();
if (x1 + x >= 0 && x1 + x < width && y1 + y >= 0 && y1 + y < height) {
if ((x1 + x) >= 0 && (x1 + x) < width && (y1 + y) >= 0 &&
(y1 + y) < height) {
final d = ds[i][0];
final nx = x + x1;
final ny = y + y1;
Expand Down
3 changes: 2 additions & 1 deletion test/filter/quantize_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void main() {

final i2 = decodePng(bytes)!;
final q2 =
quantize(i2, numberOfColors: 32, dither: DitherKernel.floydSteinberg);
quantize(grayscale(i2), numberOfColors: 2,
dither: DitherKernel.floydSteinberg);
File('$testOutputPath/filter/quantize_neural_dither.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(q2));
Expand Down

0 comments on commit 2c652ee

Please sign in to comment.