You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2020/08/13 01:21:13 UTC

[commons-imaging] branch master updated (789f157 -> 64461da)

This is an automated email from the ASF dual-hosted git repository.

kinow pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git.


    from 789f157  Merge pull request #92 from apache/dependabot/github_actions/actions/setup-java-v1.4.1
     new 00c2f34  [IMAGING-263]: Correction for indexing in partial raster
     new 560e8d6  [IMAGING-263]: Increase coverage in TIFF data reader
     new c376036  [IMAGING-263]: add changelog
     new 64461da  Merge branch 'pr-93'

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   4 +-
 .../formats/tiff/datareaders/DataReaderTiled.java  |   7 +-
 .../formats/tiff/TiffFloatingPointReadTest.java    | 105 ++++++++++++++-------
 3 files changed, 77 insertions(+), 39 deletions(-)


[commons-imaging] 04/04: Merge branch 'pr-93'

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 64461da4a981222e793e3031e1727efd464613be
Merge: 789f157 c376036
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Thu Aug 13 13:19:21 2020 +1200

    Merge branch 'pr-93'
    
    This closes #93

 src/changes/changes.xml                            |   4 +-
 .../formats/tiff/datareaders/DataReaderTiled.java  |   7 +-
 .../formats/tiff/TiffFloatingPointReadTest.java    | 105 ++++++++++++++-------
 3 files changed, 77 insertions(+), 39 deletions(-)


[commons-imaging] 01/04: [IMAGING-263]: Correction for indexing in partial raster

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 00c2f34f13c7ad2d06aa38dd4659fbd5fb82adb8
Author: gwlucastrig <co...@gmail.com>
AuthorDate: Wed Aug 12 18:48:20 2020 -0400

    [IMAGING-263]: Correction for indexing in partial raster
---
 .../formats/tiff/datareaders/DataReaderTiled.java  |   7 +-
 .../formats/tiff/TiffFloatingPointReadTest.java    | 100 ++++++++++++++-------
 2 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
