kinow commented on a change in pull request #179:
URL: https://github.com/apache/commons-imaging/pull/179#discussion_r733222342
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
##########
@@ -62,15 +63,15 @@
* Unfortunately, the TIFF floating-point format allows for a lot of different
* variations. At this time, only the most widely used of these are supported.
* When this code was written, only a small set of test data products were
- * available. Thus it is likely that developers will wish to extend the
- * range of floating-point data that can be processed as
- * additional test data become available. When implementing extensions to this
- * logic, developers are reminded that image processing requires
- * the handling of literally millions of pixels, so attention to performance
- * is essential to a successful implementation (please see the notes in
- * DataReaderStrips.java for more information).
+ * available. Thus it is likely that developers will wish to extend the range
of
+ * floating-point data that can be processed as additional test data become
+ * available. When implementing extensions to this logic, developers are
+ * reminded that image processing requires the handling of literally millions
of
+ * pixels, so attention to performance is essential to a successful
+ * implementation (please see the notes in DataReaderStrips.java for more
Review comment:
Use `{@code DataReaderStrips}` or `{@link DataReaderStrips}`.
##########
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:
For a follow-up, we should probably simplify this method, splitting into
separate methods if possible.
##########
File path:
src/test/java/org/apache/commons/imaging/formats/tiff/TiffRasterDataTest.java
##########
@@ -84,6 +85,45 @@ public void testGetValue() {
}
}
+ /**
+ * Test of setValue method, of class TiffRasterData.
+ */
+ @Test
+ public void testSetValue2() {
+ final TiffRasterData instance = new TiffRasterDataFloat(width, height,
2);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ final int index = y * width + height;
+ instance.setValue(x, y, 1, index);
+ final int test = (int) instance.getValue(x, y, 1);
+ assertEquals(index, test, "Set/get value test failed at (" + x
+ "," + y + ")");
+ instance.setIntValue(x, y, 1, index);
+ final int iTest = instance.getIntValue(x, y, 1);
+ assertEquals(index, iTest, "Get/set value test failed at (" +
x + "," + y + ")");
+ }
+ }
+ }
+
+ /**
+ * Test of getValue method, of class TiffRasterData.
+ */
+ @Test
+ public void testGetValue2() {
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ final int index = y * width + x;
+ final int test = (int) raster.getValue(x, y, 0);
+ assertEquals(index, test, "Get into source data test failed at
(" + x + "," + y + ")");
+ final int iTest = raster.getIntValue(x, y, 0);
+ assertEquals(index, iTest, "Get into source data test failed
at (" + x + "," + y + ")");
+ }
+ }
+ }
+
+
+
+
+
Review comment:
Unnecessary extra blank lines :point_up:
--
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]