1 /* Copyright (C) 2005-2011 Fabio Riccardi */
2 
3 package com.lightcrafts.jai.operator;
4 
5 import com.lightcrafts.mediax.jai.*;
6 import com.lightcrafts.mediax.jai.registry.RenderedRegistryMode;
7 import com.lightcrafts.mediax.jai.registry.RenderableRegistryMode;
8 
9 import java.awt.image.RenderedImage;
10 import java.awt.image.renderable.RenderableImage;
11 import java.awt.*;
12 
13 /**
14  * Created by IntelliJ IDEA.
15  * User: fabio
16  * Date: Apr 1, 2005
17  * Time: 10:09:12 AM
18  * To change this template use File | Settings | File Templates.
19  */
20 public class BlendDescriptor extends OperationDescriptorImpl {
21 
22     /**
23      * The resource strings that provide the general documentation
24      * and specify the parameter list for this operation.
25      */
26     private static final String[][] resources = {
27         {"GlobalName",  "Blend"},
28         {"LocalName",   "Blend"},
29         {"Vendor",      "lightcrafts.com"},
30         {"Description", "Blend Two Images and a Mask"},
31         {"DocURL",      "none"},
32         {"Version",     "1.0"}
33     };
34 
35     private static Class[] paramClasses = { String.class, Double.class, ROIShape.class, RenderedImage.class };
36     private static String[] paramNames = { "blendingMode", "opacity", "mask", "colorSelection" };
37     private static Object[] paramDefaults = { "Overlay", 1.0, null, null };
38 
39     /** Constructor. */
BlendDescriptor()40     public BlendDescriptor() {
41         super(resources, 2, paramClasses, paramNames, paramDefaults);
42     }
43 
44     /** Returns <code>true</code> since renderable operation is supported. */
isRenderableSupported()45     public boolean isRenderableSupported() {
46         return true;
47     }
48 
49 
50     /**
51      * Adds two images.
52      *
53      * <p>Creates a <code>ParameterBlockJAI</code> from all
54      * supplied arguments except <code>hints</code> and invokes
55      * {@link com.lightcrafts.mediax.jai.JAI#create(String,java.awt.image.renderable.ParameterBlock,java.awt.RenderingHints)}.
56      *
57      * @see com.lightcrafts.mediax.jai.JAI
58      * @see com.lightcrafts.mediax.jai.ParameterBlockJAI
59      * @see com.lightcrafts.mediax.jai.RenderedOp
60      *
61      * @param source0 <code>RenderedImage</code> source 0.
62      * @param source1 <code>RenderedImage</code> source 1.
63      * @param hints The <code>RenderingHints</code> to use.
64      * May be <code>null</code>.
65      * @return The <code>RenderedOp</code> destination.
66      * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
67      * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
68      */
create(RenderedImage source0, RenderedImage source1, RenderedImage colorSelection, RenderingHints hints)69     public static RenderedOp create(RenderedImage source0,
70                                     RenderedImage source1,
71                                     RenderedImage colorSelection,
72                                     RenderingHints hints)  {
73         ParameterBlockJAI pb =
74             new ParameterBlockJAI("Blend",
75                                   RenderedRegistryMode.MODE_NAME);
76 
77         pb.setSource("source0", source0);
78         pb.setSource("source1", source1);
79         pb.setParameter("blendingMode", paramDefaults[0]);
80         pb.setParameter("opacity", paramDefaults[1]);
81         pb.setParameter("mask", paramDefaults[2]);
82         pb.setParameter("colorSelection", colorSelection);
83         return JAI.create("Blend", pb, hints);
84     }
85 
create(RenderedImage source0, RenderedImage source1, RenderedImage colorSelection, String blendingMode, Double opacity, ROI mask, RenderingHints hints)86     public static RenderedOp create(RenderedImage source0,
87                                     RenderedImage source1,
88                                     RenderedImage colorSelection,
89                                     String blendingMode,
90                                     Double opacity,
91                                     ROI mask,
92                                     RenderingHints hints)  {
93         ParameterBlockJAI pb =
94             new ParameterBlockJAI("Blend",
95                                   RenderedRegistryMode.MODE_NAME);
96 
97         pb.setSource("source0", source0);
98         pb.setSource("source1", source1);
99         pb.setSource("colorSelection", colorSelection);
100         pb.setParameter("blendingMode", blendingMode);
101         pb.setParameter("opacity", opacity);
102         pb.setParameter("mask", mask);
103         return JAI.create("Blend", pb, hints);
104     }
105 
106     /**
107      * Adds two images.
108      *
109      * <p>Creates a <code>ParameterBlockJAI</code> from all
110      * supplied arguments except <code>hints</code> and invokes
111      * {@link JAI#createRenderable(String,java.awt.image.renderable.ParameterBlock,RenderingHints)}.
112      *
113      * @see JAI
114      * @see ParameterBlockJAI
115      * @see com.lightcrafts.mediax.jai.RenderableOp
116      *
117      * @param source0 <code>RenderableImage</code> source 0.
118      * @param source1 <code>RenderableImage</code> source 1.
119      * @param hints The <code>RenderingHints</code> to use.
120      * May be <code>null</code>.
121      * @return The <code>RenderableOp</code> destination.
122      * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
123      * @throws IllegalArgumentException if <code>source1</code> is <code>null</code>.
124      */
createRenderable(RenderableImage source0, RenderableImage source1, RenderingHints hints)125     public static RenderableOp createRenderable(RenderableImage source0,
126                                                 RenderableImage source1,
127                                                 RenderingHints hints)  {
128         ParameterBlockJAI pb =
129             new ParameterBlockJAI("Blend",
130                                   RenderableRegistryMode.MODE_NAME);
131 
132         pb.setSource("source0", source0);
133         pb.setSource("source1", source1);
134         pb.setParameter("blendingMode", paramDefaults[0]);
135         pb.setParameter("opacity", paramDefaults[1]);
136         pb.setParameter("mask", paramDefaults[2]);
137         return JAI.createRenderable("Blend", pb, hints);
138     }
139 }
140