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 Details

    • version

      public static final String version
      DocuImage version
      See Also:
    • 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)
  • Constructor Details

    • ImageLoaderDocuImage

      public ImageLoaderDocuImage()
  • Method Details

    • 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
    • getHacksAsString

      public String getHacksAsString()
      Description copied from interface: DocuImage
      Return String representation of implementation specific image hacks.
      Specified by:
      getHacksAsString in interface DocuImage
      Overrides:
      getHacksAsString in class DocuImageImpl
      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 interface DocuImage
      Overrides:
      setReaderClasses in class DocuImageImpl
      Parameters:
      typeClassMap -
    • 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
      Parameters:
      typeClassMap -
    • getVersion

      public String getVersion()
      Description copied from class: DocuImageImpl
      Returns the version.
      Specified by:
      getVersion in interface DocuImage
      Overrides:
      getVersion in class DocuImageImpl
      Returns:
      the version
    • isSubimageSupported

      public boolean isSubimageSupported()
      Description copied from interface: DocuImage
      This DocuImage supports the loadSubImage operation.
      Specified by:
      isSubimageSupported in interface DocuImage
      Overrides:
      isSubimageSupported in class DocuImageImpl
      Returns:
      if loadSubImage is supported
    • setQuality

      public void setQuality(int qual)
      Description copied from class: DocuImageImpl
      Sets the quality.
      Specified by:
      setQuality in interface DocuImage
      Overrides:
      setQuality in class DocuImageImpl
      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 interface DocuImage
      Overrides:
      getSize in class DocuImageImpl
      Returns:
      the ImageSize
    • getSupportedFormats

      public Iterator<String> getSupportedFormats()
      Description copied from interface: DocuImage
      Returns the list of supported image formats.
      Specified by:
      getSupportedFormats in interface DocuImage
      Overrides:
      getSupportedFormats in class DocuImageImpl
      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 interface DocuImage
      Overrides:
      identify in class ImageInfoDocuImage
      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 interface DocuImage
      Specified by:
      loadImage in class DocuImageImpl
      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 interface DocuImage
      Overrides:
      loadSubimage in class DocuImageImpl
      Parameters:
      ii - the ImageInput
      region - the region
      prescale - 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-type mt and sent to the output stream ostream. Currently only mime-types "image/jpeg", "image/png" and "image/webp" are supported.
      Specified by:
      writeImage in interface DocuImage
      Specified by:
      writeImage in class DocuImageImpl
      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
    • writeWebp

      protected void writeWebp(ImageWriter writer) throws IOException
      Write the current image to the given ImageWriter as WEBP.
      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
    • 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
      Overrides:
      getAwtImage in class DocuImageImpl
      Returns:
      the Image