KickJava   Java API By Example, From Geeks To Geeks.

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


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.RenderingHints JavaDoc;
21 import java.awt.image.ByteLookupTable JavaDoc;
22 import java.awt.image.LookupOp JavaDoc;
23 import java.awt.image.WritableRaster JavaDoc;
24
25 import org.apache.batik.ext.awt.image.GraphicsUtil;
26 import org.apache.batik.ext.awt.image.TransferFunction;
27
28 /**
29  *
30  * @author <a HREF="mailto:thomas.deweese@kodak.com">Thomas DeWeese</a>
31  * @version $Id: ComponentTransferRed.java,v 1.4 2004/08/18 07:14:08 vhardy Exp $
32  */

33 public class ComponentTransferRed extends AbstractRed {
34     LookupOp JavaDoc operation;
35
36     /**
37      * The constructor will instantiate a LookupOp instance using
38      * a LookupOp, which is built using the four LUT
39      * data obtained by the TransferFunction objects
40      * funcs[0] : Alpha component transfer function
41      * funcs[1] : Red component transfer function
42      * funcs[2] : Green component transfer function
43      * funcs[3] : Blue component transfer function
44      */

45     public ComponentTransferRed(CachableRed src,
46                                 TransferFunction [] funcs,
47                                 RenderingHints JavaDoc hints) {
48         super(src, src.getBounds(),
49               GraphicsUtil.coerceColorModel(src.getColorModel(), false),
50               src.getSampleModel(),
51               null);
52
53         byte [][] tableData = {funcs[1].getLookupTable(),
54                                funcs[2].getLookupTable(),
55                                funcs[3].getLookupTable(),
56                                funcs[0].getLookupTable()};
57
58         // Note that we create an anonymous subclass here.
59
// For what ever reason this makes the Op work correctly.
60
// If you remove this, it seems to get the color channels messed
61
// up. The downside is that I suspect that this means we are
62
// falling into a more general, and hence slower case, but
63
// at least it works....
64
operation = new LookupOp JavaDoc(new ByteLookupTable JavaDoc(0, tableData), hints)
65             { };
66     }
67     
68     public WritableRaster JavaDoc copyData(WritableRaster JavaDoc wr){
69         CachableRed src = (CachableRed)getSources().elementAt(0);
70
71         wr = src.copyData(wr);
72         GraphicsUtil.coerceData(wr, src.getColorModel(), false);
73
74         WritableRaster JavaDoc srcWR = wr.createWritableTranslatedChild(0,0);
75
76         operation.filter(srcWR, srcWR);
77
78         return wr;
79     }
80 }
81
Popular Tags