Package digilib.image
Class DocuImageImpl
java.lang.Object
digilib.image.DocuImageImpl
- All Implemented Interfaces:
DocuImage
- Direct Known Subclasses:
ImageInfoDocuImage
Simple abstract implementation of the
DocuImage interface.
This implementation provides basic functionality for the utility methods like
getKnownFileTypes. Image methods like loadImage,
writeImage, getWidth, getHeight,
crop and scale must be implemented by derived
classes.-
Nested Class Summary
Nested classes/interfaces inherited from interface digilib.image.DocuImage
DocuImage.ColorOp -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleepsilon for float comparisons.image specific hintsprotected ImageSizeimage sizeprotected ImageInputImageInput that was readprotected static final org.slf4j.Loggerloggerprotected intInterpolation quality.static final StringDocuImage version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChanges the colors of the current image.voidcrop(int xoff, int yoff, int width, int height) Crops the current image.voidcropAndScale(int x_off, int y_off, int width, int height, double scale, int qual) Crop and scale the current image.voiddispose()Frees all resources bound to the DocuImage.voidenhance(float mult, float add) Enhances brightness and contrast of the current image.voidenhanceRGB(float[] rgbm, float[] rgba) Manipulates the colors of the current image.returns the underlying image as java.awt.Image (if possible, or null)Return String representation of implementation specific image hacks.intThe height of the current image in pixel.Returns the image specific hint with the given key.The mime-type of the image, i.e.intReturns the quality.getSize()The size of the current image in pixel.Returns the list of supported image formats.Returns the version.intgetWidth()The width of the current image in pixel.identify(ImageInput ii) Check image size and type and store in ImageInput iibooleanThis DocuImage supports the loadSubImage operation.abstract voidloadImage(ImageInput ii) Loads an image file into the Object.voidloadSubimage(ImageInput ii, Rectangle region, int subsample) Load only a subsampled region of the image file.voidmirror(double angle) Mirrors the current image.voidrotate(double angle) Rotates the current image.abstract voidscale(double scaleX, double scaleY) Scales the current image.voidSet implementation specific image hacks.voidSet optional image specific hints with additional information.voidsetQuality(int quality) Sets the quality.voidsetReaderClasses(Map<String, String> typeClassMap) Set preferred image reader classes.voidsetWriterClasses(Map<String, String> typeClassMap) Set preferred image writer classes.abstract voidwriteImage(String mt, OutputStream ostream) Writes the current image to an OutputStream.
-
Field Details
-
version
DocuImage version- See Also:
-
logger
protected static final org.slf4j.Logger loggerlogger -
quality
protected int qualityInterpolation quality. -
epsilon
public static final double epsilonepsilon for float comparisons.- See Also:
-
imgSize
image size -
input
ImageInput that was read -
hints
image specific hints
-
-
Constructor Details
-
DocuImageImpl
public DocuImageImpl()
-
-
Method Details
-
getVersion
Returns the version.- Specified by:
getVersionin interfaceDocuImage- Returns:
- the version
-
getQuality
public int getQuality()Returns the quality.- Specified by:
getQualityin interfaceDocuImage- Returns:
- int
-
setQuality
public void setQuality(int quality) Sets the quality.- Specified by:
setQualityin 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:
cropAndScalein 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
Description copied from interface:DocuImageThe mime-type of the image, i.e. the mime-type of the input that was read.- Specified by:
getMimetypein interfaceDocuImage- Returns:
- String the mime-type of this image.
-
identify
Description copied from interface:DocuImageCheck image size and type and store in ImageInput ii- Specified by:
identifyin interfaceDocuImage- Parameters:
ii- the ImageInput- Returns:
- the ImageInput
- Throws:
IOException- on error
-
rotate
Description copied from interface:DocuImageRotates the current image. Replaces the current image with a rotated image. The image is rotated around the center by theanglegiven in degrees [0, 360] clockwise. Image size and aspect ratio are likely to change.- Specified by:
rotatein interfaceDocuImage- Parameters:
angle- rotation angle in degree- Throws:
ImageOpException- on error
-
mirror
Description copied from interface:DocuImageMirrors the current image. Replaces the current image with a mirrored image. The mirror axis goes through the center of the image and is rotated byangledegrees. Currently only horizontal and vertical mirroring (0 and 90 degree) are supported.- Specified by:
mirrorin interfaceDocuImage- Parameters:
angle- angle of mirror axis- Throws:
ImageOpException- on error
-
enhance
Description copied from interface:DocuImageEnhances 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 constantaddto the pixel value. Operation: p1 = (p0*mult)+add.- Specified by:
enhancein 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:DocuImageThis DocuImage supports the loadSubImage operation.- Specified by:
isSubimageSupportedin interfaceDocuImage- Returns:
- if loadSubImage is supported
-
loadSubimage
Description copied from interface:DocuImageLoad only a subsampled region of the image file.- Specified by:
loadSubimagein interfaceDocuImage- Parameters:
ii- the ImageInputregion- the regionsubsample- the subsample- Throws:
FileOpException- on error
-
enhanceRGB
Description copied from interface:DocuImageManipulates 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 constantmand added to the constanta. Operation: p1 = (p0*m)+a.- Specified by:
enhanceRGBin interfaceDocuImage- Parameters:
rgbm- multiplicative constants for red, green, bluergba- additive constant for red, green, blue- Throws:
ImageOpException- on error
-
colorOp
Description copied from interface:DocuImageChanges 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:
colorOpin interfaceDocuImage- Parameters:
op- the ColorOp- Throws:
ImageOpException- on error
-
dispose
public void dispose()Description copied from interface:DocuImageFrees all resources bound to the DocuImage. Things that should be freed are image objects and open files. -
getSupportedFormats
Description copied from interface:DocuImageReturns the list of supported image formats.- Specified by:
getSupportedFormatsin interfaceDocuImage- Returns:
- the list of supported image formats
-
crop
Description copied from interface:DocuImageCrops the current image. Cuts out a region of the sizewidthxheightat the offsetxoff,yofffrom the current image and replaces the current image with the result.- Specified by:
cropin 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
Description copied from interface:DocuImagereturns the underlying image as java.awt.Image (if possible, or null)- Specified by:
getAwtImagein interfaceDocuImage- Returns:
- the Image
-
getHeight
public int getHeight()Description copied from interface:DocuImageThe height of the current image in pixel. -
getWidth
public int getWidth()Description copied from interface:DocuImageThe width of the current image in pixel. -
getSize
Description copied from interface:DocuImageThe size of the current image in pixel. -
loadImage
Description copied from interface:DocuImageLoads an image file into the Object.- Specified by:
loadImagein interfaceDocuImage- Parameters:
ii- Image File.- Throws:
FileOpException- Exception thrown if any error occurs.
-
scale
Description copied from interface:DocuImageScales the current image. Replaces the current image with an image scaled by the factorscale.- Specified by:
scalein 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:DocuImageWrites the current image to an OutputStream. The image is encoded to the mime-typemtand sent to the output streamostream. Currently only mime-types "image/jpeg", "image/png" and "image/webp" are supported.- Specified by:
writeImagein 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
Description copied from interface:DocuImageSet 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
Description copied from interface:DocuImageReturn String representation of implementation specific image hacks.- Specified by:
getHacksAsStringin interfaceDocuImage- Returns:
- the hackstring
-
setHint
Description copied from interface:DocuImageSet optional image specific hints with additional information. -
getHint
Description copied from interface:DocuImageReturns the image specific hint with the given key. -
setReaderClasses
Description copied from interface:DocuImageSet 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:
setReaderClassesin interfaceDocuImage- Parameters:
typeClassMap-
-
setWriterClasses
Description copied from interface:DocuImageSet 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:
setWriterClassesin interfaceDocuImage- Parameters:
typeClassMap-
-