Blender  V2.93
thumbs_font.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_fileops.h"
22 #include "BLI_hash_md5.h"
23 #include "BLI_string.h"
24 #include "BLI_utildefines.h"
25 
26 #include "IMB_imbuf.h"
27 #include "IMB_imbuf_types.h"
28 
29 #include "IMB_thumbs.h"
30 
31 /* XXX, bad level call */
32 #include "../../blenfont/BLF_api.h"
33 #include "../../blentranslation/BLT_translation.h"
34 
35 #define THUMB_TXT_ITEMS \
36  N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"),
37 
38 static const char *thumb_str[] = {THUMB_TXT_ITEMS};
39 
40 static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS};
41 
42 #undef THUMB_TXT_ITEMS
43 
45 {
46  for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
47  i18n_thumb_str[i] = NULL;
48  }
49 }
50 
52 {
53  for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
55  }
56 }
57 
58 struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y)
59 {
60  const int font_size = y / 4;
61 
62  struct ImBuf *ibuf;
63  float font_color[4];
64 
65  /* create a white image (theme color is used for drawing) */
66  font_color[0] = font_color[1] = font_color[2] = 1.0f;
67 
68  /* fill with zero alpha */
69  font_color[3] = 0.0f;
70 
71  ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
72  IMB_rectfill(ibuf, font_color);
73 
74  /* draw with full alpha */
75  font_color[3] = 1.0f;
76 
77  BLF_thumb_preview(filename,
78  thumb_str,
81  font_color,
82  font_size,
83  (unsigned char *)ibuf->rect,
84  ibuf->x,
85  ibuf->y,
86  ibuf->channels);
87 
88  return ibuf;
89 }
90 
91 bool IMB_thumb_load_font_get_hash(char *r_hash)
92 {
93  char buf[1024];
94  char *str = buf;
95  size_t len = 0;
96 
97  int draw_str_lines = ARRAY_SIZE(thumb_str);
98  int i;
99 
100  unsigned char digest[16];
101 
102  len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len);
103 
104  for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) {
107  sizeof(buf) - len);
108  }
109 
110  BLI_hash_md5_buffer(str, len, digest);
111  r_hash[0] = '\0';
112  BLI_hash_md5_to_hexdigest(digest, r_hash);
113 
114  return true;
115 }
void BLF_thumb_preview(const char *filename, const char **draw_str, const char **i18n_draw_str, const unsigned char draw_str_lines, const float font_color[4], const int font_size, unsigned char *buf, int w, int h, int channels) ATTR_NONNULL()
Definition: blf_thumbs.c:51
File and directory operations.
void * BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock)
Definition: hash_md5.c:370
char * BLI_hash_md5_to_hexdigest(void *resblock, char r_hex_digest[33])
Definition: hash_md5.c:406
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:187
#define ARRAY_SIZE(arr)
const char * BLT_translate_do(const char *msgctxt, const char *msgid)
#define BLT_I18NCONTEXT_DEFAULT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Definition: allocimbuf.c:478
void IMB_rectfill(struct ImBuf *drect, const float col[4])
Definition: rectop.c:1077
Contains defines and structs used throughout the imbuf module.
@ IB_metadata
@ IB_rect
#define THUMB_DEFAULT_HASH
Definition: IMB_thumbs.h:59
#define str(s)
int channels
unsigned int * rect
static const char * i18n_thumb_str[]
Definition: thumbs_font.c:40
struct ImBuf * IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y)
Definition: thumbs_font.c:58
bool IMB_thumb_load_font_get_hash(char *r_hash)
Definition: thumbs_font.c:91
static const char * thumb_str[]
Definition: thumbs_font.c:38
void IMB_thumb_clear_translations(void)
Definition: thumbs_font.c:44
#define THUMB_TXT_ITEMS
Definition: thumbs_font.c:35
void IMB_thumb_ensure_translations(void)
Definition: thumbs_font.c:51
uint len