32#include "config_components.h"
78 "rendered_padded_qr_w",
"Q",
87#define V(name_) qr->var_values[VAR_##name_]
150#define OFFSET(x) offsetof(QREncodeContext, x)
151#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
152#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
154#define COMMON_OPTIONS \
155 { "qrcode_width", "set rendered QR code width expression", OFFSET(rendered_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "64"}, 0, INT_MAX, FLAGS }, \
156 { "q", "set rendered QR code width expression", OFFSET(rendered_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "64"}, 0, INT_MAX, FLAGS }, \
157 { "padded_qrcode_width", "set rendered padded QR code width expression", OFFSET(rendered_padded_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "q"}, 0, INT_MAX, FLAGS }, \
158 { "Q", "set rendered padded QR code width expression", OFFSET(rendered_padded_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "q"}, 0, INT_MAX, FLAGS }, \
159 { "case_sensitive", "generate code which is case sensitive", OFFSET(case_sensitive), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, \
160 { "cs", "generate code which is case sensitive", OFFSET(case_sensitive), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, \
162 { "level", "error correction level, lowest is L", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, QR_ECLEVEL_H, .flags = FLAGS, .unit = "level"}, \
163 { "l", "error correction level, lowest is L", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, QR_ECLEVEL_H, .flags = FLAGS, .unit = "level"}, \
164 { "L", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_L }, 0, 0, FLAGS, .unit = "level" }, \
165 { "M", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_M }, 0, 0, FLAGS, .unit = "level" }, \
166 { "Q", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_Q }, 0, 0, FLAGS, .unit = "level" }, \
167 { "H", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_H }, 0, 0, FLAGS, .unit = "level" }, \
169 {"expansion", "set the expansion mode", OFFSET(expansion), AV_OPT_TYPE_INT, {.i64=EXPANSION_NORMAL}, 0, 2, FLAGS, .unit = "expansion"}, \
170 {"none", "set no expansion", OFFSET(expansion), AV_OPT_TYPE_CONST, {.i64 = EXPANSION_NONE}, 0, 0, FLAGS, .unit = "expansion"}, \
171 {"normal", "set normal expansion", OFFSET(expansion), AV_OPT_TYPE_CONST, {.i64 = EXPANSION_NORMAL}, 0, 0, FLAGS, .unit = "expansion"}, \
173 { "foreground_color", "set QR foreground color", OFFSET(foreground_color), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS }, \
174 { "fc", "set QR foreground color", OFFSET(foreground_color), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS }, \
175 { "background_color", "set QR background color", OFFSET(background_color), AV_OPT_TYPE_COLOR, {.str = "white"}, 0, 0, FLAGS }, \
176 { "bc", "set QR background color", OFFSET(background_color), AV_OPT_TYPE_COLOR, {.str = "white"}, 0, 0, FLAGS }, \
178 {"text", "set text to encode", OFFSET(text), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, \
179 {"textfile", "set text file to encode", OFFSET(textfile), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, \
190static const ff_eval_func2
fun2[] = {
195static int func_pts(
void *
ctx, AVBPrint *bp,
const char *function_name,
196 unsigned argc,
char **argv)
200 const char *strftime_fmt =
NULL;
206 fmt = argc >= 1 ? argv[0] :
"flt";
211 strftime_fmt = argv[2];
218 unsigned argc,
char **argv)
227 unsigned argc,
char **argv)
229 const char *strftime_fmt = argc ? argv[0] :
NULL;
231 return ff_print_time(
ctx, bp, strftime_fmt, !strcmp(function_name,
"localtime"));
235 unsigned argc,
char **argv)
249 unsigned argc,
char **argv)
259 unsigned argc,
char **argv)
275 " to print: '%s'\n", argv[2]);
313 "Both text and text file provided. Please provide only one\n");
350 const char *p = qrcode->data;
354 for (
i = 0;
i < qrcode->width;
i++) {
355 for (j = 0; j < qrcode->width; j++)
356 line[j] = (*p++)&1 ?
'@' :
' ';
368 QRcode *qrcode =
NULL;
370 char qrcode_width_changed;
374 uint8_t *dstp0, *dstp;
404 "Failed to encode string with error \'%s\'\n",
av_err2str(ret));
409 "Encoded QR with width:%d version:%d\n", qrcode->width, qrcode->version);
414 qrcode_width_changed = qr->
qrcode_width != qrcode->width;
418 if (qrcode_width_changed) {
421 qrcode->width, qrcode->width,
425 "Failed to allocate image for QR code with width %d\n", qrcode->width);
434 for (
i = 0;
i < qrcode->width;
i++) {
436 for (j = 0; j < qrcode->width; j++)
437 *dstp++ = (*srcp++ & 1) ? 255 : 0;
442 if (qrcode_width_changed) {
456 "Failed to allocate image for QR code with width %d\n",
498#define EVAL_EXPR(name_) \
499 av_expr_eval(qr->name_##_pexpr, qr->var_values, &qr->lfg);
501 V(qr_w) =
V(
w) = qrcode->width;
503 V(rendered_qr_w) =
V(q) = EVAL_EXPR(rendered_qrcode_width);
504 V(rendered_padded_qr_w) =
V(
Q) = EVAL_EXPR(rendered_padded_qrcode_width);
506 V(rendered_qr_w) =
V(q) = EVAL_EXPR(rendered_qrcode_width);
514 "Rendering QR code with values n:%d w:%d q:%d Q:%d x:%d y:%d t:%f\n",
515 (
int)
V(n), (
int)
V(
w), (
int)
V(q), (
int)
V(
Q), (
int)
V(x), (
int)
V(y),
V(t));
531 "Failed to allocate image for rendered QR code with width %d\n",
576#if CONFIG_QRENCODESRC_FILTER
597#define PARSE_AND_EVAL_EXPR(var_name_, expr_name_) \
598 ret = av_expr_parse_and_eval(&qr->var_values[VAR_##var_name_], \
599 qr->expr_name_##_expr, \
600 var_names, qr->var_values, \
605 av_log(ctx, AV_LOG_ERROR, \
606 "Could not evaluate expression '%s'\n", \
607 qr->expr_name_##_expr); \
614 V(x) =
V(y) =
V(t) =
V(n) =
NAN;
615 V(dar) =
V(sar) = 1.0;
617 PARSE_AND_EVAL_EXPR(rendered_qr_w, rendered_qrcode_width);
618 V(q) =
V(rendered_qr_w);
619 PARSE_AND_EVAL_EXPR(rendered_padded_qr_w, rendered_padded_qrcode_width);
620 V(
Q) =
V(rendered_padded_qr_w);
621 PARSE_AND_EVAL_EXPR(rendered_qr_w, rendered_qrcode_width);
622 V(q) =
V(rendered_qr_w);
628 "q:%d Q:%d case_sensitive:%d level:%d\n",
634 "Resulting padded QR code width (%d) is lesser than the QR code width (%d)\n",
713 .p.name =
"qrencodesrc",
715 .p.priv_class = &qrencodesrc_class,
726#if CONFIG_QRENCODE_FILTER
752 V(
W) =
V(main_w) = inlink->
w;
753 V(
H) =
V(main_h) = inlink->
h;
755 V(dar) = (
double)inlink->
w / inlink->
h *
V(sar);
764#define PARSE_EXPR(name_) \
765 ret = av_expr_parse(&qr->name_##_pexpr, expr = qr->name_##_expr, var_names, \
766 NULL, NULL, fun2_names, fun2, 0, ctx); \
768 av_log(ctx, AV_LOG_ERROR, \
769 "Could not to parse expression '%s' for '%s'\n", \
771 return AVERROR(EINVAL); \
810 V(pict_type) =
frame->pict_type;
832 .p.name =
"qrencode",
834 .p.priv_class = &qrencode_class,
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vsrc_qrencodesrc
const FFFilter ff_vf_qrencode
static AVFormatContext * ctx
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define i(width, name, range_min, range_max)
static enum AVPixelFormat pix_fmt
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h)
Blend a rectangle with an uniform color.
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
int ff_draw_init_from_link(FFDrawContext *draw, const AVFilterLink *link, unsigned flags)
Init a draw context, taking the format, colorspace and range from the given filter link.
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
int(* init)(AVBSFContext *ctx)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
#define AV_NOPTS_VALUE
Undefined timestamp value.
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
@ SWS_POINT
nearest neighbor
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
static const char *const var_names[]
#define sws_isSupportedOutput(x)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int qrencode_config_input(AVFilterLink *inlink)
@ VAR_rendered_padded_qr_w
static int qrencodesrc_config_props(AVFilterLink *outlink)
static void show_qrcode(AVFilterContext *ctx, const QRcode *qrcode)
static int draw_qrcode(AVFilterContext *ctx, AVFrame *frame)
static int func_eval_expr(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static int func_strftime(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static int qrencode_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int request_frame(AVFilterLink *outlink)
static const ff_eval_func2 fun2[]
static int func_pts(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static const AVOption qrencodesrc_options[]
static const AVFilterPad qrencodesrc_outputs[]
static double drand(void *opaque, double min, double max)
static int func_frame_num(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static int func_eval_expr_formatted(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static const char *const fun2_names[]
static av_cold void uninit(AVFilterContext *ctx)
static int qrencodesrc_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const AVOption qrencode_options[]
static int func_frame_metadata(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static const AVFilterPad avfilter_vf_qrencode_inputs[]
static const FFExpandTextFunction expand_text_functions[]
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
Rational number (pair of numerator and denominator).
Text expander context, used to encapsulate the logic to expand a given text template.
Function used to expand a template sequence in the format %{FUNCTION_NAME[:PARAMS]}...
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
FFExpandTextContext expand_text
expand text in case expansion is enabled
int qrcode_mask_linesize[4]
int expansion
expansion mode to use for the text
AVExpr * rendered_qrcode_width_pexpr
char * rendered_padded_qrcode_width_expr
AVLFG lfg
random generator
AVExpr * rendered_padded_qrcode_width_pexpr
FFDrawColor draw0_background_color
background color
FFDrawColor draw_foreground_color
foreground color
int rendered_qrcode_linesize[4]
int rendered_padded_qrcode_width
FFDrawColor draw_background_color
background color
int rendered_qrcode_width
uint8_t background_color[4]
double var_values[VAR_VARS_NB]
AVBPrint expanded_text
used to contain the expanded text
uint8_t * rendered_qrcode_data[4]
uint8_t * qrcode_mask_data[4]
char * rendered_qrcode_width_expr
uint8_t foreground_color[4]
Main external API structure.
int ff_print_pts(void *log_ctx, AVBPrint *bp, double pts, const char *delta, const char *fmt, const char *strftime_fmt)
int ff_load_textfile(void *log_ctx, const char *textfile, unsigned char **text, size_t *text_size)
int ff_expand_text(FFExpandTextContext *expand_text, const char *text, AVBPrint *bp)
Expand text template.
int ff_print_time(void *log_ctx, AVBPrint *bp, const char *strftime_fmt, char localtime)
int ff_print_formatted_eval_expr(void *log_ctx, AVBPrint *bp, const char *expr, const char *const *fun_names, const ff_eval_func2 *fun_values, const char *const *var_names, const double *var_values, void *eval_ctx, const char format, int positions)
int ff_print_eval_expr(void *log_ctx, AVBPrint *bp, const char *expr, const char *const *fun_names, const ff_eval_func2 *fun_values, const char *const *var_names, const double *var_values, void *eval_ctx)
static const uint16_t positions[][14][3]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.