gwlucastrig commented on a change in pull request #98:
URL: https://github.com/apache/commons-imaging/pull/98#discussion_r491751220
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
##########
@@ -291,25 +318,50 @@ public BufferedImage readImageData(final Rectangle
subImage)
// or working
final ImageBuilder workingBuilder =
new ImageBuilder(width, workingHeight, false);
-
- for (int strip = strip0; strip <= strip1; strip++) {
- final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
- final long rowsRemaining = height - (strip * rowsPerStripLong);
- final long rowsInThisStrip = Math.min(rowsRemaining,
rowsPerStripLong);
- final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
- final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
- final long pixelsPerStrip = rowsInThisStrip * width;
-
- final byte[] compressed = imageData.getImageData(strip).getData();
-
- final byte[] decompressed = decompress(compressed, compression,
- (int) bytesPerStrip, width, (int) rowsInThisStrip);
-
- interpretStrip(
- workingBuilder,
- decompressed,
- (int) pixelsPerStrip,
- yLimit);
+ if (planarConfiguration != 2) {
+ for (int strip = strip0; strip <= strip1; strip++) {
+ final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
+ final long rowsRemaining = height - (strip * rowsPerStripLong);
+ final long rowsInThisStrip = Math.min(rowsRemaining,
rowsPerStripLong);
+ final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
+ final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
+ final long pixelsPerStrip = rowsInThisStrip * width;
+
+ final byte[] compressed =
imageData.getImageData(strip).getData();
+
+ final byte[] decompressed = decompress(compressed, compression,
+ (int) bytesPerStrip, width, (int) rowsInThisStrip);
+
+ interpretStrip(
+ workingBuilder,
+ decompressed,
+ (int) pixelsPerStrip,
+ yLimit);
+ }
+ } else {
+ int nStripsInPlane = imageData.getImageDataLength() / 3;
+ for (int strip = strip0; strip <= strip1; strip++) {
+ final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
+ final long rowsRemaining = height - (strip * rowsPerStripLong);
+ final long rowsInThisStrip = Math.min(rowsRemaining,
rowsPerStripLong);
+ final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
+ final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
+ final long pixelsPerStrip = rowsInThisStrip * width;
+
+ byte[] b = new byte[(int) bytesPerStrip];
+ for (int iPlane = 0; iPlane < 3; iPlane++) {
+ int planeStrip = iPlane * nStripsInPlane + strip;
+ final byte[] compressed =
imageData.getImageData(planeStrip).getData();
+ final byte[] decompressed = decompress(compressed,
compression,
+ (int) bytesPerStrip, width, (int) rowsInThisStrip);
+ int index = iPlane;
+ for (int i = 0; i < decompressed.length; i++) {
+ b[index] = decompressed[i];
+ index += 3;
+ }
+ }
+ interpretStrip(workingBuilder, b, (int) pixelsPerStrip,
height);
+ }
Review comment:
These are two methods have a lot of redundancy and it would be better to
combine them into one. Unfortunately, they are both public APIs, so I'm not
sure we could change their external appearance. Of course, we could create a
single, consolidated method that does the processing. Then we could rewrite the
existing methods to be "wrapper" methods that called the new consolidated
method.
I think it might be better to treat that change as a separate pull request.
I contributed the "sub-image" logic a number of years ago. At the time,
there was a certain amount of resistance to the idea of a sub-image API, but I
thought it was necessary because may GeoTIFFs are huge (I'd been working with
some that are 20000-by-20000 pixels large). Anyway, I think I left the
original method in place because the code was simpler than the sub-image code
and I thought it would serve as a reference for anyone who was trying to figure
out how it worked. But I think you are right and the time has come to clean
things up.
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
##########
@@ -140,8 +145,8 @@ public ImageDataReader getDataReader(final TiffDirectory
directory,
public abstract ImageDataReader getDataReader(TiffDirectory directory,
PhotometricInterpreter photometricInterpreter, int bitsPerPixel,
int[] bitsPerSample, int predictor, int samplesPerPixel, int width,
- int height, int compression, ByteOrder byteOrder) throws
IOException,
- ImageReadException;
+ int height, int compression, int planarConfiguration,
+ ByteOrder byteOrder) throws IOException, ImageReadException;
Review comment:
Some of the spacing got accidentally modified when I edited file. I
thought I cleaned them all, but I missed this one. Sorry.
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
##########
@@ -237,27 +240,51 @@ private void interpretStrip(
@Override
public void readImageData(final ImageBuilder imageBuilder)
- throws ImageReadException, IOException {
- for (int strip = 0; strip < imageData.getImageDataLength(); strip++) {
- final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
- final long rowsRemaining = height - (strip * rowsPerStripLong);
- final long rowsInThisStrip = Math.min(rowsRemaining,
rowsPerStripLong);
- final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
- final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
- final long pixelsPerStrip = rowsInThisStrip * width;
-
- final byte[] compressed = imageData.getImageData(strip).getData();
-
- final byte[] decompressed = decompress(compressed, compression,
- (int) bytesPerStrip, width, (int) rowsInThisStrip);
-
- interpretStrip(
- imageBuilder,
- decompressed,
- (int) pixelsPerStrip,
- height);
-
+ throws ImageReadException, IOException {
+ if (planarConfiguration != 2) {
Review comment:
You are absolutely right about using the TiffTagConstant values in the
places you cited. Actually, I wanted to make line 244 test for
planarConfiguration == "Chunky" rather than != "Planar", but I was afraid that
there might be places in the code where the planarConfiguration variable didn't
get set correctly. So I thought this would be safer.
If we ever get our hands on some additional test files, I might revisit
this. But that may be unlikely... The Tiff Specification itself describes
planar-configuration 2 as follows: _PlanarConfiguration=2 is not currently in
widespread use and it is not recommended for general interchange. It is used an
extension and Baseline TIFF readers are not required to support it._
##########
File path:
src/test/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStripsTest.java
##########
@@ -24,7 +24,7 @@
@Test
public void testApplyPredictor() throws Exception {
final int[] bitsPerPixel = {1,2,3};
- final DataReaderStrips strips = new DataReaderStrips(null, null, 3,
bitsPerPixel, 2, 4, 0, 3, 1, 1, null, 2, null);
+ final DataReaderStrips strips = new DataReaderStrips(null, null, 3,
bitsPerPixel, 2, 4, 0, 3, 1, 1, 1, null, 2, null);
Review comment:
Agreed. Good catch.
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
##########
@@ -291,25 +318,50 @@ public BufferedImage readImageData(final Rectangle
subImage)
// or working
final ImageBuilder workingBuilder =
new ImageBuilder(width, workingHeight, false);
-
- for (int strip = strip0; strip <= strip1; strip++) {
- final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
- final long rowsRemaining = height - (strip * rowsPerStripLong);
- final long rowsInThisStrip = Math.min(rowsRemaining,
rowsPerStripLong);
- final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
- final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
- final long pixelsPerStrip = rowsInThisStrip * width;
-
- final byte[] compressed = imageData.getImageData(strip).getData();
-
- final byte[] decompressed = decompress(compressed, compression,
- (int) bytesPerStrip, width, (int) rowsInThisStrip);
-
- interpretStrip(
- workingBuilder,
- decompressed,
- (int) pixelsPerStrip,
- yLimit);
+ if (planarConfiguration != 2) {
Review comment:
Agreed. Good catch.
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java
##########
@@ -898,7 +921,7 @@ TiffRasterData getFloatingPointRasterData(
final ImageDataReader dataReader = imageData.getDataReader(directory,
photometricInterpreter, bitsPerPixel, bitsPerSample, predictor,
- samplesPerPixel, width, height, compression, byteOrder);
+ samplesPerPixel, width, height, compression, 1, byteOrder);
Review comment:
Agreed. Good catch.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]