01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.cocoon.reading.imageop;
18:
19: import java.awt.image.RescaleOp;
20: import java.awt.image.WritableRaster;
21:
22: import org.apache.avalon.framework.parameters.Parameters;
23:
24: public class ColorOperation implements ImageOperation {
25: private RescaleOp m_ColorFilter;
26: private String m_Prefix;
27: private boolean m_Enabled;
28:
29: public void setPrefix(String prefix) {
30: m_Prefix = prefix;
31: }
32:
33: public void setup(Parameters params) {
34: m_Enabled = params.getParameterAsBoolean(m_Prefix + "enabled",
35: true);
36: float[] scaleColor = new float[3];
37: float[] offsetColor = new float[3];
38: scaleColor[0] = params.getParameterAsFloat(m_Prefix
39: + "scale-red", -1.0f);
40: scaleColor[1] = params.getParameterAsFloat(m_Prefix
41: + "scale-green", -1.0f);
42: scaleColor[2] = params.getParameterAsFloat(m_Prefix
43: + "scale-blue", -1.0f);
44: offsetColor[0] = params.getParameterAsFloat(m_Prefix
45: + "offset-red", 0.0f);
46: offsetColor[1] = params.getParameterAsFloat(m_Prefix
47: + "offset-green", 0.0f);
48: offsetColor[2] = params.getParameterAsFloat(m_Prefix
49: + "offset-blue", 0.0f);
50: m_ColorFilter = new RescaleOp(scaleColor, offsetColor, null);
51: }
52:
53: public WritableRaster apply(WritableRaster image) {
54: if (!m_Enabled)
55: return image;
56:
57: WritableRaster r = m_ColorFilter.filter(image, null);
58: return r;
59: }
60:
61: public String getKey() {
62: return "colorop:" + (m_Enabled ? "enable" : "disable") + ":"
63: + m_ColorFilter + ":" + m_Prefix;
64: }
65: }
|