Go to the documentation of this file.
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}, \
190 static const ff_eval_func2
fun2[] = {
195 static 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",
659 ff_get_video_buffer(outlink, qr->rendered_padded_qrcode_width, qr->rendered_padded_qrcode_width);
665 V(n) =
frame->pts = qr->pts++;
704 .
name =
"qrencodesrc",
707 .priv_class = &qrencodesrc_class,
715 #endif // CONFIG_QRENCODESRC_FILTER
717 #if CONFIG_QRENCODE_FILTER
752 #define PARSE_EXPR(name_) \
753 ret = av_expr_parse(&qr->name_##_pexpr, expr = qr->name_##_expr, var_names, \
754 NULL, NULL, fun2_names, fun2, 0, ctx); \
756 av_log(ctx, AV_LOG_ERROR, \
757 "Could not to parse expression '%s' for '%s'\n", \
759 return AVERROR(EINVAL); \
795 V(pict_type) =
frame->pict_type;
820 .priv_class = &qrencode_class,
829 #endif // CONFIG_QRENCODE_FILTER
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_BPRINT_SIZE_UNLIMITED
uint8_t foreground_color[4]
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int func_eval_expr_formatted(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
#define sws_isSupportedOutput(x)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int qrencode_config_input(AVFilterLink *inlink)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
static const AVFilterPad qrencodesrc_outputs[]
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
FFDrawColor draw_background_color
background color
AVExpr * rendered_padded_qrcode_width_pexpr
uint8_t background_color[4]
FFDrawColor draw_foreground_color
foreground color
double var_values[VAR_VARS_NB]
#define AV_LOG_VERBOSE
Detailed information.
static int func_pts(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
const char * name
Filter name.
A link between two filters.
static double drand(void *opaque, double min, double max)
Link properties exposed to filter code, but not external callers.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
static int draw_qrcode(AVFilterContext *ctx, AVFrame *frame)
uint8_t * rendered_qrcode_data[4]
static const FFExpandTextFunction expand_text_functions[]
const static uint16_t positions[][14][3]
int rendered_qrcode_linesize[4]
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
void * log_ctx
log context to pass to the function, used for logging and for accessing the context for the function
int ff_expand_text(FFExpandTextContext *expand_text, const char *text, AVBPrint *bp)
Expand text template.
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.
Function used to expand a template sequence in the format %{FUNCTION_NAME[:PARAMS]},...
FFDrawColor draw0_background_color
background color
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
struct SwsContext SwsContext
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int ff_load_textfile(void *log_ctx, const char *textfile, unsigned char **text, size_t *text_size)
AVLFG lfg
random generator
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVFilter ff_vsrc_qrencodesrc
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static int request_frame(AVFilterLink *outlink)
static enum AVPixelFormat pix_fmt
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int func_frame_num(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
#define FILTER_OUTPUTS(array)
int expansion
expansion mode to use for the text
Describe the class of an AVClass context structure.
char * rendered_padded_qrcode_width_expr
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)
Rational number (pair of numerator and denominator).
int rendered_padded_qrcode_width
char * rendered_qrcode_width_expr
static const AVFilterPad avfilter_vf_qrencode_inputs[]
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static FilterLink * ff_filter_link(AVFilterLink *link)
static int qrencodesrc_config_props(AVFilterLink *outlink)
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 AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Context structure for the Lagged Fibonacci PRNG.
int rendered_qrcode_width
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
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 qrcode_mask_linesize[4]
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)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, unsigned flags)
Init a draw context.
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
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.
static const char *const fun2_names[]
uint8_t * qrcode_mask_data[4]
AVFilterContext * src
source filter
AVFILTER_DEFINE_CLASS(qrencodesrc)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static const AVOption qrencode_options[]
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
int ff_print_pts(void *log_ctx, AVBPrint *bp, double pts, const char *delta, const char *fmt, const char *strftime_fmt)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
#define FILTER_QUERY_FUNC2(func)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
static const char *const var_names[]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
const AVFilter ff_vf_qrencode
void av_bprintf(AVBPrint *buf, const char *fmt,...)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your see the OFFSET() macro
static const AVOption qrencodesrc_options[]
static int qrencodesrc_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
int h
agreed upon image height
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 av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
in a text template, followed by any character, always expands to the second character.
FFExpandTextContext expand_text
expand text in case expansion is enabled
static void show_qrcode(AVFilterContext *ctx, const QRcode *qrcode)
static const ff_eval_func2 fun2[]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static int func_frame_metadata(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static int func_eval_expr(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
static int func_strftime(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **argv)
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
@ VAR_rendered_padded_qr_w
AVBPrint expanded_text
used to contain the expanded text
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
@ 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...
static int qrencode_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
enum AVColorRange color_range
agreed upon YUV color range
int ff_print_time(void *log_ctx, AVBPrint *bp, const char *strftime_fmt, char localtime)
AVExpr * rendered_qrcode_width_pexpr