Package digilib.image

Class ImageLoaderDocuImage

  • All Implemented Interfaces:
    DocuImage

    public class ImageLoaderDocuImage
    extends ImageInfoDocuImage
    Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D.
    • Field Detail

      • reader

        protected ImageReader reader
        the reader object
      • reuseReader

        public boolean reuseReader
        try to reuse reader object
      • 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
      • 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)
    • Constructor Detail

      • ImageLoaderDocuImage

        public ImageLoaderDocuImage()
    • 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 interface DocuImage
        Overrides:
        setHacks in class DocuImageImpl
        Parameters:
        hackString - 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 interface DocuImage
        Overrides:
        setReaderClasses in class DocuImageImpl
      • 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 interface DocuImage
        Overrides:
        setWriterClasses in class DocuImageImpl
      • 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:
      • 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
      • 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 factor scale.
        Specified by:
        scale in interface DocuImage
        Specified by:
        scale in class DocuImageImpl
        Parameters:
        scaleX - the scaleX
        scaleY - 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 size width x height at the offset xoff, yoff from the current image and replaces the current image with the result.
        Specified by:
        crop in interface DocuImage
        Overrides:
        crop in class DocuImageImpl
        Parameters:
        x_off - X offset of crop region
        y_off - Y offset of crop region
        width - width of crop region
        height - 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 the angle given in degrees [0, 360] clockwise. Image size and aspect ratio are likely to change.
        Specified by:
        rotate in interface DocuImage
        Overrides:
        rotate in class DocuImageImpl
        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 by angle degrees. Currently only horizontal and vertical mirroring (0 and 90 degree) are supported.
        Specified by:
        mirror in interface DocuImage
        Overrides:
        mirror in class DocuImageImpl
        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 constant mult. Brightness is enhanced by adding the constant add to the pixel value. Operation: p1 = (p0*mult)+add.
        Specified by:
        enhance in interface DocuImage
        Overrides:
        enhance in class DocuImageImpl
        Parameters:
        mult - multiplicative constant for contrast enhancement
        add - 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 constant m and added to the constant a. Operation: p1 = (p0*m)+a.
        Specified by:
        enhanceRGB in interface DocuImage
        Overrides:
        enhanceRGB in class DocuImageImpl
        Parameters:
        rgbm - multiplicative constants for red, green, blue
        rgba - 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 interface DocuImage
        Overrides:
        colorOp in class DocuImageImpl
        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 interface DocuImage
        Overrides:
        dispose in class DocuImageImpl