org.mycore.services.imaging
Class MCRImgProcessor

java.lang.Object
  extended by org.mycore.services.imaging.MCRImgProcessor
All Implemented Interfaces:
ImgProcessor

public class MCRImgProcessor
extends Object
implements ImgProcessor

This implementation of ImgProcessor is responsible for the manipulation of image data. It offers methods for scaling and croping of an image and a two encoding possibility (JPEG, TIFF). For TIFF-Encoding ones can set the tile size, default tile size is 480.

Version:
1.00 8/08/2006
Author:
Vu Huu Chi

Field Summary
static int JPEG_ENC
          The JPEG encoder
static int PNG_ENC
          The PNG encoder
protected  float scaleFactor
           
static int TIFF_ENC
          The TIFF encoder
 
Constructor Summary
MCRImgProcessor()
           
 
Method Summary
 void encode(InputStream input, OutputStream output, int encoder)
          Change the format of an image.
 void encode(OutputStream output)
           
 void encode(OutputStream output, int encoder)
           
 void encodeIO(OutputStream output, String type)
           
 Dimension getCurrentSize()
          Returns the size of the edited image.
 String getFileFormat()
           
 Dimension getImageSize(InputStream input)
          Returns the size of the image which is passed as InputStream.
 float getJpegQuality()
          Return the JPEG quality setting of the image processor.
 Dimension getOrigSize()
          Returns the original image size of the image currently loades in the processor.
 float getScaleFactor()
          Returns the scale factor used for the accomplished scale operation.
 boolean hasCorrectTileSize()
          Check if an image loaded into the processor has the correct tile size.
 boolean isTransparent()
           
 void jpegEncode(OutputStream output)
          Encode the loaded image as a JPEG image to a given OutputStream.
 void loadImage(InputStream input)
          Loads an image into the processor.
 javax.media.jai.PlanarImage loadImageFileCache(InputStream input)
          loadImageFileCache - load an input stream of image data into to JAI.
 javax.media.jai.PlanarImage loadImageIO(InputStream input)
           
 void pngEncode(OutputStream output)
           
 void resize(InputStream input, int newWidth, int newHeight, OutputStream output)
          Scales the image to fit into the new width and height in due proportion and encode it depending on the encoder setting of the ImgProcessor.
 void resize(int newWidth, int newHeight)
          Scales the image to fit into the new width and height in due proportion.
 void resizeFitHeight(InputStream input, int newHeight, OutputStream output)
          Scales the image to the new height and encode it depending on the encoder setting of the ImgProcessor.
 void resizeFitHeight(int newHeight)
          Scales the image to the new height in due proportion.
 void resizeFitWidth(InputStream input, int newWidth, OutputStream output)
          Scales the image to the new width in due proportion and encode it depending on the encoder setting of the ImgProcessor.
 void resizeFitWidth(int newWidth)
          Scales the image to the new width in due proportion.
 void scale(float scaleFactor)
          Scales the image with the given scale factor in due proportion.
 void scale(InputStream input, float scaleFactor, OutputStream output)
          Scales the image with the given scale factor in due proportion and encode it depending on the encoder setting of the ImgProcessor.
 void scaleROI(InputStream input, int xTopPos, int yTopPos, int boundWidth, int boundHeight, float scaleFactor, OutputStream output)
          Scales the image with the given scale factor in due proportion cut off a region of interest and encode it depending on the encoder setting of the ImgProcessor.
 void scaleROI(int xTopPos, int yTopPos, int boundWidth, int boundHeight, float scaleFactor)
          Scales the image with the given scale factor in due proportion cut off a region of interest and encode it depending on the encoder setting of the ImgProcessor.
 void setFileFormat(String fileFormat)
           
 void setJpegQuality(float jpegQuality)
          Set the JPEG quality of the image processor.
 void setScaleFactor(float scaleFactor)
           
 void setTileSize(int tileWidth, int tileHeight)
          Set the tile width and height for a TIFF image, which is used in the encoding process.
 void setTransparent(boolean transparent)
           
 void tiffEncode(OutputStream output)
          Encode the loaded image as a TIFF image to a given OutputStream.
 void useEncoder(int Encoder)
          Set which encoder to use in the encoding process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scaleFactor

protected float scaleFactor

JPEG_ENC

public static final int JPEG_ENC
The JPEG encoder

See Also:
Constant Field Values

TIFF_ENC

public static final int TIFF_ENC
The TIFF encoder

