OSDN Git Service

Merge branch 'git-svn'
[nyartoolkit-and/nyartoolkit-and.git] / trunk / sample / qt / jp / nyatla / nyartoolkit / qt / sample / QtCaptureTest.java
1 /* 
2  * PROJECT: NyARToolkit QuickTime sample program.
3  * --------------------------------------------------------------------------------
4  * The MIT License
5  * Copyright (c) 2008 nyatla
6  * airmail(at)ebony.plala.or.jp
7  * http://nyatla.jp/nyartoolkit/
8  * 
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  * 
26  */
27 package jp.nyatla.nyartoolkit.qt.sample;
28
29 import jp.nyatla.nyartoolkit.NyARException;
30 import jp.nyatla.nyartoolkit.qt.utils.*;
31 import jp.nyatla.nyartoolkit.core.types.*;
32
33 import java.awt.*;
34 import java.awt.image.*;
35 /**
36  * QuickTimeキャプチャプログラム
37  *
38  * On windows, You might get couldntGetRequiredComponent error.
39  * If you got error try to install WinVDIG. 
40  * http://www.eden.net.nz/7/20071008/
41  * --
42  * Windowsの場合、WinVDIGが無いとキャプチャプログラムが動かないことがあります。
43  * couldntGetRequiredComponentエラーが出たら、WinVDIGをインストールしてみてね。
44  * WinVIDGはとりあえずここから入手可能。http://www.eden.net.nz/7/20071008/
45  * 
46  *
47  */
48 public class QtCaptureTest extends Frame implements QtCaptureListener
49 {
50         private static final long serialVersionUID = -734697739607654631L;
51
52         public QtCaptureTest() throws NyARException
53         {
54                 setTitle("QtCaptureTest");
55                 setBounds(0, 0, 320 + 64, 240 + 64);
56                 capture = new QtCameraCapture(320, 240, 30f);
57                 capture.setCaptureListener(this);
58                 //キャプチャイメージ用のラスタを準備
59                 raster = new QtNyARRaster_RGB(320, 240);
60         }
61
62         private QtCameraCapture capture;
63         private QtNyARRaster_RGB raster;
64         
65         public void onUpdateBuffer(byte[] pixels)
66         {
67                 try{
68                         this.raster.wrapBuffer(pixels);
69                 }catch(Exception e){
70                         e.printStackTrace();
71                         return;
72                 }
73                 //Imageに変換してみよう!
74
75                 
76                 NyARIntSize s=raster.getSize();
77                 WritableRaster wr = WritableRaster.createInterleavedRaster(DataBuffer.TYPE_BYTE, s.w,s.h, s.w * 3, 3, new int[] { 0, 1, 2 }, null);
78                 BufferedImage  bi = new BufferedImage(s.w, s.h, BufferedImage.TYPE_3BYTE_BGR);
79
80                 wr.setDataElements(0, 0, s.w, s.h,raster.getBuffer());
81                 bi.setData(wr);
82                 
83                 Graphics g = getGraphics();
84                 g.drawImage(bi, 32, 32, this);
85         }
86
87         private void startCapture()
88         {
89                 try {
90                         capture.start();
91                 } catch (Exception e) {
92                         e.printStackTrace();
93                 }
94         }
95
96         public static void main(String[] args)
97         {
98                 try {
99                         QtCaptureTest mainwin = new QtCaptureTest();
100                         mainwin.setVisible(true);
101                         mainwin.startCapture();
102                 } catch (Exception e) {
103                         e.printStackTrace();
104                 }
105
106         }
107
108 }