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 e05004b7dd43402d48dbbaa28ced0ae22b68756b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Sep 3 12:03:03 2020 +0200
If the image to resample is too small for the specified interpolation, use nearest neighbor.
It happens if user tries to apply a bilinear interpolation on an image of size 1×1 pixel
(an image of such size if typically a template for ColorModel and SampleModel).
---
.../src/main/java/org/apache/sis/image/ResampledImage.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 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 592b921..de94d0d 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
@@ -202,7 +202,7 @@ public class ResampledImage extends ComputedImage {
* @see ImageProcessor#resample(RenderedImage, Rectangle, MathTransform)
*/
protected ResampledImage(final RenderedImage source, final SampleModel sampleModel, final
Point minTile,
- final Rectangle bounds, final MathTransform toSource, final Interpolation interpolation,
+ final Rectangle bounds, final MathTransform toSource, Interpolation interpolation,
final Number[] fillValues, final Quantity<?>[] accuracy)
{
super(sampleModel, source);
@@ -240,8 +240,12 @@ public class ResampledImage extends ComputedImage {
* point will be between the second and third pixel, so there is one more pixel on
the left
* to grab. We shift to the left because we need the coordinates of the first pixel.
*/
+ Dimension s = interpolation.getSupportSize();
+ if (s.width > width || s.height > height) {
+ interpolation = Interpolation.NEAREST;
+ s = interpolation.getSupportSize();
+ }
this.interpolation = interpolation;
- final Dimension s = interpolation.getSupportSize();
final double[] offset = new double[numDim];
offset[0] = interpolationSupportOffset(s.width);
offset[1] = interpolationSupportOffset(s.height);
|