This is shorter and consistent across filters.
Anton Khirnov authored on 2013/03/19 04:44:36... | ... |
@@ -231,13 +231,13 @@ static int glyph_cmp(void *key, const void *b) |
231 | 231 |
*/ |
232 | 232 |
static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) |
233 | 233 |
{ |
234 |
- DrawTextContext *dtext = ctx->priv; |
|
234 |
+ DrawTextContext *s = ctx->priv; |
|
235 | 235 |
Glyph *glyph; |
236 | 236 |
struct AVTreeNode *node = NULL; |
237 | 237 |
int ret; |
238 | 238 |
|
239 |
- /* load glyph into dtext->face->glyph */ |
|
240 |
- if (FT_Load_Char(dtext->face, code, dtext->ft_load_flags)) |
|
239 |
+ /* load glyph into s->face->glyph */ |
|
240 |
+ if (FT_Load_Char(s->face, code, s->ft_load_flags)) |
|
241 | 241 |
return AVERROR(EINVAL); |
242 | 242 |
|
243 | 243 |
/* save glyph */ |
... | ... |
@@ -248,15 +248,15 @@ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) |
248 | 248 |
} |
249 | 249 |
glyph->code = code; |
250 | 250 |
|
251 |
- if (FT_Get_Glyph(dtext->face->glyph, glyph->glyph)) { |
|
251 |
+ if (FT_Get_Glyph(s->face->glyph, glyph->glyph)) { |
|
252 | 252 |
ret = AVERROR(EINVAL); |
253 | 253 |
goto error; |
254 | 254 |
} |
255 | 255 |
|
256 |
- glyph->bitmap = dtext->face->glyph->bitmap; |
|
257 |
- glyph->bitmap_left = dtext->face->glyph->bitmap_left; |
|
258 |
- glyph->bitmap_top = dtext->face->glyph->bitmap_top; |
|
259 |
- glyph->advance = dtext->face->glyph->advance.x >> 6; |
|
256 |
+ glyph->bitmap = s->face->glyph->bitmap; |
|
257 |
+ glyph->bitmap_left = s->face->glyph->bitmap_left; |
|
258 |
+ glyph->bitmap_top = s->face->glyph->bitmap_top; |
|
259 |
+ glyph->advance = s->face->glyph->advance.x >> 6; |
|
260 | 260 |
|
261 | 261 |
/* measure text height to calculate text_height (or the maximum text height) */ |
262 | 262 |
FT_Glyph_Get_CBox(*glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox); |
... | ... |
@@ -266,7 +266,7 @@ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) |
266 | 266 |
ret = AVERROR(ENOMEM); |
267 | 267 |
goto error; |
268 | 268 |
} |
269 |
- av_tree_insert(&dtext->glyphs, glyph, glyph_cmp, &node); |
|
269 |
+ av_tree_insert(&s->glyphs, glyph, glyph_cmp, &node); |
|
270 | 270 |
|
271 | 271 |
if (glyph_ptr) |
272 | 272 |
*glyph_ptr = glyph; |
... | ... |
@@ -283,80 +283,80 @@ error: |
283 | 283 |
static av_cold int init(AVFilterContext *ctx) |
284 | 284 |
{ |
285 | 285 |
int err; |
286 |
- DrawTextContext *dtext = ctx->priv; |
|
286 |
+ DrawTextContext *s = ctx->priv; |
|
287 | 287 |
Glyph *glyph; |
288 | 288 |
|
289 |
- if (!dtext->fontfile) { |
|
289 |
+ if (!s->fontfile) { |
|
290 | 290 |
av_log(ctx, AV_LOG_ERROR, "No font filename provided\n"); |
291 | 291 |
return AVERROR(EINVAL); |
292 | 292 |
} |
293 | 293 |
|
294 |
- if (dtext->textfile) { |
|
294 |
+ if (s->textfile) { |
|
295 | 295 |
uint8_t *textbuf; |
296 | 296 |
size_t textbuf_size; |
297 | 297 |
|
298 |
- if (dtext->text) { |
|
298 |
+ if (s->text) { |
|
299 | 299 |
av_log(ctx, AV_LOG_ERROR, |
300 | 300 |
"Both text and text file provided. Please provide only one\n"); |
301 | 301 |
return AVERROR(EINVAL); |
302 | 302 |
} |
303 |
- if ((err = av_file_map(dtext->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) { |
|
303 |
+ if ((err = av_file_map(s->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) { |
|
304 | 304 |
av_log(ctx, AV_LOG_ERROR, |
305 | 305 |
"The text file '%s' could not be read or is empty\n", |
306 |
- dtext->textfile); |
|
306 |
+ s->textfile); |
|
307 | 307 |
return err; |
308 | 308 |
} |
309 | 309 |
|
310 |
- if (!(dtext->text = av_malloc(textbuf_size+1))) |
|
310 |
+ if (!(s->text = av_malloc(textbuf_size+1))) |
|
311 | 311 |
return AVERROR(ENOMEM); |
312 |
- memcpy(dtext->text, textbuf, textbuf_size); |
|
313 |
- dtext->text[textbuf_size] = 0; |
|
312 |
+ memcpy(s->text, textbuf, textbuf_size); |
|
313 |
+ s->text[textbuf_size] = 0; |
|
314 | 314 |
av_file_unmap(textbuf, textbuf_size); |
315 | 315 |
} |
316 | 316 |
|
317 |
- if (!dtext->text) { |
|
317 |
+ if (!s->text) { |
|
318 | 318 |
av_log(ctx, AV_LOG_ERROR, |
319 | 319 |
"Either text or a valid file must be provided\n"); |
320 | 320 |
return AVERROR(EINVAL); |
321 | 321 |
} |
322 | 322 |
|
323 |
- if ((err = av_parse_color(dtext->fontcolor_rgba, dtext->fontcolor_string, -1, ctx))) { |
|
323 |
+ if ((err = av_parse_color(s->fontcolor_rgba, s->fontcolor_string, -1, ctx))) { |
|
324 | 324 |
av_log(ctx, AV_LOG_ERROR, |
325 |
- "Invalid font color '%s'\n", dtext->fontcolor_string); |
|
325 |
+ "Invalid font color '%s'\n", s->fontcolor_string); |
|
326 | 326 |
return err; |
327 | 327 |
} |
328 | 328 |
|
329 |
- if ((err = av_parse_color(dtext->boxcolor_rgba, dtext->boxcolor_string, -1, ctx))) { |
|
329 |
+ if ((err = av_parse_color(s->boxcolor_rgba, s->boxcolor_string, -1, ctx))) { |
|
330 | 330 |
av_log(ctx, AV_LOG_ERROR, |
331 |
- "Invalid box color '%s'\n", dtext->boxcolor_string); |
|
331 |
+ "Invalid box color '%s'\n", s->boxcolor_string); |
|
332 | 332 |
return err; |
333 | 333 |
} |
334 | 334 |
|
335 |
- if ((err = av_parse_color(dtext->shadowcolor_rgba, dtext->shadowcolor_string, -1, ctx))) { |
|
335 |
+ if ((err = av_parse_color(s->shadowcolor_rgba, s->shadowcolor_string, -1, ctx))) { |
|
336 | 336 |
av_log(ctx, AV_LOG_ERROR, |
337 |
- "Invalid shadow color '%s'\n", dtext->shadowcolor_string); |
|
337 |
+ "Invalid shadow color '%s'\n", s->shadowcolor_string); |
|
338 | 338 |
return err; |
339 | 339 |
} |
340 | 340 |
|
341 |
- if ((err = FT_Init_FreeType(&(dtext->library)))) { |
|
341 |
+ if ((err = FT_Init_FreeType(&(s->library)))) { |
|
342 | 342 |
av_log(ctx, AV_LOG_ERROR, |
343 | 343 |
"Could not load FreeType: %s\n", FT_ERRMSG(err)); |
344 | 344 |
return AVERROR(EINVAL); |
345 | 345 |
} |
346 | 346 |
|
347 | 347 |
/* load the face, and set up the encoding, which is by default UTF-8 */ |
348 |
- if ((err = FT_New_Face(dtext->library, dtext->fontfile, 0, &dtext->face))) { |
|
348 |
+ if ((err = FT_New_Face(s->library, s->fontfile, 0, &s->face))) { |
|
349 | 349 |
av_log(ctx, AV_LOG_ERROR, "Could not load fontface from file '%s': %s\n", |
350 |
- dtext->fontfile, FT_ERRMSG(err)); |
|
350 |
+ s->fontfile, FT_ERRMSG(err)); |
|
351 | 351 |
return AVERROR(EINVAL); |
352 | 352 |
} |
353 |
- if ((err = FT_Set_Pixel_Sizes(dtext->face, 0, dtext->fontsize))) { |
|
353 |
+ if ((err = FT_Set_Pixel_Sizes(s->face, 0, s->fontsize))) { |
|
354 | 354 |
av_log(ctx, AV_LOG_ERROR, "Could not set font size to %d pixels: %s\n", |
355 |
- dtext->fontsize, FT_ERRMSG(err)); |
|
355 |
+ s->fontsize, FT_ERRMSG(err)); |
|
356 | 356 |
return AVERROR(EINVAL); |
357 | 357 |
} |
358 | 358 |
|
359 |
- dtext->use_kerning = FT_HAS_KERNING(dtext->face); |
|
359 |
+ s->use_kerning = FT_HAS_KERNING(s->face); |
|
360 | 360 |
|
361 | 361 |
/* load the fallback glyph with code 0 */ |
362 | 362 |
load_glyph(ctx, NULL, 0); |
... | ... |
@@ -366,7 +366,7 @@ static av_cold int init(AVFilterContext *ctx) |
366 | 366 |
av_log(ctx, AV_LOG_ERROR, "Could not set tabsize.\n"); |
367 | 367 |
return err; |
368 | 368 |
} |
369 |
- dtext->tabsize *= glyph->advance; |
|
369 |
+ s->tabsize *= glyph->advance; |
|
370 | 370 |
|
371 | 371 |
#if !HAVE_LOCALTIME_R |
372 | 372 |
av_log(ctx, AV_LOG_WARNING, "strftime() expansion unavailable!\n"); |
... | ... |
@@ -399,20 +399,20 @@ static int glyph_enu_free(void *opaque, void *elem) |
399 | 399 |
|
400 | 400 |
static av_cold void uninit(AVFilterContext *ctx) |
401 | 401 |
{ |
402 |
- DrawTextContext *dtext = ctx->priv; |
|
402 |
+ DrawTextContext *s = ctx->priv; |
|
403 | 403 |
int i; |
404 | 404 |
|
405 |
- av_freep(&dtext->expanded_text); |
|
406 |
- av_freep(&dtext->positions); |
|
407 |
- av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free); |
|
408 |
- av_tree_destroy(dtext->glyphs); |
|
409 |
- dtext->glyphs = 0; |
|
410 |
- FT_Done_Face(dtext->face); |
|
411 |
- FT_Done_FreeType(dtext->library); |
|
405 |
+ av_freep(&s->expanded_text); |
|
406 |
+ av_freep(&s->positions); |
|
407 |
+ av_tree_enumerate(s->glyphs, NULL, NULL, glyph_enu_free); |
|
408 |
+ av_tree_destroy(s->glyphs); |
|
409 |
+ s->glyphs = 0; |
|
410 |
+ FT_Done_Face(s->face); |
|
411 |
+ FT_Done_FreeType(s->library); |
|
412 | 412 |
|
413 | 413 |
for (i = 0; i < 4; i++) { |
414 |
- av_freep(&dtext->box_line[i]); |
|
415 |
- dtext->pixel_step[i] = 0; |
|
414 |
+ av_freep(&s->box_line[i]); |
|
415 |
+ s->pixel_step[i] = 0; |
|
416 | 416 |
} |
417 | 417 |
|
418 | 418 |
} |
... | ... |
@@ -424,11 +424,11 @@ static inline int is_newline(uint32_t c) |
424 | 424 |
|
425 | 425 |
static int dtext_prepare_text(AVFilterContext *ctx) |
426 | 426 |
{ |
427 |
- DrawTextContext *dtext = ctx->priv; |
|
427 |
+ DrawTextContext *s = ctx->priv; |
|
428 | 428 |
uint32_t code = 0, prev_code = 0; |
429 | 429 |
int x = 0, y = 0, i = 0, ret; |
430 | 430 |
int text_height, baseline; |
431 |
- char *text = dtext->text; |
|
431 |
+ char *text = s->text; |
|
432 | 432 |
uint8_t *p; |
433 | 433 |
int str_w = 0, len; |
434 | 434 |
int y_min = 32000, y_max = -32000; |
... | ... |
@@ -441,37 +441,37 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
441 | 441 |
#if HAVE_LOCALTIME_R |
442 | 442 |
time_t now = time(0); |
443 | 443 |
struct tm ltime; |
444 |
- uint8_t *buf = dtext->expanded_text; |
|
445 |
- int buf_size = dtext->expanded_text_size; |
|
444 |
+ uint8_t *buf = s->expanded_text; |
|
445 |
+ int buf_size = s->expanded_text_size; |
|
446 | 446 |
|
447 | 447 |
if (!buf) |
448 |
- buf_size = 2*strlen(dtext->text)+1; |
|
448 |
+ buf_size = 2*strlen(s->text)+1; |
|
449 | 449 |
|
450 | 450 |
localtime_r(&now, <ime); |
451 | 451 |
|
452 | 452 |
while ((buf = av_realloc(buf, buf_size))) { |
453 | 453 |
*buf = 1; |
454 |
- if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0) |
|
454 |
+ if (strftime(buf, buf_size, s->text, <ime) != 0 || *buf == 0) |
|
455 | 455 |
break; |
456 | 456 |
buf_size *= 2; |
457 | 457 |
} |
458 | 458 |
|
459 | 459 |
if (!buf) |
460 | 460 |
return AVERROR(ENOMEM); |
461 |
- text = dtext->expanded_text = buf; |
|
462 |
- dtext->expanded_text_size = buf_size; |
|
461 |
+ text = s->expanded_text = buf; |
|
462 |
+ s->expanded_text_size = buf_size; |
|
463 | 463 |
#endif |
464 | 464 |
|
465 |
- if ((len = strlen(text)) > dtext->nb_positions) { |
|
466 |
- FT_Vector *p = av_realloc(dtext->positions, |
|
467 |
- len * sizeof(*dtext->positions)); |
|
465 |
+ if ((len = strlen(text)) > s->nb_positions) { |
|
466 |
+ FT_Vector *p = av_realloc(s->positions, |
|
467 |
+ len * sizeof(*s->positions)); |
|
468 | 468 |
if (!p) { |
469 |
- av_freep(dtext->positions); |
|
470 |
- dtext->nb_positions = 0; |
|
469 |
+ av_freep(s->positions); |
|
470 |
+ s->nb_positions = 0; |
|
471 | 471 |
return AVERROR(ENOMEM); |
472 | 472 |
} else { |
473 |
- dtext->positions = p; |
|
474 |
- dtext->nb_positions = len; |
|
473 |
+ s->positions = p; |
|
474 |
+ s->nb_positions = len; |
|
475 | 475 |
} |
476 | 476 |
} |
477 | 477 |
|
... | ... |
@@ -481,7 +481,7 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
481 | 481 |
|
482 | 482 |
/* get glyph */ |
483 | 483 |
dummy.code = code; |
484 |
- glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); |
|
484 |
+ glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); |
|
485 | 485 |
if (!glyph) { |
486 | 486 |
ret = load_glyph(ctx, &glyph, code); |
487 | 487 |
if (ret) |
... | ... |
@@ -505,7 +505,7 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
505 | 505 |
|
506 | 506 |
prev_code = code; |
507 | 507 |
if (is_newline(code)) { |
508 |
- str_w = FFMAX(str_w, x - dtext->x); |
|
508 |
+ str_w = FFMAX(str_w, x - s->x); |
|
509 | 509 |
y += text_height; |
510 | 510 |
x = 0; |
511 | 511 |
continue; |
... | ... |
@@ -514,11 +514,11 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
514 | 514 |
/* get glyph */ |
515 | 515 |
prev_glyph = glyph; |
516 | 516 |
dummy.code = code; |
517 |
- glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); |
|
517 |
+ glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); |
|
518 | 518 |
|
519 | 519 |
/* kerning */ |
520 |
- if (dtext->use_kerning && prev_glyph && glyph->code) { |
|
521 |
- FT_Get_Kerning(dtext->face, prev_glyph->code, glyph->code, |
|
520 |
+ if (s->use_kerning && prev_glyph && glyph->code) { |
|
521 |
+ FT_Get_Kerning(s->face, prev_glyph->code, glyph->code, |
|
522 | 522 |
ft_kerning_default, &delta); |
523 | 523 |
x += delta.x >> 6; |
524 | 524 |
} |
... | ... |
@@ -530,19 +530,19 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
530 | 530 |
} |
531 | 531 |
|
532 | 532 |
/* save position */ |
533 |
- dtext->positions[i].x = x + glyph->bitmap_left; |
|
534 |
- dtext->positions[i].y = y - glyph->bitmap_top + baseline; |
|
535 |
- if (code == '\t') x = (x / dtext->tabsize + 1)*dtext->tabsize; |
|
533 |
+ s->positions[i].x = x + glyph->bitmap_left; |
|
534 |
+ s->positions[i].y = y - glyph->bitmap_top + baseline; |
|
535 |
+ if (code == '\t') x = (x / s->tabsize + 1)*s->tabsize; |
|
536 | 536 |
else x += glyph->advance; |
537 | 537 |
} |
538 | 538 |
|
539 | 539 |
str_w = FFMIN(width - 1, FFMAX(str_w, x)); |
540 | 540 |
y = FFMIN(y + text_height, height - 1); |
541 | 541 |
|
542 |
- dtext->w = str_w; |
|
543 |
- dtext->var_values[VAR_TEXT_W] = dtext->var_values[VAR_TW] = dtext->w; |
|
544 |
- dtext->h = y; |
|
545 |
- dtext->var_values[VAR_TEXT_H] = dtext->var_values[VAR_TH] = dtext->h; |
|
542 |
+ s->w = str_w; |
|
543 |
+ s->var_values[VAR_TEXT_W] = s->var_values[VAR_TW] = s->w; |
|
544 |
+ s->h = y; |
|
545 |
+ s->var_values[VAR_TEXT_H] = s->var_values[VAR_TH] = s->h; |
|
546 | 546 |
|
547 | 547 |
return 0; |
548 | 548 |
} |
... | ... |
@@ -551,58 +551,58 @@ static int dtext_prepare_text(AVFilterContext *ctx) |
551 | 551 |
static int config_input(AVFilterLink *inlink) |
552 | 552 |
{ |
553 | 553 |
AVFilterContext *ctx = inlink->dst; |
554 |
- DrawTextContext *dtext = ctx->priv; |
|
554 |
+ DrawTextContext *s = ctx->priv; |
|
555 | 555 |
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); |
556 | 556 |
int ret; |
557 | 557 |
|
558 |
- dtext->hsub = pix_desc->log2_chroma_w; |
|
559 |
- dtext->vsub = pix_desc->log2_chroma_h; |
|
558 |
+ s->hsub = pix_desc->log2_chroma_w; |
|
559 |
+ s->vsub = pix_desc->log2_chroma_h; |
|
560 | 560 |
|
561 |
- dtext->var_values[VAR_E ] = M_E; |
|
562 |
- dtext->var_values[VAR_PHI] = M_PHI; |
|
563 |
- dtext->var_values[VAR_PI ] = M_PI; |
|
561 |
+ s->var_values[VAR_E ] = M_E; |
|
562 |
+ s->var_values[VAR_PHI] = M_PHI; |
|
563 |
+ s->var_values[VAR_PI ] = M_PI; |
|
564 | 564 |
|
565 |
- dtext->var_values[VAR_MAIN_W] = |
|
566 |
- dtext->var_values[VAR_MW] = ctx->inputs[0]->w; |
|
567 |
- dtext->var_values[VAR_MAIN_H] = |
|
568 |
- dtext->var_values[VAR_MH] = ctx->inputs[0]->h; |
|
565 |
+ s->var_values[VAR_MAIN_W] = |
|
566 |
+ s->var_values[VAR_MW] = ctx->inputs[0]->w; |
|
567 |
+ s->var_values[VAR_MAIN_H] = |
|
568 |
+ s->var_values[VAR_MH] = ctx->inputs[0]->h; |
|
569 | 569 |
|
570 |
- dtext->var_values[VAR_X] = 0; |
|
571 |
- dtext->var_values[VAR_Y] = 0; |
|
572 |
- dtext->var_values[VAR_N] = 0; |
|
573 |
- dtext->var_values[VAR_T] = NAN; |
|
570 |
+ s->var_values[VAR_X] = 0; |
|
571 |
+ s->var_values[VAR_Y] = 0; |
|
572 |
+ s->var_values[VAR_N] = 0; |
|
573 |
+ s->var_values[VAR_T] = NAN; |
|
574 | 574 |
|
575 |
- av_lfg_init(&dtext->prng, av_get_random_seed()); |
|
575 |
+ av_lfg_init(&s->prng, av_get_random_seed()); |
|
576 | 576 |
|
577 |
- if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names, |
|
577 |
+ if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, |
|
578 | 578 |
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || |
579 |
- (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names, |
|
579 |
+ (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names, |
|
580 | 580 |
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || |
581 |
- (ret = av_expr_parse(&dtext->d_pexpr, dtext->d_expr, var_names, |
|
581 |
+ (ret = av_expr_parse(&s->d_pexpr, s->d_expr, var_names, |
|
582 | 582 |
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0) |
583 | 583 |
return AVERROR(EINVAL); |
584 | 584 |
|
585 | 585 |
if ((ret = |
586 |
- ff_fill_line_with_color(dtext->box_line, dtext->pixel_step, |
|
587 |
- inlink->w, dtext->boxcolor, |
|
588 |
- inlink->format, dtext->boxcolor_rgba, |
|
589 |
- &dtext->is_packed_rgb, dtext->rgba_map)) < 0) |
|
586 |
+ ff_fill_line_with_color(s->box_line, s->pixel_step, |
|
587 |
+ inlink->w, s->boxcolor, |
|
588 |
+ inlink->format, s->boxcolor_rgba, |
|
589 |
+ &s->is_packed_rgb, s->rgba_map)) < 0) |
|
590 | 590 |
return ret; |
591 | 591 |
|
592 |
- if (!dtext->is_packed_rgb) { |
|
593 |
- uint8_t *rgba = dtext->fontcolor_rgba; |
|
594 |
- dtext->fontcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); |
|
595 |
- dtext->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
596 |
- dtext->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
597 |
- dtext->fontcolor[3] = rgba[3]; |
|
598 |
- rgba = dtext->shadowcolor_rgba; |
|
599 |
- dtext->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); |
|
600 |
- dtext->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
601 |
- dtext->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
602 |
- dtext->shadowcolor[3] = rgba[3]; |
|
592 |
+ if (!s->is_packed_rgb) { |
|
593 |
+ uint8_t *rgba = s->fontcolor_rgba; |
|
594 |
+ s->fontcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); |
|
595 |
+ s->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
596 |
+ s->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
597 |
+ s->fontcolor[3] = rgba[3]; |
|
598 |
+ rgba = s->shadowcolor_rgba; |
|
599 |
+ s->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); |
|
600 |
+ s->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
601 |
+ s->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); |
|
602 |
+ s->shadowcolor[3] = rgba[3]; |
|
603 | 603 |
} |
604 | 604 |
|
605 |
- dtext->draw = 1; |
|
605 |
+ s->draw = 1; |
|
606 | 606 |
|
607 | 607 |
return dtext_prepare_text(ctx); |
608 | 608 |
} |
... | ... |
@@ -705,10 +705,10 @@ static inline void drawbox(AVFrame *frame, unsigned int x, unsigned int y, |
705 | 705 |
} |
706 | 706 |
} |
707 | 707 |
|
708 |
-static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, |
|
708 |
+static int draw_glyphs(DrawTextContext *s, AVFrame *frame, |
|
709 | 709 |
int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y) |
710 | 710 |
{ |
711 |
- char *text = HAVE_LOCALTIME_R ? dtext->expanded_text : dtext->text; |
|
711 |
+ char *text = HAVE_LOCALTIME_R ? s->expanded_text : s->text; |
|
712 | 712 |
uint32_t code = 0; |
713 | 713 |
int i; |
714 | 714 |
uint8_t *p; |
... | ... |
@@ -723,20 +723,20 @@ static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, |
723 | 723 |
continue; |
724 | 724 |
|
725 | 725 |
dummy.code = code; |
726 |
- glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); |
|
726 |
+ glyph = av_tree_find(s->glyphs, &dummy, (void *)glyph_cmp, NULL); |
|
727 | 727 |
|
728 | 728 |
if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && |
729 | 729 |
glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) |
730 | 730 |
return AVERROR(EINVAL); |
731 | 731 |
|
732 |
- if (dtext->is_packed_rgb) { |
|
732 |
+ if (s->is_packed_rgb) { |
|
733 | 733 |
draw_glyph_rgb(frame, &glyph->bitmap, |
734 |
- dtext->positions[i].x+x, dtext->positions[i].y+y, width, height, |
|
735 |
- dtext->pixel_step[0], rgbcolor, dtext->rgba_map); |
|
734 |
+ s->positions[i].x+x, s->positions[i].y+y, width, height, |
|
735 |
+ s->pixel_step[0], rgbcolor, s->rgba_map); |
|
736 | 736 |
} else { |
737 | 737 |
draw_glyph_yuv(frame, &glyph->bitmap, |
738 |
- dtext->positions[i].x+x, dtext->positions[i].y+y, width, height, |
|
739 |
- yuvcolor, dtext->hsub, dtext->vsub); |
|
738 |
+ s->positions[i].x+x, s->positions[i].y+y, width, height, |
|
739 |
+ yuvcolor, s->hsub, s->vsub); |
|
740 | 740 |
} |
741 | 741 |
} |
742 | 742 |
|
... | ... |
@@ -746,30 +746,30 @@ static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, |
746 | 746 |
static int draw_text(AVFilterContext *ctx, AVFrame *frame, |
747 | 747 |
int width, int height) |
748 | 748 |
{ |
749 |
- DrawTextContext *dtext = ctx->priv; |
|
749 |
+ DrawTextContext *s = ctx->priv; |
|
750 | 750 |
int ret; |
751 | 751 |
|
752 | 752 |
/* draw box */ |
753 |
- if (dtext->draw_box) |
|
754 |
- drawbox(frame, dtext->x, dtext->y, dtext->w, dtext->h, |
|
755 |
- dtext->box_line, dtext->pixel_step, dtext->boxcolor, |
|
756 |
- dtext->hsub, dtext->vsub, dtext->is_packed_rgb, |
|
757 |
- dtext->rgba_map); |
|
758 |
- |
|
759 |
- if (dtext->shadowx || dtext->shadowy) { |
|
760 |
- if ((ret = draw_glyphs(dtext, frame, width, height, |
|
761 |
- dtext->shadowcolor_rgba, |
|
762 |
- dtext->shadowcolor, |
|
763 |
- dtext->x + dtext->shadowx, |
|
764 |
- dtext->y + dtext->shadowy)) < 0) |
|
753 |
+ if (s->draw_box) |
|
754 |
+ drawbox(frame, s->x, s->y, s->w, s->h, |
|
755 |
+ s->box_line, s->pixel_step, s->boxcolor, |
|
756 |
+ s->hsub, s->vsub, s->is_packed_rgb, |
|
757 |
+ s->rgba_map); |
|
758 |
+ |
|
759 |
+ if (s->shadowx || s->shadowy) { |
|
760 |
+ if ((ret = draw_glyphs(s, frame, width, height, |
|
761 |
+ s->shadowcolor_rgba, |
|
762 |
+ s->shadowcolor, |
|
763 |
+ s->x + s->shadowx, |
|
764 |
+ s->y + s->shadowy)) < 0) |
|
765 | 765 |
return ret; |
766 | 766 |
} |
767 | 767 |
|
768 |
- if ((ret = draw_glyphs(dtext, frame, width, height, |
|
769 |
- dtext->fontcolor_rgba, |
|
770 |
- dtext->fontcolor, |
|
771 |
- dtext->x, |
|
772 |
- dtext->y)) < 0) |
|
768 |
+ if ((ret = draw_glyphs(s, frame, width, height, |
|
769 |
+ s->fontcolor_rgba, |
|
770 |
+ s->fontcolor, |
|
771 |
+ s->x, |
|
772 |
+ s->y)) < 0) |
|
773 | 773 |
return ret; |
774 | 774 |
|
775 | 775 |
return 0; |
... | ... |
@@ -793,7 +793,7 @@ static inline int normalize_double(int *n, double d) |
793 | 793 |
static int filter_frame(AVFilterLink *inlink, AVFrame *frame) |
794 | 794 |
{ |
795 | 795 |
AVFilterContext *ctx = inlink->dst; |
796 |
- DrawTextContext *dtext = ctx->priv; |
|
796 |
+ DrawTextContext *s = ctx->priv; |
|
797 | 797 |
int ret = 0; |
798 | 798 |
|
799 | 799 |
if ((ret = dtext_prepare_text(ctx)) < 0) { |
... | ... |
@@ -802,40 +802,40 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) |
802 | 802 |
return ret; |
803 | 803 |
} |
804 | 804 |
|
805 |
- dtext->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ? |
|
805 |
+ s->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ? |
|
806 | 806 |
NAN : frame->pts * av_q2d(inlink->time_base); |
807 |
- dtext->var_values[VAR_X] = |
|
808 |
- av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); |
|
809 |
- dtext->var_values[VAR_Y] = |
|
810 |
- av_expr_eval(dtext->y_pexpr, dtext->var_values, &dtext->prng); |
|
811 |
- dtext->var_values[VAR_X] = |
|
812 |
- av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); |
|
813 |
- |
|
814 |
- dtext->draw = av_expr_eval(dtext->d_pexpr, dtext->var_values, &dtext->prng); |
|
815 |
- |
|
816 |
- normalize_double(&dtext->x, dtext->var_values[VAR_X]); |
|
817 |
- normalize_double(&dtext->y, dtext->var_values[VAR_Y]); |
|
818 |
- |
|
819 |
- if (dtext->fix_bounds) { |
|
820 |
- if (dtext->x < 0) dtext->x = 0; |
|
821 |
- if (dtext->y < 0) dtext->y = 0; |
|
822 |
- if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w) |
|
823 |
- dtext->x = inlink->w - dtext->w; |
|
824 |
- if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h) |
|
825 |
- dtext->y = inlink->h - dtext->h; |
|
807 |
+ s->var_values[VAR_X] = |
|
808 |
+ av_expr_eval(s->x_pexpr, s->var_values, &s->prng); |
|
809 |
+ s->var_values[VAR_Y] = |
|
810 |
+ av_expr_eval(s->y_pexpr, s->var_values, &s->prng); |
|
811 |
+ s->var_values[VAR_X] = |
|
812 |
+ av_expr_eval(s->x_pexpr, s->var_values, &s->prng); |
|
813 |
+ |
|
814 |
+ s->draw = av_expr_eval(s->d_pexpr, s->var_values, &s->prng); |
|
815 |
+ |
|
816 |
+ normalize_double(&s->x, s->var_values[VAR_X]); |
|
817 |
+ normalize_double(&s->y, s->var_values[VAR_Y]); |
|
818 |
+ |
|
819 |
+ if (s->fix_bounds) { |
|
820 |
+ if (s->x < 0) s->x = 0; |
|
821 |
+ if (s->y < 0) s->y = 0; |
|
822 |
+ if ((unsigned)s->x + (unsigned)s->w > inlink->w) |
|
823 |
+ s->x = inlink->w - s->w; |
|
824 |
+ if ((unsigned)s->y + (unsigned)s->h > inlink->h) |
|
825 |
+ s->y = inlink->h - s->h; |
|
826 | 826 |
} |
827 | 827 |
|
828 |
- dtext->x &= ~((1 << dtext->hsub) - 1); |
|
829 |
- dtext->y &= ~((1 << dtext->vsub) - 1); |
|
828 |
+ s->x &= ~((1 << s->hsub) - 1); |
|
829 |
+ s->y &= ~((1 << s->vsub) - 1); |
|
830 | 830 |
|
831 | 831 |
av_dlog(ctx, "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", |
832 |
- (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T], |
|
833 |
- dtext->x, dtext->y, dtext->x+dtext->w, dtext->y+dtext->h); |
|
832 |
+ (int)s->var_values[VAR_N], s->var_values[VAR_T], |
|
833 |
+ s->x, s->y, s->x+s->w, s->y+s->h); |
|
834 | 834 |
|
835 |
- if (dtext->draw) |
|
835 |
+ if (s->draw) |
|
836 | 836 |
draw_text(inlink->dst, frame, frame->width, frame->height); |
837 | 837 |
|
838 |
- dtext->var_values[VAR_N] += 1.0; |
|
838 |
+ s->var_values[VAR_N] += 1.0; |
|
839 | 839 |
|
840 | 840 |
return ff_filter_frame(inlink->dst->outputs[0], frame); |
841 | 841 |
} |