Blender V5.3
effect_text.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10
11#include "BKE_lib_id.hh"
12#include "BKE_library.hh"
13#include "BKE_main.hh"
14
15#include "BLI_map.hh"
16#include "BLI_math_base.hh"
18#include "BLI_math_vector.hh"
19#include "BLI_math_vector_c.hh"
20#include "BLI_path_utils.hh"
21#include "BLI_rect.hh"
22#include "BLI_string.hh"
23#include "BLI_string_utf8.hh"
24#include "BLI_task.hh"
25#include "BLI_vector.hh"
26
27#include "BLF_api.hh"
28
30#include "DNA_scene_types.h"
31#include "DNA_sequence_types.h"
32#include "DNA_space_types.h"
33#include "DNA_vfont_types.h"
34
36#include "IMB_imbuf_types.hh"
37
38#include "PRF_profile.hh"
39
40#include "SEQ_effects.hh"
41#include "SEQ_proxy.hh"
42#include "SEQ_render.hh"
43#include "SEQ_utils.hh"
44
45#include "effects.hh"
46
47namespace blender::seq {
48
49static std::recursive_mutex text_runtime_mutex;
50
51std::recursive_mutex &text_runtime_mutex_get()
52{
53 return text_runtime_mutex;
54}
55
56/* -------------------------------------------------------------------- */
57/* Sequencer font access.
58 *
59 * Text strips can access and use fonts from a background thread
60 * (when depsgraph evaluation copies the scene, or when prefetch renders
61 * frames with text strips in a background thread).
62 *
63 * To not interfere with what might be happening on the main thread, all
64 * fonts used by the sequencer are made unique via #BLF_load_unique
65 * #BLF_load_mem_unique, and there's a mutex to guard against
66 * sequencer itself possibly using the fonts from several threads.
67 */
68
69struct SeqFontMap {
70 /* File path -> font ID mapping for file-based fonts. */
72 /* Datablock name -> font ID mapping for memory (datablock) fonts. */
74
75 /* Font access mutex. Recursive since it is locked from
76 * text strip rendering, which can call into loading from within. */
77 std::recursive_mutex mutex;
78};
79
81static int g_fallback_font_id = -1;
82
84{
85 std::lock_guard lock(g_font_map.mutex);
86 for (const auto &item : g_font_map.path_to_file_font_id.items()) {
87 BLF_unload_id(item.value);
88 }
90 for (const auto &item : g_font_map.name_to_mem_font_id.items()) {
91 BLF_unload_id(item.value);
92 }
94
95 if (g_fallback_font_id >= 0) {
98 }
99}
100
101static int strip_load_font_file(const std::string &path)
102{
103 std::lock_guard lock(g_font_map.mutex);
105 path,
106 [&](int *fontid) {
107 /* New path: load font. */
108 *fontid = BLF_load_unique(path.c_str());
109 return *fontid;
110 },
111 [&](int *fontid) {
112 /* Path already in cache: add reference to already loaded font,
113 * or load a new one in case that
114 * font id was unloaded behind our backs. */
115 if (*fontid >= 0) {
116 if (BLF_is_loaded_id(*fontid)) {
117 BLF_addref_id(*fontid);
118 }
119 else {
120 *fontid = BLF_load_unique(path.c_str());
121 }
122 }
123 return *fontid;
124 });
125 return fontid;
126}
127
128static int strip_load_font_mem(const std::string &name, const uchar *data, int data_size)
129{
130 std::lock_guard lock(g_font_map.mutex);
132 name,
133 [&](int *fontid) {
134 /* New name: load font. */
135 *fontid = BLF_load_mem_unique(name.c_str(), data, data_size);
136 return *fontid;
137 },
138 [&](int *fontid) {
139 /* Name already in cache: add reference to already loaded font,
140 * or (if we're on the main thread) load a new one in case that
141 * font id was unloaded behind our backs. */
142 if (*fontid >= 0) {
143 if (BLF_is_loaded_id(*fontid)) {
144 BLF_addref_id(*fontid);
145 }
146 else {
147 *fontid = BLF_load_mem_unique(name.c_str(), data, data_size);
148 }
149 }
150 return *fontid;
151 });
152 return fontid;
153}
154
155static void strip_unload_font(int fontid)
156{
157 std::lock_guard lock(g_font_map.mutex);
158 bool unloaded = BLF_unload_id(fontid);
159 /* If that was the last usage of the font and it got unloaded: remove
160 * it from our maps. */
161 if (unloaded) {
162 g_font_map.path_to_file_font_id.remove_if([&](auto item) { return item.value == fontid; });
163 g_font_map.name_to_mem_font_id.remove_if([&](auto item) { return item.value == fontid; });
164 }
165}
166
167/* -------------------------------------------------------------------- */
170
172{
173 /* `data->text[0] == 0` is ignored on purpose in order to make it possible to edit. */
174
175 TextVars *data = static_cast<TextVars *>(strip->effectdata);
176 if (data->text_size < 1.0f ||
177 ((data->color[3] == 0.0f) &&
178 (data->shadow_color[3] == 0.0f || (data->flag & SEQ_TEXT_SHADOW) == 0) &&
179 (data->outline_color[3] == 0.0f || data->outline_width <= 0.0f ||
180 (data->flag & SEQ_TEXT_OUTLINE) == 0)))
181 {
182 return false;
183 }
184 return true;
185}
186
187static void init_text_effect(Strip *strip)
188{
189 TextVars *data = MEM_new<TextVars>("textvars");
190 strip->effectdata = data;
191
192 data->text_font = nullptr;
193 data->text_blf_id = -1;
194 data->text_size = 60.0f;
195 data->space_line = 1.0f;
196 data->abs_space_line = 60.0f; /* Keep in sync with `data->text_size` at init. */
197
198 copy_v4_fl(data->color, 1.0f);
199 data->shadow_color[3] = 0.7f;
200 data->shadow_angle = DEG2RADF(65.0f);
201 data->shadow_offset = 0.04f;
202 data->shadow_blur = 0.0f;
203 data->box_color[0] = 0.2f;
204 data->box_color[1] = 0.2f;
205 data->box_color[2] = 0.2f;
206 data->box_color[3] = 0.7f;
207 data->box_margin = 0.01f;
208 data->box_roundness = 0.0f;
209 data->outline_color[3] = 0.7f;
210 data->outline_width = 0.05f;
211
212 data->text_ptr = BLI_strdup("Text");
213 data->text_len_bytes = strlen(data->text_ptr);
214 data->cursor_offset = data->text_len_bytes;
215
216 data->loc[0] = 0.5f;
217 data->loc[1] = 0.5f;
218 data->anchor_x = SEQ_TEXT_ANCHOR_X_CENTER;
219 data->anchor_y = SEQ_TEXT_ANCHOR_Y_CENTER;
221 data->wrap_width = 1.0f;
222}
223
224static void text_font_unload(TextVars *data, const bool do_id_user)
225{
226 if (data == nullptr) {
227 return;
228 }
229
230 /* Unlink the VFont */
231 if (do_id_user && data->text_font != nullptr) {
232 id_us_min(&data->text_font->id);
233 data->text_font = nullptr;
234 }
235
236 /* Unload the font. */
237 if (data->text_blf_id >= 0) {
238 strip_unload_font(data->text_blf_id);
239 data->text_blf_id = -1;
240 }
241}
242
244{
245 if (strip == nullptr || strip->type != STRIP_TYPE_TEXT) {
246 return;
247 }
248 TextVars *data = static_cast<TextVars *>(strip->effectdata);
249 text_font_unload(data, true);
250
251 id_us_plus(&font->id);
252 data->text_blf_id = STRIP_FONT_NOT_LOADED;
253 data->text_font = font;
254}
255
256static void text_font_load(TextVars *data, const bool do_id_user)
257{
258 VFont *vfont = data->text_font;
259 if (vfont == nullptr) {
260 return;
261 }
262
263 if (do_id_user) {
264 id_us_plus(&vfont->id);
265 }
266
267 if (vfont->packedfile != nullptr) {
268 PackedFile *pf = vfont->packedfile;
269 /* Create a name that's unique between library data-blocks to avoid loading
270 * a font per strip which will load fonts many times.
271 *
272 * WARNING: this isn't fool proof!
273 * The #VFont may be renamed which will cause this to load multiple times,
274 * in practice this isn't so likely though. */
275 char name[MAX_ID_FULL_NAME];
276 BKE_id_full_name_get(name, &vfont->id, 0);
277
278 data->text_blf_id = strip_load_font_mem(name, static_cast<const uchar *>(pf->data), pf->size);
279 }
280 else {
281 char filepath[FILE_MAX];
282 STRNCPY(filepath, vfont->filepath);
283
284 BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id));
285 data->text_blf_id = strip_load_font_file(filepath);
286 }
287}
288
289static void free_text_effect(Strip *strip, const bool do_id_user)
290{
291 TextVars *data = static_cast<TextVars *>(strip->effectdata);
292 text_font_unload(data, do_id_user);
293
294 if (data) {
295 MEM_SAFE_DELETE(data->text_ptr);
296 MEM_delete(data->runtime);
297 MEM_delete(data);
298 strip->effectdata = nullptr;
299 }
300}
301
302static void copy_text_effect(Strip *dst, const Strip *src, const int flag)
303{
304 TextVars *data = MEM_dupalloc(static_cast<TextVars *>(src->effectdata));
305 data->text_ptr = BLI_strdup_null(data->text_ptr);
306
307 data->runtime = nullptr;
308 data->text_blf_id = -1;
310
311 dst->effectdata = data;
312}
313
314static StripEarlyOut early_out_text(const Strip *strip, float /*fac*/)
315{
316 if (!effects_can_render_text(strip)) {
318 }
320}
321
322/* Simplified version of gaussian blur specifically for text shadow blurring:
323 * - Data is only the alpha channel,
324 * - Skips blur outside of shadow rectangle. */
325static void text_gaussian_blur_x(const Span<float> gaussian,
326 int half_size,
327 int start_line,
328 int width,
329 int height,
330 const uchar *rect,
331 uchar *dst,
332 const rcti &shadow_rect)
333{
334 dst += int64_t(start_line) * width;
335 for (int y = start_line; y < start_line + height; y++) {
336 for (int x = 0; x < width; x++) {
337 float accum(0.0f);
338 if (x >= shadow_rect.xmin && x <= shadow_rect.xmax) {
339 float accum_weight = 0.0f;
340 int xmin = math::max(x - half_size, shadow_rect.xmin);
341 int xmax = math::min(x + half_size, shadow_rect.xmax);
342 for (int nx = xmin, index = (xmin - x) + half_size; nx <= xmax; nx++, index++) {
343 float weight = gaussian[index];
344 int offset = y * width + nx;
345 accum += rect[offset] * weight;
346 accum_weight += weight;
347 }
348 accum *= (1.0f / accum_weight);
349 }
350
351 *dst = accum;
352 dst++;
353 }
354 }
355}
356
357static void text_gaussian_blur_y(const Span<float> gaussian,
358 int half_size,
359 int start_line,
360 int width,
361 int height,
362 const uchar *rect,
363 uchar *dst,
364 const rcti &shadow_rect)
365{
366 dst += int64_t(start_line) * width;
367 for (int y = start_line; y < start_line + height; y++) {
368 for (int x = 0; x < width; x++) {
369 float accum(0.0f);
370 if (x >= shadow_rect.xmin && x <= shadow_rect.xmax) {
371 float accum_weight = 0.0f;
372 int ymin = math::max(y - half_size, shadow_rect.ymin);
373 int ymax = math::min(y + half_size, shadow_rect.ymax);
374 for (int ny = ymin, index = (ymin - y) + half_size; ny <= ymax; ny++, index++) {
375 float weight = gaussian[index];
376 int offset = ny * width + x;
377 accum += rect[offset] * weight;
378 accum_weight += weight;
379 }
380 accum *= (1.0f / accum_weight);
381 }
382 *dst = accum;
383 dst++;
384 }
385 }
386}
387
388static void clamp_rect(int width, int height, rcti &r_rect)
389{
390 r_rect.xmin = math::clamp(r_rect.xmin, 0, width - 1);
391 r_rect.xmax = math::clamp(r_rect.xmax, 0, width - 1);
392 r_rect.ymin = math::clamp(r_rect.ymin, 0, height - 1);
393 r_rect.ymax = math::clamp(r_rect.ymax, 0, height - 1);
394}
395
396static void initialize_shadow_alpha(int width,
397 int height,
398 int2 offset,
399 const rcti &shadow_rect,
400 const uchar *input,
401 Array<uchar> &r_shadow_mask)
402{
403 const IndexRange shadow_y_range(shadow_rect.ymin, shadow_rect.ymax - shadow_rect.ymin + 1);
404 threading::parallel_for(shadow_y_range, 8, [&](const IndexRange y_range) {
405 for (const int64_t y : y_range) {
406 const int64_t src_y = math::clamp<int64_t>(y + offset.y, 0, height - 1);
407 for (int x = shadow_rect.xmin; x <= shadow_rect.xmax; x++) {
408 int src_x = math::clamp(x - offset.x, 0, width - 1);
409 size_t src_offset = width * src_y + src_x;
410 size_t dst_offset = width * y + x;
411 r_shadow_mask[dst_offset] = input[src_offset * 4 + 3];
412 }
413 }
414 });
415}
416
417static void composite_shadow(int width,
418 const rcti &shadow_rect,
419 const float4 &shadow_color,
420 const Array<uchar> &shadow_mask,
421 uchar *output)
422{
423 const IndexRange shadow_y_range(shadow_rect.ymin, shadow_rect.ymax - shadow_rect.ymin + 1);
424 threading::parallel_for(shadow_y_range, 8, [&](const IndexRange y_range) {
425 for (const int64_t y : y_range) {
426 size_t offset = y * width + shadow_rect.xmin;
427 uchar *dst = output + offset * 4;
428 for (int x = shadow_rect.xmin; x <= shadow_rect.xmax; x++, offset++, dst += 4) {
429 uchar a = shadow_mask[offset];
430 if (a == 0) {
431 /* Fully transparent, leave output pixel as is. */
432 continue;
433 }
434 float4 col1 = load_premul_pixel(dst);
435 float4 col2 = shadow_color * (a * (1.0f / 255.0f));
436 /* Blend under the output. */
437 float fac = 1.0f - col1.w;
438 float4 col = col1 + fac * col2;
439 store_premul_pixel(col, dst);
440 }
441 }
442 });
443}
444
446 const RenderData *context, const TextVars *data, int line_height, const rcti &rect, ImBuf *out)
447{
448 const int width = context->rectx;
449 const int height = context->recty;
450 /* Blur value of 1.0 applies blur kernel that is half of text line height. */
451 const float blur_amount = line_height * 0.5f * data->shadow_blur;
452 bool do_blur = blur_amount >= 1.0f;
453
454 Array<uchar> shadow_mask(size_t(width) * height, 0);
455
456 const int2 offset = int2(cosf(data->shadow_angle) * line_height * data->shadow_offset,
457 sinf(data->shadow_angle) * line_height * data->shadow_offset);
458
459 rcti shadow_rect = rect;
460 BLI_rcti_translate(&shadow_rect, offset.x, -offset.y);
461 BLI_rcti_pad(&shadow_rect, 1, 1);
462 clamp_rect(width, height, shadow_rect);
463
464 /* Initialize shadow by copying existing text/outline alpha. */
465 initialize_shadow_alpha(width, height, offset, shadow_rect, out->byte_data(), shadow_mask);
466
467 if (do_blur) {
468 /* Create blur kernel weights. */
469 const int half_size = int(blur_amount + 0.5f);
470 Array<float> gaussian = make_gaussian_blur_kernel(blur_amount, half_size);
471
472 BLI_rcti_pad(&shadow_rect, half_size + 1, half_size + 1);
473 clamp_rect(width, height, shadow_rect);
474
475 /* Horizontal blur: blur shadow_mask into blur_buffer. */
476 Array<uchar> blur_buffer(size_t(width) * height, NoInitialization());
477 IndexRange blur_y_range(shadow_rect.ymin, shadow_rect.ymax - shadow_rect.ymin + 1);
478 threading::parallel_for(blur_y_range, 8, [&](const IndexRange y_range) {
479 const int y_first = y_range.first();
480 const int y_size = y_range.size();
481 text_gaussian_blur_x(gaussian,
482 half_size,
483 y_first,
484 width,
485 y_size,
486 shadow_mask.data(),
487 blur_buffer.data(),
488 shadow_rect);
489 });
490
491 /* Vertical blur: blur blur_buffer into shadow_mask. */
492 threading::parallel_for(blur_y_range, 8, [&](const IndexRange y_range) {
493 const int y_first = y_range.first();
494 const int y_size = y_range.size();
495 text_gaussian_blur_y(gaussian,
496 half_size,
497 y_first,
498 width,
499 y_size,
500 blur_buffer.data(),
501 shadow_mask.data(),
502 shadow_rect);
503 });
504 }
505
506 /* Composite shadow under regular output. */
507 float4 color = data->shadow_color;
508 color.x *= color.w;
509 color.y *= color.w;
510 color.z *= color.w;
511 composite_shadow(width, shadow_rect, color, shadow_mask, out->byte_data_for_write());
512}
513
514/* Text outline calculation is done by Jump Flooding Algorithm (JFA).
515 * This is similar to inpaint/jump_flooding in Compositor, also to
516 * "The Quest for Very Wide Outlines", Ben Golus 2020
517 * https://bgolus.medium.com/the-quest-for-very-wide-outlines-ba82ed442cd9 */
518
519constexpr uint16_t JFA_INVALID = 0xFFFF;
520
525
528 int2 size,
529 IndexRange x_range,
530 IndexRange y_range,
531 int step_size)
532{
533 threading::parallel_for(y_range, 8, [&](const IndexRange sub_y_range) {
534 for (const int64_t y : sub_y_range) {
535 size_t index = y * size.x;
536 for (const int64_t x : x_range) {
537 float2 coord = float2(x, y);
538
539 /* For each pixel, sample 9 pixels at +/- step size pattern,
540 * and output coordinate of closest to the boundary. */
541 JFACoord closest_texel{JFA_INVALID, JFA_INVALID};
542 float minimum_squared_distance = std::numeric_limits<float>::max();
543 for (int dy = -step_size; dy <= step_size; dy += step_size) {
544 int yy = y + dy;
545 if (yy < 0 || yy >= size.y) {
546 continue;
547 }
548 for (int dx = -step_size; dx <= step_size; dx += step_size) {
549 int xx = x + dx;
550 if (xx < 0 || xx >= size.x) {
551 continue;
552 }
553 JFACoord val = input[size_t(yy) * size.x + xx];
554 if (val.x == JFA_INVALID) {
555 continue;
556 }
557
558 float squared_distance = math::distance_squared(float2(val.x, val.y), coord);
559 if (squared_distance < minimum_squared_distance) {
560 minimum_squared_distance = squared_distance;
561 closest_texel = val;
562 }
563 }
564 }
565
566 output[index + x] = closest_texel;
567 }
568 }
569 });
570}
571
572static void text_draw(const char *text_ptr, const TextVarsRuntime *runtime, float color[4])
573{
574 const bool use_fallback = BLF_is_builtin(runtime->font);
575 if (!use_fallback) {
577 }
578
579 for (const LineInfo &line : runtime->lines) {
580 for (const CharInfo &character : line.characters) {
581 BLF_position(runtime->font, character.position.x, character.position.y, 0.0f);
582 BLF_buffer_col(runtime->font, color);
583 BLF_draw_buffer(runtime->font, text_ptr + character.offset, character.byte_length);
584 }
585 }
586
587 if (!use_fallback) {
589 }
590}
591
592static rcti draw_text_outline(const RenderData *context, const TextVars *data, ImBuf *out)
593{
594 /* Outline width of 1.0 maps to half of text line height. */
595 const int outline_width = int(data->runtime->line_height * 0.5f * data->outline_width);
596 if (outline_width < 1 || data->outline_color[3] <= 0.0f ||
597 ((data->flag & SEQ_TEXT_OUTLINE) == 0))
598 {
599 return data->runtime->text_boundbox;
600 }
601
602 const int2 size = int2(context->rectx, context->recty);
603
604 /* Draw white text into temporary buffer. */
605 const size_t pixel_count = size_t(size.x) * size.y;
606 Array<uchar4> tmp_buf(pixel_count, uchar4(0));
607 BLF_buffer(data->runtime->font,
608 nullptr,
609 reinterpret_cast<uchar *>(tmp_buf.data()),
610 size.x,
611 size.y,
612 4,
613 out->byte_buffer.colorspace);
614
615 text_draw(data->text_ptr, data->runtime, float4(1.0f));
616
617 rcti outline_rect = data->runtime->text_boundbox;
618 BLI_rcti_pad(&outline_rect, outline_width + 1, outline_width + 1);
619 outline_rect.xmin = clamp_i(outline_rect.xmin, 0, size.x - 1);
620 outline_rect.xmax = clamp_i(outline_rect.xmax, 0, size.x - 1);
621 outline_rect.ymin = clamp_i(outline_rect.ymin, 0, size.y - 1);
622 outline_rect.ymax = clamp_i(outline_rect.ymax, 0, size.y - 1);
623 const IndexRange rect_x_range(outline_rect.xmin, outline_rect.xmax - outline_rect.xmin + 1);
624 const IndexRange rect_y_range(outline_rect.ymin, outline_rect.ymax - outline_rect.ymin + 1);
625
626 /* Initialize JFA: invalid values for empty regions, pixel coordinates
627 * for opaque regions. */
629 threading::parallel_for(IndexRange(size.y), 16, [&](const IndexRange y_range) {
630 for (const int y : y_range) {
631 size_t index = size_t(y) * size.x;
632 for (int x = 0; x < size.x; x++, index++) {
633 bool is_opaque = tmp_buf[index].w >= 128;
634 JFACoord coord;
635 coord.x = is_opaque ? x : JFA_INVALID;
636 coord.y = is_opaque ? y : JFA_INVALID;
637 boundary[index] = coord;
638 }
639 }
640 });
641
642 /* Do jump flooding calculations. */
643 JFACoord invalid_coord{JFA_INVALID, JFA_INVALID};
644 Array<JFACoord> initial_flooded_result(pixel_count, invalid_coord);
645 jump_flooding_pass(boundary, initial_flooded_result, size, rect_x_range, rect_y_range, 1);
646
647 Array<JFACoord> *result_to_flood = &initial_flooded_result;
648 Array<JFACoord> intermediate_result(pixel_count, invalid_coord);
649 Array<JFACoord> *result_after_flooding = &intermediate_result;
650
651 int step_size = power_of_2_max_i(outline_width) / 2;
652
653 while (step_size != 0) {
655 *result_to_flood, *result_after_flooding, size, rect_x_range, rect_y_range, step_size);
656 std::swap(result_to_flood, result_after_flooding);
657 step_size /= 2;
658 }
659
660 /* Premultiplied outline color. */
661 float4 color = data->outline_color;
662 color.x *= color.w;
663 color.y *= color.w;
664 color.z *= color.w;
665
666 const float text_color_alpha = data->color[3];
667
668 /* We have distances to the closest opaque parts of the image now. Composite the
669 * outline into the output image. */
670
671 uchar *byte_data = out->byte_data_for_write();
672 threading::parallel_for(rect_y_range, 8, [&](const IndexRange y_range) {
673 for (const int y : y_range) {
674 size_t index = size_t(y) * size.x + rect_x_range.start();
675 uchar *dst = byte_data + index * 4;
676 for (int x = rect_x_range.start(); x < rect_x_range.one_after_last(); x++, index++, dst += 4)
677 {
678 JFACoord closest_texel = (*result_to_flood)[index];
679 if (closest_texel.x == JFA_INVALID) {
680 /* Outside of outline, leave output pixel as is. */
681 continue;
682 }
683
684 /* Fade out / anti-alias the outline over one pixel towards outline distance. */
685 float distance = math::distance(float2(x, y), float2(closest_texel.x, closest_texel.y));
686 float alpha = math::clamp(outline_width - distance + 1.0f, 0.0f, 1.0f);
687
688 /* Do not put outline inside the text shape:
689 * - When overall text color is fully opaque, we want to make
690 * outline fully transparent only where text is fully opaque.
691 * This ensures that combined anti-aliased pixels at text boundary
692 * are properly fully opaque.
693 * - However when text color is fully transparent, we want to
694 * Use opposite alpha of text, to anti-alias the inner edge of
695 * the outline.
696 * In between those two, interpolate the alpha modulation factor. */
697 float text_alpha = tmp_buf[index].w * (1.0f / 255.0f);
698 float mul_opaque_text = text_alpha >= 1.0f ? 0.0f : 1.0f;
699 float mul_transparent_text = 1.0f - text_alpha;
700 float mul = math::interpolate(mul_transparent_text, mul_opaque_text, text_color_alpha);
701 alpha *= mul;
702
703 float4 col1 = color;
704 col1 *= alpha;
705
706 /* Blend over the output. */
707 float mfac = 1.0f - col1.w;
708 float4 col2 = load_premul_pixel(dst);
709 float4 col = col1 + mfac * col2;
710 store_premul_pixel(col, dst);
711 }
712 }
713 });
715 data->runtime->font, nullptr, byte_data, size.x, size.y, 4, out->byte_buffer.colorspace);
716
717 return outline_rect;
718}
719
720/* Similar to #IMB_rectfill_area but blends the given color under the
721 * existing image. Also can do rounded corners. Only works on byte buffers. */
723 ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, float corner_radius)
724{
725 const int width = ibuf->x;
726 const int height = ibuf->y;
727 x1 = math::clamp(x1, 0, width);
728 x2 = math::clamp(x2, 0, width);
729 y1 = math::clamp(y1, 0, height);
730 y2 = math::clamp(y2, 0, height);
731 if (x1 > x2) {
732 std::swap(x1, x2);
733 }
734 if (y1 > y2) {
735 std::swap(y1, y2);
736 }
737 if (x1 == x2 || y1 == y2) {
738 return;
739 }
740
741 corner_radius = math::clamp(corner_radius, 0.0f, math::min(x2 - x1, y2 - y1) / 2.0f);
742
743 float4 premul_col_base;
744 straight_to_premul_v4_v4(premul_col_base, col);
745
746 uchar *byte_data = ibuf->byte_data_for_write();
747 threading::parallel_for(IndexRange::from_begin_end(y1, y2), 16, [&](const IndexRange y_range) {
748 for (const int y : y_range) {
749 uchar *dst = byte_data + (size_t(width) * y + x1) * 4;
750 float origin_x = 0.0f, origin_y = 0.0f;
751 for (int x = x1; x < x2; x++) {
752 float4 pix = load_premul_pixel(dst);
753 float fac = 1.0f - pix.w;
754
755 float4 premul_col = premul_col_base;
756 bool is_corner = false;
757 if (x < x1 + corner_radius && y < y1 + corner_radius) {
758 is_corner = true;
759 origin_x = x1 + corner_radius - 1;
760 origin_y = y1 + corner_radius - 1;
761 }
762 else if (x >= x2 - corner_radius && y < y1 + corner_radius) {
763 is_corner = true;
764 origin_x = x2 - corner_radius;
765 origin_y = y1 + corner_radius - 1;
766 }
767 else if (x < x1 + corner_radius && y >= y2 - corner_radius) {
768 is_corner = true;
769 origin_x = x1 + corner_radius - 1;
770 origin_y = y2 - corner_radius;
771 }
772 else if (x >= x2 - corner_radius && y >= y2 - corner_radius) {
773 is_corner = true;
774 origin_x = x2 - corner_radius;
775 origin_y = y2 - corner_radius;
776 }
777 if (is_corner) {
778 /* If we are inside rounded corner, evaluate a superellipse and
779 * modulate color with that. Superellipse instead of just a circle
780 * since the curvature between flat and rounded area looks a bit
781 * nicer. */
782 constexpr float curve_pow = 2.1f;
783 float r = powf(powf(abs(x - origin_x), curve_pow) + powf(abs(y - origin_y), curve_pow),
784 1.0f / curve_pow);
785 float alpha = math::clamp(corner_radius - r, 0.0f, 1.0f);
786 premul_col *= alpha;
787 }
788
789 float4 dst_fl = fac * premul_col + pix;
790 store_premul_pixel(dst_fl, dst);
791 dst += 4;
792 }
793 }
794 });
795}
796
797static int text_effect_line_size_get(const RenderData *context, const TextVars &text)
798{
799 /* Used to calculate boundbox. Render scale compensation is not needed there. */
800 if (context == nullptr) {
801 return text.text_size;
802 }
803
804 /* Compensate for preview render size. */
805 const float size_scale = seq::get_render_scale_factor(*context);
806 return size_scale * text.text_size;
807}
808
810{
811 int font = -1;
812 /* In case font got unloaded behind our backs: mark it as needing a load. */
813 if (text.text_blf_id >= 0 && !BLF_is_loaded_id(text.text_blf_id)) {
815 }
816
818 text.text_blf_id = -1;
819 text_font_load(&text, false);
820 }
821
822 if (text.text_blf_id >= 0) {
823 font = text.text_blf_id;
824 }
825
826 if (font < 0) {
827 /* Try to fallback to the default Blender monospaced font. */
828 std::lock_guard lock(g_font_map.mutex);
831 }
832 if (g_fallback_font_id < 0) {
834 }
835 font = g_fallback_font_id;
836 }
837 return font;
838}
839
840static int text_effect_font_init(const RenderData *context, TextVars &text, FontFlags font_flags)
841{
842 int font = text_effect_font_get(text);
843 BLF_size(font, text_effect_line_size_get(context, text));
844 BLF_enable(font, font_flags);
845 return font;
846}
847
849{
850 Vector<CharInfo> characters;
851 characters.reserve(data->text_len_bytes / 2);
852
853 const bool use_fallback = BLF_is_builtin(font);
854 if (!use_fallback) {
856 }
857
859 data->text_ptr,
860 data->text_len_bytes,
861 [&](int index, size_t byte_offset, int byte_len, int advance_x) {
862 CharInfo info;
863 info.index = index;
864 info.offset = byte_offset;
865 info.byte_length = byte_len;
866 info.advance_x = advance_x;
867 characters.append(info);
868 });
869
870 if (!use_fallback) {
872 }
873
874 return characters;
875}
876
877static int wrap_width_get(const TextVars *data, const int2 image_size)
878{
879 if (data->wrap_width == 0.0f) {
880 return std::numeric_limits<int>::max();
881 }
882 return data->wrap_width * image_size.x;
883}
884
885/* Lines must contain CharInfo for newlines and \0, as UI must know where they begin. */
887 TextVarsRuntime *runtime,
888 const int2 image_size,
889 Vector<CharInfo> &characters)
890{
891 runtime->lines.clear();
892
893 const int wrap_width = wrap_width_get(data, image_size);
894
895 float cur_pixel_x = 0.0f;
896 CharInfo *last_space = nullptr;
897
898 /* First pass: Find characters where line has to be broken. Temporarily set `CharInfo.position`
899 * only for space characters for now so that we can jump back if we find a breaking space. */
900 for (CharInfo &character : characters) {
901 char chr = data->text_ptr[character.offset];
902 if (chr == '\0') {
903 break;
904 }
905
906 if (chr == ' ') {
907 character.position.x = cur_pixel_x;
908 last_space = &character;
909 }
910 else if (chr == '\n') {
911 character.do_wrap = true;
912 cur_pixel_x = 0;
913 last_space = nullptr;
914 }
915 else if ((cur_pixel_x + character.advance_x) > wrap_width && last_space != nullptr) {
916 last_space->do_wrap = true;
917 cur_pixel_x -= last_space->position.x + last_space->advance_x;
918 last_space = nullptr;
919 }
920 cur_pixel_x += character.advance_x;
921 }
922
923 /* Second pass: Fill lines with characters. */
924 float2 cur_pixel_pos = {0.0f, 0.0f};
925 runtime->lines.append(LineInfo());
926 for (CharInfo &character : characters) {
927 LineInfo &line = runtime->lines.last();
928 character.position = cur_pixel_pos;
929 line.characters.append(character);
930
931 cur_pixel_pos.x += character.advance_x;
932
933 /* If line is ending, calculate final line width. */
934 const bool line_end = data->text_ptr[character.offset] == '\0' || character.do_wrap;
935 if (line_end) {
936 /* Subtract one to ignore \0 or \n character. */
937 const int num_visible_chars = line.characters.size() - 1;
938 if (num_visible_chars <= 0) {
939 line.width = 0;
940 }
941 else {
942 const CharInfo last_char = line.characters[num_visible_chars - 1];
943 /* Note that we cannot only rely on `advance_x`, since e.g. italic fonts can extend further
944 * than this, so calculate the last glyph width to get a correct result. See !145692. */
945 const int glyph_width = math::ceil(
946 BLF_width(runtime->font, &data->text_ptr[last_char.offset], last_char.byte_length));
947 line.width = last_char.position.x + glyph_width;
948 }
949 }
950
951 if (character.do_wrap) {
952 const int line_spacing = (data->flag & SEQ_TEXT_USE_ABSOLUTE_LINE_SPACING) ?
953 data->abs_space_line :
954 runtime->line_height * data->space_line;
955 runtime->lines.append(LineInfo());
956 cur_pixel_pos.x = 0;
957 cur_pixel_pos.y -= line_spacing;
958 }
959 }
960}
961
962static int text_box_width_get(const Vector<LineInfo> &lines)
963{
964 int width_max = 0;
965
966 for (const LineInfo &line : lines) {
967 width_max = std::max(width_max, line.width);
968 }
969 return width_max;
970}
971
973 float line_width,
974 int max_width)
975{
976 const float line_offset = (max_width - line_width);
977
978 if (data->align == SEQ_TEXT_ALIGN_X_RIGHT) {
979 return {line_offset, 0.0f};
980 }
981 if (data->align == SEQ_TEXT_ALIGN_X_CENTER) {
982 return {line_offset / 2.0f, 0.0f};
983 }
984
985 return {0.0f, 0.0f};
986}
987
988static float2 anchor_offset_get(const TextVars *data, int width_max, int text_height)
989{
990 float2 anchor_offset;
991
992 switch (data->anchor_x) {
994 anchor_offset.x = 0;
995 break;
997 anchor_offset.x = -width_max / 2.0f;
998 break;
1000 anchor_offset.x = -width_max;
1001 break;
1002 }
1003 switch (data->anchor_y) {
1005 anchor_offset.y = 0;
1006 break;
1008 anchor_offset.y = text_height / 2.0f;
1009 break;
1011 anchor_offset.y = text_height;
1012 break;
1013 }
1014
1015 return anchor_offset;
1016}
1017
1018static void calc_boundbox(const TextVars *data, TextVarsRuntime *runtime, const int2 image_size)
1019{
1020 /* `BLF_bounds_max()` is used, because some fonts have glyphs overlapping with lines above. */
1021 rctf glyph_bounds_max;
1022 BLF_bounds_max(runtime->font, &glyph_bounds_max);
1023 const int line_spacing = (data->flag & SEQ_TEXT_USE_ABSOLUTE_LINE_SPACING) ?
1024 data->abs_space_line :
1025 runtime->line_height * data->space_line;
1026 const int text_height = (runtime->lines.size() - 1) * line_spacing +
1027 math::ceil(BLI_rctf_size_y(&glyph_bounds_max));
1028
1029 int width_max = text_box_width_get(runtime->lines);
1030
1031 /* Add width to empty text, so there is something to draw or select. */
1032 if (width_max == 0) {
1033 width_max = text_height * 2;
1034 }
1035
1036 const float2 image_center{data->loc[0] * image_size.x, data->loc[1] * image_size.y};
1037 const float2 anchor = anchor_offset_get(data, width_max, text_height);
1038
1039 runtime->text_boundbox.xmin = anchor.x + image_center.x;
1040 runtime->text_boundbox.xmax = anchor.x + image_center.x + width_max;
1041 runtime->text_boundbox.ymin = anchor.y + image_center.y - text_height;
1042 runtime->text_boundbox.ymax = runtime->text_boundbox.ymin + text_height;
1043}
1044
1046 TextVarsRuntime *runtime,
1047 const int2 image_size)
1048{
1049 const int box_width = text_box_width_get(runtime->lines);
1050 const int line_spacing = (data->flag & SEQ_TEXT_USE_ABSOLUTE_LINE_SPACING) ?
1051 data->abs_space_line :
1052 runtime->line_height * data->space_line;
1053 const int box_height = runtime->line_height + (runtime->lines.size() - 1) * line_spacing;
1054
1055 const float2 image_center{data->loc[0] * image_size.x, data->loc[1] * image_size.y};
1056 const float2 line_height_offset{0.0f,
1057 float(-runtime->line_height - BLF_descender(runtime->font))};
1058 const float2 anchor_offset = anchor_offset_get(data, box_width, box_height);
1059
1060 for (LineInfo &line : runtime->lines) {
1061 const float2 align_offset = horizontal_alignment_offset_get(data, line.width, box_width);
1062 const float2 offset = math::round(image_center + line_height_offset + align_offset +
1063 anchor_offset);
1064
1065 for (CharInfo &character : line.characters) {
1066 character.position += offset;
1067 }
1068 }
1069}
1070
1071void text_effect_update_runtime(const RenderData *context, TextVars &text, const int2 image_size)
1072{
1073 if (text.runtime == nullptr) {
1074 text.runtime = MEM_new<TextVarsRuntime>(__func__);
1075 }
1076 TextVarsRuntime &runtime = *text.runtime;
1077
1078 const FontFlags font_flags = ((text.flag & SEQ_TEXT_BOLD) ? BLF_BOLD : BLF_NONE) |
1079 ((text.flag & SEQ_TEXT_ITALIC) ? BLF_ITALIC : BLF_NONE);
1080
1081 const int font = text_effect_font_init(context, text, font_flags);
1082
1083 runtime.font = font;
1084 runtime.image_size = image_size;
1085 runtime.line_height = BLF_height_max(font);
1086 runtime.font_descender = BLF_descender(font);
1088
1089 Vector<CharInfo> characters_temp = build_character_info(&text, font);
1090 apply_word_wrapping(&text, &runtime, image_size, characters_temp);
1091 apply_text_alignment(&text, &runtime, image_size);
1092 calc_boundbox(&text, &runtime, image_size);
1093}
1094
1095void text_effect_adjust_relative(TextVars &text, const int2 old_size, const int2 new_size)
1096{
1097 /* Word wrap is relative to image width. Adjust to avoid text reflow at the new size. */
1098 text.wrap_width *= float(old_size.x) / float(new_size.x);
1099
1100 /* Location is relative to image size. Shift so it sits at the origin, filling the new size. */
1101 std::scoped_lock runtime_lock(text_runtime_mutex_get());
1102 text_effect_update_runtime(nullptr, text, new_size);
1104 text.loc[0] -= float(text.runtime->text_boundbox.xmin) / new_size.x;
1105 text.loc[1] -= float(text.runtime->text_boundbox.ymin) / new_size.y;
1106}
1107
1109 SeqRenderState * /*state*/,
1110 Strip *strip,
1111 float /*timeline_frame*/,
1112 float /*fac*/,
1113 const SeqResult & /*ibuf1*/,
1114 const SeqResult & /*ibuf2*/)
1115{
1117 /* NOTE: text rasterization only fills in part of output image,
1118 * need to clear it. */
1119 SeqResult out = prepare_effect_imbufs(context, {}, {}, false);
1120 /* Text colors are stored as sRGB in DNA, so image buffer is as well. */
1123 TextVars *data = static_cast<TextVars *>(strip->effectdata);
1124
1125 /* Guard against parallel accesses to the fonts map. */
1126 std::lock_guard text_runtime_lock(text_runtime_mutex);
1127 std::lock_guard font_map_lock(g_font_map.mutex);
1128
1129 text_effect_update_runtime(context, *data, {out.image->x, out.image->y});
1130 const int font = data->runtime->font;
1131
1132 rcti outline_rect = draw_text_outline(context, data, out.image);
1133 BLF_buffer(font,
1134 nullptr,
1135 out.image->byte_data_for_write(),
1136 out.image->x,
1137 out.image->y,
1138 4,
1139 out.image->byte_buffer.colorspace);
1140 text_draw(data->text_ptr, data->runtime, data->color);
1141 BLF_buffer(font, nullptr, nullptr, 0, 0, 4, nullptr);
1143
1144 /* Draw shadow. */
1145 if (data->flag & SEQ_TEXT_SHADOW) {
1146 draw_text_shadow(context, data, data->runtime->line_height, outline_rect, out.image);
1147 }
1148
1149 /* Draw box under text. */
1150 if (data->flag & SEQ_TEXT_BOX) {
1151 if (out.image->byte_data()) {
1152 const int margin = data->box_margin * out.image->x;
1153 const int minx = data->runtime->text_boundbox.xmin - margin;
1154 const int maxx = data->runtime->text_boundbox.xmax + margin;
1155 const int miny = data->runtime->text_boundbox.ymin - margin;
1156 const int maxy = data->runtime->text_boundbox.ymax + margin;
1157 float corner_radius = data->box_roundness * (maxy - miny) / 2.0f;
1158 fill_rect_alpha_under(out.image, data->box_color, minx, miny, maxx, maxy, corner_radius);
1159 }
1160 }
1161
1162 return out;
1163}
1164
1166{
1167 rval.init = init_text_effect;
1168 rval.free = free_text_effect;
1169 rval.copy = copy_text_effect;
1171 rval.execute = do_text_effect;
1172}
1173
1175
1176} // namespace blender::seq
#define MAX_ID_FULL_NAME
#define DEG2RADF(_deg)
#define FILE_MAX
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Definition DNA_ID.h:691
#define STRIP_FONT_NOT_LOADED
#define PRF_scope_with_name(ui_name, category)
volatile int lock
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define output
const T * data() const
Definition BLI_array.hh:323
constexpr int64_t first() const
constexpr int64_t size() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr IndexRange()=default
void clear()
Definition BLI_map.hh:1038
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
Definition BLI_map.hh:481
int64_t remove_if(Predicate &&predicate)
Definition BLI_map.hh:948
ItemIterator items() const &
Definition BLI_map.hh:902
void reserve(const int64_t min_capacity)
#define powf(x, y)
#define pf(_x, _i)
Prefetch 64.
Definition gim_memory.h:48
#define index(i)
#define abs
float distance(float, float) RET
int size(const AssetLibraryReference *library_reference)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T ceil(const T &a)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T max(const T &a, const T &b)
T round(const T &a)
void effect_text_font_set(Strip *strip, VFont *font)
static int wrap_width_get(const TextVars *data, const int2 image_size)
std::recursive_mutex & text_runtime_mutex_get()
static int text_effect_line_size_get(const RenderData *context, const TextVars &text)
static int g_fallback_font_id
void fontmap_clear()
float4 load_premul_pixel(const uchar *ptr)
Definition effects.hh:88
static void fill_rect_alpha_under(ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, float corner_radius)
static void calc_boundbox(const TextVars *data, TextVarsRuntime *runtime, const int2 image_size)
static void initialize_shadow_alpha(int width, int height, int2 offset, const rcti &shadow_rect, const uchar *input, Array< uchar > &r_shadow_mask)
static void text_draw(const char *text_ptr, const TextVarsRuntime *runtime, float color[4])
void text_effect_get_handle(EffectHandle &rval)
float get_render_scale_factor(eSpaceSeq_Proxy_RenderSize render_size, short scene_render_scale)
Definition render.cc:2249
Array< float > make_gaussian_blur_kernel(float rad, int size)
Definition effects.cc:77
void text_effect_update_runtime(const RenderData *context, TextVars &text, const int2 image_size)
SeqResult prepare_effect_imbufs(const RenderData *context, const SeqResult &ibuf1, const SeqResult &ibuf2, bool uninitialized_pixels)
Definition effects.cc:34
static Vector< CharInfo > build_character_info(const TextVars *data, int font)
static float2 anchor_offset_get(const TextVars *data, int width_max, int text_height)
static void text_font_unload(TextVars *data, const bool do_id_user)
int text_effect_font_get(TextVars &text)
static SeqFontMap g_font_map
void text_effect_adjust_relative(TextVars &text, const int2 old_size, const int2 new_size)
static void init_text_effect(Strip *strip)
static StripEarlyOut early_out_text(const Strip *strip, float)
bool effects_can_render_text(const Strip *strip)
static void jump_flooding_pass(Span< JFACoord > input, MutableSpan< JFACoord > output, int2 size, IndexRange x_range, IndexRange y_range, int step_size)
static void apply_word_wrapping(const TextVars *data, TextVarsRuntime *runtime, const int2 image_size, Vector< CharInfo > &characters)
static int text_effect_font_init(const RenderData *context, TextVars &text, FontFlags font_flags)
static std::recursive_mutex text_runtime_mutex
static void composite_shadow(int width, const rcti &shadow_rect, const float4 &shadow_color, const Array< uchar > &shadow_mask, uchar *output)
static void apply_text_alignment(const TextVars *data, TextVarsRuntime *runtime, const int2 image_size)
static SeqResult do_text_effect(const RenderData *context, SeqRenderState *, Strip *strip, float, float, const SeqResult &, const SeqResult &)
static void text_gaussian_blur_y(const Span< float > gaussian, int half_size, int start_line, int width, int height, const uchar *rect, uchar *dst, const rcti &shadow_rect)
static int text_box_width_get(const Vector< LineInfo > &lines)
static void draw_text_shadow(const RenderData *context, const TextVars *data, int line_height, const rcti &rect, ImBuf *out)
static float2 horizontal_alignment_offset_get(const TextVars *data, float line_width, int max_width)
static rcti draw_text_outline(const RenderData *context, const TextVars *data, ImBuf *out)
static void text_gaussian_blur_x(const Span< float > gaussian, int half_size, int start_line, int width, int height, const uchar *rect, uchar *dst, const rcti &shadow_rect)
static void free_text_effect(Strip *strip, const bool do_id_user)
static int strip_load_font_mem(const std::string &name, const uchar *data, int data_size)
static void text_font_load(TextVars *data, const bool do_id_user)
static void copy_text_effect(Strip *dst, const Strip *src, const int flag)
static void strip_unload_font(int fontid)
void store_premul_pixel(const float4 &pix, uchar *dst)
Definition effects.hh:100
static int strip_load_font_file(const std::string &path)
constexpr uint16_t JFA_INVALID
static void clamp_rect(int width, int height, rcti &r_rect)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
VecBase< uint8_t, 4 > uchar4
bool BLF_is_loaded_id(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:172
__int64 int64_t
Definition BKE_text.h:90
char * STRNCPY(char(&dst)[N], const char *src)
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void id_us_plus(ID *id)
Definition lib_id.cc:433
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int channel_count, const ColorSpace *colorspace)
Definition blf.cc:989
int BLF_load_mono_default(bool unique)
MINLINE int power_of_2_max_i(int n)
MINLINE void copy_v4_fl(float r[4], float f)
MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
void BLF_addref_id(int fontid)
Definition blf.cc:313
bool BLF_bounds_max(int fontid, rctf *r_bounds) ATTR_NONNULL(2)
Definition blf.cc:927
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
@ LIB_ID_CREATE_NO_USER_REFCOUNT
VecBase< float, 4 > float4
unsigned short uint16_t
Definition BKE_text.h:80
void BLF_size(int fontid, float size)
Definition blf.cc:445
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
unsigned char uchar
Definition BKE_text.h:58
BMesh const char void * data
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL(1
Definition blf.cc:236
void IMB_colormanagement_assign_byte_colorspace(ImBuf *ibuf, const char *name)
@ SEQ_TEXT_USE_ABSOLUTE_LINE_SPACING
const char * IMB_colormanagement_srgb_colorspace_name_get()
void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2)
Definition blf.cc:1057
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:190
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:1087
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separator_char)
Definition lib_id.cc:2691
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
void BLF_info_foreach_glyph(int fontid, const char *str, size_t str_len, FunctionRef< void(int index, size_t byte_offset, int byte_len, int advance_x)> callback)
Definition blf.cc:701
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y)
Definition rct.cc:643
bool BLF_is_builtin(int fontid)
Definition blf.cc:340
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
MINLINE int clamp_i(int value, int min, int max)
void id_us_min(ID *id)
Definition lib_id.cc:441
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_NO_FALLBACK
Definition BLF_enums.hh:66
@ BLF_ITALIC
Definition BLF_enums.hh:49
bool BLF_unload_id(int fontid)
Definition blf.cc:282
SphericalHarmonicL1< float4 > mul(SphericalHarmonicL1< float4 > a, float b)
#define sinf
#define cosf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
eEffectTextFlags flag
seq::TextVarsRuntime * runtime
struct PackedFile * packedfile
char filepath[1024]
void(*) copy(Strip *dst, const Strip *src, int flag)
Definition effects.hh:44
void(*) free(Strip *strip, bool do_id_user)
Definition effects.hh:47
void(*) init(Strip *strip)
Definition effects.hh:41
StripEarlyOut(*) early_out(const Strip *strip, float fac)
Definition effects.hh:49
SeqResult(*) execute(const RenderData *context, SeqRenderState *state, Strip *strip, float timeline_frame, float fac, const SeqResult &input1, const SeqResult &input2)
Definition effects.hh:52
Vector< CharInfo > characters
Map< std::string, int > path_to_file_font_id
std::recursive_mutex mutex
Map< std::string, int > name_to_mem_font_id
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225