APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.scenario.effect.impl.state

public Class BoxRenderState

extends LinearConvolveRenderState
Class Inheritance
Imports
com.sun.javafx.geom.Rectangle, com.sun.javafx.geom.transform.BaseTransform, .NoninvertibleTransformException, com.sun.scenario.effect.Color4f, .Effect, .FilterContext, .Filterable, .ImageData, com.sun.scenario.effect.impl.BufferUtil, .EffectPeer, .Renderer, java.nio.FloatBuffer

The RenderState for a box filter kernel that can be applied using a standard linear convolution kernel. A box filter has a size that represents how large of an area around a given pixel should be averaged. If the size is 1.0 then just the pixel itself should be averaged and the operation is a NOP. Values smaller than that are automatically treated as 1.0/NOP. For any odd size, the kernel weights the center pixel and an equal number of pixels on either side of it equally, so the weights for size 2N+1 are: [ {N copes of 1.0} 1.0 {N more copies of 1.0} ] As the size grows past that integer size, we must then add another kernel weight entry on both sides of the existing array of 1.0 weights and give them a fractional weight of half of the amount we exceeded the last odd size, so the weights for some size (2N+1)+e (e for epsilon) are: [ e/2.0 {2*N+1 copies of 1.0} e/2.0 ] As the size continues to grow, when it reaches the next even size, we get weights for size 2*N+1+1 to be: [ 0.5 {2*N+1 copies of 1.0} 0.5 ] and as the size continues to grow and approaches the next odd number, we see that 2(N+1)+1 == 2N+2+1 == 2N+1 + 2, so (e) approaches 2 and the numbers on each end of the weights array approach e/2.0 == 1.0 and we end up back at the pattern for an odd size again: [ 1.0 {2*N+1 copies of 1.0} 1.0 ] *************************** SOFTWARE LIMITATION CAVEAT: *************************** Note that the highly optimized software filters for BoxBlur/Shadow will actually do a very optimized "running sum" operation that is only currently implemented for equal weighted kernels. Also, until recently we had always been rounding down the size by casting it to an integer at a high level (in the FX layer peer synchronization code), so for now the software filters may only implement a subset of the above theory and new optimized loops that allow partial sums on the first and last values will need to be written. Until then we will be rounding the sizes to an odd size, but only in the sw loops.

Field Summary

Modifier and TypeField and Description
private final int
private final float
private final float
private BaseTransform
private final boolean
private static final int[]
private float
private BaseTransform
private float[]
private Color4f
private RenderState.EffectCoordinateSpace
private final float
private final int
private boolean
private int
private FloatBuffer
private float
private float
Inherited from com.sun.scenario.effect.impl.state.LinearConvolveRenderState:
BLACK_COMPONENTSMAX_COMPILED_KERNEL_SIZEMAX_KERNEL_SIZEMIN_EFFECT_RADIUS

Constructor Summary

AccessConstructor and Description
public
BoxRenderState(float hsize, float vsize, int blurPasses, float spread, boolean isShadow, Color4f shadowColor, BaseTransform filtertx)

Method Summary

Modifier and TypeMethod and Description
public int
public int
getBoxPixelSize(int pass)

public RenderState.EffectCoordinateSpace
getEffectTransformSpace()

Implements com.sun.scenario.effect.impl.state.RenderState.getEffectTransformSpace.

Return a hint indicating which coordinate space should be used for the pixel filtering for this particular filtering operation.

public Rectangle
getInputClip(int i, Rectangle filterClip)

Implements com.sun.scenario.effect.impl.state.RenderState.getInputClip.

Return the clip for the indicated input based on the indicated output clip.

public int
getInputKernelSize(int pass)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getInputKernelSize.

Returns the size of the desired convolution kernel for the given pass as it would be applied in the coordinate space indicated by the getInputKernelSize(int) method.

public BaseTransform
getInputTransform(BaseTransform filterTransform)

Implements com.sun.scenario.effect.impl.state.RenderState.getInputTransform.

Return the transform that should be used to obtain pixel input from the Effect inputs for this filter operation.

public static int
getKernelSize(int passSize, int blurPasses)

public static int
getMaxSizeForKernelSize(int kernelSize, int blurPasses)

public int
getPassKernelSize()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassKernelSize.

Returns the appropriate kernel size for the pass that was last validated using validateInput().

public EffectPeer<BoxRenderState>
getPassPeer(Renderer r, FilterContext fctx)

Overrides com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassPeer.

Return the EffectPeer to be used to perform the currently validated pass of the convolution operation, or null if this pass is a NOP.

public Rectangle
getPassResultBounds(Rectangle srcdimension, Rectangle outputClip)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassResultBounds.

Returns the size of the scaled result image needed to hold the output for the currently validated pass with the indicated input dimensions and output clip.

public float[]
getPassShadowColorComponents()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassShadowColorComponents.

For a shadow convolution operation, return the 4 float versions of the color components, in the range [0, 1] for the shadow color to be substituted for the input colors.

