modules/graphics/src/main/java/com/sun/scenario/effect/impl/sw/java/JSWBoxShadowPeer.java

Print this page




  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.java;
  32 
  33 import com.sun.scenario.effect.Effect;
  34 import com.sun.scenario.effect.BoxShadow;
  35 import com.sun.scenario.effect.FilterContext;
  36 import com.sun.scenario.effect.ImageData;
  37 import com.sun.scenario.effect.impl.HeapImage;
  38 import com.sun.scenario.effect.impl.Renderer;
  39 import com.sun.javafx.geom.Rectangle;
  40 import com.sun.javafx.geom.transform.BaseTransform;

  41 
  42 public class JSWBoxShadowPeer extends JSWEffectPeer {
  43 
  44     public JSWBoxShadowPeer(FilterContext fctx, Renderer r, String uniqueName) {
  45         super(fctx, r, uniqueName);
  46     }
  47 
  48     @Override
  49     protected final BoxShadow getEffect() {
  50         return (BoxShadow)super.getEffect();
  51     }
  52 
  53     @Override
  54     public ImageData filter(Effect effect,

  55                             BaseTransform transform,
  56                             Rectangle outputClip,
  57                             ImageData... inputs)
  58     {

  59         // NOTE: for now, all input images must be TYPE_INT_ARGB_PRE
  60         setEffect(effect);
  61         Rectangle dstBounds = getResultBounds(transform, outputClip, inputs);
  62 
  63         // Calculate the amount the image grows on each iteration (size-1)
  64         boolean horizontal = (getPass() == 0);
  65         int hinc = horizontal ? getEffect().getHorizontalSize() - 1 : 0;
  66         int vinc = horizontal ? 0 : getEffect().getVerticalSize() - 1;
  67         if (hinc < 0) hinc = 0;
  68         if (vinc < 0) vinc = 0;
  69         int iterations = getEffect().getPasses();
  70         float spread = getEffect().getSpread();
  71         if (horizontal && (iterations < 1 || (hinc < 1 && vinc < 1))) {
  72             inputs[0].addref();
  73             return inputs[0];
  74         }
  75         // Calculate the amount the image will grow through the full operation
  76         // Always upgrade to the next even amount of growth
  77         int growx = (hinc * iterations + 1) & (~0x1);
  78         int growy = (vinc * iterations + 1) & (~0x1);
  79 
  80         // Assert: ((FilterEffect) effect).operatesInUserSpace()...
  81         // NOTE: We could still have a transformed ImageData for other reasons...
  82         HeapImage src = (HeapImage)inputs[0].getUntransformedImage();
  83         Rectangle srcr = inputs[0].getUntransformedBounds();
  84 
  85         HeapImage cur = src;
  86         int curw = srcr.width;
  87         int curh = srcr.height;
  88         int curscan = cur.getScanlineStride();
  89         int[] curPixels = cur.getPixelArray();
  90 
  91         int finalw = curw + growx;
  92         int finalh = curh + growy;
  93         boolean force = !horizontal;
  94         while (force || curw < finalw || curh < finalh) {
  95             int neww = curw + hinc;
  96             int newh = curh + vinc;
  97             if (neww > finalw) neww = finalw;
  98             if (newh > finalh) newh = finalh;
  99             HeapImage dst = (HeapImage)getRenderer().getCompatibleImage(neww, newh);
 100             int newscan = dst.getScanlineStride();
 101             int[] newPixels = dst.getPixelArray();
 102             if (iterations == 0) {
 103                 // The last "fixup" iteration of 2 should have no spread.
 104                 spread = 0f;
 105             }
 106             if (horizontal) {
 107                 filterHorizontalBlack(newPixels, neww, newh, newscan,
 108                                       curPixels, curw, curh, curscan,
 109                                       spread);
 110             } else if (neww < finalw || newh < finalh) {
 111                 // Use BLACK for shadow color until very last pass
 112                 filterVerticalBlack(newPixels, neww, newh, newscan,
 113                                     curPixels, curw, curh, curscan,
 114                                     spread);
 115             } else {
 116                 float shadowColor[] =
 117                      getEffect().getColor().getPremultipliedRGBComponents();
 118                 if (shadowColor[3] == 1f &&
 119                     shadowColor[0] == 0f &&
 120                     shadowColor[1] == 0f &&
 121                     shadowColor[2] == 0f)
 122                 {
 123                     filterVerticalBlack(newPixels, neww, newh, newscan,
 124                                         curPixels, curw, curh, curscan,
 125                                         spread);
 126                 } else {
 127                     filterVertical(newPixels, neww, newh, newscan,
 128                                    curPixels, curw, curh, curscan,
 129                                    spread, shadowColor);
 130                 }
 131             }
 132             if (cur != src) {
 133                 getRenderer().releaseCompatibleImage(cur);
 134             }
 135             iterations--;
 136             force = false;
 137             cur = dst;




  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.java;
  32 
  33 import com.sun.scenario.effect.Effect;
  34 import com.sun.scenario.effect.BoxShadow;
  35 import com.sun.scenario.effect.FilterContext;
  36 import com.sun.scenario.effect.ImageData;
  37 import com.sun.scenario.effect.impl.HeapImage;
  38 import com.sun.scenario.effect.impl.Renderer;
  39 import com.sun.javafx.geom.Rectangle;
  40 import com.sun.javafx.geom.transform.BaseTransform;
  41 import com.sun.scenario.effect.impl.state.BoxRenderState;
  42 
  43 public class JSWBoxShadowPeer extends JSWEffectPeer<BoxRenderState> {
  44 
  45     public JSWBoxShadowPeer(FilterContext fctx, Renderer r, String uniqueName) {
  46         super(fctx, r, uniqueName);
  47     }
  48 
  49     @Override





  50     public ImageData filter(Effect effect,
  51                             BoxRenderState brstate,
  52                             BaseTransform transform,
  53                             Rectangle outputClip,
  54                             ImageData... inputs)
  55     {
  56         setRenderState(brstate);
  57         // NOTE: for now, all input images must be TYPE_INT_ARGB_PRE


  58 
  59         // Calculate the amount the image grows on each iteration (size-1)
  60         boolean horizontal = (getPass() == 0);
  61         int hinc = horizontal ? brstate.getBoxPixelSize(0) - 1 : 0;
  62         int vinc = horizontal ? 0 : brstate.getBoxPixelSize(1) - 1;
  63         if (hinc < 0) hinc = 0;
  64         if (vinc < 0) vinc = 0;
  65         int iterations = brstate.getBlurPasses();
  66         float spread = brstate.getSpread();
  67         if (horizontal && (iterations < 1 || (hinc < 1 && vinc < 1))) {
  68             inputs[0].addref();
  69             return inputs[0];
  70         }
  71         // Calculate the amount the image will grow through the full operation
  72         // Always upgrade to the next even amount of growth
  73         int growx = (hinc * iterations + 1) & (~0x1);
  74         int growy = (vinc * iterations + 1) & (~0x1);
  75 
  76         // Assert: rstate.getEffectTransformSpace() == UserSpace
  77         // NOTE: We could still have a transformed ImageData for other reasons...
  78         HeapImage src = (HeapImage)inputs[0].getUntransformedImage();
  79         Rectangle srcr = inputs[0].getUntransformedBounds();
  80 
  81         HeapImage cur = src;
  82         int curw = srcr.width;
  83         int curh = srcr.height;
  84         int curscan = cur.getScanlineStride();
  85         int[] curPixels = cur.getPixelArray();
  86 
  87         int finalw = curw + growx;
  88         int finalh = curh + growy;
  89         boolean force = !horizontal;
  90         while (force || curw < finalw || curh < finalh) {
  91             int neww = curw + hinc;
  92             int newh = curh + vinc;
  93             if (neww > finalw) neww = finalw;
  94             if (newh > finalh) newh = finalh;
  95             HeapImage dst = (HeapImage)getRenderer().getCompatibleImage(neww, newh);
  96             int newscan = dst.getScanlineStride();
  97             int[] newPixels = dst.getPixelArray();
  98             if (iterations == 0) {
  99                 // The last "fixup" iteration of 2 should have no spread.
 100                 spread = 0f;
 101             }
 102             if (horizontal) {
 103                 filterHorizontalBlack(newPixels, neww, newh, newscan,
 104                                       curPixels, curw, curh, curscan,
 105                                       spread);
 106             } else if (neww < finalw || newh < finalh) {
 107                 // Use BLACK for shadow color until very last pass
 108                 filterVerticalBlack(newPixels, neww, newh, newscan,
 109                                     curPixels, curw, curh, curscan,
 110                                     spread);
 111             } else {
 112                 float shadowColor[] =
 113                      brstate.getShadowColor().getPremultipliedRGBComponents();
 114                 if (shadowColor[3] == 1f &&
 115                     shadowColor[0] == 0f &&
 116                     shadowColor[1] == 0f &&
 117                     shadowColor[2] == 0f)
 118                 {
 119                     filterVerticalBlack(newPixels, neww, newh, newscan,
 120                                         curPixels, curw, curh, curscan,
 121                                         spread);
 122                 } else {
 123                     filterVertical(newPixels, neww, newh, newscan,
 124                                    curPixels, curw, curh, curscan,
 125                                    spread, shadowColor);
 126                 }
 127             }
 128             if (cur != src) {
 129                 getRenderer().releaseCompatibleImage(cur);
 130             }
 131             iterations--;
 132             force = false;
 133             cur = dst;