[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30346] trunk/blender/source/blender: - change blend thumbnail loading function not to use goto's
Campbell Barton
ideasman42 at gmail.com
Wed Jul 14 22:31:11 CEST 2010
Revision: 30346
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30346
Author: campbellbarton
Date: 2010-07-14 22:31:11 +0200 (Wed, 14 Jul 2010)
Log Message:
-----------
- change blend thumbnail loading function not to use goto's
- fix for some warnings
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface_templates.c
trunk/blender/source/blender/imbuf/intern/thumbs_blend.c
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c 2010-07-14 20:26:46 UTC (rev 30345)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c 2010-07-14 20:31:11 UTC (rev 30346)
@@ -197,7 +197,7 @@
if (RNA_function_call(C, &reports, &ptr, func, &parms) == 0) {
int* ret;
- RNA_parameter_get_lookup(&parms, "ret", &ret);
+ RNA_parameter_get_lookup(&parms, "ret", (void **)&ret);
if (!(*ret)) {
RNA_parameter_list_free(&parms);
Modified: trunk/blender/source/blender/imbuf/intern/thumbs_blend.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/thumbs_blend.c 2010-07-14 20:26:46 UTC (rev 30345)
+++ trunk/blender/source/blender/imbuf/intern/thumbs_blend.c 2010-07-14 20:31:11 UTC (rev 30346)
@@ -37,54 +37,60 @@
/* extracts the thumbnail from between the 'REND' and the 'GLOB'
* chunks of the header, dont use typical blend loader because its too slow */
-ImBuf *IMB_loadblend_thumb(const char *path)
+
+static ImBuf *loadblend_thumb(gzFile gzfile)
{
char buf[8];
int code= 0;
char endian, pointer_size;
char endian_switch;
int len, im_len, x, y;
- int *rect= NULL;
+ ImBuf *img= NULL;
- gzFile gzfile;
-
- ImBuf *img;
-
- /* not necessarily a gzip */
- gzfile = gzopen(path, "rb");
- if (NULL == gzfile ) {
+ /* read the blend file header */
+ if(gzread(gzfile, buf, 8) != 8)
return NULL;
- }
-
- /* read the blend file header */
- if(gzread(gzfile, buf, 8) != 8) goto thumb_error;
- if(strncmp(buf, "BLENDER", 7)) goto thumb_error;
-
- if(buf[7]=='-') pointer_size= 8;
- else if(buf[7]=='_') pointer_size= 4;
- else goto thumb_error;
-
+ if(strncmp(buf, "BLENDER", 7))
+ return NULL;
+
+ if(buf[7]=='-')
+ pointer_size= 8;
+ else if(buf[7]=='_')
+ pointer_size= 4;
+ else
+ return NULL;
+
/* read the next 4 bytes, only need the first char, ignore the version */
/* endian and vertsion (ignored) */
- if(gzread(gzfile, buf, 4) != 4) goto thumb_error;
-
- if(buf[0]=='V') endian= B_ENDIAN; /* big: PPC */
- else if(buf[0]=='v') endian= L_ENDIAN; /* little: x86 */
- else goto thumb_error;
+ if(gzread(gzfile, buf, 4) != 4)
+ return NULL;
+ if(buf[0]=='V')
+ endian= B_ENDIAN; /* big: PPC */
+ else if(buf[0]=='v')
+ endian= L_ENDIAN; /* little: x86 */
+ else
+ return NULL;
+
while(gzread(gzfile, &code, sizeof(int)) == sizeof(int)) {
endian_switch = ((ENDIAN_ORDER != endian)) ? 1 : 0;
-
- if(gzread(gzfile, buf, sizeof(int)) != sizeof(int)) goto thumb_error;
+
+ if(gzread(gzfile, buf, sizeof(int)) != sizeof(int))
+ return NULL;
+
len = *( (int *)((void *)buf) );
- if(endian_switch) SWITCH_INT(len);
-
+
+ if(endian_switch)
+ SWITCH_INT(len);
+
/* finally read the rest of the bhead struct, pointer and 2 ints */
- if(gzread(gzfile, buf, pointer_size) != pointer_size) goto thumb_error;
- if(gzread(gzfile, buf, sizeof(int) * 2) != sizeof(int) * 2) goto thumb_error;
+ if(gzread(gzfile, buf, pointer_size) != pointer_size)
+ return NULL;
+ if(gzread(gzfile, buf, sizeof(int) * 2) != sizeof(int) * 2)
+ return NULL;
+
/* we dont actually care whats in the bhead */
-
if (code==REND) {
gzseek(gzfile, len, SEEK_CUR); /* skip to the next */
}
@@ -92,40 +98,57 @@
break;
}
}
-
+
/* using 'TEST' since new names segfault when loading in old blenders */
- if(code != TEST) goto thumb_error;
-
- if(gzread(gzfile, &x, sizeof(int)) != sizeof(int)) goto thumb_error;
- if(gzread(gzfile, &y, sizeof(int)) != sizeof(int)) goto thumb_error;
+ if(code != TEST)
+ return NULL;
+
+ if(gzread(gzfile, &x, sizeof(int)) != sizeof(int))
+ return NULL;
+ if(gzread(gzfile, &y, sizeof(int)) != sizeof(int))
+ return NULL;
+
len -= sizeof(int) * 2;
- if(endian_switch) { SWITCH_INT(x); SWITCH_INT(y); }
+ if(endian_switch) {
+ SWITCH_INT(x);
+ SWITCH_INT(y);
+ }
/* inconsistant image size, quit early */
im_len = x * y * sizeof(int);
- if(im_len != len) goto thumb_error;
+ if(im_len != len)
+ return NULL;
/* finally malloc and read the data */
- rect= MEM_mallocN(len, "imb_loadblend_thumb");
+ img= IMB_allocImBuf(x, y, 32, IB_rect, 0);
- if(gzread(gzfile, rect, len) != len) goto thumb_error;
+ if(gzread(gzfile, img->rect, len) != len) {
+ IMB_freeImBuf(img);
+ img= NULL;
+ }
- /* read ok! */
- gzclose(gzfile);
+ return img;
+}
- img = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata, 0);
+ImBuf *IMB_loadblend_thumb(const char *path)
+{
+ gzFile gzfile;
- memcpy(img->rect, rect, im_len);
+ /* not necessarily a gzip */
+ gzfile = gzopen(path, "rb");
- MEM_freeN(rect);
-
- return img;
+ if (NULL == gzfile ) {
+ return NULL;
+ }
+ else {
+ ImBuf *img= loadblend_thumb(gzfile);
-thumb_error:
- gzclose(gzfile);
- if(rect) MEM_freeN(rect);
- return NULL;
+ /* read ok! */
+ gzclose(gzfile);
+
+ return img;
+ }
}
/* add a fake passepartout overlay to a byte buffer, use for blend file thumbnails */
Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2010-07-14 20:26:46 UTC (rev 30345)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2010-07-14 20:31:11 UTC (rev 30346)
@@ -2611,7 +2611,7 @@
ViewContext vc;
- int hit = 0;
+ // int hit = 0;
int flip;
int sign;
@@ -2779,7 +2779,7 @@
int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
- wmWindow *win = CTX_wm_window(C);
+ // wmWindow *win = CTX_wm_window(C);
int mode = RNA_int_get(op->ptr, "mode");
float initial_value = RNA_float_get(op->ptr, "initial_value");
//float initial_size = RNA_float_get(op->ptr, "initial_size");
More information about the Bf-blender-cvs
mailing list