[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29074] trunk/blender/source/blender/ windowmanager/intern/wm_files.c: thumbnail passepartout effect, distinguishes blend files from images.
Campbell Barton
ideasman42 at gmail.com
Sun May 30 11:16:51 CEST 2010
Revision: 29074
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29074
Author: campbellbarton
Date: 2010-05-30 11:16:50 +0200 (Sun, 30 May 2010)
Log Message:
-----------
thumbnail passepartout effect, distinguishes blend files from images.
Modified Paths:
--------------
trunk/blender/source/blender/windowmanager/intern/wm_files.c
Modified: trunk/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_files.c 2010-05-30 01:48:03 UTC (rev 29073)
+++ trunk/blender/source/blender/windowmanager/intern/wm_files.c 2010-05-30 09:16:50 UTC (rev 29074)
@@ -492,6 +492,64 @@
}
/* writes a thumbnail for a blendfile */
+static void writeThumb_overlay(int *thumb, int width, int height, float aspect)
+{
+ 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 */
@@ -507,7 +565,8 @@
ibuf= ED_view3d_draw_offscreen_imbuf_simple(scene, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, OB_SOLID);
if(ibuf) {
-
+ float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
+
/* dirty oversampling */
IMB_scaleImBuf(ibuf, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE);
@@ -518,6 +577,7 @@
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);
More information about the Bf-blender-cvs
mailing list