int main(void) { int i; AVTreeNode *root = NULL, *node = NULL; AVLFG prng; av_lfg_init(&prng, 1); for (i = 0; i < 10000; i++) { AVTreeNode *node2 = NULL; intptr_t j = av_lfg_get(&prng) % 86294; void *ret, *jj = (void *)(j + 1); while (ret = av_tree_find(root, jj, cmp, NULL)) { j = av_lfg_get(&prng) % 86294; jj = (void *)(j + 1); } if (check(root) > 999) { av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return 1; } if (!node) node = av_tree_node_alloc(); if (!node) { av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); return 1; } av_tree_insert(&root, jj, cmp, &node); while (ret = av_tree_find(root, jj, cmp, NULL)) { j = av_lfg_get(&prng) % 86294; jj = (void *)(j + 1); } ret = av_tree_insert(&root, jj, cmp, &node2); if (ret != jj) av_tree_destroy(node2); ret = av_tree_find(root, jj, cmp, NULL); if (ret) av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); } av_tree_destroy(root); return 0; }
static int dtext_prepare_text(AVFilterContext *ctx) { DrawTextContext *s = ctx->priv; uint32_t code = 0, prev_code = 0; int x = 0, y = 0, i = 0, ret; int text_height, baseline; char *text; uint8_t *p; int str_w = 0, len; int y_min = 32000, y_max = -32000; FT_Vector delta; Glyph *glyph = NULL, *prev_glyph = NULL; Glyph dummy = { 0 }; int width = ctx->inputs[0]->w; int height = ctx->inputs[0]->h; ret = expand_strftime(s); if (ret < 0) return ret; text = s->expanded_text ? s->expanded_text : s->text; if ((len = strlen(text)) > s->nb_positions) { FT_Vector *p = av_realloc(s->positions, len * sizeof(*s->positions)); if (!p) { av_freep(s->positions); s->nb_positions = 0; return AVERROR(ENOMEM); } else { s->positions = p; s->nb_positions = len; } } /* load and cache glyphs */ for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); /* get glyph */ dummy.code = code; glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); if (!glyph) { ret = load_glyph(ctx, &glyph, code); if (ret) return ret; } y_min = FFMIN(glyph->bbox.yMin, y_min); y_max = FFMAX(glyph->bbox.yMax, y_max); }
int main(int argc, char **argv) { int i; void *k; AVTreeNode *root = NULL, *node = NULL; AVLFG prng; int log_level = argc <= 1 ? AV_LOG_INFO : atoi(argv[1]); av_log_set_level(log_level); av_lfg_init(&prng, 1); for (i = 0; i < 10000; i++) { intptr_t j = av_lfg_get(&prng) % 86294; if (check(root) > 999) { av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return 1; } av_log(NULL, AV_LOG_DEBUG, "inserting %4d\n", (int)j); if (!node) node = av_tree_node_alloc(); if (!node) { av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); return 1; } av_tree_insert(&root, (void *)(j + 1), cmp, &node); j = av_lfg_get(&prng) % 86294; { AVTreeNode *node2 = NULL; av_log(NULL, AV_LOG_DEBUG, "removing %4d\n", (int)j); av_tree_insert(&root, (void *)(j + 1), cmp, &node2); k = av_tree_find(root, (void *)(j + 1), cmp, NULL); if (k) av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); av_free(node2); } } av_free(node); av_tree_destroy(root); return 0; }
static int draw_glyphs(DrawTextContext *s, AVFrame *frame, int width, int height, FFDrawColor *color, int x, int y, int borderw) { char *text = s->expanded_text.str; uint32_t code = 0; int i, x1, y1; uint8_t *p; Glyph *glyph = NULL; for (i = 0, p = text; *p; i++) { FT_Bitmap bitmap; Glyph dummy = { 0 }; GET_UTF8(code, *p++, continue;); /* skip new line chars, just go to new line */ if (code == '\n' || code == '\r' || code == '\t') continue; dummy.code = code; glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); bitmap = borderw ? glyph->border_bitmap : glyph->bitmap; if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) return AVERROR(EINVAL); x1 = s->positions[i].x+s->x+x - borderw; y1 = s->positions[i].y+s->y+y - borderw; ff_blend_mask(&s->dc, color, frame->data, frame->linesize, width, height, bitmap.buffer, bitmap.pitch, bitmap.width, bitmap.rows, bitmap.pixel_mode == FT_PIXEL_MODE_MONO ? 0 : 3, 0, x1, y1); }
static int dtext_prepare_text(AVFilterContext *ctx) { DrawTextContext *s = ctx->priv; uint32_t code = 0, prev_code = 0; int x = 0, y = 0, i = 0, ret; int text_height, baseline; char *text = s->text; uint8_t *p; int str_w = 0, len; int y_min = 32000, y_max = -32000; FT_Vector delta; Glyph *glyph = NULL, *prev_glyph = NULL; Glyph dummy = { 0 }; int width = ctx->inputs[0]->w; int height = ctx->inputs[0]->h; time_t now = time(0); struct tm ltime; uint8_t *buf = s->expanded_text; int buf_size = s->expanded_text_size; if (!buf) buf_size = 2*strlen(s->text)+1; localtime_r(&now, <ime); while ((buf = av_realloc(buf, buf_size))) { *buf = 1; if (strftime(buf, buf_size, s->text, <ime) != 0 || *buf == 0) break; buf_size *= 2; } if (!buf) return AVERROR(ENOMEM); text = s->expanded_text = buf; s->expanded_text_size = buf_size; if ((len = strlen(text)) > s->nb_positions) { FT_Vector *p = av_realloc(s->positions, len * sizeof(*s->positions)); if (!p) { av_freep(s->positions); s->nb_positions = 0; return AVERROR(ENOMEM); } else { s->positions = p; s->nb_positions = len; } } /* load and cache glyphs */ for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); /* get glyph */ dummy.code = code; glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); if (!glyph) { ret = load_glyph(ctx, &glyph, code); if (ret) return ret; } y_min = FFMIN(glyph->bbox.yMin, y_min); y_max = FFMAX(glyph->bbox.yMax, y_max); }