Skip to content

Commit

Permalink
Merge pull request #686 from cantaloupe-project/add_pdf_test
Browse files Browse the repository at this point in the history
Adding failing test to check if the fix for PDF is working
  • Loading branch information
jcoyne authored Aug 15, 2024
2 parents 6657b4d + 605fbc1 commit 773ddee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 773ddee

Please sign in to comment.