Change PhotometricInterpretation / SamplesPerPixel detection for one bit per pixel ColorSpaces

This commit is contained in:
Schmidor 2015-10-11 17:31:28 +02:00
parent 6c702c447b
commit 306a8ae166

View File

@ -288,6 +288,10 @@ public final class TIFFImageWriter extends ImageWriterBase {
entries.put(TIFF.TAG_SAMPLES_PER_PIXEL, new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, 1));
}
else {
if (colorModel.getPixelSize() == 1) {
numComponents = 1;
}
entries.put(TIFF.TAG_SAMPLES_PER_PIXEL, new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, numComponents));
// Note: Assuming sRGB to be the default RGB interpretation
@ -523,12 +527,12 @@ public final class TIFFImageWriter extends ImageWriterBase {
}
private int getPhotometricInterpretation(final ColorModel colorModel) {
if (colorModel.getNumComponents() == 1 && colorModel.getComponentSize(0) == 1) {
if (colorModel.getPixelSize() == 1) {
if (colorModel instanceof IndexColorModel) {
if (colorModel.getRGB(0) == 0xFFFFFF && colorModel.getRGB(1) == 0x000000) {
if (colorModel.getRGB(0) == 0xFFFFFFFF && colorModel.getRGB(1) == 0xFF000000) {
return TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO;
}
else if (colorModel.getRGB(0) != 0x000000 || colorModel.getRGB(1) != 0xFFFFFF) {
else if (colorModel.getRGB(0) != 0xFF000000 || colorModel.getRGB(1) != 0xFFFFFFFF) {
return TIFFBaseline.PHOTOMETRIC_PALETTE;
}
// Else, fall through to default, BLACK_IS_ZERO
@ -617,7 +621,6 @@ public final class TIFFImageWriter extends ImageWriterBase {
final Raster tile = renderedImage.getTile(xTile, yTile);
final DataBuffer dataBuffer = tile.getDataBuffer();
final int numBands = tile.getNumBands();
// final SampleModel sampleModel = tile.getSampleModel();
switch (dataBuffer.getDataType()) {
case DataBuffer.TYPE_BYTE:
@ -746,7 +749,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
}
private byte normalizeBlack(int photometricInterpretation, byte data) {
if (photometricInterpretation == TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO) {
if (photometricInterpretation == TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO) {
// Inverse values
return (byte) (0xff - data & 0xff);
}
@ -973,7 +976,6 @@ public final class TIFFImageWriter extends ImageWriterBase {
// }
// writer.dispose();
image = null;
BufferedImage read = ImageIO.read(output);