[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12039] trunk/blender/source/blender: == imagebrowser ==

Andrea Weikert elubie at gmx.net
Fri Sep 14 20:21:23 CEST 2007


Revision: 12039
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12039
Author:   elubie
Date:     2007-09-14 20:21:23 +0200 (Fri, 14 Sep 2007)

Log Message:
-----------
== imagebrowser ==
* fix for do_versions, bump correction of old imasel to all files including version 2.44 
* refactoring of filtering code using indices instead of copying entries in filelist 
* memleak fix.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/src/editimasel.c
    trunk/blender/source/blender/src/filelist.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2007-09-14 16:20:02 UTC (rev 12038)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2007-09-14 18:21:23 UTC (rev 12039)
@@ -6505,61 +6505,7 @@
 		}		
 
 	}
-
-
-	if (main->versionfile < 244) {
-		bScreen *sc;
-		Image* ima;
-
-		/* repair preview from 242 */
-		for(ima= main->image.first; ima; ima= ima->id.next) {
-			ima->preview = NULL;
-		}
-		
-		/* repair imasel space - completely reworked */
-		for(sc= main->screen.first; sc; sc= sc->id.next) {
-			ScrArea *sa;
-			sa= sc->areabase.first;
-			while(sa) {
-				SpaceLink *sl;
-
-				for (sl= sa->spacedata.first; sl; sl= sl->next) {
-					if(sl->spacetype==SPACE_IMASEL) {
-						SpaceImaSel *simasel= (SpaceImaSel*) sl;
-						simasel->blockscale= 0.7;
-						/* view 2D */
-						simasel->v2d.tot.xmin=  -10.0;
-						simasel->v2d.tot.ymin=  -10.0;
-						simasel->v2d.tot.xmax= (float)sa->winx + 10.0f;
-						simasel->v2d.tot.ymax= (float)sa->winy + 10.0f;						
-						simasel->v2d.cur.xmin=  0.0;
-						simasel->v2d.cur.ymin=  0.0;
-						simasel->v2d.cur.xmax= (float)sa->winx;
-						simasel->v2d.cur.ymax= (float)sa->winy;						
-						simasel->v2d.min[0]= 1.0;
-						simasel->v2d.min[1]= 1.0;						
-						simasel->v2d.max[0]= 32000.0f;
-						simasel->v2d.max[1]= 32000.0f;						
-						simasel->v2d.minzoom= 0.5f;
-						simasel->v2d.maxzoom= 1.21f;						
-						simasel->v2d.scroll= 0;
-						simasel->v2d.keepaspect= 1;
-						simasel->v2d.keepzoom= 1;
-						simasel->v2d.keeptot= 0;
-						simasel->prv_h = 96;
-						simasel->prv_w = 96;
-						simasel->flag = 7; /* ??? elubie */
-						strcpy (simasel->dir,  U.textudir);	/* TON */
-						strcpy (simasel->file, "");
-
-						simasel->returnfunc     =  0;	
-						simasel->title[0]       =  0;
-					}
-				}
-				sa = sa->next;
-			}
-		}
-	}
+	
 	if(main->versionfile <= 244) {
 		Scene *sce;
 		Material *ma;
@@ -6725,6 +6671,65 @@
 		}
 	}
 
+	if (main->versionfile <= 245) {
+		bScreen *sc;
+		Image* ima;
+
+		/* fix all versions before 2.45 */
+		if (main->versionfile != 245) {
+
+			/* repair preview from 242 - 244*/
+			for(ima= main->image.first; ima; ima= ima->id.next) {
+				ima->preview = NULL;
+			}
+			
+			/* repair imasel space - completely reworked */
+			for(sc= main->screen.first; sc; sc= sc->id.next) {
+				ScrArea *sa;
+				sa= sc->areabase.first;
+				while(sa) {
+					SpaceLink *sl;
+
+					for (sl= sa->spacedata.first; sl; sl= sl->next) {
+						if(sl->spacetype==SPACE_IMASEL) {
+							SpaceImaSel *simasel= (SpaceImaSel*) sl;
+							simasel->blockscale= 0.7;
+							/* view 2D */
+							simasel->v2d.tot.xmin=  -10.0;
+							simasel->v2d.tot.ymin=  -10.0;
+							simasel->v2d.tot.xmax= (float)sa->winx + 10.0f;
+							simasel->v2d.tot.ymax= (float)sa->winy + 10.0f;						
+							simasel->v2d.cur.xmin=  0.0;
+							simasel->v2d.cur.ymin=  0.0;
+							simasel->v2d.cur.xmax= (float)sa->winx;
+							simasel->v2d.cur.ymax= (float)sa->winy;						
+							simasel->v2d.min[0]= 1.0;
+							simasel->v2d.min[1]= 1.0;						
+							simasel->v2d.max[0]= 32000.0f;
+							simasel->v2d.max[1]= 32000.0f;						
+							simasel->v2d.minzoom= 0.5f;
+							simasel->v2d.maxzoom= 1.21f;						
+							simasel->v2d.scroll= 0;
+							simasel->v2d.keepaspect= 1;
+							simasel->v2d.keepzoom= 1;
+							simasel->v2d.keeptot= 0;
+							simasel->prv_h = 96;
+							simasel->prv_w = 96;
+							simasel->flag = 7; /* ??? elubie */
+							strcpy (simasel->dir,  U.textudir);	/* TON */
+							strcpy (simasel->file, "");
+
+							simasel->returnfunc     =  0;	
+							simasel->title[0]       =  0;
+						}
+					}
+					sa = sa->next;
+				}
+			}
+		}
+
+	}
+
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
 

