Package digilib.image
Class DocuImageImpl
- java.lang.Object
-
- digilib.image.DocuImageImpl
-
- All Implemented Interfaces:
DocuImage
- Direct Known Subclasses:
ImageInfoDocuImage
public abstract class DocuImageImpl extends Object implements DocuImage
Simple abstract implementation of theDocuImage
interface. This implementation provides basic functionality for the utility methods likegetKnownFileTypes
. Image methods likeloadImage
,writeImage
,getWidth
,getHeight
,crop
andscale
must be implemented by derived classes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface digilib.image.DocuImage
DocuImage.ColorOp
-
-
Field Summary
Fields Modifier and Type Field Description static double
epsilon
epsilon for float comparisons.protected Map<String,Object>
hints
image specific hintsprotected ImageSize
imgSize
image sizeprotected ImageInput
input
ImageInput that was readprotected static org.slf4j.Logger
logger
loggerprotected int
quality
Interpolation quality.static String
version
DocuImage version
-
Constructor Summary
Constructors Constructor Description DocuImageImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
colorOp(DocuImage.ColorOp op)
Changes the colors of the current image.void
crop(int xoff, int yoff, int width, int height)
Crops the current image.void
cropAndScale(int x_off, int y_off, int width, int height, double scale, int qual)
Crop and scale the current image.void
dispose()
Frees all resources bound to the DocuImage.void
enhance(float mult, float add)
Enhances brightness and contrast of the current image.void
enhanceRGB(float[] rgbm, float[] rgba)
Manipulates the colors of the current image.Image
getAwtImage()
returns the underlying image as java.awt.Image (if possible, or null)String
getHacksAsString()
Return String representation of implementation specific image hacks.int
getHeight()
The height of the current image in pixel.Object
getHint(String key)
Returns the image specific hint with the given key.String
getMimetype()
The mime-type of the image, i.e.int
getQuality()
Returns the quality.ImageSize
getSize()
The size of the current image in pixel.Iterator<String>
getSupportedFormats()
Returns the list of supported image formats.String
getVersion()
Returns the version.int
getWidth()
The width of the current image in pixel.ImageInput
identify(ImageInput ii)
Check image size and type and store in ImageInput iiboolean
isSubimageSupported()
This DocuImage supports the loadSubImage operation.abstract void
loadImage(ImageInput ii)
Loads an image file into the Object.void
loadSubimage(ImageInput ii, Rectangle region, int subsample)
Load only a subsampled region of the image file.void
mirror(double angle)
Mirrors the current image.void
rotate(double angle)
Rotates the current image.abstract void
scale(double scaleX, double scaleY)
Scales the current image.void
setHacks(String hacks)
Set implementation specific image hacks.void
setHint(String key, Object value)
Set optional image specific hints with additional information.void
setQuality(int quality)
Sets the quality.void
setReaderClasses(Map<String,String> typeClassMap)
Set preferred image reader classes.void
setWriterClasses(Map<String,String> typeClassMap)
Set preferred image writer classes.abstract void
writeImage(String mt, OutputStream ostream)
Writes the current image to an OutputStream.
-
-
-
Field Detail
-
version
public static final String version
DocuImage version- See Also:
- Constant Field Values
-
logger
protected static final org.slf4j.Logger logger
logger
-
quality
protected int quality
Interpolation quality.
-
epsilon
public static final double epsilon
epsilon for float comparisons.- See Also:
- Constant Field Values
-
imgSize
protected ImageSize imgSize
image size
-
input
protected ImageInput input
ImageInput that was read
-
-
Method Detail
-
getVersion
public String getVersion()
Returns the version.- Specified by:
getVersion
in interfaceDocuImage
- Returns:
- the version
-
getQuality
public int getQuality()
Returns the quality.- Specified by:
getQuality
in interfaceDocuImage
- Returns:
- int
-
setQuality
public void setQuality(int quality)
Sets the quality.- Specified by:
setQuality
in interfaceDocuImage
- Parameters:
quality
- The quality to set
-
cropAndScale
public void cropAndScale(int x_off, int y_off, int width, int height, double scale, int qual) throws ImageOpException
Crop and scale the current image. The current image is cropped to a rectangle of width, height at position x_off, y_off. The resulting image is scaled by the factor scale using the interpolation quality qual (0=worst).- Specified by:
cropAndScale
in interfaceDocuImage
- Parameters:
x_off
- X offset of the crop rectangle in pixel.y_off
- Y offset of the crop rectangle in pixel.width
- Width of the crop rectangle in pixel.height
- Height of the crop rectangle in pixel.scale
- Scaling factor.qual
- Interpolation quality (0=worst).- Throws:
ImageOpException
- Exception thrown on any error.
-
getMimetype
public String getMimetype()
Description copied from interface:DocuImage
The mime-type of the image, i.e. the mime-type of the input that was read.- Specified by:
getMimetype
in interfaceDocuImage
- Returns:
- String the mime-type of this image.
-
identify
public ImageInput identify(ImageInput ii) throws IOException
Description copied from interface:DocuImage
Check image size and type and store in ImageInput ii- Specified by:
identify
in interfaceDocuImage
- Parameters:
ii
- the ImageInput- Returns:
- the ImageInput
- Throws:
IOException
- on error
-
rotate
public void rotate(double angle) throws ImageOpException
Description copied from interface:DocuImage
Rotates the current image. Replaces the current image with a rotated image. The image is rotated around the center by theangle
given in degrees [0, 360] clockwise. Image size and aspect ratio are likely to change.- Specified by:
rotate
in interfaceDocuImage
- Parameters:
angle
- rotation angle in degree- Throws:
ImageOpException
- on error
-
mirror
public void mirror(double angle) throws ImageOpException
Description copied from interface:DocuImage
Mirrors the current image. Replaces the current image with a mirrored image. The mirror axis goes through the center of the image and is rotated byangle
degrees. Currently only horizontal and vertical mirroring (0 and 90 degree) are supported.- Specified by:
mirror
in interfaceDocuImage
- Parameters:
angle
- angle of mirror axis- Throws:
ImageOpException
- on error
-
enhance
public void enhance(float mult, float add) throws ImageOpException
Description copied from interface:DocuImage
Enhances brightness and contrast of the current image. Replaces the current image with a brightness and contrast enhanced image. Contrast is enhanced by multiplying the pixel value with the constantmult
. Brightness is enhanced by adding the constantadd
to the pixel value. Operation: p1 = (p0*mult)+add.- Specified by:
enhance
in interfaceDocuImage
- Parameters:
mult
- multiplicative constant for contrast enhancementadd
- additive constant for brightness enhancement- Throws:
ImageOpException
- on error
-
isSubimageSupported
public boolean isSubimageSupported()
Description copied from interface:DocuImage
This DocuImage supports the loadSubImage operation.- Specified by:
isSubimageSupported
in interfaceDocuImage
- Returns:
- if loadSubImage is supported
-
loadSubimage
public void loadSubimage(ImageInput ii, Rectangle region, int subsample) throws FileOpException
Description copied from interface:DocuImage
Load only a subsampled region of the image file.- Specified by:
loadSubimage
in interfaceDocuImage
- Parameters:
ii
- the ImageInputregion
- the regionsubsample
- the subsample- Throws:
FileOpException
- on error
-
enhanceRGB
public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException
Description copied from interface:DocuImage
Manipulates the colors of the current image. Replaces the current image with a color modified image. For the red, green and blue color channels all pixel values are multiplied by the constantm
and added to the constanta
. Operation: p1 = (p0*m)+a.- Specified by:
enhanceRGB
in interfaceDocuImage
- Parameters:
rgbm
- multiplicative constants for red, green, bluergba
- additive constant for red, green, blue- Throws:
ImageOpException
- on error
-
colorOp
public void colorOp(DocuImage.ColorOp op) throws ImageOpException
Description copied from interface:DocuImage
Changes the colors of the current image. Changes the colors of the current image. Operations are instances of ColorOp: GRAYSCALE: cast color image to grayscale NTSC_GRAY: convert color image to grayscale using NTSC formula INVERT: invert colors (every channel separately) MAP_GRAY_BGR: false color image from grayscale (0: blue, 128: green, 255: red)- Specified by:
colorOp
in interfaceDocuImage
- Parameters:
op
- the ColorOp- Throws:
ImageOpException
- on error
-
dispose
public void dispose()
Description copied from interface:DocuImage
Frees all resources bound to the DocuImage. Things that should be freed are image objects and open files.
-
getSupportedFormats
public Iterator<String> getSupportedFormats()
Description copied from interface:DocuImage
Returns the list of supported image formats.- Specified by:
getSupportedFormats
in interfaceDocuImage
- Returns:
- the list of supported image formats
-
crop
public void crop(int xoff, int yoff, int width, int height) throws ImageOpException
Description copied from interface:DocuImage
Crops the current image. Cuts out a region of the sizewidth
xheight
at the offsetxoff
,yoff
from the current image and replaces the current image with the result.- Specified by:
crop
in interfaceDocuImage
- Parameters:
xoff
- X offset of crop regionyoff
- Y offset of crop regionwidth
- width of crop regionheight
- height of crop region- Throws:
ImageOpException
- on error
-
getAwtImage
public Image getAwtImage()
Description copied from interface:DocuImage
returns the underlying image as java.awt.Image (if possible, or null)- Specified by:
getAwtImage
in interfaceDocuImage
- Returns:
- the Image
-
getHeight
public int getHeight()
Description copied from interface:DocuImage
The height of the current image in pixel.
-
getWidth
public int getWidth()
Description copied from interface:DocuImage
The width of the current image in pixel.
-
getSize
public ImageSize getSize()
Description copied from interface:DocuImage
The size of the current image in pixel.
-
loadImage
public abstract void loadImage(ImageInput ii) throws FileOpException
Description copied from interface:DocuImage
Loads an image file into the Object.- Specified by:
loadImage
in interfaceDocuImage
- Parameters:
ii
- Image File.- Throws:
FileOpException
- Exception thrown if any error occurs.
-
scale
public abstract void scale(double scaleX, double scaleY) throws ImageOpException
Description copied from interface:DocuImage
Scales the current image. Replaces the current image with an image scaled by the factorscale
.- Specified by:
scale
in interfaceDocuImage
- Parameters:
scaleX
- the scaleXscaleY
- the scaleY- Throws:
ImageOpException
- on error
-
writeImage
public abstract void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException
Description copied from interface:DocuImage
Writes the current image to an OutputStream. The image is encoded to the mime-typemt
and sent to the output streamostream
. Currently only mime-types "image/jpeg" and "image/png" are supported.- Specified by:
writeImage
in interfaceDocuImage
- Parameters:
mt
- mime-type of the image to be sent.ostream
- OutputStream where the image is sent.- Throws:
ImageOpException
- Exception in other cases.FileOpException
- Exception on sending data
-
setHacks
public void setHacks(String hacks)
Description copied from interface:DocuImage
Set implementation specific image hacks. Sets static class members. Needs to be called only once per class. Format: comma separated key=value pairs (no spaces!).
-
getHacksAsString
public String getHacksAsString()
Description copied from interface:DocuImage
Return String representation of implementation specific image hacks.- Specified by:
getHacksAsString
in interfaceDocuImage
- Returns:
- the hackstring
-
setHint
public void setHint(String key, Object value)
Description copied from interface:DocuImage
Set optional image specific hints with additional information.
-
getHint
public Object getHint(String key)
Description copied from interface:DocuImage
Returns the image specific hint with the given key.
-
setReaderClasses
public void setReaderClasses(Map<String,String> typeClassMap)
Description copied from interface:DocuImage
Set preferred image reader classes. Configured with a Map containing content-type and class-name. Sets static class members. Needs to be called only once per class.- Specified by:
setReaderClasses
in interfaceDocuImage
-
setWriterClasses
public void setWriterClasses(Map<String,String> typeClassMap)
Description copied from interface:DocuImage
Set preferred image writer classes. Configured with a Map containing content-type and class-name. Sets static class members. Needs to be called only once per class.- Specified by:
setWriterClasses
in interfaceDocuImage
-
-