mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 11:35:29 -04:00
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:
parent
66363f8d09
commit
defadbbbcd
@ -303,7 +303,15 @@ 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
|
||||
|
@ -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();
|
||||
|
BIN
imageio/imageio-pict/src/test/resources/pict/cow.pict
Normal file
BIN
imageio/imageio-pict/src/test/resources/pict/cow.pict
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user