Skip to content

Commit

Permalink
qr: add support for raw binary data extraction
Browse files Browse the repository at this point in the history
If a QR code doesn't specify the text encoding of binary data through
Extended Channel Interpretation, ZBar tries to guess the encoding.
This unconditional character set conversion makes it impossible
to recover other types of binary data stored in the QR code.

The QR decoder now supports the ZBAR_CFG_BINARY configuration option.
If set, it will output the bytes without converting them to text.
This allows access to the actual bytes encoded in a binary QR code.

Closes: #55
Thanks: Martin von Wittich <[email protected]>
Signed-off-by: Matheus Afonso Martins Moreira <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
matheusmoreira authored and mchehab committed Mar 13, 2020
1 parent 488bac3 commit 59e0ed1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions zbar/qrcode/qrdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ struct qr_code_data_list{

/*Extract symbol data from a list of QR codes and attach to the image.
All text is converted to UTF-8.
For binary/byte mode QR codes: if configured with ZBAR_CFG_BINARY,
the bytes will be returned as is. Otherwise, the encoding will be
automatically determined and the data will be converted to that character set.
Any structured-append group that does not have all of its members is decoded
as ZBAR_PARTIAL with ZBAR_PARTIAL components for the discontinuities.
Note that isolated members of a structured-append group may be decoded with
Expand Down
13 changes: 12 additions & 1 deletion zbar/qrcode/qrdectxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ int qr_code_data_list_extract_text(const qr_code_data_list *_qrlist,
unsigned char *mark;
int ntext;
int i;
int raw_binary = 0;
zbar_image_scanner_get_config(iscn, ZBAR_QRCODE, ZBAR_CFG_BINARY, &raw_binary);
qrdata=_qrlist->qrdata;
nqrdata=_qrlist->nqrdata;
mark=(unsigned char *)calloc(nqrdata,sizeof(*mark));
Expand Down Expand Up @@ -243,8 +245,16 @@ int qr_code_data_list_extract_text(const qr_code_data_list *_qrlist,
inleft=bytebuf_ntext;
out=sa_text+sa_ntext;
outleft=sa_ctext-sa_ntext;
/*If we have no specified encoding, attempt to auto-detect it.*/
/*If we have no specified encoding, attempt to auto-detect it
unless configured with ZBAR_CFG_BINARY.*/
if(eci<0){
if (raw_binary) {
/* copy all remaining bytes to output buffer. */
memcpy(out, in, inleft);
sa_ntext += inleft;
bytebuf_ntext = 0;
}
else {
int ei;
/*If there was data encoded in kanji mode, assume it's SJIS.*/
if(has_kanji)enc_list_mtf(enc_list,sjis_cd);
Expand Down Expand Up @@ -309,6 +319,7 @@ int qr_code_data_list_extract_text(const qr_code_data_list *_qrlist,
out=sa_text+sa_ntext;
outleft=sa_ctext-sa_ntext;
}
}
}
/*We were actually given a character set; use it.
The spec says that in this case, data should be treated as if it
Expand Down

0 comments on commit 59e0ed1

Please sign in to comment.