Set 'frame' to correct image bounds (#1130)

Ensure the x,y offset for extended v2 pictures is respected by updating 'frame' to the correct bounding rectangle. As a result we
need to base output image directly on frame size rather than applying screen image ratio. See cow.pict.

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
This commit is contained in:
Rolf Howarth 2025-05-30 15:07:16 +01:00 committed by GitHub
parent 66363f8d09
commit defadbbbcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -303,8 +303,16 @@ public final class PICTImageReader extends ImageReaderBase {
}
if (DEBUG) {
System.out.println("bounding rect: " + new Rectangle(x2, y2, w2 - x2, h2 - y2));
if (frame.x != x2 || frame.y != y2 || frame.width != w2-x2 || frame.height != h2-y2) {
System.out.println("*** replacing old frame " + frame);
}
}
frame.x = x2;
frame.y = y2;
frame.width = w2 - x2;
frame.height = h2 - y2;
// long reserved
pStream.skipBytes(4);
}
@ -2617,7 +2625,7 @@ public final class PICTImageReader extends ImageReaderBase {
}
Rectangle frame = getPICTFrame();
BufferedImage image = getDestination(pParam, getImageTypes(pIndex), getXPtCoord(frame.width), getYPtCoord(frame.height));
BufferedImage image = getDestination(pParam, getImageTypes(pIndex), frame.width, frame.height);
Graphics2D g = image.createGraphics();
try {
// Might need to clear background

View File

@ -84,6 +84,7 @@ public class PICTImageReaderTest extends ImageReaderAbstractTest<PICTImageReader
new TestData(getClassLoaderResource("/pict/FC10.PCT"), new Dimension(2265, 2593)),
// 1000 DPI with bounding box not matching DPI
new TestData(getClassLoaderResource("/pict/oom.pict"), new Dimension(1713, 1263)),
new TestData(getClassLoaderResource("/pict/cow.pict"), new Dimension(787, 548)),
new TestData(getClassLoaderResource("/pict/CatDV==2.0=1=.pict"), new Dimension(375, 165)),
new TestData(getClassLoaderResource("/pict/Picture14.pict"), new Dimension(404, 136)),
new TestData(getClassLoaderResource("/pict/J19.pict"), new Dimension(640, 480)),
@ -251,6 +252,22 @@ public class PICTImageReaderTest extends ImageReaderAbstractTest<PICTImageReader
reader.read(0);
}
@Test
public void testFrameBoundsIssue() throws IOException {
PICTImageReader reader = createReader();
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/pict/cow.pict"))) {
reader.setInput(stream);
// This file is from Apache POI test data. It should render as a black silhouette of a cow on a transparent
// background. Without the fix the image is completely transparent.
BufferedImage image = reader.read(0, null);
assertRGBEquals("RGB values differ", 0xff000000, image.getRGB(100, 100), 1); // was transparent 00ffffff
}
finally {
reader.dispose();
}
}
@Test
public void testBoundsIssue() throws IOException {
PICTImageReader reader = createReader();

Binary file not shown.