[OpenJDK 2D-Dev] [9] Review request for 8152309 Seamless way of using image filters with multi-resolution images
Alexander Scherbatiy
alexandr.scherbatiy at oracle.com
Tue Apr 5 14:30:01 UTC 2016
Hello,
Could you review the fix:
bug: https://bugs.openjdk.java.net/browse/JDK-8152309
webrev: http://cr.openjdk.java.net/~alexsch/8152309/webrev.00
The purpose of the fix is to allow to apply an image filter for a
multi-resolution image to get new multi-resolution image so the code
below works without changes:
----------
Image mrImage = getMultiResolutionImage();
ImageProducer mriProducer = new
FilteredImageSource(mrImage.getSource(), new CropImageFilter(x, y, w, h));
Image filteredMRImage =
Toolkit.getDefaultToolkit().createImage(mriProducer);
----------
The Image producer needs to be updated to contain a set of
resolution-variant image producers. It can be done introducing a new
MultiResolution[Image]Producer interface. However, the
FilteredImageSource which takes an original image producer as a
constructor argument needs to be declared as
MultiResolution[Image]Producer even for ordinary image producers.
I chose to add the getRVProducers() method directly to the ImageProducer
interface.
The option to add a method which request a resolution variant producer
for the given image size (getRVProducer(width, height) ) seems is not
possible because the result multi-resolution image can be loaded by a
MediaTracker which can load only finite number of resolution variants.
Applying an image filter to resolution-variant producers requires to
scale filters which use fixed image size (like CropImageFilter and
ReplicateScaleFilter).
There should be a way to get a scaled filter using the original one. The
resolution variant image producer need to provide necessary scale
factors for the used filter.
To do that getScaledFilterInstance(scaleX, scaleY) method is added to
the ImageFilter and public ResolutionVariantItem class which can hold
image or image producer with associated scale factors is introduced.
There is an interesting problem in SunGraphics2D where a
multi-resolution image size is requested. To do that it is necessary to
have an image observer which needs to redirect calls to the base image
observer. The resolution variant observer needs to know scale factors to
recalculate given [x, y, width, height] values. The scale factors are
provided by toolkit multi-resolution image but for non toolkit
multi-resolution images they need to be calculated dividing a rv-image
size to base image size. It looks like a closed loop when to know scale
factors it needs to get a rv-image size but for this it is necessary to
use an image observer which requires scale factors.
The current fix just divides rv-image size to base image size for non
toolkit multi-resolution images to get scale factors .
Thanks,
Alexandr.
More information about the 2d-dev
mailing list