sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Disable interpolations on image using an IndexColorModel.
Date Sat, 12 Sep 2020 14:47:29 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

commit a56b98f503a6a448392d4f041569de9fd745849f
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Sep 12 15:45:46 2020 +0200

    Disable interpolations on image using an IndexColorModel.
---
 .../main/java/org/apache/sis/image/ResampledImage.java    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
index 2e54c40..84ae73e 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
@@ -25,6 +25,7 @@ import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
+import java.awt.image.IndexColorModel;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
 import java.awt.image.WritableRaster;
@@ -241,6 +242,20 @@ public class ResampledImage extends ComputedImage {
                     Errors.Keys.MismatchedDimension_3, "toSource", BIDIMENSIONAL, numDim));
         }
         /*
+         * If the image uses an index color model, interpolating the indexed values does
not produce
+         * the expected colors. Safest approach is to disable completely interpolations in
that case.
+         *
+         * Note: we could interpolate if we knew that all index values, without exception
(i.e. no index for
+         * missing values), are related to measurements by a linear function. It practice
it rarely happens,
+         * because there is usually at least one index value reserved for missing values.
Scientific data in
+         * SIS are usually stored as floating point type (with missing values mapped to NaN),
which can not
+         * be associated to `IndexColorModel`. For now we don't try to perform a more sophisticated
detection
+         * of which interpolations are allowed, but a future SIS version may revisit this
policy if needed.
+         */
+        if (source.getColorModel() instanceof IndexColorModel) {
+            interpolation = Interpolation.NEAREST;
+        }
+        /*
          * If the interpolation requires more than 2×2 pixels, we will need to shift the
transform
          * to source image. For example if the interpolation requires 4×4 pixels, the interpolation
          * point will be between the second and third pixel, so there is one more pixel on
the left


Mime
View raw message