I've gone up and down the API (and most of the implementation)

ResolutionVariantItem is really only used in the public API in one place :-

ImageProducer defines :-

+    default List<ResolutionVariantItem<ImageProducer>> 
getResolutionVariantItems() {
+        return Arrays.asList(new ResolutionVariantItem<>(this, 1, 1));


The sort-of second place is that FilteredImageSource over-rides this.
The rest is the internal uses of the class (and its definition of course)

So do we need such a generic sounding API class for this one case, (or
are there other API-level uses?) and is there a different approach which avoid the new class entirely ?

Assuming ResolutionVariantItem is the right name - and design - it
seems like it could use a bit more class javadoc, even if it is basically
a bag to hold a few things.

There are few formatting/typo things I noticed but no point in talking about
those until the rest is near conclusion.

-phil.

On 04/05/2016 07:30 AM, Alexander Scherbatiy wrote:

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.


Reply via email to