Wrap all invokations of normalizeColor and normalizeColorPlanar

This commit is contained in:
Bertil Chapuis 2023-12-22 10:26:24 +01:00 committed by Harald Kuhr
parent 57d9bfda59
commit 6501321fac

View File

@ -1154,8 +1154,10 @@ public final class TIFFImageReader extends ImageReaderBase {
// Need to do color normalization after reading all bands for planar // Need to do color normalization after reading all bands for planar
if (planarConfiguration == TIFFExtension.PLANARCONFIG_PLANAR) { if (planarConfiguration == TIFFExtension.PLANARCONFIG_PLANAR) {
if (normalize) {
normalizeColorPlanar(interpretation, destRaster); normalizeColorPlanar(interpretation, destRaster);
} }
}
col += colsInTile; col += colsInTile;
@ -1252,10 +1254,14 @@ public final class TIFFImageReader extends ImageReaderBase {
// TODO: Refactor + duplicate this for all JPEG-in-TIFF cases // TODO: Refactor + duplicate this for all JPEG-in-TIFF cases
switch (raster.getTransferType()) { switch (raster.getTransferType()) {
case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_BYTE:
if (normalize) {
normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData()); normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData());
}
break; break;
case DataBuffer.TYPE_USHORT: case DataBuffer.TYPE_USHORT:
if (normalize) {
normalizeColor(interpretation, samplesInTile, ((DataBufferUShort) raster.getDataBuffer()).getData()); normalizeColor(interpretation, samplesInTile, ((DataBufferUShort) raster.getDataBuffer()).getData());
}
break; break;
default: default:
throw new IllegalStateException("Unsupported transfer type: " + raster.getTransferType()); throw new IllegalStateException("Unsupported transfer type: " + raster.getTransferType());
@ -1418,7 +1424,9 @@ public final class TIFFImageReader extends ImageReaderBase {
// Otherwise, it's likely CMYK or some other interpretation we don't need to convert. // Otherwise, it's likely CMYK or some other interpretation we don't need to convert.
// We'll have to use readAsRaster and later apply color space conversion ourselves // We'll have to use readAsRaster and later apply color space conversion ourselves
Raster raster = jpegReader.readRaster(0, jpegParam); Raster raster = jpegReader.readRaster(0, jpegParam);
if (normalize) {
normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData()); normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData());
}
destination.getRaster().setDataElements(offset.x, offset.y, raster); destination.getRaster().setDataElements(offset.x, offset.y, raster);
} }
} }
@ -1568,7 +1576,9 @@ public final class TIFFImageReader extends ImageReaderBase {
// Otherwise, it's likely CMYK or some other interpretation we don't need to convert. // Otherwise, it's likely CMYK or some other interpretation we don't need to convert.
// We'll have to use readAsRaster and later apply color space conversion ourselves // We'll have to use readAsRaster and later apply color space conversion ourselves
Raster raster = jpegReader.readRaster(0, jpegParam); Raster raster = jpegReader.readRaster(0, jpegParam);
if (normalize) {
normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData()); normalizeColor(interpretation, samplesInTile, ((DataBufferByte) raster.getDataBuffer()).getData());
}
destination.getRaster().setDataElements(offset.x, offset.y, raster); destination.getRaster().setDataElements(offset.x, offset.y, raster);
} }
} }
@ -1954,7 +1964,7 @@ public final class TIFFImageReader extends ImageReaderBase {
input.readFully(rowDataByte); input.readFully(rowDataByte);
if (row % ySub == 0 && row >= srcRegion.y) { if (row % ySub == 0 && row >= srcRegion.y) {
if (!banded) { if (normalize && !banded) {
normalizeColor(interpretation, numBands, rowDataByte); normalizeColor(interpretation, numBands, rowDataByte);
} }
@ -1985,7 +1995,9 @@ public final class TIFFImageReader extends ImageReaderBase {
input.readFully(rowDataShort, 0, rowDataShort.length); input.readFully(rowDataShort, 0, rowDataShort.length);
if (row >= srcRegion.y) { if (row >= srcRegion.y) {
if (normalize) {
normalizeColor(interpretation, numBands, rowDataShort); normalizeColor(interpretation, numBands, rowDataShort);
}
// Subsample horizontal // Subsample horizontal
subsampleRow(rowDataShort, srcRegion.x * numBands, colsInTile, subsampleRow(rowDataShort, srcRegion.x * numBands, colsInTile,
@ -2013,7 +2025,9 @@ public final class TIFFImageReader extends ImageReaderBase {
input.readFully(rowDataInt, 0, rowDataInt.length); input.readFully(rowDataInt, 0, rowDataInt.length);
if (row >= srcRegion.y) { if (row >= srcRegion.y) {
if (normalize) {
normalizeColor(interpretation, numBands, rowDataInt); normalizeColor(interpretation, numBands, rowDataInt);
}
// Subsample horizontal // Subsample horizontal
subsampleRow(rowDataInt, srcRegion.x * numBands, colsInTile, subsampleRow(rowDataInt, srcRegion.x * numBands, colsInTile,