[Bf-blender-cvs] [6c6f3baaa8c] master: VSE: Fix image adding inconsistency

Richard Antalik noreply at git.blender.org
Tue Mar 30 03:03:09 CEST 2021


Commit: 6c6f3baaa8c5d3a0cc3eb033e93cc6fb0f5721cc
Author: Richard Antalik
Date:   Tue Mar 30 02:41:12 2021 +0200
Branches: master
https://developer.blender.org/rB6c6f3baaa8c5d3a0cc3eb033e93cc6fb0f5721cc

VSE: Fix image adding inconsistency

When adding images with operator, image file path is split into filename
and directory passed to load function in name and path fields of
SeqLoadData struct. This is because when loading images directory
and filenames are split.

RNA API function passes whole path in path filed.

Apart from loading API inconsistency, this causes initial image loading
to fail, so strip resolution is not set. Also name field of SeqLoadData
should be reserved for strip name.

Let operator code concatenate and split filepath when needed so loading
API can be consistent with RNA API and also between strip types.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D10818

===================================================================

M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/sequencer/intern/strip_add.c

===================================================================

diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index a6e7903d1b1..2df8dce0b3c 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -228,7 +228,6 @@ static void load_data_init_from_operator(SeqLoadData *load_data, bContext *C, wm
   PropertyRNA *prop;
   const bool relative = (prop = RNA_struct_find_property(op->ptr, "relative_path")) &&
                         RNA_property_boolean_get(op->ptr, prop);
-  int is_file = -1;
   memset(load_data, 0, sizeof(SeqLoadData));
 
   load_data->start_frame = RNA_int_get(op->ptr, "frame_start");
@@ -242,17 +241,26 @@ static void load_data_init_from_operator(SeqLoadData *load_data, bContext *C, wm
   }
 
   if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
-    /* Full path, file is set by the caller. */
     RNA_property_string_get(op->ptr, prop, load_data->path);
-    is_file = 1;
+    BLI_strncpy(load_data->name, BLI_path_basename(load_data->path), sizeof(load_data->name));
   }
   else if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
-    /* Full path, file is set by the caller. */
-    RNA_property_string_get(op->ptr, prop, load_data->path);
-    is_file = 0;
+    char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
+
+    if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
+      RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
+        char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+        BLI_strncpy(load_data->name, filename, sizeof(load_data->name));
+        BLI_snprintf(load_data->path, sizeof(load_data->path), "%s%s", directory, filename);
+        MEM_freeN(filename);
+        break;
+      }
+      RNA_PROP_END;
+    }
+    MEM_freeN(directory);
   }
 
-  if ((is_file != -1) && relative) {
+  if (relative) {
     BLI_path_rel(load_data->path, BKE_main_blendfile_path(bmain));
   }
 
@@ -276,19 +284,6 @@ static void load_data_init_from_operator(SeqLoadData *load_data, bContext *C, wm
     load_data->flags |= SEQ_LOAD_MOVIE_SYNC_FPS;
   }
 
-  if (is_file == 1) {
-    BLI_strncpy(load_data->name, BLI_path_basename(load_data->path), sizeof(load_data->name));
-  }
-  else if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
-    RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
-      char *name = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
-      BLI_strncpy(load_data->name, name, sizeof(load_data->name));
-      MEM_freeN(name);
-      break;
-    }
-    RNA_PROP_END;
-  }
-
   if ((prop = RNA_struct_find_property(op->ptr, "use_multiview")) &&
       RNA_property_boolean_get(op->ptr, prop)) {
     if (op->customdata) {
@@ -990,8 +985,10 @@ static void sequencer_add_image_strip_load_files(
     wmOperator *op, Sequence *seq, SeqLoadData *load_data, const int minframe, const int numdigits)
 {
   const bool use_placeholders = RNA_boolean_get(op->ptr, "use_placeholders");
-
-  SEQ_add_image_set_directory(seq, load_data->path);
+  /* size of Strip->dir. */
+  char directory[768];
+  BLI_split_dir_part(load_data->path, directory, sizeof(directory));
+  SEQ_add_image_set_directory(seq, directory);
 
   if (use_placeholders) {
     sequencer_image_seq_reserve_frames(
diff --git a/source/blender/sequencer/intern/strip_add.c b/source/blender/sequencer/intern/strip_add.c
index 33dd74cb527..55d92c1eb10 100644
--- a/source/blender/sequencer/intern/strip_add.c
+++ b/source/blender/sequencer/intern/strip_add.c
@@ -324,7 +324,7 @@ Sequence *SEQ_add_image_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
 
   /* Set initial scale based on load_data->fit_method. */
   char file_path[FILE_MAX];
-  BLI_join_dirfile(file_path, sizeof(file_path), load_data->path, load_data->name);
+  BLI_strncpy(file_path, load_data->path, sizeof(file_path));
   BLI_path_abs(file_path, BKE_main_blendfile_path(bmain));
   ImBuf *ibuf = IMB_loadiffname(file_path, IB_rect, seq->strip->colorspace_settings.name);
   if (ibuf != NULL) {



More information about the Bf-blender-cvs mailing list