[Bf-blender-cvs] [566f3cf] gooseberry: Sort files in collapsed sequences by frame number.

Antony Riakiotakis noreply at git.blender.org
Mon Jun 8 15:52:10 CEST 2015


Commit: 566f3cfb0b96726eee15e64ee65aece52d637fe6
Author: Antony Riakiotakis
Date:   Mon Jun 8 15:51:09 2015 +0200
Branches: gooseberry
https://developer.blender.org/rB566f3cfb0b96726eee15e64ee65aece52d637fe6

Sort files in collapsed sequences by frame number.

Now getting an "animation" preview should be pretty easy.

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

M	source/blender/blenlib/BLI_fileops_types.h
M	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filelist.c

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

diff --git a/source/blender/blenlib/BLI_fileops_types.h b/source/blender/blenlib/BLI_fileops_types.h
index de834c5..ea1b5d5 100644
--- a/source/blender/blenlib/BLI_fileops_types.h
+++ b/source/blender/blenlib/BLI_fileops_types.h
@@ -46,11 +46,12 @@ typedef struct CollapsedEntry {
 	/* list that gets populated during file open */
 	ListBase list;
 	/* sorted array of the files for quick access of frames */
-	struct direntry *darray;
+	struct direntry **darray;
 	off_t totalsize;
 	int minframe;
 	int maxframe;
 	int numdigits;
+	int totfiles;
 } CollapsedEntry;
 
 struct direntry {
@@ -81,7 +82,8 @@ struct direntry {
 	int     nr;
 	struct ImBuf *image;
 	unsigned int selflag; /* selection flag */
-	off_t realsize;
+	off_t realsize;	/* real size of file */
+	int frame; /* frame of file in a movie sequence */
 
 	CollapsedEntry collapsed_info;
 };
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index b5a0a01..f700a12 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -365,6 +365,9 @@ void BLI_filelist_duplicate(
 		if (dest->poin && dup_poin) {
 			dest->poin = dup_poin(src->poin);
 		}
+		if (dest->collapsed_info.darray) {
+			dest->collapsed_info.darray = NULL;
+		}
 	}
 }
 
