001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.ext.awt.image.renderable;
020:
021: import java.awt.color.ColorSpace;
022: import java.awt.image.RenderedImage;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.batik.ext.awt.image.GraphicsUtil;
027: import org.apache.batik.ext.awt.image.rendered.CachableRed;
028:
029: /**
030: * This is an abstract base class that adds the ability to specify the
031: * Color Space that the operation should take place in (linear sRGB or
032: * gamma corrected sRBG).
033: *
034: * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
035: * @version $Id: AbstractColorInterpolationRable.java 475477 2006-11-15 22:44:28Z cam $
036: */
037: public abstract class AbstractColorInterpolationRable extends
038: AbstractRable {
039:
040: /**
041: * Indicates if the operation should be done in linear or gamma
042: * corrected sRGB.
043: */
044: protected boolean csLinear = true;
045:
046: /**
047: * void constructor. The subclass must call one of the
048: * flavors of init before the object becomes usable.
049: * This is useful when the proper parameters to the init
050: * method need to be computed in the subclasses constructor. */
051: protected AbstractColorInterpolationRable() {
052: super ();
053: }
054:
055: /**
056: * Construct an Abstract Rable from src.
057: * @param src will be the first (and only) member of the srcs
058: * Vector. The bounds of src are also used to set the bounds of
059: * this renderable.
060: */
061: protected AbstractColorInterpolationRable(Filter src) {
062: super (src);
063: }
064:
065: /**
066: * Construct an Abstract Rable from src and props.
067: * @param src will also be set as the first (and only) member of
068: * the srcs Vector.
069: * @param props use to initialize the properties on this renderable image.
070: */
071: protected AbstractColorInterpolationRable(Filter src, Map props) {
072: super (src, props);
073: }
074:
075: /**
076: * Construct an Abstract Rable from a list of sources.
077: * @param srcs This is used to initialize the srcs Vector.
078: * The bounds of this renderable will be the union of the bounds
079: * of all the sources in srcs. All the members of srcs must be
080: * CachableRable otherwise an error will be thrown.
081: */
082: protected AbstractColorInterpolationRable(List srcs) {
083: super (srcs);
084: }
085:
086: /**
087: * Construct an Abstract Rable from a list of sources, and bounds.
088: * @param srcs This is used to initialize the srcs Vector. All
089: * the members of srcs must be CachableRable otherwise an error
090: * will be thrown.
091: * @param props use to initialize the properties on this renderable image.
092: */
093: protected AbstractColorInterpolationRable(List srcs, Map props) {
094: super (srcs, props);
095: }
096:
097: /**
098: * Returns true if this operation is to be performed in
099: * the linear sRGB colorspace, returns false if the
100: * operation is performed in gamma corrected sRGB.
101: */
102: public boolean isColorSpaceLinear() {
103: return csLinear;
104: }
105:
106: /**
107: * Sets the colorspace the operation will be performed in.
108: * @param csLinear if true this operation will be performed in the
109: * linear sRGB colorspace, if false the operation will be performed in
110: * gamma corrected sRGB.
111: */
112: public void setColorSpaceLinear(boolean csLinear) {
113: touch();
114: this .csLinear = csLinear;
115: }
116:
117: public ColorSpace getOperationColorSpace() {
118: if (csLinear)
119: return ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
120: else
121: return ColorSpace.getInstance(ColorSpace.CS_sRGB);
122: }
123:
124: protected CachableRed convertSourceCS(CachableRed cr) {
125: if (csLinear)
126: return GraphicsUtil.convertToLsRGB(cr);
127: else
128: return GraphicsUtil.convertTosRGB(cr);
129: }
130:
131: protected CachableRed convertSourceCS(RenderedImage ri) {
132: return convertSourceCS(GraphicsUtil.wrap(ri));
133: }
134: }
|