KickJava   Java API By Example, From Geeks To Geeks.

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


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.FilterAsAlphaRed;
31 import org.apache.batik.ext.awt.image.rendered.RenderedImageCachableRed;
32
33 /**
34  * FilterAsAlphaRable implementation.
35  *
36  * This will take any source Filter and convert it to an alpha channel
37  * according the the SVG Mask operation.
38  *
39  * @author <a HREF="mailto:Thomas.DeWeese@Kodak.com">Thomas DeWeese</a>
40  * @version $Id: FilterAsAlphaRable.java,v 1.7 2005/03/27 08:58:33 cam Exp $
41  */

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

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