OSDN Git Service

7fbfbc025ed1f26dd431ac1899abef5923f6353e
[nyartoolkit-and/nyartoolkit-and.git] / trunk / sample / sandbox / jp / nyatla / nyartoolkit / core / rasterfilter / NyARRasterOperator_Mul.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java edition ARToolKit class library.\r
11  * Copyright (C)2008-2009 Ryo Iizuka\r
12  *\r
13  * This program is free software: you can redistribute it and/or modify\r
14  * it under the terms of the GNU General Public License as published by\r
15  * the Free Software Foundation, either version 3 of the License, or\r
16  * (at your option) any later version.\r
17  * \r
18  * This program is distributed in the hope that it will be useful,\r
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21  * GNU General Public License for more details.\r
22  *\r
23  * You should have received a copy of the GNU General Public License\r
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
25  * \r
26  * For further information please contact.\r
27  *      http://nyatla.jp/nyatoolkit/\r
28  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
29  * \r
30  */\r
31 package jp.nyatla.nyartoolkit.core.rasterfilter;\r
32 \r
33 import jp.nyatla.nyartoolkit.NyARException;\r
34 import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
35 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
36 \r
37 /**\r
38  * 入力Aと入力Bの積を出力します。\r
39  * \r
40  */\r
41 public class NyARRasterOperator_Mul\r
42 {\r
43         private IdoFilterImpl _dofilterimpl;\r
44         public NyARRasterOperator_Mul(int i_raster_type) throws NyARException\r
45         {\r
46                 switch (i_raster_type) {\r
47                 case INyARRaster.BUFFERFORMAT_INT1D_GRAY_8:\r
48                         this._dofilterimpl=new IdoFilterImpl_INT1D_GRAY_8();\r
49                         break;\r
50                 default:\r
51                         throw new NyARException();\r
52                 }\r
53         }\r
54         //\r
55         public void doFilter(INyARRaster i_input_a,INyARRaster i_input_b, INyARRaster i_output) throws NyARException\r
56         {\r
57                 assert (i_input_a.getSize().isEqualSize(i_output.getSize()) == true);\r
58                 assert (i_input_b.getSize().isEqualSize(i_output.getSize()) == true);\r
59                 this._dofilterimpl.doFilter(i_input_a,i_input_b,i_output,i_output.getSize());\r
60         }\r
61         \r
62         abstract class IdoFilterImpl\r
63         {\r
64                 int[] _window_ref;\r
65                 public abstract void doFilter(INyARRaster i_input_a,INyARRaster i_input_b,INyARRaster i_output,NyARIntSize i_size) throws NyARException;\r
66                 \r
67         }\r
68         class IdoFilterImpl_INT1D_GRAY_8 extends IdoFilterImpl\r
69         {\r
70                 public void doFilter(INyARRaster i_input_a,INyARRaster i_input_b,INyARRaster i_output,NyARIntSize i_size) throws NyARException\r
71                 {\r
72                         assert(i_input_a.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));\r
73                         assert(i_input_b.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));\r
74                         assert(i_output.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));\r
75                         \r
76                         int[] out_buf = (int[]) i_output.getBuffer();\r
77                         int[] in_buf1 = (int[]) i_input_a.getBuffer();\r
78                         int[] in_buf2 = (int[]) i_input_b.getBuffer();\r
79                         for(int i=i_size.h*i_size.w-1;i>=0;i--)\r
80                         {\r
81                                 out_buf[i]=(in_buf1[i]*in_buf2[i])>>8;\r
82                         }\r
83                         return;\r
84                 }\r
85         }       \r
86 }