Debug.output("OMScalingRaster.scaleTo() sourceImage is null");
if (DEBUG) { Debug.output("OMScalingRaster.scaleTo() sourceImage is null"); }
    protected void scaleTo(Projection thisProj) {        if (DEBUG) Debug.output("OMScalingRaster: scaleTo()");        if (sourceImage == null) {            Debug.output("OMScalingRaster.scaleTo() sourceImage is null");            return;        }                // Get the projection window rectangle in pix        Rectangle winRect = new Rectangle(thisProj.getWidth(),                                            thisProj.getHeight());        // Get image projection rectangle        Rectangle projRect = new Rectangle();        projRect.setLocation(point1);        projRect.setSize(point2.x - point1.x, point2.y - point1.y);                Rectangle sourceRect = new Rectangle();        sourceRect.width = sourceImage.getWidth();        sourceRect.height = sourceImage.getHeight();                // Now we have everything we need to sort out this new        // projection.        setVisible(false); // Assume we wont see it        clipRect = null;        Rectangle iRect = winRect.intersection(projRect);        if (!iRect.isEmpty()) {            // Now we have the visible rectangle of the projected            // image we need to figure out which pixels from the            // source image get scaled to produce it.                        // Assume will need whole image, set the clipRect so it's            // on the map, somewhere.            clipRect = new Rectangle();            clipRect.setBounds(sourceRect);            // If big enough to see            if ((iRect.width >= 1) && (iRect.height >= 1)) {                // If it didn't all fit                if (!winRect.contains(projRect)) {                    //   calc X scale factor                    float xScaleFactor = (float)sourceRect.width / (float)projRect.width;                    //   and Y scale factor                    float yScaleFactor = (float)sourceRect.height / (float)projRect.height;                    int xOffset = (int)((iRect.x - projRect.x)); //   and x offset                    int yOffset = (int)((iRect.y - projRect.y)); //   and y offset                    clipRect.x = (int)(xOffset * xScaleFactor); //   scale the x position                    clipRect.y = (int)(yOffset * yScaleFactor); //   scale the y position                    // Do Math.ceil because the icon was getting                    // clipped a little if it started to move off the                    // screen a little.                    clipRect.width = (int)Math.ceil(iRect.width * xScaleFactor); //   scale the width                    clipRect.height = (int)Math.ceil(iRect.height * yScaleFactor); //   scale the height                }                // check width and height of clipRect, in case it got                // rounded down to zero.                if (clipRect.width <= 0) {                    clipRect.width = 1;                }                if (clipRect.height <= 0) {                    clipRect.height = 1;                }                // Now we can grab the bit we want out of the source and                // scale it to fit the intersection.                // Calc width adjustment                double widthAdj = (double)iRect.width / (double)clipRect.width;                // Calc height adjustment                double heightAdj = (double)iRect.height / (double)clipRect.height;                // Create the transform                AffineTransform xform = new AffineTransform();                // Specify scaling                xform.setToScale(widthAdj, heightAdj);                                // Create the transform op.                AffineTransformOp xformOp = new AffineTransformOp(xform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);                // Scale clip area -> newImage                //   extract sub-image                BufferedImage newImage = xformOp.filter(sourceImage.getSubimage(clipRect.x, clipRect.y, clipRect.width, clipRect.height), null);                                bitmap = newImage;                point1.setLocation(iRect.x, iRect.y);                setVisible(true);            }        }    }