Add support for ECI decoding.
ECI values are decoded and stored in the eci field of struct quirc_data. Constants of the form QUIRC_ECI_* are defined in quirc.h.
This commit is contained in:
parent
a8291391ec
commit
ab341691c9
3 changed files with 51 additions and 1 deletions
29
lib/decode.c
29
lib/decode.c
|
@ -802,6 +802,29 @@ static quirc_decode_error_t decode_kanji(struct quirc_data *data,
|
|||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_eci(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
if (bits_remaining(ds) < 8)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = take_bits(ds, 8);
|
||||
|
||||
if ((data->eci & 0xc0) == 0x80) {
|
||||
if (bits_remaining(ds) < 8)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = (data->eci << 8) | take_bits(ds, 8);
|
||||
} else if ((data->eci & 0xe0) == 0xc0) {
|
||||
if (bits_remaining(ds) < 16)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = (data->eci << 16) | take_bits(ds, 16);
|
||||
}
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_payload(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
|
@ -826,6 +849,10 @@ static quirc_decode_error_t decode_payload(struct quirc_data *data,
|
|||
err = decode_kanji(data, ds);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
err = decode_eci(data, ds);
|
||||
break;
|
||||
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
|
@ -833,7 +860,7 @@ static quirc_decode_error_t decode_payload(struct quirc_data *data,
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
if (type > data->data_type)
|
||||
if (!(type & (type - 1)) && (type > data->data_type))
|
||||
data->data_type = type;
|
||||
}
|
||||
done:
|
||||
|
|
20
lib/quirc.h
20
lib/quirc.h
|
@ -89,6 +89,23 @@ const char *quirc_strerror(quirc_decode_error_t err);
|
|||
#define QUIRC_DATA_TYPE_BYTE 4
|
||||
#define QUIRC_DATA_TYPE_KANJI 8
|
||||
|
||||
/* Common character encodings */
|
||||
#define QUIRC_ECI_ISO_8859_1 1
|
||||
#define QUIRC_ECI_IBM437 2
|
||||
#define QUIRC_ECI_ISO_8859_2 4
|
||||
#define QUIRC_ECI_ISO_8859_3 5
|
||||
#define QUIRC_ECI_ISO_8859_4 6
|
||||
#define QUIRC_ECI_ISO_8859_5 7
|
||||
#define QUIRC_ECI_ISO_8859_6 8
|
||||
#define QUIRC_ECI_ISO_8859_7 9
|
||||
#define QUIRC_ECI_ISO_8859_8 10
|
||||
#define QUIRC_ECI_ISO_8859_9 11
|
||||
#define QUIRC_ECI_WINDOWS_874 13
|
||||
#define QUIRC_ECI_ISO_8859_13 15
|
||||
#define QUIRC_ECI_ISO_8859_15 17
|
||||
#define QUIRC_ECI_SHIFT_JIS 20
|
||||
#define QUIRC_ECI_UTF_8 26
|
||||
|
||||
/* This structure is used to return information about detected QR codes
|
||||
* in the input image.
|
||||
*/
|
||||
|
@ -127,6 +144,9 @@ struct quirc_data {
|
|||
*/
|
||||
uint8_t payload[QUIRC_MAX_PAYLOAD];
|
||||
int payload_len;
|
||||
|
||||
/* ECI assignment number */
|
||||
uint32_t eci;
|
||||
};
|
||||
|
||||
/* Return the number of QR-codes identified in the last processed
|
||||
|
|
|
@ -46,6 +46,9 @@ void dump_data(const struct quirc_data *data)
|
|||
data->data_type, data_type_str(data->data_type));
|
||||
printf(" Length: %d\n", data->payload_len);
|
||||
printf(" Payload: %s\n", data->payload);
|
||||
|
||||
if (data->eci)
|
||||
printf(" ECI: %d\n", data->eci);
|
||||
}
|
||||
|
||||
void dump_cells(const struct quirc_code *code)
|
||||
|
|
Loading…
Reference in a new issue