gwlucastrig commented on a change in pull request #179:
URL: https://github.com/apache/commons-imaging/pull/179#discussion_r734099977
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
##########
@@ -382,53 +413,91 @@ protected void applyPredictorToBlock(final int width,
final int height, final in
final int height,
final int scanSize,
final byte[] bytes,
- final int predictor,
- final int bitsPerSample,
+ final int bitsPerPixel,
final ByteOrder byteOrder)
throws ImageReadException {
+ final int bitsPerSample = bitsPerPixel / samplesPerPixel;
final int bytesPerSample = bitsPerSample / 8;
- final int nBytes = bytesPerSample * scanSize * height;
- final int length = bytes.length < nBytes ? nBytes / scanSize : height;
-
- final int[] samples = new int[scanSize * height];
+ final int bytesPerScan = scanSize * samplesPerPixel * bytesPerSample;
+ final int nBytes = bytesPerScan * height;
+ final int length = bytes.length < nBytes ? nBytes / bytesPerScan :
height;
+ final int[] samples = new int[scanSize * samplesPerPixel * height];
// floating-point differencing is indicated by a predictor value of 3.
if (predictor ==
TiffTagConstants.PREDICTOR_VALUE_FLOATING_POINT_DIFFERENCING) {
// at this time, this class supports the 32-bit format. The
// main reason for this is that we have not located sample data
// that can be used for testing and analysis.
- if (bitsPerSample != 32) {
+ if (bitsPerPixel / samplesPerPixel != 32) {
throw new ImageReadException(
"Imaging does not yet support floating-point data"
+ " with predictor type 3 for "
- + bitsPerSample + " bits per sample");
+ + bitsPerPixel + " bits per sample");
}
- final int bytesInRow = scanSize * 4;
- for (int i = 0; i < length; i++) {
- final int aOffset = i * bytesInRow;
- final int bOffset = aOffset + scanSize;
- final int cOffset = bOffset + scanSize;
- final int dOffset = cOffset + scanSize;
- // in this loop, the source bytes give delta values.
- // we adjust them to give true values. This operation is
- // done on a row-by-row basis.
- for (int j = 1; j < bytesInRow; j++) {
- bytes[aOffset + j] += bytes[aOffset + j - 1];
+
+ if (planarConfiguration == TiffPlanarConfiguration.CHUNKY) {
+ final int bytesInRow = scanSize * 4 * samplesPerPixel;
+ for (int i = 0; i < length; i++) {
+ final int aOffset = i * bytesInRow;
+ final int bOffset = aOffset + scanSize * samplesPerPixel;
+ final int cOffset = bOffset + scanSize * samplesPerPixel;
+ final int dOffset = cOffset + scanSize * samplesPerPixel;
+ // in this loop, the source bytes give delta values.
+ // we adjust them to give true values. This operation is
+ // done on a row-by-row basis.
+ for (int j = 1; j < bytesInRow; j++) {
+ bytes[aOffset + j] += bytes[aOffset + j - 1];
+ }
+ // pack the bytes into the integer bit-equivalent of
+ // floating point values
+ int index = i * scanSize;
+ for (int j = 0; j < width * samplesPerPixel; j++) {
+ final int a = bytes[aOffset + j];
+ final int b = bytes[bOffset + j];
+ final int c = bytes[cOffset + j];
+ final int d = bytes[dOffset + j];
+ // Pack the 4 byte components into a single integer
+ // in the byte order used by the TIFF standard
+ samples[index++] = ((a & 0xff) << 24)
+ | ((b & 0xff) << 16)
+ | ((c & 0xff) << 8)
+ | (d & 0xff);
+ }
}
- // pack the bytes into the integer bit-equivalent of
- // floating point values
- int index = i * scanSize;
- for (int j = 0; j < width; j++) {
- final int a = bytes[aOffset + j];
- final int b = bytes[bOffset + j];
- final int c = bytes[cOffset + j];
- final int d = bytes[dOffset + j];
- // Pack the 4 byte components into a single integer
- // in the byte order used by the TIFF standard
- samples[index++] = ((a & 0xff) << 24)
- | ((b & 0xff) << 16)
- | ((c & 0xff) << 8)
- | (d & 0xff);
+ } else {
+ final int bytesInRow = scanSize * 4;
+ for (int iPlane = 0; iPlane < samplesPerPixel; iPlane++) {
+ int planarIntOffset = iPlane * length * scanSize;
+ int planarByteOffset = planarIntOffset * 4;
+
+ for (int i = 0; i < length; i++) {
+ final int aOffset = i * bytesInRow + planarByteOffset;
+ final int bOffset = aOffset + scanSize;
+ final int cOffset = bOffset + scanSize;
+ final int dOffset = cOffset + scanSize;
+ // in this loop, the source bytes give delta values.
+ // we adjust them to give true values. This operation
is
+ // done on a row-by-row basis.
+ for (int j = 1; j < bytesInRow; j++) {
+ bytes[aOffset + j] += bytes[aOffset + j - 1];
+ }
+ // pack the bytes into the integer bit-equivalent of
+ // floating point values
+ int index = planarIntOffset + i * scanSize;
+ for (int j = 0; j < width; j++) {
+ final int a = bytes[aOffset + j];
+ final int b = bytes[bOffset + j];
+ final int c = bytes[cOffset + j];
+ final int d = bytes[dOffset + j];
+ // Pack the 4 byte components into a single integer
+ // in the byte order used by the TIFF standard
+ samples[index++] = ((a & 0xff) << 24)
+ | ((b & 0xff) << 16)
+ | ((c & 0xff) << 8)
+ | (d & 0xff);
+ }
+ }
Review comment:
In a future PR, I would like to do some code clean up like that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]