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/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/src/camera.c \
|
||||
$(PACKAGE)-$(VERSION)/src/overlay.c \
|
||||
$(PACKAGE)-$(VERSION)/src/main.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/camera.h \
|
||||
$(PACKAGE)-$(VERSION)/src/overlay.h \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/tools/gallery.c \
|
||||
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||
|
|
|
@ -17,16 +17,19 @@ INSTALL = install
|
|||
|
||||
all: $(TARGETS)
|
||||
|
||||
camera_OBJS = camera.o main.o
|
||||
camera_OBJS = camera.o overlay.o main.o
|
||||
camera_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
camera_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
camera: $(camera_OBJS)
|
||||
$(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
|
||||
|
||||
overlay.o: overlay.c overlay.h
|
||||
$(CC) $(camera_CFLAGS) -c overlay.c
|
||||
|
||||
main.o: main.c camera.h
|
||||
$(CC) $(camera_CFLAGS) -c main.c
|
||||
|
||||
|
|
41
src/camera.c
41
src/camera.c
|
@ -69,6 +69,10 @@ struct _Camera
|
|||
/* decoding */
|
||||
int yuv_amp;
|
||||
|
||||
/* overlays */
|
||||
CameraOverlay ** overlays;
|
||||
size_t overlays_cnt;
|
||||
|
||||
/* widgets */
|
||||
PangoFontDescription * bold;
|
||||
GdkGC * gc;
|
||||
|
@ -215,6 +219,8 @@ Camera * camera_new(char const * device)
|
|||
camera->rgb_buffer = NULL;
|
||||
camera->rgb_buffer_cnt = 0;
|
||||
camera->yuv_amp = 255;
|
||||
camera->overlays = NULL;
|
||||
camera->overlays_cnt = 0;
|
||||
camera->bold = NULL;
|
||||
camera->gc = NULL;
|
||||
camera->window = NULL;
|
||||
|
@ -293,8 +299,13 @@ Camera * camera_new(char const * device)
|
|||
/* camera_delete */
|
||||
void camera_delete(Camera * camera)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if(camera->source != 0)
|
||||
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)
|
||||
{
|
||||
/* XXX we ignore errors at this point */
|
||||
|
@ -323,6 +334,23 @@ void camera_delete(Camera * camera)
|
|||
|
||||
|
||||
/* 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 */
|
||||
static int _snapshot_dcim(Camera * camera, char const * homedir,
|
||||
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_yuv(int amp, uint8_t y, uint8_t u, uint8_t v,
|
||||
uint8_t * r, uint8_t * g, uint8_t * b);
|
||||
static void _refresh_overlays(Camera * camera, GdkPixbuf * pixbuf);
|
||||
|
||||
static gboolean _camera_on_refresh(gpointer data)
|
||||
{
|
||||
|
@ -880,7 +909,8 @@ static gboolean _camera_on_refresh(gpointer data)
|
|||
camera->format.fmt.pix.pixelformat);
|
||||
#endif
|
||||
_refresh_convert(camera);
|
||||
if(width == allocation->width && height == allocation->height)
|
||||
if(width == allocation->width && height == allocation->height
|
||||
&& camera->overlays_cnt == 0)
|
||||
/* render directly */
|
||||
gdk_draw_rgb_image(camera->pixmap, camera->gc, 0, 0,
|
||||
width, height, GDK_RGB_DITHER_NORMAL,
|
||||
|
@ -893,6 +923,7 @@ static gboolean _camera_on_refresh(gpointer data)
|
|||
width * 3, NULL, NULL);
|
||||
pixbuf2 = gdk_pixbuf_scale_simple(pixbuf, allocation->width,
|
||||
allocation->height, GDK_INTERP_BILINEAR);
|
||||
_refresh_overlays(camera, pixbuf2);
|
||||
gdk_pixbuf_render_to_drawable(pixbuf2, camera->pixmap,
|
||||
camera->gc, 0, 0, 0, 0, -1, -1,
|
||||
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);
|
||||
}
|
||||
|
||||
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 */
|
||||
static void _camera_on_snapshot(gpointer data)
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#ifndef CAMERA_CAMERA_H
|
||||
# define CAMERA_CAMERA_H
|
||||
|
||||
# include "overlay.h"
|
||||
|
||||
|
||||
/* public */
|
||||
/* types */
|
||||
|
@ -31,4 +33,7 @@ void camera_delete(Camera * camera);
|
|||
/* useful */
|
||||
int camera_snapshot(Camera * camera);
|
||||
|
||||
CameraOverlay * camera_add_overlay(Camera * camera, char const * filename,
|
||||
int opacity);
|
||||
|
||||
#endif /* !CAMERA_CAMERA_H */
|
||||
|
|
21
src/main.c
21
src/main.c
|
@ -1,5 +1,5 @@
|
|||
/* $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 program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -40,19 +40,21 @@
|
|||
|
||||
/* private */
|
||||
/* prototypes */
|
||||
static int _camera(char const * device);
|
||||
static int _camera(char const * device, char const * overlay);
|
||||
|
||||
static int _usage(void);
|
||||
|
||||
|
||||
/* functions */
|
||||
/* camera */
|
||||
static int _camera(char const * device)
|
||||
static int _camera(char const * device, char const * overlay)
|
||||
{
|
||||
Camera * camera;
|
||||
|
||||
if((camera = camera_new(device)) == NULL)
|
||||
return error_print(PACKAGE);
|
||||
if(overlay != NULL)
|
||||
camera_add_overlay(camera, overlay, 50);
|
||||
gtk_main();
|
||||
camera_delete(camera);
|
||||
return 0;
|
||||
|
@ -62,8 +64,9 @@ static int _camera(char const * device)
|
|||
/* usage */
|
||||
static int _usage(void)
|
||||
{
|
||||
fputs(_("Usage: camera [-d device]\n"
|
||||
" -d Video device to open\n"), stderr);
|
||||
fputs(_("Usage: camera [-d device][-O filename]\n"
|
||||
" -d Video device to open\n"
|
||||
" -O Use this file as an overlay\n"), stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -75,21 +78,25 @@ int main(int argc, char * argv[])
|
|||
{
|
||||
int o;
|
||||
char const * device = NULL;
|
||||
char const * overlay = NULL;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
gtk_init(&argc, &argv);
|
||||
while((o = getopt(argc, argv, "d:")) != -1)
|
||||
while((o = getopt(argc, argv, "d:O:")) != -1)
|
||||
switch(o)
|
||||
{
|
||||
case 'd':
|
||||
device = optarg;
|
||||
break;
|
||||
case 'O':
|
||||
overlay = optarg;
|
||||
break;
|
||||
default:
|
||||
return _usage();
|
||||
}
|
||||
if(optind != argc)
|
||||
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=-Wall -g -O2
|
||||
ldflags_force=`pkg-config --libs libDesktop`
|
||||
dist=Makefile,camera.h
|
||||
dist=Makefile,camera.h,overlay.h
|
||||
|
||||
[camera]
|
||||
type=binary
|
||||
sources=camera.c,main.c
|
||||
sources=camera.c,overlay.c,main.c
|
||||
install=$(BINDIR)
|
||||
|
||||
[camera.c]
|
||||
depends=camera.h
|
||||
depends=overlay.h,camera.h
|
||||
|
||||
[overlay.c]
|
||||
depends=overlay.h
|
||||
|
||||
[main.c]
|
||||
depends=camera.h
|
||||
|
|
Loading…
Reference in New Issue
Block a user