org.mycore.services.imaging
Interface ImgProcessor

All Known Implementing Classes:
MCRImgProcessor

public interface ImgProcessor

An image processor (short ImgProcesor) represent an object with the ability to manipulate image data. The image data is passed as InputStream. The edited image data is encoded at least in JPEG or TIFF and passed as OutputStream. There are two modes how the processor work. The first mode is when you want to perform only one image operation. So you can use the methods which has input and output parameter. The second mode is when you want to perform several image operation on the same image like "scale, encode, scale, encode,...". So first you have to load the image into the processor and then you can perform any image operation.

Author:
chi

Method Summary
 void encode(InputStream input, OutputStream output, int encoder)
          Change the format of an image.
 Dimension getCurrentSize()
          Returns the size of the edited image.
 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.
 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.
 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 setJpegQuality(float jpegQuality)
          Set the JPEG quality of the image processor.
 void setTileSize(int tileWidth, int tileHeight)
          Set the tile width and height for a TIFF image, which is used in the encoding process.
 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.
 

Method Detail

resizeFitWidth

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. Default encoder is JPEG.

Parameters:
input - the image data as InputStream
newWidth - the new width
output - the scaled and encoded image as OutputStream

resizeFitHeight

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. Default encoder is JPEG.

Parameters:
input - the image data as InputStream
newHeight - the new height
output - the scaled and encoded image as OutputStream

resize

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. Default encoder is JPEG.

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

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. Default encoder is JPEG.

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

scaleROI

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. Default encoder is JPEG.

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

float getScaleFactor()
Returns the scale factor used for the accomplished scale operation.

Returns:
float value of the scale factor

getJpegQuality

float getJpegQuality()
Return the JPEG quality setting of the image processor.

Returns:
float value of the JPEG quality

setJpegQuality

void setJpegQuality(float jpegQuality)
Set the JPEG quality of the image processor.

Parameters:
jpegQuality - the float value of the JPEG quality

setTileSize

void setTileSize(int tileWidth,
                 int tileHeight)
Set the tile width and height for a TIFF image, which is used in the encoding process.

Parameters:
tileWidth -
tileHeight -

useEncoder

void useEncoder(int encoder)
                throws Exception
Set which encoder to use in the encoding process.

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

encode

void encode(InputStream input,
            OutputStream output,
            int encoder)
            throws Exception
Change the format of an image.

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

getOrigSize

Dimension getOrigSize()
                      throws Exception
Returns the original image size of the image currently loades in the processor.

Returns:
Dimension of the image
Throws:
Exception - if no image is loaded in the processor

getCurrentSize

Dimension getCurrentSize()
                         throws Exception
Returns the size of the edited image. The current size change after every scale operation.

Returns:
Dimension of the edited image
Throws:
Exception - if no image is loaded in the processor

getImageSize

Dimension getImageSize(InputStream input)
Returns the size of the image which is passed as InputStream.

Parameters:
input - the image data as InputStream
Returns:
Dimension of the image

loadImage

void loadImage(InputStream input)
Loads an image into the processor.

Parameters:
input - the image data as InputStream

hasCorrectTileSize

boolean hasCorrectTileSize()
                           throws Exception
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.

Returns:
true if the image has the correct tile size
Throws:
Exception - if no image is loaded in the processor

resizeFitWidth

void resizeFitWidth(int newWidth)
                    throws Exception
Scales the image to the new width in due proportion. An image should be loaded into the processor before using this method.

Parameters:
newWidth - the new width
Throws:
Exception - if no image is loaded in the processor

resizeFitHeight

void resizeFitHeight(int newHeight)
                     throws Exception
Scales the image to the new height in due proportion. An image should be loaded into the processor before using this method.

Parameters:
newHeight - the new height
Throws:
Exception - if no image is loaded in the processor

resize

void resize(int newWidth,
            int newHeight)
            throws Exception
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.

Parameters:
newWidth - new width to fit in
newHeight - new height to fit in
Throws:
Exception - if no image is loaded in the processor

scale

void scale(float scaleFactor)
           throws Exception
Scales the image with the given scale factor in due proportion.

Parameters:
scaleFactor - the scale factor for width and height of the image
Throws:
Exception - if no image is loaded in the processor

scaleROI

void scaleROI(int xTopPos,
              int yTopPos,
              int boundWidth,
              int boundHeight,
              float scaleFactor)
              throws Exception
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.

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
Throws:
Exception - if no image is loaded in the processor

jpegEncode

void jpegEncode(OutputStream output)
                throws Exception
Encode the loaded image as a JPEG image to a given OutputStream.

Parameters:
output - the encoded image
Throws:
Exception - if no image is loaded in the processor

tiffEncode

void tiffEncode(OutputStream output)
                throws Exception
Encode the loaded image as a TIFF image to a given OutputStream.

Parameters:
output - the encodes image
Throws:
Exception - if no image is loaded in the processor