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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 9a6ace7 Remove one level of indirection when the image given to
GridCoverage2D is a RelocatedImage. Relax the check for sample model size
compared to tile size.
9a6ace7 is described below
commit 9a6ace7be484f8b8320e91ec7e89fb6cd36bb323
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sun Dec 29 11:38:59 2019 +0100
Remove one level of indirection when the image given to GridCoverage2D is a
RelocatedImage.
Relax the check for sample model size compared to tile size.
---
.../apache/sis/coverage/grid/GridCoverage2D.java | 21 +++++++++++++++++++--
.../apache/sis/coverage/grid/RelocatedImage.java | 7 +++----
.../sis/internal/coverage/j2d/PlanarImage.java | 8 ++++++--
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
index ad0e279..614fa86 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -171,8 +171,8 @@ public class GridCoverage2D extends GridCoverage {
* @throws IllegalArgumentException if the image number of bands is not
the same than the number of sample dimensions.
* @throws ArithmeticException if the distance between grid location and
image location exceeds the {@code long} capacity.
*/
- public GridCoverage2D(GridGeometry domain, final Collection<? extends
SampleDimension> range, final RenderedImage data) {
- super(domain = addExtentIfAbsent(domain, data), defaultIfAbsent(range,
data));
+ public GridCoverage2D(GridGeometry domain, final Collection<? extends
SampleDimension> range, RenderedImage data) {
+ super(domain = addExtentIfAbsent(domain, data =
unwrapIfSameSize(data)), defaultIfAbsent(range, data));
this.data = data; // Non-null verified by
addExtentIfAbsent(…, data).
/*
* Find indices of the two dimensions of the slice. Those dimensions
are usually 0 for x and 1 for y,
@@ -204,6 +204,21 @@ public class GridCoverage2D extends GridCoverage {
}
/**
+ * Returns the wrapped image if the only difference is a translation, or
{@code data} otherwise.
+ * Workaround for RFE #4093999 ("Relax constraint on placement of
this()/super() call in constructors").
+ */
+ @Workaround(library="JDK", version="1.8")
+ private static RenderedImage unwrapIfSameSize(RenderedImage data) {
+ if (data instanceof RelocatedImage) {
+ final RenderedImage image = ((RelocatedImage) data).image;
+ if (image.getWidth() == data.getWidth() && image.getHeight() ==
data.getHeight()) {
+ data = image;
+ }
+ }
+ return data;
+ }
+
+ /**
* If the given domain does not have a {@link GridExtent}, creates a new
grid geometry
* with an extent computed from the given image. The new grid will start
at the same
* location than the image and will have the same size.
@@ -480,6 +495,7 @@ public class GridCoverage2D extends GridCoverage {
* @see BufferedImage#getSubimage(int, int, int, int)
*/
@Override
+ @SuppressWarnings("AssertWithSideEffects")
public RenderedImage render(final GridExtent sliceExtent) throws
CannotEvaluateException {
if (sliceExtent == null) {
return data;
@@ -525,6 +541,7 @@ public class GridCoverage2D extends GridCoverage {
* (5,5) but the image to return starts at (1,1), then we need to
set its location to (-4,-4).
*/
final RelocatedImage r = new RelocatedImage(data, xmin, ymin,
xmax, ymax);
+ String error; assert (error = r.verify()) != null : error;
return r.isIdentity() ? data : r;
} catch (ArithmeticException e) {
throw new CannotEvaluateException(e.getMessage(), e);
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/RelocatedImage.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/RelocatedImage.java
index 3396556..2110dc0 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/RelocatedImage.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/RelocatedImage.java
@@ -49,7 +49,7 @@ final class RelocatedImage extends PlanarImage {
/**
* The image to translate.
*/
- private final RenderedImage image;
+ final RenderedImage image;
/**
* Value to add for converting a column index from the coordinate system
of the wrapped image
@@ -141,9 +141,8 @@ final class RelocatedImage extends PlanarImage {
* Returns {@code true} if this image does not move and does not subset
the wrapped image.
*/
final boolean isIdentity() {
- return offsetX == 0 && offsetY == 0 &&
- minX == image.getMinX() && width == image.getWidth() &&
- minY == image.getMinY() && height == image.getHeight();
+ // The use of >= is a paranoiac check, but the > case should never
happen actually.
+ return offsetX == 0 && offsetY == 0 && width >= image.getWidth() &&
height >= image.getHeight();
}
/**
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
index 27e13dd..76a350f 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
@@ -330,8 +330,12 @@ public abstract class PlanarImage implements RenderedImage
{
final int tileHeight = getTileHeight();
final SampleModel sm = getSampleModel();
if (sm != null) {
- if (sm.getWidth() != tileWidth) return "tileWidth";
- if (sm.getHeight() != tileHeight) return "tileHeight";
+ /*
+ * The SampleModel size represents the physical layout of pixels
in the data buffer,
+ * while the Raster may be a virtual view over a sub-region of a
parent raster.
+ */
+ if (sm.getWidth() < tileWidth) return "tileWidth";
+ if (sm.getHeight() < tileHeight) return "tileHeight";
final ColorModel cm = getColorModel();
if (cm != null) {
if (!cm.isCompatibleSampleModel(sm)) return "SampleModel";