Package digilib.image
Class ImageLoaderDocuImage
java.lang.Object
digilib.image.DocuImageImpl
digilib.image.ImageInfoDocuImage
digilib.image.ImageLoaderDocuImage
- All Implemented Interfaces:
DocuImage
Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumhacks for specific platform bugsNested classes/interfaces inherited from interface digilib.image.DocuImage
DocuImage.ColorOp -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ICC_ProfileICC color profile of the current image (null=sRGB)protected static Kernel[]convolution kernels for blur()protected static EnumMap<ImageLoaderDocuImage.Hacks, Boolean> active hacksprotected ImageSizethe size of the current imageprotected BufferedImageimage objectprotected static LookupTablelookup table for inverting images (byte)protected static LookupTablelookup table for inverting images (byte)protected static LookupTablelookup table for false-colorpreferred image reader classespreferred image writer classesprotected ImageReaderthe reader objectprotected RenderingHintsinterpolation typebooleantry to reuse reader objectstatic final StringDocuImage version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidblur(int radius) Blur the image with a convolution using the given radius.protected BufferedImagechangeColorProfile(BufferedImage bi, ICC_Profile profile) Change the color profile of a BufferedImage while keeping the same raw pixel values.protected voidchangeRasterToSrgb(BufferedImage img, ICC_Profile realProfile) Change the pixels of a BufferedImage in-place from the given profile to the sRGB color space.protected BufferedImageChange the color depth of a BufferedImage to 8 bit.protected BufferedImageChange the bit-depth of an image to 8 bit and remove the alpha channel.voidcolorOp(DocuImage.ColorOp colop) Changes the colors of the current image.protected BufferedImagecreateCompatibleImage(int width, int height, boolean hasAlpha, BufferedImage oldImg) Create an empty BufferedImage that is compatible and uses the same ColorModel as oldImg.voidcrop(int x_off, int y_off, int width, int height) Crops 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.protected ICC_ProfilegetPngColorProfile(ImageReader reader) Extracts the ICC color profile from the PNG iCCP element of the given ImageReader.protected ImageReadergetReader(ImageInput input) Get an ImageReader for the image input.getSize()The size of the current image in pixel.Returns the list of supported image formats.Returns the version.protected ImageWriterGet an ImageWriter for the mime-type.identify(ImageInput input) Check image size and type and store in ImageInput iibooleanThis DocuImage supports the loadSubImage operation.voidloadImage(ImageInput ii) Loads an image file into the Object.voidloadSubimage(ImageInput ii, Rectangle region, int prescale) Load only a subsampled region of the image file.voidmirror(double angle) Mirrors the current image.voidrotate(double angle) Rotates the current image.voidscale(double scaleX, double scaleY) Scales the current image.voidSet implementation specific image hacks.voidsetQuality(int qual) Sets the quality.voidsetReaderClasses(Map<String, String> typeClassMap) Set preferred image reader classes.voidsetWriterClasses(Map<String, String> typeClassMap) Set preferred image writer classes.voidwriteImage(String mt, OutputStream ostream) Writes the current image to an OutputStream.protected voidwriteJpeg(ImageWriter writer) Write the current image to the given ImageWriter as JPEG with the correct color profile.protected voidwritePng(ImageWriter writer) Write the current image to the given ImageWriter as PNG with the correct color profile.protected voidwriteWebp(ImageWriter writer) Write the current image to the given ImageWriter as WEBP.Methods inherited from class digilib.image.DocuImageImpl
cropAndScale, getHeight, getHint, getMimetype, getQuality, getWidth, setHint
-
Field Details
-
version
DocuImage version- See Also:
-
img
image object -
reader
the reader object -
reuseReader
public boolean reuseReadertry to reuse reader object -
renderHint
interpolation type -
convolutionKernels
convolution kernels for blur() -
invertSingleByteTable
lookup table for inverting images (byte) -
invertRgbaByteTable
lookup table for inverting images (byte) -
mapBgrByteTable
lookup table for false-color -
imageHacks
active hacks -
preferredReaders
preferred image reader classes -
preferredWriters
preferred image writer classes -
imageSize
the size of the current image -
colorProfile
ICC color profile of the current image (null=sRGB)
-
-
Constructor Details
-
ImageLoaderDocuImage
public ImageLoaderDocuImage()
-
-
Method Details
-
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!).- Specified by:
setHacksin interfaceDocuImage- Overrides:
setHacksin classDocuImageImpl- Parameters:
hackString- the hackString
-
getHacksAsString
Description copied from interface:DocuImageReturn String representation of implementation specific image hacks.- Specified by:
getHacksAsStringin interfaceDocuImage- Overrides:
getHacksAsStringin classDocuImageImpl- Returns:
- the hackstring
-
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- Overrides:
setReaderClassesin classDocuImageImpl- 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- Overrides:
setWriterClassesin classDocuImageImpl- Parameters:
typeClassMap-
-
getVersion
Description copied from class:DocuImageImplReturns the version.- Specified by:
getVersionin interfaceDocuImage- Overrides:
getVersionin classDocuImageImpl- Returns:
- the version
-
isSubimageSupported
public boolean isSubimageSupported()Description copied from interface:DocuImageThis DocuImage supports the loadSubImage operation.- Specified by:
isSubimageSupportedin interfaceDocuImage- Overrides:
isSubimageSupportedin classDocuImageImpl- Returns:
- if loadSubImage is supported
-
setQuality
public void setQuality(int qual) Description copied from class:DocuImageImplSets the quality.- Specified by:
setQualityin interfaceDocuImage- Overrides:
setQualityin classDocuImageImpl- Parameters:
qual- The quality to set
-
getSize
Description copied from interface:DocuImageThe size of the current image in pixel.- Specified by:
getSizein interfaceDocuImage- Overrides:
getSizein classDocuImageImpl- Returns:
- the ImageSize
-
getSupportedFormats
Description copied from interface:DocuImageReturns the list of supported image formats.- Specified by:
getSupportedFormatsin interfaceDocuImage- Overrides:
getSupportedFormatsin classDocuImageImpl- Returns:
- the list of supported image formats
-
createCompatibleImage
protected BufferedImage createCompatibleImage(int width, int height, boolean hasAlpha, BufferedImage oldImg) Create an empty BufferedImage that is compatible and uses the same ColorModel as oldImg.- Parameters:
width-height-hasAlpha-oldImg-- Returns:
-
changeColorProfile
Change the color profile of a BufferedImage while keeping the same raw pixel values. Returns a new BufferedImage with the given profile.- Parameters:
bi-profile-- Returns:
-
changeRasterToSrgb
Change the pixels of a BufferedImage in-place from the given profile to the sRGB color space. This is only useful if the BufferedImage has an sRGB ColorSpace but the pixel values are actually matching realProfile.- Parameters:
img-realProfile-
-
changeTo8BitDepth
Change the color depth of a BufferedImage to 8 bit.- Parameters:
bi-- Returns:
-
changeTo8BitNoAlpha
Change the bit-depth of an image to 8 bit and remove the alpha channel. Removes the alpha channel by ignoring the alpha band. Returns a new BufferedImage using the same ColorSpace.- Parameters:
bi-- Returns:
-
identify
Description copied from interface:DocuImageCheck image size and type and store in ImageInput ii- Specified by:
identifyin interfaceDocuImage- Overrides:
identifyin classImageInfoDocuImage- Parameters:
input- the ImageInput- Returns:
- the ImageInput
- Throws:
IOException- on error
-
loadImage
Description copied from interface:DocuImageLoads an image file into the Object.- Specified by:
loadImagein interfaceDocuImage- Specified by:
loadImagein classDocuImageImpl- Parameters:
ii- Image File.- Throws:
FileOpException- Exception thrown if any error occurs.
-
getReader
Get an ImageReader for the image input.- Parameters:
input- the ImageInput- Returns:
- the ImageReader
- Throws:
IOException- on error
-
getPngColorProfile
Extracts the ICC color profile from the PNG iCCP element of the given ImageReader.- Parameters:
reader-- Returns:
- Throws:
IOException
-
loadSubimage
Description copied from interface:DocuImageLoad only a subsampled region of the image file.- Specified by:
loadSubimagein interfaceDocuImage- Overrides:
loadSubimagein classDocuImageImpl- Parameters:
ii- the ImageInputregion- the regionprescale- the subsample- Throws:
FileOpException- on error
-
getWriter
Get an ImageWriter for the mime-type.- Parameters:
mimetype-- Returns:
- Throws:
ImageOpException
-
writeImage
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- Specified by:
writeImagein classDocuImageImpl- 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
-
writePng
Write the current image to the given ImageWriter as PNG with the correct color profile.- Parameters:
writer-- Throws:
IOExceptionIIOInvalidTreeException
-
writeJpeg
Write the current image to the given ImageWriter as JPEG with the correct color profile.- Parameters:
writer-- Throws:
IOException
-
writeWebp
Write the current image to the given ImageWriter as WEBP.- Parameters:
writer-- Throws:
IOException
-
scale
Description copied from interface:DocuImageScales the current image. Replaces the current image with an image scaled by the factorscale.- Specified by:
scalein interfaceDocuImage- Specified by:
scalein classDocuImageImpl- Parameters:
scaleX- the scaleXscaleY- the scaleY- Throws:
ImageOpException- on error
-
blur
Blur the image with a convolution using the given radius.- Parameters:
radius- the radius- Throws:
ImageOpException- on error
-
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- Overrides:
cropin classDocuImageImpl- Parameters:
x_off- X offset of crop regiony_off- Y offset of crop regionwidth- width of crop regionheight- height of crop region- Throws:
ImageOpException- 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- Overrides:
rotatein classDocuImageImpl- 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- Overrides:
mirrorin classDocuImageImpl- 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- Overrides:
enhancein classDocuImageImpl- Parameters:
mult- multiplicative constant for contrast enhancementadd- additive constant for brightness enhancement- Throws:
ImageOpException- 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- Overrides:
enhanceRGBin classDocuImageImpl- 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- Overrides:
colorOpin classDocuImageImpl- Parameters:
colop- 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.- Specified by:
disposein interfaceDocuImage- Overrides:
disposein classDocuImageImpl
-
getAwtImage
Description copied from interface:DocuImagereturns the underlying image as java.awt.Image (if possible, or null)- Specified by:
getAwtImagein interfaceDocuImage- Overrides:
getAwtImagein classDocuImageImpl- Returns:
- the Image
-