OSDN Git Service

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