See Also:
Constant Field Values

PNG_ENC

public static final int PNG_ENC
The PNG encoder

See Also:
Constant Field Values
Constructor Detail

MCRImgProcessor

MCRImgProcessor()
Method Detail

getJpegQuality

public float getJpegQuality()
Description copied from interface: ImgProcessor
Return the JPEG quality setting of the image processor.

Specified by:
getJpegQuality in interface ImgProcessor
Returns:
float value of the JPEG quality

setJpegQuality

public void setJpegQuality(float jpegQuality)
Description copied from interface: ImgProcessor
Set the JPEG quality of the image processor.

Specified by:
setJpegQuality in interface ImgProcessor
Parameters:
jpegQuality - the float value of the JPEG quality

setTileSize

public void setTileSize(int tileWidth,
                        int tileHeight)
Description copied from interface: ImgProcessor
Set the tile width and height for a TIFF image, which is used in the encoding process.

Specified by:
setTileSize in interface ImgProcessor

useEncoder

public void useEncoder(int Encoder)
                throws Exception
Description copied from interface: ImgProcessor
Set which encoder to use in the encoding process.

Specified by:
useEncoder in interface ImgProcessor
Parameters:
Encoder - the encoder should be a static field variable of the impleming class e.g. ImplementedClass.JPEG
Throws:
Exception - if you enter a number which is not in the encoder list

resizeFitWidth

public void resizeFitWidth(InputStream input,
                           int newWidth,
                           OutputStream output)
Description copied from interface: ImgProcessor
Scales the image to the new width in due proportion and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
resizeFitWidth in interface ImgProcessor
Parameters:
input - the image data as InputStream
newWidth - the new width
output - the scaled and encoded image as OutputStream

resizeFitHeight

public void resizeFitHeight(InputStream input,
                            int newHeight,
                            OutputStream output)
Description copied from interface: ImgProcessor
Scales the image to the new height and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
resizeFitHeight in interface ImgProcessor
Parameters:
input - the image data as InputStream
newHeight - the new height
output - the scaled and encoded image as OutputStream

resize

public void resize(InputStream input,
                   int newWidth,
                   int newHeight,
                   OutputStream output)
Description copied from interface: ImgProcessor
Scales the image to fit into the new width and height in due proportion and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
resize in interface ImgProcessor
Parameters:
input - the image data as InputStream
newWidth - the new width to fit in
newHeight - the new height to fit in
output - the scaled and encoded image as OutputStream

scale

public void scale(InputStream input,
                  float scaleFactor,
                  OutputStream output)
Description copied from interface: ImgProcessor
Scales the image with the given scale factor in due proportion and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
scale in interface ImgProcessor
Parameters:
input - the image data as InputStream
scaleFactor - the scale factor for width and height
output - the scaled and encoded image as OutputStream

scaleROI

public void scaleROI(InputStream input,
                     int xTopPos,
                     int yTopPos,
                     int boundWidth,
                     int boundHeight,
                     float scaleFactor,
                     OutputStream output)
Description copied from interface: ImgProcessor
Scales the image with the given scale factor in due proportion cut off a region of interest and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
scaleROI in interface ImgProcessor
Parameters:
input - the image data as InputStream
xTopPos - the x-coordinate of the top left position of the region of interest
yTopPos - the y-coordinate of the top left position of the region of interest
boundWidth - the width of the region of interest
boundHeight - the height of the region of interest
scaleFactor - the scale factor for width and height of the image
output - the scaled and encoded region of interest as OutputStream

getScaleFactor

public float getScaleFactor()
Description copied from interface: ImgProcessor
Returns the scale factor used for the accomplished scale operation.

Specified by:
getScaleFactor in interface ImgProcessor
Returns:
float value of the scale factor

getOrigSize

public Dimension getOrigSize()
                      throws Exception
Description copied from interface: ImgProcessor
Returns the original image size of the image currently loades in the processor.

Specified by:
getOrigSize in interface ImgProcessor
Returns:
Dimension of the image
Throws:
Exception - if no image is loaded in the processor

getCurrentSize

public Dimension getCurrentSize()
                         throws Exception
Description copied from interface: ImgProcessor
Returns the size of the edited image. The current size change after every scale operation.

Specified by:
getCurrentSize in interface ImgProcessor
Returns:
Dimension of the edited image
Throws:
Exception - if no image is loaded in the processor

getImageSize

