Class EditableImage

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class EditableImage
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    An opaque class which encapsulates all the image manipulation logics, and allows the implementation of these logics to be transparently changed (e.g. by using or not JAI, etc...)
    Author:
    Fabrizio Giudici
    See Also:
    Serialized Form
    • Field Detail

      • PROP_FORMAT

        public static final it.tidalwave.util.Key<java.lang.String> PROP_FORMAT
      • PROP_MIME_TYPE

        public static final it.tidalwave.util.Key<java.lang.String> PROP_MIME_TYPE
    • Constructor Detail

      • EditableImage

        public EditableImage()
        For serialization only. Do not use.
      • EditableImage

        public EditableImage​(ImageModel imageModel)
        For inner implementation only. Do not use.
    • Method Detail

      • setNickName

        public void setNickName​(@Nonnull
                                java.lang.String nickName)
      • getNickName

        @Nonnull
        public java.util.Optional<java.lang.String> getNickName()
      • create

        @Nonnull
        public static EditableImage create​(@Nonnull
                                           AbstractCreateOp createOp)
        Creates a new EditableImage as specified by the parameter
        Parameters:
        createOp - the way the image should be created
        Returns:
        the image
      • create

        @Nonnull
        public static EditableImage create​(@Nonnull
                                           ReadOp readOp)
                                    throws java.io.IOException
        Reads a new EditableImage as specified by the parameter
        Parameters:
        readOp - the way the image should be read
        Returns:
        the image
        Throws:
        java.io.IOException
      • hasRaster

        public boolean hasRaster()
        Returns true if the image has a raster (EditableImages can be loaded with metadata only).
        Returns:
        true if the image has a raster
      • getImageModel

        public ImageModel getImageModel()
        DO NOT USE THIS. This method is only used by the module implementation.
      • getAvailableExtensions

        @Nonnull
        public static java.util.Collection<java.lang.String> getAvailableExtensions()
        Returns all the file extensions of file formats that can be read into an EditableImage. The ImageIO registry is called to retrieve the requested information.
        Returns:
        an array of all file extensions
      • getMetadata

        public <T extends Directory> java.util.Optional<T> getMetadata​(@Nonnull
                                                                       java.lang.Class<T> metadataClass)
      • getMetadata

        public <T extends Directory> java.util.Optional<T> getMetadata​(@Nonnull
                                                                       java.lang.Class<T> metadataClass,
                                                                       @Nonnegative
                                                                       int index)
        Retrieve a metadata directory.
        Parameters:
        metadataClass - the type of the directory
        index - the index (in case of multiple items)
        Returns:
        the metadata directory
      • getMetadataCount

        @Nonnegative
        public int getMetadataCount​(@Nonnull
                                    java.lang.Class<?> metadataClass)
      • getWidth

        @Nonnegative
        public int getWidth()
        Returns the width of this image.
        Returns:
        the width
      • getHeight

        @Nonnegative
        public int getHeight()
        Returns the height of this image.
        Returns:
        the height
      • getDataType

        @Nonnull
        public EditableImage.DataType getDataType()
        Returns the dataType used by this image.
        Returns:
        the data type
      • getBandCount

        @Nonnegative
        public int getBandCount()
        Returns the number of bands this EditableImage is composed of.
        Returns:
        the band count
      • getBitsPerBand

        @Nonnegative
        public int getBitsPerBand()
        Returns the number of sample bits for each band this EditableImage is composed of.
        Returns:
        the number of bits
      • getBitsPerPixel

        @Nonnegative
        public int getBitsPerPixel()
        Returns the number of sample bits for each pixel this EditableImage is composed of.
        Returns:
        the number of bits
      • executeInPlace

        @Nonnull
        public <T extends Operation> T executeInPlace​(@Nonnull
                                                      T operation)
        Executes an operation. The original image is lost and replaced by results.
        Parameters:
        operation - the operation to perform
        Returns:
        the operation (as a convenience in case it carries results)
      • execute

        @Nonnull
        public EditableImage execute​(@Nonnull
                                     Operation operation)
        Executes an operation. The original image is untouched as the results are placed in a brand-new instance of EditableImage.
        Parameters:
        operation - the operation to perform
        Returns:
        the result
      • getLatestOperationDuration

        @Nonnull
        public java.time.Duration getLatestOperationDuration()
        Returns the elapsed time of the latest operation performed. Note that for execute2() this value is available on the result. When an image is deserialized, this method returns the serialization time (this relies upon the fact that the clocks on all network nodes are synchronized).
        Returns:
        the latest operation elapsed time
      • createSimilarImage

        @Nonnull
        public EditableImage createSimilarImage()
        Deprecated.
        will be merged with create(AbstractCreateOp)
        Creates a similar image, that is a blank image with the same characteristics of this image (width, height, data type, color model).
        Returns:
        a new, similar image
      • cloneImage

        @Nonnull
        public EditableImage cloneImage()
        Clones this image.
      • createResizedImage

        @Nonnull
        public EditableImage createResizedImage​(@Nonnegative
                                                int width,
                                                @Nonnegative
                                                int height)
        Deprecated.
        Creates a resized image. - FIXME should be removed
      • createResizedImage

        @Nonnull
        public EditableImage createResizedImage​(@Nonnegative
                                                int width,
                                                @Nonnegative
                                                int height,
                                                @Nonnull
                                                Quality quality)
        Deprecated.
        Creates a resized image. - FIXME move to a factory method for ScaleOp.
      • setAttribute

        public <T> void setAttribute​(@Nonnull
                                     it.tidalwave.util.Key<T> key,
                                     @Nonnull
                                     T value)
        Sets an attribute of this image. Attributes are user-specific name-value pairs.
        Parameters:
        key - the attribute name
        value - the attribute value
      • getAttribute

        @Nonnull
        public <T> java.util.Optional<T> getAttribute​(@Nonnull
                                                      it.tidalwave.util.Key<T> key)
        Returns an attribute of this image.
        Parameters:
        key - the attribute name
        Returns:
        the attribute value
      • setAttributes

        public void setAttributes​(@Nonnull
                                  java.util.Map<it.tidalwave.util.Key<?>,​java.lang.Object> attributes)
      • getAttributes

        @Nonnull
        public it.tidalwave.util.TypeSafeMap getAttributes()
      • removeAttribute

        @Nonnull
        public <T> T removeAttribute​(@Nonnull
                                     java.lang.String name)
        Removes an attribute from this image.
        Parameters:
        name - the attribute name
        Returns:
        the attribute value
      • dispose

        public void dispose()
        Removes all the resources bound to this image.
      • getMemorySize

        @Nonnegative
        public long getMemorySize()
        Returns an estimate of the memory allocated by this image.
        Returns:
        the memory allocated for this image
      • getColorModel

        @Nonnegative
        public java.awt.image.ColorModel getColorModel()
        Returns the ColorModel of this image.
        Returns:
        the color model
      • getICCProfile

        @Nonnegative
        public java.awt.color.ICC_Profile getICCProfile()
        Returns the ICC_Profile of this image (null will be returned if the ColorModel is not ICC-based). Note that this is the profile of the image as it is optimized for the display, which is almost surely sRGB; and it's probably different than the original image profile.
        Returns:
        the color profile
      • getLatestSerializationSize

        @Nonnull
        public long getLatestSerializationSize()
      • getInnerProperty

        @Nonnull
        public <T> T getInnerProperty​(@Nonnull
                                      java.lang.Class<T> propertyClass)
        DO NOT USE. This is only for implementation and testing purposes.