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.Point2D;
29 import com.sun.javafx.geom.Rectangle;
30 import com.sun.javafx.geom.transform.BaseTransform;
31
32 /**
33 * An effect that merges two inputs together into one result. This produces
34 * the same result as using the {@code Blend} effect with
35 * {@code Blend.Mode.SRC_OVER} and {@code opacity=1.0}, except possibly
36 * more efficient.
37 */
38 public class Merge extends CoreEffect {
39
40 /**
41 * Constructs a new {@code Merge} effect for the given inputs.
42 *
43 * @param bottomInput the bottom input
44 * @param topInput the top input
45 */
46 public Merge(Effect bottomInput, Effect topInput) {
47 super(bottomInput, topInput);
48 updatePeerKey("Merge");
49 }
50
149 if (botimg != null) {
150 if (!botimg.validate(fctx)) {
151 return new ImageData(fctx, null, null);
152 }
153 if (renderHelper instanceof ImageDataRenderer) {
154 ImageDataRenderer imgr = (ImageDataRenderer) renderHelper;
155 imgr.renderImage(botimg, BaseTransform.IDENTITY_TRANSFORM, fctx);
156 botimg.unref();
157 botimg = null;
158 }
159 }
160 if (botimg == null) {
161 return topinput.filter(fctx, transform, outputClip,
162 renderHelper, defaultInput);
163 }
164 ImageData topimg = topinput.filter(fctx, transform, outputClip,
165 null, defaultInput);
166 if (!topimg.validate(fctx)) {
167 return new ImageData(fctx, null, null);
168 }
169 ImageData ret = filterImageDatas(fctx, transform, outputClip,
170 botimg, topimg);
171 botimg.unref();
172 topimg.unref();
173 return ret;
174 }
175
176 @Override
177 protected Rectangle getInputClip(int inputIndex,
178 BaseTransform transform,
179 Rectangle outputClip)
180 {
181 // This no longer matters since we completely override the
182 // filter method so the FilterEffect.filter() method no longer
183 // comes into play.
184 throw new InternalError("Merge.getInputClip should not be called");
185 }
186
187 @Override
188 public boolean reducesOpaquePixels() {
189 final Effect topInput = getTopInput();
190 final Effect bottomInput = getBottomInput();
191 return topInput != null && topInput.reducesOpaquePixels() && bottomInput != null && bottomInput.reducesOpaquePixels();
192 }
193
194 }
|
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.Point2D;
29 import com.sun.javafx.geom.Rectangle;
30 import com.sun.javafx.geom.transform.BaseTransform;
31 import com.sun.scenario.effect.impl.state.RenderState;
32
33 /**
34 * An effect that merges two inputs together into one result. This produces
35 * the same result as using the {@code Blend} effect with
36 * {@code Blend.Mode.SRC_OVER} and {@code opacity=1.0}, except possibly
37 * more efficient.
38 */
39 public class Merge extends CoreEffect {
40
41 /**
42 * Constructs a new {@code Merge} effect for the given inputs.
43 *
44 * @param bottomInput the bottom input
45 * @param topInput the top input
46 */
47 public Merge(Effect bottomInput, Effect topInput) {
48 super(bottomInput, topInput);
49 updatePeerKey("Merge");
50 }
51
150 if (botimg != null) {
151 if (!botimg.validate(fctx)) {
152 return new ImageData(fctx, null, null);
153 }
154 if (renderHelper instanceof ImageDataRenderer) {
155 ImageDataRenderer imgr = (ImageDataRenderer) renderHelper;
156 imgr.renderImage(botimg, BaseTransform.IDENTITY_TRANSFORM, fctx);
157 botimg.unref();
158 botimg = null;
159 }
160 }
161 if (botimg == null) {
162 return topinput.filter(fctx, transform, outputClip,
163 renderHelper, defaultInput);
164 }
165 ImageData topimg = topinput.filter(fctx, transform, outputClip,
166 null, defaultInput);
167 if (!topimg.validate(fctx)) {
168 return new ImageData(fctx, null, null);
169 }
170 RenderState rstate = getRenderState(fctx, transform, outputClip,
171 renderHelper, defaultInput);
172 ImageData ret = filterImageDatas(fctx, transform, outputClip, rstate,
173 botimg, topimg);
174 botimg.unref();
175 topimg.unref();
176 return ret;
177 }
178
179 @Override
180 public RenderState getRenderState(FilterContext fctx,
181 BaseTransform transform,
182 Rectangle outputClip,
183 Object renderHelper,
184 Effect defaultInput)
185 {
186 return RenderState.RenderSpaceRenderState;
187 }
188
189 @Override
190 public boolean reducesOpaquePixels() {
191 final Effect topInput = getTopInput();
192 final Effect bottomInput = getBottomInput();
193 return topInput != null && topInput.reducesOpaquePixels() && bottomInput != null && bottomInput.reducesOpaquePixels();
194 }
195
196 }
|