diff --git a/pom.xml b/pom.xml index adcb0c1..e4d0c55 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.mycore mycore-parent - 48 + 51 org.mycore.iview2 image-tiler diff --git a/src/main/java/org/mycore/imagetiler/MCRImage.java b/src/main/java/org/mycore/imagetiler/MCRImage.java index 46d7fe4..874bdb4 100644 --- a/src/main/java/org/mycore/imagetiler/MCRImage.java +++ b/src/main/java/org/mycore/imagetiler/MCRImage.java @@ -21,6 +21,7 @@ import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.awt.image.ColorConvertOp; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.io.BufferedOutputStream; @@ -115,6 +116,8 @@ public class MCRImage { private static final double ZOOM_FACTOR = 0.5; + private static final ColorConvertOp COLOR_CONVERT_OP = new ColorConvertOp(null); + /** * derivate ID (for output directory calculation). */ @@ -247,7 +250,7 @@ private static Path getTiledFileBaseDir(Path tileDir, String derivateID) { if (lastPart.length() > MIN_FILENAME_SUFFIX_LEN) { baseDir = baseDir.resolve( lastPart.substring(lastPart.length() - DIRECTORY_PART_LEN * 2, lastPart.length() - DIRECTORY_PART_LEN)); - baseDir = baseDir.resolve(lastPart.substring(lastPart.length() - DIRECTORY_PART_LEN, lastPart.length())); + baseDir = baseDir.resolve(lastPart.substring(lastPart.length() - DIRECTORY_PART_LEN)); } else { baseDir = baseDir.resolve(lastPart); } @@ -282,7 +285,7 @@ private static ImageReader createImageReader(final ImageInputStream imageInputSt return null; } final ImageReader reader = readers.next(); - reader.setInput(imageInputStream, false); + reader.setInput(imageInputStream, false, true); return reader; } @@ -336,12 +339,7 @@ private static BufferedImage convertIfNeeded(BufferedImage tile) { } final BufferedImage newTile = new BufferedImage(tile.getWidth(), tile.getHeight(), convertToGray ? BufferedImage.TYPE_BYTE_GRAY : BufferedImage.TYPE_INT_RGB); - Graphics2D graphics2d = newTile.createGraphics(); - try { - graphics2d.drawImage(tile, 0, 0, tile.getWidth(), tile.getHeight(), null); - } finally { - graphics2d.dispose(); - } + COLOR_CONVERT_OP.filter(tile, newTile); return newTile; } diff --git a/src/test/java/org/mycore/imagetiler/MCRImageTest.java b/src/test/java/org/mycore/imagetiler/MCRImageTest.java index 1986a5c..e8b0a9a 100644 --- a/src/test/java/org/mycore/imagetiler/MCRImageTest.java +++ b/src/test/java/org/mycore/imagetiler/MCRImageTest.java @@ -90,6 +90,7 @@ public void setUp() { pics.put("extra small", "src/test/resources/5x5.jpg"); pics.put("tiff 48 bit", "src/test/resources/tiff48.tif"); pics.put("tiff 16 bit", "src/test/resources/tiff16.tif"); + pics.put("tiff ICC", "src/test/resources/rgb-to-gbr.tif"); tileDir = Paths.get("target/tileDir"); System.setProperty("java.awt.headless", "true"); diff --git a/src/test/resources/rgb-to-gbr.tif b/src/test/resources/rgb-to-gbr.tif new file mode 100644 index 0000000..8c84787 Binary files /dev/null and b/src/test/resources/rgb-to-gbr.tif differ