Package digilib.image

Class DocuImageImpl

  • All Implemented Interfaces:
    DocuImage
    Direct Known Subclasses:
    ImageInfoDocuImage

    public abstract class DocuImageImpl
    extends Object
    implements DocuImage
    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.
    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
        logger
      • quality

        protected int quality
        Interpolation quality.
      • epsilon

        public static final double epsilon
        epsilon for float comparisons.
        See Also:
        Constant Field Values
      • imgSize

        protected ImageSize imgSize
        image size
      • input

        protected ImageInput input
        ImageInput that was read
    • Constructor Detail

      • DocuImageImpl

        public DocuImageImpl()
    • Method Detail

      • getVersion

        public String getVersion()
        Returns the version.
        Specified by:
        getVersion in interface DocuImage
        Returns:
        the version
      • getQuality

        public int getQuality()
        Returns the quality.
        Specified by:
        getQuality in interface DocuImage
        Returns:
        int
      • setQuality

        public void setQuality​(int quality)
        Sets the quality.
        Specified by:
        setQuality in interface DocuImage
        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:
        cropAndScale in interface DocuImage
        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

        public String getMimetype()
        Description copied from interface: DocuImage
        The mime-type of the image, i.e. the mime-type of the input that was read.
        Specified by:
        getMimetype in interface DocuImage
        Returns:
        String the mime-type of this image.
      • 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
        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
        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
        Parameters:
        mult - multiplicative constant for contrast enhancement
        add - additive constant for brightness enhancement
        Throws:
        ImageOpException - on error
      • isSubimageSupported

        public boolean isSubimageSupported()
        Description copied from interface: DocuImage
        This DocuImage supports the loadSubImage operation.
        Specified by:
        isSubimageSupported in interface DocuImage
        Returns:
        if loadSubImage is supported
      • 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
        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 op)
                     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
        Parameters:
        op - 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
      • getSupportedFormats

        public Iterator<String> getSupportedFormats()
        Description copied from interface: DocuImage
        Returns the list of supported image formats.
        Specified by:
        getSupportedFormats in interface DocuImage
        Returns:
        the list of supported image formats
      • crop

        public void crop​(int xoff,
                         int yoff,
                         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
        Parameters:
        xoff - X offset of crop region
        yoff - Y offset of crop region
        width - width of crop region
        height - height of crop region
        Throws:
        ImageOpException - on error
      • 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 interface DocuImage
        Returns:
        the Image
      • getHeight

        public int getHeight()
        Description copied from interface: DocuImage
        The height of the current image in pixel.
        Specified by:
        getHeight in interface DocuImage
        Returns:
        Image height in pixels.
      • getWidth

        public int getWidth()
        Description copied from interface: DocuImage
        The width of the current image in pixel.
        Specified by:
        getWidth in interface DocuImage
        Returns:
        Image width in pixels.
      • getSize

        public ImageSize getSize()
        Description copied from interface: DocuImage
        The size of the current image in pixel.
        Specified by:
        getSize in interface DocuImage
        Returns:
        the ImageSize
      • scale

        public abstract 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
        Parameters:
        scaleX - the scaleX
        scaleY - the scaleY
        Throws:
        ImageOpException - on error
      • writeImage

        public abstract 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-type mt and sent to the output stream ostream. Currently only mime-types "image/jpeg" and "image/png" are supported.
        Specified by:
        writeImage in interface DocuImage
        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

        public void setHacks​(String hacks)
        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
        Parameters:
        hacks - the hackString
      • getHacksAsString

        public String getHacksAsString()
        Description copied from interface: DocuImage
        Return String representation of implementation specific image hacks.
        Specified by:
        getHacksAsString in interface DocuImage
        Returns:
        the hackstring
      • setHint

        public void setHint​(String key,
                            Object value)
        Description copied from interface: DocuImage
        Set optional image specific hints with additional information.
        Specified by:
        setHint in interface DocuImage
        Parameters:
        key - the key
        value - the value
      • getHint

        public Object getHint​(String key)
        Description copied from interface: DocuImage
        Returns the image specific hint with the given key.
        Specified by:
        getHint in interface DocuImage
        Parameters:
        key - the key
        Returns:
        the hint
      • 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
      • 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