aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>2019-11-02 06:13:11 -0300
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-03-13 10:49:04 +0100
commit59e0ed18f5185a57516ea3115027a9bdbad04fd8 (patch)
tree02b071402810e0e2ad49a242259e825c4c6572b2
parent488bac3f9be27a27cffb6d21a95887ed0d4568c9 (diff)
qr: add support for raw binary data extraction
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 <martin.von.wittich@iserv.eu> Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--zbar/qrcode/qrdec.h3
-rw-r--r--zbar/qrcode/qrdectxt.c13
2 files changed, 15 insertions, 1 deletions
diff --git a/zbar/qrcode/qrdec.h b/zbar/qrcode/qrdec.h
index 3d3d0de..0911be6 100644
--- a/zbar/qrcode/qrdec.h
+++ b/zbar/qrcode/qrdec.h
@@ -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
diff --git a/zbar/qrcode/qrdectxt.c b/zbar/qrcode/qrdectxt.c
index 4be7635..977d552 100644
--- a/zbar/qrcode/qrdectxt.c
+++ b/zbar/qrcode/qrdectxt.c
@@ -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));
@@ -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);
@@ -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

Privacy Policy