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 private LinearConvolveKernel getKernel() { 28 return (LinearConvolveKernel) AccessHelper.getState(getEffect()); 29 } 30 31 public int getPow2ScaleX(LinearConvolveKernel kernel) { 32 return kernel.getPow2ScaleX(); 33 } 34 35 public int getPow2ScaleY(LinearConvolveKernel kernel) { 36 return kernel.getPow2ScaleY(); 37 } 38 39 public Rectangle getResultBounds(com.sun.javafx.geom.transform.BaseTransform transform, 40 com.sun.javafx.geom.Rectangle outputClip, 41 com.sun.scenario.effect.ImageData... inputDatas) 42 { 43 return getKernel().getScaledResultBounds(inputDatas[0].getTransformedBounds(outputClip), getPass()); 44 } 45 46 private int getCount() { 47 return (getKernel().getScaledKernelSize(getPass()) + 3) / 4; 48 } 49 50 private float[] getOffset() { 51 return getKernel().getVector(getInputNativeBounds(0), getInputTransform(0), getPass()); 52 } 53 54 private FloatBuffer getWeights() { 55 return getKernel().getWeights(getPass()); 56 } 57 58 private int getWeightsArrayLength() { 59 return getKernel().getWeightsArrayLength(getPass()); 60 } 61 >> 62 63 param sampler img; 64 param int count; 65 // offset.x = dx offset between adjacent weighted convolution samples 66 // offset.y = dy offset between adjacent weighted convolution samples 67 // offset.z = dx offset to first weighted convolution sample 68 // offset.w = dy offset to first weighted convolution sample 69 param float4 offset; 70 // value for each location in the offsets array: 71 // weights[i].x = weight for pos0 + offset + i*direction*4+0 72 // weights[i].y = weight for pos0 + offset + i*direction*4+1 73 // weights[i].z = weight for pos0 + offset + i*direction*4+2 74 // weights[i].w = weight for pos0 + offset + i*direction*4+3 75 param float4 weights[%d]; 76 77 void main() 78 { 79 int i; 80 float4 tmp = float4(0.0, 0.0, 0.0, 0.0); 81 float2 loc = pos0 + offset.zw; 82 unroll (%d, 0) for (i = 0; i < count; i++) { 83 tmp += weights[i].x * sample(img, loc); 84 loc += offset.xy; 85 tmp += weights[i].y * sample(img, loc); 86 loc += offset.xy; 87 tmp += weights[i].z * sample(img, loc); 88 loc += offset.xy; 89 tmp += weights[i].w * sample(img, loc); 90 loc += offset.xy; 91 } 92 color = tmp; 93 }