Blender  V3.3
thumbs_font.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_fileops.h"
8 #include "BLI_hash_md5.h"
9 #include "BLI_string.h"
10 #include "BLI_utildefines.h"
11 
12 #include "IMB_imbuf.h"
13 #include "IMB_imbuf_types.h"
14 
15 #include "IMB_thumbs.h"
16 
17 /* XXX, bad level call */
18 #include "../../blenfont/BLF_api.h"
19 #include "../../blentranslation/BLT_translation.h"
20 
21 #define THUMB_TXT_ITEMS \
22  N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"),
23 
24 static const char *thumb_str[] = {THUMB_TXT_ITEMS};
25 
26 static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS};
27 
28 #undef THUMB_TXT_ITEMS
29 
31 {
32  for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
33  i18n_thumb_str[i] = NULL;
34  }
35 }
36 
38 {
39  for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
41  }
42 }
43 
44 struct ImBuf *IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y)
45 {
46  const int font_size = y / 4;
47 
48  struct ImBuf *ibuf;
49  float font_color[4];
50 
51  /* create a white image (theme color is used for drawing) */
52  font_color[0] = font_color[1] = font_color[2] = 1.0f;
53 
54  /* fill with zero alpha */
55  font_color[3] = 0.0f;
56 
57  ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
58  IMB_rectfill(ibuf, font_color);
59 
60  /* draw with full alpha */
61  font_color[3] = 1.0f;
62 
63  BLF_thumb_preview(filepath,
64  thumb_str,
67  font_color,
68  font_size,
69  (unsigned char *)ibuf->rect,
70  ibuf->x,
71  ibuf->y,
72  ibuf->channels);
73 
74  return ibuf;
75 }
76 
77 bool IMB_thumb_load_font_get_hash(char *r_hash)
78 {
79  char buf[1024];
80  char *str = buf;
81  size_t len = 0;
82 
83  int draw_str_lines = ARRAY_SIZE(thumb_str);
84  int i;
85 
86  unsigned char digest[16];
87 
88  len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len);
89 
90  for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) {
93  sizeof(buf) - len);
94  }
95 
96  BLI_hash_md5_buffer(str, len, digest);
97  r_hash[0] = '\0';
98  BLI_hash_md5_to_hexdigest(digest, r_hash);
99 
100  return true;
101 }
void BLF_thumb_preview(const char *filepath, const char **draw_str, const char **i18n_draw_str, unsigned char draw_str_lines, const float font_color[4], int font_size, unsigned char *buf, int w, int h, int channels) ATTR_NONNULL()
Definition: blf_thumbs.c:32
File and directory operations.
void * BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock)
Definition: hash_md5.c:345
char * BLI_hash_md5_to_hexdigest(void *resblock, char r_hex_digest[33])
Definition: hash_md5.c:381
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:120
#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:500
void IMB_rectfill(struct ImBuf *drect, const float col[4])
Definition: rectop.c:1050
Contains defines and structs used throughout the imbuf module.
@ IB_metadata
@ IB_rect
#define THUMB_DEFAULT_HASH
Definition: IMB_thumbs.h:48
int len
Definition: draw_manager.c:108
#define str(s)
int channels
unsigned int * rect
static const char * i18n_thumb_str[]
Definition: thumbs_font.c:26
bool IMB_thumb_load_font_get_hash(char *r_hash)
Definition: thumbs_font.c:77
static const char * thumb_str[]
Definition: thumbs_font.c:24
struct ImBuf * IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y)
Definition: thumbs_font.c:44
void IMB_thumb_clear_translations(void)
Definition: thumbs_font.c:30
#define THUMB_TXT_ITEMS
Definition: thumbs_font.c:21
void IMB_thumb_ensure_translations(void)
Definition: thumbs_font.c:37