Saving snapshots in the DCIM directory
This commit is contained in:
parent
16390fbc25
commit
2d60f2fd17
32
src/camera.c
32
src/camera.c
|
@ -816,12 +816,37 @@ static void _refresh_convert_yuv(int amp, uint8_t y, uint8_t u, uint8_t v,
|
||||||
static void _camera_on_snapshot(gpointer data)
|
static void _camera_on_snapshot(gpointer data)
|
||||||
{
|
{
|
||||||
Camera * camera = data;
|
Camera * camera = data;
|
||||||
|
char const * homedir;
|
||||||
|
char const dcim[] = "DCIM";
|
||||||
|
char * path;
|
||||||
GdkPixbuf * pixbuf;
|
GdkPixbuf * pixbuf;
|
||||||
GError * error = NULL;
|
GError * error = NULL;
|
||||||
|
|
||||||
if(camera->rgb_buffer == NULL)
|
if(camera->rgb_buffer == NULL)
|
||||||
/* ignore the action */
|
/* ignore the action */
|
||||||
return;
|
return;
|
||||||
|
if((homedir = getenv("HOME")) == NULL)
|
||||||
|
homedir = g_get_home_dir();
|
||||||
|
if((path = g_build_filename(homedir, dcim, NULL)) == NULL)
|
||||||
|
{
|
||||||
|
_camera_error(camera, "Could not save picture", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(mkdir(path, 0777) != 0 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
error_set("%s: %s: %s", "Could not save picture", path,
|
||||||
|
strerror(errno));
|
||||||
|
_camera_error(camera, error_get(), 1);
|
||||||
|
free(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(path);
|
||||||
|
if((path = g_build_filename(homedir, dcim, "Snapshot.png", NULL))
|
||||||
|
== NULL)
|
||||||
|
{
|
||||||
|
_camera_error(camera, "Could not save picture", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if((pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer,
|
if((pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer,
|
||||||
GDK_COLORSPACE_RGB, FALSE, 8,
|
GDK_COLORSPACE_RGB, FALSE, 8,
|
||||||
camera->format.fmt.pix.width,
|
camera->format.fmt.pix.width,
|
||||||
|
@ -830,14 +855,15 @@ static void _camera_on_snapshot(gpointer data)
|
||||||
NULL, NULL)) == NULL)
|
NULL, NULL)) == NULL)
|
||||||
{
|
{
|
||||||
_camera_error(camera, "Could not save picture", 1);
|
_camera_error(camera, "Could not save picture", 1);
|
||||||
|
free(path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(gdk_pixbuf_save(pixbuf, "Snapshot.png", "png", &error, NULL)
|
if(gdk_pixbuf_save(pixbuf, path, "png", &error, NULL) != TRUE)
|
||||||
!= TRUE)
|
|
||||||
{
|
{
|
||||||
error_set("%s (%s)", "Could not save picture", error->message);
|
error_set("%s (%s)", "Could not save picture", error->message);
|
||||||
_camera_error(camera, error_get(), 1);
|
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
|
_camera_error(camera, error_get(), 1);
|
||||||
}
|
}
|
||||||
|
free(path);
|
||||||
g_object_unref(pixbuf);
|
g_object_unref(pixbuf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user