Added a flag to flip the image horizontally
This commit is contained in:
parent
c4c19ca672
commit
c8117bfb0e
14
src/camera.c
14
src/camera.c
|
@ -57,6 +57,7 @@ static char const _license[] =
|
||||||
struct _Camera
|
struct _Camera
|
||||||
{
|
{
|
||||||
String * device;
|
String * device;
|
||||||
|
gboolean flip;
|
||||||
|
|
||||||
guint source;
|
guint source;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -143,7 +144,7 @@ static DesktopToolbar _camera_toolbar[] =
|
||||||
/* functions */
|
/* functions */
|
||||||
/* camera_new */
|
/* camera_new */
|
||||||
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
||||||
char const * device)
|
char const * device, int flip)
|
||||||
{
|
{
|
||||||
Camera * camera;
|
Camera * camera;
|
||||||
GtkWidget * vbox;
|
GtkWidget * vbox;
|
||||||
|
@ -154,6 +155,7 @@ Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
||||||
if(device == NULL)
|
if(device == NULL)
|
||||||
device = "/dev/video0";
|
device = "/dev/video0";
|
||||||
camera->device = string_new(device);
|
camera->device = string_new(device);
|
||||||
|
camera->flip = flip ? TRUE : FALSE;
|
||||||
camera->source = 0;
|
camera->source = 0;
|
||||||
camera->fd = -1;
|
camera->fd = -1;
|
||||||
memset(&camera->cap, 0, sizeof(camera->cap));
|
memset(&camera->cap, 0, sizeof(camera->cap));
|
||||||
|
@ -863,7 +865,9 @@ static gboolean _camera_on_refresh(gpointer data)
|
||||||
camera->format.fmt.pix.pixelformat);
|
camera->format.fmt.pix.pixelformat);
|
||||||
#endif
|
#endif
|
||||||
_refresh_convert(camera);
|
_refresh_convert(camera);
|
||||||
if(width == allocation->width && height == allocation->height
|
if(camera->flip == FALSE
|
||||||
|
&& width == allocation->width
|
||||||
|
&& height == allocation->height
|
||||||
&& camera->overlays_cnt == 0)
|
&& camera->overlays_cnt == 0)
|
||||||
/* render directly */
|
/* render directly */
|
||||||
gdk_draw_rgb_image(camera->pixmap, camera->gc, 0, 0,
|
gdk_draw_rgb_image(camera->pixmap, camera->gc, 0, 0,
|
||||||
|
@ -875,6 +879,12 @@ static gboolean _camera_on_refresh(gpointer data)
|
||||||
pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer,
|
pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer,
|
||||||
GDK_COLORSPACE_RGB, FALSE, 8, width, height,
|
GDK_COLORSPACE_RGB, FALSE, 8, width, height,
|
||||||
width * 3, NULL, NULL);
|
width * 3, NULL, NULL);
|
||||||
|
if(camera->flip)
|
||||||
|
{
|
||||||
|
pixbuf2 = gdk_pixbuf_flip(pixbuf, TRUE);
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
pixbuf = pixbuf2;
|
||||||
|
}
|
||||||
pixbuf2 = gdk_pixbuf_scale_simple(pixbuf, allocation->width,
|
pixbuf2 = gdk_pixbuf_scale_simple(pixbuf, allocation->width,
|
||||||
allocation->height, GDK_INTERP_BILINEAR);
|
allocation->height, GDK_INTERP_BILINEAR);
|
||||||
_refresh_overlays(camera, pixbuf2);
|
_refresh_overlays(camera, pixbuf2);
|
||||||
|
|
|
@ -34,7 +34,7 @@ typedef enum _CameraSnapshotFormat
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
||||||
char const * device);
|
char const * device, int flip);
|
||||||
void camera_delete(Camera * camera);
|
void camera_delete(Camera * camera);
|
||||||
|
|
||||||
/* accessors */
|
/* accessors */
|
||||||
|
|
28
src/main.c
28
src/main.c
|
@ -44,23 +44,26 @@
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _camera(int embedded, char const * device, char const * overlay);
|
static int _camera(int embedded, char const * device, int flip,
|
||||||
|
char const * overlay);
|
||||||
|
|
||||||
static int _usage(void);
|
static int _usage(void);
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* camera */
|
/* camera */
|
||||||
static int _camera_embedded(char const * device, char const * overlay);
|
static int _camera_embedded(char const * device, int flip,
|
||||||
|
char const * overlay);
|
||||||
static void _embedded_on_embedded(gpointer data);
|
static void _embedded_on_embedded(gpointer data);
|
||||||
|
|
||||||
static int _camera(int embedded, char const * device, char const * overlay)
|
static int _camera(int embedded, char const * device, int flip,
|
||||||
|
char const * overlay)
|
||||||
{
|
{
|
||||||
CameraWindow * camera;
|
CameraWindow * camera;
|
||||||
|
|
||||||
if(embedded != 0)
|
if(embedded != 0)
|
||||||
return _camera_embedded(device, overlay);
|
return _camera_embedded(device, flip, overlay);
|
||||||
if((camera = camerawindow_new(device)) == NULL)
|
if((camera = camerawindow_new(device, flip)) == NULL)
|
||||||
return error_print(PACKAGE);
|
return error_print(PACKAGE);
|
||||||
if(overlay != NULL)
|
if(overlay != NULL)
|
||||||
camerawindow_add_overlay(camera, overlay, 50);
|
camerawindow_add_overlay(camera, overlay, 50);
|
||||||
|
@ -69,7 +72,7 @@ static int _camera(int embedded, char const * device, char const * overlay)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _camera_embedded(char const * device, char const * overlay)
|
static int _camera_embedded(char const * device, int flip, char const * overlay)
|
||||||
{
|
{
|
||||||
GtkWidget * window;
|
GtkWidget * window;
|
||||||
GtkWidget * widget;
|
GtkWidget * widget;
|
||||||
|
@ -80,7 +83,7 @@ static int _camera_embedded(char const * device, char const * overlay)
|
||||||
gtk_widget_realize(window);
|
gtk_widget_realize(window);
|
||||||
g_signal_connect_swapped(window, "embedded", G_CALLBACK(
|
g_signal_connect_swapped(window, "embedded", G_CALLBACK(
|
||||||
_embedded_on_embedded), window);
|
_embedded_on_embedded), window);
|
||||||
if((camera = camera_new(window, NULL, device)) == NULL)
|
if((camera = camera_new(window, NULL, device, flip)) == NULL)
|
||||||
{
|
{
|
||||||
gtk_widget_destroy(window);
|
gtk_widget_destroy(window);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -109,8 +112,9 @@ static void _embedded_on_embedded(gpointer data)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("Usage: %s [-d device][-O filename][-x]\n"
|
fprintf(stderr, _("Usage: %s [-d device][-O filename][-Hx]\n"
|
||||||
" -d Video device to open\n"
|
" -d Video device to open\n"
|
||||||
|
" -H Flip horizontally\n"
|
||||||
" -O Use this file as an overlay\n"
|
" -O Use this file as an overlay\n"
|
||||||
" -x Start in embedded mode\n"), PROGNAME);
|
" -x Start in embedded mode\n"), PROGNAME);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -125,18 +129,22 @@ int main(int argc, char * argv[])
|
||||||
int o;
|
int o;
|
||||||
int embedded = 0;
|
int embedded = 0;
|
||||||
char const * device = NULL;
|
char const * device = NULL;
|
||||||
|
int flip = 0;
|
||||||
char const * overlay = NULL;
|
char const * overlay = NULL;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
while((o = getopt(argc, argv, "d:O:x")) != -1)
|
while((o = getopt(argc, argv, "d:HO:x")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
device = optarg;
|
device = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
flip = 1;
|
||||||
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
overlay = optarg;
|
overlay = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -148,5 +156,5 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
if(optind != argc)
|
if(optind != argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
return (_camera(embedded, device, overlay) == 0) ? 0 : 2;
|
return (_camera(embedded, device, flip, overlay) == 0) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ static const DesktopMenubar _camerawindow_menubar[] =
|
||||||
/* public */
|
/* public */
|
||||||
/* functions */
|
/* functions */
|
||||||
/* camerawindow_new */
|
/* camerawindow_new */
|
||||||
CameraWindow * camerawindow_new(char const * device)
|
CameraWindow * camerawindow_new(char const * device, int flip)
|
||||||
{
|
{
|
||||||
CameraWindow * camera;
|
CameraWindow * camera;
|
||||||
GtkAccelGroup * group;
|
GtkAccelGroup * group;
|
||||||
|
@ -144,7 +144,8 @@ CameraWindow * camerawindow_new(char const * device)
|
||||||
if(camera->window != NULL)
|
if(camera->window != NULL)
|
||||||
{
|
{
|
||||||
gtk_widget_realize(camera->window);
|
gtk_widget_realize(camera->window);
|
||||||
camera->camera = camera_new(camera->window, group, device);
|
camera->camera = camera_new(camera->window, group, device,
|
||||||
|
flip);
|
||||||
}
|
}
|
||||||
if(camera->camera == NULL)
|
if(camera->camera == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef struct _CameraWindow CameraWindow;
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
CameraWindow * camerawindow_new(char const * device);
|
CameraWindow * camerawindow_new(char const * device, int flip);
|
||||||
void camerawindow_delete(CameraWindow * camera);
|
void camerawindow_delete(CameraWindow * camera);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user