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 1b1eb69ea9348727b9d774981855e56dcb383cd6 Author: Martin Desruisseaux <[email protected]> AuthorDate: Wed Nov 10 18:40:35 2021 +0100 Verify that the sample model size is compatible with image tile size. Bug identified by Alexis Manin. --- .../java/org/apache/sis/image/SourceAlignedImage.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java index 65e0b03..1c3724e 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java @@ -68,11 +68,27 @@ abstract class SourceAlignedImage extends ComputedImage { * @param source the image to use as a background for this image. */ protected SourceAlignedImage(final RenderedImage source) { - super(source.getSampleModel(), source); + super(getSampleModel(source), source); colorModel = source.getColorModel(); } /** + * Gets the sample model, making sure it has the right size. This is a workaround for RFE #4093999 + * ("Relax constraint on placement of this()/super() call in constructors"). + */ + @Workaround(library="JDK", version="1.8") + private static SampleModel getSampleModel(final RenderedImage source) { + final SampleModel sm = source.getSampleModel(); + final int width = source.getTileWidth(); + final int height = source.getTileHeight(); + if (sm.getWidth() == width && sm.getHeight() == height) { + return sm; + } else { + return sm.createCompatibleSampleModel(width, height); + } + } + + /** * Creates a new image with the given source, color model and sample model. * This constructor is not public because user could specify a sample model * with mismatched tile size.