public Dimension getImageSize(InputStream input)
Description copied from interface: ImgProcessor
Returns the size of the image which is passed as InputStream.

Specified by:
getImageSize in interface ImgProcessor
Parameters:
input - the image data as InputStream
Returns:
Dimension of the image

encode

public void encode(InputStream input,
                   OutputStream output,
                   int encoder)
            throws Exception
Description copied from interface: ImgProcessor
Change the format of an image.

Specified by:
encode in interface ImgProcessor
Parameters:
input - the image data as InputStream
output - the image in a new format
encoder - the encoder should be a static field variable of the impleming class e.g. ImplementedClass.JPEG
Throws:
Exception - if you enter a number which is not in the encoder list

loadImage

public void loadImage(InputStream input)
Description copied from interface: ImgProcessor
Loads an image into the processor.

Specified by:
loadImage in interface ImgProcessor
Parameters:
input - the image data as InputStream

loadImageIO

public javax.media.jai.PlanarImage loadImageIO(InputStream input)

hasCorrectTileSize

public boolean hasCorrectTileSize()
Description copied from interface: ImgProcessor
Check if an image loaded into the processor has the correct tile size. The "correct" size is the size set in the processor. Default is 480 x 480.

Specified by:
hasCorrectTileSize in interface ImgProcessor
Returns:
true if the image has the correct tile size

resizeFitWidth

public void resizeFitWidth(int newWidth)
Description copied from interface: ImgProcessor
Scales the image to the new width in due proportion. An image should be loaded into the processor before using this method.

Specified by:
resizeFitWidth in interface ImgProcessor
Parameters:
newWidth - the new width

resizeFitHeight

public void resizeFitHeight(int newHeight)
Description copied from interface: ImgProcessor
Scales the image to the new height in due proportion. An image should be loaded into the processor before using this method.

Specified by:
resizeFitHeight in interface ImgProcessor
Parameters:
newHeight - the new height

resize

public void resize(int newWidth,
                   int newHeight)
Description copied from interface: ImgProcessor
Scales the image to fit into the new width and height in due proportion. An image should be loaded into the processor before using this method.

Specified by:
resize in interface ImgProcessor
Parameters:
newWidth - new width to fit in
newHeight - new height to fit in

scale

public void scale(float scaleFactor)
Description copied from interface: ImgProcessor
Scales the image with the given scale factor in due proportion.

Specified by:
scale in interface ImgProcessor
Parameters:
scaleFactor - the scale factor for width and height of the image

scaleROI

public void scaleROI(int xTopPos,
                     int yTopPos,
                     int boundWidth,
                     int boundHeight,
                     float scaleFactor)
Description copied from interface: ImgProcessor
Scales the image with the given scale factor in due proportion cut off a region of interest and encode it depending on the encoder setting of the ImgProcessor. Default encoder is JPEG.

Specified by:
scaleROI in interface ImgProcessor
Parameters:
xTopPos - the x-coordinate of the top left position of the region of interest
yTopPos - the y-coordinate of the top left position of the region of interest
boundWidth - the width of the region of interest
boundHeight - the height of the region of interest
scaleFactor - the scale factor for width and height of the image

jpegEncode

public void jpegEncode(OutputStream output)
Description copied from interface: ImgProcessor
Encode the loaded image as a JPEG image to a given OutputStream.

Specified by:
jpegEncode in interface ImgProcessor
Parameters:
output - the encoded image

encodeIO

public void encodeIO(OutputStream output,
                     String type)

tiffEncode

public void tiffEncode(OutputStream output)
Description copied from interface: ImgProcessor
Encode the loaded image as a TIFF image to a given OutputStream.

Specified by:
tiffEncode in interface ImgProcessor
Parameters:
output - the encodes image

pngEncode

public void pngEncode(OutputStream output)

loadImageFileCache

public javax.media.jai.PlanarImage loadImageFileCache(InputStream input)
loadImageFileCache - load an input stream of image data into to JAI. JAI use a cache in form of a file on the HDD for the image data. This is slower than using the RAM but for large files it's the only solution.

Parameters:
input -
Returns:
PlanarImage

encode

public void encode(OutputStream output,
                   int encoder)

encode

public void encode(OutputStream output)

setScaleFactor

public void setScaleFactor(float scaleFactor)

isTransparent

public boolean isTransparent()

setTransparent

public void setTransparent(boolean transparent)

getFileFormat

public String getFileFormat()

setFileFormat

public void setFileFormat(String fileFormat)