mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 04:25:29 -04:00
Change PhotometricInterpretation / SamplesPerPixel detection for one bit per pixel ColorSpaces
This commit is contained in:
parent
6c702c447b
commit
306a8ae166
@ -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));
|
entries.put(TIFF.TAG_SAMPLES_PER_PIXEL, new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, 1));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (colorModel.getPixelSize() == 1) {
|
||||||
|
numComponents = 1;
|
||||||
|
}
|
||||||
|
|
||||||
entries.put(TIFF.TAG_SAMPLES_PER_PIXEL, new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, numComponents));
|
entries.put(TIFF.TAG_SAMPLES_PER_PIXEL, new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, numComponents));
|
||||||
|
|
||||||
// Note: Assuming sRGB to be the default RGB interpretation
|
// Note: Assuming sRGB to be the default RGB interpretation
|
||||||
@ -298,7 +302,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default sample format SAMPLEFORMAT_UINT need not be written
|
// Default sample format SAMPLEFORMAT_UINT need not be written
|
||||||
if (sampleModel.getDataType() == DataBuffer.TYPE_SHORT/* TODO: if isSigned(sampleModel.getDataType) or getSampleFormat(sampleModel) != 0 */) {
|
if (sampleModel.getDataType() == DataBuffer.TYPE_SHORT/* TODO: if isSigned(sampleModel.getDataType) or getSampleFormat(sampleModel) != 0 */) {
|
||||||
entries.put(TIFF.TAG_SAMPLE_FORMAT, new TIFFEntry(TIFF.TAG_SAMPLE_FORMAT, TIFFExtension.SAMPLEFORMAT_INT));
|
entries.put(TIFF.TAG_SAMPLE_FORMAT, new TIFFEntry(TIFF.TAG_SAMPLE_FORMAT, TIFFExtension.SAMPLEFORMAT_INT));
|
||||||
}
|
}
|
||||||
// TODO: Float values!
|
// TODO: Float values!
|
||||||
@ -523,12 +527,12 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getPhotometricInterpretation(final ColorModel colorModel) {
|
private int getPhotometricInterpretation(final ColorModel colorModel) {
|
||||||
if (colorModel.getNumComponents() == 1 && colorModel.getComponentSize(0) == 1) {
|
if (colorModel.getPixelSize() == 1) {
|
||||||
if (colorModel instanceof IndexColorModel) {
|
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;
|
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;
|
return TIFFBaseline.PHOTOMETRIC_PALETTE;
|
||||||
}
|
}
|
||||||
// Else, fall through to default, BLACK_IS_ZERO
|
// Else, fall through to default, BLACK_IS_ZERO
|
||||||
@ -561,9 +565,9 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
|
|
||||||
for (int i = 0; i < colorModel.getMapSize(); i++) {
|
for (int i = 0; i < colorModel.getMapSize(); i++) {
|
||||||
int color = colorModel.getRGB(i);
|
int color = colorModel.getRGB(i);
|
||||||
colorMap[i ] = (short) upScale((color >> 16) & 0xff);
|
colorMap[i] = (short) upScale((color >> 16) & 0xff);
|
||||||
colorMap[i + colorMap.length / 3] = (short) upScale((color >> 8) & 0xff);
|
colorMap[i + colorMap.length / 3] = (short) upScale((color >> 8) & 0xff);
|
||||||
colorMap[i + 2 * colorMap.length / 3] = (short) upScale((color ) & 0xff);
|
colorMap[i + 2 * colorMap.length / 3] = (short) upScale((color) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
return colorMap;
|
return colorMap;
|
||||||
@ -617,7 +621,6 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
final Raster tile = renderedImage.getTile(xTile, yTile);
|
final Raster tile = renderedImage.getTile(xTile, yTile);
|
||||||
final DataBuffer dataBuffer = tile.getDataBuffer();
|
final DataBuffer dataBuffer = tile.getDataBuffer();
|
||||||
final int numBands = tile.getNumBands();
|
final int numBands = tile.getNumBands();
|
||||||
// final SampleModel sampleModel = tile.getSampleModel();
|
|
||||||
|
|
||||||
switch (dataBuffer.getDataType()) {
|
switch (dataBuffer.getDataType()) {
|
||||||
case DataBuffer.TYPE_BYTE:
|
case DataBuffer.TYPE_BYTE:
|
||||||
@ -632,7 +635,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
final int xOff = yOff + x * numBands;
|
final int xOff = yOff + x * numBands;
|
||||||
|
|
||||||
for (int s = 0; s < numBands; s++) {
|
for (int s = 0; s < numBands; s++) {
|
||||||
buffer.put(normalizeBlack(photometric,(byte) (dataBuffer.getElem(b, xOff + bandOffsets[s]) & 0xff)));
|
buffer.put(normalizeBlack(photometric, (byte) (dataBuffer.getElem(b, xOff + bandOffsets[s]) & 0xff)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,9 +747,9 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
|
|
||||||
processImageComplete();
|
processImageComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte normalizeBlack(int photometricInterpretation, byte data) {
|
private byte normalizeBlack(int photometricInterpretation, byte data) {
|
||||||
if (photometricInterpretation == TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO) {
|
if (photometricInterpretation == TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO) {
|
||||||
// Inverse values
|
// Inverse values
|
||||||
return (byte) (0xff - data & 0xff);
|
return (byte) (0xff - data & 0xff);
|
||||||
}
|
}
|
||||||
@ -848,7 +851,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
int argIdx = 0;
|
int argIdx = 0;
|
||||||
|
|
||||||
// TODO: Proper argument parsing: -t <type> -c <compression>
|
// TODO: Proper argument parsing: -t <type> -c <compression>
|
||||||
int type = args.length > argIdx + 1 ? Integer.parseInt(args[argIdx++]) : -1;
|
int type = args.length > argIdx + 1 ? Integer.parseInt(args[argIdx++]) : -1;
|
||||||
int compression = args.length > argIdx + 1 ? Integer.parseInt(args[argIdx++]) : 0;
|
int compression = args.length > argIdx + 1 ? Integer.parseInt(args[argIdx++]) : 0;
|
||||||
|
|
||||||
if (args.length <= argIdx) {
|
if (args.length <= argIdx) {
|
||||||
@ -973,7 +976,6 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
|||||||
// }
|
// }
|
||||||
// writer.dispose();
|
// writer.dispose();
|
||||||
|
|
||||||
|
|
||||||
image = null;
|
image = null;
|
||||||
|
|
||||||
BufferedImage read = ImageIO.read(output);
|
BufferedImage read = ImageIO.read(output);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user