OSDN Git Service

[TAG]NyARToolkit for Java 2.4.2
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / 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.rasterreader.INyARBufferReader;\r
36 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
37 \r
38 /**\r
39  * 入力Aと入力Bの積を出力します。\r
40  * \r
41  */\r
42 public class NyARRasterOperator_Mul\r
43 {\r
44         private IdoFilterImpl _dofilterimpl;\r
45         public NyARRasterOperator_Mul(int i_raster_type) throws NyARException\r
46         {\r
47                 switch (i_raster_type) {\r
48                 case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
49                         this._dofilterimpl=new IdoFilterImpl_INT1D_GRAY_8();\r
50                         break;\r
51                 default:\r
52                         throw new NyARException();\r
53                 }\r
54         }\r
55         //\r
56         public void doFilter(INyARRaster i_input_a,INyARRaster i_input_b, INyARRaster i_output) throws NyARException\r
57         {\r
58                 assert (i_input_a.getSize().isEqualSize(i_output.getSize()) == true);\r
59                 assert (i_input_b.getSize().isEqualSize(i_output.getSize()) == true);\r
60                 this._dofilterimpl.doFilter(i_input_a.getBufferReader(),i_input_b.getBufferReader(),i_output.getBufferReader(),i_output.getSize());\r
61         }\r
62         \r
63         abstract class IdoFilterImpl\r
64         {\r
65                 int[] _window_ref;\r
66                 public abstract void doFilter(INyARBufferReader i_input_a,INyARBufferReader i_input_b,INyARBufferReader i_output,NyARIntSize i_size) throws NyARException;\r
67                 \r
68         }\r
69         class IdoFilterImpl_INT1D_GRAY_8 extends IdoFilterImpl\r
70         {\r
71                 public void doFilter(INyARBufferReader i_input_a,INyARBufferReader i_input_b,INyARBufferReader i_output,NyARIntSize i_size) throws NyARException\r
72                 {\r
73                         int[] out_buf = (int[]) i_output.getBuffer();\r
74                         int[] in_buf1 = (int[]) i_input_a.getBuffer();\r
75                         int[] in_buf2 = (int[]) i_input_b.getBuffer();\r
76                         for(int i=i_size.h*i_size.w-1;i>=0;i--)\r
77                         {\r
78                                 out_buf[i]=(in_buf1[i]*in_buf2[i])>>8;\r
79                         }\r
80                         return;\r
81                 }\r
82         }       \r
83 }