1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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 <<
  27 public Rectangle getResultBounds(com.sun.javafx.geom.transform.BaseTransform transform,
  28                                  com.sun.javafx.geom.Rectangle outputClip,
  29                                  com.sun.scenario.effect.ImageData... inputDatas)
  30 {
  31     return getRenderState().getPassResultBounds(inputDatas[0].getTransformedBounds(outputClip));
  32 }
  33 
  34 private int getCount() {
  35     // The shader consumes weights 4 at a time so we need to round the
  36     // kernel size to the next multiple of 4.
  37     return (getRenderState().getPassKernelSize() + 3) / 4;
  38 }
  39 
  40 private float[] getOffset() {
  41     return getRenderState().getPassVector();
  42 }
  43 
  44 private FloatBuffer getWeights() {
  45     return getRenderState().getPassWeights();
  46 }
  47 
  48 private int getWeightsArrayLength() {
  49     return getRenderState().getPassWeightsArrayLength();
  50 }
  51 >>
  52 
  53 param sampler img;
  54 param int count;
  55 // offset.x = dx offset between adjacent weighted convolution samples
  56 // offset.y = dy offset between adjacent weighted convolution samples
  57 // offset.z = dx offset to first weighted convolution sample
  58 // offset.w = dy offset to first weighted convolution sample
  59 param float4 offset;
  60 // value for each location in the offsets array:
  61 //   weights[i].x = weight for pos0 + offset.zw + (i*4+0)*offset.xy
  62 //   weights[i].y = weight for pos0 + offset.zw + (i*4+1)*offset.xy
  63 //   weights[i].z = weight for pos0 + offset.zw + (i*4+2)*offset.xy
  64 //   weights[i].w = weight for pos0 + offset.zw + (i*4+3)*offset.xy
  65 param float4 weights[%d];
  66 
  67 void main()
  68 {
  69     int i;
  70     float4 tmp = float4(0.0, 0.0, 0.0, 0.0);
  71     float2 loc = pos0 + offset.zw;
  72     unroll (%d, 0) for (i = 0; i < count; i++) {
  73         tmp += weights[i].x * sample(img, loc);
  74         loc += offset.xy;
  75         tmp += weights[i].y * sample(img, loc);
  76         loc += offset.xy;
  77         tmp += weights[i].z * sample(img, loc);
  78         loc += offset.xy;
  79         tmp += weights[i].w * sample(img, loc);
  80         loc += offset.xy;
  81     }
  82     color = tmp;
  83 }