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 9c732194b95f21acd503ca5f6a7c855792621121
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Aug 3 12:34:08 2020 +0200
ResampleImage computes itself the ranges of values instead than invoking `PixelIterator.getSampleRanges()`,
because that later method returns ranges of source pixel values while we need ranges of
target pixel values.
---
.../java/org/apache/sis/image/ResampledImage.java | 20 +++++++++++---------
.../sis/internal/coverage/j2d/ImageUtilities.java | 15 +++++++++++++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
index 87de4f5..acb9b1e 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
@@ -39,12 +39,12 @@ import org.apache.sis.referencing.operation.transform.MathTransforms;
import org.apache.sis.internal.coverage.j2d.ImageUtilities;
import org.apache.sis.internal.feature.Resources;
import org.apache.sis.internal.system.Modules;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.geometry.Shapes2D;
-import org.apache.sis.measure.NumberRange;
import org.apache.sis.measure.Quantities;
import org.apache.sis.measure.Units;
@@ -585,7 +585,7 @@ public class ResampledImage extends ComputedImage {
ymax = domain.getMaxY() - 1;
xlim = xmax + support.width - 0.5; // Limit of coordinates where we
can interpolate.
ylim = ymax + support.height - 0.5;
- xoff = interpolationSupportOffset(support.width) - 0.5; // Always negative.
+ xoff = interpolationSupportOffset(support.width) - 0.5; //
Always negative.
yoff = interpolationSupportOffset(support.height) - 0.5;
}
/*
@@ -603,15 +603,17 @@ public class ResampledImage extends ComputedImage {
final boolean isInteger = (fillValues instanceof int[]);
if (isInteger) {
values = new double[numBands];
+ minValues = new long [numBands];
+ maxValues = new long [numBands];
intValues = new int[scanline * numBands];
valuesArray = intValues;
- final NumberRange<?>[] ranges = it.getSampleRanges(); // Assumes source.sampleModel
== this.sampleModel.
- minValues = new long[ranges.length];
- maxValues = new long[ranges.length];
- for (int i=0; i<ranges.length; i++) {
- final NumberRange<?> r = ranges[i];
- minValues[i] = r.getMinValue().longValue();
- maxValues[i] = r.getMaxValue().longValue();
+ for (int b=0; b<numBands; b++) {
+ maxValues[b] = Numerics.bitmask(sampleModel.getSampleSize(b)) - 1;
+ }
+ if (!ImageUtilities.isUnsignedType(sampleModel.getDataType())) {
+ for (int b=0; b<numBands; b++) {
+ minValues[b] = ~(maxValues[b] >>>= 1); // Convert unsigned
type to signed type range.
+ }
}
} else {
intValues = null;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
index f289d59..32b0d57 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
@@ -387,6 +387,21 @@ public final class ImageUtilities extends Static {
}
/**
+ * Returns {@code true} if the given data buffer type is an unsigned integer type.
+ * Returns {@code false} if the type is a floating point type or in case of doubt
+ * (e.g. for {@link DataBuffer#TYPE_UNDEFINED}).
+ *
+ * @param dataType one of {@link DataBuffer} constants.
+ * @return whether the given constant is for an unsigned integer type.
+ *
+ * @see #getDataType(RenderedImage)
+ * @see #getDataType(Raster)
+ */
+ public static boolean isUnsignedType(final int dataType) {
+ return dataType >= DataBuffer.TYPE_BYTE && dataType <= DataBuffer.TYPE_USHORT;
+ }
+
+ /**
* Converts a <var>x</var> pixel coordinates to a tile index.
*
* @param image the image containing tiles.
|