Class ImageLayout
- Direct Known Subclasses:
ImageCombiner.Layout
,ImageLayout.FixedSize
ImageLayout
does not store
those information directly, but provides method for deriving those properties from a given image.- Since:
- 1.1
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Override preferred tile size with a fixed size. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ImageLayout
The default instance which will target 256 pixels as tile width and height.final boolean
Whether image size can be modified if needed.private static final int
The minimum tile size.private final int
Preferred size for tiles.private final int
Preferred size for tiles.static final ImageLayout
Same asDEFAULT
, but makes image size an integer amount of tiles. -
Constructor Summary
ConstructorsConstructorDescriptionImageLayout
(Dimension preferredTileSize, boolean isBoundsAdjustmentAllowed) Creates a new image layout. -
Method Summary
Modifier and TypeMethodDescriptioncreateBandedSampleModel
(int type, int numBands, RenderedImage image, Rectangle bounds) Creates a banded sample model of the given type with the suggested tile size for the given image.createCompatibleSampleModel
(RenderedImage image, Rectangle bounds) Creates a sample model compatible with the sample model of the given image but with a size matching the preferred tile size.static ImageLayout
fixedSize
(RenderedImage source) Creates a new layout with exactly the tile size of given image.Returns indices of the first tile (minTileX
,minTileY
), ornull
for (0,0).final Dimension
Returns the preferred tile size.private static int
sizeToAdd
(int size, int tileSize) Computes the size to add to the width or height for making it divisible by the given tile size.suggestTileSize
(int imageWidth, int imageHeight, boolean allowPartialTiles) Suggests a tile size for the specified image size.suggestTileSize
(RenderedImage image, Rectangle bounds, boolean allowPartialTiles) Suggests a tile size for operations derived from the given image.toString()
Returns a string representation for debugging purpose.private static int
toTileSize
(int imageSize, int preferredTileSize, boolean allowPartialTiles) Suggests a tile size close totileSize
for the specifiedimageSize
.
-
Field Details
-
MIN_TILE_SIZE
private static final int MIN_TILE_SIZEThe minimum tile size. ThetoTileSize(int, int, boolean)
method will not suggest tiles smaller than this size. This size must be smaller thanImageUtilities.DEFAULT_TILE_SIZE
.Tiles of 180×180 pixels consume about 127 kB, assuming 4 bytes per pixel. This is about half the consumption of tiles of 256×256 pixels. We select a size which is a multiple of 90 because images are often used with a resolution of e.g. ½° per pixel.
- See Also:
-
DEFAULT
The default instance which will target 256 pixels as tile width and height. -
SIZE_ADJUST
Same asDEFAULT
, but makes image size an integer amount of tiles. -
preferredTileWidth
private final int preferredTileWidthPreferred size for tiles.- See Also:
-
preferredTileHeight
private final int preferredTileHeightPreferred size for tiles.- See Also:
-
isBoundsAdjustmentAllowed
public final boolean isBoundsAdjustmentAllowedWhether image size can be modified if needed. Changes are applied only if an image cannot be tiled becausesuggestTileSize(int, int, boolean)
cannot find a tile size close to the desired 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.If this flag is
true
, then thebounds
argument given to thesuggestTileSize(RenderedImage, Rectangle, boolean)
will be modified in-place.
-
-
Constructor Details
-
ImageLayout
Creates a new image layout.- Parameters:
preferredTileSize
- the preferred tile size, ornull
for the default size.isBoundsAdjustmentAllowed
- whether image size can be modified if needed.
-
-
Method Details
-
fixedSize
Creates a new layout with exactly the tile size of given image.- Parameters:
source
- image from which to take tile size and indices.- Returns:
- layout giving exactly the tile size and indices of given image.
-
getPreferredTileSize
Returns the preferred tile size. This is the dimension values specified at construction time.- Returns:
- the preferred tile size.
-
toTileSize
private static int toTileSize(int imageSize, int preferredTileSize, boolean allowPartialTiles) Suggests a tile size close totileSize
for the specifiedimageSize
. First, this method tries to return a tile size which is a divisor of the image size. If no such divisor is found andallowPartialTiles
istrue
, then this method returns a size that minimize the amount of empty pixels in the last tile.- Parameters:
imageSize
- the image size (width or height).preferredTileSize
- the preferred tile size, which is often 256.allowPartialTiles
- whether to allow tiles that are only partially filled.- Returns:
- the suggested tile size, or
imageSize
if none.
-
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. TheallowPartialTile
argument 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
allowPartialTile
argument should befalse
if 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.allowPartialTiles
- whether to allow tiles that are only partially filled.- 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 also checks whether the color model supports transparency. If not, then this method will not return a size that may result in the creation of partially empty tiles.
- Parameters:
image
- the image for which to derive a tile size, ornull
.bounds
- the bounds of the image to create, ornull
if same asimage
.allowPartialTiles
- whether to allow tiles that are only partially filled. This argument is ignored (reset tofalse
) if the given image is opaque.- Returns:
- suggested tile size for the given image.
-
sizeToAdd
private static int sizeToAdd(int size, int tileSize) Computes the size to add to the width or height for making it divisible by the given tile size. -
createBandedSampleModel
public BandedSampleModel createBandedSampleModel(int type, int numBands, RenderedImage image, Rectangle bounds) Creates a banded sample model of the given type with the suggested tile size for the given image.- Parameters:
type
- desired data type as aDataBuffer
constant.numBands
- desired number of bands.image
- the image which will be the source of the image for which a sample model is created.bounds
- the bounds of the image to create, ornull
if same asimage
.- Returns:
- a banded sample model of the given type with the given number of bands.
-
createCompatibleSampleModel
Creates a sample model compatible with the sample model of the given image but with a size matching the preferred tile size. This method can be used for determining thesampleModel
argument ofComputedImage
constructor.- Parameters:
image
- the image form which to get a sample model.bounds
- the bounds of the image to create, ornull
if same asimage
.- Returns:
- image sample model with preferred tile size.
- See Also:
-
getMinTile
Returns indices of the first tile (minTileX
,minTileY
), ornull
for (0,0). The default implementation returnsnull
.- Returns:
- indices of the first tile (
minTileX
,minTileY
), ornull
for (0,0).
-
toString
Returns a string representation for debugging purpose.
-