static int32_t dt_camera_capture_job_run(dt_job_t *job) { dt_camera_capture_t *params = dt_control_job_get_params(job); int total; char message[512] = { 0 }; double fraction = 0; total = params->brackets ? params->count * params->brackets : params->count; snprintf(message, sizeof(message), ngettext("capturing %d image", "capturing %d images", total), total); dt_control_job_set_progress_message(job, message); /* try to get exp program mode for nikon */ char *expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "expprogram"); /* if fail, lets try fetching mode for cannon */ if(!expprogram) expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); /* Fetch all values for shutterspeed and initialize current value */ GList *values = NULL; gconstpointer original_value = NULL; const char *cvalue = dt_camctl_camera_get_property(darktable.camctl, NULL, "shutterspeed"); const char *value = dt_camctl_camera_property_get_first_choice(darktable.camctl, NULL, "shutterspeed"); /* get values for bracketing */ if(params->brackets && expprogram && expprogram[0] == 'M' && value && cvalue) { do { // Add value to list values = g_list_append(values, g_strdup(value)); // Check if current values is the same as original value, then lets store item ptr if(strcmp(value, cvalue) == 0) original_value = g_list_last(values)->data; } while((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) != NULL); } else { /* if this was an intended bracket capture bail out */ if(params->brackets) { dt_control_log(_("please set your camera to manual mode first!")); return 1; } } GList *current_value = g_list_find(values, original_value); for(uint32_t i = 0; i < params->count; i++) { // Delay if active if(params->delay) g_usleep(params->delay * G_USEC_PER_SEC); for(uint32_t b = 0; b < (params->brackets * 2) + 1; b++) { // If bracket capture, lets set change shutterspeed if(params->brackets) { if(b == 0) { // First bracket, step down time with (steps*brackets), also check so we never set the longest // shuttertime which would be bulb mode for(uint32_t s = 0; s < (params->steps * params->brackets); s++) if(g_list_next(current_value) && g_list_next(g_list_next(current_value))) current_value = g_list_next(current_value); } else { // Step up with (steps) for(uint32_t s = 0; s < params->steps; s++) if(g_list_previous(current_value)) current_value = g_list_previous(current_value); } } // set the time property for bracket capture if(params->brackets && current_value) dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); // Capture image dt_camctl_camera_capture(darktable.camctl, NULL); fraction += 1.0 / total; dt_control_job_set_progress(job, fraction); } // lets reset to original value before continue if(params->brackets) { current_value = g_list_find(values, original_value); dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); } } // free values if(values) { g_list_free_full(values, g_free); } return 0; }
static int32_t dt_camera_capture_job_run(dt_job_t *job) { dt_camera_capture_t *params = dt_control_job_get_params(job); int total; char message[512]= {0}; double fraction=0; total = params->total = params->brackets ? params->count * params->brackets : params->count; snprintf(message, sizeof(message), ngettext ("capturing %d image", "capturing %d images", total), total ); pthread_mutex_init(¶ms->mutex, NULL); pthread_cond_init(¶ms->done, NULL); // register listener dt_camctl_listener_t *listener; listener = g_malloc0(sizeof(dt_camctl_listener_t)); listener->data = params; listener->image_downloaded = _camera_capture_image_downloaded; listener->request_image_path = _camera_request_image_path; listener->request_image_filename = _camera_request_image_filename; dt_camctl_register_listener(darktable.camctl, listener); /* try to get exp program mode for nikon */ char *expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "expprogram"); /* if fail, lets try fetching mode for cannon */ if(!expprogram) expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); /* Fetch all values for shutterspeed and initialize current value */ GList *values=NULL; gconstpointer original_value=NULL; const char *cvalue = dt_camctl_camera_get_property(darktable.camctl, NULL, "shutterspeed"); const char *value = dt_camctl_camera_property_get_first_choice(darktable.camctl, NULL, "shutterspeed"); /* get values for bracketing */ if (params->brackets && expprogram && expprogram[0]=='M' && value && cvalue) { do { // Add value to list values = g_list_append(values, g_strdup(value)); // Check if current values is the same as original value, then lets store item ptr if (strcmp(value,cvalue) == 0) original_value = g_list_last(values)->data; } while ((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) != NULL); } else { /* if this was an intended bracket capture bail out */ if(params->brackets) { dt_control_log(_("please set your camera to manual mode first!")); pthread_mutex_lock(¶ms->mutex); pthread_cond_wait(¶ms->done, ¶ms->mutex); pthread_mutex_unlock(¶ms->mutex); pthread_mutex_destroy(¶ms->mutex); pthread_cond_destroy(¶ms->done); dt_import_session_destroy(params->shared.session); dt_camctl_unregister_listener(darktable.camctl, listener); g_free(listener); free(params); return 1; } } /* create the bgjob plate */ const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, message); GList *current_value = g_list_find(values,original_value); for(uint32_t i=0; i < params->count; i++) { // Delay if active if(params->delay) g_usleep(params->delay*G_USEC_PER_SEC); for(uint32_t b=0; b < (params->brackets*2)+1; b++) { // If bracket capture, lets set change shutterspeed if (params->brackets) { if (b == 0) { // First bracket, step down time with (steps*brackets), also check so we never set the longest shuttertime which would be bulb mode for(uint32_t s=0; s < (params->steps * params->brackets); s++) if (g_list_next(current_value) && g_list_next(g_list_next(current_value))) current_value = g_list_next(current_value); } else { // Step up with (steps) for(uint32_t s=0; s < params->steps; s++) if(g_list_previous(current_value)) current_value = g_list_previous(current_value); } } // set the time property for bracket capture if (params->brackets && current_value) dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); // Capture image dt_camctl_camera_capture(darktable.camctl,NULL); fraction += 1.0/total; dt_control_backgroundjobs_progress(darktable.control, jid, fraction); } // lets reset to original value before continue if (params->brackets) { current_value = g_list_find(values,original_value); dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); } } /* wait for last image capture before exiting job */ pthread_mutex_lock(¶ms->mutex); pthread_cond_wait(¶ms->done, ¶ms->mutex); pthread_mutex_unlock(¶ms->mutex); pthread_mutex_destroy(¶ms->mutex); pthread_cond_destroy(¶ms->done); /* cleanup */ dt_control_backgroundjobs_destroy(darktable.control, jid); dt_import_session_destroy(params->shared.session); dt_camctl_unregister_listener(darktable.camctl, listener); g_free(listener); // free values if(values) { g_list_free_full(values, g_free); } free(params); return 0; }