1 /* 2 * Copyright (c) 2009, 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 * This file was originally generated by JSLC 28 * and then hand edited for performance. 29 */ 30 31 package com.sun.scenario.effect.impl.sw.sse; 32 33 import com.sun.scenario.effect.Effect; 34 import com.sun.scenario.effect.FilterContext; 35 import com.sun.scenario.effect.ImageData; 36 import com.sun.scenario.effect.impl.HeapImage; 37 import com.sun.scenario.effect.impl.Renderer; 38 import com.sun.javafx.geom.Rectangle; 39 import com.sun.javafx.geom.transform.BaseTransform; 40 import com.sun.scenario.effect.impl.state.BoxRenderState; 41 42 public class SSEBoxBlurPeer extends SSEEffectPeer<BoxRenderState> { 43 44 public SSEBoxBlurPeer(FilterContext fctx, Renderer r, String uniqueName) { 45 super(fctx, r, uniqueName); 46 } 47 48 @Override 49 public ImageData filter(Effect effect, 50 BoxRenderState brstate, 51 BaseTransform transform, 52 Rectangle outputClip, 53 ImageData... inputs) 54 { 55 setRenderState(brstate); 56 // NOTE: for now, all input images must be TYPE_INT_ARGB_PRE 57 58 boolean horizontal = (getPass() == 0); 59 60 // Calculate the amount the image grows on each iteration (size-1) 61 int hinc = horizontal ? brstate.getBoxPixelSize(0) - 1 : 0; 62 int vinc = horizontal ? 0 : brstate.getBoxPixelSize(1) - 1; 63 int iterations = brstate.getBlurPasses(); 64 if (iterations < 1 || (hinc < 1 && vinc < 1)) { 65 inputs[0].addref(); 66 return inputs[0]; 67 } 68 // Calculate the amount the image will grow through the full operation 69 // Always upgrade to the next even amount of growth 70 int growx = (hinc * iterations + 1) & (~0x1); 71 int growy = (vinc * iterations + 1) & (~0x1); 72 73 // Assert: rstate.getEffectTransformSpace() == UserSpace 74 // NOTE: We could still have a transformed ImageData for other reasons... 75 HeapImage src = (HeapImage)inputs[0].getUntransformedImage(); 76 Rectangle srcr = inputs[0].getUntransformedBounds(); 77 78 HeapImage cur = src; 79 int curw = srcr.width; 80 int curh = srcr.height; 81 int curscan = cur.getScanlineStride(); 82 int[] curPixels = cur.getPixelArray(); 83 84 int finalw = curw + growx; 85 int finalh = curh + growy; 86 while (curw < finalw || curh < finalh) { 87 int neww = curw + hinc; 88 int newh = curh + vinc; 89 if (neww > finalw) neww = finalw; 90 if (newh > finalh) newh = finalh; 91 HeapImage dst = (HeapImage)getRenderer().getCompatibleImage(neww, newh); 92 int newscan = dst.getScanlineStride(); 93 int[] newPixels = dst.getPixelArray(); 94 if (horizontal) { 95 filterHorizontal(newPixels, neww, newh, newscan, 96 curPixels, curw, curh, curscan); 97 } else { 98 filterVertical(newPixels, neww, newh, newscan, 99 curPixels, curw, curh, curscan); 100 } 101 if (cur != src) { 102 getRenderer().releaseCompatibleImage(cur); 103 } 104 cur = dst; 105 curw = neww; 106 curh = newh; 107 curPixels = newPixels; 108 curscan = newscan; 109 } 110 111 Rectangle dstBounds = 112 new Rectangle(srcr.x - growx/2, srcr.y - growy/2, curw, curh); 113 return new ImageData(getFilterContext(), cur, dstBounds); 114 } 115 116 private static native void 117 filterHorizontal(int dstPixels[], int dstw, int dsth, int dstscan, 118 int srcPixels[], int srcw, int srch, int srcscan); 119 120 private static native void 121 filterVertical(int dstPixels[], int dstw, int dsth, int dstscan, 122 int srcPixels[], int srcw, int srch, int srcscan); 123 }