Skip to content

Commit

Permalink
Higher precision error diffusion
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Aug 23, 2013
1 parent 05d50b7 commit df396aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions blurize.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static void optimizeForAverageFilter(
const int filterCenter = 2;
const int bytesPerPixel = 4;
const int errorRowCount = 3;
const int ditheringPrecision = 256;
int stride = width * bytesPerPixel;
colorDelta row0[width + filterWidth - 1], row1[width + filterWidth - 1], row2[width + filterWidth - 1];
colorDelta *colorError[3] = { row0, row1, row2 };
Expand All @@ -92,15 +93,15 @@ static void optimizeForAverageFilter(
}
int average = (up + left) / 2; // PNG average filter

int newValue = diffusion[c] + here - average;
int newValue = diffusion[c]/ditheringPrecision + here - average;
newValue += halfStep;
newValue -= newValue % quantization;
newValue += average;
if (newValue >= 0 && newValue <= 255) {
pixels[offset] = newValue;
errorHere = here - newValue;
}
colorError[0][x + filterCenter][c] = errorHere;
colorError[0][x + filterCenter][c] = errorHere * ditheringPrecision;
}
}
}
Expand Down

0 comments on commit df396aa

Please sign in to comment.