diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-04-08 03:10:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-04-08 03:38:19 +0300 |
commit | 8c539b0ab521d442d88c70243c04cbb9e40fe412 (patch) | |
tree | 58b1ffb19b1117404698a6705a87406722400b01 /source/blender/imbuf | |
parent | c56c493cf403b63ec46b90023cdc8137275a310f (diff) |
Font preview for file browser
D1002 by @plasmasolutions, with own refactoring.
Note, needed to do a bad-level call here (IMB -> BLF)
Also can't use the BLF API directly because its not thread-safe.
So keep the function isolated (blf_thumbs.c).
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_thumbs.h | 8 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 19 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs_font.c | 73 |
4 files changed, 94 insertions, 7 deletions
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index eadedbd5e00..bdd8230a6ff 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -66,6 +66,7 @@ set(SRC intern/targa.c intern/thumbs.c intern/thumbs_blend.c + intern/thumbs_font.c intern/util.c intern/writeimage.c diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h index bea531c1442..404052f2e8e 100644 --- a/source/blender/imbuf/IMB_thumbs.h +++ b/source/blender/imbuf/IMB_thumbs.h @@ -54,7 +54,8 @@ typedef enum ThumbSize { typedef enum ThumbSource { THB_SOURCE_IMAGE, THB_SOURCE_MOVIE, - THB_SOURCE_BLEND + THB_SOURCE_BLEND, + THB_SOURCE_FONT, } ThumbSource; /* don't generate thumbs for images bigger then this (100mb) */ @@ -79,6 +80,11 @@ void IMB_thumb_makedirs(void); ImBuf *IMB_thumb_load_blend(const char *path); void IMB_thumb_overlay_blend(unsigned int *thumb, int width, int height, float aspect); +/* special function for previewing fonts */ +ImBuf *IMB_thumb_load_font( + const char *filename, + unsigned int x, unsigned int y); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index e88cbef206a..78f47b7bc34 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -330,15 +330,22 @@ ImBuf *IMB_thumb_create(const char *path, ThumbSize size, ThumbSource source, Im if (!img) return NULL; } else { - if (THB_SOURCE_IMAGE == source || THB_SOURCE_BLEND == source) { + if (ELEM(source, THB_SOURCE_IMAGE, THB_SOURCE_BLEND, THB_SOURCE_FONT)) { /* only load if we didnt give an image */ if (img == NULL) { - if (THB_SOURCE_BLEND == source) { - img = IMB_thumb_load_blend(path); - } - else { - img = IMB_loadiffname(path, IB_rect | IB_metadata | IB_thumbnail, NULL); + switch (source) { + case THB_SOURCE_IMAGE: + img = IMB_loadiffname(path, IB_rect | IB_metadata, NULL); + break; + case THB_SOURCE_BLEND: + img = IMB_thumb_load_blend(path); + break; + case THB_SOURCE_FONT: + img = IMB_thumb_load_font(path, tsize, tsize); + break; + default: + BLI_assert(0); /* This should never happen */ } } diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c new file mode 100644 index 00000000000..c8982318d80 --- /dev/null +++ b/source/blender/imbuf/intern/thumbs_font.c @@ -0,0 +1,73 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Thomas Beck. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/imbuf/intern/thumbs_font.c + * \ingroup imbuf + */ + +#include "BLI_utildefines.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#include "IMB_thumbs.h" + + +/* XXX, bad level call */ +#include "../../blenfont/BLF_api.h" + + +struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y) +{ + const int font_size = y / 4; + const char *thumb_str[] = { + "AaBbCc", + + "The quick", + "brown fox", + "jumps over", + "the lazy dog", + }; + + struct ImBuf *ibuf; + float font_color[4]; + + /* create a white image (theme color is used for drawing) */ + font_color[0] = font_color[1] = font_color[2] = 1.0f; + + /* fill with zero alpha */ + font_color[3] = 0.0f; + + ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata); + IMB_rectfill(ibuf, font_color); + + /* draw with full alpha */ + font_color[3] = 1.0f; + + BLF_thumb_preview( + filename, thumb_str, ARRAY_SIZE(thumb_str), + font_color, font_size, + (unsigned char *)ibuf->rect, ibuf->x, ibuf->y, ibuf->channels); + + return ibuf; +} + |