Module io.github.stanio.xbrz.awt
Package io.github.stanio.xbrz.awt.util
Class BaseMultiResolutionImage
java.lang.Object
java.awt.Image
java.awt.image.AbstractMultiResolutionImage
io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
- All Implemented Interfaces:
MultiResolutionImage
- Direct Known Subclasses:
MultiResolutionCachedImage
Convenience base
MultiResolutionImage
implementation...-
Field Summary
Fields inherited from class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
-
Constructor Summary
ModifierConstructorDescriptionprotected
BaseMultiResolutionImage
(int baseWidth, int baseHeight) Initializes aBaseMultiResolutionImage
with the given base width and height properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected Image
This implementation delegates togetResolutionVariant(baseWidth, baseHeight)
.int
getHeight
(ImageObserver observer) Returns thebaseHeight
specified during the initialization.getProperty
(String name, ImageObserver observer) This implementation returnsUndefinedProperty
.abstract Image
getResolutionVariant
(double destWidth, double destHeight) Gets a specific image that is the best variant to represent this logical image at the indicated size.This implementation returns a singleton list containing thebaseImage
.getScaledInstance
(int width, int height, int hints) This implementation delegates togetResolutionVariant(width, height)
.int
getWidth
(ImageObserver observer) Returns thebaseWidth
specified during the initialization.protected static Image
preloadDimensions
(Image image) Preload dimensions of Toolkit images.static BaseMultiResolutionImage
withProducer
(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) Returns aBaseMultiResolutionImage
delegating to the given resolutionvariantProducer
.Methods inherited from class java.awt.image.AbstractMultiResolutionImage
getGraphics, getSource
Methods inherited from class java.awt.Image
flush, getAccelerationPriority, getCapabilities, setAccelerationPriority
-
Field Details
-
baseWidth
protected final int baseWidth -
baseHeight
protected final int baseHeight
-
-
Constructor Details
-
BaseMultiResolutionImage
protected BaseMultiResolutionImage(int baseWidth, int baseHeight) Initializes aBaseMultiResolutionImage
with the given base width and height properties.- Parameters:
baseWidth
- the user-space logical with of the imagebaseHeight
- the user-space logical height of the image
-
-
Method Details
-
withProducer
public static BaseMultiResolutionImage withProducer(int baseWidth, int baseHeight, BiFunction<Integer, Integer, Image> variantProducer) Returns aBaseMultiResolutionImage
delegating to the given resolutionvariantProducer
.The returned
MultiResolutionImage
implementation will return the last produced variant if request for the same destination width and height, as at the time the variant has been created, is received. That is it won't continuously request creation of the same variant in succession.- Parameters:
baseWidth
- ...baseHeight
- ...variantProducer
- ...- Returns:
- A
MultiResolutionImage
...
-
getWidth
Returns thebaseWidth
specified during the initialization.- Overrides:
getWidth
in classAbstractMultiResolutionImage
- Parameters:
observer
- an object waiting for the image to be loaded.- Returns:
- the width of the base image, or -1 if the width is not yet known
- See Also:
-
getHeight
Returns thebaseHeight
specified during the initialization.- Overrides:
getHeight
in classAbstractMultiResolutionImage
- Parameters:
observer
- an object waiting for the image to be loaded.- Returns:
- the height of the base image, or -1 if the height is not yet known
- See Also:
-
getBaseImage
This implementation delegates togetResolutionVariant(baseWidth, baseHeight)
.- Specified by:
getBaseImage
in classAbstractMultiResolutionImage
- Returns:
- the base image of the set of multi-resolution images
-
getProperty
This implementation returnsUndefinedProperty
.- Overrides:
getProperty
in classAbstractMultiResolutionImage
- Parameters:
name
- a property name.observer
- an object waiting for this image to be loaded.- Returns:
- the value of the named property in the base image
- See Also:
-
getScaledInstance
This implementation delegates togetResolutionVariant(width, height)
.- Overrides:
getScaledInstance
in classImage
- Parameters:
width
- the width to which to scale the image.height
- the height to which to scale the image.hints
- flags to indicate the type of algorithm to use for image resampling.- Returns:
- a scaled version of the image.
- See Also:
-
getResolutionVariants
This implementation returns a singleton list containing thebaseImage
.- Returns:
- list of resolution variants.
-
getResolutionVariant
Description copied from interface:java.awt.image.MultiResolutionImage
Gets a specific image that is the best variant to represent this logical image at the indicated size.- Parameters:
destWidth
- the width of the destination image, in pixels.destHeight
- the height of the destination image, in pixels.- Returns:
- image resolution variant.
-
preloadDimensions
Preload dimensions of Toolkit images. This is crucial for the Java 2D drawing pipeline. If dimensions are not immediately available, agetResolutionVariant()
request for the base width and height is made, that could trigger unexpected internal loops, depending on the actual implementation.
-