MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / draw_qrcode

Function draw_qrcode

libavfilter/qrencode.c:364–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362#endif
363
364static int draw_qrcode(AVFilterContext *ctx, AVFrame *frame)
365{
366 QREncodeContext *qr = ctx->priv;
367 struct SwsContext *sws = NULL;
368 QRcode *qrcode = NULL;
369 int i, j;
370 char qrcode_width_changed;
371 int ret;
372 int offset;
373 uint8_t *srcp;
374 uint8_t *dstp0, *dstp;
375
376 av_bprint_clear(&qr->expanded_text);
377
378 switch (qr->expansion) {
379 case EXPANSION_NONE:
380 av_bprintf(&qr->expanded_text, "%s", qr->text);
381 break;
382 case EXPANSION_NORMAL:
383 if ((ret = ff_expand_text(&qr->expand_text, qr->text, &qr->expanded_text)) < 0)
384 return ret;
385 break;
386 }
387
388 if (!qr->expanded_text.str || qr->expanded_text.str[0] == 0) {
389 if (qr->is_source) {
390 ff_fill_rectangle(&qr->draw0, &qr->draw0_background_color,
391 frame->data, frame->linesize,
392 0, 0, qr->rendered_padded_qrcode_width, qr->rendered_padded_qrcode_width);
393 }
394
395 return 0;
396 }
397
398 av_log(ctx, AV_LOG_DEBUG, "Encoding string '%s'\n", qr->expanded_text.str);
399 qrcode = QRcode_encodeString(qr->expanded_text.str, 1, qr->level, QR_MODE_8,
400 qr->case_sensitive);
401 if (!qrcode) {
402 ret = AVERROR(errno);
403 av_log(ctx, AV_LOG_ERROR,
404 "Failed to encode string with error \'%s\'\n", av_err2str(ret));
405 goto end;
406 }
407
408 av_log(ctx, AV_LOG_DEBUG,
409 "Encoded QR with width:%d version:%d\n", qrcode->width, qrcode->version);
410#ifdef DEBUG
411 show_qrcode(ctx, (const QRcode *)qrcode);
412#endif
413
414 qrcode_width_changed = qr->qrcode_width != qrcode->width;
415 qr->qrcode_width = qrcode->width;
416
417 // realloc mask if needed
418 if (qrcode_width_changed) {
419 av_freep(&qr->qrcode_mask_data[0]);
420 ret = av_image_alloc(qr->qrcode_mask_data, qr->qrcode_mask_linesize,
421 qrcode->width, qrcode->width,

Callers 2

request_frameFunction · 0.85
filter_frameFunction · 0.85

Calls 15

av_bprint_clearFunction · 0.85
av_bprintfFunction · 0.85
ff_expand_textFunction · 0.85
ff_fill_rectangleFunction · 0.85
av_logFunction · 0.85
show_qrcodeFunction · 0.85
av_freepFunction · 0.85
av_image_allocFunction · 0.85
ff_blend_maskFunction · 0.85
sws_alloc_contextFunction · 0.85
av_opt_set_intFunction · 0.85
sws_init_contextFunction · 0.85

Tested by

no test coverage detected