Package it.tidalwave.image
Class EditableImage
- java.lang.Object
-
- it.tidalwave.image.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EditableImage.Accessor
static class
EditableImage.DataType
-
Field Summary
Fields Modifier and Type Field Description static it.tidalwave.util.Key<java.lang.String>
PROP_FORMAT
static it.tidalwave.util.Key<java.lang.String>
PROP_MIME_TYPE
-
Constructor Summary
Constructors Constructor Description EditableImage()
For serialization only.EditableImage(ImageModel imageModel)
For inner implementation only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description EditableImage
cloneImage()
Clones this image.static EditableImage
create(AbstractCreateOp createOp)
Creates a new EditableImage as specified by the parameterstatic EditableImage
create(ReadOp readOp)
Reads a new EditableImage as specified by the parameterEditableImage
createResizedImage(int width, int height)
Deprecated.EditableImage
createResizedImage(int width, int height, Quality quality)
Deprecated.EditableImage
createSimilarImage()
Deprecated.will be merged with create(AbstractCreateOp)void
dispose()
Removes all the resources bound to this image.EditableImage
execute(Operation operation)
Executes an operation.<T extends Operation>
TexecuteInPlace(T operation)
Executes an operation.<T> java.util.Optional<T>
getAttribute(it.tidalwave.util.Key<T> key)
Returns an attribute of this image.it.tidalwave.util.TypeSafeMap
getAttributes()
static java.util.Collection<java.lang.String>
getAvailableExtensions()
Returns all the file extensions of file formats that can be read into an EditableImage.int
getBandCount()
Returns the number of bands this EditableImage is composed of.int
getBitsPerBand()
Returns the number of sample bits for each band this EditableImage is composed of.int
getBitsPerPixel()
Returns the number of sample bits for each pixel this EditableImage is composed of.java.awt.image.ColorModel
getColorModel()
Returns the ColorModel of this image.EditableImage.DataType
getDataType()
Returns the dataType used by this image.int
getHeight()
Returns the height of this image.java.awt.color.ICC_Profile
getICCProfile()
Returns the ICC_Profile of this image (null will be returned if the ColorModel is not ICC-based).ImageModel
getImageModel()
DO NOT USE THIS.<T> T
getInnerProperty(java.lang.Class<T> propertyClass)
DO NOT USE.java.time.Duration
getLatestOperationDuration()
Returns the elapsed time of the latest operation performed.long
getLatestSerializationSize()
long
getMemorySize()
Returns an estimate of the memory allocated by this image.<T extends Directory>
java.util.Optional<T>getMetadata(java.lang.Class<T> metadataClass)
<T extends Directory>
java.util.Optional<T>getMetadata(java.lang.Class<T> metadataClass, int index)
Retrieve a metadata directory.int
getMetadataCount(java.lang.Class<?> metadataClass)
java.util.Optional<java.lang.String>
getNickName()
int
getWidth()
Returns the width of this image.boolean
hasRaster()
Returns true if the image has a raster (EditableImages can be loaded with metadata only).<T> T
removeAttribute(java.lang.String name)
Removes an attribute from this image.<T> void
setAttribute(it.tidalwave.util.Key<T> key, T value)
Sets an attribute of this image.void
setAttributes(java.util.Map<it.tidalwave.util.Key<?>,java.lang.Object> attributes)
void
setNickName(java.lang.String nickName)
-
-
-
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. TheImageIO
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 directoryindex
- 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 namevalue
- 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.
-
-