OSDN Git Service

[backup]NyARToolkit
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / core / raster / NyARRaster.java
index 540a3bb..98f74cd 100644 (file)
@@ -39,32 +39,67 @@ import jp.nyatla.nyartoolkit.core.types.*;
  */\r
 public final class NyARRaster extends NyARRaster_BasicClass\r
 {\r
-       protected NyARBufferReader _reader;\r
        protected Object _buf;\r
-       \r
-       public NyARRaster(NyARIntSize i_size,int i_buf_type) throws NyARException\r
+       protected int _buf_type;\r
+       /**\r
+        * バッファオブジェクトがアタッチされていればtrue\r
+        */\r
+       protected boolean _is_attached_buffer;\r
+       /**\r
+        * 指定したバッファタイプのラスタを作成します。\r
+        * @param i_width\r
+        * @param i_height\r
+        * @param i_buffer_type\r
+        * @param i_is_alloc\r
+        * @throws NyARException\r
+        */\r
+       public NyARRaster(int i_width, int i_height,int i_buffer_type,boolean i_is_alloc) throws NyARException\r
        {\r
-               super(i_size);\r
-               if(!initInstance(i_size,i_buf_type)){\r
+               super(new NyARIntSize(i_width,i_height),i_buffer_type);\r
+               if(!initInstance(this._size,i_buffer_type,i_is_alloc)){\r
                        throw new NyARException();\r
                }\r
                return;\r
-       }\r
-       protected boolean initInstance(NyARIntSize i_size,int i_buf_type)\r
+       }       \r
+\r
+       public NyARRaster(int i_width, int i_height,int i_buffer_type) throws NyARException\r
+       {\r
+               super(new NyARIntSize(i_width,i_height),i_buffer_type);\r
+               if(!initInstance(this._size,i_buffer_type,true)){\r
+                       throw new NyARException();\r
+               }\r
+               return;\r
+       }       \r
+       protected boolean initInstance(NyARIntSize i_size,int i_buf_type,boolean i_is_alloc)\r
        {\r
                switch(i_buf_type)\r
                {\r
-                       case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
-                               this._buf=new int[i_size.w*i_size.h];\r
+                       case INyARRaster.BUFFERFORMAT_INT1D_X8R8G8B8_32:\r
+                               this._buf=i_is_alloc?new int[i_size.w*i_size.h]:null;\r
                                break;\r
                        default:\r
                                return false;\r
                }\r
-               this._reader=new NyARBufferReader(this._buf,i_buf_type);\r
+               this._is_attached_buffer=i_is_alloc;\r
                return true;\r
        }\r
-       public INyARBufferReader getBufferReader()\r
+       public Object getBuffer()\r
        {\r
-               return this._reader;\r
-       }       \r
+               return this._buf;\r
+       }\r
+       /**\r
+        * インスタンスがバッファを所有するかを返します。\r
+        * コンストラクタでi_is_allocをfalseにしてラスタを作成した場合、\r
+        * バッファにアクセスするまえに、バッファの有無をこの関数でチェックしてください。\r
+        * @return\r
+        */     \r
+       public boolean hasBuffer()\r
+       {\r
+               return this._buf!=null;\r
+       }\r
+       public void wrapBuffer(Object i_ref_buf) throws NyARException\r
+       {\r
+               assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。\r
+               this._buf=i_ref_buf;\r
+       }\r
 }
\ No newline at end of file