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 enum
hacks for specific platform bugsNested classes/interfaces inherited from interface digilib.image.DocuImage
DocuImage.ColorOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ICC_Profile
ICC color profile of the current image (null=sRGB)protected static Kernel[]
convolution kernels for blur()protected static EnumMap
<ImageLoaderDocuImage.Hacks, Boolean> active hacksprotected ImageSize
the size of the current imageprotected BufferedImage
image objectprotected static LookupTable
lookup table for inverting images (byte)protected static LookupTable
lookup table for inverting images (byte)protected static LookupTable
lookup table for false-colorpreferred image reader classespreferred image writer classesprotected ImageReader
the reader objectprotected RenderingHints
interpolation typeboolean
try to reuse reader objectstatic final String
DocuImage version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
blur
(int radius) Blur the image with a convolution using the given radius.protected BufferedImage
changeColorProfile
(BufferedImage bi, ICC_Profile profile) Change the color profile of a BufferedImage while keeping the same raw pixel values.protected void
changeRasterToSrgb
(BufferedImage img, ICC_Profile realProfile) Change the pixels of a BufferedImage in-place from the given profile to the sRGB color space.protected BufferedImage
Change the color depth of a BufferedImage to 8 bit.protected BufferedImage
Change the bit-depth of an image to 8 bit and remove the alpha channel.void
colorOp
(DocuImage.ColorOp colop) Changes the colors of the current image.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.void
crop
(int x_off, int y_off, int width, int height) Crops 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.returns the underlying image as java.awt.Image (if possible, or null)Return String representation of implementation specific image hacks.protected ICC_Profile
getPngColorProfile
(ImageReader reader) Extracts the ICC color profile from the PNG iCCP element of the given ImageReader.protected ImageReader
getReader
(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 ImageWriter
Get an ImageWriter for the mime-type.identify
(ImageInput input) Check image size and type and store in ImageInput iiboolean
This DocuImage supports the loadSubImage operation.void
loadImage
(ImageInput ii) Loads an image file into the Object.void
loadSubimage
(ImageInput ii, Rectangle region, int prescale) 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.void
scale
(double scaleX, double scaleY) Scales the current image.void
Set implementation specific image hacks.void
setQuality
(int qual) 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.void
writeImage
(String mt, OutputStream ostream) Writes the current image to an OutputStream.protected void
writeJpeg
(ImageWriter writer) Write the current image to the given ImageWriter as JPEG with the correct color profile.protected void
writePng
(ImageWriter writer) Write the current image to the given ImageWriter as PNG with the correct color profile.protected void
writeWebp
(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: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!).- Specified by:
setHacks
in interfaceDocuImage
- Overrides:
setHacks
in classDocuImageImpl
- Parameters:
hackString
- the hackString
-
getHacksAsString
Description copied from interface:DocuImage
Return String representation of implementation specific image hacks.- Specified by:
getHacksAsString
in interfaceDocuImage
- Overrides:
getHacksAsString
in classDocuImageImpl
- Returns:
- the hackstring
-
setReaderClasses
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
- Overrides:
setReaderClasses
in classDocuImageImpl
- Parameters:
typeClassMap
-
-
setWriterClasses
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
- Overrides:
setWriterClasses
in classDocuImageImpl
- Parameters:
typeClassMap
-
-
getVersion
Description copied from class:DocuImageImpl
Returns the version.- Specified by:
getVersion
in interfaceDocuImage
- Overrides:
getVersion
in classDocuImageImpl
- Returns:
- the version
-
isSubimageSupported
public boolean isSubimageSupported()Description copied from interface:DocuImage
This DocuImage supports the loadSubImage operation.- Specified by:
isSubimageSupported
in interfaceDocuImage
- Overrides:
isSubimageSupported
in classDocuImageImpl
- Returns:
- if loadSubImage is supported
-
setQuality
public void setQuality(int qual) Description copied from class:DocuImageImpl
Sets the quality.- Specified by:
setQuality
in interfaceDocuImage
- Overrides:
setQuality
in classDocuImageImpl
- Parameters:
qual
- The quality to set
-
getSize
Description copied from interface:DocuImage
The size of the current image in pixel.- Specified by:
getSize
in interfaceDocuImage
- Overrides:
getSize
in classDocuImageImpl
- Returns:
- the ImageSize
-
getSupportedFormats
Description copied from interface:DocuImage
Returns the list of supported image formats.- Specified by:
getSupportedFormats
in interfaceDocuImage
- Overrides:
getSupportedFormats
in 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:DocuImage
Check image size and type and store in ImageInput ii- Specified by:
identify
in interfaceDocuImage
- Overrides:
identify
in classImageInfoDocuImage
- Parameters:
input
- the ImageInput- Returns:
- the ImageInput
- Throws:
IOException
- on error
-
loadImage
Description copied from interface:DocuImage
Loads an image file into the Object.- Specified by:
loadImage
in interfaceDocuImage
- Specified by:
loadImage
in 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:DocuImage
Load only a subsampled region of the image file.- Specified by:
loadSubimage
in interfaceDocuImage
- Overrides:
loadSubimage
in 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: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", "image/png" and "image/webp" are supported.- Specified by:
writeImage
in interfaceDocuImage
- Specified by:
writeImage
in 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:
IOException
IIOInvalidTreeException
-
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:DocuImage
Scales the current image. Replaces the current image with an image scaled by the factorscale
.- Specified by:
scale
in interfaceDocuImage
- Specified by:
scale
in 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: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
- Overrides:
crop
in 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: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
- Overrides:
rotate
in classDocuImageImpl
- Parameters:
angle
- rotation angle in degree- Throws:
ImageOpException
- on error
-
mirror
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
- Overrides:
mirror
in classDocuImageImpl
- Parameters:
angle
- angle of mirror axis- Throws:
ImageOpException
- on error
-
enhance
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
- Overrides:
enhance
in classDocuImageImpl
- Parameters:
mult
- multiplicative constant for contrast enhancementadd
- additive constant for brightness enhancement- Throws:
ImageOpException
- on error
-
enhanceRGB
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
- Overrides:
enhanceRGB
in classDocuImageImpl
- Parameters:
rgbm
- multiplicative constants for red, green, bluergba
- additive constant for red, green, blue- Throws:
ImageOpException
- on error
-
colorOp
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
- Overrides:
colorOp
in classDocuImageImpl
- Parameters:
colop
- 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.- Specified by:
dispose
in interfaceDocuImage
- Overrides:
dispose
in classDocuImageImpl
-
getAwtImage
Description copied from interface:DocuImage
returns the underlying image as java.awt.Image (if possible, or null)- Specified by:
getAwtImage
in interfaceDocuImage
- Overrides:
getAwtImage
in classDocuImageImpl
- Returns:
- the Image
-