net.sf.latexdraw.util
Class ImageCropper

java.lang.Object
  extended by net.sf.latexdraw.util.ImageCropper

public final class ImageCropper
extends java.lang.Object

This singleton removes white margins of an image.

This file is part of LaTeXDraw
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

LaTeXDraw is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

23/01/12

Version:
3.0
Author:
Arnaud BLOUIN

Field Summary
static ImageCropper INSTANCE
          The singleton.
 
Constructor Summary
private ImageCropper()
           
 
Method Summary
 java.awt.Image cropImage(java.awt.image.BufferedImage img)
          Removes the white margins of the given image.
private  int getBottom(java.awt.image.BufferedImage img, int width, int height, int left, int right)
          Gets the bottom position where a pixel is not white.
private  int getLeft(java.awt.image.BufferedImage img, int width, int height)
          Gets the left position where a pixel is not white.
private  int getRight(java.awt.image.BufferedImage img, int width, int height)
          Gets the right position where a pixel is not white.
private  int getTop(java.awt.image.BufferedImage img, int width, int height, int left, int right)
          Gets the top position where a pixel is not white.
private  boolean hasColouredPixelColumn(java.awt.image.BufferedImage image, int x, int imgHeight)
           
private  boolean hasColouredPixelRow(java.awt.image.BufferedImage image, int y, int min, int max)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final ImageCropper INSTANCE
The singleton.

Constructor Detail

ImageCropper

private ImageCropper()
Method Detail

cropImage

public java.awt.Image cropImage(java.awt.image.BufferedImage img)
Removes the white margins of the given image.

Parameters:
img - The image to crop.
Returns:
The cropped image or null if the given image is null or fully white.
Since:
3.0

getBottom

private int getBottom(java.awt.image.BufferedImage img,
                      int width,
                      int height,
                      int left,
                      int right)
Gets the bottom position where a pixel is not white.


getTop

private int getTop(java.awt.image.BufferedImage img,
                   int width,
                   int height,
                   int left,
                   int right)
Gets the top position where a pixel is not white.


getRight

private int getRight(java.awt.image.BufferedImage img,
                     int width,
                     int height)
Gets the right position where a pixel is not white.


getLeft

private int getLeft(java.awt.image.BufferedImage img,
                    int width,
                    int height)
Gets the left position where a pixel is not white.


hasColouredPixelColumn

private boolean hasColouredPixelColumn(java.awt.image.BufferedImage image,
                                       int x,
                                       int imgHeight)

hasColouredPixelRow

private boolean hasColouredPixelRow(java.awt.image.BufferedImage image,
                                    int y,
                                    int min,
                                    int max)