From 4fbf882820852658a83b4a8270a35488cb87b1b2 Mon Sep 17 00:00:00 2001 From: christetreault Date: Thu, 9 Jan 2014 09:30:35 -0800 Subject: [PATCH] Minor changes to photo strip layout Combined camera-capture and camera-download into one function --- dmp_photo_booth/coordination.c | 36 +++++++++++++--------------------- dmp_photo_booth/module.c | 25 ++++------------------- dmp_photo_booth/module.h | 9 ++------- dmp_photo_booth/photo_strip.c | 30 ++++++++++++++++++---------- dmp_photo_booth/photo_strip.h | 7 +++---- 5 files changed, 43 insertions(+), 64 deletions(-) diff --git a/dmp_photo_booth/coordination.c b/dmp_photo_booth/coordination.c index 2003cff..e6588c0 100644 --- a/dmp_photo_booth/coordination.c +++ b/dmp_photo_booth/coordination.c @@ -23,11 +23,11 @@ G_LOCK_DEFINE(photo_request); static GThreadPool * photo_request_thread_pool = NULL; #define DMP_PB_COUNTDOWN_TIME 4 -#define DMP_PB_POS5_FILE_NAME "5.jpg" -#define DMP_PB_POS4_FILE_NAME "4.jpg" -#define DMP_PB_POS3_FILE_NAME "3.jpg" -#define DMP_PB_POS2_FILE_NAME "2.jpg" -#define DMP_PB_POS1_FILE_NAME "1.jpg" +#define DMP_PB_POS5_FILE_NAME "5_" +#define DMP_PB_POS4_FILE_NAME "4_" +#define DMP_PB_POS3_FILE_NAME "3_" +#define DMP_PB_POS2_FILE_NAME "2_" +#define DMP_PB_POS1_FILE_NAME "1_" /** * counts down, captures, then downloads an image @@ -40,31 +40,23 @@ static void dmp_pb_photo_request_countdown_capture(gint secs, gchar * file_name, int count; - for (count = secs; count > 0; count--) + for (count = secs; count > 0; --count) { dmp_pb_tm_set_countdown(count); g_usleep(G_USEC_PER_SEC * 1); } - if (dmp_pb_cm_capture() != DMP_PB_SUCCESS) - { - g_set_error(error, - dmp_pb_coordination_error_quark(), - CAMERA_MODULE_ERROR, - "Failed to capture image!"); - return; - } dmp_pb_tm_set_countdown(0); - g_usleep(G_USEC_PER_SEC * 1); - if (dmp_pb_cm_download(file_name) != DMP_PB_SUCCESS) + if (dmp_pb_cm_capture(file_name) != DMP_PB_SUCCESS) { g_set_error(error, dmp_pb_coordination_error_quark(), CAMERA_MODULE_ERROR, - "Failed to download image to %s!", file_name); + "Failed to capture image!"); return; } + return; } @@ -117,7 +109,7 @@ static void dmp_pb_photo_request_thread_function(gpointer data, gpointer user_da if (image_position_toggle & DMP_PB_PHOTO_STRIP_POSITION_1_FLAG) { - file1 = g_build_filename(working->str, DMP_PB_POS1_FILE_NAME, NULL); + file1 = g_build_filename(working->str, dmp_pb_coordination_get_epoch_filename(DMP_PB_POS1_FILE_NAME, "jpg"), NULL); dmp_pb_photo_request_countdown_capture(DMP_PB_COUNTDOWN_TIME, file1, &error); if (error != NULL) { @@ -133,7 +125,7 @@ static void dmp_pb_photo_request_thread_function(gpointer data, gpointer user_da if (image_position_toggle & DMP_PB_PHOTO_STRIP_POSITION_2_FLAG) { - file2 = g_build_filename(working->str, DMP_PB_POS2_FILE_NAME, NULL); + file2 = g_build_filename(working->str, dmp_pb_coordination_get_epoch_filename(DMP_PB_POS2_FILE_NAME, "jpg"), NULL); dmp_pb_photo_request_countdown_capture(DMP_PB_COUNTDOWN_TIME, file2, &error); if (error != NULL) { @@ -149,7 +141,7 @@ static void dmp_pb_photo_request_thread_function(gpointer data, gpointer user_da if (image_position_toggle & DMP_PB_PHOTO_STRIP_POSITION_3_FLAG) { - file3 = g_build_filename(working->str, DMP_PB_POS3_FILE_NAME, NULL); + file3 = g_build_filename(working->str, dmp_pb_coordination_get_epoch_filename(DMP_PB_POS3_FILE_NAME, "jpg"), NULL); dmp_pb_photo_request_countdown_capture(DMP_PB_COUNTDOWN_TIME, file3, &error); if (error != NULL) { @@ -165,7 +157,7 @@ static void dmp_pb_photo_request_thread_function(gpointer data, gpointer user_da if (image_position_toggle & DMP_PB_PHOTO_STRIP_POSITION_4_FLAG) { - file4 = g_build_filename(working->str, DMP_PB_POS4_FILE_NAME, NULL); + file4 = g_build_filename(working->str, dmp_pb_coordination_get_epoch_filename(DMP_PB_POS4_FILE_NAME, "jpg"), NULL); dmp_pb_photo_request_countdown_capture(DMP_PB_COUNTDOWN_TIME, file4, &error); if (error != NULL) { @@ -181,7 +173,7 @@ static void dmp_pb_photo_request_thread_function(gpointer data, gpointer user_da if (image_position_toggle & DMP_PB_PHOTO_STRIP_POSITION_5_FLAG) { - file5 = g_build_filename(working->str, DMP_PB_POS5_FILE_NAME, NULL); + file5 = g_build_filename(working->str, dmp_pb_coordination_get_epoch_filename(DMP_PB_POS5_FILE_NAME, "jpg"), NULL); dmp_pb_photo_request_countdown_capture(DMP_PB_COUNTDOWN_TIME, file5, &error); if (error != NULL) { diff --git a/dmp_photo_booth/module.c b/dmp_photo_booth/module.c index 956c88a..b9ff7f6 100644 --- a/dmp_photo_booth/module.c +++ b/dmp_photo_booth/module.c @@ -36,8 +36,7 @@ static gboolean dmp_pb_trigger_module_consistent = TRUE; * The camera module */ static GModule * dmp_pb_camera_module = NULL; -static int (*dmp_cm_capture)() = NULL; -static int (*dmp_cm_download)(char * location) = NULL; +static int (*dmp_cm_capture)(char * location) = NULL; static int (*dmp_cm_edit_config)() = NULL; static int (*dmp_cm_load_config)() = NULL; static int (*dmp_cm_initialize)() = NULL; @@ -95,7 +94,7 @@ static gboolean dmp_pb_is_loaded(dmp_pb_module_type to_check) //TODO: this g_assert(g_module_supported()); if (to_check == DMP_PB_CAMERA_MODULE) return (dmp_pb_camera_module != NULL - && dmp_cm_capture != NULL && dmp_cm_download != NULL); + && dmp_cm_capture != NULL); else if (to_check == DMP_PB_TRIGGER_MODULE) return (dmp_pb_trigger_module != NULL && dmp_tm_add_trigger_handler != NULL && dmp_tm_set_countdown != NULL); else if (to_check == DMP_PB_PRINTER_MODULE) return (dmp_pb_printer_module != NULL @@ -431,15 +430,6 @@ static void dmp_pb_load_camera_module(GString * module_location, GError ** error "Failed to load module at: %s", module_location->str); return; } - if (!g_module_symbol(dmp_pb_camera_module, "dmp_cm_download", (gpointer *) & dmp_cm_download)) - { - dmp_pb_camera_module_consistent = FALSE; - g_set_error(error, - dmp_pb_module_error_quark(), - G_MODULE_LOAD_FAILURE, - "Failed to load module at: %s", module_location->str); - return; - } if (!g_module_symbol(dmp_pb_camera_module, "dmp_cm_edit_config", (gpointer *) & dmp_cm_edit_config)) { dmp_pb_camera_module_consistent = FALSE; @@ -599,7 +589,6 @@ static void dmp_pb_unload_camera_module() dmp_pb_camera_module = NULL; dmp_cm_capture = NULL; - dmp_cm_download = NULL; dmp_cm_edit_config = NULL; dmp_cm_get_config_location = NULL; dmp_cm_load_config = NULL; @@ -694,16 +683,10 @@ void dmp_pb_swap_module(dmp_pb_module_type to_swap, GString * new_module_locatio -gint dmp_pb_cm_capture() -{ - g_assert(dmp_pb_check_module_state(DMP_PB_CAMERA_MODULE) == DMP_PB_MODULE_READY); - return (*dmp_cm_capture)(); -} - -gint dmp_pb_cm_download(gchar * location) +gint dmp_pb_cm_capture(gchar * location) { g_assert(dmp_pb_check_module_state(DMP_PB_CAMERA_MODULE) == DMP_PB_MODULE_READY); - return (*dmp_cm_download)(location); + return (*dmp_cm_capture)(location); } gint dmp_pb_pm_print(gchar * to_print) diff --git a/dmp_photo_booth/module.h b/dmp_photo_booth/module.h index 12c6b56..ccb1d46 100644 --- a/dmp_photo_booth/module.h +++ b/dmp_photo_booth/module.h @@ -98,16 +98,11 @@ extern "C" { gint dmp_pb_load_module_config(dmp_pb_module_type type); /** - * signals the camera to capture a picture - * @return DMP_PB_SUCCESS, or an error code - */ - gint dmp_pb_cm_capture(); - /** - * Downloads the latest taken picture to the passed in location + * signals the camera to capture a picture, and downloads it to location * @param location the location to download to * @return DMP_PB_SUCCESS, or an error code */ - gint dmp_pb_cm_download(gchar * location); + gint dmp_pb_cm_capture(gchar * location); /** * prints the file at the passed in location * @param to_print the file to print diff --git a/dmp_photo_booth/photo_strip.c b/dmp_photo_booth/photo_strip.c index bf799e6..423e497 100644 --- a/dmp_photo_booth/photo_strip.c +++ b/dmp_photo_booth/photo_strip.c @@ -166,6 +166,7 @@ void dmp_pb_photo_strip_assemble() gint last_height = 0; gint offset_x = 15; gint offset_y = 15; + gint total_height = 0; GError * error = NULL; /* ---------- */ @@ -188,6 +189,7 @@ void dmp_pb_photo_strip_assemble() return; } g_string_free(background, TRUE); + total_height = MagickGetImageHeight(working->background_wand) - 30; if (working->position_1_file_name != NULL) { @@ -232,7 +234,7 @@ void dmp_pb_photo_strip_assemble() } } - offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(width, DMP_PB_WHITE_SPACE_PERCENTAGE); + offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(total_height, last_height); if (working->position_2_file_name != NULL) { @@ -276,7 +278,7 @@ void dmp_pb_photo_strip_assemble() } } - offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(width, DMP_PB_WHITE_SPACE_PERCENTAGE); + offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(total_height, last_height); if (working->position_3_file_name != NULL) { @@ -320,7 +322,7 @@ void dmp_pb_photo_strip_assemble() } } - offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(width, DMP_PB_WHITE_SPACE_PERCENTAGE); + offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(total_height, last_height); if (working->position_4_file_name != NULL) { @@ -364,7 +366,7 @@ void dmp_pb_photo_strip_assemble() } } - offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(width, DMP_PB_WHITE_SPACE_PERCENTAGE); + offset_y = offset_y + last_height + dmp_pb_photo_strip_calculate_whitespace(total_height, last_height); if (working->position_5_file_name != NULL) { @@ -437,7 +439,15 @@ void dmp_pb_photo_strip_assemble() g_async_queue_unref(local_out_queue); return; } + /*-------------*/ + /* Cleaning up */ + /*-------------*/ + if (working->position_1_file_name != NULL) g_unlink(working->position_1_file_name); + if (working->position_2_file_name != NULL) g_unlink(working->position_2_file_name); + if (working->position_3_file_name != NULL) g_unlink(working->position_3_file_name); + if (working->position_4_file_name != NULL) g_unlink(working->position_4_file_name); + if (working->position_5_file_name != NULL) g_unlink(working->position_5_file_name); /* -------- */ /* Printing */ @@ -540,10 +550,10 @@ gint dmp_pb_photo_strip_calculate_new_height(gdouble height, return (gint) (height * (new_width / old_width)); } -gint dmp_pb_photo_strip_calculate_whitespace(gdouble width, gdouble percentage) +gint dmp_pb_photo_strip_calculate_whitespace(gint total_height, gint image_height) { - g_assert(percentage >= 0); - //if (percentage == 0) return 0; - //return (gint) (width * (percentage / 100)); - return 15; // TODO: open this can of worms some other day -} \ No newline at end of file + g_assert(total_height > 0 && image_height > 0); + g_assert(total_height >= (image_height * 5)); + + return ((total_height - (image_height * 5)) / 4); +} diff --git a/dmp_photo_booth/photo_strip.h b/dmp_photo_booth/photo_strip.h index b1b1be8..3e7918b 100644 --- a/dmp_photo_booth/photo_strip.h +++ b/dmp_photo_booth/photo_strip.h @@ -54,12 +54,11 @@ extern "C" { /** * calculates the size of the border around the photo strip images - * @param width the width of a photo strip image - * @param percentage the percent of the width that should be the size of the - * border + * @param total_height the height of the background image + * @param image_height the height of the last photo strip image * @return the border size */ - gint dmp_pb_photo_strip_calculate_whitespace(gdouble width, gdouble percentage); + gint dmp_pb_photo_strip_calculate_whitespace(gint total_height, gint image_height); /** * initializes the photo strip module