-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshow.c
161 lines (134 loc) · 4.78 KB
/
show.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Use Gtk+ to show a single frame from the dc1394 camera
*
* Written by John Stowers <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <dc1394/dc1394.h>
#include "camera.h"
#include "utils.h"
#include "gtkutils.h"
static show_mode_t show;
static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
gtk_main_quit();
return TRUE;
}
static gboolean expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
render_frame_to_widget(data, widget, show);
return TRUE;
}
int main(int argc, char *argv[])
{
dc1394_t * d;
dc1394camera_t *camera;
dc1394video_frame_t *frame;
dc1394error_t err;
unsigned int width, height;
GtkWidget *window, *canvas;
char *format = NULL;
guint64 guid;
/* Option parsing */
GError *error = NULL;
GOptionContext *context;
GOptionEntry entries[] =
{
GOPTION_ENTRY_FORMAT(&format),
GOPTION_ENTRY_GUID(&guid),
{ NULL }
};
context = g_option_context_new("- Firefly MV Camera Viewer");
g_option_context_set_summary(context, "Shows a single frame from the selected camera");
g_option_context_add_main_entries (context, entries, NULL);
/* Defaults */
guid = MY_CAMERA_GUID;
show = GRAY;
if (!g_option_context_parse (context, &argc, &argv, &error)) {
printf( "Error: %s\n%s",
error->message,
g_option_context_get_help(context, TRUE, NULL));
exit(1);
}
if (format && format[0])
show = format[0];
switch (show) {
case GRAY:
case COLOR:
case FORMAT7:
printf("Selected mode: %c\n", show);
break;
default:
printf("Invalid mode\nUsage:\n\t%s [g|c|7]\n",argv[0]);
return 1;
}
d = dc1394_new ();
if (!d)
app_exit(2, NULL, "Could not initialize libdc1394");
camera = dc1394_camera_new (d, guid);
if (!camera)
app_exit(3, context, "Could not find or initialize camera");
gtk_init( &argc, &argv );
// setup capture
switch (show) {
case GRAY:
case COLOR:
dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_640x480_MONO8, &width, &height);
err=setup_gray_capture(camera, DC1394_VIDEO_MODE_640x480_MONO8);
break;
case FORMAT7:
dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0, &width, &height);
err=setup_color_capture(camera, DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_RAW8);
break;
}
DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not setup camera");
// have the camera start sending us data
err=dc1394_video_set_transmission(camera, DC1394_ON);
DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission");
// capture one frame
err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not capture a frame");
// stop data transmission
err=dc1394_video_set_transmission(camera,DC1394_OFF);
DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not stop the camera");
// create window
gtk_widget_set_default_colormap (gdk_rgb_get_cmap());
gtk_widget_set_default_visual (gdk_rgb_get_visual());
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
g_signal_connect(
G_OBJECT(window), "delete_event",
G_CALLBACK(delete_event), NULL );
gtk_container_set_border_width( GTK_CONTAINER(window), 10 );
canvas = gtk_drawing_area_new();
gtk_widget_set_size_request(canvas, width, height);
g_signal_connect (G_OBJECT (canvas), "expose_event",
G_CALLBACK (expose_event_callback), frame);
gtk_container_add( GTK_CONTAINER(window), canvas );
// go
gtk_widget_show_all( window );
gtk_main();
// close camera
cleanup_and_exit(camera);
dc1394_free (d);
return 0;
}