2 * PROJECT: NyARToolkit Java3D utilities.
\r
3 * --------------------------------------------------------------------------------
\r
5 * Copyright (c) 2008 nyatla
\r
6 * airmail(at)ebony.plala.or.jp
\r
7 * http://nyatla.jp/nyartoolkit/
\r
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
10 * of this software and associated documentation files (the "Software"), to deal
\r
11 * in the Software without restriction, including without limitation the rights
\r
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
13 * copies of the Software, and to permit persons to whom the Software is
\r
14 * furnished to do so, subject to the following conditions:
\r
15 * The above copyright notice and this permission notice shall be included in
\r
16 * all copies or substantial portions of the Software.
\r
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 package jp.nyatla.nyartoolkit.java3d.utils;
\r
29 import java.awt.image.*;
\r
31 import javax.media.format.VideoFormat;
\r
32 import javax.media.j3d.ImageComponent;
\r
33 import javax.media.j3d.ImageComponent2D;
\r
35 import jp.nyatla.nyartoolkit.NyARException;
\r
36 import jp.nyatla.nyartoolkit.core.param.NyARParam;
\r
37 import jp.nyatla.nyartoolkit.jmf.utils.*;
\r
38 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
41 * このクラスは、Java3Dと互換性のあるNyARToolkitのラスタイメージを保持します。
\r
44 public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB
\r
46 private ImageComponent2D imc2d;
\r
48 private byte[] i2d_buf;
\r
50 private BufferedImage bufferd_image;
\r
53 * JMFのキャプチャ画像をこのクラスのBufferedImageにコピーします。
\r
55 * 画像の格納されたバッファを指定して下さい。
\r
56 * 画像サイズはコンストラクタで与えたパラメタと同じサイズである必要があります。
\r
58 public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
\r
60 this._reader.changeBuffer(i_buffer);
\r
61 synchronized (this){
\r
62 //キャプチャデータをi2dのバッファにコピーする。
\r
63 //現在はJmfNyARRaster_RGBでRGB画像がノーマライズされているので、
\r
64 //ここでもう一度flipする。(これ省略したいなあ…。)
\r
65 byte[] src=(byte[])this._reader.getBuffer();
\r
66 final int length = this._size.w * 3;
\r
68 int dest_idx = (this._size.h - 1) * length;
\r
69 for (int i = 0; i < this._size.h; i++) {
\r
70 System.arraycopy(src,src_idx, this.i2d_buf, dest_idx, length);
\r
78 public J3dNyARRaster_RGB(NyARParam i_cparam,VideoFormat i_format) throws NyARException
\r
80 super(i_cparam.getScreenSize(),i_format);
\r
81 //bufferdimageの種類を決める
\r
82 if(this._reader.getBufferType()!=INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24){
\r
83 throw new NyARException();
\r
86 this.bufferd_image = new BufferedImage(this._size.w, this._size.h, BufferedImage.TYPE_3BYTE_BGR);
\r
87 i2d_buf = ((DataBufferByte) bufferd_image.getRaster().getDataBuffer()).getData();
\r
88 this.imc2d = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);
\r
89 imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
\r
93 * 自身の格納しているImageComponent2Dオブジェクトを作り直します。
\r
94 * Java3D1.5がDirectXで動いた(らしいとき)に、ImageComponent2Dのインスタンス
\r
95 * IDが異ならないと、Behavior内でイメージの更新を通知できない事象に対応するために実装してあります。
\r
96 * Behavior内でgetImageComponent2()関数を実行する直前に呼び出すことで、この事象を回避することができます。
\r
99 public void renewImageComponent2D()
\r
101 this.imc2d = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);
\r
102 this.imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
\r
105 public ImageComponent2D getImageComponent2D()
\r