Download List

System Requirements

System requirement is not defined

Publicado: 2009-01-18 13:37
NyARToolkit for Java - NyARToolkit Core 2.2.0 (1 files Ocultar)

Release Notes

NyARToolkit core

*NyARLabelingImageのデータ保持型を、int[][]からint[]へ変更しました。影響を受けるクラスを修正しています。 *座標計算処理を最適化しました。この修正により、小数点以下12桁目以降の数値がオリジナルと異なるようになりました。オリジナルとの互換性が重要な場合は、ソースのコメントを参考に修正を行って下さい。 *傾き角度を直接取得できるAPIを追加しました。(processing用のnyar4psgで使用しているAPIです。) *JMFキャプチャがYUVに対応しました。YUV形式のみしかキャプチャできないカメラ(等)でも使用できるようになりました。YUVとRGB両方をキャプチャできるカメラの場合、デフォルトではRGBを優先します。変換には、Javaのカラースペースコンバータを使用しています。 *JMFキャッププチャの管理クラスを書きなおしました。キャプチャデバイスをリストで管理できます。これにより、JMFキャッププチャクラスのAPIが変更されます。

//変更前
capture = new JmfCameraCapture(320, 240, 30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
capture.setCaptureListener(this);
:
this._raster = new JmfNyARRaster_RGB(320, 240);
//変更後
JmfCaptureDeviceList list=new JmfCaptureDeviceList();
capture=list.getDevice(0);
capture.setCaptureFormat(320,240,30.0f);
capture.setOnCapture(this);
this._raster = new JmfNyARRaster_RGB(320, 240,capture.getCaptureFormat());

*Java3Dユーティリティで画像処理系に上下反転した画像を入力していた問題を修正しました。合わせて、関連する行列の補正方法も修正しました。 *その他、コメントの修正等を行いました。

Changelog

Index: sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java
===================================================================
--- sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java (.../2.1.0) (revision 214)
+++ sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java (.../2.2.0) (revision 214)
@@ -36,6 +36,8 @@
*/
public class QtCaptureTest extends Frame implements QtCaptureListener
{
+ private static final long serialVersionUID = -734697739607654631L;
+
public QtCaptureTest() throws NyARException
{
setTitle("QtCaptureTest");
Index: sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java
===================================================================
--- sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java (.../2.1.0) (revision 214)
+++ sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java (.../2.2.0) (revision 214)
@@ -41,6 +41,8 @@
*/
public class NyarToolkitLinkTest extends Frame implements QtCaptureListener
{
+ private static final long serialVersionUID = 6154831884117789648L;
+
private final String CARCODE_FILE = "../../Data/patt.hiro";

private final String PARAM_FILE = "../../Data/camera_para.dat";
Index: sample/java3d/.classpath
===================================================================
--- sample/java3d/.classpath (.../2.1.0) (revision 214)
+++ sample/java3d/.classpath (.../2.2.0) (revision 214)
@@ -2,7 +2,7 @@
<classpath>
<classpathentry path="" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
- <classpathentry path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>
+ <classpathentry sourcepath="/jmfapp" path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>
<classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dcore.jar" kind="lib"/>
<classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dutils.jar" kind="lib"/>
<classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/vecmath.jar" kind="lib"/>
Index: sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java
===================================================================
--- sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (.../2.1.0) (revision 214)
+++ sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (.../2.2.0) (revision 214)
@@ -47,6 +47,8 @@
*/
public class NyARJava3D extends JFrame implements NyARSingleMarkerBehaviorListener
{
+ private static final long serialVersionUID = -8472866262481865377L;
+
private final String CARCODE_FILE = "../../Data/patt.hiro";

private final String PARAM_FILE = "../../Data/camera_para.dat";
Index: sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
===================================================================
--- sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (.../2.1.0) (revision 214)
+++ sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (.../2.2.0) (revision 214)
@@ -57,7 +57,7 @@

private GLNyARRaster_RGB _cap_image;

- private JmfCameraCapture _capture;
+ private JmfCaptureDevice _capture;

private GL _gl;
private NyARGLUtil _glnya;
@@ -135,25 +135,29 @@

public void init(GLAutoDrawable drawable)
{
- _gl = drawable.getGL();
- _gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ this._gl = drawable.getGL();
+ this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//NyARToolkitの準備
try {
//キャプチャの準備
- _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- _capture.setCaptureListener(this);
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
+ this._capture=devlist.getDevice(0);
+ if(!this._capture.setCaptureFormat(SCREEN_X, SCREEN_Y,15f)){
+ throw new Exception();
+ }
+ this._capture.setOnCapture(this);
//NyARToolkitの準備
- _ar_param = new NyARParam();
+ this._ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
- _ar_param.loadARParamFromFile(PARAM_FILE);
- _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);
- _nya = new NyARSingleDetectMarker(_ar_param, ar_code, 80.0);
- _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
+ this._ar_param.loadARParamFromFile(PARAM_FILE);
+ this._ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);
+ this._nya = new NyARSingleDetectMarker(this._ar_param, ar_code, 80.0);
+ this._nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
ar_code.loadARPattFromFile(CARCODE_FILE);
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param);
+ _cap_image = new GLNyARRaster_RGB(this._ar_param,this._capture.getCaptureFormat());
//キャプチャ開始
_capture.start();
} catch (Exception e) {
@@ -225,7 +229,7 @@
{
try {
synchronized (_cap_image) {
- _cap_image.setBuffer(i_buffer, true);
+ _cap_image.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
Index: sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java
===================================================================
--- sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java (.../2.1.0) (revision 214)
+++ sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java (.../2.2.0) (revision 214)
@@ -59,7 +59,7 @@

private GLNyARRaster_RGB _cap_image;

- private JmfCameraCapture _capture;
+ private JmfCaptureDevice _capture;

private GL _gl;

@@ -142,8 +142,10 @@
//NyARToolkitの準備
try {
//キャプチャの準備
- _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- _capture.setCaptureListener(this);
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
+ _capture=devlist.getDevice(0);
+ _capture.setCaptureFormat(SCREEN_X, SCREEN_Y,15f);
+ _capture.setOnCapture(this);
//NyARToolkitの準備
_ar_param = new NyARParam();
_ar_param.loadARParamFromFile(PARAM_FILE);
@@ -161,7 +163,7 @@
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param);
+ _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
//キャプチャ開始
_capture.start();
} catch (Exception e) {
@@ -239,7 +241,7 @@
{
try {
synchronized (_cap_image) {
- _cap_image.setBuffer(i_buffer, true);
+ _cap_image.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
Index: sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java
===================================================================
--- sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (.../2.1.0) (revision 214)
+++ sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (.../2.2.0) (revision 214)
@@ -47,42 +47,52 @@
*/
public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
{
+ private static final long serialVersionUID = 6471434231970804953L;
+
private final String CARCODE_FILE = "../../Data/patt.hiro";

private final String PARAM_FILE = "../../Data/camera_para.dat";

- private JmfCameraCapture capture;
+ private JmfCaptureDevice _capture;

- private NyARSingleDetectMarker nya;
+ private NyARSingleDetectMarker _nya;

- private JmfNyARRaster_RGB raster;
+ private JmfNyARRaster_RGB _raster;

- private NyARTransMatResult trans_mat_result = new NyARTransMatResult();
+ 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);
//キャプチャの準備
- capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- capture.setCaptureListener(this);
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
+ _capture=devlist.getDevice(0);
+ //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の準備
NyARParam ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
ar_param.loadARParamFromFile(PARAM_FILE);
ar_param.changeScreenSize(320, 240);
- nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0);
+ this._nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0);
ar_code.loadARPattFromFile(CARCODE_FILE);
//キャプチャイメージ用のラスタを準備
- raster = new JmfNyARRaster_RGB(320, 240);
+ this._raster = new JmfNyARRaster_RGB(320, 240,_capture.getCaptureFormat());
+ return;
}

public void onUpdateBuffer(Buffer i_buffer)
{
try {
//キャプチャしたバッファをラスタにセット
- raster.setBuffer(i_buffer);
+ this._raster.setBuffer(i_buffer);

//キャプチャしたイメージを表示用に加工
BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
@@ -91,27 +101,27 @@
Graphics g = getGraphics();

//マーカー検出
- boolean is_marker_exist = nya.detectMarkerLite(raster, 100);
+ boolean is_marker_exist = this._nya.detectMarkerLite(this._raster, 100);
if (is_marker_exist) {
//変換行列を取得
- nya.getTransmationMatrix(this.trans_mat_result);
+ this._nya.getTransmationMatrix(this._trans_mat_result);
}
//情報を画面に書く
g.drawImage(img, 32, 32, this);
if (is_marker_exist) {
- g.drawString("マーカー検出:" + nya.getConfidence(), 32, 50);
- g.drawString("[m00]" +this.trans_mat_result.m00, 32, 50 + 16*1);
- g.drawString("[m01]" +this.trans_mat_result.m01, 32, 50 + 16*2);
- g.drawString("[m02]" +this.trans_mat_result.m02, 32, 50 + 16*3);
- g.drawString("[m03]" +this.trans_mat_result.m03, 32, 50 + 16*4);
- g.drawString("[m10]" +this.trans_mat_result.m10, 32, 50 + 16*5);
- g.drawString("[m11]" +this.trans_mat_result.m11, 32, 50 + 16*6);
- g.drawString("[m12]" +this.trans_mat_result.m12, 32, 50 + 16*7);
- g.drawString("[m13]" +this.trans_mat_result.m13, 32, 50 + 16*8);
- g.drawString("[m20]" +this.trans_mat_result.m20, 32, 50 + 16*9);
- g.drawString("[m21]" +this.trans_mat_result.m21, 32, 50 + 16*10);
- g.drawString("[m22]" +this.trans_mat_result.m22, 32, 50 + 16*11);
- g.drawString("[m23]" +this.trans_mat_result.m23, 32, 50 + 16*12);
+ g.drawString("マーカー検出:" + this._nya.getConfidence(), 32, 50);
+ g.drawString("[m00]" +this._trans_mat_result.m00, 32, 50 + 16*1);
+ g.drawString("[m01]" +this._trans_mat_result.m01, 32, 50 + 16*2);
+ g.drawString("[m02]" +this._trans_mat_result.m02, 32, 50 + 16*3);
+ g.drawString("[m03]" +this._trans_mat_result.m03, 32, 50 + 16*4);
+ g.drawString("[m10]" +this._trans_mat_result.m10, 32, 50 + 16*5);
+ g.drawString("[m11]" +this._trans_mat_result.m11, 32, 50 + 16*6);
+ g.drawString("[m12]" +this._trans_mat_result.m12, 32, 50 + 16*7);
+ g.drawString("[m13]" +this._trans_mat_result.m13, 32, 50 + 16*8);
+ g.drawString("[m20]" +this._trans_mat_result.m20, 32, 50 + 16*9);
+ g.drawString("[m21]" +this._trans_mat_result.m21, 32, 50 + 16*10);
+ g.drawString("[m22]" +this._trans_mat_result.m22, 32, 50 + 16*11);
+ g.drawString("[m23]" +this._trans_mat_result.m23, 32, 50 + 16*12);
} else {
g.drawString("マーカー未検出:", 32, 100);
}
@@ -124,7 +134,7 @@
private void startCapture()
{
try {
- capture.start();
+ this._capture.start();
} catch (Exception e) {
e.printStackTrace();
}
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/JavaSimpleLite_Quad.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/JavaSimpleLite_Quad.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/JavaSimpleLite_Quad.java (.../2.2.0) (revision 214)
@@ -42,8 +42,7 @@
import jp.nyatla.nyartoolkit.core.NyARCode;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
+import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.jogl.utils.*;
/**
* simpleLiteと同じようなテストプログラム
@@ -65,7 +64,7 @@

private GLNyARRaster_RGB _cap_image;

- private JmfCameraCapture _capture;
+ private JmfCaptureDevice _capture;

private GL _gl;

@@ -148,8 +147,10 @@
//NyARToolkitの準備
try {
//キャプチャの準備
- _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- _capture.setCaptureListener(this);
+ JmfCaptureDeviceList list=new JmfCaptureDeviceList();
+ _capture=list.getDevice(0);
+ _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);
+ _capture.setOnCapture(this);
//NyARToolkitの準備
_ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
@@ -161,7 +162,7 @@
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param);
+ _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
//キャプチャ開始
_capture.start();
} catch (Exception e) {
@@ -233,7 +234,7 @@
{
try {
synchronized (_cap_image) {
- _cap_image.setBuffer(i_buffer, true);
+ _cap_image.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java (.../2.2.0) (revision 214)
@@ -62,11 +62,11 @@
int in_buf_type=in_buffer_reader.getBufferType();

NyARIntSize size = i_output.getSize();
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));
assert (checkInputType(in_buf_type)==true);
assert (i_input.getSize().isEqualSize(size.w*2,size.h*2) == true);

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();

switch (in_buffer_reader.getBufferType()) {
@@ -83,7 +83,7 @@
return;
}

- private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
final int size_w=i_size.w*2;
final int x_mod_end= size_w-(size_w%8);
@@ -93,37 +93,37 @@
int x;
for (int y =i_size.h-1; y>=0 ; y--){
//端数分
- final int[] row_ptr=i_out[y];
+ final int row_ptr=y*i_size.w;
for (x = i_size.w-1;x>=x_mod_end;x--) {
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
+ i_out[row_ptr+x]=w<=th?0:1;
bp -= 6;
}
//タイリング
for (;x>=0;x-=8) {
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
+ i_out[row_ptr+x]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-1]=w<=th?0:1;
+ i_out[row_ptr+x-1]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-2]=w<=th?0:1;
+ i_out[row_ptr+x-2]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-3]=w<=th?0:1;
+ i_out[row_ptr+x-3]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-4]=w<=th?0:1;
+ i_out[row_ptr+x-4]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-5]=w<=th?0:1;
+ i_out[row_ptr+x-5]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-6]=w<=th?0:1;
+ i_out[row_ptr+x-6]=w<=th?0:1;
bp -= 6;
w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-7]=w<=th?0:1;
+ i_out[row_ptr+x-7]=w<=th?0:1;
bp -= 6;
}
//1行飛ばし
@@ -131,7 +131,7 @@
}
return;
}
- private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
final int size_w=i_size.w;
final int x_mod_end= size_w-(size_w%8);
@@ -140,39 +140,39 @@
int w;
int x;
for (int y =i_size.h-1; y>=0 ; y--){
- final int[] row_ptr=i_out[y];
+ final int row_ptr=y*i_size.w;

//端数分
for (x = size_w-1;x>=x_mod_end;x--) {
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
+ i_out[row_ptr+x]=w<=th?0:1;
bp -= 4;
}
//タイリング
for (;x>=0;x-=8) {
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
+ i_out[row_ptr+x]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-1]=w<=th?0:1;
+ i_out[row_ptr+x-1]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-2]=w<=th?0:1;
+ i_out[row_ptr+x-2]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-3]=w<=th?0:1;
+ i_out[row_ptr+x-3]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-4]=w<=th?0:1;
+ i_out[row_ptr+x-4]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-5]=w<=th?0:1;
+ i_out[row_ptr+x-5]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-6]=w<=th?0:1;
+ i_out[row_ptr+x-6]=w<=th?0:1;
bp -= 4;
w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-7]=w<=th?0:1;
+ i_out[row_ptr+x-7]=w<=th?0:1;
bp -= 4;
}
}
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java (.../2.2.0) (revision 214)
@@ -11,7 +11,7 @@

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 @@

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: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java (.../2.2.0) (revision 214)
@@ -59,18 +59,20 @@
this._out_image = i_destination_image;

// NyLabelingImageのイメージ初期化(枠書き)
- int[][] img = (int[][]) i_destination_image.getBufferReader().getBuffer();
+ int[] img = (int[])i_destination_image.getBufferReader().getBuffer();
+ int bottom_ptr=(size.h - 1)*size.w;
for (int i = 0; i < size.w; i++) {
- img[0][i] = 0;
- img[size.h - 1][i] = 0;
+ img[i] = 0;
+ img[bottom_ptr+i] = 0;
}
for (int i = 0; i < size.h; i++) {
- img[i][0] = 0;
- img[i][size.w - 1] = 0;
+ img[i*size.w] = 0;
+ img[(i+1)*size.w - 1] = 0;
}

// サイズ(参照値)を保存
this._dest_size = size;
+ return;
}

public INyARLabelingImage getAttachedDestination()
@@ -97,43 +99,43 @@

final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;
final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;
- int[][] label_img = (int[][]) out_image.getBufferReader().getBuffer();
+ int[] label_img = (int[])out_image.getBufferReader().getBuffer();

// 枠作成はインスタンスを作った直後にやってしまう。
-
- // ラベリング情報のリセット(ラベリングインデックスを使用)
+
+ //ラベリング情報のリセット(ラベリングインデックスを使用)
out_image.reset(true);
+
+ int[] label_idxtbl=out_image.getIndexArray();

- int[] label_idxtbl = out_image.getIndexArray();
-
int[] work2_pt;
int wk_max = 0;

int label_pixel;
- int[][] raster_buf = (int[][]) i_raster.getBufferReader().getBuffer();
- int[] line_ptr;
+ int[] raster_buf=(int[])i_raster.getBufferReader().getBuffer();
+ int line_ptr;
int[][] work2 = this.work_holder.work2;
- int[] label_img_pt0, label_img_pt1;
+ int label_img_ptr0, label_img_ptr1;
for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {
- line_ptr = raster_buf[j];
- label_img_pt0 = label_img[j];
- label_img_pt1 = label_img[j - 1];
+ line_ptr=j*lxsize;
+ label_img_ptr0=j*lxsize;//label_img_pt0 = label_img[j];
+ label_img_ptr1=label_img_ptr0-lxsize;//label_img_pt1 = label_img[j - 1];
for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
// RGBの合計値が閾値より小さいかな?
- if (line_ptr[i] == 0) {
+ if (raster_buf[line_ptr+i]==0) {
// pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);
- if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
- label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;
+ if (label_img[label_img_ptr1+i] > 0) {//if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
+ label_pixel = label_img[label_img_ptr1+i];//label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
- if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
- m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
+ } else if (label_img[label_img_ptr1+i + 1] > 0) {//} else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
+ if (label_img[label_img_ptr1+i - 1] > 0) {//if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
+ m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[label_img_ptr1+i - 1] - 1];//n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
if (m > n) {
label_pixel = n;// *pnt2 = n;
// wk=IntPointer.wrap(work, 0);//wk =
@@ -159,9 +161,9 @@
work2_pt[1] += i;
work2_pt[2] += j;
work2_pt[6] = j;
- } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
- m = label_idxtbl[(label_img_pt1[i + 1]) - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
+ } else if ((label_img[label_img_ptr0+i - 1]) > 0) {//} else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
+ m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[label_img_ptr0+i - 1] - 1];//n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
if (m > n) {

label_pixel = n;// *pnt2 = n;
@@ -186,24 +188,24 @@
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
} else {

- label_pixel = label_img_pt1[i + 1];// *pnt2 =
- // *(pnt1+1);
+ label_pixel = label_img[label_img_ptr1+i + 1];//label_pixel = label_img_pt1[i + 1];// *pnt2 =
+ // *(pnt1+1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
if (work2_pt[3] > i) {// if(
- // work2[((*pnt2)-1)*7+3] >
- // i ){
+ // work2[((*pnt2)-1)*7+3] >
+ // i ){
work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
}
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
}
- } else if ((label_img_pt1[i - 1]) > 0) {// }else if(
- // *(pnt1-1) > 0 ) {
- label_pixel = label_img_pt1[i - 1];// *pnt2 =
- // *(pnt1-1);
+ } else if ((label_img[label_img_ptr1+i - 1]) > 0) {//} else if ((label_img_pt1[i - 1]) > 0) {// }else if(
+ // *(pnt1-1) > 0 ) {
+ label_pixel = label_img[label_img_ptr1+i - 1];//label_pixel = label_img_pt1[i - 1];// *pnt2 =
+ // *(pnt1-1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
@@ -213,8 +215,8 @@
work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
}
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
- label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);
+ } else if (label_img[label_img_ptr0+i - 1] > 0) {//} else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
+ label_pixel = label_img[label_img_ptr0+i - 1];//label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
@@ -238,9 +240,9 @@
work2_pt[5] = j;
work2_pt[6] = j;
}
- label_img_pt0[i] = label_pixel;
+ label_img[label_img_ptr0+i] = label_pixel;//label_img_pt0[i] = label_pixel;
} else {
- label_img_pt0[i] = 0;// *pnt2 = 0;
+ label_img[label_img_ptr0+i] = 0;//label_img_pt0[i] = 0;// *pnt2 = 0;
}
}
}
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java (.../2.2.0) (revision 214)
@@ -42,8 +42,7 @@
import jp.nyatla.nyartoolkit.core.NyARCode;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
+import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.jogl.utils.*;
/**
* simpleLiteと同じようなテストプログラム
@@ -65,7 +64,7 @@

private GLNyARRaster_RGB _cap_image;

- private JmfCameraCapture _capture;
+ private JmfCaptureDevice _capture;

private GL _gl;

@@ -149,8 +148,10 @@
//NyARToolkitの準備
try {
//キャプチャの準備
- _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- _capture.setCaptureListener(this);
+ JmfCaptureDeviceList list=new JmfCaptureDeviceList();
+ _capture=list.getDevice(0);
+ _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);
+ _capture.setOnCapture(this);
//NyARToolkitの準備
_ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
@@ -162,7 +163,7 @@
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param);
+ _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
//キャプチャ開始
_capture.start();
} catch (Exception e) {
@@ -234,7 +235,7 @@
{
try {
synchronized (_cap_image) {
- _cap_image.setBuffer(i_buffer, true);
+ _cap_image.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatFitVecCalculator.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatFitVecCalculator.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatFitVecCalculator.java (.../2.2.0) (revision 214)
@@ -31,7 +31,6 @@
*/
package jp.nyatla.nyartoolkit.sandbox.x2;

-import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.*;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point2d;
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java (.../2.2.0) (revision 214)
@@ -35,8 +35,6 @@
import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.transmat.*;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.*;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core2.types.*;

Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java (.../2.2.0) (revision 214)
@@ -34,10 +34,7 @@
import jp.nyatla.nyartoolkit.core.labeling.*;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.types.matrix.*;
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Linear;
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Point2d;
+import jp.nyatla.nyartoolkit.core2.types.*;
import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;
import jp.nyatla.nyartoolkit.core.*;

Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java (.../2.2.0) (revision 214)
@@ -34,7 +34,6 @@

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point2d;
import jp.nyatla.nyartoolkit.core2.types.NyARFixedFloat16Point3d;

Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java (.../2.2.0) (revision 214)
@@ -34,17 +34,19 @@

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: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java (.../2.2.0) (revision 214)
@@ -47,8 +47,8 @@
public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException
{
final NyARIntSize size = i_output.getSize();
- final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();
- final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();
+ final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();
+ final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。

@@ -63,7 +63,7 @@
sum = nn = 0;
for (int yy = y - area; yy < y + area + 1; yy++) {
for (int xx = x1 - area; xx < x1 + area; xx++) {
- sum += in_buf[yy][xx];
+ sum += in_buf[yy*size.w+xx];
nn++;
}
}
@@ -73,14 +73,14 @@
for (int x = area; x < x2; x++) {
if (!first) {
for (int yy = y - area; yy < y + area; yy++) {
- sum += in_buf[yy][x + area];
- sum -= in_buf[yy][x - area];
+ sum += in_buf[yy*size.w+x + area];
+ sum -= in_buf[yy*size.w+x - area];
}
}
first = false;
th = (sum / nn);
- int g = in_buf[y][x];
- out_buf[y][x] = th < g ? 1 : 0;
+ int g = in_buf[y*size.w+x];
+ out_buf[y*size.w+x] = th < g ? 1 : 0;
}
}
return;
Index: sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrSample.java
===================================================================
--- sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrSample.java (.../2.1.0) (revision 214)
+++ sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrSample.java (.../2.2.0) (revision 214)
@@ -55,7 +55,7 @@

private GLNyARRaster_RGB _cap_image;

- private JmfCameraCapture _capture;
+ private JmfCaptureDevice _capture;

private GL _gl;
private NyARGLUtil _glnya;
@@ -138,8 +138,11 @@
//NyARToolkitの準備
try {
//キャプチャの準備
- _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- _capture.setCaptureListener(this);
+ JmfCaptureDeviceList list=new JmfCaptureDeviceList();
+ _capture=list.getDevice(0);
+ _capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 15f);
+ _capture.setOnCapture(this);
+
//NyARToolkitの準備
_ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
@@ -151,7 +154,7 @@
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param);
+ _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
//キャプチャ開始
_capture.start();
} catch (Exception e) {
@@ -223,7 +226,7 @@
{
try {
synchronized (_cap_image) {
- _cap_image.setBuffer(i_buffer, true);
+ _cap_image.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
Index: readme.ja.txt
===================================================================
--- readme.ja.txt (.../2.1.0) (revision 214)
+++ readme.ja.txt (.../2.2.0) (revision 214)
@@ -1,7 +1,7 @@
-ARToolKit Java class library NyARToolkit.
+ARToolKit Java class library NyARToolkit.
Copyright (C)2008 R.Iizuka

-version 2.1.0
+version 2.2.0

http://nyatla.jp/nyartoolkit/
airmail(at)ebony.plala.or.jp
@@ -10,14 +10,14 @@



-・NyARToolkit/2.1
+・NyARToolkit/2.2

NyARToolkitは、Pure Javaで実装したARToolKitクラスライブラリです。

ARToolKit 2.72.1をベースに構築されています。

-NyARToolkit/2.0系は、NyARToolkit/1.xと比較して構造的な最適化がされており、
-可読性と分離性が向上しています。
+NyARToolkit/2.0系はNyARToolkit/1.xと比較して、処理速度と可読性、
+モジュールの分離性が向上しています。



@@ -35,7 +35,7 @@

 -ARToolKitと同等な処理シーケンスを、クラスベースで再構築してあります。

- -構造的な最適化がされており、ARToolKitと比較して可読性に優れています。
+ -構造的な最適化により、ARToolKitと比較して可読性に優れています。

 -座標変換の演算性能が1.5倍ほど高速です。(JIT有効時)複数マーカー取り扱い時は、
  オリジナルよりも良い成績が得られます。
@@ -69,8 +69,8 @@
NyARJMF/CaptureQT/NyARJog/NyARJ3dは、下位のキャプチャモジュール
や3Dライブラリを使いやすくするためのラッパークラス群です。

-これらとNyARToolkitは疎結合になっており、インタフェイスをあわせる
-ことで、自作モジュール等との差し替えが出来ます。
+各モジュールとNyARToolkitは容易に分離可能であり、個々を単独で
+使用することも可能です。



@@ -100,13 +100,11 @@
2.eclipseで空のワークスペースを作成し、sample,src,src.utils
  ディレクトリをインポートしてください。

-srcにはNyARToolkit本体、src.utilsにはキャプチャや3Dライブラリとの
-インタフェイスクラス群、sampleにはこれらを組み合わせた動作する
-サンプルプログラムがあります。
+srcディレクトリには、NyARToolkit本体(計算クラス群)があります。
+src.utilsディレクトリには、カメラキャプチャクラスや、3Dライブラリ用のラッパークラス群があります。
+sampleディレクトリには、NyARToolkitを使用したサンプルプログラムがあります。


-
-
・プロジェクトの説明

ライブラリ
Index: src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
===================================================================
--- src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (.../2.1.0) (revision 214)
+++ src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (.../2.2.0) (revision 214)
@@ -28,14 +28,14 @@

import java.awt.image.*;

-import javax.media.format.RGBFormat;
+import javax.media.format.VideoFormat;
import javax.media.j3d.ImageComponent;
import javax.media.j3d.ImageComponent2D;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
import jp.nyatla.nyartoolkit.jmf.utils.*;
-
+import jp.nyatla.nyartoolkit.core.rasterreader.*;
/**
*
* このクラスは、Java3Dと互換性のあるNyARToolkitのラスタイメージを保持します。
@@ -57,20 +57,31 @@
*/
public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
{
- //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。
- synchronized (this) {
- //キャプチャデータをi2dのバッファにコピーする。(これ省略したいなあ…。)
- System.arraycopy((byte[]) i_buffer.getData(), 0, this.i2d_buf, 0, this.i2d_buf.length);
+ this._reader.changeBuffer(i_buffer);
+ synchronized (this){
+ //キャプチャデータをi2dのバッファにコピーする。
+ //現在はJmfNyARRaster_RGBでRGB画像がノーマライズされているので、
+ //ここでもう一度flipする。(これ省略したいなあ…。)
+ byte[] src=(byte[])this._reader.getBuffer();
+ final int length = this._size.w * 3;
+ int src_idx = 0;
+ int dest_idx = (this._size.h - 1) * length;
+ for (int i = 0; i < this._size.h; i++) {
+ System.arraycopy(src,src_idx, this.i2d_buf, dest_idx, length);
+ src_idx += length;
+ dest_idx -= length;
+ }
}
- int buffer_type = analyzeBufferType((RGBFormat) i_buffer.getFormat());
- this._ref_buf = this.i2d_buf;
- this._reader.changeBuffer(buffer_type, this._ref_buf);
+ return;
}

- public J3dNyARRaster_RGB(NyARParam i_cparam)
+ public J3dNyARRaster_RGB(NyARParam i_cparam,VideoFormat i_format) throws NyARException
{
- super(i_cparam.getScreenSize());
-
+ super(i_cparam.getScreenSize(),i_format);
+ //bufferdimageの種類を決める
+ if(this._reader.getBufferType()!=INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24){
+ throw new NyARException();
+ }
//RGBのラスタを作る。
this.bufferd_image = new BufferedImage(this._size.w, this._size.h, BufferedImage.TYPE_3BYTE_BGR);
i2d_buf = ((DataBufferByte) bufferd_image.getRaster().getDataBuffer()).getData();
Index: src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
===================================================================
--- src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (.../2.1.0) (revision 214)
+++ src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (.../2.2.0) (revision 214)
@@ -33,8 +33,7 @@
import javax.vecmath.*;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
+import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
@@ -48,32 +47,35 @@
*/
public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener
{
- private NyARParam cparam;
+ private NyARParam _cparam;

- private JmfCameraCapture capture;
+ private JmfCaptureDevice _capture;

- private J3dNyARRaster_RGB nya_raster;//最大3スレッドで共有されるので、排他制御かけること。
+ private J3dNyARRaster_RGB _nya_raster;//最大3スレッドで共有されるので、排他制御かけること。

- private NyARSingleDetectMarker nya;
+ private NyARSingleDetectMarker _nya;

//Behaviorホルダ
- private NyARBehavior nya_behavior;
+ private NyARBehavior _nya_behavior;

public NyARSingleMarkerBehaviorHolder(NyARParam i_cparam, float i_rate, NyARCode i_ar_code, double i_marker_width) throws NyARException
{
- nya_behavior = null;
+ this._nya_behavior = null;
final NyARIntSize scr_size = i_cparam.getScreenSize();
- cparam = i_cparam;
- capture = new JmfCameraCapture(scr_size.w, scr_size.h, i_rate, JmfCameraCapture.PIXEL_FORMAT_RGB);
- capture.setCaptureListener(this);
- nya_raster = new J3dNyARRaster_RGB(cparam);
- nya = new NyARSingleDetectMarker(cparam, i_ar_code, i_marker_width);
- nya_behavior = new NyARBehavior(nya, nya_raster, i_rate);
+ this._cparam = i_cparam;
+ //キャプチャの準備
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
+ this._capture=devlist.getDevice(0);
+ this._capture.setCaptureFormat(scr_size.w, scr_size.h,15f);
+ this._capture.setOnCapture(this);
+ this._nya_raster = new J3dNyARRaster_RGB(this._cparam,this._capture.getCaptureFormat());
+ this._nya = new NyARSingleDetectMarker(this._cparam, i_ar_code, i_marker_width);
+ this._nya_behavior = new NyARBehavior(this._nya, this._nya_raster, i_rate);
}

public Behavior getBehavior()
{
- return nya_behavior;
+ return this._nya_behavior;
}

/**
@@ -85,7 +87,7 @@
public void setBackGround(Background i_back_ground)
{
//コール先で排他制御
- nya_behavior.setRelatedBackGround(i_back_ground);
+ this._nya_behavior.setRelatedBackGround(i_back_ground);
}

/**
@@ -95,7 +97,7 @@
public void setTransformGroup(TransformGroup i_trgroup)
{
//コール先で排他制御
- nya_behavior.setRelatedTransformGroup(i_trgroup);
+ this._nya_behavior.setRelatedTransformGroup(i_trgroup);
}

/**
@@ -105,7 +107,7 @@
public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)
{
//コール先で排他制御
- nya_behavior.setUpdateListener(i_listener);
+ this._nya_behavior.setUpdateListener(i_listener);
}

/**
@@ -114,8 +116,8 @@
public void onUpdateBuffer(Buffer i_buffer)
{
try {
- synchronized (nya_raster) {
- nya_raster.setBuffer(i_buffer);
+ synchronized (this._nya_raster) {
+ this._nya_raster.setBuffer(i_buffer);
}
} catch (Exception e) {
e.printStackTrace();
@@ -125,12 +127,12 @@
public void start() throws NyARException
{
//開始
- capture.start();
+ this._capture.start();
}

public void stop()
{
- capture.stop();
+ this._capture.stop();
}
}

@@ -212,7 +214,12 @@
{
final NyARTransMatResult src = this.trans_mat_result;
related_nya.getTransmationMatrix(src);
- 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);
+// 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);
+ 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);
matrix.transpose();
t3d = new Transform3D(matrix);
if (trgroup != null) {
Index: src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java
===================================================================
--- src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (.../2.1.0) (revision 214)
+++ src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (.../2.2.0) (revision 214)
@@ -31,51 +31,34 @@
*/
package jp.nyatla.nyartoolkit.jogl.utils;

-import javax.media.format.RGBFormat;
+
import javax.media.opengl.GL;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import javax.media.format.*;

-
/**
* NyARRaster_RGBにOpenGL用のデータ変換機能を追加したものです。
*/
public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
{
- private byte[] _gl_buf;
-
private int _gl_flag;
-
- public GLNyARRaster_RGB(NyARParam i_param)
+ /**
+ * コンストラクタです。i_formatを取り込めるi_paramのサイズパラメタを持つ
+ * ラスタオブジェクトを作成します。
+ * @param i_param
+ * カメラパラメタを指定します。コンストラクタは、画面サイズ以外のパラメタを見ていません。
+ * @param i_format
+ * キャプチャ画像のピクセルフォーマットを指定します。
+ * @throws NyARException
+ */
+ public GLNyARRaster_RGB(NyARParam i_param,VideoFormat i_format) throws NyARException
{
- super(i_param.getScreenSize());
- this._gl_flag = GL.GL_RGB;
- this._gl_buf = new byte[this._size.w * this._size.h * 3];
- }
-
- public void setBuffer(javax.media.Buffer i_buffer, boolean i_is_reverse) throws NyARException
- {
- int buffer_type=analyzeBufferType((RGBFormat) i_buffer.getFormat());;
- byte[] src_buf = (byte[]) i_buffer.getData();
- // GL用のデータを準備
- if (i_is_reverse) {
- final int length = this._size.w * 3;
- int src_idx = 0;
- int dest_idx = (this._size.h - 1) * length;
- for (int i = 0; i < this._size.h; i++) {
- System.arraycopy(src_buf, src_idx, this._gl_buf, dest_idx, length);
- src_idx += length;
- dest_idx -= length;
- }
- } else {
- System.arraycopy(src_buf, 0, this._gl_buf, 0, src_buf.length);
- }
-
- // GLのフラグ設定
- switch (buffer_type) {
+ super(i_param.getScreenSize(),i_format);
+ switch(this._reader.getBufferType()){
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
this._gl_flag = GL.GL_BGR;
break;
@@ -85,25 +68,24 @@
default:
throw new NyARException();
}
- // ref_bufをgl_bufに差し替える
- this._ref_buf = this._gl_buf;
- this._reader.changeBuffer(buffer_type, this._ref_buf);
+ return;
}
-
/**
- * GLでそのまま描画できるRGBバッファを返す。
- *
+ * RGBバイト配列への参照値を返します。
+ * バッファの並び順は、getGLPixelFlagが返すデータ順で格納されています。
* @return
+ * RGBバイト配列の参照値です。
*/
public byte[] getGLRgbArray()
{
- return this._ref_buf;
+ return (byte[])this._reader.getBuffer();
}

/**
- * GL用のRGBバッファのバイト並びタイプを返す。
- *
+ * OpenGLの描画フラグを返します。
+ * この値は、RGBバッファのバイト並びタイプです。
* @return
+ * GL.GL_BGR等の、RGBバイト配列の形式を表す値です。
*/
public int getGLPixelFlag()
{
Index: src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
===================================================================
--- src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (.../2.1.0) (revision 214)
+++ src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (.../2.2.0) (revision 214)
@@ -31,9 +31,7 @@
*/
package jp.nyatla.nyartoolkit.jogl.utils;

-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-
+import java.nio.*;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;

Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java (.../2.1.0) (revision 0)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java (.../2.2.0) (revision 214)
@@ -0,0 +1,221 @@
+package jp.nyatla.nyartoolkit.jmf.utils;
+
+import java.awt.Dimension;
+
+import javax.media.*;
+import javax.media.control.*;
+import javax.media.format.*;
+import javax.media.protocol.*;
+import jp.nyatla.nyartoolkit.*;
+
+public class JmfCaptureDevice
+{
+ private JmfCaptureListener _capture_listener;
+ private MonitorStream _jmf_monitor_stream;
+ private Processor _jmf_processor;
+ private CaptureDeviceInfo _info;
+ private VideoFormat _capture_format;
+ private static final String[] _enc_str={"RGB","YUV"};
+ public static final int PIXEL_FORMAT_RGB =0;// "RGB";
+ public static final int PIXEL_FORMAT_YUV =1;// "YUV";
+ public JmfCaptureDevice(CaptureDeviceInfo i_capinfo) throws NyARException
+ {
+ this._info = i_capinfo;
+ this._capture_format = null;
+ return;
+ }
+
+ /**
+ * サポートしているフォーマットの一覧を返します。
+ * @return
+ */
+ public Format[] getSupportFormats()
+ {
+ return this._info.getFormats();
+ }
+
+ public final VideoFormat getCaptureFormat()
+ {
+ return this._capture_format;
+ }
+
+ /**
+ * このキャプチャデバイスの提供する、i_index番目のフォーマットをキャプチャフォーマットに指定します。
+ * @param i_index
+ */
+ public void setCaptureFormat(int i_index)
+ {
+ this._capture_format = (VideoFormat)this._info.getFormats()[i_index];
+ return;
+ }
+ /**
+ * キャプチャ画像のフォーマットを指定した形式にしようと試みます。
+ * @param i_encode
+ * キャプチャする画像フォーマットを指定します。フォーマットはこのクラスに宣言される定数値を使ってください。
+ * @param i_size
+ * キャプチャ画像サイズを指定します。
+ * @param i_rate
+ * キャプチャレートをFPS単位で指定します。
+ * @return
+ * 指定に成功するとTRUEを返します。失敗するとFALSEを返します。
+ */
+ protected boolean setCaptureFormat(int i_encode, Dimension i_size, float i_rate) throws NyARException
+ {
+ if (this._jmf_processor != null){
+ throw new NyARException();
+ }
+ Format[] formats = this._info.getFormats();
+ VideoFormat f = new VideoFormat(_enc_str[i_encode], i_size, Format.NOT_SPECIFIED, null, i_rate);
+ for (int i = 0; i < formats.length; i++){
+ if (formats[i].matches(f)) {
+ //[暫定実装]RGBの場合のみ、24bit-BGRAを強制する。他のフォーマットも取りたいときは要改造
+ //これはMacOSのJMF等で問題が出るかもしれない。問題が出たら教えて下さい。
+ if(formats[i] instanceof RGBFormat){
+ RGBFormat fmt_ref=(RGBFormat)formats[i];
+ if(fmt_ref.getBitsPerPixel()!=24 || fmt_ref.getBlueMask()!=1 || fmt_ref.getBlueMask()!=2 || fmt_ref.getRedMask()!=3){
+ continue;
+ }
+ }
+ f =(VideoFormat)formats[i].intersects(f);
+ this._capture_format = null;
+ this._capture_format = f;
+ return true;
+ }
+ }
+ //ない。
+ return false;
+ }
+ /**
+ * キャプチャ画像のエンコード、サイズ、レートを引数とするsetCaptureFormat関数です。
+ * @param i_encode
+ * PIXEL_FORMAT_XXXで定義される定数値を指定して下さい。
+ * @param i_size_x
+ * キャプチャする画像の横幅
+ * @param i_size_y
+ * キャプチャする画像の縦幅
+ * @param i_rate
+ * フレームレート
+ * @return
+ * 関数の実行結果を真偽値で返します。
+ * @throws NyARException
+ */
+ public boolean setCaptureFormat(int i_encode,int i_size_x,int i_size_y, float i_rate) throws NyARException
+ {
+ return setCaptureFormat(i_encode,new Dimension(i_size_x,i_size_y),i_rate);
+ }
+ /**
+ * キャプチャ画像のサイズ、レートを引数とするsetCaptureFormat関数です。
+ * キャプチャ画像のエンコードは、RGB→YUVの順で検索します。
+ * @param i_size_x
+ * キャプチャする画像の横幅
+ * @param i_size_y
+ * キャプチャする画像の縦幅
+ * @param i_rate
+ * フレームレート
+ * @return
+ * 関数の実行結果を真偽値で返します。
+ * @throws NyARException
+ */
+ public boolean setCaptureFormat(int i_size_x,int i_size_y, float i_rate) throws NyARException
+ {
+ Dimension d=new Dimension(i_size_x,i_size_y);
+ if(setCaptureFormat(PIXEL_FORMAT_RGB,d,i_rate)){
+ return true;
+ }
+ if(setCaptureFormat(PIXEL_FORMAT_YUV,d,i_rate)){
+ return true;
+ }
+ return false;
+ }
+
+
+
+ /**
+ * 画像のキャプチャイベントを受信するリスナクラスを指定します。
+ * @param i_listener
+ * リスナークラス
+ * @throws NyARException
+ */
+ public void setOnCapture(JmfCaptureListener i_listener) throws NyARException
+ {
+ if (this._jmf_processor != null) {
+ throw new NyARException();
+ }
+ this._capture_listener = i_listener;
+ return;
+ }
+ /**
+ * キャプチャーを開始します。stop関数を呼び出すまでの間、setOnCaptureで指定したリスナークラスに、
+ * フォーマットで指定したキャプチャ画像が通知されます。
+ * @throws NyARException
+ */
+ public void start() throws NyARException
+ {
+ // startしていたらエラー
+ if (this._jmf_processor != null) {
+ throw new NyARException();
+ }
+ DataSource ds;
+ final MediaLocator ml = this._info.getLocator();
+ try {
+ ds = Manager.createDataSource(ml);
+ ds.connect();
+ // ここでフォーマットを作成
+ if (ds instanceof CaptureDevice) {
+ FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls();
+ if (fcs.length < 1) {
+ return;
+ }
+ FormatControl fc = fcs[0];
+ fc.setFormat(this._capture_format);
+ }
+ } catch (Exception e) {
+ throw new NyARException(e);
+ }
+ try{
+ if(ds==null){
+ //Merge the data sources, if both audio and video are available
+ ds = Manager.createMergingDataSource(new DataSource[] { null });
+ }else{
+ // Create the monitoring datasource wrapper
+ ds = new MonitorCDS(ds);
+ }
+ }catch(IncompatibleSourceException e){
+ throw new NyARException(e);
+ }
+
+ // データソース完成
+ try {
+ // Merge the data sources, if both audio and video are available
+ VideoFormat[] formats = new VideoFormat[] { new VideoFormat(null) };
+ ProcessorModel pm = new ProcessorModel(ds, formats, null);// ,
+ Processor processor;
+ processor = Manager.createRealizedProcessor(pm);
+ this._jmf_monitor_stream = (MonitorStream) ds.getControl("jmfsample.MonitorStream");
+ this._jmf_monitor_stream.setCaptureListener(this._capture_listener);
+ this._jmf_processor = processor;
+ this._jmf_processor.start();
+ } catch (Exception e) {
+ ds.disconnect();
+ throw new NyARException(e);
+ }
+ return;
+ }
+
+ public void stop()
+ {
+ this._jmf_processor.stop();
+ this._jmf_processor.close();
+ this._jmf_processor = null;
+ return;
+ }
+ protected void finalize()
+ {
+ if (this._jmf_processor != null) {
+ this._jmf_processor.stop();
+ this._jmf_processor.close();
+ this._jmf_processor = null;
+ }
+ return;
+ }
+}
\ No newline at end of file
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (.../2.2.0) (revision 214)
@@ -27,153 +27,255 @@
package jp.nyatla.nyartoolkit.jmf.utils;

import javax.media.format.*;
+import javax.media.*;
import java.awt.Dimension;
+import com.sun.media.codec.video.colorspace.*;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
import jp.nyatla.nyartoolkit.core.types.*;
+
+
+
/**
- *
- * RGB形式のJMFバッファをラップするNyARRasterです。
- * JMFから得たラスタデータのピクセル並び順を考慮します。
- *
+ * RGB24フォーマットのデータを扱うピクセルリーダ
*/
-public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass
+class NyARBufferReader_Reader_RGB24 extends NyARBufferReader_Reader
{
- protected class Reader implements INyARRgbPixelReader,INyARBufferReader
+ protected boolean _is_flipped;
+ public NyARBufferReader_Reader_RGB24(RGBFormat i_input_format,NyARIntSize i_ref_size) throws NyARException
{
- private int _buffer_type = INyARBufferReader.BUFFERFORMAT_NULL_ALLZERO;
- private byte[] _ref_buf;
- private NyARIntSize _size;
-
- public Reader(NyARIntSize i_size)
- {
- this._size = i_size;
+ super(i_ref_size);
+ //ピクセルフォーマットを設定(現状は24bitRGBを受けつける。)
+ RGBFormat fm=(RGBFormat)i_input_format;
+ if(fm.getBitsPerPixel()!=24){
+ throw new NyARException();
}
- //
- //INyARRgbPixelReader
- //
- public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException
- {
- int bp = (i_x + i_y * this._size.w) * 3;
- byte[] ref = this._ref_buf;
- switch (this._buffer_type) {
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
- o_rgb[0] = (ref[bp + 0] & 0xff);// R
- o_rgb[1] = (ref[bp + 1] & 0xff);// G
- o_rgb[2] = (ref[bp + 2] & 0xff);// B
- break;
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
- o_rgb[0] = (ref[bp + 2] & 0xff);// B
- o_rgb[1] = (ref[bp + 1] & 0xff);// G
- o_rgb[2] = (ref[bp + 0] & 0xff);// R
- break;
- default:
- throw new NyARException();
+ int r=fm.getRedMask();
+ int b=fm.getBlueMask();
+ if(r==1 && b==3){
+ this._buf_type=BUFFERFORMAT_BYTE1D_R8G8B8_24;
+ }else if(r==3 && b==1){
+ this._buf_type=BUFFERFORMAT_BYTE1D_B8G8R8_24;
+ }else{
+ throw new NyARException();
+ }
+ //vertical反転の有無を確認
+ this._is_flipped=i_input_format.getFlipped()!=0?true:false;
+ this._ref_buf=new byte[i_ref_size.w*i_ref_size.h*3];
+ //RGBフォーマット
+
+ return;
+ }
+ public void changeBuffer(javax.media.Buffer i_buffer)
+ {
+ //vertical反転が必要ならば、反転した画像を作成する。
+ byte[] src=(byte[])i_buffer.getData();
+ if(this._is_flipped){
+ final int length = this._ref_size.w * 3;
+ int src_idx = 0;
+ int dest_idx = (this._ref_size.h - 1) * length;
+ for (int i = 0; i < this._ref_size.h; i++) {
+ System.arraycopy(src,src_idx, this._ref_buf, dest_idx, length);
+ src_idx += length;
+ dest_idx -= length;
}
- return;
+ }else{
+ System.arraycopy(src,0,this._ref_buf,0,this._ref_buf.length);
+ this._ref_buf=(byte[])i_buffer.getData();
}
-
- public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException
- {
- int width = this._size.w;
- byte[] ref = this._ref_buf;
- int bp;
- switch (this._buffer_type) {
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
- for (int i = i_num - 1; i >= 0; i--) {
- bp = (i_x[i] + i_y[i] * width) * 3;
- o_rgb[i * 3 + 0] = (ref[bp + 0] & 0xff);// R
- o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G
- o_rgb[i * 3 + 2] = (ref[bp + 2] & 0xff);// B
- }
- break;
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
- for (int i = i_num - 1; i >= 0; i--) {
- bp = (i_x[i] + i_y[i] * width) * 3;
- o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// R
- o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G
- o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// B
- }
- break;
- default:
- throw new NyARException();
+ return;
+ }
+ public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException
+ {
+ int bp = (i_x + i_y * this._ref_size.w) * 3;
+ byte[] ref = this._ref_buf;
+ switch(this._buf_type){
+ case BUFFERFORMAT_BYTE1D_R8G8B8_24:
+ o_rgb[0] = (ref[bp + 0] & 0xff);// R
+ o_rgb[1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[2] = (ref[bp + 2] & 0xff);// B
+ break;
+ case BUFFERFORMAT_BYTE1D_B8G8R8_24:
+ o_rgb[0] = (ref[bp + 2] & 0xff);// B
+ o_rgb[1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[2] = (ref[bp + 0] & 0xff);// R
+ break;
+ default:
+ throw new NyARException();
+ }
+ return;
+ }
+ public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException
+ {
+ int width = this._ref_size.w;
+ byte[] ref = this._ref_buf;
+ int bp;
+ switch(this._buf_type){
+ case BUFFERFORMAT_BYTE1D_R8G8B8_24:
+ for (int i = i_num - 1; i >= 0; i--) {
+ bp = (i_x[i] + i_y[i] * width) * 3;
+ o_rgb[i * 3 + 0] = (ref[bp + 0] & 0xff);// R
+ o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[i * 3 + 2] = (ref[bp + 2] & 0xff);// B
}
- return;
+ break;
+ case BUFFERFORMAT_BYTE1D_B8G8R8_24:
+ for (int i = i_num - 1; i >= 0; i--) {
+ bp = (i_x[i] + i_y[i] * width) * 3;
+ o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// B
+ o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// R
+ }
+ break;
+ default:
+ throw new NyARException();
}
+ return;
+ }
+}

- public void changeBuffer(int i_buffer_type, byte[] i_buffer)
- {
- if(i_buffer_type==1){
- System.out.println("aaa");
+
+
+
+/**
+ * ソースがYUVフォーマットのデータをBGR24として扱うピクセルリーダ
+ * ソースデータをセットした時に変換します。
+ * (将来YUVをそのまま素通りさせるように書き換えるかも)
+ */
+class NyARBufferReader_Reader_YUV extends NyARBufferReader_Reader
+{
+
+ private YUVToRGB _yuv2rgb;
+ private javax.media.Buffer _rgb_buf;
+ /**
+ * フォーマットアレイから、BGR24フォーマットを探す
+ * @param i_formats
+ * @return
+ */
+ private Format pickRGB24Format(Format[] i_formats)
+ {
+ for(int i=0;i<i_formats.length;i++){
+ RGBFormat f=(RGBFormat)i_formats[i];
+ if(f.getBitsPerPixel()!=24){
+ continue;
}
-
- this._buffer_type = i_buffer_type;
- this._ref_buf = i_buffer;
+ if(f.getRedMask()!=3 ||f.getGreenMask()!=2 ||f.getBlueMask()!=1 || f.getFlipped()!=0)
+ {
+ continue;
+ }
+ return f;
}
- //
- //INyARBufferReader
- //
- public Object getBuffer()
- {
- return this._ref_buf;
+ return null;
+ }
+ public NyARBufferReader_Reader_YUV(YUVFormat i_input_format,NyARIntSize i_ref_size) throws NyARException
+ {
+ super(i_ref_size,BUFFERFORMAT_BYTE1D_B8G8R8_24);
+ this._yuv2rgb=new YUVToRGB();
+ this._rgb_buf=new javax.media.Buffer();
+ this._ref_buf=null;
+ //24bit-RGBフォーマットのものを探す
+ Format output_format=pickRGB24Format(this._yuv2rgb.getSupportedOutputFormats(i_input_format));
+ if(output_format==null){
+ throw new NyARException();
}
- public int getBufferType()
- {
- return _buffer_type;
+ this._yuv2rgb.setInputFormat(i_input_format);
+ this._yuv2rgb.setOutputFormat(output_format);
+ try{
+ this._yuv2rgb.open();
+ }catch(Exception e){
+ throw new NyARException();
}
- public boolean isEqualBufferType(int i_type_value)
- {
- return this._buffer_type==i_type_value;
- }
+ return;
}
+ public void changeBuffer(javax.media.Buffer i_buffer)
+ {
+ //エラー出した時のトラップ
+ if(this._yuv2rgb.process(i_buffer, this._rgb_buf)!=YUVToRGB.BUFFER_PROCESSED_OK){
+ System.err.println("YUVToRGB.process error:");
+ }
+ this._ref_buf=(byte[])this._rgb_buf.getData();
+ return;
+ }
+ public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException
+ {
+ int bp = (i_x + i_y * this._ref_size.w) * 3;
+ byte[] ref = this._ref_buf;
+ o_rgb[0] = (ref[bp + 2] & 0xff);// B
+ o_rgb[1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[2] = (ref[bp + 0] & 0xff);// R
+ return;
+ }
+ public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException
+ {
+ int width = this._ref_size.w;
+ byte[] ref = this._ref_buf;
+ int bp;
+ for (int i = i_num - 1; i >= 0; i--) {
+ bp = (i_x[i] + i_y[i] * width) * 3;
+ o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// B
+ o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G
+ o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// R
+ }
+ return;
+ }
+}

- protected byte[] _ref_buf;
- protected Reader _reader;
+
+/**
+ *
+ * RGB形式のJMFバッファをラップするNyARRasterです。
+ * JMFから得たラスタデータのピクセル並び順を考慮します。
+ *
+ */
+public class JmfNyARRaster_RGB extends NyARRgbRaster_BasicClass
+{
+
+ protected NyARBufferReader_Reader _reader;
/**
- * RGB形式のJMFバッファをラップするオブジェクトをつくります。 生成直後のオブジェクトはデータを持ちません。
- * メンバ関数はsetBufferを実行後に使用可能になります。
+ * i_formatに一致する画素フォーマットの
+ * @param i_size
+ * @param i_format
+ * @throws NyARException
*/
- public JmfNyARRaster_RGB(NyARIntSize i_size)
+
+
+ public JmfNyARRaster_RGB(NyARIntSize i_ref_size,VideoFormat i_format) throws NyARException
{
- super(new NyARIntSize(i_size.w,i_size.w));
- this._size.w = i_size.w;
- this._size.h = i_size.h;
- this._ref_buf = null;
- this._reader = new Reader(this._size);
+ super(new NyARIntSize(i_ref_size));
+ this._reader = createReader(i_format);
}
- public JmfNyARRaster_RGB(int i_width,int i_height)
+ public JmfNyARRaster_RGB(int i_width,int i_height,VideoFormat i_format) throws NyARException
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf = null;
- this._reader = new Reader(this._size);
- }
+ this._reader = createReader(i_format);
+ }

/**
- * フォーマットを解析して、ラスタタイプを返します。
- *
+ * フォーマットを解析して、マッチするリーダオブジェクトを返します。
* @param i_fmt
+ * ビデオフォーマットを指定します。
+ * @return
+ * リーダオブジェクト
* @throws NyARException
*/
- protected int analyzeBufferType(RGBFormat i_fmt) throws NyARException
+ private NyARBufferReader_Reader createReader(VideoFormat i_fmt) throws NyARException
{
// データサイズの確認
- Dimension s = i_fmt.getSize();
+ final Dimension s = i_fmt.getSize();
if (!this._size.isEqualSize(s.width, s.height)) {
throw new NyARException();
}
// データ配列の確認
- int r = i_fmt.getRedMask() - 1;
- int b = i_fmt.getBlueMask() - 1;
-
- // 色配列の特定
- if (r == 0 && b == 2) {
- return INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;
- } else if (r == 2 && b == 0) {
- return INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24;
- } else {
- throw new NyARException("Unknown pixel order.");
+ if(i_fmt instanceof YUVFormat){
+ //YUVフォーマット
+ return new NyARBufferReader_Reader_YUV((YUVFormat)i_fmt,this._size);
+ }else if(i_fmt instanceof RGBFormat){
+ //RGBフォーマット
+ return new NyARBufferReader_Reader_RGB24((RGBFormat)i_fmt,this._size);
+ }else{
+ throw new NyARException();
}
}

@@ -188,20 +290,17 @@
*/
public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
{
- int buftype= analyzeBufferType((RGBFormat) i_buffer.getFormat());
- this._ref_buf = (byte[]) i_buffer.getData();
- this._reader.changeBuffer(buftype, this._ref_buf);
+ this._reader.changeBuffer(i_buffer);
+ return;
}
-
/**
* データを持っているかを返します。
* @return
*/
public boolean hasData()
{
- return this._ref_buf != null;
+ return this._reader._ref_buf != null;
}
-
public INyARRgbPixelReader getRgbPixelReader()
{
return this._reader;
@@ -211,3 +310,6 @@
return this._reader;
}

}
+
+
+
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (.../2.2.0) (revision 214)
@@ -27,110 +27,114 @@
*/
package jp.nyatla.nyartoolkit.jmf.utils;

-
import javax.media.*;
import javax.media.protocol.*;
import javax.media.control.*;

import java.io.IOException;

+public class MonitorCDS extends PushBufferDataSource
+{

+ private PushBufferDataSource delegate = null;

-public class MonitorCDS extends PushBufferDataSource{
+ private PushBufferStream[] delStreams = null;

- private PushBufferDataSource delegate = null;
- private PushBufferStream [] delStreams = null;
- private MonitorStream monitorStream = null;
- private PushBufferStream [] monitorStreams = null;
- boolean delStarted = false; // variable used by MonitorStream also
- private Control [] controls;
+ private MonitorStream monitorStream = null;

- public MonitorCDS(DataSource ds)
- {
- // Get the stream from the actual datasource
- // and create a MonitorStream from it
- // Export the MonitorControl interface of the MonitorStream
- if (ds instanceof PushBufferDataSource)
+ private PushBufferStream[] monitorStreams = null;
+
+ boolean delStarted = false; // variable used by MonitorStream also
+
+ private Control[] controls;
+
+ public MonitorCDS(DataSource ds)
{
- delegate = (PushBufferDataSource) ds;
- delStreams = delegate.getStreams();
- monitorStream = new MonitorStream(delStreams[0], this);
- monitorStreams = new PushBufferStream[] {monitorStream};
+ // Get the stream from the actual datasource
+ // and create a MonitorStream from it
+ // Export the MonitorControl interface of the MonitorStream
+ if (ds instanceof PushBufferDataSource) {
+ delegate = (PushBufferDataSource) ds;
+ delStreams = delegate.getStreams();
+ monitorStream = new MonitorStream(delStreams[0], this);
+ monitorStreams = new PushBufferStream[] { monitorStream };
+ }
}
- }

- public Object [] getControls()
- {
- return controls;
- }
+ public Object[] getControls()
+ {
+ return controls;
+ }

- public Object getControl(String value) {
- if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
- return monitorStream;
- else
- return null;
- }
+ public Object getControl(String value)
+ {
+ if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl")){
+ return monitorStream;
+ }else{
+ return null;
+ }
+ }

- public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
- {
- return ((CaptureDevice)delegate).getCaptureDeviceInfo();
- }
+ public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
+ {
+ return ((CaptureDevice) delegate).getCaptureDeviceInfo();
+ }

- public FormatControl[] getFormatControls()
- {
- return ((CaptureDevice)delegate).getFormatControls();
- }
+ public FormatControl[] getFormatControls()
+ {
+ return ((CaptureDevice) delegate).getFormatControls();
+ }

- public String getContentType()
- {
- return delegate.getContentType();
- }
+ public String getContentType()
+ {
+ return delegate.getContentType();
+ }

- public void connect() throws IOException
- {
- if (delegate == null)
- throw new IOException("Incompatible DataSource");
- // Delegate is already connected
- }
+ public void connect() throws IOException
+ {
+ if (delegate == null)
+ throw new IOException("Incompatible DataSource");
+ // Delegate is already connected
+ }

- public void disconnect()
- {
- monitorStream.setEnabled(false);
- delegate.disconnect();
- }
+ public void disconnect()
+ {
+ monitorStream.setEnabled(false);
+ delegate.disconnect();
+ }

- public synchronized void start() throws IOException
- {
- startDelegate();
- delStarted = true;
- }
+ public synchronized void start() throws IOException
+ {
+ startDelegate();
+ delStarted = true;
+ }

- public synchronized void stop() throws IOException
- {
- if (!monitorStream.isEnabled()) {
- stopDelegate();
+ public synchronized void stop() throws IOException
+ {
+ if (!monitorStream.isEnabled()) {
+ stopDelegate();
+ }
+ delStarted = false;
}
- delStarted = false;
- }

- public Time getDuration()
- {
- return delegate.getDuration();
- }
+ public Time getDuration()
+ {
+ return delegate.getDuration();
+ }

- public PushBufferStream [] getStreams()
- {
- return monitorStreams;
- }
+ public PushBufferStream[] getStreams()
+ {
+ return monitorStreams;
+ }

- void startDelegate() throws IOException
- {
- delegate.start();
- }
+ void startDelegate() throws IOException
+ {
+ delegate.start();
+ }

- void stopDelegate() throws IOException
- {
- delegate.stop();
- }
+ void stopDelegate() throws IOException
+ {
+ delegate.stop();
+ }

}
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java (.../2.2.0) (revision 214)
@@ -40,15 +40,22 @@
*/
public class JmfCaptureTest extends Frame implements JmfCaptureListener
{
+ private static final long serialVersionUID = -2110888320986446576L;
+ private JmfCaptureDevice _capture;
public JmfCaptureTest() throws NyARException
{
setTitle("JmfCaptureTest");
setBounds(0, 0, 320 + 64, 240 + 64);
- capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
- capture.setCaptureListener(this);
+ 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);
}

- private JmfCameraCapture capture;

public void onUpdateBuffer(Buffer i_buffer)
{
@@ -61,7 +68,7 @@
private void startCapture()
{
try {
- capture.start();
+ this._capture.start();
} catch (Exception e) {
e.printStackTrace();
}
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (.../2.2.0) (revision 214)
@@ -27,8 +27,6 @@
*/
package jp.nyatla.nyartoolkit.jmf.utils;

-
-
import javax.media.*;
import javax.media.protocol.*;

@@ -36,161 +34,161 @@
import java.io.IOException;
import java.awt.*;

-public class MonitorStream implements PushBufferStream, BufferTransferHandler {
+public class MonitorStream implements PushBufferStream, BufferTransferHandler
+{

- JmfCaptureListener img_listener;
- PushBufferStream actual = null;
- boolean dataAvailable = false;
- boolean terminate = false;
- boolean enabled = false;
- Object bufferLock = new Object();
- Buffer cbuffer = new Buffer();
- BufferTransferHandler transferHandler = null;
- Component component = null;
- MonitorCDS cds;
- BufferToImage bti = null;
-
- MonitorStream(PushBufferStream actual, MonitorCDS cds) {
- this.actual = actual;
- actual.setTransferHandler(this);
- this.cds = cds;
- }
+ JmfCaptureListener img_listener;

- public javax.media.Format getFormat()
- {
- return actual.getFormat();
- }
- /**
- * 非同期READ
- */
- public void read(Buffer buffer) throws IOException
- {
- // Wait for data to be available
- // Doesn't get used much because the transferData
- // call is made when data IS available. And most
- // Processors/Players read the data in the same
- // thread that called transferData, although that's

- // not a safe assumption to make
- if (!dataAvailable) {
- synchronized (bufferLock) {
- while (!dataAvailable && !terminate) {
- try {
- bufferLock.wait(100);
- } catch (InterruptedException ie) {
- }
- }
- }
+ PushBufferStream actual = null;
+
+ boolean dataAvailable = false;
+
+ boolean terminate = false;
+
+ boolean enabled = false;
+
+ Object bufferLock = new Object();
+
+ Buffer cbuffer = new Buffer();
+
+ BufferTransferHandler transferHandler = null;
+
+ Component component = null;
+
+ MonitorCDS cds;
+
+ BufferToImage bti = null;
+
+ MonitorStream(PushBufferStream actual, MonitorCDS cds)
+ {
+ this.actual = actual;
+ actual.setTransferHandler(this);
+ this.cds = cds;
}

- if (dataAvailable) {
- synchronized (bufferLock) {
- // Copy the buffer attributes, but swap the data
- // attributes so that no extra copy is made.
- buffer.copy(cbuffer, true);
- //dataAvailable = false;
- }
+ public javax.media.Format getFormat()
+ {
+ return actual.getFormat();
}
-// return;
- }
- public void setCaptureListener(JmfCaptureListener i_listener)
- {
- img_listener=i_listener;
- }

- public void transferData(PushBufferStream pbs)
- {
- // Get the data from the original source stream
- synchronized (bufferLock) {
- try {
- pbs.read(cbuffer);
- } catch (IOException ioe) {
- return;
- }
- dataAvailable = true;
- bufferLock.notifyAll();
+ /**
+ * 非同期READ
+ */
+ public void read(Buffer buffer) throws IOException
+ {
+ // Wait for data to be available
+ // Doesn't get used much because the transferData
+ // call is made when data IS available. And most
+ // Processors/Players read the data in the same
+ // thread that called transferData, although that's
+ // not a safe assumption to make
+ if (!dataAvailable) {
+ synchronized (bufferLock) {
+ while (!dataAvailable && !terminate) {
+ try {
+ bufferLock.wait(100);
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+ }
+
+ if (dataAvailable) {
+ synchronized (bufferLock) {
+ // Copy the buffer attributes, but swap the data
+ // attributes so that no extra copy is made.
+ buffer.copy(cbuffer, true);
+ //dataAvailable = false;
+ }
+ }
+ // return;
}
- if(img_listener!=null){
- img_listener.onUpdateBuffer(cbuffer);
+
+ public void setCaptureListener(JmfCaptureListener i_listener)
+ {
+ img_listener = i_listener;
}
-
-/*
- // 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);
- }
+
+ public void transferData(PushBufferStream pbs)
+ {
+ // Get the data from the original source stream
+ synchronized (bufferLock) {
+ try {
+ pbs.read(cbuffer);
+ } catch (IOException ioe) {
+ return;
+ }
+ dataAvailable = true;
+ bufferLock.notifyAll();
+ }
+ if (img_listener != null) {
+ img_listener.onUpdateBuffer(cbuffer);
+ }
+
+ // Maybe synchronize this with setTransferHandler() ?
+ if (transferHandler != null && cds.delStarted)
+ transferHandler.transferData(this);
}
-*/
- // Maybe synchronize this with setTransferHandler() ?
- if (transferHandler != null && cds.delStarted)
- transferHandler.transferData(this);
- }

- public void setTransferHandler(BufferTransferHandler transferHandler) {
- this.transferHandler = transferHandler;
- }
+ public void setTransferHandler(BufferTransferHandler transferHandler)
+ {
+ this.transferHandler = transferHandler;
+ }

- public boolean setEnabled(boolean value) {
- enabled = value;
- if (value == false) {
- if (!cds.delStarted) {
- try {
- cds.stopDelegate();
- } catch (IOException ioe) {
+ public boolean setEnabled(boolean value)
+ {
+ enabled = value;
+ if (value == false) {
+ if (!cds.delStarted) {
+ try {
+ cds.stopDelegate();
+ } catch (IOException ioe) {
+ }
+ }
+ } else {
+ // Start the capture datasource if the monitor is enabled
+ try {
+ cds.startDelegate();
+ } catch (IOException ioe) {
+ }
}
- }
- } else {
- // Start the capture datasource if the monitor is enabled
- try {
- cds.startDelegate();
- }catch (IOException ioe) {
- }
+ return enabled;
}
- return enabled;
- }

- public boolean isEnabled()
- {
- return enabled;
- }
+ public boolean isEnabled()
+ {
+ return enabled;
+ }

+ public float setPreviewFrameRate(float rate)
+ {
+ System.err.println("TODO");
+ return rate;
+ }

+ public ContentDescriptor getContentDescriptor()
+ {
+ return actual.getContentDescriptor();
+ }

- public float setPreviewFrameRate(float rate)
- {
- System.err.println("TODO");
- return rate;
- }
-
- public ContentDescriptor getContentDescriptor()
- {
- return actual.getContentDescriptor();
- }
+ public long getContentLength()
+ {
+ return actual.getContentLength();
+ }

- public long getContentLength()
- {
- return actual.getContentLength();
- }
+ public boolean endOfStream()
+ {
+ return actual.endOfStream();
+ }

- public boolean endOfStream() {
- return actual.endOfStream();
- }
+ public Object[] getControls()
+ {
+ return new Object[0];
+ }

- public Object [] getControls() {
- return new Object[0];
- }
+ public Object getControl(String str)
+ {
+ return null;
+ }

- public Object getControl(String str) {
- return null;
- }
-
-
}
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (.../2.2.0) (revision 214)
@@ -33,5 +33,4 @@
*/
public interface JmfCaptureListener{
public void onUpdateBuffer(Buffer i_buffer);
-
}
\ No newline at end of file
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java (.../2.1.0) (revision 0)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/NyARBufferReader_Reader.java (.../2.2.0) (revision 214)
@@ -0,0 +1,63 @@
+/*
+ * PROJECT: NyARToolkit JMF utilities.
+ * --------------------------------------------------------------------------------
+ * The MIT License
+ * Copyright (c) 2008 nyatla
+ * airmail(at)ebony.plala.or.jp
+ * http://nyatla.jp/nyartoolkit/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+package jp.nyatla.nyartoolkit.jmf.utils;
+
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARRgbPixelReader;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+
+public abstract class NyARBufferReader_Reader implements INyARRgbPixelReader,INyARBufferReader
+{
+ protected byte[] _ref_buf;
+ protected NyARIntSize _ref_size;
+ protected int _buf_type;
+ protected NyARBufferReader_Reader(NyARIntSize i_ref_size,int i_buf_type)
+ {
+ this._ref_size =i_ref_size;
+ this._buf_type=i_buf_type;
+ return;
+ }
+ protected NyARBufferReader_Reader(NyARIntSize i_ref_size)
+ {
+ this._ref_size =i_ref_size;
+ return;
+ }
+ final public Object getBuffer()
+ {
+ return this._ref_buf;
+ }
+ final public int getBufferType()
+ {
+ return this._buf_type;
+ }
+ final public boolean isEqualBufferType(int i_type_value)
+ {
+ return this._buf_type==i_type_value;
+ }
+ public abstract void changeBuffer(javax.media.Buffer i_buffer);
+
+}
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (.../2.1.0) (revision 214)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (.../2.2.0) (revision 214)
@@ -35,12 +35,15 @@
import javax.media.protocol.DataSource;

import jp.nyatla.nyartoolkit.NyARException;
+
/**
* 簡易JMFキャプチャクラス
- * @author atla
+ * @deprecated このクラスは近い将来削除します。
+ * JmfCaptureDeviceList/JmfCaptureDeviceを使用してください。
+ * {@link #JmfCaptureDeviceList()}
*
*/
-public class JmfCameraCapture
+@Deprecated public class JmfCameraCapture
{
private Dimension image_size;

@@ -84,7 +87,8 @@

public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException
{
- if (jmf_processor != null) {
+ if (jmf_processor != null)
+ {
throw new NyARException();
}
capture_listener = i_listener;
Index: src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java
===================================================================
--- src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java (.../2.1.0) (revision 0)
+++ src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java (.../2.2.0) (revision 214)
@@ -0,0 +1,101 @@
+package jp.nyatla.nyartoolkit.jmf.utils;
+
+import java.awt.Dimension;
+import java.util.Vector;
+
+import javax.media.CaptureDeviceInfo;
+import javax.media.CaptureDeviceManager;
+import javax.media.Format;
+import javax.media.format.*;
+import jp.nyatla.nyartoolkit.*;
+
+
+
+/**
+ * JMFキャプチャデバイスのリストを保持します。
+ * 複数のカメラが接続された環境では、最も初めに認識したカメラの実がアクティブになるため、
+ * このクラスで実際に認識できるカメラは1個だけです。
+ *
+ */
+public class JmfCaptureDeviceList
+{
+ private Vector _devices;
+
+ public JmfCaptureDeviceList() throws NyARException
+ {
+ this._devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone();
+ // ビデオソースのデバイスだけ残す
+ try {
+
+ for (int i = 0; i < this._devices.size();) {
+ CaptureDeviceInfo cdi = (CaptureDeviceInfo) this._devices.elementAt(i);
+ // VideoFormatもってるかな?
+ if (!isCaptureDevice(cdi)) {
+ this._devices.remove(i);
+ continue;
+ }
+ i++;
+ }
+ } catch (Exception e) {
+ throw new NyARException(e);
+ }
+ return;
+ }
+
+ /**
+ * i_cdiがビデオキャプチャデバイスかを調べる。ようなことをする。
+ *
+ * @param i_cdi
+ * @return
+ */
+ private static boolean isCaptureDevice(CaptureDeviceInfo i_cdi)
+ {
+ Format[] fms = i_cdi.getFormats();
+ for (int i = 0; i < fms.length; i++) {
+ Format f = fms[i];
+ if (f instanceof VideoFormat) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 使用できるキャプチャデバイスの数を数える
+ * @return
+ * キャプチャデバイスの数を返却する。
+ */
+ public int getCount()
+ {
+ return this._devices.size();
+ }
+ /**
+ * i_index番目のキャプチャデバイスを得る。
+ * @param i_index
+ * @return
+ * @throws NyARException
+ */
+ public JmfCaptureDevice getDevice(int i_index) throws NyARException
+ {
+ return new JmfCaptureDevice((CaptureDeviceInfo) this._devices.elementAt(i_index));
+ }
+
+ public static void main(String[] args)
+ {
+ //テストケース
+ try {
+ JmfCaptureDeviceList j = new JmfCaptureDeviceList();
+ System.out.println(j.getCount());
+ JmfCaptureDevice d = j.getDevice(0);
+ d.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB, new Dimension(320, 240), 15.0f);
+// YUVFormat f=(YUVFormat)d.getCaptureFormat();
+ d.start();
+ d.stop();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+
+}
Index: src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java (.../2.2.0) (revision 214)
@@ -30,18 +30,25 @@
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;
-
+/**
+ * このインタフェイスは、画素データを格納するバッファオブジェクト
+ * へのアクセス方法と、その形式を定義します。
+ *
+ */
public interface INyARBufferReader
{
+ public static final int BYTE1D =0x00010000;
+ public static final int INT2D =0x00020000;
+ public static final int SHORT1D=0x00030000;
+ public static final int INT1D =0x00040000;
// ID規約
- // 00-07(8)型番号
+ // 24-31(8)予約
+ // 16-27(8)型ID
+ // 00:無効/01:byte[]/02:int[][]/03:short[]
// 08-15(8)ビットフォーマットID
// 00:24bit/01:32bit/02:16bit
- // 16-27(8)型ID
- // 00:無効/01:byte[]/02:int[][]/03:short[]
- // 24-31(8)予約
+ // 00-07(8)型番号
//
-
/**
* RGB24フォーマットで、全ての画素が0
*/
@@ -50,46 +57,73 @@
/**
* byte[]で、R8G8B8の24ビットで画素が格納されている。
*/
- public static final int BUFFERFORMAT_BYTE1D_R8G8B8_24 = 0x00010001;
-
+ public static final int BUFFERFORMAT_BYTE1D_R8G8B8_24 = BYTE1D|0x0001;
/**
* byte[]で、B8G8R8の24ビットで画素が格納されている。
*/
- public static final int BUFFERFORMAT_BYTE1D_B8G8R8_24 = 0x00010002;
-
+ public static final int BUFFERFORMAT_BYTE1D_B8G8R8_24 = BYTE1D|0x0002;
/**
* byte[]で、R8G8B8X8の32ビットで画素が格納されている。
*/
- public static final int BUFFERFORMAT_BYTE1D_B8G8R8X8_32 = 0x00010101;
+ public static final int BUFFERFORMAT_BYTE1D_B8G8R8X8_32 = BYTE1D|0x0101;

/**
* byte[]で、RGB565の16ビット(little/big endian)で画素が格納されている。
*/
- public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16LE = 0x00010201;
- public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16BE = 0x00010202;
+ public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16LE = BYTE1D|0x0201;
+ public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16BE = BYTE1D|0x0202;
/**
* short[]で、RGB565の16ビット(little/big endian)で画素が格納されている。
*/
- public static final int BUFFERFORMAT_WORD1D_R5G6B5_16LE = 0x00030201;
- public static final int BUFFERFORMAT_WORD1D_R5G6B5_16BE = 0x00030202;
+ public static final int BUFFERFORMAT_WORD1D_R5G6B5_16LE = SHORT1D|0x0201;
+ public static final int BUFFERFORMAT_WORD1D_R5G6B5_16BE = SHORT1D|0x0202;


/**
* int[][]で特に値範囲を定めない
*/
- public static final int BUFFERFORMAT_INT2D = 0x00020000;
-
+ public static final int BUFFERFORMAT_INT2D = INT2D|0x0000;
/**
* int[][]で0-255のグレイスケール画像
*/
- public static final int BUFFERFORMAT_INT2D_GLAY_8 = 0x00020001;
-
+ public static final int BUFFERFORMAT_INT2D_GLAY_8 = INT2D|0x0001;
/**
* int[][]で0/1の2値画像
*/
- public static final int BUFFERFORMAT_INT2D_BIN_8 = 0x00020002;
+ public static final int BUFFERFORMAT_INT2D_BIN_8 = INT2D|0x0002;

+ /**
+ * int[]で特に値範囲を定めない
+ */
+ public static final int BUFFERFORMAT_INT1D = INT1D|0x0000;
+ /**
+ * int[]で0-255のグレイスケール画像
+ */
+ public static final int BUFFERFORMAT_INT1D_GLAY_8 = INT1D|0x0001;
+ /**
+ * int[]で特に値範囲を定めない
+ */
+ public static final int BUFFERFORMAT_INT1D_BIN_8 = INT1D|0x0002;
+ /**
+ * int[]で、XRGB32の32ビットで画素が格納されている。
+ */
+ public static final int BUFFERFORMAT_INT1D_X8R8G8B8_32 = INT1D|0x0102;
+
+
+ /**
+ * バッファオブジェクトを返します。
+ * @return
+ */
public Object getBuffer();
+ /**
+ * バッファオブジェクトの形式を返します。
+ * @return
+ */
public int getBufferType();
+ /**
+ * バッファオブジェクトの形式が、i_type_valueにが一致するか返します。
+ * @param i_type_value
+ * @return
+ */
public boolean isEqualBufferType(int i_type_value);
}
Index: src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java (.../2.2.0) (revision 214)
@@ -35,10 +35,15 @@
{
protected Object _buffer;
protected int _buffer_type;
+ protected NyARBufferReader()
+ {
+ return;
+ }
public NyARBufferReader(Object i_buffer,int i_buffer_type)
{
this._buffer=i_buffer;
this._buffer_type=i_buffer_type;
+ return;
}
public Object getBuffer()
{
Index: src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java (.../2.2.0) (revision 214)
@@ -32,7 +32,6 @@
package jp.nyatla.nyartoolkit.core.pca2d;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;

Index: src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java (.../2.2.0) (revision 214)
@@ -177,8 +177,7 @@
double err, minerr = 0;
int i,i2;
int best_idx=0;
-
- io_rot.getAngle(angle);// arGetAngle( rot, &a, &b, &c );
+ angle.copyFrom(io_rot.refAngle());// arGetAngle( rot, &a, &b, &c );
factor = 10.0 * Math.PI / 180.0;
for (int j = 0; j < 10; j++){
minerr = 1000000000.0;
Index: src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java (.../2.2.0) (revision 214)
@@ -76,7 +76,6 @@
}

private final double[][] __modifyMatrix_double1D = new double[8][3];
- private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();
/**
* arGetRot計算を階層化したModifyMatrix 896
*
@@ -157,7 +156,6 @@
double SACASC, SACACBSC, SACACBCC, SACACC;
final double[][] double1D = this.__modifyMatrix_double1D;

- final NyARDoublePoint3d angle = this.__modifyMatrix_angle;

final double[] a_factor = double1D[1];
final double[] sinb = double1D[2];
@@ -169,7 +167,8 @@
double w, w2;
double wsin, wcos;

- io_rot.getAngle(angle);// arGetAngle( rot, &a, &b, &c );
+ //現在の角度を確保
+ final NyARDoublePoint3d angle = io_rot.refAngle();
a2 = angle.x;
b2 = angle.y;
c2 = angle.z;
Index: src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java (.../2.2.0) (revision 214)
@@ -76,11 +76,9 @@
}

private final double[][] __modifyMatrix_double1D = new double[8][3];
- private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();
/**
* arGetRot計算を階層化したModifyMatrix 896
*
- * @param nyrot
* @param trans
* @param i_vertex3d
* [m][3]
@@ -137,7 +135,6 @@
double SACASC, SACACBSC, SACACBCC, SACACC;
final double[][] double1D = this.__modifyMatrix_double1D;

- final NyARDoublePoint3d angle = this.__modifyMatrix_angle;
final double[] a_factor = double1D[1];
final double[] sinb = double1D[2];
final double[] cosb = double1D[3];
@@ -148,7 +145,7 @@
double w, w2;
double wsin, wcos;

- io_rot.getAngle(angle);// arGetAngle( rot, &a, &b, &c );
+ final NyARDoublePoint3d angle = io_rot.refAngle();
a2 = angle.x;
b2 = angle.y;
c2 = angle.z;
Index: src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (.../2.2.0) (revision 214)
@@ -33,6 +33,7 @@


import jp.nyatla.nyartoolkit.core.types.matrix.*;
+import jp.nyatla.nyartoolkit.core.types.*;

/**
* NyARTransMat戻り値専用のNyARMat
@@ -41,4 +42,5 @@
public class NyARTransMatResult extends NyARDoubleMatrix34
{
public boolean has_value = false;
+ public NyARDoublePoint3d angle=new NyARDoublePoint3d();
}
Index: src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (.../2.2.0) (revision 214)
@@ -70,7 +70,10 @@
final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
this._calculator=new NyARFitVecCalculator(pmat,dist);
- this._rotmatrix = new NyARRotMatrix_ARToolKit(pmat);
+ //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
+ //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
+ this._rotmatrix = new NyARRotMatrix_NyARToolKit(pmat);
+// this._rotmatrix = new NyARRotMatrix_ARToolKit(pmat);
this._mat_optimize=new NyARRotTransOptimize_O2(pmat);
}

@@ -234,6 +237,7 @@
o_result.m22 = i_rot.m22;
o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;

+ o_result.angle.copyFrom(i_rot.refAngle());
o_result.has_value = true;
return;
}
Index: src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java (.../2.1.0) (revision 0)
+++ src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java (.../2.2.0) (revision 214)
@@ -0,0 +1,86 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java version ARToolkit class library.
+ * Copyright (C)2008 R.Iizuka
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this framework; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+/**
+ * 回転行列計算用の、3x3行列
+ * 計算方法はARToolKitと同じだが、ARToolKitにある不要な行列から角度を逆算する
+ * 処理を省略しているため、下位12桁目の計算値が異なる。
+ *
+ */
+public class NyARRotMatrix_NyARToolKit extends NyARRotMatrix_ARToolKit
+{
+ /**
+ * インスタンスを準備します。
+ *
+ * @param i_param
+ */
+ public NyARRotMatrix_NyARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
+ {
+ super(i_matrix);
+ return;
+ }
+ public final void setAngle(final double i_x, final double i_y, final double i_z)
+ {
+ final double sina = Math.sin(i_x);
+ final double cosa = Math.cos(i_x);
+ final double sinb = Math.sin(i_y);
+ final double cosb = Math.cos(i_y);
+ final double sinc = Math.sin(i_z);
+ final double cosc = Math.cos(i_z);
+ // Optimize
+ final double CACA = cosa * cosa;
+ final double SASA = sina * sina;
+ final double SACA = sina * cosa;
+ final double SASB = sina * sinb;
+ final double CASB = cosa * sinb;
+ final double SACACB = SACA * cosb;
+
+ this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
+ this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
+ this.m02 = CASB;
+ this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
+ this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
+ this.m12 = SASB;
+ this.m20 = -CASB * cosc - SASB * sinc;
+ this.m21 = CASB * sinc - SASB * cosc;
+ this.m22 = cosb;
+ //angleを逆計算せずに直接代入
+ this._angle.x=i_x;
+ this._angle.y=i_y;
+ this._angle.z=i_z;
+ return;
+ }
+
+}
Index: src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (.../2.2.0) (revision 214)
@@ -48,13 +48,11 @@
public abstract void initRotByPrevResult(NyARTransMatResult i_prev_result);
public abstract void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException;
/**
- * int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )
- * Optimize:2008.04.20:STEP[481→433]
- * 3x3変換行列から、回転角を復元して返します。
- * @param o_angle
+ * 格納しているAngleの参照値を返します。
+ * 返したオブジェクトはクラスに所有し続けられ、内容が変わることがあります。
* @return
*/
- public abstract void getAngle(final NyARDoublePoint3d o_angle);
+ public abstract NyARDoublePoint3d refAngle();
/**
* 回転角から回転行列を計算してセットします。
* @param i_x
Index: src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (.../2.2.0) (revision 214)
@@ -50,10 +50,13 @@
{
this.__initRot_vec1=new NyARRotVector(i_matrix);
this.__initRot_vec2=new NyARRotVector(i_matrix);
+ this._angle=new NyARDoublePoint3d();
return;
}
final private NyARRotVector __initRot_vec1;
final private NyARRotVector __initRot_vec2;
+ final protected NyARDoublePoint3d _angle;
+



@@ -108,29 +111,99 @@
this.m02 = w02/w;
this.m12 = w12/w;
this.m22 = w22/w;
+ //Matrixからangleをロード
+ this.updateAngleFromMatrix();
return;
}
+ public final NyARDoublePoint3d refAngle()
+ {
+ return this._angle;
+ }
+ /**
+ * 回転角から回転行列を計算してセットします。
+ * @param i_x
+ * @param i_y
+ * @param i_z
+ */
+ public void setAngle(final double i_x, final double i_y, final double i_z)
+ {
+ final double sina = Math.sin(i_x);
+ final double cosa = Math.cos(i_x);
+ final double sinb = Math.sin(i_y);
+ final double cosb = Math.cos(i_y);
+ final double sinc = Math.sin(i_z);
+ final double cosc = Math.cos(i_z);
+ // Optimize
+ final double CACA = cosa * cosa;
+ final double SASA = sina * sina;
+ final double SACA = sina * cosa;
+ final double SASB = sina * sinb;
+ final double CASB = cosa * sinb;
+ final double SACACB = SACA * cosb;

-
-
+ this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
+ this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
+ this.m02 = CASB;
+ this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
+ this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
+ this.m12 = SASB;
+ this.m20 = -CASB * cosc - SASB * sinc;
+ this.m21 = CASB * sinc - SASB * cosc;
+ this.m22 = cosb;
+ updateAngleFromMatrix();
+ return;
+ }
/**
- * int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )
- * Optimize:2008.04.20:STEP[481→433]
- * 3x3変換行列から、回転角を復元して返します。
+ * i_in_pointを変換行列で座標変換する。
+ * @param i_in_point
+ * @param i_out_point
+ */
+ public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)
+ {
+ final double x=i_in_point.x;
+ final double y=i_in_point.y;
+ final double z=i_in_point.z;
+ i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;
+ i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;
+ i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;
+ return;
+ }
+ /**
+ * 複数の頂点を一括して変換する
+ * @param i_in_point
+ * @param i_out_point
+ * @param i_number_of_vertex
+ */
+ public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)
+ {
+ for(int i=i_number_of_vertex-1;i>=0;i--){
+ final NyARDoublePoint3d out_ptr=i_out_point[i];
+ final NyARDoublePoint3d in_ptr=i_in_point[i];
+ final double x=in_ptr.x;
+ final double y=in_ptr.y;
+ final double z=in_ptr.z;
+ out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;
+ out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;
+ out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;
+ }
+ return;
+ }
+ /**
+ * 現在のMatrixからangkeを復元する。
* @param o_angle
- * @return
*/
- public final void getAngle(final NyARDoublePoint3d o_angle)
+ private final void updateAngleFromMatrix()
{
double a,b,c;
double sina, cosa, sinb,cosb,sinc, cosc;

if (this.m22 > 1.0) {// <Optimize/>if( rot[2][2] > 1.0 ) {
- this.m22 = 1.0;// <Optimize/>rot[2][2] = 1.0;
+ cosb = 1.0;// <Optimize/>rot[2][2] = 1.0;
} else if (this.m22 < -1.0) {// <Optimize/>}else if( rot[2][2] < -1.0 ) {
- this.m22 = -1.0;// <Optimize/>rot[2][2] = -1.0;
+ cosb = -1.0;// <Optimize/>rot[2][2] = -1.0;
+ }else{
+ cosb =this.m22;// <Optimize/>cosb = rot[2][2];
}
- cosb =this.m22;// <Optimize/>cosb = rot[2][2];
b = Math.acos(cosb);
sinb =Math.sin(b);
final double rot02=this.m02;
@@ -139,22 +212,18 @@
cosa = rot02 / sinb;// <Optimize/>cosa = rot[0][2] / sinb;
sina = rot12 / sinb;// <Optimize/>sina = rot[1][2] / sinb;
if (cosa > 1.0) {
- /* printf("cos(alph) = %f\n", cosa); */
cosa = 1.0;
sina = 0.0;
}
if (cosa < -1.0) {
- /* printf("cos(alph) = %f\n", cosa); */
cosa = -1.0;
sina = 0.0;
}
if (sina > 1.0) {
- /* printf("sin(alph) = %f\n", sina); */
sina = 1.0;
cosa = 0.0;
}
if (sina < -1.0) {
- /* printf("sin(alph) = %f\n", sina); */
sina = -1.0;
cosa = 0.0;
}
@@ -162,31 +231,23 @@
if (sina < 0) {
a = -a;
}
- // <Optimize>
- // sinc = (rot[2][1]*rot[0][2]-rot[2][0]*rot[1][2])/(rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);
- // cosc = -(rot[0][2]*rot[2][0]+rot[1][2]*rot[2][1])/(rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);
final double tmp = (rot02 * rot02 + rot12 * rot12);
sinc = (this.m21 * rot02 - this.m20 * rot12) / tmp;
cosc = -(rot02 * this.m20 + rot12 * this.m21) / tmp;
- // </Optimize>

if (cosc > 1.0) {
- /* printf("cos(r) = %f\n", cosc); */
cosc = 1.0;
sinc = 0.0;
}
if (cosc < -1.0) {
- /* printf("cos(r) = %f\n", cosc); */
cosc = -1.0;
sinc = 0.0;
}
if (sinc > 1.0) {
- /* printf("sin(r) = %f\n", sinc); */
sinc = 1.0;
cosc = 0.0;
}
if (sinc < -1.0) {
- /* printf("sin(r) = %f\n", sinc); */
sinc = -1.0;
cosc = 0.0;
}
@@ -201,22 +262,18 @@
cosc=this.m00;//cosc = rot[0];// <Optimize/>cosc = rot[0][0];
sinc=this.m01;//sinc = rot[1];// <Optimize/>sinc = rot[1][0];
if (cosc > 1.0) {
- /* printf("cos(r) = %f\n", cosc); */
cosc = 1.0;
sinc = 0.0;
}
if (cosc < -1.0) {
- /* printf("cos(r) = %f\n", cosc); */
cosc = -1.0;
sinc = 0.0;
}
if (sinc > 1.0) {
- /* printf("sin(r) = %f\n", sinc); */
sinc = 1.0;
cosc = 0.0;
}
if (sinc < -1.0) {
- /* printf("sin(r) = %f\n", sinc); */
sinc = -1.0;
cosc = 0.0;
}
@@ -225,77 +282,10 @@
c = -c;
}
}
- o_angle.x = a;// wa.value=a;//*wa = a;
- o_angle.y = b;// wb.value=b;//*wb = b;
- o_angle.z = c;// wc.value=c;//*wc = c;
+ //angleの更新
+ this._angle.x = a;// wa.value=a;//*wa = a;
+ this._angle.y = b;// wb.value=b;//*wb = b;
+ this._angle.z = c;// wc.value=c;//*wc = c;
return;
- }
- /**
- * 回転角から回転行列を計算してセットします。
- * @param i_x
- * @param i_y
- * @param i_z
- */
- public final void setAngle(final double i_x, final double i_y, final double i_z)
- {
- final double sina = Math.sin(i_x);
- final double cosa = Math.cos(i_x);
- final double sinb = Math.sin(i_y);
- final double cosb = Math.cos(i_y);
- final double sinc = Math.sin(i_z);
- final double cosc = Math.cos(i_z);
- // Optimize
- final double CACA = cosa * cosa;
- final double SASA = sina * sina;
- final double SACA = sina * cosa;
- final double SASB = sina * sinb;
- final double CASB = cosa * sinb;
- final double SACACB = SACA * cosb;
-
- this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
- this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
- this.m02 = CASB;
- this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
- this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
- this.m12 = SASB;
- this.m20 = -CASB * cosc - SASB * sinc;
- this.m21 = CASB * sinc - SASB * cosc;
- this.m22 = cosb;
- return;
- }
- /**
- * i_in_pointを変換行列で座標変換する。
- * @param i_in_point
- * @param i_out_point
- */
- public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)
- {
- final double x=i_in_point.x;
- final double y=i_in_point.y;
- final double z=i_in_point.z;
- i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;
- i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;
- i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;
- return;
- }
- /**
- * 複数の頂点を一括して変換する
- * @param i_in_point
- * @param i_out_point
- * @param i_number_of_vertex
- */
- public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)
- {
- for(int i=i_number_of_vertex-1;i>=0;i--){
- final NyARDoublePoint3d out_ptr=i_out_point[i];
- final NyARDoublePoint3d in_ptr=i_in_point[i];
- final double x=in_ptr.x;
- final double y=in_ptr.y;
- final double z=in_ptr.z;
- out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;
- out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;
- out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;
- }
- return;
}
}
Index: src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java (.../2.2.0) (revision 214)
@@ -37,13 +37,13 @@
public final class NyARBinRaster extends NyARRaster_BasicClass
{
private INyARBufferReader _buffer_reader;
- protected int[][] _ref_buf;
+ protected int[] _ref_buf;

public NyARBinRaster(int i_width, int i_height)
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf = new int[i_height][i_width];
- this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8);
+ this._ref_buf = new int[i_height*i_width];
+ this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);
}
public INyARBufferReader getBufferReader()
{
Index: src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java (.../2.2.0) (revision 214)
@@ -38,14 +38,14 @@
public final class NyARGrayscaleRaster extends NyARRaster_BasicClass
{

- protected int[][] _ref_buf;
+ protected int[] _ref_buf;
private INyARBufferReader _buffer_reader;

public NyARGrayscaleRaster(int i_width, int i_height)
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf = new int[i_height][i_width];
- this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8);
+ this._ref_buf = new int[i_height*i_width];
+ this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8);
}
public INyARBufferReader getBufferReader()
{
Index: src/jp/nyatla/nyartoolkit/core/param/NyARParam.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/param/NyARParam.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/param/NyARParam.java (.../2.2.0) (revision 214)
@@ -62,6 +62,19 @@
{
return this._dist;
}
+ /**
+ *
+ * @param i_factor
+ * NyARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。
+ * @param i_projection
+ * NyARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。
+ */
+ public void setValue(double[] i_factor,double[] i_projection)
+ {
+ this._dist.setValue(i_factor);
+ this._projection_matrix.setValue(i_projection);
+ return;
+ }

/**
* ARToolKit標準ファイルから1個目の設定をロードする。
@@ -93,13 +106,6 @@
//スケールを変更
this._dist.changeScale(scale);
this._projection_matrix.changeScale(scale);
- //for (int i = 0; i < 4; i++) {
- // array34[0 * 4 + i] = array34[0 * 4 + i] * scale;// newparam->mat[0][i]=source->mat[0][i]* scale;
- // array34[1 * 4 + i] = array34[1 * 4 + i] * scale;// newparam->mat[1][i]=source->mat[1][i]* scale;
- // array34[2 * 4 + i] = array34[2 * 4 + i];// newparam->mat[2][i] = source->mat[2][i];
- //}
-
-
this._screen_size.w = i_xsize;// newparam->xsize = xsize;
this._screen_size.h = i_ysize;// newparam->ysize = ysize;
return;
Index: src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java (.../2.2.0) (revision 214)
@@ -119,7 +119,6 @@
*/
public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
{
- final INyARLabeling labeling_proc = this._labeling;
final NyARLabelingImage limage = this._limage;

// 初期化
@@ -128,7 +127,7 @@
o_square_stack.clear();

// ラベリング
- labeling_proc.labeling(i_raster);
+ this._labeling.labeling(i_raster);

// ラベル数が0ならここまで
final int label_num = limage.getLabelStack().getLength();
Index: src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java (.../2.2.0) (revision 214)
@@ -36,23 +36,25 @@
public class NyARIntSize
{
public int h;
-
public int w;
public NyARIntSize()
{
this.w=0;
this.h=0;
- return;
-
+ return;
}
-
+ public NyARIntSize(NyARIntSize i_ref_object)
+ {
+ this.w=i_ref_object.w;
+ this.h=i_ref_object.h;
+ return;
+ }
public NyARIntSize(int i_width,int i_height)
{
this.w=i_width;
this.h=i_height;
return;
}
-
/**
* サイズが同一であるかを確認する。
*
Index: src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java (.../2.2.0) (revision 214)
@@ -50,4 +50,11 @@
}
return ret;
}
+ public void copyFrom(final NyARDoublePoint3d i_in)
+ {
+ this.x=i_in.x;
+ this.y=i_in.y;
+ this.z=i_in.z;
+ return;
+ }
}
Index: src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java (.../2.2.0) (revision 214)
@@ -31,7 +31,7 @@
*/
package jp.nyatla.nyartoolkit.core.types.stack;

-import jp.nyatla.nyartoolkit.NyARException;
+
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.utils.NyObjectStack;

Index: src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java (.../2.2.0) (revision 214)
@@ -31,7 +31,7 @@
*/
package jp.nyatla.nyartoolkit.core.types.stack;

-import jp.nyatla.nyartoolkit.NyARException;
+
import jp.nyatla.nyartoolkit.core.types.NyARIntRect;
import jp.nyatla.utils.NyObjectStack;

Index: src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java (.../2.2.0) (revision 214)
@@ -50,4 +50,13 @@
}
return ret;
}
+ public static void copyArray(final NyARIntPoint[] i_from,NyARIntPoint[] i_to)
+ {
+ for(int i=i_from.length-1;i>=0;i--)
+ {
+ i_to[i].x=i_from[i].x;
+ i_to[i].y=i_from[i].y;
+ }
+ return;
+ }
}
Index: src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java (.../2.2.0) (revision 214)
@@ -60,11 +60,11 @@
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
int in_buf_type=in_buffer_reader.getBufferType();

- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));
assert (checkInputType(in_buf_type)==true);
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();

NyARIntSize size = i_output.getSize();
@@ -82,97 +82,104 @@
return;
}

- private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
- final int size_w=i_size.w;
- final int x_mod_end= size_w-(size_w%8);
final int th=this._threshold*3;
- int bp =(size_w*i_size.h-1)*3;
+ int bp =(i_size.w*i_size.h-1)*3;
int w;
- int x;
- for (int y =i_size.h-1; y>=0 ; y--){
- //端数分
- final int[] row_ptr=i_out[y];
- for (x = size_w-1;x>=x_mod_end;x--) {
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
- bp -= 3;
- }
- //タイリング
- for (;x>=0;x-=8) {
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-1]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-2]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-3]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-4]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-5]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-6]=w<=th?0:1;
- bp -= 3;
- w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-7]=w<=th?0:1;
- bp -= 3;
- }
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
}
+ //タイリング
+ for (;xy>=0;) {
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ }
return;
}
- private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
- final int size_w=i_size.w;
- final int x_mod_end= size_w-(size_w%8);
final int th=this._threshold*3;
- int bp =(size_w*i_size.h-1)*4;
+ int bp =(i_size.w*i_size.h-1)*4;
int w;
- int x;
- for (int y =i_size.h-1; y>=0 ; y--){
- final int[] row_ptr=i_out[y];
-
- //端数分
- for (x = size_w-1;x>=x_mod_end;x--) {
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
- bp -= 4;
- }
- //タイリング
- for (;x>=0;x-=8) {
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-1]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-2]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-3]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-4]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-5]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-6]=w<=th?0:1;
- bp -= 4;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- row_ptr[x-7]=w<=th?0:1;
- bp -= 4;
- }
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
}
+ //タイリング
+ for (;xy>=0;) {
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
+ i_out[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ }
return;
}

Index: src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java (.../2.2.0) (revision 214)
@@ -31,8 +31,6 @@
*/
package jp.nyatla.nyartoolkit.core.labeling;

-
-
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.types.*;
@@ -44,34 +42,41 @@
public class NyARLabeling_ARToolKit implements INyARLabeling
{
private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32
+
private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE);
+
private NyARIntSize _dest_size;
+
private INyARLabelingImage _out_image;

- public void attachDestination(INyARLabelingImage i_destination_image)throws NyARException
+ public void attachDestination(INyARLabelingImage i_destination_image) throws NyARException
{
// サイズチェック
NyARIntSize size = i_destination_image.getSize();
this._out_image = i_destination_image;

// NyLabelingImageのイメージ初期化(枠書き)
- int[][] img = (int[][])i_destination_image.getBufferReader().getBuffer();
+ int[] img = (int[]) i_destination_image.getBufferReader().getBuffer();
+ int bottom_ptr = (size.h - 1) * size.w;
for (int i = 0; i < size.w; i++) {
- img[0][i] = 0;
- img[size.h - 1][i] = 0;
+ img[i] = 0;
+ img[bottom_ptr + i] = 0;
}
for (int i = 0; i < size.h; i++) {
- img[i][0] = 0;
- img[i][size.w - 1] = 0;
+ img[i * size.w] = 0;
+ img[(i + 1) * size.w - 1] = 0;
}

// サイズ(参照値)を保存
this._dest_size = size;
+ return;
}
+
public INyARLabelingImage getAttachedDestination()
{
return this._out_image;
}
+
/**
* static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品
* ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493]
@@ -81,9 +86,9 @@
*/
public void labeling(NyARBinRaster i_raster) throws NyARException
{
- int m, n; /* work */
- int i, j, k;
- INyARLabelingImage out_image = this._out_image;
+ int label_img_ptr1, label_pixel;
+ int i, j;
+ int n, k; /* work */

// サイズチェック
NyARIntSize in_size = i_raster.getSize();
@@ -91,88 +96,82 @@

final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;
final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;
- int[][] label_img = (int[][])out_image.getBufferReader().getBuffer();
+ final int[] label_img = (int[]) this._out_image.getBufferReader().getBuffer();

// 枠作成はインスタンスを作った直後にやってしまう。
-
- //ラベリング情報のリセット(ラベリングインデックスを使用)
- out_image.reset(true);
-
- int[] label_idxtbl=out_image.getIndexArray();

+ // ラベリング情報のリセット(ラベリングインデックスを使用)
+ this._out_image.reset(true);
+
+ int[] label_idxtbl = this._out_image.getIndexArray();
+ int[] raster_buf = (int[]) i_raster.getBufferReader().getBuffer();
+
int[] work2_pt;
int wk_max = 0;

- int label_pixel;
- int[][] raster_buf=(int[][])i_raster.getBufferReader().getBuffer();
- int[] line_ptr;
+ int pixel_index;
int[][] work2 = this.work_holder.work2;
- int[] label_img_pt0, label_img_pt1;
+
+ // [1,1](ptr0)と、[0,1](ptr1)のインデクス値を計算する。
for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {
- line_ptr=raster_buf[j];
- label_img_pt0 = label_img[j];
- label_img_pt1 = label_img[j - 1];
- for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
+ pixel_index = j * lxsize + 1;
+ label_img_ptr1 = pixel_index - lxsize;// label_img_pt1 = label_img[j - 1];
+ for (i = 1; i < lxsize - 1; i++, pixel_index++, label_img_ptr1++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
// RGBの合計値が閾値より小さいかな?
- if (line_ptr[i]==0) {
+ if (raster_buf[pixel_index] != 0) {
+ label_img[pixel_index] = 0;// label_img_pt0[i] = 0;// *pnt2 = 0;
+ } else {
// pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);
- if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
- label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;
+ if (label_img[label_img_ptr1] > 0) {// if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
+ label_pixel = label_img[label_img_ptr1];// label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
- if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
- m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
- if (m > n) {
- label_pixel = n;// *pnt2 = n;
- // wk=IntPointer.wrap(work, 0);//wk =
- // &(work[0]);
+ } else if (label_img[label_img_ptr1 + 1] > 0) {// } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
+ if (label_img[label_img_ptr1 - 1] > 0) {// if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
+ label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m
+ // =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[label_img_ptr1 - 1] - 1];// n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
+ if (label_pixel > n) {
+ // wk=IntPointer.wrap(work, 0);//wk = &(work[0]);
for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == m) {// if( *wk == m )
+ if (label_idxtbl[k] == label_pixel) {// if( *wk == m )
label_idxtbl[k] = n;// *wk = n;
}
}
- } else if (m < n) {
- label_pixel = m;// *pnt2 = m;
+ label_pixel = n;// *pnt2 = n;
+ } else if (label_pixel < n) {
// wk=IntPointer.wrap(work,0);//wk = &(work[0]);
for (k = 0; k < wk_max; k++) {
if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = m;// *wk = m;
+ label_idxtbl[k] = label_pixel;// *wk = m;
}
}
- } else {
- label_pixel = m;// *pnt2 = m;
}
work2_pt = work2[label_pixel - 1];
work2_pt[0]++;
work2_pt[1] += i;
work2_pt[2] += j;
work2_pt[6] = j;
- } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
- m = label_idxtbl[(label_img_pt1[i + 1]) - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
- if (m > n) {
-
- label_pixel = n;// *pnt2 = n;
+ } else if ((label_img[pixel_index - 1]) > 0) {// } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
+ label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[pixel_index - 1] - 1];// n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
+ if (label_pixel > n) {
for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == m) {// if( *wk == m ){
+ if (label_idxtbl[k] == label_pixel) {// if( *wk == m ){
label_idxtbl[k] = n;// *wk = n;
}
}
- } else if (m < n) {
- label_pixel = m;// *pnt2 = m;
+ label_pixel = n;// *pnt2 = n;
+ } else if (label_pixel < n) {
for (k = 0; k < wk_max; k++) {
if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = m;// *wk = m;
+ label_idxtbl[k] = label_pixel;// *wk = m;
}
}
- } else {
- label_pixel = m;// *pnt2 = m;
}
work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
@@ -180,24 +179,22 @@
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
} else {

- label_pixel = label_img_pt1[i + 1];// *pnt2 =
- // *(pnt1+1);
+ label_pixel = label_img[label_img_ptr1 + 1];// label_pixel = label_img_pt1[i + 1];// *pnt2 =
+ // *(pnt1+1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[3] > i) {// if(
- // work2[((*pnt2)-1)*7+3] >
- // i ){
+ if (work2_pt[3] > i) {// if(work2[((*pnt2)-1)*7+3] > i ){
work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
}
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
}
- } else if ((label_img_pt1[i - 1]) > 0) {// }else if(
- // *(pnt1-1) > 0 ) {
- label_pixel = label_img_pt1[i - 1];// *pnt2 =
- // *(pnt1-1);
+ } else if ((label_img[label_img_ptr1 - 1]) > 0) {// } else if ((label_img_pt1[i - 1]) > 0) {// }else if(
+ // *(pnt1-1) > 0 ) {
+ label_pixel = label_img[label_img_ptr1 - 1];// label_pixel = label_img_pt1[i - 1];// *pnt2 =
+ // *(pnt1-1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
@@ -207,8 +204,8 @@
work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
}
work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
- label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);
+ } else if (label_img[pixel_index - 1] > 0) {// } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
+ label_pixel = label_img[pixel_index - 1];// label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);

work2_pt = work2[label_pixel - 1];
work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
@@ -232,11 +229,10 @@
work2_pt[5] = j;
work2_pt[6] = j;
}
- label_img_pt0[i] = label_pixel;
- } else {
- label_img_pt0[i] = 0;// *pnt2 = 0;
+ label_img[pixel_index] = label_pixel;// label_img_pt0[i] = label_pixel;
}
}
+
}
// インデックステーブルとラベル数の計算
int wlabel_num = 1;// *label_num = *wlabel_num = j - 1;
@@ -247,26 +243,26 @@
wlabel_num -= 1;// *label_num = *wlabel_num = j - 1;
if (wlabel_num == 0) {// if( *label_num == 0 ) {
// 発見数0
- out_image.getLabelStack().clear();
+ this._out_image.getLabelStack().clear();
return;
}
// ラベル情報の保存等
- NyARLabelingLabelStack label_list = out_image.getLabelStack();
+ NyARLabelingLabelStack label_list = this._out_image.getLabelStack();

// ラベルバッファを予約
label_list.reserv(wlabel_num);

// エリアと重心、クリップ領域を計算
NyARLabelingLabel label_pt;
- NyARLabelingLabel[] labels = (NyARLabelingLabel[])label_list.getArray();
+ NyARLabelingLabel[] labels = (NyARLabelingLabel[]) label_list.getArray();
for (i = 0; i < wlabel_num; i++) {
- label_pt =labels[i];
- label_pt.id =i+1;
+ label_pt = labels[i];
+ label_pt.id = i + 1;
label_pt.area = 0;
- label_pt.pos_x =label_pt.pos_y = 0;
+ label_pt.pos_x = label_pt.pos_y = 0;
label_pt.clip_l = lxsize;// wclip[i*4+0] = lxsize;
label_pt.clip_t = lysize;// wclip[i*4+2] = lysize;
- label_pt.clip_r =label_pt.clip_b = 0;// wclip[i*4+3] = 0;
+ label_pt.clip_r = label_pt.clip_b = 0;// wclip[i*4+3] = 0;
}

for (i = 0; i < wk_max; i++) {
Index: src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java (.../2.2.0) (revision 214)
@@ -43,7 +43,7 @@
public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLabelingImage
{
private final static int MAX_LABELS = 1024*32;
- protected int[][] _ref_buf;
+ protected int[] _ref_buf;
private INyARBufferReader _buffer_reader;
protected NyARLabelingLabelStack _label_list;
protected int[] _index_table;
@@ -51,11 +51,11 @@
public NyARLabelingImage(int i_width, int i_height)
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf =new int[i_height][i_width];
+ this._ref_buf =new int[i_height*i_width];
this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
this._index_table=new int[MAX_LABELS];
this._is_index_table_enable=false;
- this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D);
+ this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D);

return;
}
@@ -102,15 +102,16 @@
*/
protected int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException
{
- int w;
+ int pix;
int i_label_id=i_label.id;
int[] index_table=this._index_table;
- int[] limage_j=this._ref_buf[i_label.clip_t];
+ int[] limage=this._ref_buf;
+ int limage_ptr=i_label.clip_t*this._size.w;
final int clip1 = i_label.clip_r;
// p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]);
for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
- w = limage_j[i];
- if (w > 0 && index_table[w-1] == i_label_id){
+ pix = limage[limage_ptr+i];
+ if (pix > 0 && index_table[pix-1] == i_label_id){
return i;
}
}
@@ -129,6 +130,7 @@
*/
public int getContour(int i_index,int i_array_size,int[] o_coord_x,int[] o_coord_y) throws NyARException
{
+ final int width=this._size.w;
final int[] xdir = this._getContour_xdir;// static int xdir[8] = { 0,1, 1, 1, 0,-1,-1,-1};
final int[] ydir = this._getContour_ydir;// static int ydir[8] = {-1,-1,0, 1, 1, 1, 0,-1};
final NyARLabelingLabel label=(NyARLabelingLabel)this._label_list.getItem(i_index);
@@ -142,13 +144,13 @@
o_coord_y[0] = sy;
int dir = 5;

- int[][] limage=this._ref_buf;
+ int[] limage=this._ref_buf;
int c = o_coord_x[0];
int r = o_coord_y[0];
for (;;) {
dir = (dir + 5) % 8;
for (i = 0; i < 8; i++) {
- if (limage[r + ydir[dir]][c + xdir[dir]] > 0) {
+ if (limage[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
break;
}
dir = (dir + 1) % 8;
Index: src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java
===================================================================
--- src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (.../2.1.0) (revision 0)
+++ src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (.../2.2.0) (revision 214)
@@ -0,0 +1,247 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java version ARToolkit class library.
+ * Copyright (C)2008 R.Iizuka
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this framework; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.detector;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.match.*;
+import jp.nyatla.nyartoolkit.core.param.NyARParam;
+import jp.nyatla.nyartoolkit.core.pickup.*;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+/**
+ * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
+ *
+ */
+public class NyARCustomSingleDetectMarker
+{
+ private static final int AR_SQUARE_MAX = 100;
+
+ private boolean _is_continue = false;
+ private NyARMatchPatt_Color_WITHOUT_PCA _match_patt;
+ private INyARSquareDetector _square_detect;
+
+ private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX);
+
+ private NyARCode _code;
+
+ protected INyARTransMat _transmat;
+
+ private double _marker_width;
+ // 検出結果の保存用
+ private int _detected_direction;
+ private double _detected_confidence;
+ private NyARSquare _detected_square;
+ private INyARColorPatt _patt;
+ //画処理用
+ private NyARBinRaster _bin_raster;
+ protected INyARRasterFilter_RgbToBin _tobin_filter;
+
+ /**
+ * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
+ *
+ * @param i_param
+ * カメラパラメータを指定します。
+ * @param i_code
+ * 検出するARCodeを指定します。
+ * @param i_marker_width
+ * ARコードの物理サイズを、ミリメートルで指定します。
+ * @param i_filter
+ * RGB→BIN変換フィルタを指定します。
+ * @throws NyARException
+ */
+ public NyARCustomSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,INyARRasterFilter_RgbToBin i_filter) throws NyARException
+ {
+ final NyARIntSize scr_size=i_param.getScreenSize();
+ // 解析オブジェクトを作る
+ this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size);
+ this._transmat = new NyARTransMat(i_param);
+ // 比較コードを保存
+ this._code = i_code;
+ this._marker_width = i_marker_width;
+ // 評価パターンのホルダを作る
+ this._patt = new NyARColorPatt_O3(_code.getWidth(), _code.getHeight());
+ // 評価器を作る。
+ this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA();
+ //2値画像バッファを作る
+ this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
+ this._tobin_filter=i_filter;
+ }
+
+
+ /**
+ * i_imageにマーカー検出処理を実行し、結果を記録します。
+ *
+ * @param i_raster
+ * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
+ * と一致していなければなりません。
+ * @return マーカーが検出できたかを真偽値で返します。
+ * @throws NyARException
+ */
+ public boolean detectMarkerLite(INyARRgbRaster i_raster) throws NyARException
+ {
+ //サイズチェック
+ if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){
+ throw new NyARException();
+ }
+
+ //ラスタを2値イメージに変換する.
+ this._tobin_filter.doFilter(i_raster,this._bin_raster);
+
+
+ this._detected_square = null;
+ NyARSquareStack l_square_list = this._square_list;
+ // スクエアコードを探す
+ this._square_detect.detectMarker(this._bin_raster, l_square_list);
+
+
+ int number_of_square = l_square_list.getLength();
+ // コードは見つかった?
+ if (number_of_square < 1) {
+ return false;
+ }
+
+ // 評価基準になるパターンをイメージから切り出す
+ if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(0))) {
+ // パターンの切り出しに失敗
+ return false;
+ }
+ // パターンを評価器にセット
+ if (!this._match_patt.setPatt(this._patt)) {
+ // 計算に失敗した。
+ throw new NyARException();
+ }
+ // コードと比較する
+ this._match_patt.evaluate(this._code);
+ int square_index = 0;
+ int direction = this._match_patt.getDirection();
+ double confidence = this._match_patt.getConfidence();
+ for (int i = 1; i < number_of_square; i++) {
+ // 次のパターンを取得
+ this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i));
+ // 評価器にセットする。
+ this._match_patt.setPatt(this._patt);
+ // コードと比較する
+ this._match_patt.evaluate(this._code);
+ double c2 = this._match_patt.getConfidence();
+ if (confidence > c2) {
+ continue;
+ }
+ // もっと一致するマーカーがあったぽい
+ square_index = i;
+ direction = this._match_patt.getDirection();
+ confidence = c2;
+ }
+ // マーカー情報を保存
+ this._detected_square = (NyARSquare)l_square_list.getItem(square_index);
+ this._detected_direction = direction;
+ this._detected_confidence = confidence;
+ return true;
+ }
+
+ /**
+ * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。
+ * 直前に実行したdetectMarkerLiteが成功していないと使えません。
+ *
+ * @param o_result
+ * 変換行列を受け取るオブジェクトを指定します。
+ * @throws NyARException
+ */
+ public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException
+ {
+ // 一番一致したマーカーの位置とかその辺を計算
+ if (this._is_continue) {
+ this._transmat.transMatContinue(this._detected_square,this._detected_direction,this._marker_width, o_result);
+ } else {
+ this._transmat.transMat(this._detected_square,this._detected_direction,this._marker_width, o_result);
+ }
+ return;
+ }
+ /**
+ * 画面上のマーカ頂点情報を配列へ取得します。
+ * @param o_point
+ * 4要素以上の配列を指定して下さい。先頭の4要素に値がコピーされます。
+ */
+ public void getSquarePosition(NyARIntPoint[] o_point)
+ {
+ NyARIntPoint.copyArray(this._detected_square.imvertex,o_point);
+ return;
+ }
+ /**
+ * 画面上のマーカ頂点情報を配列へのリファレンスを返します。
+ * 返されたオブジェクトはクラスに所有し続けられています。クラスのメンバ関数を実行すると内容が書き変わります。
+ * 外部でデータをストックする場合は、getSquarePositionで複製して下さい。
+ * @return
+ */
+ public NyARIntPoint[] refSquarePosition()
+ {
+ return this._detected_square.imvertex;
+ }
+
+
+ /**
+ * 検出したマーカーの一致度を返します。
+ *
+ * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。
+ * @throws NyARException
+ */
+ public double getConfidence()
+ {
+ return this._detected_confidence;
+ }
+
+ /**
+ * 検出したマーカーの方位を返します。
+ *
+ * @return 0,1,2,3の何れかを返します。
+ */
+ public int getDirection()
+ {
+ return this._detected_direction;
+ }
+
+ /**
+ * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。
+ *
+ * @param i_is_continue
+ * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。
+ */
+ public void setContinueMode(boolean i_is_continue)
+ {
+ this._is_continue = i_is_continue;
+ }
+}
Index: src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
===================================================================
--- src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (.../2.2.0) (revision 214)
@@ -33,44 +33,16 @@

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.*;
-import jp.nyatla.nyartoolkit.core.match.*;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
-import jp.nyatla.nyartoolkit.core.pickup.*;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.transmat.*;
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;

/**
* 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
*
*/
-public class NyARSingleDetectMarker
+public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker
{
- private static final int AR_SQUARE_MAX = 100;
-
- private boolean _is_continue = false;
- private NyARMatchPatt_Color_WITHOUT_PCA _match_patt;
- private INyARSquareDetector _square_detect;
-
- private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX);
-
- private NyARCode _code;
-
- protected INyARTransMat _transmat;
-
- private double _marker_width;
-
- // 検出結果の保存用
- private int _detected_direction;
-
- private double _detected_confidence;
-
- private NyARSquare _detected_square;
-
- private INyARColorPatt _patt;
-
/**
* 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
*
@@ -84,23 +56,9 @@
*/
public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width) throws NyARException
{
- final NyARIntSize scr_size=i_param.getScreenSize();
- // 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size);
- this._transmat = new NyARTransMat(i_param);
- // 比較コードを保存
- this._code = i_code;
- this._marker_width = i_marker_width;
- // 評価パターンのホルダを作る
- this._patt = new NyARColorPatt_O3(_code.getWidth(), _code.getHeight());
- // 評価器を作る。
- this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA();
- //2値画像バッファを作る
- this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
+ super(i_param,i_code,i_marker_width,new NyARRasterFilter_ARToolkitThreshold(100));
}

- NyARBinRaster _bin_raster;
- NyARRasterFilter_ARToolkitThreshold _tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100);

/**
* i_imageにマーカー検出処理を実行し、結果を記録します。
@@ -113,114 +71,7 @@
*/
public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException
{
- //サイズチェック
- if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){
- throw new NyARException();
- }
-
- //ラスタを2値イメージに変換する.
- this._tobin_filter.setThreshold(i_threshold);
- this._tobin_filter.doFilter(i_raster,this._bin_raster);
-
-
- this._detected_square = null;
- NyARSquareStack l_square_list = this._square_list;
- // スクエアコードを探す
- this._square_detect.detectMarker(this._bin_raster, l_square_list);
-
-
- int number_of_square = l_square_list.getLength();
- // コードは見つかった?
- if (number_of_square < 1) {
- return false;
- }
-
- // 評価基準になるパターンをイメージから切り出す
- if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(0))) {
- // パターンの切り出しに失敗
- return false;
- }
- // パターンを評価器にセット
- if (!this._match_patt.setPatt(this._patt)) {
- // 計算に失敗した。
- throw new NyARException();
- }
- // コードと比較する
- this._match_patt.evaluate(this._code);
- int square_index = 0;
- int direction = this._match_patt.getDirection();
- double confidence = this._match_patt.getConfidence();
- for (int i = 1; i < number_of_square; i++) {
- // 次のパターンを取得
- this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i));
- // 評価器にセットする。
- this._match_patt.setPatt(this._patt);
- // コードと比較する
- this._match_patt.evaluate(this._code);
- double c2 = this._match_patt.getConfidence();
- if (confidence > c2) {
- continue;
- }
- // もっと一致するマーカーがあったぽい
- square_index = i;
- direction = this._match_patt.getDirection();
- confidence = c2;
- }
- // マーカー情報を保存
- this._detected_square = (NyARSquare)l_square_list.getItem(square_index);
- this._detected_direction = direction;
- this._detected_confidence = confidence;
- return true;
+ ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
+ return super.detectMarkerLite(i_raster);
}
-
- /**
- * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。
- * 直前に実行したdetectMarkerLiteが成功していないと使えません。
- *
- * @param o_result
- * 変換行列を受け取るオブジェクトを指定します。
- * @throws NyARException
- */
- public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException
- {
- // 一番一致したマーカーの位置とかその辺を計算
- if (this._is_continue) {
- this._transmat.transMatContinue(this._detected_square,this._detected_direction,this._marker_width, o_result);
- } else {
- this._transmat.transMat(this._detected_square,this._detected_direction,this._marker_width, o_result);
- }
- return;
- }
-
- /**
- * 検出したマーカーの一致度を返します。
- *
- * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。
- * @throws NyARException
- */
- public double getConfidence()
- {
- return this._detected_confidence;
- }
-
- /**
- * 検出したマーカーの方位を返します。
- *
- * @return 0,1,2,3の何れかを返します。
- */
- public int getDirection()
- {
- return this._detected_direction;
- }
-
- /**
- * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。
- *
- * @param i_is_continue
- * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。
- */
- public void setContinueMode(boolean i_is_continue)
- {
- this._is_continue = i_is_continue;
- }
}
Index: src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java (.../2.2.0) (revision 214)
@@ -89,7 +89,7 @@
public void analyzeRaster(INyARRaster i_input) throws NyARException
{
INyARBufferReader buffer_reader=i_input.getBufferReader();
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8));
+ assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));

// 結果をクリア
this._result.clear();
@@ -100,11 +100,12 @@
w1 = b1 = w2 = b2 = w3 = b3 = 0;

NyARIntRect item;
- int[] line;
+ int[] raster_buf=(int[])buffer_reader.getBuffer();
+ int line_ptr;
int s_pos, b2_spos,b3_spos;
b2_spos=0;
for (int y = size.h - 1-8; y >= 8; y--) {
- line = ((int[][]) buffer_reader.getBuffer())[y];
+ line_ptr = y*size.w;
x = size.w - 1;
s_pos=0;
int token_id=0;
@@ -114,7 +115,7 @@
// w1の特定
w1 = 0;
for (; x >= 0; x--) {
- if (line[x] == 0) {
+ if (raster_buf[line_ptr+x] == 0) {
// 検出条件確認:w1は2以上欲しいな。
if (!check_w1(w1)) {
// 条件不十分
@@ -133,7 +134,7 @@
b1 = 0;
s_pos = x;
for (; x >= 0; x--) {
- if (line[x] > 0) {
+ if (raster_buf[line_ptr+x] > 0) {
// 検出条件確認:b1は1以上欲しいな。
if (!check_b1(b1)){
//条件不十分→白検出からやり直し
@@ -151,7 +152,7 @@
// w2の特定
w2 = 0;
for (; x >= 0; x--) {
- if (line[x] == 0) {
+ if (raster_buf[line_ptr+x] == 0) {
// 検出条件確認:w2*10/b1は80-120以上欲しいな。
if (!check_w2(b1,w2)) {
//条件不十分→w2→w1として、b1を解析
@@ -173,7 +174,7 @@
b2 = 0;
b2_spos=x;
for (; x >= 0; x--) {
- if (line[x] > 0){
+ if (raster_buf[line_ptr+x] > 0){
//条件:(w1+b1)/2の2~4倍

if (!check_b2(b1,b2)) {
@@ -201,7 +202,7 @@
// w3の特定
w3 = 0;
for (; x >= 0; x--) {
- if (line[x] == 0){
+ if (raster_buf[line_ptr+x] == 0){
if (!check_w3(w2,w3)) {
//w2→w1,b2->b1として解析しなおす。
if(check_w1(w2) && check_b1(b2)){
@@ -228,7 +229,7 @@
b3 = 0;
b3_spos=x;
for (; x >= 0; x--) {
- if (line[x] > 0) {
+ if (raster_buf[line_ptr+x] > 0) {
// 検出条件確認
if (!check_b3(b3,b1)) {
if(check_w1(w2) && check_b1(b2)){
Index: src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java (.../2.2.0) (revision 214)
@@ -48,7 +48,7 @@
{
}

- private int createHistgram(int[][] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException
+ private int createHistgram(int[] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException
{
int[][] fil1={
{-1,-2,-1},
@@ -63,11 +63,11 @@
int sam1,sam2;
for (int y = 1; y < i_size.h-1; y++) {
for (int x = 1; x < i_size.w-1; x++) {
- int v = in_buf[y][x];
+ int v = in_buf[y* i_size.w+x];
sam1=sam2=0;
for(int yy=0;yy<3;yy++){
for(int xx=0;xx<3;xx++){
- int v2=in_buf[y+yy-1][x+xx-1];
+ int v2=in_buf[(y+yy-1)* i_size.w+(x+xx-1)];
sam1+=v2*fil1[xx][yy];
sam2+=v2*fil1[yy][xx];
}
@@ -90,9 +90,9 @@
public void analyzeRaster(INyARRaster i_input) throws NyARException
{
final INyARBufferReader buffer_reader=i_input.getBufferReader();
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
int[] histgram = new int[256];
- this._threshold = createHistgram((int[][])buffer_reader.getBuffer(),i_input.getSize(), histgram);
+ this._threshold = createHistgram((int[])buffer_reader.getBuffer(),i_input.getSize(), histgram);
}

/**
@@ -105,20 +105,20 @@
{
INyARBufferReader in_buffer_reader=i_input.getBufferReader();
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
NyARIntSize size = i_output.getSize();

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
// 0で塗りつぶし
for (int y = 0; y < size.h; y++) {
for (int x = 0; x < size.w; x++) {
- out_buf[y][x] = 0;
+ out_buf[y* size.w+x] = 0;
}
}
// ヒストグラムを計算
int[] histgram = new int[256];
- int threshold = createHistgram((int[][])in_buffer_reader.getBuffer(),i_input.getSize(), histgram);
+ int threshold = createHistgram((int[])in_buffer_reader.getBuffer(),i_input.getSize(), histgram);

// ヒストグラムの最大値を出す
int max_v = 0;
@@ -129,17 +129,17 @@
}
// 目盛り
for (int i = 0; i < size.h; i++) {
- out_buf[i][0] = 128;
- out_buf[i][128] = 128;
- out_buf[i][255] = 128;
+ out_buf[i* size.w+0] = 128;
+ out_buf[i* size.w+128] = 128;
+ out_buf[i* size.w+255] = 128;
}
// スケーリングしながら描画
for (int i = 0; i < 255; i++) {
- out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255;
+ out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;
}
// 値
for (int i = 0; i < size.h; i++) {
- out_buf[i][threshold] = 255;
+ out_buf[i* size.w+threshold] = 255;
}
return;
}
Index: src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java (.../2.2.0) (revision 214)
@@ -59,7 +59,7 @@

private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException
{
- int[][] in_buf = (int[][]) i_reader.getBuffer();
+ int[] in_buf = (int[]) i_reader.getBuffer();
int[] histgram = o_histgram;

// ヒストグラムを作成
@@ -70,7 +70,7 @@
for (int y = 0; y < i_size.h; y++) {
int sum2 = 0;
for (int x = 0; x < i_size.w; x++) {
- int v = in_buf[y][x];
+ int v = in_buf[y* i_size.w+x];
histgram[v]++;
sum2 += v;
}
@@ -105,7 +105,7 @@
public void analyzeRaster(INyARRaster i_input) throws NyARException
{
final INyARBufferReader buffer_reader=i_input.getBufferReader();
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
int[] histgram = new int[256];
this._threshold = createHistgram(buffer_reader,i_input.getSize(), histgram);
}
@@ -120,15 +120,15 @@
{
INyARBufferReader in_buffer_reader=i_input.getBufferReader();
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
NyARIntSize size = i_output.getSize();

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
// 0で塗りつぶし
for (int y = 0; y < size.h; y++) {
for (int x = 0; x < size.w; x++) {
- out_buf[y][x] = 0;
+ out_buf[y* size.w+x] = 0;
}
}
// ヒストグラムを計算
@@ -144,17 +144,17 @@
}
// 目盛り
for (int i = 0; i < size.h; i++) {
- out_buf[i][0] = 128;
- out_buf[i][128] = 128;
- out_buf[i][255] = 128;
+ out_buf[i* size.w+0] = 128;
+ out_buf[i* size.w+128] = 128;
+ out_buf[i* size.w+255] = 128;
}
// スケーリングしながら描画
for (int i = 0; i < 255; i++) {
- out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255;
+ out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;
}
// 値
for (int i = 0; i < size.h; i++) {
- out_buf[i][threshold] = 255;
+ out_buf[i* size.w+threshold] = 255;
}
return;
}
Index: src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java (.../2.2.0) (revision 214)
@@ -61,7 +61,7 @@

private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException
{
- int[][] in_buf = (int[][]) i_reader.getBuffer();
+ int[] in_buf = (int[]) i_reader.getBuffer();
int[] histgram = o_histgram;

// ヒストグラムを作成
@@ -72,7 +72,7 @@
for (int y = 0; y < i_size.h; y++) {
int sum2 = 0;
for (int x = 0; x < i_size.w; x++) {
- int v = in_buf[y][x];
+ int v = in_buf[y* i_size.w+x];
histgram[v]++;
sum2 += v;
}
@@ -106,7 +106,7 @@
public void analyzeRaster(INyARRaster i_input) throws NyARException
{
final INyARBufferReader buffer_reader=i_input.getBufferReader();
- assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));

int[] histgram = new int[256];
// 閾値の基準値を出す。
@@ -123,16 +123,16 @@
{
INyARBufferReader in_buffer_reader=i_input.getBufferReader();
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));

NyARIntSize size = i_output.getSize();

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
// 0で塗りつぶし
for (int y = 0; y < size.h; y++) {
for (int x = 0; x < size.w; x++) {
- out_buf[y][x] = 0;
+ out_buf[y* size.w+x] = 0;
}
}
// ヒストグラムを計算
@@ -151,17 +151,17 @@
}
// 目盛り
for (int i = 0; i < size.h; i++) {
- out_buf[i][0] = 128;
- out_buf[i][128] = 128;
- out_buf[i][255] = 128;
+ out_buf[i* size.w+0] = 128;
+ out_buf[i* size.w+128] = 128;
+ out_buf[i* size.w+255] = 128;
}
// スケーリングしながら描画
for (int i = 0; i < 255; i++) {
- out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255;
+ out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;
}
// 値
for (int i = 0; i < size.h; i++) {
- out_buf[i][threshold] = 255;
+ out_buf[i* size.w+threshold] = 255;
}
return;
}
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java (.../2.2.0) (revision 214)
@@ -46,20 +46,20 @@
{
INyARBufferReader in_buffer_reader=i_input.getBufferReader();
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
- assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));
+ assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8));
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
- int[][] in_buf = (int[][]) in_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
+ int[] in_buf = (int[]) in_buffer_reader.getBuffer();

int bp = 0;
NyARIntSize size = i_output.getSize();
for (int y = 1; y < size.h; y++) {
int prev = 128;
for (int x = 1; x < size.w; x++) {
- int w = in_buf[y][x];
- out_buf[y][x] = (Math.abs(w - prev) + Math.abs(w - in_buf[y - 1][x])) / 2;
+ int w = in_buf[y* size.w+x];
+ out_buf[y* size.w+x] = (Math.abs(w - prev) + Math.abs(w - in_buf[(y - 1)* size.w+x])) / 2;

prev = w;
bp += 3;
}
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java (.../2.2.0) (revision 214)
@@ -47,8 +47,8 @@
public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException
{
final NyARIntSize size = i_output.getSize();
- final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();
- final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();
+ final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();
+ final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。

@@ -63,7 +63,7 @@
sum = nn = 0;
for (int yy = y - area; yy < y + area + 1; yy++) {
for (int xx = x1 - area; xx < x1 + area; xx++) {
- sum += in_buf[yy][xx];
+ sum += in_buf[yy*size.w+xx];
nn++;
}
}
@@ -71,15 +71,15 @@
for (int x = area; x < x2; x++) {
if (!first) {
for (int yy = y - area; yy < y + area; yy++) {
- sum += in_buf[yy][x + area];
- sum -= in_buf[yy][x - area];
+ sum += in_buf[yy*size.w+x + area];
+ sum -= in_buf[yy*size.w+x - area];
}
}
first = false;
int th = (sum / nn);

- int g = in_buf[y][x];
- out_buf[y][x] = th < g ? 1 : 0;
+ int g = in_buf[y*size.w+x];
+ out_buf[y*size.w+x] = th < g ? 1 : 0;
}
}
return;
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java (.../2.2.0) (revision 214)
@@ -54,14 +54,14 @@
{
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();
- final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();
+ final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();
+ final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();

int bp = 0;
NyARIntSize size = i_output.getSize();
for (int y = 0; y < size.h - 1; y++) {
for (int x = 0; x < size.w; x++) {
- out_buf[y][x] = in_buf[y][x] >= this._threshold ? 1 : 0;
+ out_buf[y*size.w+x] = in_buf[y*size.w+x] >= this._threshold ? 1 : 0;
bp += 3;
}
}
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java (.../2.2.0) (revision 214)
@@ -46,7 +46,7 @@
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();

NyARIntSize size = i_output.getSize();
@@ -64,23 +64,23 @@
return;
}

- private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
int bp = 0;
for (int y = 0; y < i_size.h; y++) {
for (int x = 0; x < i_size.w; x++) {
- i_out[y][x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
+ i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
bp += 3;
}
}
return;
}
- private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
int bp = 0;
for (int y = 0; y < i_size.h; y++) {
for (int x = 0; x < i_size.w; x++) {
- i_out[y][x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
+ i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3;
bp += 4;
}
}
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java (.../2.2.0) (revision 214)
@@ -46,7 +46,7 @@
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ int[] out_buf = (int[]) out_buffer_reader.getBuffer();
byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();

NyARIntSize size = i_output.getSize();
@@ -61,12 +61,12 @@
return;
}

- private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
int bp = 0;
for (int y = 0; y < i_size.h; y++) {
for (int x = 0; x < i_size.w; x++) {
- i_out[y][x] = ((i_in[bp] & 0xff) * (i_in[bp + 1] & 0xff) * (i_in[bp + 2] & 0xff)) >> 16;
+ i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) * (i_in[bp + 1] & 0xff) * (i_in[bp + 2] & 0xff)) >> 16;
bp += 3;
}
}
Index: src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java
===================================================================
--- src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java (.../2.2.0) (revision 214)
@@ -46,7 +46,7 @@
INyARBufferReader out_buffer_reader=i_output.getBufferReader();
assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);

- final int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
+ final int[] out_buf = (int[]) out_buffer_reader.getBuffer();
final byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();

NyARIntSize size = i_output.getSize();
@@ -61,12 +61,12 @@
return;
}

- private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
+ private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
{
int bp = 0;
for (int y = 0; y < i_size.h; y++) {
for (int x = 0; x < i_size.w; x++) {
- i_out[y][x] = ((i_in[bp] & 0xff) | (i_in[bp + 1] & 0xff) | (i_in[bp + 2] & 0xff));
+ i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) | (i_in[bp + 1] & 0xff) | (i_in[bp + 2] & 0xff));
bp += 3;
}
}
Index: src/jp/nyatla/utils/NyObjectStack.java
===================================================================
--- src/jp/nyatla/utils/NyObjectStack.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/utils/NyObjectStack.java (.../2.2.0) (revision 214)
@@ -52,7 +52,7 @@
*
* @param i_array
*/
- public NyObjectStack(Object[] i_array)
+ protected NyObjectStack(Object[] i_array)
{
// ポインタだけははじめに確保しておく
this._items = i_array;
Index: src/jp/nyatla/utils/j2se/LabelingBufferdImage.java
===================================================================
--- src/jp/nyatla/utils/j2se/LabelingBufferdImage.java (.../2.1.0) (revision 214)
+++ src/jp/nyatla/utils/j2se/LabelingBufferdImage.java (.../2.2.0) (revision 214)
@@ -122,7 +122,7 @@

public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException
{
- assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8);
+ assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8);

int w = this.getWidth();
int h = this.getHeight();
@@ -132,12 +132,12 @@
throw new NyARException();
}

- int[][] limg;
+ int[] limg;
// イメージの描画
- limg = (int[][]) i_raster.getBufferReader().getBuffer();
+ limg = (int[]) i_raster.getBufferReader().getBuffer();
for (int i = 0; i < h; i++) {
for (int i2 = 0; i2 < w; i2++) {
- this.setRGB(i2, i,limg[i][i2]);
+ this.setRGB(i2, i,limg[i*w+i2]);
}
}
return;
@@ -149,7 +149,7 @@
*/
public void drawImage(NyARBinRaster i_raster) throws NyARException
{
- assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8);
+ assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);

int w = this.getWidth();
int h = this.getHeight();
@@ -159,12 +159,12 @@
throw new NyARException();
}

- int[][] limg;
+ int[] limg;
// イメージの描画
- limg = (int[][]) i_raster.getBufferReader().getBuffer();
+ limg = (int[]) i_raster.getBufferReader().getBuffer();
for (int i = 0; i < h; i++) {
for (int i2 = 0; i2 < w; i2++) {
- this.setRGB(i2, i, limg[i][i2] > 0 ? 255 : 0);
+ this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0);
}
}
return;
@@ -186,12 +186,12 @@
}
int[] index_array=i_image.getIndexArray();

- int[][] limg;
+ int[] limg;
// イメージの描画
- limg = (int[][]) i_image.getBufferReader().getBuffer();
+ limg = (int[]) i_image.getBufferReader().getBuffer();
for (int i = 0; i < h; i++) {
for (int i2 = 0; i2 < w; i2++) {
- int t=limg[i][i2]-1;
+ int t=limg[i*w+i2]-1;
if(t<0){
t=0;
}else{