@@ -385,9 +388,8 @@ void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries, void (
 			MEM_freeN(entry->path);
 		if (entry->poin && free_poin)
 			free_poin(entry->poin);
-		if (entry->collapsed_info.list.first) {
-			BLI_freelistN(&entry->collapsed_info.list);
-		}
+		if (entry->collapsed_info.darray)
+			MEM_freeN(entry->collapsed_info.darray);
 	}
 
 	if (filelist != NULL) {
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 6da20e0..ab0e1da 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -870,25 +870,24 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
 					struct direntry *file = filelist_file(sfile->files, i);
 
 					if (file->selflag & FILE_SEL_COLLAPSED) {
+						int j = 0;
 						CollapsedEntry *collapsed = &file->collapsed_info;
-						LinkData *link_iter = collapsed->list.first;
 
-						while (link_iter) {
-							LinkData *link_tmp = link_iter->next;
-							struct direntry *file_tmp = link_iter->data;
+						for (; j < collapsed->totfiles; j++) {
+							struct direntry *file_tmp = collapsed->darray[j];
 							RNA_property_collection_add(op->ptr, prop, &itemptr);
 							RNA_string_set(&itemptr, "name", file_tmp->relname);
 							num_files++;
-							MEM_freeN(link_iter);
-							link_iter = link_tmp;
 						}
 
-						BLI_listbase_clear(&collapsed->list);
+						MEM_freeN(collapsed->darray);
+						collapsed->darray = NULL;
+					}
+					else {
+						RNA_property_collection_add(op->ptr, prop, &itemptr);
+						RNA_string_set(&itemptr, "name", file->relname);
+						num_files++;
 					}
-
-					RNA_property_collection_add(op->ptr, prop, &itemptr);
-					RNA_string_set(&itemptr, "name", file->relname);
-					num_files++;
 				}
 			}
 			/* make sure the file specified in the filename button is added even if no files selected */
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 3108c13..7602844 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -486,26 +486,32 @@ static bool is_filtered_file(struct direntry *file, const char *UNUSED(root), Fi
 					is_filtered = false;
 					ofile->selflag |= FILE_SEL_COLLAPSED;
 					file->selflag |= FILE_SEL_COLLAPSED;
+					file->frame = frame;
 					BLI_addhead(&collapsed->list, BLI_genericNodeN(file));
 					collapsed->totalsize += file->realsize;
 					collapsed->maxframe = MAX2(frame, collapsed->maxframe);
 					collapsed->minframe = MIN2(frame, collapsed->minframe);
+					collapsed->totfiles++;
 				}
 				else {
-					if (file->collapsed_info.list.first) {
-						BLI_freelistN(&file->collapsed_info.list);
+					if (file->collapsed_info.darray) {
+						MEM_freeN(file->collapsed_info.darray);
+						file->collapsed_info.darray = NULL;
 					}
 					BLI_ghash_insert(filter->unique_image_list, BLI_strdup(filename), file);
+					file->frame = frame;
 					file->collapsed_info.totalsize = file->realsize;
 					file->collapsed_info.maxframe = file->collapsed_info.minframe = frame;
 					file->collapsed_info.numdigits = numdigits;
+					file->collapsed_info.totfiles = 1;
 				}
 			}
 		}
 	}
 	else {
-		if (file->collapsed_info.list.first) {
-			BLI_freelistN(&file->collapsed_info.list);
+		if (file->collapsed_info.darray) {
+			MEM_freeN(file->collapsed_info.darray);
+			file->collapsed_info.darray = NULL;
 		}
 		/* may have been set in a previous filtering iteration, so always clear */
 		file->selflag &= ~FILE_SEL_COLLAPSED;
@@ -547,6 +553,17 @@ static void filelist_filter_clear(FileList *filelist)
 	filelist->numfiltered = 0;
 }
 
+static int compareFrame(const void *pa, const void *pb)
+{
+	struct direntry *a = *((struct direntry **)pa);
+	struct direntry *b = *((struct direntry **)pb);
+	if (a->frame < b->frame)
+		return -1;
+	if (a->frame > b->frame)
+		return 1;
+	return 0;
+}
+
 void filelist_filter(FileList *filelist)
 {
 	int num_filtered = 0;
@@ -583,6 +600,28 @@ void filelist_filter(FileList *filelist)
 		filelist->filter_data.unique_image_list = NULL;
 	}
 
+	/* extra step, need to sort the file list according to frame */
+	if (filelist->filter_data.collapse_ima_seq) {
+		for (i = 0; i < num_filtered; i++) {
+			struct direntry *file = &filelist->filelist[fidx_tmp[i]];
+			if (file->selflag & FILE_SEL_COLLAPSED) {
+				LinkData *fdata = file->collapsed_info.list.first;
+				int j = 1;
+				file->collapsed_info.darray =
+				        MEM_mallocN(sizeof(struct direntry *) * file->collapsed_info.totfiles, "collapsed files");
+				file->collapsed_info.darray[0] = file;
+
+				for (; fdata; fdata = fdata->next, j++) {
+					file->collapsed_info.darray[j] = fdata->data;
+				}
+				qsort(file->collapsed_info.darray, file->collapsed_info.totfiles, sizeof(struct direntry *), compareFrame);
+				if (file->collapsed_info.list.first) {
+					BLI_freelistN(&file->collapsed_info.list);
+				}
+			}
+		}
+	}
+
 	/* Note: maybe we could even accept filelist->fidx to be filelist->numfiles -len allocated? */
 	filelist->fidx = MEM_mallocN(sizeof(*filelist->fidx) * (size_t)num_filtered, __func__);
 	memcpy(filelist->fidx, fidx_tmp, sizeof(*filelist->fidx) * (size_t)num_filtered);




More information about the Bf-blender-cvs mailing list