Initial support for overlay (untested)
This commit is contained in:
parent
dd33550c6a
commit
f0708e3413
2
Makefile
2
Makefile
|
@ -36,9 +36,11 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/po/fr.po \
|
$(PACKAGE)-$(VERSION)/po/fr.po \
|
||||||
$(PACKAGE)-$(VERSION)/po/project.conf \
|
$(PACKAGE)-$(VERSION)/po/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/src/camera.c \
|
$(PACKAGE)-$(VERSION)/src/camera.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/overlay.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/main.c \
|
$(PACKAGE)-$(VERSION)/src/main.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/src/camera.h \
|
$(PACKAGE)-$(VERSION)/src/camera.h \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/overlay.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/tools/gallery.c \
|
$(PACKAGE)-$(VERSION)/tools/gallery.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||||
|
|
|
@ -17,16 +17,19 @@ INSTALL = install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
camera_OBJS = camera.o main.o
|
camera_OBJS = camera.o overlay.o main.o
|
||||||
camera_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
camera_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
camera_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
camera_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
camera: $(camera_OBJS)
|
camera: $(camera_OBJS)
|
||||||
$(CC) -o camera $(camera_OBJS) $(camera_LDFLAGS)
|
$(CC) -o camera $(camera_OBJS) $(camera_LDFLAGS)
|
||||||
|
|
||||||
camera.o: camera.c camera.h
|
camera.o: camera.c overlay.h camera.h
|
||||||
$(CC) $(camera_CFLAGS) -c camera.c
|
$(CC) $(camera_CFLAGS) -c camera.c
|
||||||
|
|
||||||
|
overlay.o: overlay.c overlay.h
|
||||||
|
$(CC) $(camera_CFLAGS) -c overlay.c
|
||||||
|
|
||||||
main.o: main.c camera.h
|
main.o: main.c camera.h
|
||||||
$(CC) $(camera_CFLAGS) -c main.c
|
$(CC) $(camera_CFLAGS) -c main.c
|
||||||
|
|
||||||
|
|
41
src/camera.c
41
src/camera.c
|
@ -69,6 +69,10 @@ struct _Camera
|
||||||
/* decoding */
|
/* decoding */
|
||||||
int yuv_amp;
|
int yuv_amp;
|
||||||
|
|
||||||
|
/* overlays */
|
||||||
|
CameraOverlay ** overlays;
|
||||||
|
size_t overlays_cnt;
|
||||||
|
|
||||||
/* widgets */
|
/* widgets */
|
||||||
PangoFontDescription * bold;
|
PangoFontDescription * bold;
|
||||||
GdkGC * gc;
|
GdkGC * gc;
|
||||||
|
@ -215,6 +219,8 @@ Camera * camera_new(char const * device)
|
||||||
camera->rgb_buffer = NULL;
|
camera->rgb_buffer = NULL;
|
||||||
camera->rgb_buffer_cnt = 0;
|
camera->rgb_buffer_cnt = 0;
|
||||||
camera->yuv_amp = 255;
|
camera->yuv_amp = 255;
|
||||||
|
camera->overlays = NULL;
|
||||||
|
camera->overlays_cnt = 0;
|
||||||
camera->bold = NULL;
|
camera->bold = NULL;
|
||||||
camera->gc = NULL;
|
camera->gc = NULL;
|
||||||
camera->window = NULL;
|
camera->window = NULL;
|
||||||
|
@ -293,8 +299,13 @@ Camera * camera_new(char const * device)
|
||||||
/* camera_delete */
|
/* camera_delete */
|
||||||
void camera_delete(Camera * camera)
|
void camera_delete(Camera * camera)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if(camera->source != 0)
|
if(camera->source != 0)
|
||||||
g_source_remove(camera->source);
|
g_source_remove(camera->source);
|
||||||
|
for(i = 0; i < camera->overlays_cnt; i++)
|
||||||
|
cameraoverlay_delete(camera->overlays[i]);
|
||||||
|
free(camera->overlays);
|
||||||
if(camera->channel != NULL)
|
if(camera->channel != NULL)
|
||||||
{
|
{
|
||||||
/* XXX we ignore errors at this point */
|
/* XXX we ignore errors at this point */
|
||||||
|
@ -323,6 +334,23 @@ void camera_delete(Camera * camera)
|
||||||
|
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
|
/* camera_add_overlay */
|
||||||
|
CameraOverlay * camera_add_overlay(Camera * camera, char const * filename,
|
||||||
|
int opacity)
|
||||||
|
{
|
||||||
|
CameraOverlay ** p;
|
||||||
|
|
||||||
|
if((p = realloc(camera->overlays, (camera->overlays_cnt + 1)
|
||||||
|
* sizeof(*p))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
camera->overlays = p;
|
||||||
|
if((camera->overlays[camera->overlays_cnt] = cameraoverlay_new(
|
||||||
|
filename, opacity)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
return camera->overlays[camera->overlays_cnt++];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* camera_snapshot */
|
/* camera_snapshot */
|
||||||
static int _snapshot_dcim(Camera * camera, char const * homedir,
|
static int _snapshot_dcim(Camera * camera, char const * homedir,
|
||||||
char const * dcim);
|
char const * dcim);
|
||||||
|
@ -865,6 +893,7 @@ static GtkWidget * _properties_label(Camera * camera, GtkSizeGroup * group,
|
||||||
static void _refresh_convert(Camera * camera);
|
static void _refresh_convert(Camera * camera);
|
||||||
static void _refresh_convert_yuv(int amp, uint8_t y, uint8_t u, uint8_t v,
|
static void _refresh_convert_yuv(int amp, uint8_t y, uint8_t u, uint8_t v,
|
||||||
uint8_t * r, uint8_t * g, uint8_t * b);
|
uint8_t * r, uint8_t * g, uint8_t * b);
|
||||||
|
static void _refresh_overlays(Camera * camera, GdkPixbuf * pixbuf);
|
||||||
|
|
||||||
static gboolean _camera_on_refresh(gpointer data)
|
static gboolean _camera_on_refresh(gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -880,7 +909,8 @@ 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(width == allocation->width && height == allocation->height
|
||||||
|
&& 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,
|
||||||
width, height, GDK_RGB_DITHER_NORMAL,
|
width, height, GDK_RGB_DITHER_NORMAL,
|
||||||
|
@ -893,6 +923,7 @@ static gboolean _camera_on_refresh(gpointer data)
|
||||||
width * 3, NULL, NULL);
|
width * 3, NULL, NULL);
|
||||||
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);
|
||||||
gdk_pixbuf_render_to_drawable(pixbuf2, camera->pixmap,
|
gdk_pixbuf_render_to_drawable(pixbuf2, camera->pixmap,
|
||||||
camera->gc, 0, 0, 0, 0, -1, -1,
|
camera->gc, 0, 0, 0, 0, -1, -1,
|
||||||
GDK_RGB_DITHER_NORMAL, 0, 0);
|
GDK_RGB_DITHER_NORMAL, 0, 0);
|
||||||
|
@ -961,6 +992,14 @@ static void _refresh_convert_yuv(int amp, uint8_t y, uint8_t u, uint8_t v,
|
||||||
*b = (db < 0) ? 0 : ((db > 255) ? 255 : db);
|
*b = (db < 0) ? 0 : ((db > 255) ? 255 : db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _refresh_overlays(Camera * camera, GdkPixbuf * pixbuf)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for(i = 0; i < camera->overlays_cnt; i++)
|
||||||
|
cameraoverlay_blit(camera->overlays[i], pixbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* camera_on_snapshot */
|
/* camera_on_snapshot */
|
||||||
static void _camera_on_snapshot(gpointer data)
|
static void _camera_on_snapshot(gpointer data)
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#ifndef CAMERA_CAMERA_H
|
#ifndef CAMERA_CAMERA_H
|
||||||
# define CAMERA_CAMERA_H
|
# define CAMERA_CAMERA_H
|
||||||
|
|
||||||
|
# include "overlay.h"
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
/* types */
|
/* types */
|
||||||
|
@ -31,4 +33,7 @@ void camera_delete(Camera * camera);
|
||||||
/* useful */
|
/* useful */
|
||||||
int camera_snapshot(Camera * camera);
|
int camera_snapshot(Camera * camera);
|
||||||
|
|
||||||
|
CameraOverlay * camera_add_overlay(Camera * camera, char const * filename,
|
||||||
|
int opacity);
|
||||||
|
|
||||||
#endif /* !CAMERA_CAMERA_H */
|
#endif /* !CAMERA_CAMERA_H */
|
||||||
|
|
21
src/main.c
21
src/main.c
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
/* Copyright (c) 2012-2013 Pierre Pronchery <khorben@defora.org> */
|
||||||
/* This file is part of DeforaOS Desktop Camera */
|
/* This file is part of DeforaOS Desktop Camera */
|
||||||
/* This program is free software: you can redistribute it and/or modify
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -40,19 +40,21 @@
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _camera(char const * device);
|
static int _camera(char const * device, char const * overlay);
|
||||||
|
|
||||||
static int _usage(void);
|
static int _usage(void);
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* camera */
|
/* camera */
|
||||||
static int _camera(char const * device)
|
static int _camera(char const * device, char const * overlay)
|
||||||
{
|
{
|
||||||
Camera * camera;
|
Camera * camera;
|
||||||
|
|
||||||
if((camera = camera_new(device)) == NULL)
|
if((camera = camera_new(device)) == NULL)
|
||||||
return error_print(PACKAGE);
|
return error_print(PACKAGE);
|
||||||
|
if(overlay != NULL)
|
||||||
|
camera_add_overlay(camera, overlay, 50);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
camera_delete(camera);
|
camera_delete(camera);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -62,8 +64,9 @@ static int _camera(char const * device)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fputs(_("Usage: camera [-d device]\n"
|
fputs(_("Usage: camera [-d device][-O filename]\n"
|
||||||
" -d Video device to open\n"), stderr);
|
" -d Video device to open\n"
|
||||||
|
" -O Use this file as an overlay\n"), stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,21 +78,25 @@ int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int o;
|
int o;
|
||||||
char const * device = NULL;
|
char const * device = 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:")) != -1)
|
while((o = getopt(argc, argv, "d:O:")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
device = optarg;
|
device = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'O':
|
||||||
|
overlay = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(optind != argc)
|
if(optind != argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
return (_camera(device) == 0) ? 0 : 2;
|
return (_camera(device, overlay) == 0) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
91
src/overlay.c
Normal file
91
src/overlay.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS desktop camera */
|
||||||
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <System.h>
|
||||||
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
#include "overlay.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* CameraOverlay */
|
||||||
|
/* protected */
|
||||||
|
/* types */
|
||||||
|
struct _CameraOverlay
|
||||||
|
{
|
||||||
|
GdkPixbuf * pixbuf;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int opacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* functions */
|
||||||
|
/* cameraoverlay_new */
|
||||||
|
CameraOverlay * cameraoverlay_new(char const * filename, int opacity)
|
||||||
|
{
|
||||||
|
CameraOverlay * overlay;
|
||||||
|
GError * error = NULL;
|
||||||
|
|
||||||
|
if((overlay = object_new(sizeof(*overlay))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
if((overlay->pixbuf = gdk_pixbuf_new_from_file(filename, &error))
|
||||||
|
== NULL)
|
||||||
|
{
|
||||||
|
error_set("%s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
cameraoverlay_delete(overlay);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
overlay->width = gdk_pixbuf_get_width(overlay->pixbuf);
|
||||||
|
overlay->height = gdk_pixbuf_get_height(overlay->pixbuf);
|
||||||
|
overlay->opacity = opacity;
|
||||||
|
return overlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* cameraoverlay_delete */
|
||||||
|
void cameraoverlay_delete(CameraOverlay * overlay)
|
||||||
|
{
|
||||||
|
if(overlay->pixbuf != NULL)
|
||||||
|
g_object_unref(overlay->pixbuf);
|
||||||
|
object_delete(overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* accessors */
|
||||||
|
/* cameraoverlay_get_opacity */
|
||||||
|
int cameraoverlay_get_opacity(CameraOverlay * overlay)
|
||||||
|
{
|
||||||
|
return overlay->opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* cameraoverlay_set_opacity */
|
||||||
|
void cameraoverlay_set_opacity(CameraOverlay * overlay, int opacity)
|
||||||
|
{
|
||||||
|
overlay->opacity = opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
void cameraoverlay_blit(CameraOverlay * overlay, GdkPixbuf * dest)
|
||||||
|
{
|
||||||
|
/* XXX hard-coded */
|
||||||
|
gdk_pixbuf_composite(overlay->pixbuf, dest, 0, 0, overlay->width,
|
||||||
|
overlay->height, 0, 0, 1.0, 1.0,
|
||||||
|
GDK_INTERP_BILINEAR, overlay->opacity);
|
||||||
|
}
|
38
src/overlay.h
Normal file
38
src/overlay.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS desktop camera */
|
||||||
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CAMERA_OVERLAY_H
|
||||||
|
# define CAMERA_OVERLAY_H
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* types */
|
||||||
|
typedef struct _CameraOverlay CameraOverlay;
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
CameraOverlay * cameraoverlay_new(char const * filename, int opacity);
|
||||||
|
void cameraoverlay_delete(CameraOverlay * overlay);
|
||||||
|
|
||||||
|
/* accessors */
|
||||||
|
int cameraoverlay_get_opacity(CameraOverlay * overlay);
|
||||||
|
void cameraoverlay_set_opacity(CameraOverlay * overlay, int opacity);
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
void cameraoverlay_blit(CameraOverlay * overlay, GdkPixbuf * dest);
|
||||||
|
|
||||||
|
#endif /* !CAMERA_OVERLAY_H */
|
|
@ -2,15 +2,18 @@ targets=camera
|
||||||
cflags_force=-W `pkg-config --cflags libDesktop`
|
cflags_force=-W `pkg-config --cflags libDesktop`
|
||||||
cflags=-Wall -g -O2
|
cflags=-Wall -g -O2
|
||||||
ldflags_force=`pkg-config --libs libDesktop`
|
ldflags_force=`pkg-config --libs libDesktop`
|
||||||
dist=Makefile,camera.h
|
dist=Makefile,camera.h,overlay.h
|
||||||
|
|
||||||
[camera]
|
[camera]
|
||||||
type=binary
|
type=binary
|
||||||
sources=camera.c,main.c
|
sources=camera.c,overlay.c,main.c
|
||||||
install=$(BINDIR)
|
install=$(BINDIR)
|
||||||
|
|
||||||
[camera.c]
|
[camera.c]
|
||||||
depends=camera.h
|
depends=overlay.h,camera.h
|
||||||
|
|
||||||
|
[overlay.c]
|
||||||
|
depends=overlay.h
|
||||||
|
|
||||||
[main.c]
|
[main.c]
|
||||||
depends=camera.h
|
depends=camera.h
|
||||||
|
|
Loading…
Reference in New Issue
Block a user