This is an automated email from the ASF dual-hosted git repository. jsorel 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 9d4fa26 Coverage : add GridCoverageBuilder tests 9d4fa26 is described below commit 9d4fa26b363b0e2d04ac3c0e15da0c9a5a92b010 Author: jsorel AuthorDate: Wed Mar 18 10:15:39 2020 +0100 Coverage : add GridCoverageBuilder tests --- .../sis/coverage/grid/GridCoverageBuilder.java | 131 +++++++++--------- .../coverage/j2d/BufferedGridCoverage.java | 15 ++- .../sis/coverage/grid/GridCoverageBuilderTest.java | 150 +++++++++++++++++++++ .../apache/sis/test/suite/FeatureTestSuite.java | 1 + 4 files changed, 228 insertions(+), 69 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java index d1d234b..fe89f23 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java @@ -17,7 +17,6 @@ package org.apache.sis.coverage.grid; import java.awt.image.DataBuffer; -import java.awt.image.DataBufferInt; import java.awt.image.RenderedImage; import java.util.ArrayList; import java.util.Arrays; @@ -64,71 +63,71 @@ public class GridCoverageBuilder { this.bufferNbSample = -1; } - /** - * Creates a coverage from the given matrix. - * This method copies the values from the given matrix to a new DataBuffer. - *

- * The coverage height will be the length of the {@code matrix} argument. - * The coverage width will be the length of the first row, all rows are expected - * to have the same length. - * - * @param matrix The matrix data in a {@code [row][column]} layout. - * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. - */ - public void setValues(int[][] matrix) throws ArithmeticException { - final int height = matrix.length; - final int width = matrix[0].length; - final int[] datas = new int[StrictMath.toIntExact( ((long) height) * width)]; - for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { - System.arraycopy(matrix[i], 0, datas, offset, width); - } - final DataBuffer buffer = new DataBufferInt(datas, datas.length); - setValues(buffer, width, height); - } - - /** - * Creates a coverage from the given matrix. - * This method copies the values from the given matrix to a new DataBuffer. - *

- * The coverage height will be the length of the {@code matrix} argument. - * The coverage width will be the length of the first row, all rows are expected - * to have the same length. - * - * @param matrix The matrix data in a {@code [row][column]} layout. - * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. - */ - public void setValues(float[][] matrix) throws ArithmeticException { - final int height = matrix.length; - final int width = matrix[0].length; - final int[] datas = new int[StrictMath.toIntExact( ((long) height) * width)]; - for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { - System.arraycopy(matrix[i], 0, datas, offset, width); - } - final DataBuffer buffer = new DataBufferInt(datas, datas.length); - setValues(buffer, width, height); - } - - /** - * Creates a coverage from the given matrix. - * This method copies the values from the given matrix to a new DataBuffer. - *

- * The coverage height will be the length of the {@code matrix} argument. - * The coverage width will be the length of the first row, all rows are expected - * to have the same length. - * - * @param matrix The matrix data in a {@code [row][column]} layout. - * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. - */ - public void setValues(double[][] matrix) throws ArithmeticException { - final int height = matrix.length; - final int width = matrix[0].length; - final int[] datas = new int[StrictMath.toIntExact( ((long) height) * width)]; - for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { - System.arraycopy(matrix[i], 0, datas, offset, width); - } - final DataBuffer buffer = new DataBufferInt(datas, datas.length); - setValues(buffer, width, height); - } +// /** +// * Creates a coverage from the given matrix. +// * This method copies the values from the given matrix to a new DataBuffer. +// *

+// * The coverage height will be the length of the {@code matrix} argument. +// * The coverage width will be the length of the first row, all rows are expected +// * to have the same length. +// * +// * @param matrix The matrix data in a {@code [row][column]} layout. +// * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. +// */ +// public void setValues(int[][] matrix) throws ArithmeticException { +// final int height = matrix.length; +// final int width = matrix[0].length; +// final int[] datas = new int[Math.multiplyExact(height,width)]; +// for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { +// System.arraycopy(matrix[i], 0, datas, offset, width); +// } +// final DataBuffer buffer = new DataBufferInt(datas, datas.length); +// setValues(buffer, width, height); +// } +// +// /** +// * Creates a coverage from the given matrix. +// * This method copies the values from the given matrix to a new DataBuffer. +// *

+// * The coverage height will be the length of the {@code matrix} argument. +// * The coverage width will be the length of the first row, all rows are expected +// * to have the same length. +// * +// * @param matrix The matrix data in a {@code [row][column]} layout. +// * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. +// */ +// public void setValues(float[][] matrix) throws ArithmeticException { +// final int height = matrix.length; +// final int width = matrix[0].length; +// final float[] datas = new float[Math.multiplyExact(height,width)]; +// for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { +// System.arraycopy(matrix[i], 0, datas, offset, width); +// } +// final DataBuffer buffer = new DataBufferFloat(datas, datas.length); +// setValues(buffer, width, height); +// } +// +// /** +// * Creates a coverage from the given matrix. +// * This method copies the values from the given matrix to a new DataBuffer. +// *

+// * The coverage height will be the length of the {@code matrix} argument. +// * The coverage width will be the length of the first row, all rows are expected +// * to have the same length. +// * +// * @param matrix The matrix data in a {@code [row][column]} layout. +// * @throws ArithmeticException if the buffer size exceeds the {@code int} capacity. +// */ +// public void setValues(double[][] matrix) throws ArithmeticException { +// final int height = matrix.length; +// final int width = matrix[0].length; +// final double[] datas = new double[Math.multiplyExact(height,width)]; +// for (int i = 0, offset=0; i < matrix.length; i++,offset+=width) { +// System.arraycopy(matrix[i], 0, datas, offset, width); +// } +// final DataBuffer buffer = new DataBufferDouble(datas, datas.length); +// setValues(buffer, width, height); +// } /** * Creates a coverage from the given buffer. diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BufferedGridCoverage.java b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BufferedGridCoverage.java index f11cf6d..061c079 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BufferedGridCoverage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BufferedGridCoverage.java @@ -16,7 +16,6 @@ */ package org.apache.sis.internal.coverage.j2d; -import java.util.Collection; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.DataBufferDouble; @@ -26,15 +25,15 @@ import java.awt.image.DataBufferShort; import java.awt.image.DataBufferUShort; import java.awt.image.RasterFormatException; import java.awt.image.RenderedImage; +import java.util.Collection; import org.apache.sis.coverage.SampleDimension; import org.apache.sis.coverage.grid.GridCoverage; import org.apache.sis.coverage.grid.GridExtent; import org.apache.sis.coverage.grid.GridGeometry; +import org.apache.sis.coverage.grid.IllegalGridGeometryException; import org.apache.sis.coverage.grid.ImageRenderer; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; - -// Branch-specific imports import org.opengis.coverage.CannotEvaluateException; @@ -67,6 +66,16 @@ public class BufferedGridCoverage extends GridCoverage { super(grid, bands); this.data = data; ArgumentChecks.ensureNonNull("data", data); + + //verify buffer size + GridExtent extent = grid.getExtent(); + long expectedSize = extent.getSize(0) * bands.size(); + for (int i = 1; i