OSDN Git Service

Merge branch 'git-svn'
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / src.utils / jmf / jp / nyatla / nyartoolkit / jmf / utils / sample / JmfCaptureTest.java
1 /*
2  * PROJECT: NyARToolkit JMF utilities.
3  * --------------------------------------------------------------------------------
4  * The MIT License
5  * Copyright (c) 2008 nyatla
6  * 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  * 
24  */
25
26 package jp.nyatla.nyartoolkit.jmf.utils.sample;
27
28 import javax.media.*;
29
30 import javax.media.util.BufferToImage;
31 import javax.media.format.*;
32
33 import jp.nyatla.nyartoolkit.NyARException;
34 import jp.nyatla.nyartoolkit.jmf.utils.*;
35
36 import java.awt.*;
37
38 /**
39  * VFMキャプチャテストプログラム
40  */
41 public class JmfCaptureTest extends Frame implements JmfCaptureListener
42 {
43         private static final long serialVersionUID = -2110888320986446576L;
44         private JmfCaptureDevice _capture;
45         public JmfCaptureTest() throws NyARException
46         {
47                 setTitle("JmfCaptureTest");
48                 setBounds(0, 0, 320 + 64, 240 + 64);
49                 JmfCaptureDeviceList dl=new JmfCaptureDeviceList();
50                 this._capture=dl.getDevice(0);
51                 if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320,240,30.0f)){
52                         if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320,240,30.0f)){
53                                 throw new NyARException("キャプチャフォーマットが見つかりません。");
54                         }
55                 }
56                 this._capture.setOnCapture(this);
57         }
58
59
60         public void onUpdateBuffer(Buffer i_buffer)
61         {
62                 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
63                 Image img = b2i.createImage(i_buffer);
64                 Graphics g = getGraphics();
65                 g.drawImage(img, 32, 32, this);
66         }
67
68         private void startCapture()
69         {
70                 try {
71                         this._capture.start();
72                 } catch (Exception e) {
73                         e.printStackTrace();
74                 }
75         }
76
77         public static void main(String[] args)
78         {
79                 try {
80                         JmfCaptureTest mainwin = new JmfCaptureTest();
81                         mainwin.setVisible(true);
82                         mainwin.startCapture();
83                 } catch (Exception e) {
84                         e.printStackTrace();
85                 }
86
87         }
88
89 }