if (DEBUG) Debug.output("TrimScaleFilter.trimExcessPixels(): clipping enlarged image.");
if (DEBUG) { Debug.output("TrimScaleFilter.trimExcessPixels(): clipping enlarged image."); }
        protected Image trimExcessPixels() {            if (filteredWidth <= width && filteredHeight <= height) {                if (DEBUG) Debug.output("TrimScaleFilter.trimExcessPixels(): image not enlarged, using entire image.");                return null;            }                        if (DEBUG) Debug.output("TrimScaleFilter.trimExcessPixels(): clipping enlarged image.");            //  Figure out the pixels of the old image being used in            // the new image.  Figure out the proj location of the upper            // left pixel of the new image.  We want to subsitute this            // proj location for the projection location already            // calculated.  This should get overwritten later for any            // projection changes.            float widthScale = (float)filteredWidth/(float)width;            float heightScale = (float)filteredHeight/(float)height;            int startXPixelInSource = point1.x < 0?(int)((-1.0*point1.x)/widthScale):0;            int startYPixelInSource = point1.y < 0?(int)((-1*point1.y)/heightScale):0;            Point scaledDim = new Point((int)(point1.x + (width*widthScale)),                                        (int)(point1.y +(height*heightScale)));            int endXPixelInSource = (scaledDim.x > projWidth?                (int)((projWidth - point1.x)/widthScale)+1:width);            int endYPixelInSource = scaledDim.y > projHeight?                (int)((projHeight - point1.y)/heightScale)+1:height;            if (DEBUG) {                Debug.output("TrimScaleFilter.trimExcessPixels(): image contributes " +                              startXPixelInSource + ", " + startYPixelInSource + " to " +                             endXPixelInSource + ", " + endYPixelInSource);            }            // Create a buffered image out of the old image, clipping            // out the unused pixels.                        if (DEBUG) {                Debug.output("TrimScaleFilter.trimExcessPixels(): " +                              " new dimensions of scaled image " +                             (int)((endXPixelInSource - startXPixelInSource) * widthScale)                             + ", " +                             (int)((endYPixelInSource - startYPixelInSource) * heightScale));            }            // Get only the pixels you need.            // Use a pixel grabber to get the right pixels.            PixelGrabber pg = new PixelGrabber(bitmap,                                                startXPixelInSource, startYPixelInSource,                                               endXPixelInSource - startXPixelInSource,                                               endYPixelInSource - startYPixelInSource,                                                true);            int[] pix = ImageHelper.grabPixels(pg);            if (pix == null) {                return null;            }            // Set the filter to the demisnsions.  Need to remember to ask for this!!!            actualFilter = new TrimScaleFilter(                (int)((endXPixelInSource - startXPixelInSource) * widthScale),                 (int)((endYPixelInSource - startYPixelInSource) * heightScale),                 algorithmType);                        // create the new bitmap, which holds the image that gets drawn            Toolkit tk = Toolkit.getDefaultToolkit();            Image image = tk.createImage(                new MemoryImageSource(endXPixelInSource - startXPixelInSource,                                      endYPixelInSource - startYPixelInSource,                                       pix, 0, endXPixelInSource - startXPixelInSource));            return image;        }