RFR: 8282526: Default icon is not painted properly
Phil Race
prr at openjdk.java.net
Thu Mar 17 21:59:33 UTC 2022
On Sun, 13 Mar 2022 21:06:24 GMT, Alexander Zuev <kizune at openjdk.org> wrote:
> Detect the situation where we do need to perform interpolation during ImageIcon
> painting and set a hint to the rendering to perform bicubic approximation so
> image details are preserved during transition.
src/java.desktop/share/classes/javax/swing/ImageIcon.java line 463:
> 461: if (hintChanged) {
> 462: ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
> 463: oldHint == null ? RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR : oldHint);
So this is one of only two hints which do not have an "_DEFAULT" value. I don't know why it doesn't.
Not authoritative but the only place where we currently set this hint and then restore it is here
share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java
Object oldScaleingHints = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
ImageScalingHelper.paint(g, 0, 0, w, h, img, insets, dstInsets,
ImageScalingHelper.PaintType.PAINT9_STRETCH, ImageScalingHelper.PAINT_ALL);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
oldScaleingHints!=null?oldScaleingHints:RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
if the get() returns null and you aren't happy with that then creating a new Graphics is the only alternative I see.
But it seems to me there are bigger problems to resolve first
> Image variant = ((MultiResolutionImage) image).getResolutionVariant(this.width, this.height);
So getResolutionVariant wants image pixels, but I expect ImageIcon is sized in user-space, isn't it ?
Don't you need to apply the scale from the Graphics ?
Next, if we have an exact match for what we want, why do we need the hint ?
Next, as Sergey mentions, BICUBIC is expensive.
Probably how that should be used is to redraw the image into a cached image that
is dw= iw*sx and dh= iwh*sy where sx and sy are the graphics scale
and that is the graphics on which you apply the hint and the graphics is disposed and the restore issue vanishes
then you can just blit that resulting image so long as the cached dw x dy isn't changed.
The MR is still useful for finding the best starting image
-------------
PR: https://git.openjdk.java.net/jdk/pull/7805
More information about the client-libs-dev
mailing list