[ 
https://issues.apache.org/jira/browse/IMAGING-311?focusedWorklogId=668683&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-668683
 ]

ASF GitHub Bot logged work on IMAGING-311:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Oct/21 22:59
            Start Date: 21/Oct/21 22:59
    Worklog Time Spent: 10m 
      Work Description: 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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 668683)
    Time Spent: 50m  (was: 40m)

> Read TIFFs with multiple floating-point samples
> -----------------------------------------------
>
>                 Key: IMAGING-311
>                 URL: https://issues.apache.org/jira/browse/IMAGING-311
>             Project: Commons Imaging
>          Issue Type: New Feature
>          Components: Format: TIFF
>    Affects Versions: 1.0-alpha2
>         Environment: 
> [IMAGING-251|https://issues.apache.org/jira/browse/IMAGING-251]
>            Reporter: Gary Lucas
>            Assignee: Bruno P. Kinoshita
>            Priority: Major
>             Fix For: 1.0-alpha3
>
>         Attachments: NBS_Example.jpg
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> I propose to extend Commons Imaging to support reading TIFF files that 
> contain floating-point formats that feature more than one sample.  The 
> ability to support floating-point samples was introduced in  
> [ISSUE-251|https://issues.apache.org/jira/browse/IMAGING-251].  But that 
> implementation was limited to only those files that provided a single sample 
> per raster cell (e.g. "a single sample per pixel"). The ability to read files 
> with multiple samples per raster cell would extend the usefulness of the 
> Commons Imaging API, particularly for geophysical applications.
> If anyone knows of good sources for test TIFF files that use this format, 
> please let me know.
> *Background*
> In addition to conventional image data, TIFF files can provide floating-point 
> numerical information.  This feature is often used for geophysical data (in 
> GeoTIFF files), but can also be applied to other uses.  Although the existing 
> implementation can support files which give a single value per raster cell, 
> there are some products that carry multiple samples per cell. Examples 
> include products that give both a measured value and a corresponding accuracy 
> estimate (i.e. 245.6 meters plus or minus 0.5 meters). Some geophysical 
> products give vectors (gravitational potential, wind vectors, ocean currents, 
> etc.).
> Changes would involve extensions to the classes in the TIFF datareader 
> package as well as the TiffRasterData class.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to