OSDN Git Service

1.JMFライブラリのリファクタリング。
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 17 Jan 2009 15:29:15 +0000 (15:29 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 17 Jan 2009 15:29:15 +0000 (15:29 +0000)
 JMFのキャプチャデバイスを、デバイスリストで扱うようにした。

2.JMFのYUV対応
 YUVをRGBに自動的に変換するシーケンスを追加

3.キャプチャ方式の切り替え
 JmfCameraCaptureクラスの廃止と、JmfCaptureDeviceへの切り替え

4.java3Dサンプル・ユーティリティのバグ修正

24 files changed:
readme.ja.txt
sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java
sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrSample.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/JavaSimpleLite_Quad.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatFitVecCalculator.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java
src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java [new file with mode: 0644]
src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java

index c08e897..a39ec7d 100644 (file)
@@ -1,7 +1,7 @@
-ARToolKit Java class library NyARToolkit.\r
+ARToolKit Java class library NyARToolkit.\r
 Copyright (C)2008 R.Iizuka\r
 \r
-version 2.1.0\r
+version 2.2.0\r
 \r
 http://nyatla.jp/nyartoolkit/\r
 airmail(at)ebony.plala.or.jp\r
@@ -10,14 +10,14 @@ airmail(at)ebony.plala.or.jp
 \r
 \r
 \r
-・NyARToolkit/2.1\r
+・NyARToolkit/2.2\r
 \r
 NyARToolkitは、Pure Javaで実装したARToolKitクラスライブラリです。\r
 \r
 ARToolKit 2.72.1をベースに構築されています。\r
 \r
-NyARToolkit/2.0系は、NyARToolkit/1.xと比較して構造的な最適化がされており\r
-可読性と分離性が向上しています。\r
+NyARToolkit/2.0系はNyARToolkit/1.xと比較して、処理速度と可読性\r
+モジュールの分離性が向上しています。\r
 \r
 \r
 \r
@@ -35,7 +35,7 @@ http://www.hitl.washington.edu/artoolkit/
 \r
  -ARToolKitと同等な処理シーケンスを、クラスベースで再構築してあります。\r
 \r
-  -æ§\8bé\80 ç\9a\84ã\81ªæ\9c\80é\81©å\8c\96ã\81\8cã\81\95ã\82\8cã\81¦ã\81\8aり、ARToolKitと比較して可読性に優れています。\r
+  -æ§\8bé\80 ç\9a\84ã\81ªæ\9c\80é\81©å\8c\96ã\81«ã\82\88り、ARToolKitと比較して可読性に優れています。\r
 \r
  -座標変換の演算性能が1.5倍ほど高速です。(JIT有効時)複数マーカー取り扱い時は、\r
   オリジナルよりも良い成績が得られます。\r
@@ -69,8 +69,8 @@ http://www.hitl.washington.edu/artoolkit/
 NyARJMF/CaptureQT/NyARJog/NyARJ3dは、下位のキャプチャモジュール\r
 や3Dライブラリを使いやすくするためのラッパークラス群です。\r
 \r
-これらとNyARToolkitは疎結合になっており、インタフェイスをあわせる\r
-ことで、自作モジュール等との差し替えが出来ます。\r
+各モジュールとNyARToolkitは容易に分離可能であり、個々を単独で\r
+使用することも可能です。\r
 \r
 \r
 \r
@@ -100,11 +100,9 @@ http://www.apple.com/quicktime/qtjava/
 2.eclipseで空のワークスペースを作成し、sample,src,src.utils\r
   ディレクトリをインポートしてください。\r
 \r
-srcにはNyARToolkit本体、src.utilsにはキャプチャや3Dライブラリとの\r
-インタフェイスクラス群、sampleにはこれらを組み合わせた動作する\r
-サンプルプログラムがあります。\r
-\r
-\r
+srcディレクトリには、NyARToolkit本体(計算クラス群)があります。\r
+src.utilsディレクトリには、カメラキャプチャクラスや、3Dライブラリ用のラッパークラス群があります。\r
+sampleディレクトリには、NyARToolkitを使用したサンプルプログラムがあります。\r
 \r
 \r
 ・プロジェクトの説明\r
index f19612f..89769ef 100644 (file)
@@ -61,14 +61,19 @@ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
 
        private NyARTransMatResult _trans_mat_result = new NyARTransMatResult();
 
-       public NyarToolkitLinkTest() throws NyARException, NyARException
+       public NyarToolkitLinkTest() throws NyARException
        {
                setTitle("JmfCaptureTest");
                setBounds(0, 0, 320 + 64, 240 + 64);
                //キャプチャの準備
                JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
                _capture=devlist.getDevice(0);
-               _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f);
+               //JmfNyARRaster_RGBはYUVよりもRGBで高速に動作します。
+               if(!_capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f)){
+                       if(!_capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320, 240,15f)){
+                               throw new NyARException("キャプチャフォーマットが見つかりません");
+                       }               
+               }
                _capture.setOnCapture(this);
 
                //NyARToolkitの準備
@@ -79,7 +84,7 @@ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
                this._nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0);
                ar_code.loadARPattFromFile(CARCODE_FILE);
                //キャプチャイメージ用のラスタを準備
-               this._raster = new JmfNyARRaster_RGB(320, 240);
+               this._raster = new JmfNyARRaster_RGB(320, 240,_capture.getCaptureFormat());
                return;
        }
 
