Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding failing test to check if the fix for PDF is working #686

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void write(BufferedImage image,
// Also, JPEG doesn't support alpha, so we have to remove that,
// otherwise readers will interpret as CMYK.
if (image.getRaster().getSampleModelTranslateX() < 0 ||
image.getRaster().getSampleModelTranslateX() < 0) {
image.getRaster().getSampleModelTranslateY() < 0) {
BufferedImage newImage = new BufferedImage(
image.getWidth(), image.getHeight(),
BufferedImage.TYPE_INT_RGB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ public void testWriteWithBufferedImage() throws Exception {
}
}

/**
* Note the TurboJPEGImageWriter.write method is used in the PDFbox processor
*/
@Test
public void testWriteWithBufferedImageYZero() throws Exception {
Path path = TestUtil.getImage("jpg");
BufferedImage image = ImageIO.read(path.toFile());

image = image.getSubimage(0, 10, 10,10);

try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
instance.write(image, os);
ImageInputStream is = ImageIO.createImageInputStream(new ByteArrayInputStream(os.toByteArray()));
image = ImageIO.read(is); // also closes the stream
Color color = new Color(image.getRGB(0,0));
assertEquals(116, color.getRed(), "Expected a particular color pixel but it wasn't found. Potentially the TurboJPEGImageWriter is returning the wrong image. Red value");
assertEquals(151, color.getGreen(), "Expected a particular color pixel but it wasn't found. Potentially the TurboJPEGImageWriter is returning the wrong image. Green value");
assertEquals(97, color.getBlue(), "Expected a particular color pixel but it wasn't found. Potentially the TurboJPEGImageWriter is returning the wrong image. Blue value");
// ImageIO.write(image, "jpg", new java.io.File("/tmp/test.jpg"));
}
}

@Test
public void testWriteWithGrayBufferedImage() throws Exception {
BufferedImage image = new BufferedImage(50, 50,
Expand Down
Loading