index da11b01..9b8903b 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
@@ -324,17 +324,14 @@ public final class DataReaderTiled extends ImageDataReader {
 
         final int nColumnsOfTiles = (width + tileWidth - 1) / tileWidth;
 
-        final int x0 = col0 * tileWidth;
-        final int y0 = row0 * tileLength;
-
         for (int iRow = row0; iRow <= row1; iRow++) {
             for (int iCol = col0; iCol <= col1; iCol++) {
                 final int tile = iRow * nColumnsOfTiles + iCol;
                 final byte[] compressed = imageData.tiles[tile].getData();
                 final byte[] decompressed = decompress(compressed, compression,
                     bytesPerTile, tileWidth, tileLength);
-                int x = iCol * tileWidth - x0;
-                int y = iRow * tileLength - y0;
+                int x = iCol * tileWidth;
+                int y = iRow * tileLength;
                 int[] blockData = unpackFloatingPointSamples(
                     tileWidth, tileLength, tileWidth,
                     decompressed,
diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
index 12977e7..a73bf2e 100644
--- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
@@ -124,7 +124,6 @@ public class TiffFloatingPointReadTest {
     @Test
     public void test() {
         Map<String, Object> params = new HashMap<>();
-
         // These TIFF sample data includes files that contain known
         // floating-point values in various formats.  We know the range
         // of values from inspection using separate utilies. This
@@ -134,6 +133,7 @@ public class TiffFloatingPointReadTest {
         // code in the tabulation.  If you have a file that does not
         // define a no-data value, just use Float.NaN for testing purposes.
         try {
+            // Test the satellite-derived cloud imagery file -----------------------------
             // We know from inspection that this sample file contains values
             // in the range 0 to 1 and uses 9999 as a "no-data" value.
             File target = getTiffFile("Sample64BitFloatingPointPix451x337.tiff");
@@ -143,34 +143,43 @@ public class TiffFloatingPointReadTest {
             }
             float minVal = pInterp.getMinFound();
             float maxVal = pInterp.getMaxFound();
-
             boolean testCondition = 0.0 <= minVal && minVal <= 1.0 && 0.0 <= maxVal && maxVal <= 1.0;
             assertTrue(testCondition, "Min,Max values not in range 0 to 1: " + minVal + ", " + maxVal);
             assertTrue(minVal <= maxVal, "Min Value not <= maxVal: " + minVal + ", " + maxVal);
 
             // To test the sub-image logic, read the full raster and then
-            // the sub-raster.  Compare the results.  The offsets of
-            // 17 are just an arbitrary value not likely to align with
-            // any arbitrary features in the TIFF files.
-            params.clear();
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, 17);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, 17);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, 200);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, 200);
+            // the sub-raster.  Compare the results.  We know from inspection
+            // that the source file is organized using strips of 2 rows each.
+            // The source file is of dimensions 451x337.
+            // The dimensions of the sub-image are arbitrary
             TiffRasterData fullRaster = readRasterFromTIFF(target, null);
-            TiffRasterData partRaster = readRasterFromTIFF(target, params);
-            assertEquals(200, partRaster.getWidth(), "Invalid width in partial for " + target.getName());
-            assertEquals(200, partRaster.getHeight(), "Invalid height in partial for " + target.getName());
-            for (int y = 17; y < 217; y++) {
-                for (int x = 17; x < 217; x++) {
-                    float vFull = fullRaster.getValue(x, y);
-                    float vPart = partRaster.getValue(x - 17, y - 17);
-                    assertEquals(vFull, vPart, "Invalid value match for partial at (" + x + "," + y + ")");
-                }
+            int height = fullRaster.getHeight();
+            int width  = fullRaster.getWidth();
+            // checks based on the 2-rows per strip model
+            checkSubImage(target, fullRaster, 17, 17, 200, 200);
+            checkSubImage(target, fullRaster, 1, 3, width-2, 1);
+            checkSubImage(target, fullRaster, 1, 3, width-2, 3);
+            checkSubImage(target, fullRaster, 1, 4, width-2, 1);
+            checkSubImage(target, fullRaster, 1, 4, width-2, 3);
+            // check the 4 edges
+            checkSubImage(target, fullRaster, 0, 0, width, 1);         // bottom row
+            checkSubImage(target, fullRaster, 0, 0, 1, height);        // left column
+            checkSubImage(target, fullRaster, 0, height-1, width, 1);  // top row
+            checkSubImage(target, fullRaster, width-1, 0, 1, height);  // right column
+
+            // test along the main diagnonal and a parallel that reaches the top-right corner
+            int s = width-height;
+            for(int i=0; i<height-8; i++){
+                checkSubImage(target, fullRaster, i, i, 8, 8);
+                checkSubImage(target, fullRaster, i+1, i, 8, 8);
             }
 
+
+            // Test the USGS overview file ------------------------------
             // We know from inspection that this sample file contains values
             // in the range -2 to 62 and uses -99999 as a "no-data" value.
+            // The file is organized using tiles of size 128-by-128.
+            // and that the overall image size is 338-by-338.
             target = getTiffFile("USGS_13_n38w077_dir5.tiff");
             pInterp = readAndInterpretTIFF(target, -2f, 62f, -99999f);
             if (pInterp == null) {
@@ -182,24 +191,49 @@ public class TiffFloatingPointReadTest {
             assertTrue(testCondition, "Min,Max values not in range -2 to 62: " + minVal + ", " + maxVal);
             assertTrue(minVal <= maxVal, "Min Value not <= maxVal: " + minVal + ", " + maxVal);
 
-            params.clear();
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, 17);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, 17);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, 200);
-            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, 200);
             fullRaster = readRasterFromTIFF(target, null);
-            partRaster = readRasterFromTIFF(target, params);
-            assertEquals(200, partRaster.getWidth(), "Invalid width in partial for " + target.getName());
-            assertEquals(200, partRaster.getHeight(), "Invalid height in partial for " + target.getName());
-            for (int y = 17; y < 217; y++) {
-                for (int x = 17; x < 217; x++) {
+            // The tile size for this file is 128-by-128. The following tests
+            // read subsections starting right before the tile transition and right after it.
+            height = fullRaster.getHeight();
+            width  = fullRaster.getWidth();
+            // checks based on the 128-by-128 tile model
+            checkSubImage(target, fullRaster, 126, 126, 132, 132);
+            checkSubImage(target, fullRaster, 128, 128, 128, 128);
+            checkSubImage(target, fullRaster, 1, 1, width-2, height-2);
+            // check the 4 edges
+            checkSubImage(target, fullRaster, 0, 0, width, 1);         // bottom row
+            checkSubImage(target, fullRaster, 0, 0, 1, height);        // left column
+            checkSubImage(target, fullRaster, 0, height-1, width, 1);  // top row
+            checkSubImage(target, fullRaster, width-1, 0, 1, height);  // right column
+
+            // now test along the main diagonal
+            for(int i=0; i<height-8; i++){
+                checkSubImage(target, fullRaster, i, i, 8, 8);
+            }
+        } catch (ImageReadException | IOException ex) {
+            fail("Exception during test " + ex.getMessage());
+        }
+    }
+
+
+    private void checkSubImage(File target, TiffRasterData fullRaster, int x0, int y0, int width, int height){
+        try{
+            Map<String, Object> params = new HashMap<>();
+            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, x0);
+            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, y0);
+            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, width);
+            params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, height);
+            TiffRasterData partRaster = readRasterFromTIFF(target, params);
+            assertEquals(width, partRaster.getWidth(), "Invalid width in partial for " + target.getName());
+            assertEquals(height, partRaster.getHeight(), "Invalid height in partial for " + target.getName());
+            for (int y = y0; y < y0+height; y++) {
+                for (int x = x0; x < x0+width; x++) {
                     float vFull = fullRaster.getValue(x, y);
-                    float vPart = partRaster.getValue(x - 17, y - 17);
-                    assertEquals(vFull, vPart, "Invalid value match for partial at (" + x + "," + y + ")");
+                    float vPart = partRaster.getValue(x - x0, y - y0);
+                    assertEquals(vFull, vPart, "Invalid value match for partial at (" + x + "," + y + ") for "+target.getName());
                 }
             }
-
-        } catch (ImageReadException | IOException ex) {
+        }catch (ImageReadException | IOException ex) {
             fail("Exception during test " + ex.getMessage());
         }
     }


