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
|
||||
{
|
||||
String * device;
|
||||
gboolean flip;
|
||||
|
||||
guint source;
|
||||
int fd;
|
||||
|
@ -143,7 +144,7 @@ static DesktopToolbar _camera_toolbar[] =
|
|||
/* functions */
|
||||
/* camera_new */
|
||||
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
||||
char const * device)
|
||||
char const * device, int flip)
|
||||
{
|
||||
Camera * camera;
|
||||
GtkWidget * vbox;
|
||||
|
@ -154,6 +155,7 @@ Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
|||
if(device == NULL)
|
||||
device = "/dev/video0";
|
||||
camera->device = string_new(device);
|
||||
camera->flip = flip ? TRUE : FALSE;
|
||||
camera->source = 0;
|
||||
camera->fd = -1;
|
||||
memset(&camera->cap, 0, sizeof(camera->cap));
|
||||
|
@ -863,7 +865,9 @@ static gboolean _camera_on_refresh(gpointer data)
|
|||
camera->format.fmt.pix.pixelformat);
|
||||
#endif
|
||||
_refresh_convert(camera);
|
||||
if(width == allocation->width && height == allocation->height
|
||||
if(camera->flip == FALSE
|
||||
&& width == allocation->width
|
||||
&& height == allocation->height
|
||||
&& camera->overlays_cnt == 0)
|
||||
/* render directly */
|
||||
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,
|
||||
GDK_COLORSPACE_RGB, FALSE, 8, width, height,
|
||||
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,
|
||||
allocation->height, GDK_INTERP_BILINEAR);
|
||||
_refresh_overlays(camera, pixbuf2);
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef enum _CameraSnapshotFormat
|
|||
|
||||
/* functions */
|
||||
Camera * camera_new(GtkWidget * window, GtkAccelGroup * group,
|
||||
char const * device);
|
||||
char const * device, int flip);
|
||||
void camera_delete(Camera * camera);
|
||||
|
||||
/* accessors */
|
||||
|
|
28
src/main.c
28
src/main.c
|
@ -44,23 +44,26 @@
|
|||
|
||||
/* private */
|
||||
/* 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);
|
||||
|
||||
|
||||
/* functions */
|
||||
/* 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 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;
|
||||
|
||||
if(embedded != 0)
|
||||
return _camera_embedded(device, overlay);
|
||||
if((camera = camerawindow_new(device)) == NULL)
|
||||
return _camera_embedded(device, flip, overlay);
|
||||
if((camera = camerawindow_new(device, flip)) == NULL)
|
||||
return error_print(PACKAGE);
|
||||
if(overlay != NULL)
|
||||
camerawindow_add_overlay(camera, overlay, 50);
|
||||
|
@ -69,7 +72,7 @@ static int _camera(int embedded, char const * device, char const * overlay)
|
|||
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 * widget;
|
||||
|
@ -80,7 +83,7 @@ static int _camera_embedded(char const * device, char const * overlay)
|
|||
gtk_widget_realize(window);
|
||||
g_signal_connect_swapped(window, "embedded", G_CALLBACK(
|
||||
_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);
|
||||
return -1;
|
||||
|
@ -109,8 +112,9 @@ static void _embedded_on_embedded(gpointer data)
|
|||
/* usage */
|
||||
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"
|
||||
" -H Flip horizontally\n"
|
||||
" -O Use this file as an overlay\n"
|
||||
" -x Start in embedded mode\n"), PROGNAME);
|
||||
return 1;
|
||||
|
@ -125,18 +129,22 @@ int main(int argc, char * argv[])
|
|||
int o;
|
||||
int embedded = 0;
|
||||
char const * device = NULL;
|
||||
int flip = 0;
|
||||
char const * overlay = NULL;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
gtk_init(&argc, &argv);
|
||||
while((o = getopt(argc, argv, "d:O:x")) != -1)
|
||||
while((o = getopt(argc, argv, "d:HO:x")) != -1)
|
||||
switch(o)
|
||||
{
|
||||
case 'd':
|
||||
device = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
flip = 1;
|
||||
break;
|
||||
case 'O':
|
||||
overlay = optarg;
|
||||
break;
|
||||
|
@ -148,5 +156,5 @@ int main(int argc, char * argv[])
|
|||
}
|
||||
if(optind != argc)
|
||||
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 */
|
||||
/* functions */
|
||||
/* camerawindow_new */
|
||||
CameraWindow * camerawindow_new(char const * device)
|
||||
CameraWindow * camerawindow_new(char const * device, int flip)
|
||||
{
|
||||
CameraWindow * camera;
|
||||
GtkAccelGroup * group;
|
||||
|
@ -144,7 +144,8 @@ CameraWindow * camerawindow_new(char const * device)
|
|||
if(camera->window != NULL)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct _CameraWindow CameraWindow;
|
|||
|
||||
|
||||
/* functions */
|
||||
CameraWindow * camerawindow_new(char const * device);
|
||||
CameraWindow * camerawindow_new(char const * device, int flip);
|
||||
void camerawindow_delete(CameraWindow * camera);
|
||||
|
||||
/* useful */
|
||||
|
|
Loading…
Reference in New Issue
Block a user