hey Mike, comments inline
On 11/19/2020 9:02, jump-pilot-svn--- via Jump-pilot-devel wrote: > Revision: 6625 > http://sourceforge.net/p/jump-pilot/code/6625 > Author: michaudm > Date: 2020-11-19 08:02:57 +0000 (Thu, 19 Nov 2020) > Log Message: > ----------- > Fix more deeply and document the half pixel shift problem > > Modified Paths: > -------------- > > core/trunk/src/com/vividsolutions/jump/workbench/imagery/geoimg/GeoImage.java > > core/trunk/src/com/vividsolutions/jump/workbench/imagery/geoimg/GeoReferencedRaster.java > > Modified: > core/trunk/src/com/vividsolutions/jump/workbench/imagery/geoimg/GeoImage.java > =================================================================== > --- > core/trunk/src/com/vividsolutions/jump/workbench/imagery/geoimg/GeoImage.java > 2020-11-15 17:54:16 UTC (rev 6624) > +++ > core/trunk/src/com/vividsolutions/jump/workbench/imagery/geoimg/GeoImage.java > 2020-11-19 08:02:57 UTC (rev 6625) > @@ -43,6 +43,7 @@ > import java.awt.image.renderable.ParameterBlock; > import java.lang.reflect.InvocationTargetException; > > +import javax.media.jai.InterpolationNearest; > import javax.media.jai.JAI; > import javax.media.jai.RenderedOp; > import javax.media.jai.operator.AffineDescriptor; > @@ -147,7 +148,7 @@ > // System.out.println("GI: NO SCALE CACHE"); > > // First, scale the original image > - double scaleX = scale * gtr.getDblModelUnitsPerRasterUnit_X(); > + double scaleX = scale * > Math.abs(gtr.getDblModelUnitsPerRasterUnit_X()); > double scaleY = scale * > Math.abs(gtr.getDblModelUnitsPerRasterUnit_Y()); would you mind commenting here why Math.abs() is necessary? or pointing to a place in GeoReferencedRaster where you added some doc about it? > // calculate predicted dimensions > @@ -209,7 +210,11 @@ > // Interpolation interp = Interpolation > // .getInstance(Interpolation.INTERP_BICUBIC); > // pb.add(interp); // add interpolation method > - img = JAI.create("scale", pb, hints); > + //img = JAI.create("scale", pb, hints); > + // Prefer affine to scale as affine uses double parameters and > preserve scale signus > + // while scale uses float parameters and forbid negative scaleY > + AffineTransform tr = new AffineTransform(scaleX_toUse, 0, 0, > scaleY_toUse, 0, 0); > + img = JAI.create("affine", scale_src_img, tr, new > InterpolationNearest()); > } else { > pb.add(scaleX_toUse); > pb.add(scaleY_toUse); > @@ -270,9 +275,9 @@ > raster_cropX = Math.min((float)raster_cropX, (float)img.getWidth()); > raster_cropY = Math.min((float)raster_cropY, (float)img.getHeight()); > raster_cropW = Math > - .min((float)raster_cropW, (float)img.getWidth() - /*(int)*/ > raster_cropX); > - raster_cropH = Math.min((float)raster_cropH, (float)img.getHeight() > - - /*(int)*/ raster_cropY); > + .min((float)raster_cropW, (float)(img.getWidth() - raster_cropX)); > + raster_cropH = Math.min((float)raster_cropH, (float)(img.getHeight() > + - raster_cropY)); > > pb = new ParameterBlock(); > pb.addSource(img); > @@ -282,8 +287,11 @@ > //System.out.println("croph " + (float)raster_cropH + " " + > (img.getHeight() - /*(int)*/ raster_cropY)); > pb.add((float)raster_cropX); > pb.add((float)raster_cropY); > - pb.add((float)raster_cropW); > - pb.add((float)raster_cropH); > + // conversions of cropX/Y and width/height from double to float may > + // create an envelope slightly outside the real envelope of the image > + // removing ulp to the width/height solve the problem > + pb.add((float)raster_cropW-Math.ulp((float)raster_cropW)); > + pb.add((float)raster_cropH-Math.ulp((float)raster_cropH)); > img = JAI.create("crop", pb, null); nifty. reading your eplpanation it makes total sense now :) ..ede _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel