Skip to content

Commit

Permalink
Minor changes to photo strip layout
Browse files Browse the repository at this point in the history
Combined camera-capture and camera-download into one function
  • Loading branch information
christetreault committed Jan 9, 2014
1 parent 0ca4a01 commit 4fbf882
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 64 deletions.
36 changes: 14 additions & 22 deletions dmp_photo_booth/coordination.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
25 changes: 4 additions & 21 deletions dmp_photo_booth/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions dmp_photo_booth/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions dmp_photo_booth/photo_strip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/* ---------- */
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
}
g_assert(total_height > 0 && image_height > 0);
g_assert(total_height >= (image_height * 5));

return ((total_height - (image_height * 5)) / 4);
}
7 changes: 3 additions & 4 deletions dmp_photo_booth/photo_strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fbf882

Please sign in to comment.