From: <svn...@os...> - 2012-03-08 14:14:30
|
Author: aaime Date: 2012-03-08 06:14:21 -0800 (Thu, 08 Mar 2012) New Revision: 38617 Modified: branches/2.7.x/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java branches/2.7.x/modules/library/coverage/src/test/java/org/geotools/image/palette/CustomPaletteBuilderTest.java Log: [GEOT-4065] CustomPaletteBuilder may fail on images with shifted tile origin Modified: branches/2.7.x/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java =================================================================== --- branches/2.7.x/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java 2012-03-08 14:13:58 UTC (rev 38616) +++ branches/2.7.x/modules/library/coverage/src/main/java/org/geotools/image/palette/CustomPaletteBuilder.java 2012-03-08 14:14:21 UTC (rev 38617) @@ -173,12 +173,18 @@ int minx = r.getMinX(); int miny = r.getMinY(); + int sampleModelTx = r.getSampleModelTranslateX(); + int sampleModelTy = r.getSampleModelTranslateY(); + 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 maxxR = maxx + sampleModelTx; + int maxyR = maxy + sampleModelTy; + maxx = maxx > maxx_ ? (maxx_ > maxxR ? maxxR : maxx_) : (maxx > maxxR ? maxxR : maxx); + maxy = maxy > maxy_ ? (maxy_ > maxyR ? maxyR : maxy_) : (maxy > maxyR ? maxyR : maxy); + actualWidth = maxx - minx; actualHeight = maxy - miny; for (int j = miny, jj = dstTempY; j < maxy; j++, jj++) { @@ -316,12 +322,17 @@ int minx = r.getMinX(); int miny = r.getMinY(); + int sampleModelTx = r.getSampleModelTranslateX(); + int sampleModelTy = r.getSampleModelTranslateY(); 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 maxxR = maxx + sampleModelTx; + int maxyR = maxy + sampleModelTy; + maxx = maxx > maxx_ ? (maxx_ > maxxR ? maxxR : maxx_) : (maxx > maxxR ? maxxR : maxx); + maxy = maxy > maxy_ ? (maxy_ > maxyR ? maxyR : maxy_) : (maxy > maxyR ? maxyR : maxy); + for (int j = miny; j < maxy; j++) { if ((subsampley > 1) && ((j % subsampley) != 0)) { continue; Modified: branches/2.7.x/modules/library/coverage/src/test/java/org/geotools/image/palette/CustomPaletteBuilderTest.java =================================================================== --- branches/2.7.x/modules/library/coverage/src/test/java/org/geotools/image/palette/CustomPaletteBuilderTest.java 2012-03-08 14:13:58 UTC (rev 38616) +++ branches/2.7.x/modules/library/coverage/src/test/java/org/geotools/image/palette/CustomPaletteBuilderTest.java 2012-03-08 14:14:21 UTC (rev 38617) @@ -19,20 +19,25 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.image.RenderedImage; +import java.awt.image.SampleModel; import javax.media.jai.ImageLayout; import javax.media.jai.JAI; import javax.media.jai.OperationDescriptor; import javax.media.jai.ParameterBlockJAI; import javax.media.jai.PlanarImage; +import javax.media.jai.TiledImage; import junit.framework.TestCase; import org.geotools.image.ImageWorker; import org.junit.Test; +import com.sun.media.jai.codecimpl.util.RasterFactory; + /** * Testing custom code for color reduction. * @@ -97,6 +102,26 @@ } + @Test + public void testTranslatedImage() { + BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY); + TiledImage image = new TiledImage(0, 0, 256, 256, 1, 1, bi.getSampleModel().createCompatibleSampleModel(256, 256), bi.getColorModel()); + Graphics g = image.createGraphics(); + g.setColor(Color.WHITE); + g.fillRect(0, 0, 20, 20); + g.setColor(new Color(20, 20, 20)); // A dark gray + g.fillRect(20, 20, 20, 20); + g.setColor(new Color(200, 200, 200)); // A light gray + g.fillRect(0, 20, 20, 20); + g.dispose(); + 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 + + } + @Test public void testFourColor() { |