[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29086] trunk/blender/source/blender: blend file thumbnails
Campbell Barton
ideasman42 at gmail.com
Sun May 30 21:21:28 CEST 2010
Revision: 29086
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29086
Author: campbellbarton
Date: 2010-05-30 21:21:28 +0200 (Sun, 30 May 2010)
Log Message:
-----------
blend file thumbnails
- fix for blend file thumbnails not being immediately visible in an external file manager (was writing the thumb before the blend)
- move overlay function from wm_files.c into thumbs_blend.c
Modified Paths:
--------------
trunk/blender/source/blender/imbuf/IMB_thumbs.h
trunk/blender/source/blender/imbuf/intern/thumbs.c
trunk/blender/source/blender/imbuf/intern/thumbs_blend.c
trunk/blender/source/blender/windowmanager/intern/wm_files.c
Modified: trunk/blender/source/blender/imbuf/IMB_thumbs.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_thumbs.h 2010-05-30 18:18:14 UTC (rev 29085)
+++ trunk/blender/source/blender/imbuf/IMB_thumbs.h 2010-05-30 19:21:28 UTC (rev 29086)
@@ -73,6 +73,8 @@
/* special function for loading a thumbnail embedded into a blend file */
ImBuf *IMB_loadblend_thumb(const char *path);
+void IMB_overlayblend_thumb(int *thumb, int width, int height, float aspect);
+
#endif /* _IMB_THUMBS_H */
Modified: trunk/blender/source/blender/imbuf/intern/thumbs.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/thumbs.c 2010-05-30 18:18:14 UTC (rev 29085)
+++ trunk/blender/source/blender/imbuf/intern/thumbs.c 2010-05-30 19:21:28 UTC (rev 29086)
@@ -348,6 +348,8 @@
#ifndef WIN32
chmod(temp, S_IRUSR | S_IWUSR);
#endif
+ printf("Saving: %s\n", tpath);
+
BLI_rename(temp, tpath);
}
Modified: trunk/blender/source/blender/imbuf/intern/thumbs_blend.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/thumbs_blend.c 2010-05-30 18:18:14 UTC (rev 29085)
+++ trunk/blender/source/blender/imbuf/intern/thumbs_blend.c 2010-05-30 19:21:28 UTC (rev 29086)
@@ -127,3 +127,59 @@
if(rect) MEM_freeN(rect);
return NULL;
}
+
+/* add a fake passepartout overlay to a byte buffer, use for blend file thumbnails */
+#define MARGIN 2
+
+void IMB_overlayblend_thumb(int *thumb, int width, int height, float aspect)
+{
+ unsigned char *px= (unsigned char *)thumb;
+ int margin_l = MARGIN;
+ int margin_b = MARGIN;
+ int margin_r = width - MARGIN;
+ int margin_t = height - MARGIN;
+
+ if(aspect < 1.0f) {
+ margin_l= (int)((width - ((float)width * aspect)) / 2.0f);
+ margin_l += MARGIN;
+ CLAMP(margin_l, MARGIN, (width/2));
+ margin_r = width - margin_l;
+ }
+ else if (aspect > 1.0f) {
+ margin_b= (int)((height - ((float)height / aspect)) / 2.0f);
+ margin_b += MARGIN;
+ CLAMP(margin_b, MARGIN, (height/2));
+ margin_t = height - margin_b;
+ }
+
+ {
+ int x, y;
+ int hline, vline;
+ int stride_x= (margin_r - margin_l) - 2;
+
+ for(y=0; y < height; y++) {
+ for(x=0; x < width; x++, px+=4) {
+ if((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) {
+ /* interior. skip */
+ x += stride_x;
+ px += stride_x * 4;
+ } else if( (hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) ||
+ (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r))
+ ) {
+ /* dashed line */
+ if((hline && y % 2) || (vline && x % 2)) {
+ px[0]= px[1]= px[2]= 0;
+ px[3] = 255;
+ }
+ }
+ else {
+ /* outside, fill in alpha, like passepartout */
+ px[0] *= 0.5f;
+ px[1] *= 0.5f;
+ px[2] *= 0.5f;
+ px[3] = (px[3] * 0.5f) + 96;
+ }
+ }
+ }
+ }
+}
Modified: trunk/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_files.c 2010-05-30 18:18:14 UTC (rev 29085)
+++ trunk/blender/source/blender/windowmanager/intern/wm_files.c 2010-05-30 19:21:28 UTC (rev 29086)
@@ -491,67 +491,8 @@
BKE_report(reports, RPT_ERROR, "Unable to make version backup");
}
-/* writes a thumbnail for a blendfile */
-static void writeThumb_overlay(int *thumb, int width, int height, float aspect)
+static ImBuf *blend_file_thumb(const char *path, Scene *scene, int **thumb_pt)
{
- unsigned char *px= (unsigned char *)thumb;
- int margin_l = 3;
- int margin_b = 3;
- int margin_r = width - 3;
- int margin_t = height - 3;
-
- printf("%f\n", aspect);
-
- if(aspect < 1.0f) {
- margin_l= (int)((width - ((float)width * aspect)) / 2.0f);
- margin_l += 2;
- CLAMP(margin_l, 2, (width/2));
- margin_r = width - margin_l;
- }
- else if (aspect > 1.0f) {
- margin_b= (int)((height - ((float)height / aspect)) / 2.0f);
- margin_b += 2;
- CLAMP(margin_b, 2, (height/2));
- margin_t = height - margin_b;
- }
-
- {
- int x, y;
- int hline, vline;
- float alpha;
- int stride_x= (margin_r - margin_l) - 2;
-
- for(y=0; y < height; y++) {
- float fac= (float)y / (float)height;
- alpha= (0.2f * fac) + (1.0f * (1.0f - fac));
- for(x=0; x < width; x++, px+=4) {
- if((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) {
- /* interior. skip */
- x += stride_x;
- px += stride_x * 4;
- } else if( (hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) ||
- (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r))
- ) {
- /* dashed line */
- if((hline && y % 2) || (vline && x % 2)) {
- px[0]= px[1]= px[2]= 0;
- px[3] = 255;
- }
- }
- else {
- /* outside, fill in alpha, like passepartout */
- px[0] *= 0.5f;
- px[1] *= 0.5f;
- px[2] *= 0.5f;
- px[3] = (px[3] * 0.5f) + (128 * alpha);
- }
- }
- }
- }
-}
-
-static void writeThumb(const char *path, Scene *scene, int **thumb_pt)
-{
/* will be scaled down, but gives some nice oversampling */
ImBuf *ibuf;
int *thumb;
@@ -559,7 +500,7 @@
*thumb_pt= NULL;
if(G.background || scene->camera==NULL)
- return;
+ return NULL;
/* gets scaled to BLEN_THUMB_SIZE */
ibuf= ED_view3d_draw_offscreen_imbuf_simple(scene, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, OB_SOLID);
@@ -577,15 +518,9 @@
thumb[1] = BLEN_THUMB_SIZE;
memcpy(thumb + 2, ibuf->rect, BLEN_THUMB_SIZE * BLEN_THUMB_SIZE * sizeof(int));
- writeThumb_overlay(thumb + 2, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE, aspect);
- /* the image is scaled here */
- ibuf= IMB_thumb_create(path, THB_NORMAL, THB_SOURCE_BLEND, ibuf);
-
- if (ibuf)
- IMB_freeImBuf(ibuf);
-
- ibuf= NULL;
+ /* add pretty overlay */
+ IMB_overlayblend_thumb(thumb + 2, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE, aspect);
}
else {
/* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */
@@ -594,6 +529,8 @@
/* must be freed by caller */
*thumb_pt= thumb;
+
+ return ibuf;
}
int WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports)
@@ -603,6 +540,7 @@
char di[FILE_MAX];
int *thumb= NULL;
+ ImBuf *ibuf_thumb= NULL;
len = strlen(target);
@@ -645,7 +583,7 @@
do_history(di, reports);
/* blend file thumbnail */
- writeThumb(di, CTX_data_scene(C), &thumb);
+ ibuf_thumb= blend_file_thumb(di, CTX_data_scene(C), &thumb);
if (BLO_write_file(CTX_data_main(C), di, fileflags, reports, thumb)) {
strcpy(G.sce, di);
@@ -662,9 +600,16 @@
writeBlog();
+ /* run this function after because the file cant be written before the blend is */
+ if (ibuf_thumb) {
+ ibuf_thumb= IMB_thumb_create(di, THB_NORMAL, THB_SOURCE_BLEND, ibuf_thumb);
+ IMB_freeImBuf(ibuf_thumb);
+ }
+
if(thumb) MEM_freeN(thumb);
}
else {
+ if(ibuf_thumb) IMB_freeImBuf(ibuf_thumb);
if(thumb) MEM_freeN(thumb);
return -1;
}
More information about the Bf-blender-cvs
mailing list