Skip to content

Commit

Permalink
Merge pull request #657 from glenrobson/fix-gray-turbo
Browse files Browse the repository at this point in the history
Fix gray turbo
  • Loading branch information
DiegoPino authored Jul 31, 2024
2 parents 322f101 + bd9e6aa commit e1a9d6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void write(BufferedImage image,
image = Java2DUtil.removeAlpha(image, bgColor);
image = Java2DUtil.convertCustomToRGB(image);

// Gray subsampling required to handle grayscale input
if (image.getType() == BufferedImage.TYPE_BYTE_GRAY) {
setSubsampling(TJ.SAMP_GRAY);
}

try (TJCompressor tjc = new TJCompressor()) {
tjc.setSubsamp(subsampling);
tjc.setJPEGQuality(quality);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ public void testWriteWithBufferedImage() throws Exception {
}
}

@Test
public void testWriteWithGrayBufferedImage() throws Exception {
BufferedImage image = new BufferedImage(50, 50,
BufferedImage.TYPE_BYTE_GRAY);

try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
instance.write(image, os);
assertDimensions(os, image.getWidth(), image.getHeight());
}
}

@Test
public void testWriteWithBufferedImageWithBackgroundColor()
throws Exception {
Expand All @@ -184,4 +195,4 @@ public void testWriteWithBufferedImageWithBackgroundColor()
}
}

}
}

0 comments on commit e1a9d6d

Please sign in to comment.