[commons-imaging] 03/04: [IMAGING-263]: add changelog

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit c376036f76af97f7aa6d6eaa9607e311aa3afb52
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Thu Aug 13 13:18:19 2020 +1200

    [IMAGING-263]: add changelog
---
 src/changes/changes.xml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 76af3e9..881ea2f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,7 +45,9 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
   <body>
     <release version="1.0-alpha3" date="2020-??-??" description="Third 1.0 alpha release">
-
+      <action issue="IMAGING-263" dev="kinow" type="fix" due-to"Gary Lucas">
+        Failure when reading a partial raster from a floating-point TIFF
+      </action>
     </release>
     <release version="1.0-alpha2" date="2020-08-01" description="Second 1.0 alpha release">
       <action issue="IMAGING-258" dev="kinow" type="update" due-to="Gary Lucas">


[commons-imaging] 02/04: [IMAGING-263]: Increase coverage in TIFF data reader

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 560e8d65252fb086f0aa9776488a7898a844acc9
Author: gwlucastrig <co...@gmail.com>
AuthorDate: Wed Aug 12 19:33:11 2020 -0400

    [IMAGING-263]: Increase coverage in TIFF data reader
---
 .../commons/imaging/formats/tiff/TiffFloatingPointReadTest.java      | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
index a73bf2e..0791fb8 100644
--- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffFloatingPointReadTest.java
@@ -174,6 +174,8 @@ public class TiffFloatingPointReadTest {
                 checkSubImage(target, fullRaster, i+1, i, 8, 8);
             }
 
+            // now read the entire image
+            checkSubImage(target, fullRaster, 0, 0, width, height);
 
             // Test the USGS overview file ------------------------------
             // We know from inspection that this sample file contains values
@@ -210,6 +212,9 @@ public class TiffFloatingPointReadTest {
             for(int i=0; i<height-8; i++){
                 checkSubImage(target, fullRaster, i, i, 8, 8);
             }
+            
+            // now read the entire image
+            checkSubImage(target, fullRaster, 0, 0, width, height);
         } catch (ImageReadException | IOException ex) {
             fail("Exception during test " + ex.getMessage());
         }