You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Bill van Melle (JIRA)" <ji...@apache.org> on 2011/03/25 23:13:05 UTC
[jira] [Commented] (PIVOT-723) Better GrayscaleDecorator
[ https://issues.apache.org/jira/browse/PIVOT-723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13011448#comment-13011448 ]
Bill van Melle commented on PIVOT-723:
--------------------------------------
Here is a test app using the attached image:
<Window
xmlns:effects="org.apache.pivot.wtk.effects"
xmlns="org.apache.pivot.wtk">
<BoxPane styles="{backgroundColor:'white'}">
<ImageView image="@error-round.png" styles="{backgroundColor:null}" />
<ImageView image="@error-round.png" styles="{backgroundColor:null}">
<decorators>
<effects:GrayscaleDecorator />
</decorators>
</ImageView>
</BoxPane>
</Window>
> Better GrayscaleDecorator
> -------------------------
>
> Key: PIVOT-723
> URL: https://issues.apache.org/jira/browse/PIVOT-723
> Project: Pivot
> Issue Type: Improvement
> Components: wtk-effects
> Affects Versions: 2.0
> Reporter: Bill van Melle
> Priority: Minor
> Attachments: error-round.png
>
>
> The current GrayscaleDecorator doesn't work properly when the decorated component uses transparency -- it turns the transparent pixels black, which seems unlikely to be what you want. Here's a new version of GrayscaleDecorator#prepare that creates the BufferedImage in a transparency-aware way:
> public Graphics2D prepare(Component component, Graphics2D graphics) {
> this.graphics = graphics;
> int width = component.getWidth();
> int height = component.getHeight();
>
> // To convert to gray, we create a BufferedImage in the grayscale color space
> // into which the decorated component draws, and we output the resulting image.
> // The naive way to create the buffer is
> // new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
> // but that doesn't respect transparency. Hence the following more complicated method.
>
> if (bufferedImage == null
> || bufferedImage.getWidth() < width
> || bufferedImage.getHeight() < height) {
> ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
> ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false,
> Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
> WritableRaster raster = ccm.createCompatibleWritableRaster(width, height);
> bufferedImage = new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null);
> }
> bufferedImageGraphics = bufferedImage.createGraphics();
> bufferedImageGraphics.setClip(graphics.getClip());
> return bufferedImageGraphics;
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira