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 blends the two inputs together using one of the
34 * pre-defined {@code Mode}s.
35 */
36 public class Blend extends CoreEffect {
37
38 /**
39 * A blending mode that defines the manner in which the inputs
40 * are composited together.
41 * Each {@code Mode} describes a mathematical equation that
42 * combines premultiplied inputs to produce some premultiplied result.
43 */
44 public enum Mode {
45 /**
46 * The top input is blended over the bottom input.
47 * (Equivalent to the Porter-Duff "source over destination" rule.)
48 * <p>
49 * Thus:
50 * <pre>
557 * contributes most to the definition of the output at the specified
558 * coordinate?"
559 * <p>
560 * The {@code Blend} effect delegates this operation to its {@code top}
561 * input, or the {@code defaultInput} if the {@code top} input is
562 * {@code null}.
563 *
564 * @param p the point in the coordinate space of the result output
565 * to be transformed
566 * @param defaultInput the default input {@code Effect} to be used in
567 * all cases where a filter has a null input
568 * @return the untransformed point in the coordinate space of the
569 * primary content input
570 */
571 @Override
572 public Point2D untransform(Point2D p, Effect defaultInput) {
573 return getDefaultedInput(1, defaultInput).untransform(p, defaultInput);
574 }
575
576 @Override
577 protected Rectangle getInputClip(int inputIndex,
578 BaseTransform transform,
579 Rectangle outputClip)
580 {
581 // A blend operation operates on its inputs pixel-by-pixel
582 // with no expansion or contraction.
583 // RT-27563
584 // TODO: For blend modes which "intersect" their inputs, we
585 // could further restrict the amount we ask for each input to the
586 // intersection of the two input bounds, but for now we will
587 // simply pass along the output clip as the input clip.
588 return outputClip;
589 }
590
591 @Override
592 public boolean reducesOpaquePixels() {
593 final Effect bottomInput = getBottomInput();
594 final Effect topInput = getTopInput();
595 switch (getMode()) {
596 case SRC_IN:
597 case SRC_OUT:
598 return true;
599 case SRC_ATOP:
600 return bottomInput != null && bottomInput.reducesOpaquePixels();
601 case SRC_OVER:
602 case ADD:
603 case MULTIPLY:
604 case SCREEN:
605 case OVERLAY:
606 case DARKEN:
607 case LIGHTEN:
608 case COLOR_DODGE:
|
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 blends the two inputs together using one of the
35 * pre-defined {@code Mode}s.
36 */
37 public class Blend extends CoreEffect {
38
39 /**
40 * A blending mode that defines the manner in which the inputs
41 * are composited together.
42 * Each {@code Mode} describes a mathematical equation that
43 * combines premultiplied inputs to produce some premultiplied result.
44 */
45 public enum Mode {
46 /**
47 * The top input is blended over the bottom input.
48 * (Equivalent to the Porter-Duff "source over destination" rule.)
49 * <p>
50 * Thus:
51 * <pre>
558 * contributes most to the definition of the output at the specified
559 * coordinate?"
560 * <p>
561 * The {@code Blend} effect delegates this operation to its {@code top}
562 * input, or the {@code defaultInput} if the {@code top} input is
563 * {@code null}.
564 *
565 * @param p the point in the coordinate space of the result output
566 * to be transformed
567 * @param defaultInput the default input {@code Effect} to be used in
568 * all cases where a filter has a null input
569 * @return the untransformed point in the coordinate space of the
570 * primary content input
571 */
572 @Override
573 public Point2D untransform(Point2D p, Effect defaultInput) {
574 return getDefaultedInput(1, defaultInput).untransform(p, defaultInput);
575 }
576
577 @Override
578 public RenderState getRenderState(FilterContext fctx,
579 BaseTransform transform,
580 Rectangle outputClip,
581 Object renderHelper,
582 Effect defaultInput)
583 {
584 // A blend operation operates on its inputs pixel-by-pixel
585 // with no expansion or contraction.
586 // RT-27563
587 // TODO: The RenderSpaceRenderState object uses the output clip unchanged
588 // for its inputs, but we could further restrict the amount we ask for
589 // each input to the intersection of the two input bounds, but for now we
590 // will simply let it pass along the output clip as the input clip.
591 return RenderState.RenderSpaceRenderState;
592 }
593
594 @Override
595 public boolean reducesOpaquePixels() {
596 final Effect bottomInput = getBottomInput();
597 final Effect topInput = getTopInput();
598 switch (getMode()) {
599 case SRC_IN:
600 case SRC_OUT:
601 return true;
602 case SRC_ATOP:
603 return bottomInput != null && bottomInput.reducesOpaquePixels();
604 case SRC_OVER:
605 case ADD:
606 case MULTIPLY:
607 case SCREEN:
608 case OVERLAY:
609 case DARKEN:
610 case LIGHTEN:
611 case COLOR_DODGE:
|