Class ImageLayout
java.lang.Object
org.apache.sis.internal.coverage.j2d.ImageLayout
Derives information about image location, size and tile grid.
ImageLayout does not store
those information directly, but provides method for deriving those properties from a given image.- Since:
- 1.1
- Version:
- 1.2
- Author:
- Martin Desruisseaux (Geomatys)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ImageLayoutThe default instance which will target 256 pixels as tile width and height.final booleanWhether image size can be modified if needed.static final ImageLayoutSame 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 ImageLayoutfixedSize(RenderedImage source) Creates a new layout with exactly the tile size of given image.Returns indices of the first tile (minTileX,minTileY), ornullfor (0,0).final DimensionReturns the preferred 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.
-
Field Details
-
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. -
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 theboundsargument 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, ornullfor 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.
-
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. TheallowPartialTileargument specifies whether to allow tiles that are only partially filled. A value oftrueimplies that tiles in the last row or in the last column may contain empty pixels. A value offalseimplies that this class will be unable to subdivide large images in smaller tiles if the image size is a prime number.The
allowPartialTileargument should befalseif 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, ornullif 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.
-
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 aDataBufferconstant.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, ornullif 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 thesampleModelargument ofComputedImageconstructor.- Parameters:
image- the image form which to get a sample model.bounds- the bounds of the image to create, ornullif same asimage.- Returns:
- image sample model with preferred tile size.
- See Also:
-
getMinTile
Returns indices of the first tile (minTileX,minTileY), ornullfor (0,0). The default implementation returnsnull.- Returns:
- indices of the first tile (
minTileX,minTileY), ornullfor (0,0).
-
toString
Returns a string representation for debugging purpose.
-