Skip to content

Commit

Permalink
fix tiling of greyscale images with more than 8 bit (closes #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
yagee-de committed Jul 20, 2021
1 parent 40e0778 commit 17aea4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/mycore/imagetiler/MCRImage.java
Expand Up @@ -316,7 +316,7 @@ protected static int getBufferedImageType(final ImageReader reader) throws IOExc

private static BufferedImage convertIfNeeded(BufferedImage tile) {
ColorModel colorModel = tile.getColorModel();
boolean convertToGray = isFakeGrayScale(colorModel);
boolean convertToGray = isFakeGrayScale(colorModel) || colorModel.getNumColorComponents() == 1;
int pixelSize = colorModel.getPixelSize();
int targetType = tile.getType();
if (convertToGray) {
Expand Down Expand Up @@ -411,6 +411,10 @@ public static int getImageType(final ImageReader imageReader) throws IOException
private static int getImageType(ColorModel colorModel) {
int pixelSize = colorModel.getPixelSize();
if (pixelSize > 8) {
if (colorModel.getNumColorComponents() == 1) {
LOGGER.debug("Quite sure we should use TYPE_BYTE_GRAY for a pixel size of {}", pixelSize);
return BufferedImage.TYPE_BYTE_GRAY;
}
LOGGER.debug("Quite sure we should use TYPE_INT_RGB for a pixel size of {}", pixelSize);
return BufferedImage.TYPE_INT_RGB;
} else if (pixelSize == 8) {
Expand Down Expand Up @@ -720,7 +724,7 @@ private void writeImageIoTile(final ZipOutputStream zout, final BufferedImage ti
}
try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(zout)) {
imgWriter.setOutput(imageOutputStream);
//tile = addWatermark(scaleBufferedImage(tile));
//tile = addWatermark(scaleBufferedImage(tile));
final IIOImage iioImage = new IIOImage(tile, null, null);
imgWriter.write(null, iioImage, imageWriteParam);
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mycore/imagetiler/MCRImageTest.java
Expand Up @@ -89,6 +89,7 @@ public void setUp() {
pics.put("1 pixel mega tile rest", "src/test/resources/BE_0681_0397.jpg");
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");

tileDir = Paths.get("target/tileDir");
System.setProperty("java.awt.headless", "true");
Expand Down
Binary file added src/test/resources/tiff16.tif
Binary file not shown.

0 comments on commit 17aea4d

Please sign in to comment.