From issues-return-92350-archive-asf-public=cust-asf.ponee.io@commons.apache.org Sat Sep 19 07:23:16 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 4175418066B for ; Sat, 19 Sep 2020 09:23:16 +0200 (CEST) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id 72D5942831 for ; Sat, 19 Sep 2020 07:23:15 +0000 (UTC) Received: (qmail 75395 invoked by uid 500); 19 Sep 2020 07:23:15 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 75378 invoked by uid 99); 19 Sep 2020 07:23:15 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Sep 2020 07:23:14 +0000 From: =?utf-8?q?GitBox?= To: issues@commons.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bcommons-imaging=5D_kinow_commented_on_a_change_in_?= =?utf-8?q?pull_request_=2398=3A_Fix_for_IMAGING-265?= Message-ID: <160050019489.32230.14096989336367845777.asfpy@gitbox.apache.org> Date: Sat, 19 Sep 2020 07:23:14 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: kinow commented on a change in pull request #98: URL: https://github.com/apache/commons-imaging/pull/98#discussion_r491307463 ########## 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: Not sure if this is GitHub's UI issue, but looks like there are several spaces between `IOException, ` and `ImageReadException`? ########## 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: Is `1` the equivalent of `TiffTagConstants.PLANAR_CONFIGURATION_VALUE_PLANAR`? If so, I think we should use the constant? ########## 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: This code here (`readImageData(final Rectangle subImage)`) looks a lot like the code above for `readImageData(final ImageBuilder imageBuilder)`. Should we make a function to read strips and re-use in both methods? ########## 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: Can we use the constant `TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY` (not sure if the `1` here corresponds to that constant's value?)? ########## 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: Is `1` the equivalent of `TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY`? If so, I think we should use the constant? ########## 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: Is `1` the equivalent of `TiffTagConstants.PLANAR_CONFIGURATION_VALUE_PLANAR`? If so, I think we should use the constant? ---------------------------------------------------------------- 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