public float[]
getPassVector()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassVector.

Returns an array of 4 floats used to initialize a float4 Shader constant with the relative starting location of the first weight in the convolution kernel and the incremental offset between each sample to be weighted and accumulated.

public FloatBuffer
getPassWeights()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeights.

A FloatBuffer padded out to the required size as specified by the getPeerSize() method filled with the convolution weights needed for the currently validated pass.

public int
getPassWeightsArrayLength()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeightsArrayLength.

Returns the maximum number of valid float4 elements that should be referenced from the buffer returned by getWeights() for the currently validated pass.

public BaseTransform
getResultTransform(BaseTransform filterTransform)

Implements com.sun.scenario.effect.impl.state.RenderState.getResultTransform.

Return the transform that should be used to transform the results of the filter operation.

public Color4f
getShadowColor()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getShadowColor.

Returns the Color4f representing the shadow color if this is a shadow operation.

public float
public boolean
isNop()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isNop.

Returns true if the resulting operation is globally a NOP operation.

public boolean
isPassNop()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isPassNop.

Returns true if the operation of the currently validated pass would be a NOP operation.

public boolean
isShadow()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isShadow.

Returns true if this is a shadow convolution operation where a constant color is substituted for the color components of the output.

public ImageData
validatePassInput(ImageData src, int pass)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.validatePassInput.

Validates the RenderState object for a given pass of the convolution.

private void
Inherited from com.sun.scenario.effect.impl.state.LinearConvolveRenderState:
getPassTypegetPeerSizenearOnenearZero

Field Detail

blurPassesback to summary
private final int blurPasses
inputSizeHback to summary
private final float inputSizeH
inputSizeVback to summary
private final float inputSizeV
inputtxback to summary
private BaseTransform inputtx
isShadowback to summary
private final boolean isShadow
MAX_BOX_SIZESback to summary
private static final int[] MAX_BOX_SIZES
passSizeback to summary
private float passSize
resulttxback to summary
private BaseTransform resulttx
samplevectorsback to summary
private float[] samplevectors
shadowColorback to summary
private Color4f shadowColor
spaceback to summary
private RenderState.EffectCoordinateSpace space
spreadback to summary
private final float spread
spreadPassback to summary
private final int spreadPass
swCompatibleback to summary
private boolean swCompatible
validatedPassback to summary
private int validatedPass
weightsback to summary
private FloatBuffer weights
weightsValidSizeback to summary
private float weightsValidSize
weightsValidSpreadback to summary
private float weightsValidSpread

Constructor Detail

BoxRenderStateback to summary
public BoxRenderState(float hsize, float vsize, int blurPasses, float spread, boolean isShadow, Color4f shadowColor, BaseTransform filtertx)

Method Detail

getBlurPassesback to summary
public int getBlurPasses()
getBoxPixelSizeback to summary
public int getBoxPixelSize(int pass)
getEffectTransformSpaceback to summary
public RenderState.EffectCoordinateSpace getEffectTransformSpace()

Implements com.sun.scenario.effect.impl.state.RenderState.getEffectTransformSpace.

Doc from com.sun.scenario.effect.impl.state.RenderState.getEffectTransformSpace.

Return a hint indicating which coordinate space should be used for the pixel filtering for this particular filtering operation. The getEffectTransform() and getResultTransform() methods will always be used to get the actual transforms to be used to get input data and transform the results, but this method can help to set the expectations of the caller to optimize techniques.

Annotations
@Override
getInputClipback to summary
public Rectangle getInputClip(int i, Rectangle filterClip)

Implements com.sun.scenario.effect.impl.state.RenderState.getInputClip.

Doc from com.sun.scenario.effect.impl.state.RenderState.getInputClip.

Return the clip for the indicated input based on the indicated output clip.

Annotations
@Override
getInputKernelSizeback to summary
public int getInputKernelSize(int pass)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getInputKernelSize.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getInputKernelSize.

Returns the size of the desired convolution kernel for the given pass as it would be applied in the coordinate space indicated by the getInputKernelSize(int) method. This value is calculated at the start of the render operation and does not vary as the filter operation progresses, but it may not represent the actual kernel size used when the indicated pass actually occurs if the validatePassInput() method needs to choose different values when it sees the incoming image source.

Annotations
@Override
getInputTransformback to summary
public BaseTransform getInputTransform(BaseTransform filterTransform)

Implements com.sun.scenario.effect.impl.state.RenderState.getInputTransform.

Doc from com.sun.scenario.effect.impl.state.RenderState.getInputTransform.

Return the transform that should be used to obtain pixel input from the Effect inputs for this filter operation. The returned transform is handed to all input Effect objects to obtain pixel data for the inputs. Typically, the output of getInputTransform(transform) and getResultTransform(transform) could be concatenated to produce the original filterTransform.

Annotations
@Override
getKernelSizeback to summary
public static int getKernelSize(int passSize, int blurPasses)
getMaxSizeForKernelSizeback to summary
public static int getMaxSizeForKernelSize(int kernelSize, int blurPasses)
getPassKernelSizeback to summary
public int getPassKernelSize()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassKernelSize.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassKernelSize.

