Skip to content

Commit

Permalink
use ColorConvertOp instead of Graphics2D #31
Browse files Browse the repository at this point in the history
Seems to increase the conversion performance by a factor of around 40
  • Loading branch information
yagee-de committed Jul 5, 2023
1 parent da116d3 commit 050ff49
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.mycore</groupId>
<artifactId>mycore-parent</artifactId>
<version>48</version>
<version>51</version>
</parent>
<groupId>org.mycore.iview2</groupId>
<artifactId>image-tiler</artifactId>
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/mycore/imagetiler/MCRImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mycore/imagetiler/MCRImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Binary file added src/test/resources/rgb-to-gbr.tif
Binary file not shown.

0 comments on commit 050ff49

Please sign in to comment.