modules/graphics/src/main/java/com/sun/scenario/effect/impl/state/HVSeparableKernel.java

Print this page




   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 package com.sun.scenario.effect.impl.state;
  27 
  28 import com.sun.javafx.geom.Rectangle;
  29 import com.sun.javafx.geom.transform.BaseTransform;
  30 import com.sun.javafx.geom.transform.NoninvertibleTransformException;
  31 
  32 /**
  33  * An abstract helper intermediate implementation class for
  34  * {@code LinearConvolve} effects that break down into a horizontal and
  35  * a vertical pass.
  36  */
  37 public abstract class HVSeparableKernel extends LinearConvolveKernel {
  38     @Override
  39     public final int getNumberOfPasses() {
  40         return 2;
  41     }
  42 
  43     @Override
  44     public PassType getPassType(int pass) {
  45         return (pass == 0)
  46             ? PassType.HORIZONTAL_CENTERED
  47             : PassType.VERTICAL_CENTERED;
  48     }
  49 
  50     @Override
  51     public final Rectangle getResultBounds(Rectangle srcdimension, int pass) {
  52         int ksize = getKernelSize(pass);
  53         Rectangle ret = new Rectangle(srcdimension);
  54         if (pass == 0) {
  55             ret.grow(ksize/2, 0);
  56         } else {
  57             ret.grow(0, ksize/2);
  58         }
  59         return ret;
  60     }
  61 
  62     @Override
  63     public final Rectangle getScaledResultBounds(Rectangle srcdimension, int pass) {
  64         int ksize = getScaledKernelSize(pass);
  65         Rectangle ret = new Rectangle(srcdimension);
  66         if (pass == 0) {
  67             ret.grow(ksize/2, 0);
  68         } else {
  69             ret.grow(0, ksize/2);
  70         }
  71         return ret;
  72     }
  73 
  74     @Override
  75     public final float[] getVector(Rectangle srcnativedimensions,
  76                                    BaseTransform transform, int pass)
  77     {
  78         float ret[] = new float[4];
  79         float ps;
  80         if (transform.isTranslateOrIdentity()) {
  81             ps = 1f;
  82         } else {
  83             ret[0] = (pass == 0) ? 1f : 0f;
  84             ret[1] = (pass == 1) ? 1f : 0f;
  85             try {
  86                 transform.inverseDeltaTransform(ret, 0, ret, 0, 1);
  87                 ps = (float) Math.hypot(ret[0], ret[1]);
  88             } catch (NoninvertibleTransformException e) {
  89                 ps = 0f;
  90             }
  91         }
  92         float xoff = (pass == 0) ? ps / srcnativedimensions.width  : 0f;
  93         float yoff = (pass == 1) ? ps / srcnativedimensions.height : 0f;
  94         int ksize = getScaledKernelSize(pass);
  95         int center = ksize / 2;
  96         ret[0] = xoff;
  97         ret[1] = yoff;
  98         ret[2] = -center * xoff;
  99         ret[3] = -center * yoff;
 100         return ret;
 101     }
 102 }


   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 package com.sun.scenario.effect.impl.state;
  27 
  28 import com.sun.javafx.geom.Rectangle;


  29 
  30 /**
  31  * An abstract helper intermediate implementation class for
  32  * {@code LinearConvolve} effects that break down into a horizontal and
  33  * a vertical pass.
  34  */
  35 public abstract class HVSeparableKernel extends LinearConvolveKernel {
  36     @Override












  37     public final Rectangle getResultBounds(Rectangle srcdimension, int pass) {
  38         int ksize = getKernelSize(pass);
  39         Rectangle ret = new Rectangle(srcdimension);
  40         if (pass == 0) {
  41             ret.grow(ksize/2, 0);
  42         } else {
  43             ret.grow(0, ksize/2);
  44         }
  45         return ret;
  46     }









































  47 }