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

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

commit a2886d110b06bc13f3d52007aa98660ec52dfacd
Author: jsorel <[email protected]>
AuthorDate: Tue Nov 10 10:03:01 2026 +0100

    fix(SE1): fix gamma value can be combined with normalize or histogram
---
 .../apache/sis/style/se1/ContrastEnhancement.java  | 21 ++++++++++-----------
 .../org/apache/sis/style/se1/ContrastMethod.java   |  7 -------
 .../sis/style/se1/ContrastEnhancementTest.java     | 22 +++++++++++++++++++++-
 3 files changed, 31 insertions(+), 19 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastEnhancement.java
 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastEnhancement.java
index dfe1298c6c..1d254e9539 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastEnhancement.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastEnhancement.java
@@ -72,6 +72,8 @@ public class ContrastEnhancement<R> extends StyleElement<R> {
 
     /**
      * Returns the method to use for applying contrast enhancement.
+     * If no method has been explicitly set, then the default is {@link 
ContrastMethod#NONE}
+     * if a {@linkplain #getGammaValue() gamma value} has been set, or {@link 
ContrastMethod#NONE} otherwise.
      *
      * @return method to use for applying contrast enhancement.
      */
@@ -80,21 +82,19 @@ public class ContrastEnhancement<R> extends StyleElement<R> 
{
         if (value != null) {
             return value;
         }
-        return (gammaValue != null) ? ContrastMethod.GAMMA : 
ContrastMethod.NONE;
+        return ContrastMethod.NONE;
     }
 
     /**
      * Sets the method to use for applying contrast enhancement.
-     * Setting this method to anything else than {@link ContrastMethod#GAMMA}
-     * clears the {@linkplain #getGammaValue() gamma value}.
+     * This method does not change the {@linkplain #getGammaValue() gamma 
value}, which can be combined
+     * with the {@link ContrastMethod#NORMALIZE} and {@link 
ContrastMethod#HISTOGRAM} methods,
+     * as allowed by OGC 05-077r4.
      *
-     * @param  value  new method to use, or {@code null} for none.
+     * @param  value  new method to use, or {@code null} for the default.
      */
     public void setMethod(final ContrastMethod value) {
         method = value;
-        if (value != ContrastMethod.GAMMA) {
-            gammaValue = null;
-        }
     }
 
     /**
@@ -109,16 +109,15 @@ public class ContrastEnhancement<R> extends 
StyleElement<R> {
 
     /**
      * Sets how much to brighten (values greater than 1) or dim (values less 
than 1) an image.
-     * Setting a non-null value sets the method to {@link 
ContrastMethod#GAMMA}.
+     * This method does not change the {@linkplain #getMethod() method}: the 
gamma value can be combined
+     * with the {@link ContrastMethod#NORMALIZE} and {@link 
ContrastMethod#HISTOGRAM} methods.
+     * If no method has been explicitly set, then a non-null gamma value 
implies {@link ContrastMethod#GAMMA}.
      * If this method is never invoked, then the default value is literal 1.
      *
      * @param  value  new expression to control gamma adjustment, or {@code 
null} for the default.
      */
     public void setGammaValue(final Expression<R, ? extends Number> value) {
         gammaValue = value;
-        if (value != null) {
-            method = null;
-        }
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastMethod.java
 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastMethod.java
index f3695f65ab..59ffcd8ad6 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastMethod.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/se1/ContrastMethod.java
@@ -37,13 +37,6 @@ public enum ContrastMethod {
      */
     HISTOGRAM,
 
-    /**
-     * Contrast based on a gamma value.
-     * A gamma value tells how much to brighten (value greater than 1)
-     * or dim (value less than 1) an image, with 1 meaning no change.
-     */
-    GAMMA,
-
     /**
      * No enhancement.
      * This is the default value.
diff --git 
a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/se1/ContrastEnhancementTest.java
 
b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/se1/ContrastEnhancementTest.java
index dacabbd561..a3abf0372b 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/se1/ContrastEnhancementTest.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/se1/ContrastEnhancementTest.java
@@ -61,6 +61,26 @@ public final class ContrastEnhancementTest extends 
StyleTestCase {
         // Check get/set
         cdt.setGammaValue(literal(2));
         assertLiteralEquals(2, cdt.getGammaValue());
-        assertEquals(ContrastMethod.GAMMA, cdt.getMethod());
+        assertEquals(ContrastMethod.NONE, cdt.getMethod());
+    }
+
+    /**
+     * Verifies that a gamma value can be combined with the normalize or 
histogram method.
+     * OGC 05-077r4 and OGC 02-070 allow {@code <GammaValue>} after {@code 
<Normalize>} or {@code <Histogram>}.
+     * The result shall not depend on the order in which the properties are 
set.
+     */
+    @Test
+    public void testMethodWithGammaValue() {
+        var cdt = factory.createContrastEnhancement();
+        cdt.setMethod(ContrastMethod.NORMALIZE);
+        cdt.setGammaValue(literal(2.5));
+        assertEquals(ContrastMethod.NORMALIZE, cdt.getMethod());
+        assertLiteralEquals(2.5, cdt.getGammaValue());
+
+        cdt = factory.createContrastEnhancement();
+        cdt.setGammaValue(literal(2.5));
+        cdt.setMethod(ContrastMethod.HISTOGRAM);
+        assertEquals(ContrastMethod.HISTOGRAM, cdt.getMethod());
+        assertLiteralEquals(2.5, cdt.getGammaValue());
     }
 }

Reply via email to