OSDN Git Service

[tag]NyARToolkit/2.5.1
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.5.1 / src / jp / nyatla / nyartoolkit / core / raster / rgb / NyARRgbRaster.java
1 package jp.nyatla.nyartoolkit.core.raster.rgb;\r
2 \r
3 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
4 import jp.nyatla.nyartoolkit.core.types.*;\r
5 import jp.nyatla.nyartoolkit.*;\r
6 import jp.nyatla.nyartoolkit.core.raster.*;\r
7 \r
8 public class NyARRgbRaster extends NyARRgbRaster_BasicClass\r
9 {\r
10         protected Object _buf;\r
11         protected INyARRgbPixelReader _reader;\r
12         /**\r
13          * バッファオブジェクトがアタッチされていればtrue\r
14          */\r
15         protected boolean _is_attached_buffer;\r
16         /**\r
17          * \r
18          * @param i_width\r
19          * @param i_height\r
20          * @param i_raster_type\r
21          * NyARBufferTypeに定義された定数値を指定してください。\r
22          * @param i_is_alloc\r
23          * @throws NyARException\r
24          */\r
25         public NyARRgbRaster(int i_width, int i_height,int i_raster_type,boolean i_is_alloc) throws NyARException\r
26         {\r
27                 super(new NyARIntSize(i_width,i_height),i_raster_type);\r
28                 if(!initInstance(this._size,i_raster_type,i_is_alloc)){\r
29                         throw new NyARException();\r
30                 }\r
31         }\r
32         /**\r
33          * \r
34          * @param i_width\r
35          * @param i_height\r
36          * @param i_raster_type\r
37          * NyARBufferTypeに定義された定数値を指定してください。\r
38          * @throws NyARException\r
39          */\r
40         public NyARRgbRaster(int i_width, int i_height,int i_raster_type) throws NyARException\r
41         {\r
42                 super(new NyARIntSize(i_width,i_height),i_raster_type);\r
43                 if(!initInstance(this._size,i_raster_type,true)){\r
44                         throw new NyARException();\r
45                 }\r
46         }\r
47         protected boolean initInstance(NyARIntSize i_size,int i_raster_type,boolean i_is_alloc)\r
48         {\r
49                 switch(i_raster_type)\r
50                 {\r
51                         case NyARBufferType.INT1D_X8R8G8B8_32:\r
52                                 this._buf=i_is_alloc?new int[i_size.w*i_size.h]:null;\r
53                                 this._reader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32((int[])this._buf,i_size);\r
54                                 break;\r
55                         case NyARBufferType.BYTE1D_B8G8R8X8_32:\r
56                                 this._buf=i_is_alloc?new byte[i_size.w*i_size.h*4]:null;\r
57                                 this._reader=new NyARRgbPixelReader_BYTE1D_B8G8R8X8_32((byte[])this._buf,i_size);\r
58                                 break;\r
59                         case NyARBufferType.BYTE1D_R8G8B8_24:\r
60                                 this._buf=i_is_alloc?new byte[i_size.w*i_size.h*3]:null;\r
61                                 this._reader=new NyARRgbPixelReader_BYTE1D_R8G8B8_24((byte[])this._buf,i_size);\r
62                                 break;\r
63                         default:\r
64                                 return false;\r
65                 }\r
66                 this._is_attached_buffer=i_is_alloc;\r
67                 return true;\r
68         }\r
69         public INyARRgbPixelReader getRgbPixelReader() throws NyARException\r
70         {\r
71                 return this._reader;\r
72         }\r
73         public Object getBuffer()\r
74         {\r
75                 return this._buf;\r
76         }\r
77         public boolean hasBuffer()\r
78         {\r
79                 return this._buf!=null;\r
80         }\r
81         public void wrapBuffer(Object i_ref_buf) throws NyARException\r
82         {\r
83                 assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。\r
84                 this._buf=i_ref_buf;\r
85                 //ピクセルリーダーの参照バッファを切り替える。\r
86                 this._reader.switchBuffer(i_ref_buf);\r
87         }\r
88 }\r