void align_other_to_depth_bytes(byte* other_aligned_to_depth, GET_DEPTH get_depth, const rs2_intrinsics& depth_intrin, const rs2_extrinsics& depth_to_other, const rs2_intrinsics& other_intrin, const byte* other_pixels) { auto in_other = (const bytes<N> *)(other_pixels); auto out_other = (bytes<N> *)(other_aligned_to_depth); align_images(depth_intrin, depth_to_other, other_intrin, get_depth, [out_other, in_other](int depth_pixel_index, int other_pixel_index) { out_other[depth_pixel_index] = in_other[other_pixel_index]; }); }
void align::align_z_to_other(byte* aligned_data, const rs2::video_frame& depth, const rs2::video_stream_profile& other_profile, float z_scale) { auto depth_profile = depth.get_profile().as<rs2::video_stream_profile>(); auto z_intrin = depth_profile.get_intrinsics(); auto other_intrin = other_profile.get_intrinsics(); auto z_to_other = depth_profile.get_extrinsics_to(other_profile); auto z_pixels = reinterpret_cast<const uint16_t*>(depth.get_data()); auto out_z = (uint16_t *)(aligned_data); align_images(z_intrin, z_to_other, other_intrin, [z_pixels, z_scale](int z_pixel_index) { return z_scale * z_pixels[z_pixel_index]; }, [out_z, z_pixels](int z_pixel_index, int other_pixel_index) { out_z[other_pixel_index] = out_z[other_pixel_index] ? std::min((int)out_z[other_pixel_index], (int)z_pixels[z_pixel_index]) : z_pixels[z_pixel_index]; }); }
gchar * rs_enfuse(RS_BLOB *rs, GList *files, gboolean quick, gint boundingbox) { gint num_selected = g_list_length(files); gint i; gchar *name = NULL; gchar *file = NULL; GString *outname = g_string_new(""); GString *fullpath = NULL; gchar *align_options = NULL; GString *enfuse_options = g_string_new(""); gdouble extend_negative = 0.0; gdouble extend_positive = 0.0; gdouble extend_step = 0.0; GTimer *timer = g_timer_new(); g_timer_start(timer); if (!rs_conf_get_double( (num_selected == 1) ? CONF_ENFUSE_EXTEND_NEGATIVE_SINGLE : CONF_ENFUSE_EXTEND_NEGATIVE_MULTI, &extend_negative)) extend_negative = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_NEGATIVE_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_NEGATIVE_MULTI; if (!rs_conf_get_double( (num_selected == 1) ? CONF_ENFUSE_EXTEND_POSITIVE_SINGLE : CONF_ENFUSE_EXTEND_POSITIVE_MULTI, &extend_positive)) extend_positive = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_POSITIVE_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_POSITIVE_MULTI; if (!rs_conf_get_double( (num_selected == 1) ? CONF_ENFUSE_EXTEND_STEP_SINGLE : CONF_ENFUSE_EXTEND_STEP_MULTI, &extend_step)) extend_step = (num_selected == 1) ? DEFAULT_CONF_ENFUSE_EXTEND_STEP_SINGLE : DEFAULT_CONF_ENFUSE_EXTEND_STEP_MULTI; gboolean align = DEFAULT_CONF_ENFUSE_ALIGN_IMAGES; rs_conf_get_boolean_with_default(CONF_ENFUSE_ALIGN_IMAGES, &align, DEFAULT_CONF_ENFUSE_ALIGN_IMAGES); gboolean extend = DEFAULT_CONF_ENFUSE_EXTEND; rs_conf_get_boolean_with_default(CONF_ENFUSE_EXTEND, &extend, DEFAULT_CONF_ENFUSE_EXTEND); gint method = 0; if (!rs_conf_get_integer(CONF_ENFUSE_METHOD, &method)) method = DEFAULT_CONF_ENFUSE_METHOD; if (boundingbox == -1) { if (!rs_conf_get_integer(CONF_ENFUSE_SIZE, &boundingbox)) boundingbox = DEFAULT_CONF_ENFUSE_SIZE; } gchar *method_options = NULL; if (method == ENFUSE_METHOD_EXPOSURE_BLENDING_ID) { method_options = g_strdup(ENFUSE_OPTIONS_EXPOSURE_BLENDING); } else if (method == ENFUSE_METHOD_FOCUS_STACKING_ID) { method_options = g_strdup(ENFUSE_OPTIONS_FOCUS_STACKING); extend = FALSE; } if (quick) enfuse_options = g_string_append(enfuse_options, ENFUSE_OPTIONS_QUICK); else enfuse_options = g_string_append(enfuse_options, ENFUSE_OPTIONS); enfuse_options = g_string_append(enfuse_options, " "); enfuse_options = g_string_append(enfuse_options, method_options); gchar *first = NULL; gchar *parsed_filename = NULL; gchar *temp_filename = g_strdup("/tmp/.rawstudio-temp.png"); RS_PROGRESS *progress = NULL; if (quick == FALSE) { progress = gui_progress_new("Enfusing...", 5); GUI_CATCHUP(); } /* if only one picture is selected we have to do extending, it doesn't make sense to run enfuse on a single photo otherwise... */ if (num_selected == 1) extend = TRUE; if (g_list_length(files)) { for(i=0; i<num_selected; i++) { name = (gchar*) g_list_nth_data(files, i); if (first == NULL) first = g_strdup(name); file = g_malloc(sizeof(char)*strlen(name)); sscanf(g_path_get_basename(name), "%[^.]", file); outname = g_string_append(outname, file); g_free(file); if (i+1 != num_selected) outname = g_string_append(outname, "+"); } fullpath = g_string_new(g_path_get_dirname(name)); fullpath = g_string_append(fullpath, "/"); fullpath = g_string_append(fullpath, outname->str); fullpath = g_string_append(fullpath, "_%2c"); fullpath = g_string_append(fullpath, ".rse"); parsed_filename = filename_parse(fullpath->str, g_strdup(first), 0, FALSE); g_string_free(outname, TRUE); g_string_free(fullpath, TRUE); } if (quick == FALSE) { g_usleep(500000); /* FIXME */ gui_progress_advance_one(progress); /* 1 - initiate */ } GList *exported_names = export_images(rs, files, extend, extend_negative, extend_step, extend_positive, extend_step, boundingbox, quick); if (quick == FALSE) gui_progress_advance_one(progress); /* 2 - after exported images */ GList *aligned_names = NULL; if (has_align_image_stack() && num_selected > 1 && quick == FALSE && align == TRUE) { aligned_names = align_images(exported_names, align_options); g_free(align_options); } else aligned_names = exported_names; if (quick == FALSE) gui_progress_advance_one(progress); /* 3 - after aligned images */ enfuse_images(aligned_names, temp_filename, enfuse_options->str, has_enfuse_mp()); g_string_free(enfuse_options, TRUE); if (quick == FALSE) gui_progress_advance_one(progress); /* 4 - after enfusing */ /* delete all temporary files */ if (exported_names != aligned_names) { delete_files_in_list(aligned_names); g_list_free(aligned_names); } delete_files_in_list(exported_names); g_list_free(exported_names); /* FIXME: should use the photo in the middle as it's averaged between it... */ rs_exif_copy(first, temp_filename, "sRGB", RS_EXIF_FILE_TYPE_PNG); if (first) g_free(first); GString *mv = g_string_new("mv "); mv = g_string_append(mv, temp_filename); mv = g_string_append(mv, " "); mv = g_string_append(mv, parsed_filename); printf("command: %s\n", mv->str); if(system(mv->str)); g_string_free(mv, TRUE); if (quick == FALSE) { gui_progress_advance_one(progress); /* 5 - misc file operations */ gui_progress_free(progress); } g_timer_stop(timer); printf("Total execution time: %.2f\n", g_timer_elapsed(timer, NULL)); return parsed_filename; }