drawtext filter, based on the original vhook/drawtext.c filter by Gustavo Sverzut Barbieri More...
#include <sys/time.h>
#include <time.h>
#include "libavutil/colorspace.h"
#include "libavutil/file.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/mathematics.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/tree.h"
#include "libavutil/lfg.h"
#include "avfilter.h"
#include "drawutils.h"
#include <ft2build.h>
#include <freetype/config/ftheader.h>
#include <FT_FREETYPE_H>
#include <FT_GLYPH_H>
#include <FT_ERRORS_H>
Go to the source code of this file.
drawtext filter, based on the original vhook/drawtext.c filter by Gustavo Sverzut Barbieri
Definition in file vf_drawtext.c.
#define FT_ERROR_END_LIST { 0, NULL } }; |
Definition at line 195 of file vf_drawtext.c.
#define FT_ERROR_START_LIST { |
Definition at line 193 of file vf_drawtext.c.
#define FT_ERRORDEF | ( | e, | |
v, | |||
s | |||
) | { (e), (s) }, |
Definition at line 194 of file vf_drawtext.c.
#define GET_BITMAP_VAL | ( | r, | |
c | |||
) |
bitmap->pixel_mode == FT_PIXEL_MODE_MONO ? \ (bitmap->buffer[(r) * bitmap->pitch + ((c)>>3)] & (0x80 >> ((c)&7))) * 255 : \ bitmap->buffer[(r) * bitmap->pitch + (c)]
Definition at line 616 of file vf_drawtext.c.
Referenced by draw_glyph_rgb(), and draw_glyph_yuv().
#define OFFSET | ( | x | ) | offsetof(DrawTextContext, x) |
Definition at line 143 of file vf_drawtext.c.
#define SET_PIXEL_RGB | ( | picref, | |
rgba_color, | |||
val, | |||
x, | |||
y, | |||
pixel_step, | |||
r_off, | |||
g_off, | |||
b_off, | |||
a_off | |||
) |
{ \ p = picref->data[0] + (x) * pixel_step + ((y) * picref->linesize[0]); \ alpha = rgba_color[3] * (val) * 129; \ *(p+r_off) = (alpha * rgba_color[0] + (255*255*129 - alpha) * *(p+r_off)) >> 23; \ *(p+g_off) = (alpha * rgba_color[1] + (255*255*129 - alpha) * *(p+g_off)) >> 23; \ *(p+b_off) = (alpha * rgba_color[2] + (255*255*129 - alpha) * *(p+b_off)) >> 23; \ }
Definition at line 655 of file vf_drawtext.c.
Referenced by draw_glyph_rgb(), and drawbox().
#define SET_PIXEL_YUV | ( | picref, | |
yuva_color, | |||
val, | |||
x, | |||
y, | |||
hsub, | |||
vsub | |||
) |
{ \ luma_pos = ((x) ) + ((y) ) * picref->linesize[0]; \ alpha = yuva_color[3] * (val) * 129; \ picref->data[0][luma_pos] = (alpha * yuva_color[0] + (255*255*129 - alpha) * picref->data[0][luma_pos] ) >> 23; \ if (((x) & ((1<<(hsub)) - 1)) == 0 && ((y) & ((1<<(vsub)) - 1)) == 0) {\ chroma_pos1 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[1]; \ chroma_pos2 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[2]; \ picref->data[1][chroma_pos1] = (alpha * yuva_color[1] + (255*255*129 - alpha) * picref->data[1][chroma_pos1]) >> 23; \ picref->data[2][chroma_pos2] = (alpha * yuva_color[2] + (255*255*129 - alpha) * picref->data[2][chroma_pos2]) >> 23; \ }\ }
Definition at line 621 of file vf_drawtext.c.
Referenced by draw_glyph_yuv(), and drawbox().
typedef double(* eval_func2)(void *, double a, double b) |
Definition at line 76 of file vf_drawtext.c.
enum var_name |
Definition at line 83 of file vf_drawtext.c.
static int config_input | ( | AVFilterLink * | inlink | ) | [static] |
Definition at line 557 of file vf_drawtext.c.
Definition at line 71 of file vf_drawtext.c.
static int draw_glyph_rgb | ( | AVFilterBufferRef * | picref, |
FT_Bitmap * | bitmap, | ||
unsigned int | x, | ||
unsigned int | y, | ||
unsigned int | width, | ||
unsigned int | height, | ||
int | pixel_step, | ||
const uint8_t | rgba_color[4], | ||
const uint8_t | rgba_map[4] | ||
) | [inline, static] |
Definition at line 663 of file vf_drawtext.c.
Referenced by draw_glyphs().
static int draw_glyph_yuv | ( | AVFilterBufferRef * | picref, |
FT_Bitmap * | bitmap, | ||
unsigned int | x, | ||
unsigned int | y, | ||
unsigned int | width, | ||
unsigned int | height, | ||
const uint8_t | yuva_color[4], | ||
int | hsub, | ||
int | vsub | ||
) | [inline, static] |
Definition at line 633 of file vf_drawtext.c.
Referenced by draw_glyphs().
static int draw_glyphs | ( | DrawTextContext * | dtext, |
AVFilterBufferRef * | picref, | ||
int | width, | ||
int | height, | ||
const uint8_t | rgbcolor[4], | ||
const uint8_t | yuvcolor[4], | ||
int | x, | ||
int | y | ||
) | [static] |
Definition at line 714 of file vf_drawtext.c.
Referenced by draw_text().
static int draw_text | ( | AVFilterContext * | ctx, |
AVFilterBufferRef * | picref, | ||
int | width, | ||
int | height | ||
) | [static] |
Definition at line 752 of file vf_drawtext.c.
Referenced by end_frame().
static void drawbox | ( | AVFilterBufferRef * | picref, |
unsigned int | x, | ||
unsigned int | y, | ||
unsigned int | width, | ||
unsigned int | height, | ||
uint8_t * | line[4], | ||
int | pixel_step[4], | ||
uint8_t | color[4], | ||
int | hsub, | ||
int | vsub, | ||
int | is_rgba_packed, | ||
uint8_t | rgba_map[4] | ||
) | [inline, static] |
Definition at line 687 of file vf_drawtext.c.
Referenced by avfilter_register_all(), config_input(), draw_slice(), draw_text(), and init().
static const char* drawtext_get_name | ( | void * | ctx | ) | [static] |
Definition at line 181 of file vf_drawtext.c.
static int dtext_prepare_text | ( | AVFilterContext * | ctx | ) | [static] |
Definition at line 435 of file vf_drawtext.c.
Referenced by config_input(), and start_frame().
static void end_frame | ( | AVFilterLink * | inlink | ) | [static] |
Definition at line 844 of file vf_drawtext.c.
Definition at line 216 of file vf_drawtext.c.
Referenced by draw_glyphs(), dtext_prepare_text(), and load_glyph().
static int glyph_enu_free | ( | void * | opaque, |
void * | elem | ||
) | [static] |
Definition at line 399 of file vf_drawtext.c.
Referenced by uninit().
static av_cold int init | ( | AVFilterContext * | ctx, |
const char * | args, | ||
void * | opaque | ||
) | [static] |
Definition at line 277 of file vf_drawtext.c.
static int is_newline | ( | uint32_t | c | ) | [inline, static] |
Definition at line 430 of file vf_drawtext.c.
Referenced by dtext_prepare_text().
static int load_glyph | ( | AVFilterContext * | ctx, |
Glyph ** | glyph_ptr, | ||
uint32_t | code | ||
) | [static] |
Load glyphs corresponding to the UTF-32 codepoint code.
Definition at line 226 of file vf_drawtext.c.
Referenced by dtext_prepare_text(), and init().
static int normalize_double | ( | int * | n, |
double | d | ||
) | [inline, static] |
Definition at line 786 of file vf_drawtext.c.
Referenced by start_frame().
static void null_draw_slice | ( | AVFilterLink * | link, |
int | y, | ||
int | h, | ||
int | slice_dir | ||
) | [static] |
Definition at line 784 of file vf_drawtext.c.
static int query_formats | ( | AVFilterContext * | ctx | ) | [static] |
Definition at line 383 of file vf_drawtext.c.
static void start_frame | ( | AVFilterLink * | inlink, |
AVFilterBufferRef * | inpicref | ||
) | [static] |
Definition at line 801 of file vf_drawtext.c.
static av_cold void uninit | ( | AVFilterContext * | ctx | ) | [static] |
Definition at line 405 of file vf_drawtext.c.
{ .name = "drawtext", .description = NULL_IF_CONFIG_SMALL("Draw text on top of video frames using libfreetype library."), .priv_size = sizeof(DrawTextContext), .init = init, .uninit = uninit, .query_formats = query_formats, .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, .get_video_buffer = avfilter_null_get_video_buffer, .start_frame = start_frame, .draw_slice = null_draw_slice, .end_frame = end_frame, .config_props = config_input, .min_perms = AV_PERM_WRITE | AV_PERM_READ, .rej_perms = AV_PERM_PRESERVE }, { .name = NULL}}, .outputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, }, { .name = NULL}}, }
Definition at line 859 of file vf_drawtext.c.
const AVClass drawtext_class [static] |
{ "DrawTextContext", drawtext_get_name, drawtext_options }
Definition at line 186 of file vf_drawtext.c.
Referenced by init().
const AVOption drawtext_options[] [static] |
Definition at line 145 of file vf_drawtext.c.
const eval_func2 fun2[] [static] |
Definition at line 78 of file vf_drawtext.c.
Referenced by config_input().
const char* fun2_names[] [static] |
{
"rand",
}
Definition at line 67 of file vf_drawtext.c.
Referenced by config_input().
const char* var_names[] [static] |
{ "E", "PHI", "PI", "main_w", "W", "main_h", "H", "text_w", "w", "text_h", "h", "x", "y", "n", "t", NULL }
Definition at line 52 of file vf_drawtext.c.
Referenced by config_input().