OSDN Git Service

[tag]NyARToolkit/2.5.1
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.5.1 / 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.types.*;\r
35 \r
36 public class NyARGrayscaleRaster extends NyARRaster_BasicClass\r
37 {\r
38 \r
39         protected Object _buf;\r
40         /**\r
41          * バッファオブジェクトがアタッチされていればtrue\r
42          */\r
43         protected boolean _is_attached_buffer;\r
44 \r
45         public NyARGrayscaleRaster(int i_width, int i_height) throws NyARException\r
46         {\r
47                 super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_GRAY_8);\r
48                 if(!initInstance(this._size,NyARBufferType.INT1D_GRAY_8,true)){\r
49                         throw new NyARException();\r
50                 }\r
51         }       \r
52         public NyARGrayscaleRaster(int i_width, int i_height,boolean i_is_alloc) throws NyARException\r
53         {\r
54                 super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D_GRAY_8);\r
55                 if(!initInstance(this._size,NyARBufferType.INT1D_GRAY_8,i_is_alloc)){\r
56                         throw new NyARException();\r
57                 }\r
58         }\r
59         /**\r
60          * @param i_width\r
61          * @param i_height\r
62          * @param i_raster_type\r
63          * NyARBufferTypeに定義された定数値を指定してください。\r
64          * @param i_is_alloc\r
65          * @throws NyARException\r
66          */\r
67         public NyARGrayscaleRaster(int i_width, int i_height,int i_raster_type,boolean i_is_alloc) throws NyARException\r
68         {\r
69                 super(new NyARIntSize(i_width,i_height),i_raster_type);\r
70                 if(!initInstance(this._size,i_raster_type,i_is_alloc)){\r
71                         throw new NyARException();\r
72                 }\r
73         }\r
74         protected boolean initInstance(NyARIntSize i_size,int i_buf_type,boolean i_is_alloc)\r
75         {\r
76                 switch(i_buf_type)\r
77                 {\r
78                         case NyARBufferType.INT1D_GRAY_8:\r
79                                 this._buf =i_is_alloc?new int[i_size.w*i_size.h]:null;\r
80                                 break;\r
81                         default:\r
82                                 return false;\r
83                 }\r
84                 this._is_attached_buffer=i_is_alloc;\r
85                 return true;\r
86         }\r
87         public Object getBuffer()\r
88         {\r
89                 return this._buf;\r
90         }\r
91         /**\r
92          * インスタンスがバッファを所有するかを返します。\r
93          * コンストラクタでi_is_allocをfalseにしてラスタを作成した場合、\r
94          * バッファにアクセスするまえに、バッファの有無をこの関数でチェックしてください。\r
95          * @return\r
96          */\r
97         public boolean hasBuffer()\r
98         {\r
99                 return this._buf!=null;\r
100         }\r
101         public void wrapBuffer(Object i_ref_buf)\r
102         {\r
103                 assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。\r
104                 this._buf=i_ref_buf;\r
105         }       \r
106 }\r