OSDN Git Service

[TAG]NyARToolkit-2.0.0
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.0.0 / src.utils / qt / jp / nyatla / nyartoolkit / qt / utils / QtNyARRaster_RGB.java
1 /* \r
2  * PROJECT: NyARToolkit Quicktime utilities.\r
3  * --------------------------------------------------------------------------------\r
4  * Copyright (C)2008 arc@dmz\r
5  *\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
10  * \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
15  * \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
19  * \r
20  * For further information please contact.\r
21  *      \r
22  *      <arc(at)digitalmuseum.jp>\r
23  * \r
24  */\r
25 package jp.nyatla.nyartoolkit.qt.utils;\r
26 \r
27 import java.awt.image.BufferedImage;\r
28 import java.awt.image.DataBuffer;\r
29 import java.awt.image.WritableRaster;\r
30 \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
35 /**\r
36  * RGB形式のbyte配列をラップするNyARRasterです。\r
37  * 保持したデータからBufferedImageを出力する機能も持ちます。\r
38  */\r
39 public class QtNyARRaster_RGB extends NyARRgbRaster_BasicClass\r
40 {\r
41         private class PixcelReader extends NyARRgbPixelReader_RGB24 implements INyARBufferReader\r
42         {\r
43                 public PixcelReader(NyARIntSize i_size)\r
44                 {\r
45                         super(null, i_size);\r
46                         return;\r
47                 }\r
48 \r
49                 public void syncBuffer(byte[] i_ref_buffer)\r
50                 {\r
51                         this._ref_buf = i_ref_buffer;\r
52                         return;\r
53                 }\r
54 \r
55                 //\r
56                 // INyARBufferReader\r
57                 //\r
58                 public Object getBuffer()\r
59                 {\r
60                         return this._ref_buf;\r
61                 }\r
62 \r
63                 public int getBufferType()\r
64                 {\r
65                         return INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;\r
66                 }\r
67 \r
68                 public boolean isEqualBufferType(int i_type_value)\r
69                 {\r
70                         return i_type_value == INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24;\r
71                 }\r
72         }\r
73 \r
74         protected byte[] _ref_buf;\r
75 \r
76         protected PixcelReader _reader;\r
77 \r
78         private WritableRaster _raster;\r
79 \r
80         private BufferedImage _image;\r
81 \r
82         /**\r
83          * RGB形式のJMFバッファをラップするオブジェクトをつくります。 生成直後のオブジェクトはデータを持ちません。 メンバ関数はsetBufferを実行後に使用可能になります。\r
84          */\r
85         public QtNyARRaster_RGB(int i_width, int i_height)\r
86         {\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
92         }\r
93 \r
94         /**\r
95          * javax.media.Bufferを分析して、その分析結果をNyARRasterに適合する形で保持します。 関数実行後に外部でi_bufferの内容変更した場合には、再度setBuffer関数を呼び出してください。\r
96          * \r
97          * @param i_buffer\r
98          * RGB形式のデータを格納したjavax.media.Bufferオブジェクトを指定してください。\r
99          * @return i_bufferをラップしたオブジェクトを返します。\r
100          * @throws NyARException\r
101          */\r
102         public void setBuffer(byte[] i_buffer)\r
103         {\r
104                 this._ref_buf = i_buffer;\r
105                 this._reader.syncBuffer(i_buffer);\r
106         }\r
107 \r
108         public INyARBufferReader getBufferReader()\r
109         {\r
110                 return this._reader;\r
111         }\r
112 \r
113         public INyARRgbPixelReader getRgbPixelReader()\r
114         {\r
115                 return this._reader;\r
116         }\r
117 \r
118         /**\r
119          * データを持っているかを返します。\r
120          * \r
121          * @return\r
122          */\r
123         public boolean hasData()\r
124         {\r
125                 return this._ref_buf != null;\r
126         }\r
127 \r
128         /**\r
129          * 保持しているデータからBufferedImageを作って返します。\r
130          * \r
131          * @return\r
132          */\r
133         public BufferedImage createImage()\r
134         {\r
135                 _raster.setDataElements(0, 0, this._size.w, this._size.h, this._ref_buf);\r
136                 _image.setData(_raster);\r
137                 return _image;\r
138         }\r
139 \r
140 }\r