10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.scenario.effect;
27
28 import com.sun.javafx.geom.Rectangle;
29 import com.sun.javafx.geom.transform.BaseTransform;
30
31 /**
32 * A filter that produces a sepia tone effect, similar to antique photographs.
33 */
34 public class SepiaTone extends CoreEffect {
35
36 private float level;
37
38 /**
39 * Constructs a new {@code SepiaTone} effect with the default
40 * level value (1.0), using the default input for source data.
41 * This is a shorthand equivalent to:
42 * <pre>
43 * new SepiaTone(DefaultInput)
44 * </pre>
45 */
46 public SepiaTone() {
47 this(DefaultInput);
48 }
49
94 * <pre>
95 * Min: 0.0
96 * Max: 1.0
97 * Default: 1.0
98 * Identity: 0.0
99 * </pre>
100 *
101 * @param level the level value
102 * @throws IllegalArgumentException if {@code level} is outside
103 * the allowable range
104 */
105 public void setLevel(float level) {
106 if (level < 0f || level > 1f) {
107 throw new IllegalArgumentException("Level must be in the range [0,1]");
108 }
109 float old = this.level;
110 this.level = level;
111 }
112
113 @Override
114 protected Rectangle getInputClip(int inputIndex,
115 BaseTransform transform,
116 Rectangle outputClip)
117 {
118 // Trivially, this effect simply modifies the colors of the pixels
119 // of the input on a 1:1 basis so the input clip is the same as the
120 // output clip.
121 return outputClip;
122 }
123
124 @Override
125 public boolean reducesOpaquePixels() {
126 final Effect input = getInput();
127 return input != null && input.reducesOpaquePixels();
128 }
129 }
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.scenario.effect;
27
28 import com.sun.javafx.geom.Rectangle;
29 import com.sun.javafx.geom.transform.BaseTransform;
30 import com.sun.scenario.effect.impl.state.RenderState;
31
32 /**
33 * A filter that produces a sepia tone effect, similar to antique photographs.
34 */
35 public class SepiaTone extends CoreEffect {
36
37 private float level;
38
39 /**
40 * Constructs a new {@code SepiaTone} effect with the default
41 * level value (1.0), using the default input for source data.
42 * This is a shorthand equivalent to:
43 * <pre>
44 * new SepiaTone(DefaultInput)
45 * </pre>
46 */
47 public SepiaTone() {
48 this(DefaultInput);
49 }
50
95 * <pre>
96 * Min: 0.0
97 * Max: 1.0
98 * Default: 1.0
99 * Identity: 0.0
100 * </pre>
101 *
102 * @param level the level value
103 * @throws IllegalArgumentException if {@code level} is outside
104 * the allowable range
105 */
106 public void setLevel(float level) {
107 if (level < 0f || level > 1f) {
108 throw new IllegalArgumentException("Level must be in the range [0,1]");
109 }
110 float old = this.level;
111 this.level = level;
112 }
113
114 @Override
115 public RenderState getRenderState(FilterContext fctx,
116 BaseTransform transform,
117 Rectangle outputClip,
118 Object renderHelper,
119 Effect defaultInput)
120 {
121 return RenderState.RenderSpaceRenderState;
122 }
123
124 @Override
125 public boolean reducesOpaquePixels() {
126 final Effect input = getInput();
127 return input != null && input.reducesOpaquePixels();
128 }
129 }
|