OSDN Git Service

[backup]NyARToolkit
[nyartoolkit-and/nyartoolkit-and.git] / trunk / sample / sandbox / jp / nyatla / nyartoolkit / utils / j2se / NyARRGBRaster_BufferedImage.java
index ad4264b..3e5e4c4 100644 (file)
@@ -3,46 +3,65 @@ package jp.nyatla.nyartoolkit.utils.j2se;
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
+\r
+import java.awt.color.ColorSpace;\r
 import java.awt.image.BufferedImage;\r
 \r
 \r
-public class NyARRGBRaster_BufferedImage implements INyARRgbRaster\r
+public class NyARRGBRaster_BufferedImage extends NyARRgbRaster_BasicClass\r
 {\r
-       protected INyARRgbPixelReader _reader;\r
-       protected INyARBufferReader _buffer_reader;     \r
-       final protected NyARIntSize _size;\r
-       final public int getWidth()\r
+       private INyARRgbPixelReader _reader;\r
+       private BufferedImage _buf; \r
+       \r
+       /**\r
+        * バッファオブジェクトがアタッチされていればtrue\r
+        */\r
+       protected boolean _is_attached_buffer;\r
+       public NyARRGBRaster_BufferedImage(int i_width, int i_height,boolean i_is_alloc) throws NyARException\r
        {\r
-               return this._size.w;\r
+               super( new NyARIntSize(i_width,i_height),INyARRaster.BUFFERFORMAT_OBJECT_Java_BufferedImage);\r
+               if(!initInstance(this._size,i_is_alloc)){\r
+                       throw new NyARException();\r
+               }\r
        }\r
-\r
-       final public int getHeight()\r
+       public NyARRGBRaster_BufferedImage(int i_width, int i_height) throws NyARException\r
        {\r
-               return this._size.h;\r
+               super( new NyARIntSize(i_width,i_height),INyARRaster.BUFFERFORMAT_OBJECT_Java_BufferedImage);\r
+               if(!initInstance(this._size,true)){\r
+                       throw new NyARException();\r
+               }\r
        }\r
+       protected boolean initInstance(NyARIntSize i_size,boolean i_is_alloc)\r
+       {\r
+               this._buf=i_is_alloc?new BufferedImage(i_size.w,i_size.h, ColorSpace.TYPE_RGB):null;\r
+               this._reader=new PixelReader((BufferedImage)this._buf);\r
+               this._is_attached_buffer=i_is_alloc;\r
+               return true;\r
+       }       \r
+       \r
 \r
-       final public NyARIntSize getSize()\r
+       public INyARRgbPixelReader getRgbPixelReader() throws NyARException\r
        {\r
-               return this._size;\r
+               return this._reader;\r
        }\r
-       /**\r
-        * i_imageをラップするRGBラスタを定義する。\r
-        * @param i_image\r
-        */\r
-       protected NyARRGBRaster_BufferedImage(BufferedImage i_image)\r
+       public Object getBuffer()\r
        {\r
-               this._buffer_reader=new NyARBufferReader(i_image,INyARBufferReader.BUFFERFORMAT_OBJECT_Java_BufferedImage);\r
-               this._reader=new PixelReader(i_image);\r
-               this._size= new NyARIntSize(i_image.getWidth(),i_image.getHeight());\r
+               return this._buf;\r
        }\r
-       public INyARRgbPixelReader getRgbPixelReader() throws NyARException\r
+       public boolean hasBuffer()\r
        {\r
-               return this._reader;\r
+               return this._buf!=null;\r
        }\r
-       public INyARBufferReader getBufferReader()\r
+       public void wrapBuffer(Object i_ref_buf) throws NyARException\r
        {\r
-               return this._buffer_reader;\r
+               assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。\r
+               BufferedImage buf=(BufferedImage)i_ref_buf;\r
+               assert(buf.getWidth()==this._size.w && buf.getHeight()==this._size.h);\r
+               this._buf=buf;\r
+               //ピクセルリーダーの参照バッファを切り替える。\r
+               this._reader.switchBuffer(i_ref_buf);\r
        }\r
        \r
        \r
@@ -89,6 +108,10 @@ public class NyARRGBRaster_BufferedImage implements INyARRgbRaster
                {\r
                        NyARException.notImplement();           \r
                }\r
+               public void switchBuffer(Object i_ref_buffer) throws NyARException\r
+               {\r
+                       this._ref_buf = (BufferedImage)i_ref_buffer;\r
+               }\r
                \r
        }       \r
        \r