Go to the documentation of this file.
32 #include "config_components.h"
77 "rendered_padded_qr_w",
"Q",
86 #define V(name_) qr->var_values[VAR_##name_]
149 #define OFFSET(x) offsetof(QREncodeContext, x)
150 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
151 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
153 #define COMMON_OPTIONS \
154 { "qrcode_width", "set rendered QR code width expression", OFFSET(rendered_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "64"}, 0, INT_MAX, FLAGS }, \
155 { "q", "set rendered QR code width expression", OFFSET(rendered_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "64"}, 0, INT_MAX, FLAGS }, \
156 { "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 }, \
157 { "Q", "set rendered padded QR code width expression", OFFSET(rendered_padded_qrcode_width_expr), AV_OPT_TYPE_STRING, {.str = "q"}, 0, INT_MAX, FLAGS }, \
158 { "case_sensitive", "generate code which is case sensitive", OFFSET(case_sensitive), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, \
159 { "cs", "generate code which is case sensitive", OFFSET(case_sensitive), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, \
161 { "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"}, \
162 { "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"}, \
163 { "L", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_L }, 0, 0, FLAGS, .unit = "level" }, \
164 { "M", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_M }, 0, 0, FLAGS, .unit = "level" }, \
165 { "Q", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_Q }, 0, 0, FLAGS, .unit = "level" }, \
166 { "H", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QR_ECLEVEL_H }, 0, 0, FLAGS, .unit = "level" }, \
168 {"expansion", "set the expansion mode", OFFSET(expansion), AV_OPT_TYPE_INT, {.i64=EXPANSION_NORMAL}, 0, 2, FLAGS, .unit = "expansion"}, \
169 {"none", "set no expansion", OFFSET(expansion), AV_OPT_TYPE_CONST, {.i64 = EXPANSION_NONE}, 0, 0, FLAGS, .unit = "expansion"}, \
170 {"normal", "set normal expansion", OFFSET(expansion), AV_OPT_TYPE_CONST, {.i64 = EXPANSION_NORMAL}, 0, 0, FLAGS, .unit = "expansion"}, \
172 { "foreground_color", "set QR foreground color", OFFSET(foreground_color), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS }, \
173 { "fc", "set QR foreground color", OFFSET(foreground_color), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS }, \
174 { "background_color", "set QR background color", OFFSET(background_color), AV_OPT_TYPE_COLOR, {.str = "white"}, 0, 0, FLAGS }, \
175 { "bc", "set QR background color", OFFSET(background_color), AV_OPT_TYPE_COLOR, {.str = "white"}, 0, 0, FLAGS }, \
177 {"text", "set text to encode", OFFSET(text), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, \
178 {"textfile", "set text file to encode", OFFSET(textfile), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, \
189 static const ff_eval_func2
fun2[] = {
194 static int func_pts(
void *
ctx, AVBPrint *bp,
const char *function_name,
195 unsigned argc,
char **argv)
199 const char *strftime_fmt =
NULL;
205 fmt = argc >= 1 ? argv[0] :
"flt";
210 strftime_fmt = argv[2];
217 unsigned argc,
char **argv)
226 unsigned argc,
char **argv)
228 const char *strftime_fmt = argc ? argv[0] :
NULL;
230 return ff_print_time(
ctx, bp, strftime_fmt, !strcmp(function_name,
"localtime"));
234 unsigned argc,
char **argv)
248 unsigned argc,
char **argv)
258 unsigned argc,
char **argv)
274 " to print: '%s'\n", argv[2]);
312 "Both text and text file provided. Please provide only one\n");
349 const char *p = qrcode->data;
353 for (
i = 0;
i < qrcode->width;
i++) {
354 for (j = 0; j < qrcode->width; j++)
355 line[j] = (*p++)&1 ?
'@' :
' ';
367 QRcode *qrcode =
NULL;
369 char qrcode_width_changed;
373 uint8_t *dstp0, *dstp;
403 "Failed to encode string with error \'%s\'\n",
av_err2str(
ret));
408 "Encoded QR with width:%d version:%d\n", qrcode->width, qrcode->version);
413 qrcode_width_changed = qr->
qrcode_width != qrcode->width;
417 if (qrcode_width_changed) {
420 qrcode->width, qrcode->width,
424 "Failed to allocate image for QR code with width %d\n", qrcode->width);
433 for (
i = 0;
i < qrcode->width;
i++) {
435 for (j = 0; j < qrcode->width; j++)
436 *dstp++ = (*srcp++ & 1) ? 255 : 0;
441 if (qrcode_width_changed) {
455 "Failed to allocate image for QR code with width %d\n",
497 #define EVAL_EXPR(name_) \
498 av_expr_eval(qr->name_##_pexpr, qr->var_values, &qr->lfg);
500 V(qr_w) =
V(
w) = qrcode->width;
502 V(rendered_qr_w) =
V(q) = EVAL_EXPR(rendered_qrcode_width);
503 V(rendered_padded_qr_w) =
V(
Q) = EVAL_EXPR(rendered_padded_qrcode_width);
505 V(rendered_qr_w) =
V(q) = EVAL_EXPR(rendered_qrcode_width);
513 "Rendering QR code with values n:%d w:%d q:%d Q:%d x:%d y:%d t:%f\n",
514 (
int)
V(n), (
int)
V(
w), (
int)
V(q), (
int)
V(
Q), (
int)
V(x), (
int)
V(y),
V(t));
530 "Failed to allocate image for rendered QR code with width %d\n",
575 #if CONFIG_QRENCODESRC_FILTER
595 #define PARSE_AND_EVAL_EXPR(var_name_, expr_name_) \
596 ret = av_expr_parse_and_eval(&qr->var_values[VAR_##var_name_], \
597 qr->expr_name_##_expr, \
598 var_names, qr->var_values, \
603 av_log(ctx, AV_LOG_ERROR, \
604 "Could not evaluate expression '%s'\n", \
605 qr->expr_name_##_expr); \
612 V(x) =
V(y) =
V(t) =
V(n) =
NAN;
613 V(dar) =
V(sar) = 1.0;
615 PARSE_AND_EVAL_EXPR(rendered_qr_w, rendered_qrcode_width);
616 V(q) =
V(rendered_qr_w);
617 PARSE_AND_EVAL_EXPR(rendered_padded_qr_w, rendered_padded_qrcode_width);
618 V(
Q) =
V(rendered_padded_qr_w);
619 PARSE_AND_EVAL_EXPR(rendered_qr_w, rendered_qrcode_width);
620 V(q) =
V(rendered_qr_w);
626 "q:%d Q:%d case_sensitive:%d level:%d\n",
632 "Resulting padded QR code width (%d) is lesser than the QR code width (%d)\n",
657 ff_get_video_buffer(outlink, qr->rendered_padded_qrcode_width, qr->rendered_padded_qrcode_width);
700 .
name =
"qrencodesrc",
703 .priv_class = &qrencodesrc_class,
711 #endif // CONFIG_QRENCODESRC_FILTER
713 #if CONFIG_QRENCODE_FILTER
748 #define PARSE_EXPR(name_) \
749 ret = av_expr_parse(&qr->name_##_pexpr, expr = qr->name_##_expr, var_names, \
750 NULL, NULL, fun2_names, fun2, 0, ctx); \
752 av_log(ctx, AV_LOG_ERROR, \
753 "Could not to parse expression '%s' for '%s'\n", \
755 return AVERROR(EINVAL); \
785 V(n) =
inlink->frame_count_out;
813 .priv_class = &qrencode_class,
822 #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.
int ff_expand_text(FFExpandTextContext *expand_text, char *text, AVBPrint *bp)
Expand text template.
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.
int64_t duration
Duration of the frame, in the same units as pts.
static int qrencode_config_input(AVFilterLink *inlink)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to 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
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
FFDrawColor draw_background_color
background color
AVExpr * rendered_padded_qrcode_width_pexpr
uint8_t background_color[4]
FFDrawColor draw_foreground_color
foreground color
#define FILTER_QUERY_FUNC(func)
double var_values[VAR_VARS_NB]
#define AV_LOG_VERBOSE
Detailed information.
int attribute_align_arg sws_scale(struct SwsContext *c, 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.
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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]
const static uint16_t positions[][14][3]
int rendered_qrcode_linesize[4]
void * log_ctx
log context to pass to the function, used for logging and for accessing the context for the function
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.
#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.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#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_INPUTS(array)
int expansion
expansion mode to use for the text
static int qrencode_query_formats(AVFilterContext *ctx)
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
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
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 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...
Context structure for the Lagged Fibonacci PRNG.
enum AVPictureType pict_type
Picture type of the frame.
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.
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]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
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 int qrencodesrc_query_formats(AVFilterContext *ctx)
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.
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 FFExpandTextFunction expand_text_functions[]
static const char *const var_names[]
const AVFilter ff_vf_qrencode
void av_bprintf(AVBPrint *buf, const char *fmt,...)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
av_warn_unused_result int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
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[]
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int h
agreed upon image height
AVDictionary * metadata
metadata.
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)
#define FILTER_OUTPUTS(array)
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ VAR_rendered_padded_qr_w
AVBPrint expanded_text
used to contain the expanded text
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
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.