Package digilib.image
Class ImageLoaderDocuImage
- java.lang.Object
-
- digilib.image.DocuImageImpl
-
- digilib.image.ImageInfoDocuImage
-
- digilib.image.ImageLoaderDocuImage
-
- All Implemented Interfaces:
DocuImage
public class ImageLoaderDocuImage extends ImageInfoDocuImage
Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ImageLoaderDocuImage.Hacks
hacks for specific platform bugs-
Nested classes/interfaces inherited from interface digilib.image.DocuImage
DocuImage.ColorOp
-
-
Field Summary
Fields Modifier and Type Field Description protected ICC_Profile
colorProfile
ICC color profile of the current image (null=sRGB)protected static Kernel[]
convolutionKernels
convolution kernels for blur()protected static EnumMap<ImageLoaderDocuImage.Hacks,Boolean>
imageHacks
active hacksprotected ImageSize
imageSize
the size of the current imageprotected BufferedImage
img
image objectprotected static LookupTable
invertRgbaByteTable
lookup table for inverting images (byte)protected static LookupTable
invertSingleByteTable
lookup table for inverting images (byte)protected static LookupTable
mapBgrByteTable
lookup table for false-colorprotected static Map<String,String>
preferredReaders
preferred image reader classesprotected static Map<String,String>
preferredWriters
preferred image writer classesprotected ImageReader
reader
the reader objectprotected RenderingHints
renderHint
interpolation typeboolean
reuseReader
try to reuse reader objectstatic String
version
DocuImage version
-
Constructor Summary
Constructors Constructor Description ImageLoaderDocuImage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
changeTo8BitDepth(BufferedImage bi)
Change the color depth of a BufferedImage to 8 bit.protected BufferedImage
changeTo8BitNoAlpha(BufferedImage bi)
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.Image
getAwtImage()
returns the underlying image as java.awt.Image (if possible, or null)String
getHacksAsString()
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.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.protected ImageWriter
getWriter(String mimetype)
Get an ImageWriter for the mime-type.ImageInput
identify(ImageInput input)
Check image size and type and store in ImageInput iiboolean
isSubimageSupported()
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
setHacks(String hackString)
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.-
Methods inherited from class digilib.image.DocuImageImpl
cropAndScale, getHeight, getHint, getMimetype, getQuality, getWidth, setHint
-
-
-
-
Field Detail
-
version
public static final String version
DocuImage version- See Also:
- Constant Field Values
-
img
protected BufferedImage img
image object
-
reader
protected ImageReader reader
the reader object
-
reuseReader
public boolean reuseReader
try to reuse reader object
-
renderHint
protected RenderingHints renderHint
interpolation type
-
convolutionKernels
protected static Kernel[] convolutionKernels
convolution kernels for blur()
-
invertSingleByteTable
protected static LookupTable invertSingleByteTable
lookup table for inverting images (byte)
-
invertRgbaByteTable
protected static LookupTable invertRgbaByteTable
lookup table for inverting images (byte)
-
mapBgrByteTable
protected static LookupTable mapBgrByteTable
lookup table for false-color
-
imageHacks
protected static EnumMap<ImageLoaderDocuImage.Hacks,Boolean> imageHacks
active hacks
-
preferredReaders
protected static Map<String,String> preferredReaders
preferred image reader classes
-
preferredWriters
protected static Map<String,String> preferredWriters
preferred image writer classes
-
imageSize
protected ImageSize imageSize
the size of the current image
-
colorProfile
protected ICC_Profile colorProfile
ICC color profile of the current image (null=sRGB)
-
-
Method Detail
-
setHacks
public void setHacks(String hackString)
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
public String 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
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
- Overrides:
setReaderClasses
in classDocuImageImpl
-
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
- Overrides:
setWriterClasses
in classDocuImageImpl
-
getVersion
public String 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
public ImageSize 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
public Iterator<String> 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
protected BufferedImage changeColorProfile(BufferedImage bi, ICC_Profile profile)
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
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. This is only useful if the BufferedImage has an sRGB ColorSpace but the pixel values are actually matching realProfile.- Parameters:
img
-realProfile
-
-
changeTo8BitDepth
protected BufferedImage changeTo8BitDepth(BufferedImage bi)
Change the color depth of a BufferedImage to 8 bit.- Parameters:
bi
-- Returns:
-
changeTo8BitNoAlpha
protected BufferedImage changeTo8BitNoAlpha(BufferedImage bi)
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
public ImageInput identify(ImageInput input) throws IOException
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
public void loadImage(ImageInput ii) throws FileOpException
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
protected ImageReader getReader(ImageInput input) throws IOException
Get an ImageReader for the image input.- Parameters:
input
- the ImageInput- Returns:
- the ImageReader
- Throws:
IOException
- on error
-
getPngColorProfile
protected ICC_Profile getPngColorProfile(ImageReader reader) throws IOException
Extracts the ICC color profile from the PNG iCCP element of the given ImageReader.- Parameters:
reader
-- Returns:
- Throws:
IOException
-
loadSubimage
public void loadSubimage(ImageInput ii, Rectangle region, int prescale) throws FileOpException
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
protected ImageWriter getWriter(String mimetype) throws ImageOpException
Get an ImageWriter for the mime-type.- Parameters:
mimetype
-- Returns:
- Throws:
ImageOpException
-
writeImage
public 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
- 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
protected void writePng(ImageWriter writer) throws IOException, IIOInvalidTreeException
Write the current image to the given ImageWriter as PNG with the correct color profile.- Parameters:
writer
-- Throws:
IOException
IIOInvalidTreeException
-
writeJpeg
protected void writeJpeg(ImageWriter writer) throws IOException
Write the current image to the given ImageWriter as JPEG with the correct color profile.- Parameters:
writer
-- Throws:
IOException
-
scale
public 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
- Specified by:
scale
in classDocuImageImpl
- Parameters:
scaleX
- the scaleXscaleY
- the scaleY- Throws:
ImageOpException
- on error
-
blur
public void blur(int radius) throws ImageOpException
Blur the image with a convolution using the given radius.- Parameters:
radius
- the radius- Throws:
ImageOpException
- on error
-
crop
public void crop(int x_off, int y_off, 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
- 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
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
- Overrides:
rotate
in classDocuImageImpl
- 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
- Overrides:
mirror
in classDocuImageImpl
- 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
- Overrides:
enhance
in classDocuImageImpl
- Parameters:
mult
- multiplicative constant for contrast enhancementadd
- additive constant for brightness enhancement- Throws:
ImageOpException
- 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
- Overrides:
enhanceRGB
in classDocuImageImpl
- Parameters:
rgbm
- multiplicative constants for red, green, bluergba
- additive constant for red, green, blue- Throws:
ImageOpException
- on error
-
colorOp
public void colorOp(DocuImage.ColorOp colop) 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
- 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
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
- Overrides:
getAwtImage
in classDocuImageImpl
- Returns:
- the Image
-
-