KickJava   Java API By Example, From Geeks To Geeks.

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


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.color.ColorSpace JavaDoc;
21 import java.awt.image.RenderedImage JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.batik.ext.awt.image.GraphicsUtil;
26 import org.apache.batik.ext.awt.image.rendered.CachableRed;
27
28 /**
29  * This is an abstract base class that adds the ability to specify the
30  * Color Space that the operation should take place in (linear sRGB or
31  * gamma corrected sRBG).
32  *
33  * @author <a HREF="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
34  * @version $Id: AbstractColorInterpolationRable.java,v 1.4 2004/08/18 07:13:58 vhardy Exp $
35  */

36 public abstract class AbstractColorInterpolationRable extends AbstractRable {
37
38     /**
39      * Indicates if the operation should be done in linear or gamma
40      * corrected sRGB.
41      */

42     protected boolean csLinear = true;
43
44     /**
45      * void constructor. The subclass must call one of the
46      * flavors of init before the object becomes usable.
47      * This is useful when the proper parameters to the init
48      * method need to be computed in the subclasses constructor. */

49     protected AbstractColorInterpolationRable() {
50         super();
51     }
52
53     /**
54      * Construct an Abstract Rable from src.
55      * @param src will be the first (and only) member of the srcs
56      * Vector. The bounds of src are also used to set the bounds of
57      * this renderable.
58      */

59     protected AbstractColorInterpolationRable(Filter src) {
60         super(src);
61     }
62
63     /**
64      * Construct an Abstract Rable from src and props.
65      * @param src will also be set as the first (and only) member of
66      * the srcs Vector.
67      * @param props use to initialize the properties on this renderable image.
68      */

69     protected AbstractColorInterpolationRable(Filter src, Map JavaDoc props) {
70         super(src, props);
71     }
72
73     /**
74      * Construct an Abstract Rable from a list of sources.
75      * @param srcs This is used to initialize the srcs Vector.
76      * The bounds of this renderable will be the union of the bounds
77      * of all the sources in srcs. All the members of srcs must be
78      * CachableRable otherwise an error will be thrown.
79      */

80     protected AbstractColorInterpolationRable(List JavaDoc srcs) {
81         super(srcs);
82     }
83
84     /**
85      * Construct an Abstract Rable from a list of sources, and bounds.
86      * @param srcs This is used to initialize the srcs Vector. All
87      * the members of srcs must be CachableRable otherwise an error
88      * will be thrown.
89      * @param props use to initialize the properties on this renderable image.
90      */

91     protected AbstractColorInterpolationRable(List JavaDoc srcs, Map JavaDoc props) {
92         super(srcs, props);
93     }
94
95     /**
96      * Returns true if this operation is to be performed in
97      * the linear sRGB colorspace, returns false if the
98      * operation is performed in gamma corrected sRGB.
99      */

100     public boolean isColorSpaceLinear() { return csLinear; }
101
102     /**
103      * Sets the colorspace the operation will be performed in.
104      * @param csLinear if true this operation will be performed in the
105      * linear sRGB colorspace, if false the operation will be performed in
106      * gamma corrected sRGB.
107      */

108     public void setColorSpaceLinear(boolean csLinear) {
109         touch();
110         this.csLinear = csLinear;
111     }
112
113     public ColorSpace JavaDoc getOperationColorSpace() {
114         if (csLinear)
115             return ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
116         else
117             return ColorSpace.getInstance(ColorSpace.CS_sRGB);
118     }
119
120     protected CachableRed convertSourceCS(CachableRed cr) {
121         if (csLinear)
122             return GraphicsUtil.convertToLsRGB(cr);
123         else
124             return GraphicsUtil.convertTosRGB(cr);
125     }
126
127     protected CachableRed convertSourceCS(RenderedImage JavaDoc ri) {
128         return convertSourceCS(GraphicsUtil.wrap(ri));
129     }
130 }
131
Popular Tags