2 * PROJECT: NyARToolkit Quicktime utilities.
\r
3 * --------------------------------------------------------------------------------
\r
4 * Copyright (C)2008 arc@dmz
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this framework; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * For further information please contact.
\r
22 * <arc(at)digitalmuseum.jp>
\r
25 package jp.nyatla.nyartoolkit.qt.utils;
\r
27 import java.awt.image.BufferedImage;
\r
28 import java.awt.image.DataBuffer;
\r
29 import java.awt.image.WritableRaster;
\r
31 import jp.nyatla.nyartoolkit.NyARException;
\r
32 import jp.nyatla.nyartoolkit.core.raster.rgb.NyARRgbRaster_BasicClass;
\r
33 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
34 import jp.nyatla.nyartoolkit.core.types.*;
\r
36 * RGB形式のbyte配列をラップするNyARRasterです。
\r
37 * 保持したデータからBufferedImageを出力する機能も持ちます。
\r
39 public class QtNyARRaster_RGB extends NyARRgbRaster_BasicClass
\r
41 private class PixcelReader extends NyARRgbPixelReader_RGB24 implements INyARBufferReader
\r
43 public PixcelReader(NyARIntSize i_size)
\r
45 super(null, i_size);
\r
49 public void syncBuffer(byte[] i_ref_buffer)
\r
51 this._ref_buf = i_ref_buffer;
\r
56 // INyARBufferReader
\r
58 public Object getBuffer()
\r
60 return this._ref_buf;
\r
63 public int getBufferType()
\r
65 return INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;
\r
68 public boolean isEqualBufferType(int i_type_value)
\r
70 return i_type_value == INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;
\r
74 protected byte[] _ref_buf;
\r
76 protected PixcelReader _reader;
\r
78 private WritableRaster _raster;
\r
80 private BufferedImage _image;
\r
83 * RGB形式のJMFバッファをラップするオブジェクトをつくります。 生成直後のオブジェクトはデータを持ちません。 メンバ関数はsetBufferを実行後に使用可能になります。
\r
85 public QtNyARRaster_RGB(int i_width, int i_height)
\r
87 super(new NyARIntSize(i_width,i_height));
\r
88 this._ref_buf = null;
\r
89 this._reader = new PixcelReader(this._size);
\r
90 _raster = WritableRaster.createInterleavedRaster(DataBuffer.TYPE_BYTE, i_width, i_height, i_width * 3, 3, new int[] { 0, 1, 2 }, null);
\r
91 _image = new BufferedImage(i_width, i_height, BufferedImage.TYPE_3BYTE_BGR);
\r
95 * javax.media.Bufferを分析して、その分析結果をNyARRasterに適合する形で保持します。 関数実行後に外部でi_bufferの内容変更した場合には、再度setBuffer関数を呼び出してください。
\r
98 * RGB形式のデータを格納したjavax.media.Bufferオブジェクトを指定してください。
\r
99 * @return i_bufferをラップしたオブジェクトを返します。
\r
100 * @throws NyARException
\r
102 public void setBuffer(byte[] i_buffer)
\r
104 this._ref_buf = i_buffer;
\r
105 this._reader.syncBuffer(i_buffer);
\r
108 public INyARBufferReader getBufferReader()
\r
110 return this._reader;
\r
113 public INyARRgbPixelReader getRgbPixelReader()
\r
115 return this._reader;
\r
123 public boolean hasData()
\r
125 return this._ref_buf != null;
\r
129 * 保持しているデータからBufferedImageを作って返します。
\r
133 public BufferedImage createImage()
\r
135 _raster.setDataElements(0, 0, this._size.w, this._size.h, this._ref_buf);
\r
136 _image.setData(_raster);
\r