public abstract class LinearConvolveRenderState extends java.lang.Object implements RenderState
LinearConvolveRenderState
object manages the strategies of
applying a 1 or 2 pass linear convolution to an input and calculates the
necessary data for the filter shader to compute the convolution.
The object is constructed based on the transform that was provided for
the entire filter operation and determines its strategy.
Methods prefixed by getInput*()
return information about the
general plan for obtaining and managing the input source image.
After the input effect is called with the information from the
getInput*()
methods and its result ImageData
is obtained,
the validatePassInput()
method is used to examine the size and
transform of the supplied input and determine the parameters needed to
perform the convolution for the first pass.
Once validated, the methods prefixed by getPass*()
return information
for applying the convolution for that validated pass.
If necessary, the validatePassInput()
method is called on the
results of the first pass to calculate further data for the second pass.
Finally the getResultTransform()
method is used to possibly transform
the final resulting ImageData
of the last pass.Modifier and Type | Class and Description |
---|---|
static class |
LinearConvolveRenderState.PassType |
RenderState.EffectCoordinateSpace
Modifier and Type | Field and Description |
---|---|
(package private) static float[] |
BLACK_COMPONENTS |
static int |
MAX_COMPILED_KERNEL_SIZE |
static int |
MAX_KERNEL_SIZE |
(package private) static float |
MIN_EFFECT_RADIUS |
RenderSpaceRenderState, UnclippedUserSpaceRenderState, UserSpaceRenderState
Constructor and Description |
---|
LinearConvolveRenderState() |
Modifier and Type | Method and Description |
---|---|
abstract int |
getInputKernelSize(int pass)
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. |
abstract int |
getPassKernelSize()
Returns the appropriate kernel size for the pass that was last
validated using validateInput().
|
EffectPeer<? extends LinearConvolveRenderState> |
getPassPeer(Renderer r,
FilterContext fctx)
Return the
EffectPeer to be used to perform the currently
validated pass of the convolution operation, or null if this pass
is a NOP. |
abstract Rectangle |
getPassResultBounds(Rectangle srcdimension,
Rectangle outputClip)
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.
|
abstract float[] |
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. |
LinearConvolveRenderState.PassType |
getPassType()
Return a hint about the way that the weights will be applied to the
pixels for the currently validated pass.
|
abstract float[] |
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.
|
abstract java.nio.FloatBuffer |
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. |
abstract int |
getPassWeightsArrayLength()
Returns the maximum number of valid float4 elements that should be
referenced from the buffer returned by getWeights() for the currently
validated pass.
|
static int |
getPeerSize(int ksize)
Returns the peer sample count for a given kernel size.
|
abstract Color4f |
getShadowColor()
Returns the
Color4f representing the shadow color if this
is a shadow operation. |
abstract boolean |
isNop()
Returns true if the resulting operation is globally a NOP operation.
|
abstract boolean |
isPassNop()
Returns true if the operation of the currently validated pass would
be a NOP operation.
|
abstract boolean |
isShadow()
Returns true if this is a shadow convolution operation where a
constant color is substituted for the color components of the
output.
|
(package private) static boolean |
nearOne(float v,
int size)
Returns true if summing v over size pixels ends up close enough to
size.0 that we will not have shifted the sampling by enough to see any
changes.
|
(package private) static boolean |
nearZero(float v,
int size)
Returns true if summing v over size pixels ends up close enough to
0.0 that we will not have shifted the sampling by enough to see any
changes.
|
abstract ImageData |
validatePassInput(ImageData src,
int pass)
Validates the
RenderState object for a given pass of the
convolution. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEffectTransformSpace, getInputClip, getInputTransform, getResultTransform
public static final int MAX_COMPILED_KERNEL_SIZE
public static final int MAX_KERNEL_SIZE
static final float MIN_EFFECT_RADIUS
static final float[] BLACK_COMPONENTS
public static int getPeerSize(int ksize)
ksize
- the number of computed convolution kernel weightsstatic boolean nearZero(float v, int size)
v
- the value being summed across the pixelssize
- the number of pixels being summed acrossstatic boolean nearOne(float v, int size)
v
- the value being summed across the pixelssize
- the number of pixels being summed acrosspublic abstract boolean isShadow()
Effect
from which
this RenderState
was instantiated and does not vary as the
filter operation progresses.public abstract Color4f getShadowColor()
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.Color4f
for the shadow color, or nullpublic abstract int getInputKernelSize(int pass)
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.pass
- the pass for which the intended kernel size is desiredpublic abstract boolean isNop()
public abstract ImageData validatePassInput(ImageData src, int pass)
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.src
- the ImageData
object supplied by the source effectpass
- the pass of the operation being applied (usually horizontal
for pass 0 and vertical for pass 1)ImageData
to be used for the actual convolution
operationpublic abstract boolean isPassNop()
public EffectPeer<? extends LinearConvolveRenderState> getPassPeer(Renderer r, FilterContext fctx)
EffectPeer
to be used to perform the currently
validated pass of the convolution operation, or null if this pass
is a NOP.r
- the Renderer
being used for this filter operationfctx
- the FilterContext
being used for this filter operationEffectPeer
to use for this pass, or nullpublic abstract Rectangle getPassResultBounds(Rectangle srcdimension, Rectangle outputClip)
srcdimension
- the bounds of the input imageoutputClip
- the area needed for the final resultpublic LinearConvolveRenderState.PassType getPassType()
LinearConvolveRenderState.PassType
that describes the filtering
operation for this pass of the algorithmpublic abstract java.nio.FloatBuffer getPassWeights()
FloatBuffer
padded out to the required size as specified by
the #getPeerSize()
method filled with the convolution weights
needed for the currently validated pass.FloatBuffer
containing the kernel convolution weightspublic abstract int getPassWeightsArrayLength()
public abstract float[] getPassVector()
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 sampleThese 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.
[ incdx, incdy, startdx, startdy ]
public abstract float[] getPassShadowColorComponents()
[0, 1]
for the shadow color
to be substituted for the input colors.
This method will only be called if isShadow()
returns true.public abstract int getPassKernelSize()