OSDN Git Service

[NyARToolKit for java]update document
[nyartoolkit-and/nyartoolkit-and.git] / lib / src / jp / nyatla / nyartoolkit / core / raster / NyARRaster.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 /**\r
37  * このクラスは、指定形式のバッファを持つインスタンスを生成します。\r
38  * <p>対応しているバッファ形式は以下の通りです。\r
39  * <ul>\r
40  * <li>{@link NyARBufferType#INT1D}\r
41  * <li>{@link NyARBufferType#INT1D_X8R8G8B8_32}\r
42  * <ul>\r
43  * </p>\r
44  *\r
45  */\r
46 public class NyARRaster extends NyARRaster_BasicClass\r
47 {\r
48         /** バッファオブジェクトの変数*/\r
49         protected Object _buf;\r
50         /** バッファオブジェクトがアタッチされていればtrue*/\r
51         protected boolean _is_attached_buffer;\r
52         /**\r
53          * コンストラクタです。\r
54          * 画像のサイズパラメータとバッファ形式を指定して、インスタンスを生成します。\r
55          * @param i_width\r
56          * ラスタのサイズ\r
57          * @param i_height\r
58          * ラスタのサイズ\r
59          * @param i_buffer_type\r
60          * ラスタの画素形式。\r
61          * {@link NyARBufferType}に定義された定数値を指定してください。\r
62          * 指定できる値は、クラスの説明を見てください。\r
63          * @param i_is_alloc\r
64          * バッファを外部参照にするかのフラグ値。\r
65          * trueなら内部バッファ、falseなら外部バッファを使用します。\r
66          * falseの場合、初期のバッファはnullになります。インスタンスを生成したのちに、{@link #wrapBuffer}を使って割り当ててください。\r
67          * @throws NyARException\r
68          */\r
69         public NyARRaster(int i_width, int i_height,int i_buffer_type,boolean i_is_alloc) throws NyARException\r
70         {\r
71                 super(i_width,i_height,i_buffer_type);\r
72                 if(!initInstance(this._size,i_buffer_type,i_is_alloc)){\r
73                         throw new NyARException();\r
74                 }\r
75                 return;\r
76         }       \r
77         /**\r
78          * コンストラクタです。\r
79          * 画像のサイズパラメータとバッファ形式を指定して、インスタンスを生成します。\r
80          * @param i_width\r
81          * ラスタのサイズ\r
82          * @param i_height\r
83          * ラスタのサイズ\r
84          * @param i_buffer_type\r
85          * ラスタの画素形式。\r
86          * {@link NyARBufferType}に定義された定数値を指定してください。\r
87          * 指定できる値は、クラスの説明を見てください。\r
88          * @throws NyARException\r
89          */\r
90         public NyARRaster(int i_width, int i_height,int i_buffer_type) throws NyARException\r
91         {\r
92                 super(i_width,i_height,i_buffer_type);\r
93                 if(!initInstance(this._size,i_buffer_type,true)){\r
94                         throw new NyARException();\r
95                 }\r
96                 return;\r
97         }\r
98         /**\r
99          * このクラスの初期化シーケンスです。コンストラクタから呼び出します。\r
100          * @param i_size\r
101          * ラスタサイズ\r
102          * @param i_buf_type\r
103          * バッファ形式\r
104          * @param i_is_alloc\r
105          * バッファ参照方法値\r
106          * @return\r
107          * 初期化に成功するとtrueを返します。\r
108          */\r
109         protected boolean initInstance(NyARIntSize i_size,int i_buf_type,boolean i_is_alloc)\r
110         {\r
111                 switch(i_buf_type)\r
112                 {\r
113                         case NyARBufferType.INT1D:\r
114                         case NyARBufferType.INT1D_X8R8G8B8_32:\r
115                                 this._buf=i_is_alloc?new int[i_size.w*i_size.h]:null;\r
116                                 break;\r
117                                 \r
118                         default:\r
119                                 return false;\r
120                 }\r
121                 this._is_attached_buffer=i_is_alloc;\r
122                 return true;\r
123         }\r
124         /**\r
125          * この関数は、ラスタのバッファへの参照値を返します。\r
126          * バッファの形式は、コンストラクタに指定した形式と同じです。\r
127          */             \r
128         public Object getBuffer()\r
129         {\r
130                 return this._buf;\r
131         }\r
132         /**\r
133          * インスタンスがバッファを所有するかを返します。\r
134          * コンストラクタでi_is_allocをfalseにしてラスタを作成した場合、\r
135          * バッファにアクセスするまえに、バッファの有無をこの関数でチェックしてください。\r
136          */     \r
137         public boolean hasBuffer()\r
138         {\r
139                 return this._buf!=null;\r
140         }\r
141         /**\r
142          * この関数は、ラスタに外部参照バッファをセットします。\r
143          * 外部参照バッファを持つインスタンスでのみ使用できます。内部参照バッファを持つインスタンスでは使用できません。\r
144          */     \r
145         public void wrapBuffer(Object i_ref_buf) throws NyARException\r
146         {\r
147                 assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。\r
148                 this._buf=i_ref_buf;\r
149         }\r
150 }