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 ca3387e Move RelocatedImage as a package-private class accessible
(for now) only from public static function. Rename AbstractRenderedImage as
PlanarImage (taking inspiration from Java Advanced Imaging - JAI) with the
intent to set it as the base class of most RenderedImage implementations in
Apache SIS.
ca3387e is described below
commit ca3387e0e23f4a3fc77a843105e7cd175c3c03cc
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Dec 26 23:29:15 2019 +0100
Move RelocatedImage as a package-private class accessible (for now) only
from public static function.
Rename AbstractRenderedImage as PlanarImage (taking inspiration from Java
Advanced Imaging - JAI)
with the intent to set it as the base class of most RenderedImage
implementations in Apache SIS.
---
.../apache/sis/coverage/grid/GridCoverage2D.java | 4 +-
.../java/org/apache/sis/image/ImageOperations.java | 60 ++++++++++++++++++++++
.../coverage/j2d => image}/RelocatedImage.java | 18 +++----
.../java/org/apache/sis/image/package-info.java | 2 +-
...AbstractRenderedImage.java => PlanarImage.java} | 14 +++--
.../coverage/j2d => image}/RelocatedImageTest.java | 3 +-
...RenderedImageTest.java => PlanarImageTest.java} | 16 +++---
.../apache/sis/test/suite/FeatureTestSuite.java | 6 +--
8 files changed, 94 insertions(+), 29 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 fa8473d..31a35dd 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
@@ -36,9 +36,9 @@ import org.opengis.referencing.datum.PixelInCell;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;
import org.apache.sis.coverage.SampleDimension;
+import org.apache.sis.image.ImageOperations;
import org.apache.sis.internal.coverage.j2d.ImageUtilities;
import org.apache.sis.internal.coverage.j2d.ConvertedGridCoverage;
-import org.apache.sis.internal.coverage.j2d.RelocatedImage;
import org.apache.sis.internal.feature.Resources;
import org.apache.sis.internal.system.DefaultFactories;
import org.apache.sis.util.collection.TableColumn;
@@ -519,7 +519,7 @@ public class GridCoverage2D extends GridCoverage {
* and actual region of the returned image. For example if the
user requested an image starting at
* (5,5) but the image to return starts at (1,1), then we need to
set its location to (-4,-4).
*/
- return RelocatedImage.moveTo(data,
+ return ImageOperations.moveTo(data,
Math.toIntExact(Math.subtractExact(bounds.x, x)),
Math.toIntExact(Math.subtractExact(bounds.y, y)));
} catch (ArithmeticException e) {
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/image/ImageOperations.java
b/core/sis-feature/src/main/java/org/apache/sis/image/ImageOperations.java
new file mode 100644
index 0000000..f8ae272
--- /dev/null
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ImageOperations.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.image;
+
+import java.awt.image.RenderedImage;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.Static;
+
+
+/**
+ * Provides static methods working on images. Some of those methods create
cheap <em>views</em>
+ * sharing the same pixels storage than the original image, while some other
methods may create
+ * new tiles holding computation results. See the javadoc of each method for
details.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since 1.1
+ * @module
+ */
+public final class ImageOperations extends Static {
+ /**
+ * Do not allow instantiation of this class.
+ */
+ private ImageOperations() {
+ }
+
+ /**
+ * Returns an image with the same data than the given image but located at
given coordinates.
+ * The returned image is a <em>view</em>, i.e. this method does not copy
any pixel.
+ * Changes in the original image are reflected immediately in the returned
image.
+ * This method may return the given image directly if it is already
located at the given position.
+ *
+ * @param image the image to move.
+ * @param minX new <var>x</var> coordinate of upper-left pixel.
+ * @param minY new <var>y</var> coordinate of upper-left pixel.
+ * @return image with the same data but at the given coordinates.
+ */
+ public static RenderedImage moveTo(final RenderedImage image, final int
minX, final int minY) {
+ ArgumentChecks.ensureNonNull("image", image);
+ if (minX == image.getMinX() && minY == image.getMinY()) {
+ // Condition verified here for avoiding RelocatedImage class
loading when not needed.
+ return image;
+ }
+ return RelocatedImage.moveTo(image, minX, minY);
+ }
+}
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RelocatedImage.java
b/core/sis-feature/src/main/java/org/apache/sis/image/RelocatedImage.java
similarity index 93%
rename from
core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RelocatedImage.java
rename to
core/sis-feature/src/main/java/org/apache/sis/image/RelocatedImage.java
index 0ffd902..0c3e805 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RelocatedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/RelocatedImage.java
@@ -14,15 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.internal.coverage.j2d;
+package org.apache.sis.image;
+import java.util.Vector;
import java.awt.Rectangle;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
-import java.util.Vector;
+import org.apache.sis.internal.coverage.j2d.PlanarImage;
/**
@@ -36,7 +37,7 @@ import java.util.Vector;
* @since 1.1
* @module
*/
-public final class RelocatedImage extends AbstractRenderedImage {
+final class RelocatedImage extends PlanarImage {
/**
* The image to translate.
*/
@@ -49,7 +50,7 @@ public final class RelocatedImage extends
AbstractRenderedImage {
private final int minX, minY;
/**
- * Creates a new image with the same data then the given image but located
at the given coordinates.
+ * Creates a new image with the same data than the given image but located
at given coordinates.
*
* @param image the image to move.
* @param minX <var>x</var> coordinate of upper-left pixel.
@@ -62,18 +63,15 @@ public final class RelocatedImage extends
AbstractRenderedImage {
}
/**
- * Returns an image with the same data then the given image but located at
the given coordinates.
- * This method may return the given image unchanged if it is already
located at the given position.
+ * Returns an image with the same data than the given image but located at
given coordinates.
+ * Caller should verify that the given image is not null and not already
at the given location.
*
* @param image the image to move.
* @param minX <var>x</var> coordinate of upper-left pixel.
* @param minY <var>y</var> coordinate of upper-left pixel.
* @return image with the same data but at the given coordinates.
*/
- public static RenderedImage moveTo(RenderedImage image, final int minX,
final int minY) {
- if (minX == image.getMinX() && minY == image.getMinY()) {
- return image;
- }
+ static RenderedImage moveTo(RenderedImage image, final int minX, final int
minY) {
if (image instanceof RelocatedImage) {
image = (RelocatedImage) image;
if (minX == image.getMinX() && minY == image.getMinY()) {
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/image/package-info.java
b/core/sis-feature/src/main/java/org/apache/sis/image/package-info.java
index 9150e80..142faab 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/package-info.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/package-info.java
@@ -34,7 +34,7 @@
*
* @author Rémi Maréchal (Geomatys)
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 1.0
* @module
*/
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImage.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
similarity index 95%
rename from
core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImage.java
rename to
core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
index 03c1000..1f27177 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImage.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/PlanarImage.java
@@ -35,16 +35,24 @@ import org.apache.sis.util.Classes;
/**
- * Skeleton implementation of {@link RenderedImage}.
+ * Base class of {@link RenderedImage} implementations in Apache SIS.
* Current implementation does not hold any state.
*
+ * <div class="note"><b>Note: inspirational source</b>
+ * <p>This class takes some inspiration from the {@code
javax.media.jai.PlanarImage} class
+ * defined in <cite>Java Advanced Imaging</cite> (JAI).
+ * That excellent library was maybe 20 years in advance over common imaging
frameworks,
+ * but unfortunately does not seems to be maintained anymore.
+ * We do not try to reproduce the full set of JAI functionalities here, but we
progressively
+ * reproduce some little bits of functionalities as they are needed by Apache
SIS.</p></div>
+ *
* @author Johann Sorel (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
* @since 1.1
* @module
*/
-public abstract class AbstractRenderedImage implements RenderedImage {
+public abstract class PlanarImage implements RenderedImage {
/**
* Approximate size of the buffer to use for copying data from the image
to a raster, in bits.
* The actual buffer size may be smaller or larger, depending on the
actual tile size.
@@ -54,7 +62,7 @@ public abstract class AbstractRenderedImage implements
RenderedImage {
/**
* Creates a new rendered image.
*/
- protected AbstractRenderedImage() {
+ protected PlanarImage() {
}
/**
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/RelocatedImageTest.java
b/core/sis-feature/src/test/java/org/apache/sis/image/RelocatedImageTest.java
similarity index 96%
rename from
core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/RelocatedImageTest.java
rename to
core/sis-feature/src/test/java/org/apache/sis/image/RelocatedImageTest.java
index f35009f..cbdefd1 100644
---
a/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/RelocatedImageTest.java
+++
b/core/sis-feature/src/test/java/org/apache/sis/image/RelocatedImageTest.java
@@ -14,13 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.internal.coverage.j2d;
+package org.apache.sis.image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import org.opengis.coverage.grid.SequenceType;
-import org.apache.sis.image.PixelIterator;
import org.apache.sis.test.TestCase;
import org.junit.Test;
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImageTest.java
b/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/PlanarImageTest.java
similarity index 93%
rename from
core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImageTest.java
rename to
core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/PlanarImageTest.java
index 30b71f1..6b99f49 100644
---
a/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/AbstractRenderedImageTest.java
+++
b/core/sis-feature/src/test/java/org/apache/sis/internal/coverage/j2d/PlanarImageTest.java
@@ -33,14 +33,14 @@ import static
org.apache.sis.test.FeatureAssert.assertValuesEqual;
/**
- * Tests {@link AbstractRenderedImage}.
+ * Tests {@link PlanarImage}.
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
* @since 1.1
* @module
*/
-public final strictfp class AbstractRenderedImageTest extends TestCase {
+public final strictfp class PlanarImageTest extends TestCase {
/**
* Size of tiles in this test. The width should be different than the
height
* for increasing the chances to detect errors in index calculations.
@@ -61,7 +61,7 @@ public final strictfp class AbstractRenderedImageTest extends
TestCase {
/**
* Creates a new test.
*/
- public AbstractRenderedImageTest() {
+ public PlanarImageTest() {
random = TestUtilities.createRandomNumberGenerator();
}
@@ -70,7 +70,7 @@ public final strictfp class AbstractRenderedImageTest extends
TestCase {
* We use this class for testing purpose only because tiled images in
production need a more
* sophisticated implementation capable to store some tiles on disk (for
memory consumption reasons).
*/
- private static final class TiledImage extends AbstractRenderedImage {
+ private static final class TiledImage extends PlanarImage {
/**
* Index of the first tile in the image. Should be a non-trivial value
* for increasing the chances to detect error in index calculation.
@@ -155,11 +155,11 @@ public final strictfp class AbstractRenderedImageTest
extends TestCase {
}
/**
- * Tests {@link AbstractRenderedImage#getData()} on a tiled image.
+ * Tests {@link PlanarImage#getData()} on a tiled image.
*/
@Test
public void testGetData() {
- final AbstractRenderedImage image = new TiledImage(random);
+ final PlanarImage image = new TiledImage(random);
assertValuesEqual(image.getData(), 0, new int[][] {
{ 100, 101, 102 , 200, 201, 202 , 300, 301, 302 ,
400, 401, 402},
{ 110, 111, 112 , 210, 211, 212 , 310, 311, 312 ,
410, 411, 412},
@@ -171,11 +171,11 @@ public final strictfp class AbstractRenderedImageTest
extends TestCase {
}
/**
- * Tests {@link AbstractRenderedImage#getData(Rectangle)} on a tiled image.
+ * Tests {@link PlanarImage#getData(Rectangle)} on a tiled image.
*/
@Test
public void testGetDataRegion() {
- final AbstractRenderedImage image = new TiledImage(random);
+ final PlanarImage image = new TiledImage(random);
final Rectangle region = ImageUtilities.getBounds(image);
region.x += 4; // Exclude 4 columns on left side.
region.width -= 6; // Exclude 2 columns on right side.
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
index 66270c9..48c1e07 100644
---
a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
+++
b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
@@ -76,6 +76,7 @@ import org.junit.runners.Suite;
// Rasters
org.apache.sis.image.DefaultIteratorTest.class,
org.apache.sis.image.LinearIteratorTest.class,
+ org.apache.sis.image.RelocatedImageTest.class,
org.apache.sis.coverage.CategoryTest.class,
org.apache.sis.coverage.CategoryListTest.class,
org.apache.sis.coverage.SampleDimensionTest.class,
@@ -88,9 +89,8 @@ import org.junit.runners.Suite;
org.apache.sis.coverage.grid.GridCoverage2DTest.class,
org.apache.sis.internal.coverage.j2d.ImageUtilitiesTest.class,
org.apache.sis.internal.coverage.j2d.ScaledColorSpaceTest.class,
- org.apache.sis.internal.coverage.j2d.AbstractRenderedImageTest.class,
- org.apache.sis.internal.coverage.j2d.BufferedGridCoverageTest.class,
- org.apache.sis.internal.coverage.j2d.RelocatedImageTest.class
+ org.apache.sis.internal.coverage.j2d.PlanarImageTest.class,
+ org.apache.sis.internal.coverage.j2d.BufferedGridCoverageTest.class
})
public final strictfp class FeatureTestSuite extends TestSuite {
/**