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 977ff0d3486e124c2afcf7fc830571788d50566a Author: Martin Desruisseaux <[email protected]> AuthorDate: Fri Feb 22 16:03:31 2019 +0100 Restore the resizing of array based on the actual number of elements. --- .../sis/internal/raster/ColorModelFactory.java | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/ColorModelFactory.java b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/ColorModelFactory.java index 7a535e7..e6ce4b8 100644 --- a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/ColorModelFactory.java +++ b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/ColorModelFactory.java @@ -16,26 +16,26 @@ */ package org.apache.sis.internal.raster; -import java.awt.Color; +import java.util.Map; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.function.Function; import java.awt.Transparency; +import java.awt.Color; import java.awt.color.ColorSpace; import java.awt.image.ColorModel; +import java.awt.image.IndexColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.DataBuffer; -import java.awt.image.IndexColorModel; -import java.util.Arrays; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; import org.apache.sis.coverage.Category; import org.apache.sis.coverage.SampleDimension; import org.apache.sis.measure.NumberRange; -import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.ArraysExt; +import org.apache.sis.util.ArgumentChecks; +import org.apache.sis.util.resources.Errors; import org.apache.sis.util.collection.WeakHashSet; import org.apache.sis.util.collection.WeakValueHashMap; -import org.apache.sis.util.resources.Errors; /** @@ -100,8 +100,10 @@ public final class ColorModelFactory { * In a color map defined by a piecewise function, indices where to store the first interpolated value in the color map. * The number of pieces (segments) is {@code pieceStarts.length}. The last element of this array is the index after the * end of the last piece. The indices are integers. Never {@code null} but may be empty. - * Note : indices as unsigned short won't work, in the worse case the last next index will be 65536 which would be - * converted to 0 as a short causing several exception afterward. + * + * <div class="note"><b>Note:</b> + * indices as unsigned short are not sufficient since in the worst case the last next index will + * be 65536, which would be converted to 0 as a short, causing several exception afterward.</div> */ private final int[] pieceStarts; @@ -186,6 +188,14 @@ public final class ColorModelFactory { minimum = 0; maximum = 1; } + /* + * The length of 'pieceStarts' may differ from the expected length if there is holes between categories. + * We need to adjust the array length since it will determine the number of categories. Note that there + * is one more element than the number of categories. + */ + if (starts.length != 0) { + starts = ArraysExt.resize(starts, count + 1); + } this.minimum = (float) minimum; this.maximum = (float) maximum; this.pieceStarts = starts;
