Merge pull request #34 from kAworu/decode_kanji.fix

Fix Kanji decoding.
This commit is contained in:
Daniel Beer 2017-05-31 08:23:33 +12:00 committed by GitHub
commit 5174ba77f8

View file

@ -790,12 +790,18 @@ static quirc_decode_error_t decode_kanji(struct quirc_data *data,
for (i = 0; i < count; i++) {
int d = take_bits(ds, 13);
int msB = d / 0xc0;
int lsB = d % 0xc0;
int intermediate = (msB << 8) | lsB;
uint16_t sjw;
if (d + 0x8140 >= 0x9ffc)
sjw = d + 0x8140;
else
sjw = d + 0xc140;
if (intermediate + 0x8140 <= 0x9ffc) {
/* bytes are in the range 0x8140 to 0x9FFC */
sjw = intermediate + 0x8140;
} else {
/* bytes are in the range 0xE040 to 0xEBBF */
sjw = intermediate + 0xc140;
}
data->payload[data->payload_len++] = sjw >> 8;
data->payload[data->payload_len++] = sjw & 0xff;