Fix distortion regression test after recent commit

The 1a1341c387 made it so that when ID's path changes the ID is
tagged for the source re-evaluation. Another factor here is that
there is a code in the read file which replaces alternative path
slash with the native one.

Typically it is not a problem since IDs are re-evaluated on load,
but the movie clip has the special handling on load to calculate
the image sequence length and initialize principal point.

This change makes it so that the principal point is only reset
when the clip resolution changes. This is something which is
also useful for cases when a non-centered primncipal point is
used and someone accidentally clicks on the clip reload button.
It is not really ideal but covers most of the common cases.
Ideally the principal point will be stored in relative or
normalized space.

The remaining part is that there is now extra image sequence
length calculation after file load. This needs more careful
look.
This commit is contained in:
Sergey Sharybin 2022-11-17 17:34:20 +01:00
parent 1c27cc5529
commit 52c3214776
1 changed files with 30 additions and 7 deletions

View File

@ -937,15 +937,22 @@ static void movieclip_load_get_size(MovieClip *clip)
user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, 1);
BKE_movieclip_get_size(clip, &user, &width, &height);
if (width && height) {
clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
}
else {
if (!width || !height) {
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)
{
ImBuf *ibuf;
@ -995,6 +1002,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
}
movieclip_principal_to_center(clip);
movieclip_calc_length(clip);
return clip;
@ -1672,11 +1680,26 @@ void BKE_movieclip_reload(Main *bmain, MovieClip *clip)
/* update clip source */
detect_clip_source(bmain, clip);
clip->lastsize[0] = clip->lastsize[1] = 0;
movieclip_load_get_size(clip);
const int old_width = clip->lastsize[0];
const int old_height = clip->lastsize[1];
/* Tag for re-calculation of the actual size. */
clip->lastsize[0] = clip->lastsize[1] = 0;
movieclip_load_get_size(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);
}