Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

GEOT-4446, CustomPaletteBuilder problem with strange tiling throws exception #179

Merged
merged 2 commits into from

1 participant

@simboss
Collaborator

No description provided.

@simboss simboss merged commit a0c728f into geotools:master
@simboss simboss deleted the simboss:master-up branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2013
  1. @simboss

    GEOT-446, CustomPaletteBuilder problem with strange tiling throws exc…

    simboss authored Damianofds committed
    …eption
This page is out of date. Refresh to see the latest.
View
32 modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java
@@ -180,16 +180,19 @@ public RenderedImage getIndexedImage() {
// get the source raster
final Raster r = src.getTile(tx, ty);
- int minx = r.getMinX();
- int miny = r.getMinY();
-
- minx = minx < minx_ ? minx_ : minx;
- miny = miny < miny_ ? miny_ : miny;
- int maxx = minx + tileW;
- int maxy = miny + tileH;
-
- maxx = maxx > maxx_ ? maxx_ : maxx ;
- maxy = maxy > maxy_ ? maxy_ : maxy ;
+ int minx = r.getMinX();
+ int miny = r.getMinY();
+ int maxx = minx + r.getWidth();
+ int maxy = miny + r.getHeight();
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("minx:"+minx+" miny:"+miny);
+ LOGGER.fine("maxx:"+maxx+" maxy:"+maxy);
+ }
+
+ minx = minx < minx_ ? minx_ : minx;
+ miny = miny < miny_ ? miny_ : miny;
+ maxx = maxx > maxx_ ? maxx_:maxx;
+ maxy = maxy > maxy_ ? maxy_:maxy;
actualWidth = maxx - minx;
actualHeight = maxy - miny;
@@ -419,8 +422,6 @@ public CustomPaletteBuilder buildPalette() {
final int maxy_ = miny_ + srcH_;
final int minTileX = src.getMinTileX();
final int minTileY = src.getMinTileY();
- final int tileW = src.getTileWidth();
- final int tileH = src.getTileHeight();
final int maxTileX = minTileX + src.getNumXTiles();
final int maxTileY = minTileY + src.getNumYTiles();
for (int ty = minTileY; ty < maxTileY; ty++) {
@@ -429,19 +430,20 @@ public CustomPaletteBuilder buildPalette() {
final Raster r = src.getTile(tx, ty);
if(LOGGER.isLoggable(Level.FINER)){
- LOGGER.finer("Working on tile tx:"+tx+"ty:"+ty);
+ LOGGER.fine("Working on tile tx:"+tx+"ty:"+ty);
}
int minx = r.getMinX();
int miny = r.getMinY();
+ int maxx = minx + r.getWidth();
+ int maxy = miny + r.getHeight();
if(LOGGER.isLoggable(Level.FINER)){
LOGGER.finer("minx:"+minx+" miny:"+miny);
+ LOGGER.finer("maxx:"+maxx+" maxy:"+maxy);
}
minx = minx < minx_ ? minx_ : minx;
miny = miny < miny_ ? miny_ : miny;
- int maxx = minx + tileW;
- int maxy = miny + tileH;
maxx = maxx > maxx_ ? maxx_:maxx;
maxy = maxy > maxy_ ? maxy_:maxy;
View
51 ...s/library/coverage/src/test/java/org/geotools/image/palette/CustomPaletteBuilderTest.java
@@ -27,6 +27,7 @@
import javax.media.jai.OperationDescriptor;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
+import javax.media.jai.TiledImage;
import junit.framework.Assert;
@@ -96,9 +97,9 @@ public void testGrayColor() {
}
@Test
- public void testTranslatedImage() {
- BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
- Graphics g = image.createGraphics();
+ public void testTranslatedImageTileGrid() {
+ BufferedImage image_ = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
+ Graphics g = image_.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(236, 236, 20, 20);
g.setColor(new Color(80, 80, 80)); // A dark gray
@@ -106,7 +107,19 @@ public void testTranslatedImage() {
g.setColor(new Color(200, 200, 200)); // A light gray
g.fillRect(216, 236, 20, 20);
g.dispose();
- image=image.getSubimage(128, 128, 128, 128);
+
+
+ TiledImage image=new TiledImage(
+ 0,
+ 0,
+ 256,
+ 256,
+ 128,
+ 128,
+ image_.getColorModel().createCompatibleSampleModel(256, 256),
+ image_.getColorModel());
+ image.set(image_);
+
CustomPaletteBuilder builder = new CustomPaletteBuilder(image, 256, 1, 1, 1);
RenderedImage indexed = builder.buildPalette().getIndexedImage();
assertTrue(indexed.getColorModel() instanceof IndexColorModel);
@@ -125,6 +138,36 @@ public void testTranslatedImage() {
}
+ @Test
+ public void testTranslatedImage() {
+ BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
+ Graphics g = image.createGraphics();
+ g.setColor(Color.WHITE);
+ g.fillRect(236, 236, 20, 20);
+ g.setColor(new Color(80, 80, 80)); // A dark gray
+ g.fillRect(216, 216, 20, 20);
+ g.setColor(new Color(200, 200, 200)); // A light gray
+ g.fillRect(216, 236, 20, 20);
+ g.dispose();
+ image = image.getSubimage(128, 128, 128, 128);
+ CustomPaletteBuilder builder = new CustomPaletteBuilder(image, 256, 1, 1, 1);
+ RenderedImage indexed = builder.buildPalette().getIndexedImage();
+ assertTrue(indexed.getColorModel() instanceof IndexColorModel);
+ IndexColorModel icm = (IndexColorModel) indexed.getColorModel();
+ assertEquals(4, icm.getMapSize()); // Black background, white fill, light gray fill, dark gray fill = 4 colors
+
+ // check image not black
+ ImageWorker iw = new ImageWorker(indexed).forceComponentColorModel().intensity();
+ double[] mins = iw.getMinimums();
+ double[] maxs = iw.getMaximums();
+ boolean result = true;
+ for (int i = 0; i < mins.length; i++) {
+ result = mins[i] == maxs[i] ? false : result;
+ }
+ assertTrue(result);
+
+ }
+
@Test
public void testFourColor() {
Something went wrong with that request. Please try again.