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 fed8f694946edfabfff56e2f6b379d4bd208a0ad
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Sep 16 17:00:30 2021 +0200

    Avoid a null `ColorModel` with some image shown in JavaFX applications.
---
 .../main/java/org/apache/sis/gui/dataset/ResourceExplorer.java    | 8 ++------
 .../org/apache/sis/internal/coverage/j2d/ColorModelFactory.java   | 7 +++++++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
index c295171..b19331f 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
@@ -388,7 +388,7 @@ public class ResourceExplorer extends WindowManager {
                 BackgroundThreads.execute(builder);
                 return;
             }
-            grid  = new ImageRequest((GridCoverageResource) resource, null, 0);
+            grid  = new ImageRequest((GridCoverageResource) resource, null, 
null);
             image = coverage.getDataView(CoverageExplorer.View.IMAGE);
             table = coverage.getDataView(CoverageExplorer.View.TABLE);
             type  = viewTab.isSelected() ? CoverageExplorer.View.IMAGE : 
CoverageExplorer.View.TABLE;
@@ -476,11 +476,7 @@ public class ResourceExplorer extends WindowManager {
         FeatureTable table = null;
         if (resource instanceof GridCoverageResource) {
             /*
-             * Want the full coverage in all bands (sample dimensions). This 
is different than
-             * the ImageRequest created by `updateDataTab(…)` which requested 
only an overview
-             * (i.e. potentially with subsampling) and only the first band.
-             *
-             * TODO: check if we can still share the coverage in some 
situations.
+             * Want the full coverage in all bands (sample dimensions).
              */
             grid = new ImageRequest((GridCoverageResource) resource, null, 
null);
         } else if (resource instanceof FeatureSet) {
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ColorModelFactory.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ColorModelFactory.java
index 3d258da..bb0e785 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ColorModelFactory.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ColorModelFactory.java
@@ -522,6 +522,13 @@ public final class ColorModelFactory {
             subset = ((MultiBandsIndexColorModel) 
cm).createSubsetColorModel(bands);
         } else if (cm instanceof ScaledColorModel) {
             subset = ((ScaledColorModel) cm).createSubsetColorModel(bands);
+        } else if (bands.length == 1 && cm instanceof ComponentColorModel) {
+            final int dataType = cm.getTransferType();
+            if (dataType < DataBuffer.TYPE_BYTE || dataType > 
DataBuffer.TYPE_USHORT) {
+                return Colorizer.NULL_COLOR_MODEL;
+            }
+            final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+            subset = new ComponentColorModel(cs, false, true, 
Transparency.OPAQUE, dataType);
         } else {
             // TODO: handle other color models.
             return Colorizer.NULL_COLOR_MODEL;

Reply via email to