KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > rendered > FilterAlphaRed


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.rendered;
19
20 import java.awt.image.Raster JavaDoc;
21 import java.awt.image.SampleModel JavaDoc;
22 import java.awt.image.WritableRaster JavaDoc;
23
24 import org.apache.batik.ext.awt.ColorSpaceHintKey;
25
26 /**
27  * This strips out the source alpha channel into a one band image.
28  *
29  * @author <a HREF="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
30  * @version $Id: FilterAlphaRed.java,v 1.6 2004/08/18 07:14:08 vhardy Exp $ */

31 public class FilterAlphaRed extends AbstractRed {
32
33     /**
34      * Construct an alpah channel from the given src, according to
35      * the SVG masking rules.
36      *
37      * @param src The image to convert to an alpha channel (mask image)
38      */

39     public FilterAlphaRed(CachableRed src) {
40         super(src, src.getBounds(),
41               src.getColorModel(),
42               src.getSampleModel(),
43               src.getTileGridXOffset(),
44               src.getTileGridYOffset(),
45               null);
46
47         props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
48                   ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
49     }
50
51     public WritableRaster JavaDoc copyData(WritableRaster JavaDoc wr) {
52         // new Exception("FilterAlphaRed: ").printStackTrace();
53
// Get my source.
54
CachableRed srcRed = (CachableRed)getSources().get(0);
55
56         SampleModel JavaDoc sm = srcRed.getSampleModel();
57         if (sm.getNumBands() == 1)
58             // Already one band of data so we just use it...
59
return srcRed.copyData(wr);
60
61         PadRed.ZeroRecter.zeroRect(wr);
62         Raster JavaDoc srcRas = srcRed.getData(wr.getBounds());
63         AbstractRed.copyBand(srcRas, srcRas.getNumBands()-1, wr,
64                              wr.getNumBands()-1);
65         return wr;
66     }
67
68 }
69
Popular Tags