modules/graphics/src/main/java/com/sun/scenario/effect/GaussianShadow.java

Print this page




  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.BaseBounds;
  29 import com.sun.javafx.geom.DirtyRegionContainer;
  30 import com.sun.javafx.geom.DirtyRegionPool;
  31 import com.sun.javafx.geom.RectBounds;
  32 import com.sun.javafx.geom.Rectangle;
  33 import com.sun.javafx.geom.transform.BaseTransform;
  34 import com.sun.scenario.effect.impl.Renderer;
  35 import com.sun.scenario.effect.impl.state.GaussianShadowState;


  36 
  37 /**
  38  * A blurred shadow effect using a Gaussian convolution kernel, with a
  39  * configurable radius and shadow color.  Only the alpha channel of the
  40  * input is used to create the shadow effect.  The alpha value of each
  41  * pixel from the result of the blur operation is modulated with the
  42  * specified shadow color to produce the resulting image.
  43  */
  44 public class GaussianShadow extends AbstractShadow {
  45 
  46     private GaussianShadowState state = new GaussianShadowState();
  47 
  48     /**
  49      * Constructs a new {@code GaussianShadow} effect with the default radius
  50      * (10.0) and the default color ({@code Color4f.BLACK}), using the
  51      * default input for source data.
  52      * This is a shorthand equivalent to:
  53      * <pre>
  54      *     new GaussianShadow(10f, Color4f.BLACK, DefaultInput)
  55      * </pre>


  93     }
  94 
  95     /**
  96      * Constructs a new {@code GaussianShadow} effect with the given
  97      * radius and color.
  98      *
  99      * @param radius the radius of the Gaussian kernel
 100      * @param color the shadow {@code Color4f}
 101      * @param input the single input {@code Effect}
 102      * @throws IllegalArgumentException if {@code radius} is outside the
 103      * allowable range, or if {@code color} is null
 104      */
 105     public GaussianShadow(float radius, Color4f color, Effect input) {
 106         super(input);
 107         state.setRadius(radius);
 108         state.setShadowColor(color);
 109     }
 110 
 111 
 112     @Override
 113     Object getState() {
 114         return state;
 115     }
 116 
 117     @Override
 118     public AccelType getAccelType(FilterContext fctx) {
 119         return Renderer.getRenderer(fctx).getAccelType();
 120     }
 121 
 122     /**
 123      * Returns the input for this {@code Effect}.
 124      *
 125      * @return the input for this {@code Effect}
 126      */
 127     public final Effect getInput() {
 128         return getInputs().get(0);
 129     }
 130 
 131     /**
 132      * Sets the input for this {@code Effect} to a specific {@code Effect}
 133      * or to the default input if {@code input} is {@code null}.


 341         int vpad = state.getPad(1);
 342         RectBounds ret = new RectBounds(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY());
 343         ret.grow(hpad, vpad);
 344         return transformBounds(transform, ret);
 345     }
 346 
 347     @Override
 348     public Rectangle getResultBounds(BaseTransform transform,
 349                                      Rectangle outputClip,
 350                                      ImageData... inputDatas)
 351     {
 352         Rectangle r = super.getResultBounds(transform, outputClip, inputDatas);
 353         int hpad = state.getPad(0);
 354         int vpad = state.getPad(1);
 355         Rectangle ret = new Rectangle(r);
 356         ret.grow(hpad, vpad);
 357         return ret;
 358     }
 359 
 360     @Override
 361     public ImageData filterImageDatas(FilterContext fctx,
 362                                       BaseTransform transform,
 363                                       Rectangle outputClip,
 364                                       ImageData... inputs)
 365     {
 366         return state.filterImageDatas(this, fctx, transform, outputClip, inputs);
 367     }
 368 
 369     @Override
 370     public boolean operatesInUserSpace() {
 371         return true;
 372     }
 373 
 374     @Override
 375     protected Rectangle getInputClip(int inputIndex,
 376                                      BaseTransform transform,
 377                                      Rectangle outputClip)
 378     {
 379         // A blur needs as much "fringe" data from its input as it creates
 380         // around its output so we use the same expansion as is used in the
 381         // result bounds.
 382         if (outputClip != null) {
 383             int hpad = state.getPad(0);
 384             int vpad = state.getPad(1);
 385             if ((hpad | vpad) != 0) {
 386                 outputClip = new Rectangle(outputClip);
 387                 outputClip.grow(hpad, vpad);
 388             }
 389         }
 390         return outputClip;
 391     }
 392 
 393     @Override
 394     public boolean reducesOpaquePixels() {
 395         return true;
 396     }
 397 
 398     @Override
 399     public DirtyRegionContainer getDirtyRegions(Effect defaultInput, DirtyRegionPool regionPool) {
 400         Effect di = getDefaultedInput(0, defaultInput);
 401         DirtyRegionContainer drc = di.getDirtyRegions(defaultInput, regionPool);
 402         
 403         drc.grow(state.getPad(0), state.getPad(1));
 404 
 405         return drc;
 406     }
 407 }


  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.BaseBounds;
  29 import com.sun.javafx.geom.DirtyRegionContainer;
  30 import com.sun.javafx.geom.DirtyRegionPool;
  31 import com.sun.javafx.geom.RectBounds;
  32 import com.sun.javafx.geom.Rectangle;
  33 import com.sun.javafx.geom.transform.BaseTransform;
  34 import com.sun.scenario.effect.impl.Renderer;
  35 import com.sun.scenario.effect.impl.state.GaussianShadowState;
  36 import com.sun.scenario.effect.impl.state.LinearConvolveKernel;
  37 import com.sun.scenario.effect.impl.state.LinearConvolveRenderState;
  38 
  39 /**
  40  * A blurred shadow effect using a Gaussian convolution kernel, with a
  41  * configurable radius and shadow color.  Only the alpha channel of the
  42  * input is used to create the shadow effect.  The alpha value of each
  43  * pixel from the result of the blur operation is modulated with the
  44  * specified shadow color to produce the resulting image.
  45  */
  46 public class GaussianShadow extends AbstractShadow {
  47 
  48     private GaussianShadowState state = new GaussianShadowState();
  49 
  50     /**
  51      * Constructs a new {@code GaussianShadow} effect with the default radius
  52      * (10.0) and the default color ({@code Color4f.BLACK}), using the
  53      * default input for source data.
  54      * This is a shorthand equivalent to:
  55      * <pre>
  56      *     new GaussianShadow(10f, Color4f.BLACK, DefaultInput)
  57      * </pre>


  95     }
  96 
  97     /**
  98      * Constructs a new {@code GaussianShadow} effect with the given
  99      * radius and color.
 100      *
 101      * @param radius the radius of the Gaussian kernel
 102      * @param color the shadow {@code Color4f}
 103      * @param input the single input {@code Effect}
 104      * @throws IllegalArgumentException if {@code radius} is outside the
 105      * allowable range, or if {@code color} is null
 106      */
 107     public GaussianShadow(float radius, Color4f color, Effect input) {
 108         super(input);
 109         state.setRadius(radius);
 110         state.setShadowColor(color);
 111     }
 112 
 113 
 114     @Override
 115     LinearConvolveKernel getState() {
 116         return state;
 117     }
 118 
 119     @Override
 120     public AccelType getAccelType(FilterContext fctx) {
 121         return Renderer.getRenderer(fctx).getAccelType();
 122     }
 123 
 124     /**
 125      * Returns the input for this {@code Effect}.
 126      *
 127      * @return the input for this {@code Effect}
 128      */
 129     public final Effect getInput() {
 130         return getInputs().get(0);
 131     }
 132 
 133     /**
 134      * Sets the input for this {@code Effect} to a specific {@code Effect}
 135      * or to the default input if {@code input} is {@code null}.


 343         int vpad = state.getPad(1);
 344         RectBounds ret = new RectBounds(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY());
 345         ret.grow(hpad, vpad);
 346         return transformBounds(transform, ret);
 347     }
 348 
 349     @Override
 350     public Rectangle getResultBounds(BaseTransform transform,
 351                                      Rectangle outputClip,
 352                                      ImageData... inputDatas)
 353     {
 354         Rectangle r = super.getResultBounds(transform, outputClip, inputDatas);
 355         int hpad = state.getPad(0);
 356         int vpad = state.getPad(1);
 357         Rectangle ret = new Rectangle(r);
 358         ret.grow(hpad, vpad);
 359         return ret;
 360     }
 361 
 362     @Override

































 363     public boolean reducesOpaquePixels() {
 364         return true;
 365     }
 366 
 367     @Override
 368     public DirtyRegionContainer getDirtyRegions(Effect defaultInput, DirtyRegionPool regionPool) {
 369         Effect di = getDefaultedInput(0, defaultInput);
 370         DirtyRegionContainer drc = di.getDirtyRegions(defaultInput, regionPool);
 371         
 372         drc.grow(state.getPad(0), state.getPad(1));
 373 
 374         return drc;
 375     }
 376 }