You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2021/10/28 11:25:04 UTC
[sis] 04/04: Fix a problem with `IndexColorModel` creation for
1-bit TIFF images.
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 0e4421bd37d4432d3ac82c2f16bc0abe12db68a2
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Oct 28 13:21:34 2021 +0200
Fix a problem with `IndexColorModel` creation for 1-bit TIFF images.
---
.../apache/sis/internal/coverage/j2d/ColorModelFactory.java | 12 ++++++------
.../org/apache/sis/storage/geotiff/ImageFileDirectory.java | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
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 bb0e785..615fd71 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
@@ -42,7 +42,7 @@ import org.apache.sis.util.Debug;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Johann Sorel (Geomatys)
- * @version 1.1
+ * @version 1.2
* @since 1.0
* @module
*/
@@ -382,21 +382,21 @@ public final class ColorModelFactory {
/**
* Returns a color model interpolated for the given range of values. This is a convenience method for
- * {@link #createColorModel(int, int, int, Collection)} when the collection contains only one element.
+ * {@link #createPiecewise(int, int, int, Collection)} when the collection contains only one element.
*
* @param dataType the color model type.
* @param numBands the number of bands for the color model (usually 1).
* @param visibleBand the band to be made visible (usually 0). All other bands (if any) will be ignored.
- * @param minimum the minimum value, inclusive.
- * @param maximum the maximum value, inclusive.
+ * @param lower the minimum value, inclusive.
+ * @param upper the maximum value, exclusive.
* @param colors the colors to use for the range of sample values.
* @return a color model suitable for {@link java.awt.image.RenderedImage} objects with values in the given ranges.
*/
public static ColorModel createColorScale(final int dataType, final int numBands, final int visibleBand,
- final double minimum, final double maximum, final Color... colors)
+ final double lower, final double upper, final Color... colors)
{
return createPiecewise(dataType, numBands, visibleBand, new ColorsForRange[] {
- new ColorsForRange(null, new NumberRange<>(Double.class, minimum, true, maximum, true), colors)
+ new ColorsForRange(null, new NumberRange<>(Double.class, lower, true, upper, false), colors)
});
}
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index 7600546..4430848 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -1446,7 +1446,7 @@ final class ImageFileDirectory extends DataCube {
for (int band = 0; band < samplesPerPixel;) {
NumberRange<?> sampleRange = null;
if (minValues != null && maxValues != null) {
- sampleRange = NumberRange.createBestFit(
+ sampleRange = NumberRange.createBestFit(sampleFormat == FLOAT,
minValues.get(Math.min(band, minValues.size()-1)), true,
maxValues.get(Math.min(band, maxValues.size()-1)), true);
}
@@ -1582,9 +1582,9 @@ final class ImageFileDirectory extends DataCube {
ArraysExt.swap(colors, 0, 1);
}
double min = 0;
- double max = Numerics.bitmask(bitsPerSample) - 1;
- if (minValues != null) min = Math.max(minValues.doubleValue(visibleBand), min);
- if (maxValues != null) max = Math.min(maxValues.doubleValue(visibleBand), max);
+ double max = Numerics.bitmask(bitsPerSample); // Exclusive.
+ if (minValues != null) min = Math.max(min, minValues.doubleValue(visibleBand));
+ if (maxValues != null) max = Math.min(max, maxValues.doubleValue(visibleBand) + 1);
colorModel = ColorModelFactory.createColorScale(dataType, samplesPerPixel, visibleBand, min, max, colors);
break;
}