diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-05-30 23:21:28 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-05-30 23:21:28 +0400 |
commit | 177cffc1710f8e5d4660ee29271a89865d56cfbe (patch) | |
tree | 0826ef5c238926c228ccc0d08f0b416c4829545b /source/blender/imbuf | |
parent | 8ad29c02e097038cca352e9a430da293e20da6fd (diff) |
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
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_thumbs.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs_blend.c | 56 |
3 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h index ecb0ba8abd1..68aa3c64299 100644 --- a/source/blender/imbuf/IMB_thumbs.h +++ b/source/blender/imbuf/IMB_thumbs.h @@ -73,6 +73,8 @@ void IMB_thumb_makedirs(); /* 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 */ diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 8c75f5ab1ab..1cdeb602f0f 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -348,6 +348,8 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im #ifndef WIN32 chmod(temp, S_IRUSR | S_IWUSR); #endif + printf("Saving: %s\n", tpath); + BLI_rename(temp, tpath); } diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 6e7bd4e6ca7..9df27f6f969 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -127,3 +127,59 @@ thumb_error: 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; + } + } + } + } +} |