OSDN Git Service

[TAG]NyARToolkit for Java 2.4.2
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / src / jp / nyatla / nyartoolkit / core / raster / NyARGrayscaleRaster.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.raster;\r
32 \r
33 import jp.nyatla.nyartoolkit.NyARException;\r
34 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
35 import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;\r
36 import jp.nyatla.nyartoolkit.core.types.*;\r
37 \r
38 public final class NyARGrayscaleRaster extends NyARRaster_BasicClass\r
39 {\r
40 \r
41         protected int[] _ref_buf;\r
42         private INyARBufferReader _buffer_reader;\r
43         \r
44         public NyARGrayscaleRaster(int i_width, int i_height)\r
45         {\r
46                 super(new NyARIntSize(i_width,i_height));\r
47                 this._ref_buf = new int[i_height*i_width];\r
48                 this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
49         }\r
50         public INyARBufferReader getBufferReader()\r
51         {\r
52                 return this._buffer_reader;\r
53         }\r
54         /**\r
55          * 4近傍の画素ベクトルを取得します。\r
56          * 0,1,0\r
57          * 1,x,1\r
58          * 0,1,0\r
59          * @param i_raster\r
60          * @param x\r
61          * @param y\r
62          * @param o_v\r
63          */\r
64         public void getPixelVector4(int x,int y,NyARIntPoint2d o_v)\r
65         {\r
66                 int[] buf=this._ref_buf;\r
67                 int w=this._size.w;\r
68                 int idx=w*y+x;\r
69                 o_v.x=buf[idx+1]-buf[idx-1];\r
70                 o_v.y=buf[idx+w]-buf[idx-w];\r
71         }\r
72         /**\r
73          * 8近傍画素ベクトル\r
74          * 1,2,1\r
75          * 2,x,2\r
76          * 1,2,1\r
77          * @param i_raster\r
78          * @param x\r
79          * @param y\r
80          * @param o_v\r
81          */\r
82         public void getPixelVector8(int x,int y,NyARIntPoint2d o_v)\r
83         {\r
84                 int[] buf=this._ref_buf;\r
85                 NyARIntSize s=this._size;\r
86                 int idx_0 =s.w*y+x;\r
87                 int idx_p1=idx_0+s.w;\r
88                 int idx_m1=idx_0-s.w;\r
89                 int b=buf[idx_m1-1];\r
90                 int d=buf[idx_m1+1];\r
91                 int h=buf[idx_p1-1];\r
92                 int f=buf[idx_p1+1];\r
93                 o_v.x=buf[idx_0+1]-buf[idx_0-1]+(d-b+f-h)/2;\r
94                 o_v.y=buf[idx_p1]-buf[idx_m1]+(f-d+h-b)/2;\r
95         }\r
96         \r
97         public void copyFrom(NyARGrayscaleRaster i_input) throws NyARException\r
98         {\r
99                 int[] out_buf = (int[])this._ref_buf;\r
100                 int[] in_buf = (int[]) i_input._ref_buf;\r
101                 System.arraycopy(in_buf,0,out_buf,0,this._size.h*this._size.w);\r
102                 return;\r
103         }       \r
104         \r
105 }\r