Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
RobFaustLZ committed Dec 17, 2023
1 parent 5ad8df9 commit aabd2cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.labelzoom.api'
version = '1.0.13'
version = '1.0.14'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/labelzoom/api/util/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ImageUtils
* @param luminanceThreshold luminance threshold
* @return the dithered 2-color image
*/
public static BufferedImage desaturateWithDithering(final BufferedImage image, int luminanceThreshold)
public static BufferedImage desaturateWithDithering(final BufferedImage image, final int luminanceThreshold, final int alphaThreshold)
{
// Clone original image
final ColorModel cm = image.getColorModel();
Expand All @@ -31,9 +31,6 @@ public static BufferedImage desaturateWithDithering(final BufferedImage image, i
// Apply dithering
final int width = out.getWidth();
final int height = out.getHeight();

// Two colors for dithering, typically black and white

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
final int pixel = out.getRGB(x, y);
Expand All @@ -44,7 +41,7 @@ public static BufferedImage desaturateWithDithering(final BufferedImage image, i

// Convert to grayscale (or use other method to choose between color1 and color2)
final int gray = (int)(0.299 * red + 0.587 * green + 0.114 * blue);
final int newPixel = gray < luminanceThreshold ? BLACK : WHITE;
final int newPixel = gray <= luminanceThreshold && alpha >= alphaThreshold ? BLACK : WHITE;

final int error = gray - ((newPixel == BLACK) ? 0 : 255);

Expand All @@ -54,7 +51,7 @@ public static BufferedImage desaturateWithDithering(final BufferedImage image, i
if (y < height - 1) out.setRGB(x, y + 1, applyError(out.getRGB(x, y + 1), Math.round(error * ERROR_FIVE_SIXTEENTHS)));
if (x < width - 1 && y < height - 1) out.setRGB(x + 1, y + 1, applyError(out.getRGB(x + 1, y + 1), Math.round(error * ERROR_ONE_SIXTEENTH)));

out.setRGB(x, y, newPixel | (alpha << 24));
out.setRGB(x, y, newPixel);
}
}
return out;
Expand Down

0 comments on commit aabd2cf

Please sign in to comment.