Modified: trunk/blender/source/blender/src/editimasel.c
===================================================================
--- trunk/blender/source/blender/src/editimasel.c	2007-09-14 16:20:02 UTC (rev 12038)
+++ trunk/blender/source/blender/src/editimasel.c	2007-09-14 18:21:23 UTC (rev 12039)
@@ -589,10 +589,12 @@
 				if (okee("Makedir")) {
 					BLI_recurdir_fileops(butname);
 					if (!BLI_exists(butname)) {
+						BIF_filelist_free(simasel->files);
 						BIF_filelist_parent(simasel->files);
 						BLI_strncpy(simasel->dir, BIF_filelist_dir(simasel->files), 80);
 					}
 				} else {
+					BIF_filelist_free(simasel->files);
 					BIF_filelist_parent(simasel->files);
 					BLI_strncpy(simasel->dir, BIF_filelist_dir(simasel->files), 80);
 				}

Modified: trunk/blender/source/blender/src/filelist.c
===================================================================
--- trunk/blender/source/blender/src/filelist.c	2007-09-14 16:20:02 UTC (rev 12038)
+++ trunk/blender/source/blender/src/filelist.c	2007-09-14 18:21:23 UTC (rev 12039)
@@ -91,10 +91,10 @@
 typedef struct FileList
 {
 	struct direntry *filelist;
-	struct direntry *unfiltered;
+	int *fidx;
 
 	int numfiles;
-	int numunfiltered;
+	int numfiltered;
 	char dir[FILE_MAXDIR];
 	short type;
 	short ipotype;
@@ -274,49 +274,44 @@
 		return;
 	
 	if (!filelist->filter) {
-		if (filelist->unfiltered) {
-			old_filelist = filelist->filelist;
-			filelist->filelist = filelist->unfiltered;
-			filelist->numfiles = filelist->numunfiltered;
-			filelist->unfiltered = 0;
-			filelist->numunfiltered = 0;
-			free (old_filelist);
+		if (filelist->fidx) {
+			MEM_freeN(filelist->fidx);
+			filelist->fidx = NULL;
 		}
+		filelist->fidx = (int *)MEM_callocN(filelist->numfiles*sizeof(int), "filteridx");
+		for (i = 0; i < filelist->numfiles; ++i) {
+			filelist->fidx[i] = i;
+		}
+		filelist->numfiltered = filelist->numfiles;
 		return;
 	}
 
-	if (!filelist->unfiltered) {
-		filelist->unfiltered = filelist->filelist;
-		filelist->numunfiltered = filelist->numfiles;
-	}
-
-	old_filelist = filelist->unfiltered;
-	num_files = filelist->numunfiltered;
-
-	filelist->filelist = 0;
-
 	// How many files are left after filter ?
-	for (i = 0; i < num_files; ++i) {
-		if (old_filelist[i].flags & filelist->filter) {
+	for (i = 0; i < filelist->numfiles; ++i) {
+		if (filelist->filelist[i].flags & filelist->filter) {
 			num_filtered++;
 		} 
-		else if (old_filelist[i].type & S_IFDIR) {
+		else if (filelist->filelist[i].type & S_IFDIR) {
 			if (filelist->filter & FOLDERFILE) {
 				num_filtered++;
 			}
 		}		
 	}
 	
-	filelist->filelist = (struct direntry *)malloc(num_filtered * sizeof(struct direntry));
-	filelist->numfiles = num_filtered;
+	if (filelist->fidx) {
+			MEM_freeN(filelist->fidx);
+			filelist->fidx = NULL;
+	}
+	filelist->fidx = (int *)MEM_callocN(num_filtered*sizeof(int), "filteridx");
+	filelist->numfiltered = num_filtered;
 
-	for (i = 0, j=0; i < num_files; ++i) {
-		if (old_filelist[i].flags & filelist->filter) {
-			filelist->filelist[j++] = old_filelist[i];
+	for (i = 0, j=0; i < filelist->numfiles; ++i) {
+		if (filelist->filelist[i].flags & filelist->filter) {
+			filelist->fidx[j++] = i;
 		}
-		else if (old_filelist[i].type & S_IFDIR) {
+		else if (filelist->filelist[i].type & S_IFDIR) {
 			if (filelist->filter & FOLDERFILE) {
-				filelist->filelist[j++] = old_filelist[i];
+				filelist->fidx[j++] = i;
 			}
 		}  
 	}
@@ -373,7 +368,7 @@
 	FileList* p = BIF_filelist_new();
 	BLI_strncpy(p->dir, filelist->dir, FILE_MAXDIR);
 	p->filelist = NULL;
-	p->unfiltered = NULL;
+	p->fidx = NULL;
 	p->type = filelist->type;
 	p->ipotype = filelist->ipotype;
 	p->has_func = filelist->has_func;
@@ -390,18 +385,15 @@
 		return;
 	}
 
-	if (filelist->unfiltered) {
-		struct direntry* filtered_files = filelist->filelist;
-		filelist->filelist = filelist->unfiltered;
-		filelist->numfiles = filelist->numunfiltered;
-		filelist->numunfiltered = 0;
-		free (filtered_files);
-		filelist->unfiltered = 0;
+	if (filelist->fidx) {
+		MEM_freeN(filelist->fidx);
+		filelist->fidx = NULL;
 	}
 
 	for (i = 0; i < filelist->numfiles; ++i) {
-		if (filelist->filelist[i].image)
+		if (filelist->filelist[i].image) {			
 			IMB_freeImBuf(filelist->filelist[i].image);
+		}
 		filelist->filelist[i].image = 0;
 		if (filelist->filelist[i].relname)
 			MEM_freeN(filelist->filelist[i].relname);
@@ -414,6 +406,8 @@
 	filelist->numfiles = 0;
 	free(filelist->filelist);
 	filelist->filelist = 0;	
+	filelist->filter = 0;
+	filelist->numfiltered =0;
 }
 
 void BIF_filelist_freelib(struct FileList* filelist)
@@ -430,7 +424,7 @@
 
 int	BIF_filelist_numfiles(struct FileList* filelist)
 {
-	return filelist->numfiles;
+	return filelist->numfiltered;
 }
 
 const char * BIF_filelist_dir(struct FileList* filelist)
@@ -462,19 +456,25 @@
 	int imgheight = filelist->prv_h;
 	short ex, ey, dx, dy;
 	float scaledx, scaledy;
+	int fidx = 0;
+	
+	if ( (index < 0) || (index >= filelist->numfiltered) ) {
+		return;
+	}
+	fidx = filelist->fidx[index];
 
-	if (!filelist->filelist[index].image)
+	if (!filelist->filelist[fidx].image)
 	{
 		if (filelist->type != FILE_MAIN)
 		{
-			if ( filelist->filelist[index].flags & IMAGEFILE ) {
-				imb = IMB_thumb_manage(filelist->dir, filelist->filelist[index].relname, THB_NORMAL, THB_SOURCE_IMAGE);
-			} else if ( filelist->filelist[index].flags & MOVIEFILE ) {
-				imb = IMB_thumb_manage(filelist->dir, filelist->filelist[index].relname, THB_NORMAL, THB_SOURCE_MOVIE);
+			if ( filelist->filelist[fidx].flags & IMAGEFILE ) {				
+				imb = IMB_thumb_manage(filelist->dir, filelist->filelist[fidx].relname, THB_NORMAL, THB_SOURCE_IMAGE);
+			} else if ( filelist->filelist[fidx].flags & MOVIEFILE ) {				
+				imb = IMB_thumb_manage(filelist->dir, filelist->filelist[fidx].relname, THB_NORMAL, THB_SOURCE_MOVIE);
 				if (!imb) {
 					/* remember that file can't be loaded via IMB_open_anim */
-					filelist->filelist[index].flags &= ~MOVIEFILE;
-					filelist->filelist[index].flags |= MOVIEFILE_ICON;
+					filelist->filelist[fidx].flags &= ~MOVIEFILE;
+					filelist->filelist[fidx].flags |= MOVIEFILE_ICON;
 				}
 			}
 			if (imb) {
@@ -495,7 +495,7 @@
 				IMB_scaleImBuf(imb, ex, ey);
 
 			} 
-			filelist->filelist[index].image = imb;
+			filelist->filelist[fidx].image = imb;
 			
 		}
 	}
@@ -503,13 +503,20 @@
 
 struct ImBuf * BIF_filelist_getimage(struct FileList* filelist, int index)
 {
-	ImBuf* ibuf = filelist->filelist[index].image;
+	ImBuf* ibuf = NULL;
+	int fidx = 0;	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list