index e171113..022a7b3 100644 (file)
@@ -135,27 +135,29 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
 \r
        public void init(GLAutoDrawable drawable)\r
        {\r
-               _gl = drawable.getGL();\r
-               _gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
+               this._gl = drawable.getGL();\r
+               this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
                //NyARToolkitの準備\r
                try {\r
                        //キャプチャの準備\r
                        JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
-                       _capture=devlist.getDevice(0);\r
-                       _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,SCREEN_X, SCREEN_Y,15f);\r
-                       _capture.setOnCapture(this);\r
+                       this._capture=devlist.getDevice(0);\r
+                       if(!this._capture.setCaptureFormat(SCREEN_X, SCREEN_Y,15f)){\r
+                               throw new Exception();\r
+                       }\r
+                       this._capture.setOnCapture(this);\r
                        //NyARToolkitの準備\r
-                       _ar_param = new NyARParam();\r
+                       this._ar_param = new NyARParam();\r
                        NyARCode ar_code = new NyARCode(16, 16);\r
-                       _ar_param.loadARParamFromFile(PARAM_FILE);\r
-                       _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
-                       _nya = new NyARSingleDetectMarker(_ar_param, ar_code, 80.0);\r
-                       _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
+                       this._ar_param.loadARParamFromFile(PARAM_FILE);\r
+                       this._ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
+                       this._nya = new NyARSingleDetectMarker(this._ar_param, ar_code, 80.0);\r
+                       this._nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                        ar_code.loadARPattFromFile(CARCODE_FILE);\r
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
-                       _cap_image = new GLNyARRaster_RGB(_ar_param);\r
+                       _cap_image = new GLNyARRaster_RGB(this._ar_param,this._capture.getCaptureFormat());\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
@@ -227,7 +229,7 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
        {\r
                try {\r
                        synchronized (_cap_image) {\r
-                               _cap_image.setBuffer(i_buffer, true);\r
+                               _cap_image.setBuffer(i_buffer);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
index 19ce1e3..44ed5da 100644 (file)
@@ -144,7 +144,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                        //キャプチャの準備\r
                        JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
                        _capture=devlist.getDevice(0);\r
-                       _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,SCREEN_X, SCREEN_Y,15f);\r
+                       _capture.setCaptureFormat(SCREEN_X, SCREEN_Y,15f);\r
                        _capture.setOnCapture(this);                    \r
                        //NyARToolkitの準備\r
                        _ar_param = new NyARParam();\r
@@ -163,7 +163,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
-                       _cap_image = new GLNyARRaster_RGB(_ar_param);\r
+                       _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
@@ -241,7 +241,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
        {\r
                try {\r
                        synchronized (_cap_image) {\r
-                               _cap_image.setBuffer(i_buffer, true);\r
+                               _cap_image.setBuffer(i_buffer);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
index 72720fd..1cbd761 100644 (file)
@@ -55,7 +55,7 @@ public class SingleQrSample implements GLEventListener, JmfCaptureListener
 \r
        private GLNyARRaster_RGB _cap_image;\r
 \r
-       private JmfCameraCapture _capture;\r
+       private JmfCaptureDevice _capture;\r
 \r
        private GL _gl;\r
        private NyARGLUtil _glnya;\r
@@ -138,8 +138,11 @@ public class SingleQrSample implements GLEventListener, JmfCaptureListener
                //NyARToolkitの準備\r
                try {\r
                        //キャプチャの準備\r
-                       _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-                       _capture.setCaptureListener(this);\r
+                       JmfCaptureDeviceList list=new JmfCaptureDeviceList();\r
+                       _capture=list.getDevice(0);\r
+                       _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);\r
+                       _capture.setOnCapture(this);\r
+                       \r
                        //NyARToolkitの準備\r
                        _ar_param = new NyARParam();\r
                        NyARCode ar_code = new NyARCode(16, 16);\r
@@ -151,7 +154,7 @@ public class SingleQrSample implements GLEventListener, JmfCaptureListener
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
-                       _cap_image = new GLNyARRaster_RGB(_ar_param);\r
+                       _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
@@ -223,7 +226,7 @@ public class SingleQrSample implements GLEventListener, JmfCaptureListener
        {\r
                try {\r
                        synchronized (_cap_image) {\r
-                               _cap_image.setBuffer(i_buffer, true);\r
+                               _cap_image.setBuffer(i_buffer);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
index b062adb..768925f 100644 (file)
@@ -34,17 +34,19 @@ public class SingleQrTest extends Frame implements JmfCaptureListener
 
        private JmfNyARRaster_RGB _raster;
 
-       private JmfCameraCapture capture;
+       private JmfCaptureDevice capture;
        private NyARParam ap;
        public SingleQrTest() throws NyARException, NyARException
        {
                setBounds(0, 0, 640 + 64, 720 + 64);
                // キャプチャの準備
-               capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
-               capture.setCaptureListener(this);
+               JmfCaptureDeviceList list=new JmfCaptureDeviceList();
+               capture=list.getDevice(0);
+               capture.setCaptureFormat(320,240,30.0f);
+               capture.setOnCapture(this);
 
                // キャプチャイメージ用のラスタを準備
-               this._raster = new JmfNyARRaster_RGB(320, 240);
+               this._raster = new JmfNyARRaster_RGB(320, 240,capture.getCaptureFormat());
                
                // AR用カメラパラメタファイルをロード
                ap = new NyARParam();
index d84ee4f..925ecdd 100644 (file)
@@ -42,8 +42,7 @@ import com.sun.opengl.util.Animator;
 import jp.nyatla.nyartoolkit.core.NyARCode;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 import jp.nyatla.nyartoolkit.jogl.utils.*;\r
 /**\r
  * simpleLiteと同じようなテストプログラム\r
@@ -65,7 +64,7 @@ public class JavaSimpleLite_Quad implements GLEventListener, JmfCaptureListener
 \r
        private GLNyARRaster_RGB _cap_image;\r
 \r
-       private JmfCameraCapture _capture;\r
+       private JmfCaptureDevice _capture;\r
 \r
        private GL _gl;\r
 \r
@@ -148,8 +147,10 @@ public class JavaSimpleLite_Quad implements GLEventListener, JmfCaptureListener
                //NyARToolkitの準備\r
                try {\r
                        //キャプチャの準備\r
-                       _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-                       _capture.setCaptureListener(this);\r
+                       JmfCaptureDeviceList list=new JmfCaptureDeviceList();\r
+                       _capture=list.getDevice(0);\r
+                       _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);\r
+                       _capture.setOnCapture(this);\r
                        //NyARToolkitの準備\r
                        _ar_param = new NyARParam();\r
                        NyARCode ar_code = new NyARCode(16, 16);\r
@@ -161,7 +162,7 @@ public class JavaSimpleLite_Quad implements GLEventListener, JmfCaptureListener
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
-                       _cap_image = new GLNyARRaster_RGB(_ar_param);\r
+                       _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
@@ -233,7 +234,7 @@ public class JavaSimpleLite_Quad implements GLEventListener, JmfCaptureListener
        {\r
                try {\r
                        synchronized (_cap_image) {\r
-                               _cap_image.setBuffer(i_buffer, true);\r
+                               _cap_image.setBuffer(i_buffer);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
index b08e500..cc9a3fa 100644 (file)
@@ -42,8 +42,7 @@ import com.sun.opengl.util.Animator;
 import jp.nyatla.nyartoolkit.core.NyARCode;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 import jp.nyatla.nyartoolkit.jogl.utils.*;\r
 /**\r
  * simpleLiteと同じようなテストプログラム\r
@@ -65,7 +64,7 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
 \r
        private GLNyARRaster_RGB _cap_image;\r
 \r
-       private JmfCameraCapture _capture;\r
+       private JmfCaptureDevice _capture;\r
 \r
        private GL _gl;\r
 \r
@@ -149,8 +148,10 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
                //NyARToolkitの準備\r
                try {\r
                        //キャプチャの準備\r
-                       _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-                       _capture.setCaptureListener(this);\r
+                       JmfCaptureDeviceList list=new JmfCaptureDeviceList();\r
+                       _capture=list.getDevice(0);\r
+                       _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);\r
+                       _capture.setOnCapture(this);\r
                        //NyARToolkitの準備\r
                        _ar_param = new NyARParam();\r
                        NyARCode ar_code = new NyARCode(16, 16);\r
@@ -162,7 +163,7 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
-                       _cap_image = new GLNyARRaster_RGB(_ar_param);\r
+                       _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
@@ -234,7 +235,7 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
        {\r
                try {\r
                        synchronized (_cap_image) {\r
-                               _cap_image.setBuffer(i_buffer, true);\r
+                               _cap_image.setBuffer(i_buffer);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
index 02e910a..e8f2fdd 100644 (file)
@@ -31,7 +31,6 @@
  */\r
 package jp.nyatla.nyartoolkit.sandbox.x2;\r
 \r
-import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.*;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point2d;\r
index a378a52..e85dabc 100644 (file)
@@ -34,7 +34,6 @@ package jp.nyatla.nyartoolkit.sandbox.x2;
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point2d;\r
 import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point3d;\r
 \r
index f53c3e0..5a4feb8 100644 (file)
@@ -34,10 +34,7 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.labeling.*;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Linear;\r
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Point2d;\r
+import jp.nyatla.nyartoolkit.core2.types.*;\r
 import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;\r
 import jp.nyatla.nyartoolkit.core.*;\r
 \r
index 8102bb7..ed081b7 100644 (file)
@@ -35,8 +35,6 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.NyARSquare;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core2.types.*;\r
 \r
index c0821b0..b4ca5c9 100644 (file)
@@ -11,7 +11,7 @@ import javax.media.format.*;
 
 import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.jmf.utils.*;
-import jp.nyatla.nyartoolkit.sandbox.quadx2.NyARRasterFilter_ARTTh_Quad;
+import jp.nyatla.nyartoolkit.sandbox.quadx2.*;
 
 import jp.nyatla.nyartoolkit.core.*;
 
@@ -34,17 +34,19 @@ public class VisualTest extends Frame implements JmfCaptureListener
 
        private JmfNyARRaster_RGB _raster;
 
-       private JmfCameraCapture capture;
+       private JmfCaptureDevice capture;
        private NyARParam ap;
        public VisualTest() throws NyARException, NyARException
        {
                setBounds(0, 0, 640 + 64, 720 + 64);
                // キャプチャの準備
-               capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
-               capture.setCaptureListener(this);
+               JmfCaptureDeviceList list=new JmfCaptureDeviceList();
+               capture=list.getDevice(0);
+               capture.setCaptureFormat(320,240,30.0f);
+               capture.setOnCapture(this);
 
                // キャプチャイメージ用のラスタを準備
-               this._raster = new JmfNyARRaster_RGB(320, 240);
+               this._raster = new JmfNyARRaster_RGB(320, 240,capture.getCaptureFormat());
                
                // AR用カメラパラメタファイルをロード
                ap = new NyARParam();
index c793898..106cc58 100644 (file)
@@ -28,14 +28,14 @@ package jp.nyatla.nyartoolkit.java3d.utils;
 \r
 import java.awt.image.*;\r
 \r
-import javax.media.format.RGBFormat;\r
+import javax.media.format.VideoFormat;\r
 import javax.media.j3d.ImageComponent;\r
 import javax.media.j3d.ImageComponent2D;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
 import jp.nyatla.nyartoolkit.jmf.utils.*;\r
-\r
+import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
 /**\r
  * \r
  * このクラスは、Java3Dと互換性のあるNyARToolkitのラスタイメージを保持します。\r
@@ -57,20 +57,31 @@ public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB
         */\r
        public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
        {\r
-               //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。\r
-               synchronized (this) {\r
-                       //キャプチャデータをi2dのバッファにコピーする。(これ省略したいなあ…。)\r
-                       System.arraycopy((byte[]) i_buffer.getData(), 0, this.i2d_buf, 0, this.i2d_buf.length);\r
+               this._reader.changeBuffer(i_buffer);\r
+               synchronized (this){\r
+                       //キャプチャデータをi2dのバッファにコピーする。\r
+                       //現在はJmfNyARRaster_RGBでRGB画像がノーマライズされているので、\r
+                       //ここでもう一度flipする。(これ省略したいなあ…。)\r
+                       byte[] src=(byte[])this._reader.getBuffer();\r
+                       final int length = this._size.w * 3;\r
+                       int src_idx = 0;\r
+                       int dest_idx = (this._size.h - 1) * length;                     \r
+                       for (int i = 0; i < this._size.h; i++) {\r
+                               System.arraycopy(src,src_idx, this.i2d_buf, dest_idx, length);\r
+                               src_idx += length;\r
+                               dest_idx -= length;\r
+                       }\r
                }\r
-               int buffer_type = analyzeBufferType((RGBFormat) i_buffer.getFormat());\r
-               this._ref_buf = this.i2d_buf;\r
-               this._reader.changeBuffer(buffer_type, this._ref_buf);\r
+               return;\r
        }\r
 \r
-       public J3dNyARRaster_RGB(NyARParam i_cparam)\r
+       public J3dNyARRaster_RGB(NyARParam i_cparam,VideoFormat i_format) throws NyARException\r
        {\r
-               super(i_cparam.getScreenSize());\r
-\r
+               super(i_cparam.getScreenSize(),i_format);\r
+               //bufferdimageの種類を決める\r
+               if(this._reader.getBufferType()!=INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24){\r
+                       throw new NyARException();\r
+               }\r
                //RGBのラスタを作る。\r
                this.bufferd_image = new BufferedImage(this._size.w, this._size.h, BufferedImage.TYPE_3BYTE_BGR);\r
                i2d_buf = ((DataBufferByte) bufferd_image.getRaster().getDataBuffer()).getData();\r
index 0fa6532..5e86949 100644 (file)
@@ -66,9 +66,9 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener
                //キャプチャの準備\r
                JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
                this._capture=devlist.getDevice(0);\r
-               this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,scr_size.w, scr_size.h,15f);\r
+               this._capture.setCaptureFormat(scr_size.w, scr_size.h,15f);\r
                this._capture.setOnCapture(this);               \r
-               this._nya_raster = new J3dNyARRaster_RGB(this._cparam);\r
+               this._nya_raster = new J3dNyARRaster_RGB(this._cparam,this._capture.getCaptureFormat());\r
                this._nya = new NyARSingleDetectMarker(this._cparam, i_ar_code, i_marker_width);\r
                this._nya_behavior = new NyARBehavior(this._nya, this._nya_raster, i_rate);\r
        }\r
@@ -214,7 +214,12 @@ class NyARBehavior extends Behavior
                                        {\r
                                                final NyARTransMatResult src = this.trans_mat_result;\r
                                                related_nya.getTransmationMatrix(src);\r
-                                               Matrix4d matrix = new Matrix4d(src.m00, -src.m10, -src.m20, 0, -src.m01, src.m11, src.m21, 0, -src.m02, src.m12, src.m22, 0, -src.m03, src.m13, src.m23, 1);\r
+//                                             Matrix4d matrix = new Matrix4d(src.m00, -src.m10, -src.m20, 0, -src.m01, src.m11, src.m21, 0, -src.m02, src.m12, src.m22, 0, -src.m03, src.m13, src.m23, 1);\r
+                                               Matrix4d matrix = new Matrix4d(\r
+                                                               -src.m00, -src.m10, src.m20, 0,\r
+                                                               -src.m01, -src.m11, src.m21, 0,\r
+                                                               -src.m02, -src.m12, src.m22, 0,\r
+                                                          -src.m03,-src.m13, src.m23, 1);\r
                                                matrix.transpose();\r
                                                t3d = new Transform3D(matrix);\r
                                                if (trgroup != null) {\r
index 12cea7f..1156fe6 100644 (file)
@@ -2,19 +2,11 @@ package jp.nyatla.nyartoolkit.jmf.utils;
 \r
 import java.awt.Dimension;\r
 \r
-import javax.media.CaptureDeviceInfo;\r
-import javax.media.Format;\r
-import javax.media.IncompatibleSourceException;\r
-import javax.media.Manager;\r
-import javax.media.MediaLocator;\r
-import javax.media.Processor;\r
-import javax.media.ProcessorModel;\r
-import javax.media.control.FormatControl;\r
-import javax.media.format.VideoFormat;\r
-import javax.media.protocol.CaptureDevice;\r
-import javax.media.protocol.DataSource;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
+import javax.media.*;\r
+import javax.media.control.*;\r
+import javax.media.format.*;\r
+import javax.media.protocol.*;\r
+import jp.nyatla.nyartoolkit.*;\r
 \r
 public class JmfCaptureDevice\r
 {\r
@@ -22,11 +14,10 @@ public class JmfCaptureDevice
        private MonitorStream _jmf_monitor_stream;\r
        private Processor _jmf_processor;\r
        private CaptureDeviceInfo _info;\r
-       private Format _capture_format;\r
-       public static final String PIXEL_FORMAT_RGB = "RGB";\r
-       public static final String PIXEL_FORMAT_YUV = "YUV";\r
-       \r
-\r
+       private VideoFormat _capture_format;\r
+       private static final String[] _enc_str={"RGB","YUV"};   \r
+       public static final int PIXEL_FORMAT_RGB =0;// "RGB";\r
+       public static final int PIXEL_FORMAT_YUV =1;// "YUV";\r
        public JmfCaptureDevice(CaptureDeviceInfo i_capinfo) throws NyARException\r
        {\r
                this._info = i_capinfo;\r
@@ -34,12 +25,16 @@ public class JmfCaptureDevice
                return;\r
        }\r
 \r
+       /**\r
+        * サポートしているフォーマットの一覧を返します。\r
+        * @return\r
+        */\r
        public Format[] getSupportFormats()\r
        {\r
                return this._info.getFormats();\r
        }\r
 \r
-       public final Format getCaptureFormat()\r
+       public final VideoFormat getCaptureFormat()\r
        {\r
                return this._capture_format;\r
        }\r
@@ -50,7 +45,7 @@ public class JmfCaptureDevice
         */\r
        public void setCaptureFormat(int i_index)\r
        {\r
-               this._capture_format = this._info.getFormats()[i_index];\r
+               this._capture_format = (VideoFormat)this._info.getFormats()[i_index];\r
                return;\r
        }\r
        /**\r
@@ -64,16 +59,24 @@ public class JmfCaptureDevice
         * @return\r
         * 指定に成功するとTRUEを返します。失敗するとFALSEを返します。\r
         */     \r
-       public boolean setCaptureFormat(String i_encode, Dimension i_size, float i_rate) throws NyARException\r
+       protected boolean setCaptureFormat(int i_encode, Dimension i_size, float i_rate) throws NyARException\r
        {\r
-               if (this._jmf_processor != null) {\r
+               if (this._jmf_processor != null){\r
                        throw new NyARException();\r
                }\r
                Format[] formats = this._info.getFormats();\r
-               Format f = new VideoFormat(i_encode, i_size, Format.NOT_SPECIFIED, null, i_rate);\r
-               for (int i = 0; i < formats.length; i++) {\r
+               VideoFormat f = new VideoFormat(_enc_str[i_encode], i_size, Format.NOT_SPECIFIED, null, i_rate);\r
+               for (int i = 0; i < formats.length; i++){\r
                        if (formats[i].matches(f)) {\r
-                               f = formats[i].intersects(f);\r
+                               //[暫定実装]RGBの場合のみ、24bit-BGRAを強制する。他のフォーマットも取りたいときは要改造\r
+                               //これはMacOSのJMF等で問題が出るかもしれない。問題が出たら教えて下さい。\r
+                               if(formats[i] instanceof RGBFormat){\r
+                                       RGBFormat fmt_ref=(RGBFormat)formats[i];\r
+                                       if(fmt_ref.getBitsPerPixel()!=24 || fmt_ref.getBlueMask()!=1 || fmt_ref.getBlueMask()!=2 || fmt_ref.getRedMask()!=3){\r
+                                               continue;\r
+                                       }\r
+                               }\r
+                               f =(VideoFormat)formats[i].intersects(f);\r
                                this._capture_format = null;\r
                                this._capture_format = f;\r
                                return true;\r
@@ -82,11 +85,52 @@ public class JmfCaptureDevice
                //ない。\r
                return false;\r
        }\r
-       public boolean setCaptureFormat(String i_encode,int i_size_x,int i_size_y, float i_rate) throws NyARException\r
+       /**\r
+        * キャプチャ画像のエンコード、サイズ、レートを引数とするsetCaptureFormat関数です。\r
+        * @param i_encode\r
+        * PIXEL_FORMAT_XXXで定義される定数値を指定して下さい。\r
+        * @param i_size_x\r
+        * キャプチャする画像の横幅\r
+        * @param i_size_y\r
+        * キャプチャする画像の縦幅\r
+        * @param i_rate\r
+        * フレームレート\r
+        * @return\r
+        * 関数の実行結果を真偽値で返します。\r
+        * @throws NyARException\r
+        */     \r
+       public boolean setCaptureFormat(int i_encode,int i_size_x,int i_size_y, float i_rate) throws NyARException\r
        {\r
                return setCaptureFormat(i_encode,new Dimension(i_size_x,i_size_y),i_rate);\r
        }\r
        /**\r
+        * キャプチャ画像のサイズ、レートを引数とするsetCaptureFormat関数です。\r
+        * キャプチャ画像のエンコードは、RGB→YUVの順で検索します。\r
+        * @param i_size_x\r
+        * キャプチャする画像の横幅\r
+        * @param i_size_y\r
+        * キャプチャする画像の縦幅\r
+        * @param i_rate\r
+        * フレームレート\r
+        * @return\r
+        * 関数の実行結果を真偽値で返します。\r
+        * @throws NyARException\r
+        */\r
+       public boolean setCaptureFormat(int i_size_x,int i_size_y, float i_rate) throws NyARException\r
+       {\r
+               Dimension d=new Dimension(i_size_x,i_size_y);\r
+               if(setCaptureFormat(PIXEL_FORMAT_RGB,d,i_rate)){\r
+                       return true;\r
+               }\r
+               if(setCaptureFormat(PIXEL_FORMAT_YUV,d,i_rate)){\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       \r
+       \r
+       /**\r
         * 画像のキャプチャイベントを受信するリスナクラスを指定します。\r
         * @param i_listener\r
         * リスナークラス\r
index 85d7eb0..4ce5937 100644 (file)
@@ -63,6 +63,7 @@ public class JmfCaptureDeviceList
        /**\r
         * 使用できるキャプチャデバイスの数を数える\r
         * @return\r
+        * キャプチャデバイスの数を返却する。\r
         */\r
        public int getCount()\r
        {\r
@@ -86,7 +87,7 @@ public class JmfCaptureDeviceList
                        JmfCaptureDeviceList j = new JmfCaptureDeviceList();\r
                        System.out.println(j.getCount());\r
                        JmfCaptureDevice d = j.getDevice(0);\r
-                       d.setCaptureFormat("YUV", new Dimension(320, 240), 15.0f);\r
+                       d.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB, new Dimension(320, 240), 15.0f);\r
 //                     YUVFormat f=(YUVFormat)d.getCaptureFormat();\r
                        d.start();\r
                        d.stop();\r
index efdf0ef..b17aeef 100644 (file)
 package jp.nyatla.nyartoolkit.jmf.utils;\r
 \r
 import javax.media.format.*;\r
+import javax.media.*;\r
 import java.awt.Dimension;\r
+import com.sun.media.codec.video.colorspace.*;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+\r
+\r
 /**\r
- * \r
- * RGB形式のJMFバッファをラップするNyARRasterです。\r
- * JMFから得たラスタデータのピクセル並び順を考慮します。\r
- *\r
+ * RGB24フォーマットのデータを扱うピクセルリーダ\r
  */\r
-public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass\r
+class NyARBufferReader_Reader_RGB24 extends NyARBufferReader_Reader\r
 {\r
-       protected class Reader implements INyARRgbPixelReader,INyARBufferReader\r
+       protected boolean _is_flipped;\r
+       public NyARBufferReader_Reader_RGB24(RGBFormat i_input_format,NyARIntSize i_ref_size) throws NyARException\r
        {\r
-               private int _buffer_type = INyARBufferReader.BUFFERFORMAT_NULL_ALLZERO;\r
-               private byte[] _ref_buf;\r
-               private NyARIntSize _size;\r
-\r
-               public Reader(NyARIntSize i_size)\r
-               {\r
-                       this._size = i_size;\r
+               super(i_ref_size);\r
+               //ピクセルフォーマットを設定(現状は24bitRGBを受けつける。)\r
+               RGBFormat fm=(RGBFormat)i_input_format;\r
+               if(fm.getBitsPerPixel()!=24){\r
+                       throw new NyARException();\r
+               }\r
+               int r=fm.getRedMask();\r
+               int b=fm.getBlueMask();\r
+               if(r==1 && b==3){\r
+                       this._buf_type=BUFFERFORMAT_BYTE1D_R8G8B8_24;\r
+               }else if(r==3 && b==1){\r
+                       this._buf_type=BUFFERFORMAT_BYTE1D_B8G8R8_24;                   \r
+               }else{\r
+                       throw new NyARException();\r
                }\r
-               //\r
-               //INyARRgbPixelReader\r
-               //\r
-               public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException\r
-               {\r
-                       int bp = (i_x + i_y * this._size.w) * 3;\r
-                       byte[] ref = this._ref_buf;\r
-                       switch (this._buffer_type) {\r
-                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-                               o_rgb[0] = (ref[bp + 0] & 0xff);// R\r
-                               o_rgb[1] = (ref[bp + 1] & 0xff);// G\r
-                               o_rgb[2] = (ref[bp + 2] & 0xff);// B\r
-                               break;\r
-                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-                               o_rgb[0] = (ref[bp + 2] & 0xff);// B\r
-                               o_rgb[1] = (ref[bp + 1] & 0xff);// G\r
-                               o_rgb[2] = (ref[bp + 0] & 0xff);// R\r
-                               break;\r
-                       default:\r
-                               throw new NyARException();\r
+               //vertical反転の有無を確認\r
+               this._is_flipped=i_input_format.getFlipped()!=0?true:false;\r
+               this._ref_buf=new byte[i_ref_size.w*i_ref_size.h*3];\r
+               //RGBフォーマット\r
+               \r
+               return;\r
+       }\r
+       public void changeBuffer(javax.media.Buffer i_buffer)\r
+       {\r
+               //vertical反転が必要ならば、反転した画像を作成する。\r
+               byte[] src=(byte[])i_buffer.getData();\r
+               if(this._is_flipped){\r
+                       final int length = this._ref_size.w * 3;\r
+                       int src_idx = 0;\r
+                       int dest_idx = (this._ref_size.h - 1) * length;                 \r
+                       for (int i = 0; i < this._ref_size.h; i++) {\r
+                               System.arraycopy(src,src_idx, this._ref_buf, dest_idx, length);\r
+                               src_idx += length;\r
+                               dest_idx -= length;\r
                        }\r
-                       return;\r
+               }else{\r
+                       System.arraycopy(src,0,this._ref_buf,0,this._ref_buf.length);\r
+                       this._ref_buf=(byte[])i_buffer.getData();\r
                }\r
-\r
-               public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException\r
-               {\r
-                       int width = this._size.w;\r
-                       byte[] ref = this._ref_buf;\r
-                       int bp;\r
-                       switch (this._buffer_type) {\r
-                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
-                               for (int i = i_num - 1; i >= 0; i--) {\r
-                                       bp = (i_x[i] + i_y[i] * width) * 3;\r
-                                       o_rgb[i * 3 + 0] = (ref[bp + 0] & 0xff);// R\r
-                                       o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G\r
-                                       o_rgb[i * 3 + 2] = (ref[bp + 2] & 0xff);// B\r
-                               }\r
-                               break;\r
-                       case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
-                               for (int i = i_num - 1; i >= 0; i--) {\r
-                                       bp = (i_x[i] + i_y[i] * width) * 3;\r
-                                       o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// R\r
-                                       o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G\r
-                                       o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// B\r
-                               }\r
-                               break;\r
-                       default:\r
-                               throw new NyARException();\r
+               return;\r
+       }\r
+       public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException\r
+       {\r
+               int bp = (i_x + i_y * this._ref_size.w) * 3;\r
+               byte[] ref = this._ref_buf;\r
+               switch(this._buf_type){\r
+               case BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                       o_rgb[0] = (ref[bp + 0] & 0xff);// R\r
+                       o_rgb[1] = (ref[bp + 1] & 0xff);// G\r
+                       o_rgb[2] = (ref[bp + 2] & 0xff);// B\r
+                       break;\r
+               case BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       o_rgb[0] = (ref[bp + 2] & 0xff);// B\r
+                       o_rgb[1] = (ref[bp + 1] & 0xff);// G\r
+                       o_rgb[2] = (ref[bp + 0] & 0xff);// R\r
+                       break;\r
+               default:\r
+                       throw new NyARException();\r
+               }\r
+               return;\r
+       }\r
+       public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException\r
+       {\r
+               int width = this._ref_size.w;\r
+               byte[] ref = this._ref_buf;\r
+               int bp;\r
+               switch(this._buf_type){\r
+               case BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                       for (int i = i_num - 1; i >= 0; i--) {\r
+                               bp = (i_x[i] + i_y[i] * width) * 3;\r
+                               o_rgb[i * 3 + 0] = (ref[bp + 0] & 0xff);// R\r
+                               o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G\r
+                               o_rgb[i * 3 + 2] = (ref[bp + 2] & 0xff);// B\r
                        }\r
-                       return;\r
+                       break;\r
+               case BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+                       for (int i = i_num - 1; i >= 0; i--) {\r
+                               bp = (i_x[i] + i_y[i] * width) * 3;\r
+                               o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// B\r
+                               o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G\r
+                               o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// R\r
+                       }\r
+                       break;\r
+               default:\r
+                       throw new NyARException();\r
                }\r
+               return;\r
+       }       \r
+}\r
+\r
+\r
 \r
-               public void changeBuffer(int i_buffer_type, byte[] i_buffer)\r
-               {\r
-                       if(i_buffer_type==1){\r
-                               System.out.println("aaa");\r
+\r
+/**\r
+ * ソースがYUVフォーマットのデータをBGR24として扱うピクセルリーダ\r
+ * ソースデータをセットした時に変換します。\r
+ * (将来YUVをそのまま素通りさせるように書き換えるかも)\r
+ */\r
+class NyARBufferReader_Reader_YUV extends NyARBufferReader_Reader\r
+{\r
+       \r
+       private YUVToRGB _yuv2rgb;\r
+       private javax.media.Buffer _rgb_buf;\r
+       /**\r
+        * フォーマットアレイから、BGR24フォーマットを探す\r
+        * @param i_formats\r
+        * @return\r
+        */\r
+       private Format pickRGB24Format(Format[] i_formats)\r
+       {\r
+               for(int i=0;i<i_formats.length;i++){\r
+                       RGBFormat f=(RGBFormat)i_formats[i];\r
+                       if(f.getBitsPerPixel()!=24){\r
+                               continue;\r
                        }\r
-                       \r
-                       this._buffer_type = i_buffer_type;\r
-                       this._ref_buf = i_buffer;\r
+                       if(f.getRedMask()!=3 ||f.getGreenMask()!=2 ||f.getBlueMask()!=1 || f.getFlipped()!=0)\r
+                       {\r
+                               continue;\r
+                       }\r
+                       return f;\r
                }\r
-               //\r
-               //INyARBufferReader\r
-               //\r
-               public Object getBuffer()\r
-               {\r
-                       return this._ref_buf;\r
+               return null;\r
+       }\r
+       public NyARBufferReader_Reader_YUV(YUVFormat i_input_format,NyARIntSize i_ref_size) throws NyARException\r
+       {\r
+               super(i_ref_size,BUFFERFORMAT_BYTE1D_B8G8R8_24);\r
+               this._yuv2rgb=new YUVToRGB();\r
+               this._rgb_buf=new javax.media.Buffer();\r
+               this._ref_buf=null;\r
+               //24bit-RGBフォーマットのものを探す\r
+               Format output_format=pickRGB24Format(this._yuv2rgb.getSupportedOutputFormats(i_input_format));\r
+               if(output_format==null){\r
+                       throw new NyARException();\r
                }\r
-               public int getBufferType()\r
-               {\r
-                       return _buffer_type;\r
+               this._yuv2rgb.setInputFormat(i_input_format);\r
+               this._yuv2rgb.setOutputFormat(output_format);\r
+               try{\r
+                       this._yuv2rgb.open();\r
+               }catch(Exception e){\r
+                       throw new NyARException();\r
                }\r
-               public boolean isEqualBufferType(int i_type_value)\r
-               {\r
-                       return this._buffer_type==i_type_value;\r
-               }               \r
+               return;\r
+       }\r
+       public void changeBuffer(javax.media.Buffer i_buffer)\r
+       {\r
+               //エラー出した時のトラップ\r
+               if(this._yuv2rgb.process(i_buffer, this._rgb_buf)!=YUVToRGB.BUFFER_PROCESSED_OK){\r
+                       System.err.println("YUVToRGB.process error:");\r
+               }\r
+               this._ref_buf=(byte[])this._rgb_buf.getData();\r
+               return;\r
+       }\r
+       public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException\r
+       {\r
+               int bp = (i_x + i_y * this._ref_size.w) * 3;\r
+               byte[] ref = this._ref_buf;\r
+               o_rgb[0] = (ref[bp + 2] & 0xff);// B\r
+               o_rgb[1] = (ref[bp + 1] & 0xff);// G\r
+               o_rgb[2] = (ref[bp + 0] & 0xff);// R\r
+               return;\r
        }\r
+       public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException\r
+       {\r
+               int width = this._ref_size.w;\r
+               byte[] ref = this._ref_buf;\r
+               int bp;\r
+               for (int i = i_num - 1; i >= 0; i--) {\r
+                       bp = (i_x[i] + i_y[i] * width) * 3;\r
+                       o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// B\r
+                       o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G\r
+                       o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// R\r
+               }\r
+               return;\r
+       }       \r
+}\r
+\r
+\r
+/**\r
+ * \r
+ * RGB形式のJMFバッファをラップするNyARRasterです。\r
+ * JMFから得たラスタデータのピクセル並び順を考慮します。\r
+ *\r
+ */\r
+public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass\r
+{\r
 \r
-       protected byte[] _ref_buf;\r
-       protected Reader _reader;\r
+       protected NyARBufferReader_Reader _reader;\r
        /**\r
-        * RGB形式のJMFバッファをラップするオブジェクトをつくります。 生成直後のオブジェクトはデータを持ちません。\r
-        * メンバ関数はsetBufferを実行後に使用可能になります。\r
+        * i_formatに一致する画素フォーマットの\r
+        * @param i_size\r
+        * @param i_format\r
+        * @throws NyARException\r
         */\r
-       public JmfNyARRaster_RGB(NyARIntSize i_size)\r
+\r
+\r
+       public JmfNyARRaster_RGB(NyARIntSize i_ref_size,VideoFormat i_format) throws NyARException\r
        {\r
-               super(new NyARIntSize(i_size.w,i_size.w));\r
-               this._size.w = i_size.w;\r
-               this._size.h = i_size.h;\r
-               this._ref_buf = null;\r
-               this._reader = new Reader(this._size);\r
+               super(new NyARIntSize(i_ref_size));             \r
+               this._reader = createReader(i_format);\r
        }\r
-       public JmfNyARRaster_RGB(int i_width,int i_height)\r
+       public JmfNyARRaster_RGB(int i_width,int i_height,VideoFormat i_format) throws NyARException\r
        {\r
                super(new NyARIntSize(i_width,i_height));\r
-               this._ref_buf = null;\r
-               this._reader = new Reader(this._size);\r
-       }       \r
+               this._reader = createReader(i_format);\r
+       }\r
        \r
        /**\r
-        * フォーマットを解析して、ラスタタイプを返します。\r
-        * \r
+        * フォーマットを解析して、マッチするリーダオブジェクトを返します。\r
         * @param i_fmt\r
+        * ビデオフォーマットを指定します。\r
+        * @return\r
+        * リーダオブジェクト\r
         * @throws NyARException\r
         */\r
-       protected int analyzeBufferType(RGBFormat i_fmt) throws NyARException\r
+       private NyARBufferReader_Reader createReader(VideoFormat i_fmt) throws NyARException\r
        {\r
                // データサイズの確認\r
-               Dimension s = i_fmt.getSize();\r
+               final Dimension s = i_fmt.getSize();\r
                if (!this._size.isEqualSize(s.width, s.height)) {\r
                        throw new NyARException();\r
                }\r
                // データ配列の確認\r
-               int r = i_fmt.getRedMask() - 1;\r
-               int b = i_fmt.getBlueMask() - 1;\r
-\r
-               // 色配列の特定\r
-               if (r == 0 && b == 2) {\r
-                       return INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;\r
-               } else if (r == 2 && b == 0) {\r
-                       return INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24;\r
-               } else {\r
-                       throw new NyARException("Unknown pixel order.");\r
+               if(i_fmt instanceof YUVFormat){\r
+                       //YUVフォーマット\r
+                       return new NyARBufferReader_Reader_YUV((YUVFormat)i_fmt,this._size);                    \r
+               }else if(i_fmt instanceof RGBFormat){\r
+                       //RGBフォーマット\r
+                       return new NyARBufferReader_Reader_RGB24((RGBFormat)i_fmt,this._size);\r
+               }else{\r
+                       throw new NyARException();\r
                }\r
        }\r
 \r
@@ -188,20 +290,17 @@ public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass
         */\r
        public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
        {\r
-               int buftype= analyzeBufferType((RGBFormat) i_buffer.getFormat());\r
-               this._ref_buf = (byte[]) i_buffer.getData();\r
-               this._reader.changeBuffer(buftype, this._ref_buf);\r
+               this._reader.changeBuffer(i_buffer);\r
+               return;\r
        }\r
-\r
        /**\r
         * データを持っているかを返します。\r
         * @return\r
         */\r
        public boolean hasData()\r
        {\r
-               return this._ref_buf != null;\r
+               return this._reader._ref_buf != null;\r
        }\r
-\r
        public INyARRgbPixelReader getRgbPixelReader()\r
        {\r
                return this._reader;\r
@@ -211,3 +310,6 @@ public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass
                return this._reader;\r
        }\r
 }\r
+\r
+\r
+\r
index e714240..fffb35f 100644 (file)
@@ -125,22 +125,6 @@ public class MonitorStream implements PushBufferStream, BufferTransferHandler
                        img_listener.onUpdateBuffer(cbuffer);
                }
 
-               /*
-                // Display data if monitor is active
-                if (isEnabled()) {
-                if (bti == null) {
-                VideoFormat vf = (VideoFormat) cbuffer.getFormat();
-                bti = new BufferToImage(vf);
-                }
-                if (bti != null && component != null) {
-                Image im = bti.createImage(cbuffer);
-                Graphics g = component.getGraphics();
-                Dimension size = component.getSize();
-                if (g != null)
-                g.drawImage(im, 0, 0, component);
-                }
-                }
-                */
                // Maybe synchronize this with setTransferHandler() ?
                if (transferHandler != null && cds.delStarted)
                        transferHandler.transferData(this);
diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java
new file mode 100644 (file)
index 0000000..8648612
--- /dev/null
@@ -0,0 +1,63 @@
+/* \r
+ * PROJECT: NyARToolkit JMF utilities.\r
+ * --------------------------------------------------------------------------------\r
+ * The MIT License\r
+ * Copyright (c) 2008 nyatla\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/nyartoolkit/\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to deal\r
+ * in the Software without restriction, including without limitation the rights\r
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ * copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ * THE SOFTWARE.\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.jmf.utils;\r
+\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARRgbPixelReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+public abstract class NyARBufferReader_Reader implements INyARRgbPixelReader,INyARBufferReader\r
+{\r
+       protected byte[] _ref_buf;\r
+       protected NyARIntSize _ref_size;\r
+       protected int _buf_type;\r
+       protected NyARBufferReader_Reader(NyARIntSize i_ref_size,int i_buf_type)\r
+       {\r
+               this._ref_size =i_ref_size;\r
+               this._buf_type=i_buf_type;\r
+               return;\r
+       }\r
+       protected NyARBufferReader_Reader(NyARIntSize i_ref_size)\r
+       {\r
+               this._ref_size =i_ref_size;\r
+               return;\r
+       }\r
+       final public Object getBuffer()\r
+       {\r
+               return this._ref_buf;\r
+       }\r
+       final public int getBufferType()\r
+       {\r
+               return this._buf_type;\r
+       }\r
+       final public boolean isEqualBufferType(int i_type_value)\r
+       {\r
+               return this._buf_type==i_type_value;\r
+       }\r
+       public abstract void changeBuffer(javax.media.Buffer i_buffer);\r
+\r
+}\r
index b7437e3..8c035c7 100644 (file)
@@ -48,6 +48,11 @@ public class JmfCaptureTest extends Frame implements JmfCaptureListener
                setBounds(0, 0, 320 + 64, 240 + 64);
                JmfCaptureDeviceList dl=new JmfCaptureDeviceList();
                this._capture=dl.getDevice(0);
+               if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320,240,30.0f)){
+                       if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320,240,30.0f)){
+                               throw new NyARException("キャプチャフォーマットが見つかりません。");
+                       }
+               }
                this._capture.setOnCapture(this);
        }
 
index 0c63560..9697ede 100644 (file)
  */\r
 package jp.nyatla.nyartoolkit.jogl.utils;\r
 \r
-import javax.media.format.RGBFormat;\r
+\r
 import javax.media.opengl.GL;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
-\r
+import javax.media.format.*;\r
 \r
 /**\r
  * NyARRaster_RGBにOpenGL用のデータ変換機能を追加したものです。\r
  */\r
 public class GLNyARRaster_RGB extends JmfNyARRaster_RGB\r
 {\r
-       private byte[] _gl_buf;\r
-\r
        private int _gl_flag;\r
 \r
-       public GLNyARRaster_RGB(NyARParam i_param)\r
+       public GLNyARRaster_RGB(NyARParam i_param,VideoFormat i_format) throws NyARException\r
        {\r
-               super(i_param.getScreenSize());\r
-               this._gl_flag = GL.GL_RGB;\r
-               this._gl_buf = new byte[this._size.w * this._size.h * 3];\r
-       }\r
-\r
-       public void setBuffer(javax.media.Buffer i_buffer, boolean i_is_reverse) throws NyARException\r
-       {\r
-               int buffer_type=analyzeBufferType((RGBFormat) i_buffer.getFormat());;\r
-               byte[] src_buf = (byte[]) i_buffer.getData();\r
-               // GL用のデータを準備\r
-               if (i_is_reverse) {\r
-                       final int length = this._size.w * 3;\r
-                       int src_idx = 0;\r
-                       int dest_idx = (this._size.h - 1) * length;\r
-                       for (int i = 0; i < this._size.h; i++){\r
-                               System.arraycopy(src_buf, src_idx, this._gl_buf, dest_idx, length);\r
-                               src_idx += length;\r
-                               dest_idx -= length;\r
-                       }\r
-               } else {\r
-                       System.arraycopy(src_buf, 0, this._gl_buf, 0, src_buf.length);\r
-               }\r
-\r
-               // GLのフラグ設定\r
-               switch (buffer_type) {\r
+               super(i_param.getScreenSize(),i_format);\r
+               switch(this._reader.getBufferType()){\r
                case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
                        this._gl_flag = GL.GL_BGR;\r
                        break;\r
@@ -85,11 +60,8 @@ public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
                default:\r
                        throw new NyARException();\r
                }\r
-               // ref_bufをgl_bufに差し替える\r
-               this._ref_buf = this._gl_buf;\r
-               this._reader.changeBuffer(buffer_type, this._ref_buf);\r
+               return;\r
        }\r
-\r
        /**\r
         * GLでそのまま描画できるRGBバッファを返す。\r
         * \r
@@ -97,7 +69,7 @@ public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
         */\r
        public byte[] getGLRgbArray()\r
        {\r
-               return this._ref_buf;\r
+               return (byte[])this._reader.getBuffer();\r
        }\r
 \r
        /**\r
index eeeede4..730fabe 100644 (file)
@@ -31,9 +31,7 @@
  */\r
 package jp.nyatla.nyartoolkit.jogl.utils;\r
 \r
-import java.nio.ByteBuffer;\r
-import java.nio.IntBuffer;\r
-\r
+import java.nio.*;\r
 import javax.media.opengl.GL;\r
 import javax.media.opengl.glu.GLU;\r
 \r
index 0dcb9d2..dba936f 100644 (file)
@@ -36,23 +36,25 @@ import jp.nyatla.nyartoolkit.NyARException;
 public class NyARIntSize\r
 {\r
        public int h;\r
-\r
        public int w;\r
        public NyARIntSize()\r
        {\r
                this.w=0;\r
                this.h=0;\r
-               return;\r
-               \r
+               return;         \r
+       }\r
+       public NyARIntSize(NyARIntSize i_ref_object)\r
+       {\r
+               this.w=i_ref_object.w;\r
+               this.h=i_ref_object.h;\r
+               return;         \r
        }\r
-       \r
        public NyARIntSize(int i_width,int i_height)\r
        {\r
                this.w=i_width;\r
                this.h=i_height;\r
                return;\r
        }\r
-\r
        /**\r
         * サイズが同一であるかを確認する。\r
         * \r