Class ImageLayout
ImageLayout
contains a preferred tile size, together with methods
for deriving an actual tile size for a given image size.
The rules for deriving a tile size are configurable by flags.
An image layout can be specified in more details with a SampleModel
.
The size of a sample model usually determines the size of tiles, but the former
may be replaced by the tile size computed
by this ImageLayout
class.
This class contains no information about colors.
The ColorModel
to associate with a SampleModel
is controlled by a separated interface: Colorizer
.
Instances of this class are immutable and thread-safe.
- Since:
- 1.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ImageLayout
The default instance with a preferred tile width and height of 256 pixels.static final int
Default width and height of tiles, in pixels.final boolean
Whether to allow changes of image size when needed.final boolean
Whether to allow tiles that are only partially filled in the last row and last column of the tile matrix.final boolean
Whether to allow changes of tile size when needed.protected final int
Preferred tile index where images start their tile matrix.protected final int
Preferred tile index where images start their tile matrix.protected final int
Preferred size (in pixels) for tiles.protected final int
Preferred size (in pixels) for tiles.protected final SampleModel
Preferred sample model, ornull
if none. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ImageLayout
(SampleModel sampleModel, Dimension preferredTileSize, boolean isTileSizeAdjustmentAllowed, boolean isImageBoundsAdjustmentAllowed, boolean isPartialTilesAllowed, Point preferredMinTile) Creates a new image layout with the given properties. -
Method Summary
Modifier and TypeMethodDescriptionallowImageBoundsAdjustments
(boolean allowed) Returns a new layout with the same properties than this layout except whether it allows changes of image size.allowPartialTiles
(boolean allowed) Returns a new layout with the same properties than this layout except whether it allows partially filled tiles.allowTileSizeAdjustments
(boolean allowed) Returns a new layout with the same properties than this layout except whether it allows changes of tile size.createCompatibleSampleModel
(RenderedImage image, Rectangle bounds) Returns a sample model with a size computed from the given image size.createSampleModel
(DataType dataType, Rectangle bounds, int numBands) Returns a sample model for the given data type with a size computed from the given image bounds.final Point
Returns the preferred indices of the upper-left tile in an image tile matrix.final Dimension
Returns the preferred tile size.suggestTileSize
(int imageWidth, int imageHeight) Suggests a tile size for the specified image size.suggestTileSize
(RenderedImage image, Rectangle bounds) Suggests a tile size for operations derived from the given image.Returns a string representation for debugging purpose.Returns a new layout with the same flags but a different preferred tile size.withSampleModel
(SampleModel model, boolean cascade) Returns a new layout with the same properties than this layout except for the sample model.withTileMatrix
(RenderedImage source) Creates a new layout with the tile size and tile indices of the given image.
-
Field Details
-
DEFAULT_TILE_SIZE
public static final int DEFAULT_TILE_SIZEDefault width and height of tiles, in pixels. This is currently set to 256 pixels, but may change in any future Apache SIS version.- See Also:
-
DEFAULT
The default instance with a preferred tile width and height of 256 pixels. Image sizes are preserved but the tile sizes are flexible. The last row and last column of tiles in an image are allowed to be only partially filled. -
sampleModel
Preferred sample model, ornull
if none. The sample model width and height may be replaced by the tile size computed by thisImageLayout
class.- See Also:
-
preferredTileWidth
-
preferredTileHeight
-
isTileSizeAdjustmentAllowed
public final boolean isTileSizeAdjustmentAllowedWhether to allow changes of tile size when needed. If this flag isfalse
, thensuggestTileSize(int, int)
unconditionally returns the preferred tile size.The default value is
true
.- See Also:
-
isImageBoundsAdjustmentAllowed
public final boolean isImageBoundsAdjustmentAllowedWhether to allow changes of image size when needed. An image may be resized when thesuggestTileSize(int, int)
method cannot find a size close enough to the preferred tile size. For example, if the image width is a prime number, there is no way to divide the image horizontally with an integer number of tiles. The only way to get an integer number of tiles is to change the image size. This is done by changing the fields of thebounds
argument given to thesuggestTileSize(RenderedImage, Rectangle)
method.The default value is
false
.- See Also:
-
isPartialTilesAllowed
public final boolean isPartialTilesAllowedWhether to allow tiles that are only partially filled in the last row and last column of the tile matrix. This flag may be ignored (handled asfalse
) when the image for which to compute a tile size is opaque.The default value is
true
.- See Also:
-
preferredMinTileX
protected final int preferredMinTileXPreferred tile index where images start their tile matrix. This property usually has no incidence on the appearance or performance of an image and may be ignored by image operations. The default value is 0.- See Also:
-
preferredMinTileY
protected final int preferredMinTileYPreferred tile index where images start their tile matrix. This property usually has no incidence on the appearance or performance of an image and may be ignored by image operations. The default value is 0.- See Also:
-
-
Constructor Details
-
ImageLayout
protected ImageLayout(SampleModel sampleModel, Dimension preferredTileSize, boolean isTileSizeAdjustmentAllowed, boolean isImageBoundsAdjustmentAllowed, boolean isPartialTilesAllowed, Point preferredMinTile) Creates a new image layout with the given properties.- Parameters:
sampleModel
- preferred sample model, ornull
if none.preferredTileSize
- preferred tile size, ornull
for the default size.isTileSizeAdjustmentAllowed
- whether tile size can be modified if needed.isImageBoundsAdjustmentAllowed
- whether image size can be modified if needed.isPartialTilesAllowed
- whether to allow tiles that are only partially filled.preferredMinTile
- preferred tile index where image start their tile matrix, ornull
for (0,0).
-
-
Method Details
-
withSampleModel
Returns a new layout with the same properties than this layout except for the sample model. If the given argument value results in no change, returnsthis
.- Parameters:
model
- the new sample model, ornull
if none.cascade
- whether to set the preferred tile size to the size of the given sample model.- Returns:
- the layout for the given sample model.
-
allowTileSizeAdjustments
Returns a new layout with the same properties than this layout except whether it allows changes of tile size. If the given argument value results in no change, returnsthis
.- Parameters:
allowed
- whether to allow changes of tile size when needed.- Returns:
- the layout for the given flag.
- See Also:
-
allowImageBoundsAdjustments
Returns a new layout with the same properties than this layout except whether it allows changes of image size. If the given argument value results in no change, returnsthis
.- Parameters:
allowed
- whether to allow changes of image size when needed.- Returns:
- the layout for the given flag.
- See Also:
-
allowPartialTiles
Returns a new layout with the same properties than this layout except whether it allows partially filled tiles. If the given argument value results in no change, returnsthis
.- Parameters:
allowed
- whether to allow tiles that are only partially filled in the last row and last column of the tile matrix.- Returns:
- the layout for the given flag.
- See Also:
-
withTileMatrix
Creates a new layout with the tile size and tile indices of the given image. Other properties of thisImageLayout
(sample model and all Boolean flags) are inherited unchanged. If the given argument value results in no change, returnsthis
.- Parameters:
source
- image from which to take tile size and tile indices.- Returns:
- layout giving exactly the tile size and indices of given image.
- See Also:
-
withPreferredTileSize
Returns a new layout with the same flags but a different preferred tile size. If the given argument values result in no change, returnsthis
.- Parameters:
size
- the new tile size.- Returns:
- the layout for the given size.
- See Also:
-
getPreferredTileSize
Returns the preferred tile size. This is the dimension values specified at construction time.- Returns:
- the preferred tile size.
-
suggestTileSize
Suggests a tile size for the specified image size. This method suggests a tile size which is a divisor of the given image size if possible, or a size that left as few empty pixels as possible otherwise. TheisPartialTilesAllowed
flag specifies whether to allow tiles that are only partially filled. A value oftrue
implies that tiles in the last row or in the last column may contain empty pixels. A value offalse
implies that this class will be unable to subdivide large images in smaller tiles if the image size is a prime number.The
isPartialTilesAllowed
flag should befalse
when the tiled image is opaque, or if the sample value for transparent pixels is different than zero. This restriction is for avoiding black or colored borders on the image left size and bottom size.- Parameters:
imageWidth
- the image width in pixels.imageHeight
- the image height in pixels.- Returns:
- suggested tile size for the given image size.
-
suggestTileSize
Suggests a tile size for operations derived from the given image. If the given image is null, then this method returns the preferred tile size. Otherwise, if the given image is already tiled, then this method preserves the current tile size unless the tiles are too large, in which case they may be subdivided. Otherwise (untiled image), this method proposes a tile size.This method checks whether the image color model supports transparency. If not, then this method will not return a size that may result in the creation of partially empty tiles. In other words, the
isPartialTilesAllowed
flag is ignored (handled asfalse
) for opaque images.- Parameters:
image
- the image for which to derive a tile size, ornull
.bounds
- the bounds of the image to create, ornull
if same asimage
.- Returns:
- suggested tile size for the given image.
-
createCompatibleSampleModel
Returns a sample model with a size computed from the given image size. If thisImageLayout
contains asampleModel
, then the latter is used as a template. Otherwise, the new sample model is derived from the image.- Parameters:
image
- the image from which to derive a sample model.bounds
- the bounds of the image to create, ornull
if same asimage
.- Returns:
- image sample model with a tile size derived from the given image size.
- Throws:
IllegalStateException
- ifsampleModel
is non-null and the given image does not have the same number of bands.- See Also:
-
createSampleModel
Returns a sample model for the given data type with a size computed from the given image bounds. If thisImageLayout
contains asampleModel
, then the latter is used as a template.- Parameters:
dataType
- the default data type for the sample model to create.bounds
- the bounds of the image to create.numBands
- the number of bands in the sample model to create.- Returns:
- image sample model with a tile size derived from the given image bounds.
- Throws:
IllegalStateException
- ifsampleModel
is non-null but does not have the same number of bands as the givennumBands
argument.
-
getPreferredMinTile
Returns the preferred indices of the upper-left tile in an image tile matrix. This property usually has no incidence on the appearance or performance of an image. It usually doesn't change neither the calculations that depend on georeferencing, because these calculations depend on pixel coordinates rather than tile coordinates. Therefore, this property is only a hint and may be ignored by image operations.- Returns:
- preferred tile indices of the upper-left tile.
- See Also:
-
toString
-