mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-27 00:00:02 -04:00
TMI-73: Now handles TIFF files using only the lower 8 bits of each 16 bit entry in the ColorMap.
This commit is contained in:
+38
-11
@@ -340,17 +340,7 @@ public class TIFFImageReader extends ImageReaderBase {
|
||||
throw new IIOException("Missing ColorMap for Palette TIFF");
|
||||
}
|
||||
|
||||
int[] cmapShort = (int[]) colorMap.getValue();
|
||||
int[] cmap = new int[colorMap.valueCount() / 3];
|
||||
|
||||
// All reds, then greens, and finally blues
|
||||
for (int i = 0; i < cmap.length; i++) {
|
||||
cmap[i] = (cmapShort[i ] / 256) << 16
|
||||
| (cmapShort[i + cmap.length] / 256) << 8
|
||||
| (cmapShort[i + 2 * cmap.length] / 256);
|
||||
}
|
||||
|
||||
IndexColorModel icm = new IndexColorModel(bitsPerSample, cmap.length, cmap, 0, false, -1, dataType);
|
||||
IndexColorModel icm = createIndexColorModel(bitsPerSample, dataType, (int[]) colorMap.getValue());
|
||||
|
||||
return IndexedImageTypeSpecifier.createFromIndexColorModel(icm);
|
||||
|
||||
@@ -413,6 +403,43 @@ public class TIFFImageReader extends ImageReaderBase {
|
||||
}
|
||||
}
|
||||
|
||||
private IndexColorModel createIndexColorModel(final int bitsPerSample, final int dataType, final int[] cmapShort) {
|
||||
// According to the spec, there should be exactly 3 * bitsPerSample^2 entries in the color map for TIFF.
|
||||
// Should we enforce this?
|
||||
|
||||
int[] cmap = new int[cmapShort.length / 3];
|
||||
|
||||
// We'll detect whether the color map data is 8 bit, rather than 16 bit while converting
|
||||
boolean cmapIs8Bit = true;
|
||||
|
||||
// All reds, then greens, and finally blues
|
||||
for (int i = 0; i < cmap.length; i++) {
|
||||
cmap[i] = (cmapShort[i ] / 256) << 16
|
||||
| (cmapShort[i + cmap.length] / 256) << 8
|
||||
| (cmapShort[i + 2 * cmap.length] / 256);
|
||||
|
||||
if (cmapIs8Bit && cmap[i] != 0) {
|
||||
cmapIs8Bit = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmapIs8Bit) {
|
||||
// This color map is using only the lower 8 bits, making the image all black.
|
||||
// We'll create a new color map, based on the non-scaled 8 bit values.
|
||||
|
||||
processWarningOccurred("8 bit ColorMap detected.");
|
||||
|
||||
// All reds, then greens, and finally blues
|
||||
for (int i = 0; i < cmap.length; i++) {
|
||||
cmap[i] = (cmapShort[i ]) << 16
|
||||
| (cmapShort[i + cmap.length]) << 8
|
||||
| (cmapShort[i + 2 * cmap.length]);
|
||||
}
|
||||
}
|
||||
|
||||
return new IndexColorModel(bitsPerSample, cmap.length, cmap, 0, false, -1, dataType);
|
||||
}
|
||||
|
||||
private int getSampleFormat() throws IIOException {
|
||||
long[] value = getValueAsLongArray(TIFF.TAG_SAMPLE_FORMAT, "SampleFormat", false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user