[Bf-blender-cvs] [447a297] blend-thumbnail: Some minor cleanup & enhancements from Campbell's review, thanks.

Bastien Montagne noreply at git.blender.org
Thu Aug 27 15:51:40 CEST 2015


Commit: 447a29749c2330123de8993d794ac8f25ff4ce38
Author: Bastien Montagne
Date:   Thu Aug 27 15:51:08 2015 +0200
Branches: blend-thumbnail
https://developer.blender.org/rB447a29749c2330123de8993d794ac8f25ff4ce38

Some minor cleanup & enhancements from Campbell's review, thanks.

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/BLO_writefile.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/imbuf/intern/thumbs_blend.c
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 33aa6c4..5b12858 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -38,7 +38,7 @@ extern "C" {
 
 #include "BLI_compiler_attrs.h"
 
-struct BlenThumbnail;
+struct BlendThumbnail;
 struct ListBase;
 struct ID;
 struct ImBuf;
@@ -89,8 +89,8 @@ void BKE_main_free(struct Main *mainvar);
 void BKE_main_lock(struct Main *bmain);
 void BKE_main_unlock(struct Main *bmain);
 
-struct BlenThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct ImBuf *img);
-struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlenThumbnail *data);
+struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct ImBuf *img);
+struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data);
 void BKE_main_thumbnail_create(struct Main *bmain);
 
 void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const bool tag);
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 9736c6d..6a00961 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -52,9 +52,10 @@ struct MainLock;
 
 /* Blender thumbnail, as written on file (width, height, and data as char RGBA). */
 /* We pack pixel data after that struct. */
-typedef struct BlenThumbnail {
+typedef struct BlendThumbnail {
 	int width, height;
-} BlenThumbnail;
+	char rect[0];
+} BlendThumbnail;
 
 typedef struct Main {
 	struct Main *next, *prev;
@@ -65,7 +66,7 @@ typedef struct Main {
 	char build_hash[16];  /* hash from buildinfo */
 	short recovered;	/* indicate the main->name (file) is the recovered one */
 
-	BlenThumbnail *blen_thumb;
+	BlendThumbnail *blen_thumb;
 	
 	struct Library *curlib;
 	ListBase scene;
@@ -119,7 +120,7 @@ typedef struct Main {
 
 #define BLEN_THUMB_SIZE 128
 
-#define BLEN_THUMB_MEMSIZE(_x, _y) (sizeof(BlenThumbnail) + (size_t)((_x) * (_y)) * sizeof(int))
+#define BLEN_THUMB_MEMSIZE(_x, _y) (sizeof(BlendThumbnail) + (size_t)((_x) * (_y)) * sizeof(int))
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index a7a6c6a..878334a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1178,9 +1178,9 @@ void BKE_main_unlock(struct Main *bmain)
  * @param img ImBuf image to generate thumbnail data from.
  * @return The generated .blend file raw thumbnail data.
  */
-BlenThumbnail *BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
+BlendThumbnail *BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
 {
-	BlenThumbnail *data = NULL;
+	BlendThumbnail *data = NULL;
 
 	if (bmain) {
 		MEM_SAFE_FREE(bmain->blen_thumb);
@@ -1193,7 +1193,7 @@ BlenThumbnail *BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
 		IMB_rect_from_float(img);  /* Just in case... */
 		data->width = img->x;
 		data->height = img->y;
-		memcpy(&data[1], img->rect, sz - sizeof(*data));
+		memcpy(data->rect, img->rect, sz - sizeof(*data));
 	}
 
 	if (bmain) {
@@ -1209,7 +1209,7 @@ BlenThumbnail *BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
  * @param data Raw .blend file thumbnail data.
  * @return An ImBuf from given data, or NULL if invalid.
  */
-ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain, BlenThumbnail *data)
+ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
 {
 	ImBuf *img = NULL;
 
@@ -1221,7 +1221,7 @@ ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain, BlenThumbnail *data)
 		/* Note: we cannot use IMB_allocFromBuffer(), since it tries to dupalloc passed buffer, which will fail
 		 *       here (we do not want to pass the first two ints!). */
 		img = IMB_allocImBuf((unsigned int)data->width, (unsigned int)data->height, 32, IB_rect | IB_metadata);
-		memcpy(img->rect, &data[1], BLEN_THUMB_MEMSIZE(data->width, data->height) - sizeof(*data));
+		memcpy(img->rect, data->rect, BLEN_THUMB_MEMSIZE(data->width, data->height) - sizeof(*data));
 	}
 
 	return img;
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 07872a3..77bdb99 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -36,7 +36,7 @@
 extern "C" {
 #endif
 
-struct BlenThumbnail;
+struct BlendThumbnail;
 struct bScreen;
 struct LinkNode;
 struct Main;
@@ -282,11 +282,11 @@ void BLO_update_defaults_startup_blend(struct Main *mainvar);
 /**
  * Does a very light reading of given .blend file to extract its stored thumbnail.
  *
- * @param filepath The path of the file to extract thumbnail from.
- * @return The raw thumbnail
+ * \param filepath The path of the file to extract thumbnail from.
+ * \return The raw thumbnail
  *         (MEM-allocated, as stored in file, use BKE_main_thumbnail_to_imbuf() to convert it to ImBuf image).
  */
-struct BlenThumbnail *BLO_thumbnail_from_file(const char *filepath);
+struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
 
 #ifdef __cplusplus
 } 
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h
index 86e1e07..0d66eb7 100644
--- a/source/blender/blenloader/BLO_writefile.h
+++ b/source/blender/blenloader/BLO_writefile.h
@@ -33,14 +33,13 @@
  *  \brief external writefile function prototypes.
  */
 
-struct BlenThumbnail;
+struct BlendThumbnail;
 struct MemFile;
 struct Main;
 struct ReportList;
 
-extern int BLO_write_file(
-        struct Main *mainvar, const char *filepath, int write_flags,
-        struct ReportList *reports, const struct BlenThumbnail *thumb);
+extern int BLO_write_file(struct Main *mainvar, const char *filepath, int write_flags,
+        struct ReportList *reports, const struct BlendThumbnail *thumb);
 extern int BLO_write_file_mem(struct Main *mainvar, struct MemFile *compare, struct MemFile *current, int write_flags);
 
 #endif
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 5b24564..ee07f2b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1352,10 +1352,10 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha
 	return true;
 }
 
-BlenThumbnail *BLO_thumbnail_from_file(const char *filepath)
+BlendThumbnail *BLO_thumbnail_from_file(const char *filepath)
 {
 	FileData *fd;
-	BlenThumbnail *data;
+	BlendThumbnail *data;
 	int *fd_data;
 
 	fd = blo_openblenderfile_minimal(filepath);
@@ -1368,7 +1368,7 @@ BlenThumbnail *BLO_thumbnail_from_file(const char *filepath)
 		BLI_assert((sz - sizeof(*data)) == (BLEN_THUMB_MEMSIZE_FILE(fd_data[0], fd_data[1]) - (sizeof(*fd_data) * 2)));
 		data->width = fd_data[0];
 		data->height = fd_data[1];
-		memcpy(&data[1], &fd_data[2], sz - sizeof(*data));
+		memcpy(data->rect, &fd_data[2], sz - sizeof(*data));
 	}
 	else {
 		data = NULL;
@@ -8277,7 +8277,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
 			           (BLEN_THUMB_MEMSIZE_FILE(data[0], data[1]) - (sizeof(*data) * 2)));
 			bfd->main->blen_thumb->width = data[0];
 			bfd->main->blen_thumb->height = data[1];
-			memcpy(&bfd->main->blen_thumb[1], &data[2], sz - sizeof(*bfd->main->blen_thumb));
+			memcpy(bfd->main->blen_thumb->rect, &data[2], sz - sizeof(*bfd->main->blen_thumb));
 		}
 	}
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7cb6913..94f3237 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3688,7 +3688,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
  * second are an RGBA image (unsigned char)
  * note, this uses 'TEST' since new types will segfault on file load for older blender versions.
  */
