KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > renderable > FilterAlphaRable


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.renderable;
19
20 import java.awt.RenderingHints JavaDoc;
21 import java.awt.Shape JavaDoc;
22 import java.awt.geom.AffineTransform JavaDoc;
23 import java.awt.geom.Rectangle2D JavaDoc;
24 import java.awt.image.RenderedImage JavaDoc;
25 import java.awt.image.renderable.RenderContext JavaDoc;
26
27 import org.apache.batik.ext.awt.ColorSpaceHintKey;
28 import org.apache.batik.ext.awt.RenderingHintsKeyExt;
29 import org.apache.batik.ext.awt.image.rendered.CachableRed;
30 import org.apache.batik.ext.awt.image.rendered.FilterAlphaRed;
31 import org.apache.batik.ext.awt.image.rendered.RenderedImageCachableRed;
32
33 /**
34  * FilterAlphaRable implementation.
35  *
36  * This will take any source Filter and convert it to an alpha channel
37  * image according to the SVG SourceAlpha Filter description.
38  * This sets RGB to black and Alpha to the source image's alpha channel.
39  *
40  * @author <a HREF="mailto:Thomas.DeWeese@Kodak.com">Thomas DeWeese</a>
41  * @version $Id: FilterAlphaRable.java,v 1.7 2005/03/27 08:58:33 cam Exp $
42  */

43 public class FilterAlphaRable
44     extends AbstractRable {
45
46     public FilterAlphaRable(Filter src) {
47         super(src, null);
48     }
49
50     public Filter getSource() {
51         return (Filter)getSources().get(0);
52     }
53
54     /**
55      * Pass-through: returns the source's bounds
56      */

57     public Rectangle2D JavaDoc getBounds2D(){
58         return getSource().getBounds2D();
59     }
60
61     public RenderedImage JavaDoc createRendering(RenderContext JavaDoc rc) {
62         // Source gets my usr2dev transform
63
AffineTransform JavaDoc at = rc.getTransform();
64
65         // Just copy over the rendering hints.
66
RenderingHints JavaDoc rh = rc.getRenderingHints();
67         if (rh == null) rh = new RenderingHints JavaDoc(null);
68
69         // if we didn't have an aoi specify our bounds as the aoi.
70
Shape JavaDoc aoi = rc.getAreaOfInterest();
71         if (aoi == null)
72             aoi = getBounds2D();
73
74         // We only want it's alpha channel...
75
rh.put(RenderingHintsKeyExt.KEY_COLORSPACE,
76                ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
77
78         RenderedImage JavaDoc ri;
79         ri = getSource().createRendering(new RenderContext JavaDoc(at, aoi, rh));
80         
81         if(ri == null){
82             return null;
83         }
84
85         CachableRed cr = RenderedImageCachableRed.wrap(ri);
86
87         Object JavaDoc val = cr.getProperty(ColorSpaceHintKey.PROPERTY_COLORSPACE);
88         if (val == ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA)
89             return cr; // It listened to us...
90

91         return new FilterAlphaRed(cr);
92     }
93 }
94
Popular Tags