protected Image trimExcessPixels(){
  if (filteredWidth <= width && filteredHeight <= height) {
    if (DEBUG) {
      logger.fine("TrimScaleFilter.trimExcessPixels(): image not enlarged, using entire image.");
    }
    return null;
  }
  if (DEBUG) {
    logger.fine("TrimScaleFilter.trimExcessPixels(): clipping enlarged image.");
  }
  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) {
    logger.fine("TrimScaleFilter.trimExcessPixels(): image contributes " + startXPixelInSource + ", "+ startYPixelInSource+ " to "+ endXPixelInSource+ ", "+ endYPixelInSource);
  }
  if (DEBUG) {
    logger.fine("TrimScaleFilter.trimExcessPixels(): " + " new dimensions of scaled image " + (int)((endXPixelInSource - startXPixelInSource) * widthScale) + ", "+ (int)((endYPixelInSource - startYPixelInSource) * heightScale));
  }
  PixelGrabber pg=new PixelGrabber(bitmap,startXPixelInSource,startYPixelInSource,endXPixelInSource - startXPixelInSource,endYPixelInSource - startYPixelInSource,true);
  int[] pix=ImageHelper.grabPixels(pg);
  if (pix == null) {
    return null;
  }
  actualFilter=new TrimScaleFilter((int)((endXPixelInSource - startXPixelInSource) * widthScale),(int)((endYPixelInSource - startYPixelInSource) * heightScale),algorithmType);
  Toolkit tk=Toolkit.getDefaultToolkit();
  Image image=tk.createImage(new MemoryImageSource(endXPixelInSource - startXPixelInSource,endYPixelInSource - startYPixelInSource,pix,0,endXPixelInSource - startXPixelInSource));
  return image;
}

protected Image trimExcessPixels ( ) { if ( filteredWidth <= width && filteredHeight <= height ) { if ( DEBUG ) { logger . fine ( "TrimScaleFilter.trimExcessPixels(): image not enlarged, using entire image." ) ; } return null ; } if ( DEBUG ) { logger . fine ( "TrimScaleFilter.trimExcessPixels(): clipping enlarged image." ) ; } 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 ) { logger . fine ( "TrimScaleFilter.trimExcessPixels(): image contributes " + startXPixelInSource + ", " + startYPixelInSource + " to " + endXPixelInSource + ", " + endYPixelInSource ) ; } if ( DEBUG ) { logger . fine ( "TrimScaleFilter.trimExcessPixels(): " + " new dimensions of scaled image " + ( int ) ( ( endXPixelInSource - startXPixelInSource ) * widthScale ) + ", " + ( int ) ( ( endYPixelInSource - startYPixelInSource ) * heightScale ) ) ; } PixelGrabber pg = new PixelGrabber ( bitmap , startXPixelInSource , startYPixelInSource , endXPixelInSource - startXPixelInSource , endYPixelInSource - startYPixelInSource , true ) ; int [ ] pix = ImageHelper . grabPixels ( pg ) ; if ( pix == null ) { return null ; } actualFilter = new TrimScaleFilter ( ( int ) ( ( endXPixelInSource - startXPixelInSource ) * widthScale ) , ( int ) ( ( endYPixelInSource - startYPixelInSource ) * heightScale ) , algorithmType ) ; Toolkit tk = Toolkit . getDefaultToolkit ( ) ; Image image = tk . createImage ( new MemoryImageSource ( endXPixelInSource - startXPixelInSource , endYPixelInSource - startYPixelInSource , pix , 0 , endXPixelInSource - startXPixelInSource ) ) ; return image ; }
get a trimmed - down image to expand to the map , that contains all the pixels that will be visible after expansion . returns null if the image should be used as is , and the filter as well .
