From a8077535b2da9b97090882e38e82d6be163c90af Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Fri, 21 Apr 2017 19:54:35 +0100 Subject: [PATCH] Correct Kanji processing in QR Code Bugfix by Milton Neal --- backend/qr.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/qr.c b/backend/qr.c index fdce6848..9b16214a 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -261,16 +261,15 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in /* Character representation */ for (i = 0; i < short_data_block_length; i++) { int jis = jisdata[position + i]; - int msb, lsb, prod; - - if (jis > 0x9fff) { + int prod; + + if (jis >= 0x8140 && jis <= 0x9ffc) + jis -= 0x8140; + + else if (jis >= 0xe040 && jis <= 0xebbf) jis -= 0xc140; - } - msb = (jis & 0xff00) >> 4; - lsb = (jis & 0xff); - prod = (msb * 0xc0) + lsb; - - qr_bscan(binary, prod, 0x1000); + + prod = ((jis >> 8) * 0xc0) + (jis & 0xff); if (debug) { printf("0x%4X ", prod); @@ -1765,14 +1764,17 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, /* Character representation */ for (i = 0; i < short_data_block_length; i++) { int jis = jisdata[position + i]; - int msb, lsb, prod; + int prod; - if (jis > 0x9fff) { + int jis = jisdata[position + i]; + + if (jis >= 0x8140 && jis <= 0x9ffc) + jis -= 0x8140; + + else if (jis >= 0xe040 && jis <= 0xebbf) jis -= 0xc140; - } - msb = (jis & 0xff00) >> 4; - lsb = (jis & 0xff); - prod = (msb * 0xc0) + lsb; + + prod = ((jis >> 8) * 0xc0) + (jis & 0xff); qr_bscan(binary, prod, 0x1000);