[ https://issues.apache.org/jira/browse/IMAGING-265?focusedWorklogId=486721&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-486721 ] ASF GitHub Bot logged work on IMAGING-265: ------------------------------------------ Author: ASF GitHub Bot Created on: 21/Sep/20 00:02 Start Date: 21/Sep/20 00:02 Worklog Time Spent: 10m Work Description: 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. ---------------------------------------------------------------- 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: users@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 486721) Time Spent: 1h (was: 50m) > ArrayIndexOutOfBoundsException on reading simple GeoTIFF > -------------------------------------------------------- > > Key: IMAGING-265 > URL: https://issues.apache.org/jira/browse/IMAGING-265 > Project: Commons Imaging > Issue Type: Bug > Components: Format: TIFF > Affects Versions: 1.0-alpha2 > Reporter: edgar soldin > Assignee: Bruno P. Kinoshita > Priority: Major > Attachments: small_world.tif, small_world_split.jpg > > Time Spent: 1h > Remaining Estimate: 0h > > hi, >   > we on the OpenJUMP project cannot open some GeoTIFFs with commons.imaging . for details you may find a ticket in our bug tracker [https://sourceforge.net/p/jump-pilot/bugs/498/] . >   > the gist is: on loading the attached file getBufferedImage() fails with this stack > Caused by: java.lang.ArrayIndexOutOfBoundsException: 8000Caused by: java.lang.ArrayIndexOutOfBoundsException: 8000 at org.apache.commons.imaging.formats.tiff.datareaders.DataReaderStrips.interpretStrip(DataReaderStrips.java:196) at org.apache.commons.imaging.formats.tiff.datareaders.DataReaderStrips.readImageData(DataReaderStrips.java:254) at org.apache.commons.imaging.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:665) at org.apache.commons.imaging.formats.tiff.TiffDirectory.getTiffImage(TiffDirectory.java:254) at org.apache.commons.imaging.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:469) at org.apache.commons.imaging.Imaging.getBufferedImage(Imaging.java:1442) at org.apache.commons.imaging.Imaging.getBufferedImage(Imaging.java:1335) at org.apache.commons.imaging.Imaging.getBufferedImage(Imaging.java:1304) at com.vividsolutions.jump.workbench.imagery.graphic.CommonsImage.initImage(CommonsImage.java:108) -- This message was sent by Atlassian Jira (v8.3.4#803005)