From commits-return-13382-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Wed Mar 18 09:16:07 2020 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id E89031A4FB for ; Wed, 18 Mar 2020 09:16:06 +0000 (UTC) Received: (qmail 8576 invoked by uid 500); 18 Mar 2020 09:16:06 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 8480 invoked by uid 500); 18 Mar 2020 09:16:06 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 8430 invoked by uid 99); 18 Mar 2020 09:16:05 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Mar 2020 09:16:05 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id CEC768DACA; Wed, 18 Mar 2020 09:16:05 +0000 (UTC) Date: Wed, 18 Mar 2020 09:16:05 +0000 To: "commits@sis.apache.org" Subject: [sis] branch geoapi-4.0 updated: Coverage : add GridCoverageBuilder tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <158452296579.7238.17993695041221480020@gitbox.apache.org> From: jsorel@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sis X-Git-Refname: refs/heads/geoapi-4.0 X-Git-Reftype: branch X-Git-Oldrev: 8f1e80667c5b2249d405b0aedd380c1040d966be X-Git-Newrev: 9d4fa26b363b0e2d04ac3c0e15da0c9a5a92b010 X-Git-Rev: 9d4fa26b363b0e2d04ac3c0e15da0c9a5a92b010 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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