Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/movieclip.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "BLO_read_write.h" | #include "BLO_read_write.h" | ||||
| #include "tracking_private.h" | |||||
| /* Convert camera object to legacy format where the camera tracks are stored in the MovieTracking | /* Convert camera object to legacy format where the camera tracks are stored in the MovieTracking | ||||
| * structure when saving .blend file. */ | * structure when saving .blend file. */ | ||||
| #define USE_LEGACY_CAMERA_OBJECT_FORMAT_ON_SAVE 1 | #define USE_LEGACY_CAMERA_OBJECT_FORMAT_ON_SAVE 1 | ||||
| static void free_buffers(MovieClip *clip); | static void free_buffers(MovieClip *clip); | ||||
| static void movie_clip_init_data(ID *id) | static void movie_clip_init_data(ID *id) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | if (!is_undo) { | ||||
| /* The active track in the tracking structure used to be shared across all tracking objects. */ | /* The active track in the tracking structure used to be shared across all tracking objects. */ | ||||
| tracking->act_track_legacy = active_tracking_object->active_track; | tracking->act_track_legacy = active_tracking_object->active_track; | ||||
| tracking->act_plane_track_legacy = active_tracking_object->active_plane_track; | tracking->act_plane_track_legacy = active_tracking_object->active_plane_track; | ||||
| tracking->reconstruction_legacy = tracking_camera_object->reconstruction; | tracking->reconstruction_legacy = tracking_camera_object->reconstruction; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Assign the pixel-space principal point for forward compatibility. */ | |||||
| /* TODO(sergey): Remove with the next major version update when forward compatibility is allowed | |||||
| * to be broken. */ | |||||
| if (!is_undo && clip->lastsize[0] != 0 && clip->lastsize[1] != 0) { | |||||
| tracking_principal_normalized_to_pixel(tracking->camera.principal_point, | |||||
| clip->lastsize[0], | |||||
| clip->lastsize[1], | |||||
| tracking->camera.principal_legacy); | |||||
| } | |||||
| BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); | BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); | ||||
| BKE_id_blend_write(writer, &clip->id); | BKE_id_blend_write(writer, &clip->id); | ||||
| if (clip->adt) { | if (clip->adt) { | ||||
| BKE_animdata_blend_write(writer, clip->adt); | BKE_animdata_blend_write(writer, clip->adt); | ||||
| } | } | ||||
| LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { | LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { | ||||
| ▲ Show 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | typedef struct MovieClipCache { | ||||
| /* cached postprocessed shot */ | /* cached postprocessed shot */ | ||||
| struct { | struct { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| int framenr; | int framenr; | ||||
| int flag; | int flag; | ||||
| /* cache for undistorted shot */ | /* cache for undistorted shot */ | ||||
| float focal_length; | float focal_length; | ||||
| float principal[2]; | float principal_point[2]; | ||||
| float polynomial_k[3]; | float polynomial_k[3]; | ||||
| float division_k[2]; | float division_k[2]; | ||||
| float nuke_k[2]; | float nuke_k[2]; | ||||
| float brown_k[4]; | float brown_k[4]; | ||||
| float brown_p[2]; | float brown_p[2]; | ||||
| short distortion_model; | short distortion_model; | ||||
| bool undistortion_used; | bool undistortion_used; | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | static void movieclip_load_get_size(MovieClip *clip) | ||||
| user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, 1); | user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, 1); | ||||
| BKE_movieclip_get_size(clip, &user, &width, &height); | BKE_movieclip_get_size(clip, &user, &width, &height); | ||||
| if (!width || !height) { | if (!width || !height) { | ||||
| clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK; | clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK; | ||||
| } | } | ||||
| } | } | ||||
| static void movieclip_principal_to_center(MovieClip *clip) | |||||
| { | |||||
| MovieClipUser user = *DNA_struct_default_get(MovieClipUser); | |||||
| int width, height; | |||||
| BKE_movieclip_get_size(clip, &user, &width, &height); | |||||
| clip->tracking.camera.principal[0] = ((float)width) / 2.0f; | |||||
| clip->tracking.camera.principal[1] = ((float)height) / 2.0f; | |||||
| } | |||||
| static void detect_clip_source(Main *bmain, MovieClip *clip) | static void detect_clip_source(Main *bmain, MovieClip *clip) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| char name[FILE_MAX]; | char name[FILE_MAX]; | ||||
| BLI_strncpy(name, clip->filepath, sizeof(name)); | BLI_strncpy(name, clip->filepath, sizeof(name)); | ||||
| BLI_path_abs(name, BKE_main_blendfile_path(bmain)); | BLI_path_abs(name, BKE_main_blendfile_path(bmain)); | ||||
| Show All 33 Lines | MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) | ||||
| movieclip_load_get_size(clip); | movieclip_load_get_size(clip); | ||||
| if (clip->lastsize[0]) { | if (clip->lastsize[0]) { | ||||
| int width = clip->lastsize[0]; | int width = clip->lastsize[0]; | ||||
| clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width; | clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width; | ||||
| } | } | ||||
| movieclip_principal_to_center(clip); | |||||
| movieclip_calc_length(clip); | movieclip_calc_length(clip); | ||||
| return clip; | return clip; | ||||
| } | } | ||||
| MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists) | MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists) | ||||
| { | { | ||||
| MovieClip *clip; | MovieClip *clip; | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | static bool check_undistortion_cache_flags(const MovieClip *clip) | ||||
| const MovieClipCache *cache = clip->cache; | const MovieClipCache *cache = clip->cache; | ||||
| const MovieTrackingCamera *camera = &clip->tracking.camera; | const MovieTrackingCamera *camera = &clip->tracking.camera; | ||||
| if (camera->focal != cache->postprocessed.focal_length) { | if (camera->focal != cache->postprocessed.focal_length) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* check for distortion model changes */ | /* check for distortion model changes */ | ||||
| if (!equals_v2v2(camera->principal, cache->postprocessed.principal)) { | if (!equals_v2v2(camera->principal_point, cache->postprocessed.principal_point)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (camera->distortion_model != cache->postprocessed.distortion_model) { | if (camera->distortion_model != cache->postprocessed.distortion_model) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!equals_v3v3(&camera->k1, cache->postprocessed.polynomial_k)) { | if (!equals_v3v3(&camera->k1, cache->postprocessed.polynomial_k)) { | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | static void put_postprocessed_frame_to_cache( | ||||
| else { | else { | ||||
| cache->postprocessed.proxy = IMB_PROXY_NONE; | cache->postprocessed.proxy = IMB_PROXY_NONE; | ||||
| cache->postprocessed.render_flag = 0; | cache->postprocessed.render_flag = 0; | ||||
| } | } | ||||
| if (need_undistortion_postprocess(user, flag)) { | if (need_undistortion_postprocess(user, flag)) { | ||||
| cache->postprocessed.distortion_model = camera->distortion_model; | cache->postprocessed.distortion_model = camera->distortion_model; | ||||
| cache->postprocessed.focal_length = camera->focal; | cache->postprocessed.focal_length = camera->focal; | ||||
| copy_v2_v2(cache->postprocessed.principal, camera->principal); | copy_v2_v2(cache->postprocessed.principal_point, camera->principal_point); | ||||
| copy_v3_v3(cache->postprocessed.polynomial_k, &camera->k1); | copy_v3_v3(cache->postprocessed.polynomial_k, &camera->k1); | ||||
| copy_v2_v2(cache->postprocessed.division_k, &camera->division_k1); | copy_v2_v2(cache->postprocessed.division_k, &camera->division_k1); | ||||
| copy_v2_v2(cache->postprocessed.nuke_k, &camera->nuke_k1); | copy_v2_v2(cache->postprocessed.nuke_k, &camera->nuke_k1); | ||||
| copy_v4_v4(cache->postprocessed.brown_k, &camera->brown_k1); | copy_v4_v4(cache->postprocessed.brown_k, &camera->brown_k1); | ||||
| copy_v2_v2(cache->postprocessed.brown_p, &camera->brown_p1); | copy_v2_v2(cache->postprocessed.brown_p, &camera->brown_p1); | ||||
| cache->postprocessed.undistortion_used = true; | cache->postprocessed.undistortion_used = true; | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 423 Lines • ▼ Show 20 Lines | |||||
| void BKE_movieclip_reload(Main *bmain, MovieClip *clip) | void BKE_movieclip_reload(Main *bmain, MovieClip *clip) | ||||
| { | { | ||||
| /* clear cache */ | /* clear cache */ | ||||
| free_buffers(clip); | free_buffers(clip); | ||||
| /* update clip source */ | /* update clip source */ | ||||
| detect_clip_source(bmain, clip); | detect_clip_source(bmain, clip); | ||||
| const int old_width = clip->lastsize[0]; | |||||
| const int old_height = clip->lastsize[1]; | |||||
| /* Tag for re-calculation of the actual size. */ | /* Tag for re-calculation of the actual size. */ | ||||
| clip->lastsize[0] = clip->lastsize[1] = 0; | clip->lastsize[0] = clip->lastsize[1] = 0; | ||||
| movieclip_load_get_size(clip); | movieclip_load_get_size(clip); | ||||
| movieclip_calc_length(clip); | movieclip_calc_length(clip); | ||||
| int width, height; | |||||
| MovieClipUser user = *DNA_struct_default_get(MovieClipUser); | |||||
| BKE_movieclip_get_size(clip, &user, &width, &height); | |||||
| /* If the resolution changes then re-initialize the principal point. | |||||
| * Ideally the principal point will be in some sort of relative space, but this is not how it is | |||||
| * designed currently. The code should cover the most of the common cases. */ | |||||
| if (width != old_width || height != old_height) { | |||||
| movieclip_principal_to_center(clip); | |||||
| } | |||||
| BKE_ntree_update_tag_id_changed(bmain, &clip->id); | BKE_ntree_update_tag_id_changed(bmain, &clip->id); | ||||
| } | } | ||||
| void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes) | void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes) | ||||
| { | { | ||||
| if (scopes->ok) { | if (scopes->ok) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 392 Lines • Show Last 20 Lines | |||||