sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Workaround a bug of BufferedImage.getTileGridXOffset() / getTileGridYOffset() not returning zero (contrarily to what their javadoc said).
Date Fri, 21 Feb 2020 14:00:53 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new c46f427  Workaround a bug of BufferedImage.getTileGridXOffset() / getTileGridYOffset()
not returning zero (contrarily to what their javadoc said).
c46f427 is described below

commit c46f42703ab6eb92632150a2790de259e11bf397
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Feb 21 14:59:19 2020 +0100

    Workaround a bug of BufferedImage.getTileGridXOffset() / getTileGridYOffset() not returning
zero (contrarily to what their javadoc said).
---
 .../main/java/org/apache/sis/image/PixelIterator.java  | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
index 4235a5d..9732efc 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -24,6 +24,7 @@ import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
+import java.awt.image.BufferedImage;
 import java.awt.image.RenderedImage;
 import java.awt.image.WritableRaster;
 import java.awt.image.WritableRenderedImage;
@@ -109,8 +110,8 @@ public abstract class PixelIterator {
 
     /**
      * The domain, in tile coordinates, of the region traversed by this pixel iterator.
-     * This may be smaller than the image or raster tile grid bounds, but not greater.
-     * The lower values are inclusive and the upper values exclusive.
+     * The tile index ranges may be smaller than the ranges of valid indices in image,
+     * but not greater. The lower values are inclusive and the upper values exclusive.
      */
     final int tileLowerX, tileLowerY, tileUpperX, tileUpperY;
 
@@ -308,6 +309,16 @@ public abstract class PixelIterator {
          */
         public PixelIterator create(final RenderedImage data) {
             ArgumentChecks.ensureNonNull("data", data);
+            if (data instanceof BufferedImage) {
+                return create(((BufferedImage) data).getRaster());
+            }
+            /*
+             * Note: As of Java 14, `BufferedImage.getTileGridXOffset()` and `getTileGridYOffset()`
have a bug.
+             * They should return `BufferedImage.getMinX()` (which is always 0) because the
image contains only
+             * one tile at index (0,0).  But they return `raster.getSampleModelTranslateX()`
instead, which may
+             * be non-zero if the image is a sub-region of another image.  Delegating to
`create(Raster)` avoid
+             * this problem in addition of being a slight optimization.
+             */
             if (order == SequenceType.LINEAR) {
                 return new LinearIterator(data, null, subArea, window);
             } else if (order != null) {
@@ -336,6 +347,9 @@ public abstract class PixelIterator {
          */
         public WritablePixelIterator createWritable(final WritableRenderedImage data) {
             ArgumentChecks.ensureNonNull("data", data);
+            if (data instanceof BufferedImage) {
+                return createWritable(((BufferedImage) data).getRaster());
+            }
             return createWritable(data, data);
         }
 


Mime
View raw message