-static void write_thumb(WriteData *wd, const BlenThumbnail *thumb)
+static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
 {
 	if (thumb) {
 		size_t sz = BLEN_THUMB_MEMSIZE_FILE(thumb->width, thumb->height);
@@ -3697,7 +3697,7 @@ static void write_thumb(WriteData *wd, const BlenThumbnail *thumb)
 		BLI_assert((sz - (sizeof(*img) * 2)) == (BLEN_THUMB_MEMSIZE(thumb->width, thumb->height) - sizeof(thumb)));
 		img[0] = thumb->width;
 		img[1] = thumb->height;
-		memcpy(&img[2], &thumb[1], sz - (sizeof(*img) * 2));
+		memcpy(&img[2], thumb->rect, sz - (sizeof(*img) * 2));
 		writedata(wd, TEST, sz, img);
 	}
 }
@@ -3707,7 +3707,7 @@ static int write_file_handle(
         Main *mainvar,
         WriteWrap *ww,
         MemFile *compare, MemFile *current,
-        int write_user_block, int write_flags, const BlenThumbnail *thumb)
+        int write_user_block, int write_flags, const BlendThumbnail *thumb)
 {
 	BHead bhead;
 	ListBase mainlist;
@@ -3840,7 +3840,7 @@ static bool do_history(const char *name, ReportList *reports)
 
 /* return: success (1) */
 int BLO_write_file(
-        Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const BlenThumbnail *thumb)
+        Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const BlendThumbnail *thumb)
 {
 	char tempname[FILE_MAX+1];
 	int err, write_user_block;
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index 4f1c257..b5c6deb 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -105,7 +105,7 @@ ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const
 		BLI_linklist_free(names, free);
 	}
 	else {
-		BlenThumbnail *data;
+		BlendThumbnail *data;
 
 		data = BLO_thumbnail_from_file(blen_path);
 		ima = BKE_main_thumbnail_to_imbuf(NULL, data);
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 8bdb7a9..6927e2d 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -865,11 +865,11 @@ static void wm_history_file_update(void)
 
 
 /* screen can be NULL */
-static ImBuf *blend_file_thumb(Scene *sce

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list