Cleanup: Remove goto statements from strip rendering functions
Remove goto statement from `seq_render_image_strip()` and `seq_render_movie_strip()`. `seq_render_image_strip_view()` and `seq_render_movie_strip_view()` is used to render individual views in both monoview and multiview branch. I have included `seq_can_use_proxy()` for convinience Reviewed By: sybren Differential Revision: https://developer.blender.org/D7870
This commit is contained in:
parent
67a822e086
commit
f7f3b2d318
Notes:
blender-bot
2023-02-14 06:23:08 +01:00
Referenced by commitf26d7268bf
, Silence warning introduced inf7f3b2d318
|
@ -1180,7 +1180,7 @@ static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui)
|
|||
Sequence *seq;
|
||||
for (seq = seqbasep->first; seq; seq = seq->next) {
|
||||
if ((sui->seq != seq) && STREQ(sui->name_dest, seq->name + 2)) {
|
||||
/* SEQ_NAME_MAXSTR -4 for the number, -1 for \0, - 2 for prefix */
|
||||
/* SEQ_NAME_MAXSTR -4 for the number, -1 for \0, - 2 for r_prefix */
|
||||
BLI_snprintf(sui->name_dest,
|
||||
sizeof(sui->name_dest),
|
||||
"%.*s.%03d",
|
||||
|
@ -2247,6 +2247,15 @@ void BKE_sequencer_proxy_set(struct Sequence *seq, bool value)
|
|||
}
|
||||
}
|
||||
|
||||
static bool seq_can_use_proxy(Sequence *seq, IMB_Proxy_Size psize)
|
||||
{
|
||||
if (seq->strip->proxy == NULL) {
|
||||
return false;
|
||||
}
|
||||
short size_flags = seq->strip->proxy->build_size_flags;
|
||||
return (seq->flag & SEQ_USE_PROXY) != 0 && psize != IMB_PROXY_NONE && (size_flags & psize) != 0;
|
||||
}
|
||||
|
||||
/*********************** color balance *************************/
|
||||
|
||||
static StripColorBalance calc_cb(StripColorBalance *cb_)
|
||||
|
@ -2985,97 +2994,116 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context,
|
|||
return out;
|
||||
}
|
||||
|
||||
/* Render individual view for multiview or single (default view) for monoview. */
|
||||
static ImBuf *seq_render_image_strip_view(const SeqRenderData *context,
|
||||
Sequence *seq,
|
||||
float cfra,
|
||||
char *name,
|
||||
char *prefix,
|
||||
const char *ext,
|
||||
int view_id)
|
||||
{
|
||||
|
||||
ImBuf *ibuf = NULL;
|
||||
|
||||
int flag = IB_rect | IB_metadata;
|
||||
if (seq->alpha_mode == SEQ_ALPHA_PREMUL) {
|
||||
flag |= IB_alphamode_premul;
|
||||
}
|
||||
|
||||
if (prefix[0] == '\0') {
|
||||
ibuf = IMB_loadiffname(name, flag, seq->strip->colorspace_settings.name);
|
||||
}
|
||||
else {
|
||||
char str[FILE_MAX];
|
||||
seq_multiview_name(context->scene, view_id, prefix, ext, str, FILE_MAX);
|
||||
ibuf = IMB_loadiffname(str, flag, seq->strip->colorspace_settings.name);
|
||||
}
|
||||
|
||||
if (ibuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We don't need both (speed reasons)! */
|
||||
if (ibuf->rect_float != NULL && ibuf->rect != NULL) {
|
||||
imb_freerectImBuf(ibuf);
|
||||
}
|
||||
|
||||
/* All sequencer color is done in SRGB space, linear gives odd crossfades. */
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false);
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
static bool seq_image_strip_is_multiview_render(
|
||||
Scene *scene, Sequence *seq, int totfiles, char *name, char *r_prefix, const char *r_ext)
|
||||
{
|
||||
if (totfiles > 1) {
|
||||
BKE_scene_multiview_view_prefix_get(scene, name, r_prefix, &r_ext);
|
||||
if (r_prefix[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
r_prefix[0] = '\0';
|
||||
}
|
||||
|
||||
return (seq->flag & SEQ_USE_VIEWS) != 0 && (scene->r.scemode & R_MULTIVIEW) != 0;
|
||||
}
|
||||
|
||||
static ImBuf *seq_render_image_strip(const SeqRenderData *context,
|
||||
Sequence *seq,
|
||||
float UNUSED(nr),
|
||||
float cfra)
|
||||
{
|
||||
ImBuf *ibuf = NULL;
|
||||
char name[FILE_MAX];
|
||||
bool is_multiview = (seq->flag & SEQ_USE_VIEWS) != 0 &&
|
||||
(context->scene->r.scemode & R_MULTIVIEW) != 0;
|
||||
const char *ext = NULL;
|
||||
char prefix[FILE_MAX];
|
||||
ImBuf *ibuf = NULL;
|
||||
|
||||
StripElem *s_elem = BKE_sequencer_give_stripelem(seq, cfra);
|
||||
int flag;
|
||||
|
||||
if (s_elem) {
|
||||
BLI_join_dirfile(name, sizeof(name), seq->strip->dir, s_elem->name);
|
||||
BLI_path_abs(name, BKE_main_blendfile_path_from_global());
|
||||
if (s_elem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
flag = IB_rect | IB_metadata;
|
||||
if (seq->alpha_mode == SEQ_ALPHA_PREMUL) {
|
||||
flag |= IB_alphamode_premul;
|
||||
}
|
||||
BLI_join_dirfile(name, sizeof(name), seq->strip->dir, s_elem->name);
|
||||
BLI_path_abs(name, BKE_main_blendfile_path_from_global());
|
||||
|
||||
if (!s_elem) {
|
||||
/* don't do anything */
|
||||
}
|
||||
else if (is_multiview) {
|
||||
const int totfiles = seq_num_files(context->scene, seq->views_format, true);
|
||||
int totviews;
|
||||
struct ImBuf **ibufs_arr;
|
||||
char prefix[FILE_MAX];
|
||||
const char *ext = NULL;
|
||||
const int totfiles = seq_num_files(context->scene, seq->views_format, true);
|
||||
bool is_multiview_render = seq_image_strip_is_multiview_render(
|
||||
context->scene, seq, totfiles, name, prefix, ext);
|
||||
|
||||
if (totfiles > 1) {
|
||||
BKE_scene_multiview_view_prefix_get(context->scene, name, prefix, &ext);
|
||||
if (prefix[0] == '\0') {
|
||||
goto monoview_image;
|
||||
}
|
||||
}
|
||||
else {
|
||||
prefix[0] = '\0';
|
||||
}
|
||||
|
||||
totviews = BKE_scene_multiview_num_views_get(&context->scene->r);
|
||||
ibufs_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Sequence Image Views Imbufs");
|
||||
if (is_multiview_render) {
|
||||
int totviews = BKE_scene_multiview_num_views_get(&context->scene->r);
|
||||
ImBuf **ibufs_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Sequence Image Views Imbufs");
|
||||
|
||||
for (int view_id = 0; view_id < totfiles; view_id++) {
|
||||
|
||||
if (prefix[0] == '\0') {
|
||||
ibufs_arr[view_id] = IMB_loadiffname(name, flag, seq->strip->colorspace_settings.name);
|
||||
}
|
||||
else {
|
||||
char str[FILE_MAX];
|
||||
seq_multiview_name(context->scene, view_id, prefix, ext, str, FILE_MAX);
|
||||
ibufs_arr[view_id] = IMB_loadiffname(str, flag, seq->strip->colorspace_settings.name);
|
||||
}
|
||||
|
||||
if (ibufs_arr[view_id]) {
|
||||
/* we don't need both (speed reasons)! */
|
||||
if (ibufs_arr[view_id]->rect_float && ibufs_arr[view_id]->rect) {
|
||||
imb_freerectImBuf(ibufs_arr[view_id]);
|
||||
}
|
||||
}
|
||||
ibufs_arr[view_id] = seq_render_image_strip_view(
|
||||
context, seq, cfra, name, prefix, ext, view_id);
|
||||
}
|
||||
|
||||
if (seq->views_format == R_IMF_VIEWS_STEREO_3D && ibufs_arr[0]) {
|
||||
if (ibufs_arr[0] == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (seq->views_format == R_IMF_VIEWS_STEREO_3D) {
|
||||
IMB_ImBufFromStereo3d(seq->stereo3d_format, ibufs_arr[0], &ibufs_arr[0], &ibufs_arr[1]);
|
||||
}
|
||||
|
||||
for (int view_id = 0; view_id < totviews; view_id++) {
|
||||
if (ibufs_arr[view_id]) {
|
||||
SeqRenderData localcontext = *context;
|
||||
localcontext.view_id = view_id;
|
||||
SeqRenderData localcontext = *context;
|
||||
localcontext.view_id = view_id;
|
||||
|
||||
/* all sequencer color is done in SRGB space, linear gives odd crossfades */
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibufs_arr[view_id], false);
|
||||
|
||||
if (view_id != context->view_id) {
|
||||
ibufs_arr[view_id] = seq_render_preprocess_ibuf(
|
||||
&localcontext, seq, ibufs_arr[view_id], cfra, clock(), true, false, false);
|
||||
}
|
||||
if (view_id != context->view_id) {
|
||||
ibufs_arr[view_id] = seq_render_preprocess_ibuf(
|
||||
&localcontext, seq, ibufs_arr[view_id], cfra, clock(), true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* return the original requested ImBuf */
|
||||
/* Return the original requested ImBuf. */
|
||||
ibuf = ibufs_arr[context->view_id];
|
||||
if (ibuf) {
|
||||
s_elem->orig_width = ibufs_arr[0]->x;
|
||||
s_elem->orig_height = ibufs_arr[0]->y;
|
||||
}
|
||||
|
||||
/* "remove" the others (decrease their refcount) */
|
||||
/* Remove the others (decrease their refcount). */
|
||||
for (int view_id = 0; view_id < totviews; view_id++) {
|
||||
if (ibufs_arr[view_id] != ibuf) {
|
||||
IMB_freeImBuf(ibufs_arr[view_id]);
|
||||
|
@ -3085,19 +3113,51 @@ static ImBuf *seq_render_image_strip(const SeqRenderData *context,
|
|||
MEM_freeN(ibufs_arr);
|
||||
}
|
||||
else {
|
||||
monoview_image:
|
||||
if ((ibuf = IMB_loadiffname(name, flag, seq->strip->colorspace_settings.name))) {
|
||||
/* we don't need both (speed reasons)! */
|
||||
if (ibuf->rect_float && ibuf->rect) {
|
||||
imb_freerectImBuf(ibuf);
|
||||
}
|
||||
ibuf = seq_render_image_strip_view(context, seq, cfra, name, prefix, ext, context->view_id);
|
||||
}
|
||||
|
||||
/* all sequencer color is done in SRGB space, linear gives odd crossfades */
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false);
|
||||
if (ibuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s_elem->orig_width = ibuf->x;
|
||||
s_elem->orig_height = ibuf->y;
|
||||
}
|
||||
s_elem->orig_width = ibuf->x;
|
||||
s_elem->orig_height = ibuf->y;
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
/* Render individual view for multiview or single (default view) for monoview. */
|
||||
static ImBuf *seq_render_movie_strip_view(
|
||||
const SeqRenderData *context, Sequence *seq, float nr, float cfra, StripAnim *sanim)
|
||||
{
|
||||
ImBuf *ibuf = NULL;
|
||||
IMB_Proxy_Size psize = seq_rendersize_to_proxysize(context->preview_render_size);
|
||||
|
||||
IMB_anim_set_preseek(sanim->anim, seq->anim_preseek);
|
||||
|
||||
if (seq_can_use_proxy(seq, psize)) {
|
||||
ibuf = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN,
|
||||
psize);
|
||||
}
|
||||
|
||||
/* Fetching for requested proxy size failed, try fetching the original instead. */
|
||||
if (ibuf == NULL) {
|
||||
ibuf = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN,
|
||||
IMB_PROXY_NONE);
|
||||
}
|
||||
if (ibuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false);
|
||||
|
||||
/* We don't need both (speed reasons)! */
|
||||
if (ibuf->rect_float != NULL && ibuf->rect != NULL) {
|
||||
imb_freerectImBuf(ibuf);
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
|
@ -3108,93 +3168,52 @@ static ImBuf *seq_render_movie_strip(const SeqRenderData *context,
|
|||
float nr,
|
||||
float cfra)
|
||||
{
|
||||
ImBuf *ibuf = NULL;
|
||||
StripAnim *sanim;
|
||||
|
||||
bool is_multiview = (seq->flag & SEQ_USE_VIEWS) != 0 &&
|
||||
(context->scene->r.scemode & R_MULTIVIEW) != 0;
|
||||
|
||||
IMB_Proxy_Size psize = seq_rendersize_to_proxysize(context->preview_render_size);
|
||||
|
||||
if ((seq->flag & SEQ_USE_PROXY) == 0) {
|
||||
psize = IMB_PROXY_NONE;
|
||||
}
|
||||
/* load all the videos */
|
||||
/* Load all the videos. */
|
||||
seq_open_anim_file(context->scene, seq, false);
|
||||
|
||||
if (is_multiview) {
|
||||
ImBuf *ibuf = NULL;
|
||||
StripAnim *sanim = seq->anims.first;
|
||||
const int totfiles = seq_num_files(context->scene, seq->views_format, true);
|
||||
bool is_multiview_render = (seq->flag & SEQ_USE_VIEWS) != 0 &&
|
||||
(context->scene->r.scemode & R_MULTIVIEW) != 0 &&
|
||||
BLI_listbase_count_at_most(&seq->anims, totfiles + 1) == totfiles;
|
||||
|
||||
if (is_multiview_render) {
|
||||
ImBuf **ibuf_arr;
|
||||
const int totfiles = seq_num_files(context->scene, seq->views_format, true);
|
||||
int totviews;
|
||||
int ibuf_view_id;
|
||||
|
||||
if (totfiles != BLI_listbase_count_at_most(&seq->anims, totfiles + 1)) {
|
||||
goto monoview_movie;
|
||||
}
|
||||
|
||||
totviews = BKE_scene_multiview_num_views_get(&context->scene->r);
|
||||
int totviews = BKE_scene_multiview_num_views_get(&context->scene->r);
|
||||
ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Sequence Image Views Imbufs");
|
||||
int ibuf_view_id;
|
||||
|
||||
for (ibuf_view_id = 0, sanim = seq->anims.first; sanim; sanim = sanim->next, ibuf_view_id++) {
|
||||
if (sanim->anim) {
|
||||
IMB_anim_set_preseek(sanim->anim, seq->anim_preseek);
|
||||
|
||||
ibuf_arr[ibuf_view_id] = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc :
|
||||
IMB_TC_RECORD_RUN,
|
||||
psize);
|
||||
|
||||
/* fetching for requested proxy size failed, try fetching the original instead */
|
||||
if (!ibuf_arr[ibuf_view_id] && psize != IMB_PROXY_NONE) {
|
||||
ibuf_arr[ibuf_view_id] = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc :
|
||||
IMB_TC_RECORD_RUN,
|
||||
IMB_PROXY_NONE);
|
||||
}
|
||||
if (ibuf_arr[ibuf_view_id]) {
|
||||
/* we don't need both (speed reasons)! */
|
||||
if (ibuf_arr[ibuf_view_id]->rect_float && ibuf_arr[ibuf_view_id]->rect) {
|
||||
imb_freerectImBuf(ibuf_arr[ibuf_view_id]);
|
||||
}
|
||||
}
|
||||
ibuf_arr[ibuf_view_id] = seq_render_movie_strip_view(context, seq, nr, cfra, sanim);
|
||||
}
|
||||
}
|
||||
|
||||
if (seq->views_format == R_IMF_VIEWS_STEREO_3D) {
|
||||
if (ibuf_arr[0]) {
|
||||
IMB_ImBufFromStereo3d(seq->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]);
|
||||
}
|
||||
else {
|
||||
/* probably proxy hasn't been created yet */
|
||||
if (ibuf_arr[0] == NULL) {
|
||||
/* Probably proxy hasn't been created yet. */
|
||||
MEM_freeN(ibuf_arr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IMB_ImBufFromStereo3d(seq->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]);
|
||||
}
|
||||
|
||||
for (int view_id = 0; view_id < totviews; view_id++) {
|
||||
SeqRenderData localcontext = *context;
|
||||
localcontext.view_id = view_id;
|
||||
|
||||
if (ibuf_arr[view_id]) {
|
||||
/* all sequencer color is done in SRGB space, linear gives odd crossfades */
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf_arr[view_id], false);
|
||||
}
|
||||
if (view_id != context->view_id) {
|
||||
ibuf_arr[view_id] = seq_render_preprocess_ibuf(
|
||||
&localcontext, seq, ibuf_arr[view_id], cfra, clock(), true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* return the original requested ImBuf */
|
||||
/* Return the original requested ImBuf. */
|
||||
ibuf = ibuf_arr[context->view_id];
|
||||
if (ibuf) {
|
||||
seq->strip->stripdata->orig_width = ibuf->x;
|
||||
seq->strip->stripdata->orig_height = ibuf->y;
|
||||
}
|
||||
|
||||
/* "remove" the others (decrease their refcount) */
|
||||
/* Remove the others (decrease their refcount). */
|
||||
for (int view_id = 0; view_id < totviews; view_id++) {
|
||||
if (ibuf_arr[view_id] != ibuf) {
|
||||
IMB_freeImBuf(ibuf_arr[view_id]);
|
||||
|
@ -3204,36 +3223,16 @@ static ImBuf *seq_render_movie_strip(const SeqRenderData *context,
|
|||
MEM_freeN(ibuf_arr);
|
||||
}
|
||||
else {
|
||||
monoview_movie:
|
||||
sanim = seq->anims.first;
|
||||
if (sanim && sanim->anim) {
|
||||
IMB_anim_set_preseek(sanim->anim, seq->anim_preseek);
|
||||
|
||||
ibuf = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN,
|
||||
psize);
|
||||
|
||||
/* fetching for requested proxy size failed, try fetching the original instead */
|
||||
if (!ibuf && psize != IMB_PROXY_NONE) {
|
||||
ibuf = IMB_anim_absolute(sanim->anim,
|
||||
nr + seq->anim_startofs,
|
||||
seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN,
|
||||
IMB_PROXY_NONE);
|
||||
}
|
||||
if (ibuf) {
|
||||
BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false);
|
||||
|
||||
/* we don't need both (speed reasons)! */
|
||||
if (ibuf->rect_float && ibuf->rect) {
|
||||
imb_freerectImBuf(ibuf);
|
||||
}
|
||||
|
||||
seq->strip->stripdata->orig_width = ibuf->x;
|
||||
seq->strip->stripdata->orig_height = ibuf->y;
|
||||
}
|
||||
}
|
||||
ibuf = seq_render_movie_strip_view(context, seq, nr, cfra, sanim);
|
||||
}
|
||||
|
||||
if (ibuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seq->strip->stripdata->orig_width = ibuf->x;
|
||||
seq->strip->stripdata->orig_height = ibuf->y;
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
|
@ -5016,7 +5015,7 @@ int BKE_sequence_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* prefix + [" + escaped_name + "] + \0 */
|
||||
/* r_prefix + [" + escaped_name + "] + \0 */
|
||||
#define SEQ_RNAPATH_MAXSTR ((30 + 2 + (SEQ_NAME_MAXSTR * 2) + 2) + 1)
|
||||
|
||||
static size_t sequencer_rna_path_prefix(char str[SEQ_RNAPATH_MAXSTR], const char *name)
|
||||
|
|
Loading…
Reference in New Issue