Returns the appropriate kernel size for the pass that was last validated using validateInput().

Annotations
@Override
getPassPeerback to summary
public EffectPeer<BoxRenderState> getPassPeer(Renderer r, FilterContext fctx)

Overrides com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassPeer.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassPeer.

Return the EffectPeer to be used to perform the currently validated pass of the convolution operation, or null if this pass is a NOP.

Annotations
@Override
getPassResultBoundsback to summary
public Rectangle getPassResultBounds(Rectangle srcdimension, Rectangle outputClip)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassResultBounds.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassResultBounds.

Returns the size of the scaled result image needed to hold the output for the currently validated pass with the indicated input dimensions and output clip. The image may be further scaled after the shader operation is through to obtain the final result bounds. This value is only of use to the actual shader to understand exactly how much room to allocate for the shader result.

Annotations
@Override
getPassShadowColorComponentsback to summary
public float[] getPassShadowColorComponents()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassShadowColorComponents.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassShadowColorComponents.

For a shadow convolution operation, return the 4 float versions of the color components, in the range [0, 1] for the shadow color to be substituted for the input colors. This method will only be called if isShadow() returns true.

Annotations
@Override
getPassVectorback to summary
public float[] getPassVector()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassVector.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassVector.

Returns an array of 4 floats used to initialize a float4 Shader constant with the relative starting location of the first weight in the convolution kernel and the incremental offset between each sample to be weighted and accumulated. The values are stored in the array in the following order:

    shadervec.x = vector[0] = incdx // X delta between subsequent samples
    shadervec.y = vector[1] = incdy // Y delta between subsequent samples
    shadervec.z = vector[2] = startdx // X offset to first convolution sample
    shadervec.w = vector[3] = startdy // Y offset to first convolution sample
These values are used in the shader loop as follows:
    samplelocation = outputpixellocation.xy + shadervec.zw;
    for (each weight) {
        sum += weight * sample(samplelocation.xy);
        samplelocation.xy += shadervec.xy;
    }
The values are relative to the texture coordinate space which are normalized to the range [0,1] over the source texture.
Annotations
@Override
getPassWeightsback to summary
public FloatBuffer getPassWeights()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeights.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeights.

A FloatBuffer padded out to the required size as specified by the getPeerSize() method filled with the convolution weights needed for the currently validated pass.

Annotations
@Override
getPassWeightsArrayLengthback to summary
public int getPassWeightsArrayLength()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeightsArrayLength.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getPassWeightsArrayLength.

Returns the maximum number of valid float4 elements that should be referenced from the buffer returned by getWeights() for the currently validated pass.

Annotations
@Override
getResultTransformback to summary
public BaseTransform getResultTransform(BaseTransform filterTransform)

Implements com.sun.scenario.effect.impl.state.RenderState.getResultTransform.

Doc from com.sun.scenario.effect.impl.state.RenderState.getResultTransform.

Return the transform that should be used to transform the results of the filter operation. The returned transform is combined with the resulting filter result texture to produce an output ImageData object. Typically, the output of getInputTransform(transform) and getResultTransform(transform) could be concatenated to produce the original filterTransform.

Annotations
@Override
getShadowColorback to summary
public Color4f getShadowColor()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getShadowColor.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.getShadowColor.

Returns the Color4f representing the shadow color if this is a shadow operation. This value is dependent only on the original Effect from which this RenderState was instantiated and does not vary as the filter operation progresses.

Annotations
@Override
getSpreadback to summary
public float getSpread()
isNopback to summary
public boolean isNop()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isNop.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isNop.

Returns true if the resulting operation is globally a NOP operation. This condition is calculated at the start of the render operation and is based on whether the perturbations of the convolution kernel would be noticeable at all in the coordinate space of the output.

Annotations
@Override
isPassNopback to summary
public boolean isPassNop()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isPassNop.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isPassNop.

Returns true if the operation of the currently validated pass would be a NOP operation.

Annotations
@Override
isShadowback to summary
public boolean isShadow()

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isShadow.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.isShadow.

Returns true if this is a shadow convolution operation where a constant color is substituted for the color components of the output. This value is dependent only on the original Effect from which this RenderState was instantiated and does not vary as the filter operation progresses.

Annotations
@Override
validatePassInputback to summary
public ImageData validatePassInput(ImageData src, int pass)

Implements abstract com.sun.scenario.effect.impl.state.LinearConvolveRenderState.validatePassInput.

Doc from com.sun.scenario.effect.impl.state.LinearConvolveRenderState.validatePassInput.

Validates the RenderState object for a given pass of the convolution. The supplied source image is provided so that the RenderState object can determine if it needs to change its strategy for how the convolution operation will be performed and to scale its data for the getPass*() methods relative to the source dimensions and transform.

Annotations
@Override
validateWeightsback to summary
private void validateWeights()