OSDN Git Service

[backup]NyARToolKit
[nyartoolkit-and/nyartoolkit-and.git] / trunk / src / jp / nyatla / nyartoolkit / core / raster / NyARGrayscaleRaster.java
index 78f8553..21258c4 100644 (file)
@@ -30,6 +30,7 @@
  */\r
 package jp.nyatla.nyartoolkit.core.raster;\r
 \r
+import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
@@ -37,17 +38,37 @@ import jp.nyatla.nyartoolkit.core.types.*;
 public final class NyARGrayscaleRaster extends NyARRaster_BasicClass\r
 {\r
 \r
-       protected int[] _ref_buf;\r
-       private INyARBufferReader _buffer_reader;\r
-       \r
-       public NyARGrayscaleRaster(int i_width, int i_height)\r
+       protected Object _buf;\r
+       protected INyARBufferReader _buffer_reader;\r
+       public NyARGrayscaleRaster(int i_width, int i_height) throws NyARException\r
        {\r
                super(new NyARIntSize(i_width,i_height));\r
-               this._ref_buf = new int[i_height*i_width];\r
-               this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
+               if(!initInstance(this._size,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8)){\r
+                       throw new NyARException();\r
+               }\r
+       }       \r
+       public NyARGrayscaleRaster(int i_width, int i_height,int i_raster_type) throws NyARException\r
+       {\r
+               super(new NyARIntSize(i_width,i_height));\r
+               if(!initInstance(this._size,i_raster_type)){\r
+                       throw new NyARException();\r
+               }\r
        }\r
        public INyARBufferReader getBufferReader()\r
        {\r
                return this._buffer_reader;\r
        }\r
+       protected boolean initInstance(NyARIntSize i_size,int i_buf_type)\r
+       {\r
+               switch(i_buf_type)\r
+               {\r
+                       case INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8:\r
+                               this._buf = new int[i_size.w*i_size.h];\r
+                               break;\r
+                       default:\r
+                               return false;\r
+               }\r
+               this._buffer_reader=new NyARBufferReader(this._buf,i_buf_type);\r
+               return true;\r
+       }\r
 }\r