modules/graphics/src/main/java/com/sun/scenario/effect/BoxBlur.java
Print this page
@@ -31,17 +31,18 @@
import com.sun.javafx.geom.RectBounds;
import com.sun.javafx.geom.Rectangle;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.scenario.effect.impl.Renderer;
import com.sun.scenario.effect.impl.state.BoxBlurState;
+import com.sun.scenario.effect.impl.state.LinearConvolveKernel;
/**
* A blur effect using a box-shaped convolution kernel, with a configurable
* size for each dimension of the kernel and a number of passes to control
* the quality of the blur.
*/
-public class BoxBlur extends CoreEffect {
+public class BoxBlur extends LinearConvolveCoreEffect {
private final BoxBlurState state = new BoxBlurState();
/**
* Constructs a new {@code BoxBlur} effect with
@@ -52,11 +53,11 @@
* <pre>
* new BoxBlur(1, 1, 1, DefaultInput)
* </pre>
*/
public BoxBlur() {
- this(1, 1);
+ this(1.0f, 1.0f);
}
/**
* Constructs a new {@code BoxBlur} effect with
* the given blur sizes
@@ -70,11 +71,11 @@
* @param hsize the horizontal size of the BoxBlur kernel
* @param vsize the vertical size of the BoxBlur kernel
* @throws IllegalArgumentException if either {@code hsize}
* or {@code vsize} is outside the allowable range
*/
- public BoxBlur(int hsize, int vsize) {
+ public BoxBlur(float hsize, float vsize) {
this(hsize, vsize, 1, DefaultInput);
}
/**
* Constructs a new {@code BoxBlur} effect with
@@ -91,11 +92,11 @@
* @param passes the number of blur passes to execute
* @throws IllegalArgumentException if either {@code hsize}
* or {@code vsize} or {@code passes}
* is outside the allowable range
*/
- public BoxBlur(int hsize, int vsize, int passes) {
+ public BoxBlur(float hsize, float vsize, int passes) {
this(hsize, vsize, passes, DefaultInput);
}
/**
* Constructs a new {@code BoxBlur} effect with
@@ -109,19 +110,19 @@
* @param input the single input {@code Effect}
* @throws IllegalArgumentException if either {@code hsize}
* or {@code vsize} or {@code passes}
* is outside the allowable range
*/
- public BoxBlur(int hsize, int vsize, int passes, Effect input) {
+ public BoxBlur(float hsize, float vsize, int passes, Effect input) {
super(input);
setHorizontalSize(hsize);
setVerticalSize(vsize);
setPasses(passes);
}
@Override
- Object getState() {
+ LinearConvolveKernel getState() {
return state;
}
/**
* Returns the input for this {@code Effect}.
@@ -147,11 +148,11 @@
/**
* Returns the horizontal size of the effect kernel.
*
* @return the horizontal size of the effect kernel
*/
- public int getHorizontalSize() {
+ public float getHorizontalSize() {
return state.getHsize();
}
/**
* Sets the horizontal size of the effect kernel.
@@ -164,21 +165,20 @@
*
* @param hsize the horizontal size of the effect kernel
* @throws IllegalArgumentException if {@code hsize}
* is outside the allowable range
*/
- public void setHorizontalSize(int hsize) {
- int old = state.getHsize();
+ public final void setHorizontalSize(float hsize) {
state.setHsize(hsize);
}
/**
* Returns the vertical size of the effect kernel.
*
* @return the vertical size of the effect kernel
*/
- public int getVerticalSize() {
+ public float getVerticalSize() {
return state.getVsize();
}
/**
* Sets the vertical size of the effect kernel.
@@ -191,12 +191,11 @@
*
* @param vsize the vertical size of the effect kernel
* @throws IllegalArgumentException if {@code vsize}
* is outside the allowable range
*/
- public void setVerticalSize(int vsize) {
- int old = state.getVsize();
+ public final void setVerticalSize(float vsize) {
state.setVsize(vsize);
}
/**
* Returns the number of passes of the effect kernel to control the
@@ -222,12 +221,11 @@
*
* @param passes
* @throws IllegalArgumentException if {@code passes} is outside the
* allowable range
*/
- public void setPasses(int passes) {
- int old = state.getBlurPasses();
+ public final void setPasses(int passes) {
state.setBlurPasses(passes);
}
@Override
public AccelType getAccelType(FilterContext fctx) {
@@ -255,43 +253,10 @@
r.intersectWith(outputClip);
return r;
}
@Override
- public ImageData filterImageDatas(FilterContext fctx,
- BaseTransform transform,
- Rectangle outputClip,
- ImageData... inputs)
- {
- return state.filterImageDatas(this, fctx, transform, outputClip, inputs);
- }
-
- @Override
- public boolean operatesInUserSpace() {
- return true;
- }
-
- @Override
- protected Rectangle getInputClip(int inputIndex,
- BaseTransform transform,
- Rectangle outputClip)
- {
- // A blur needs as much "fringe" data from its input as it creates
- // around its output so we use the same expansion as is used in the
- // result bounds.
- if (outputClip != null) {
- int hgrow = state.getKernelSize(0) / 2;
- int vgrow = state.getKernelSize(1) / 2;
- if ((hgrow | vgrow) != 0) {
- outputClip = new Rectangle(outputClip);
- outputClip.grow(hgrow, vgrow);
- }
- }
- return outputClip;
- }
-
- @Override
public boolean reducesOpaquePixels() {
if (!state.isNop()) {
return true;
}
final Effect input = getInput();