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 2022/01/08 09:36:58 UTC

[commons-imaging] branch master updated: Simplify conditions and avoid extra computations.

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


The following commit(s) were added to refs/heads/master by this push:
     new 5efcccd  Simplify conditions and avoid extra computations.
5efcccd is described below

commit 5efcccd909bb8fe76ab36f474c1701790ffbf495
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Fri Jan 7 22:56:42 2022 +0100

    Simplify conditions and avoid extra computations.
---
 pom.xml                                                   |  3 +++
 .../apache/commons/imaging/palette/ColorSpaceSubset.java  |  1 -
 .../apache/commons/imaging/palette/PaletteFactory.java    | 15 +++++----------
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/pom.xml b/pom.xml
index c4df085..552216d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -487,5 +487,8 @@
     <contributor>
       <name>Wanja Gayk</name>
     </contributor>
+    <contributor>
+      <name>Arturo Bernal</name>
+    </contributor>
   </contributors>
 </project>
diff --git a/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java b/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
index ea2a74c..d3e9975 100644
--- a/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
+++ b/src/main/java/org/apache/commons/imaging/palette/ColorSpaceSubset.java
@@ -42,7 +42,6 @@ class ColorSpaceSubset {
         mins = new int[PaletteFactory.COMPONENTS];
         maxs = new int[PaletteFactory.COMPONENTS];
         for (int i = 0; i < PaletteFactory.COMPONENTS; i++) {
-            mins[i] = 0;
             maxs[i] = precisionMask;
         }
 
diff --git a/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java b/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
index 9068c80..99ae006 100644
--- a/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
+++ b/src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java
@@ -145,11 +145,6 @@ public class PaletteFactory {
             return null;
         }
 
-        final int remainder = total - sum;
-        if ((remainder < 1) || (remainder >= total)) {
-            return null;
-        }
-
         final int[] sliceMins = new int[subset.mins.length];
         System.arraycopy(subset.mins, 0, sliceMins, 0, subset.mins.length);
         final int[] sliceMaxs = new int[subset.maxs.length];
@@ -268,8 +263,8 @@ public class PaletteFactory {
         }
     }
 
-    private List<ColorSpaceSubset> divide(final List<ColorSpaceSubset> v,
-            final int desiredCount, final int[] table, final int precision) {
+    private void divide(final List<ColorSpaceSubset> v,
+                        final int desiredCount, final int[] table, final int precision) {
         final List<ColorSpaceSubset> ignore = new ArrayList<>();
 
         while (true) {
@@ -292,7 +287,7 @@ public class PaletteFactory {
             }
 
             if (maxSubset == null) {
-                return v;
+                return;
             }
             if (LOGGER.isLoggable(Level.FINEST)) {
                 LOGGER.finest("\t" + "area: " + maxArea);
@@ -309,7 +304,7 @@ public class PaletteFactory {
             }
 
             if (v.size() == desiredCount) {
-                return v;
+                return;
             }
         }
     }
@@ -359,7 +354,7 @@ public class PaletteFactory {
             LOGGER.finest("width * height: " + (width * height));
         }
 
-        subsets = divide(subsets, max, table, precision);
+        divide(subsets, max, table, precision);
 
         if (LOGGER.isLoggable(Level.FINEST)) {
             LOGGER.finest("subsets: " + subsets.size());