/* quirc -- QR-code recognition library1* Copyright (C) 2010-2012 Daniel Beer <[email protected]>2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR10* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN12* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF13* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*/1516#ifndef QUIRC_H_17#define QUIRC_H_1819#include <stdint.h>2021#ifdef __cplusplus22extern "C" {23#endif2425struct quirc;2627/* Obtain the library version string. */28const char *quirc_version(void);2930/* Construct a new QR-code recognizer. This function will return NULL31* if sufficient memory could not be allocated.32*/33struct quirc *quirc_new(void);3435/* Destroy a QR-code recognizer. */36void quirc_destroy(struct quirc *q);3738/* Resize the QR-code recognizer. The size of an image must be39* specified before codes can be analyzed.40*41* This function returns 0 on success, or -1 if sufficient memory could42* not be allocated.43*/44int quirc_resize(struct quirc *q, int w, int h);4546/* These functions are used to process images for QR-code recognition.47* quirc_begin() must first be called to obtain access to a buffer into48* which the input image should be placed. Optionally, the current49* width and height may be returned.50*51* After filling the buffer, quirc_end() should be called to process52* the image for QR-code recognition. The locations and content of each53* code may be obtained using accessor functions described below.54*/55uint8_t *quirc_begin(struct quirc *q, int *w, int *h);56void quirc_end(struct quirc *q);5758/* This structure describes a location in the input image buffer. */59struct quirc_point {60int x;61int y;62};6364/* This enum describes the various decoder errors which may occur. */65typedef enum {66QUIRC_SUCCESS = 0,67QUIRC_ERROR_INVALID_GRID_SIZE,68QUIRC_ERROR_INVALID_VERSION,69QUIRC_ERROR_FORMAT_ECC,70QUIRC_ERROR_DATA_ECC,71QUIRC_ERROR_UNKNOWN_DATA_TYPE,72QUIRC_ERROR_DATA_OVERFLOW,73QUIRC_ERROR_DATA_UNDERFLOW74} quirc_decode_error_t;7576/* Return a string error message for an error code. */77const char *quirc_strerror(quirc_decode_error_t err);7879/* Limits on the maximum size of QR-codes and their content. */80#define QUIRC_MAX_BITMAP 391781#define QUIRC_MAX_PAYLOAD 88968283/* QR-code ECC types. */84#define QUIRC_ECC_LEVEL_M 085#define QUIRC_ECC_LEVEL_L 186#define QUIRC_ECC_LEVEL_H 287#define QUIRC_ECC_LEVEL_Q 38889/* QR-code data types. */90#define QUIRC_DATA_TYPE_NUMERIC 191#define QUIRC_DATA_TYPE_ALPHA 292#define QUIRC_DATA_TYPE_BYTE 493#define QUIRC_DATA_TYPE_KANJI 89495/* Common character encodings */96#define QUIRC_ECI_ISO_8859_1 197#define QUIRC_ECI_IBM437 298#define QUIRC_ECI_ISO_8859_2 499#define QUIRC_ECI_ISO_8859_3 5100#define QUIRC_ECI_ISO_8859_4 6101#define QUIRC_ECI_ISO_8859_5 7102#define QUIRC_ECI_ISO_8859_6 8103#define QUIRC_ECI_ISO_8859_7 9104#define QUIRC_ECI_ISO_8859_8 10105#define QUIRC_ECI_ISO_8859_9 11106#define QUIRC_ECI_WINDOWS_874 13107#define QUIRC_ECI_ISO_8859_13 15108#define QUIRC_ECI_ISO_8859_15 17109#define QUIRC_ECI_SHIFT_JIS 20110#define QUIRC_ECI_UTF_8 26111112/* This structure is used to return information about detected QR codes113* in the input image.114*/115struct quirc_code {116/* The four corners of the QR-code, from top left, clockwise */117struct quirc_point corners[4];118119/* The number of cells across in the QR-code. The cell bitmap120* is a bitmask giving the actual values of cells. If the cell121* at (x, y) is black, then the following bit is set:122*123* cell_bitmap[i >> 3] & (1 << (i & 7))124*125* where i = (y * size) + x.126*/127int size;128uint8_t cell_bitmap[QUIRC_MAX_BITMAP];129};130131/* This structure holds the decoded QR-code data */132struct quirc_data {133/* Various parameters of the QR-code. These can mostly be134* ignored if you only care about the data.135*/136int version;137int ecc_level;138int mask;139140/* This field is the highest-valued data type found in the QR141* code.142*/143int data_type;144145/* Data payload. For the Kanji datatype, payload is encoded as146* Shift-JIS. For all other datatypes, payload is ASCII text.147*/148uint8_t payload[QUIRC_MAX_PAYLOAD];149int payload_len;150151/* ECI assignment number */152uint32_t eci;153};154155/* Return the number of QR-codes identified in the last processed156* image.157*/158int quirc_count(const struct quirc *q);159160/* Extract the QR-code specified by the given index. */161void quirc_extract(const struct quirc *q, int index,162struct quirc_code *code);163164/* Decode a QR-code, returning the payload data. */165quirc_decode_error_t quirc_decode(const struct quirc_code *code,166struct quirc_data *data);167168#ifdef __cplusplus169}170#endif171172#endif173174175