You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Noel Grandin (JIRA)" <ji...@apache.org> on 2011/07/25 11:59:09 UTC

[jira] [Resolved] (PIVOT-723) Better GrayscaleDecorator

     [ https://issues.apache.org/jira/browse/PIVOT-723?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Noel Grandin resolved PIVOT-723.
--------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 2.1)
                   2.0.1
         Assignee: Noel Grandin

Fixed in rev 1150611

> 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
>            Assignee: Noel Grandin
>            Priority: Minor
>             Fix For: 2.0.1
>
>         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