2012-05-04 02:58:42 +02:00
|
|
|
/* quirc -- QR-code recognition library
|
|
|
|
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QUIRC_INTERNAL_H_
|
|
|
|
#define QUIRC_INTERNAL_H_
|
|
|
|
|
2021-05-11 06:22:54 +02:00
|
|
|
#include <assert.h>
|
2021-03-22 02:56:51 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-05-04 02:58:42 +02:00
|
|
|
#include "quirc.h"
|
|
|
|
|
2021-05-11 06:22:54 +02:00
|
|
|
#define QUIRC_ASSERT(a) assert(a)
|
|
|
|
|
2012-05-04 02:58:42 +02:00
|
|
|
#define QUIRC_PIXEL_WHITE 0
|
|
|
|
#define QUIRC_PIXEL_BLACK 1
|
|
|
|
#define QUIRC_PIXEL_REGION 2
|
|
|
|
|
2016-07-15 14:40:40 +02:00
|
|
|
#ifndef QUIRC_MAX_REGIONS
|
2012-05-04 02:58:42 +02:00
|
|
|
#define QUIRC_MAX_REGIONS 254
|
2016-07-15 14:40:40 +02:00
|
|
|
#endif
|
2012-05-04 02:58:42 +02:00
|
|
|
#define QUIRC_MAX_CAPSTONES 32
|
2020-05-28 03:33:51 +02:00
|
|
|
#define QUIRC_MAX_GRIDS (QUIRC_MAX_CAPSTONES * 2)
|
2012-05-04 02:58:42 +02:00
|
|
|
|
|
|
|
#define QUIRC_PERSPECTIVE_PARAMS 8
|
|
|
|
|
2016-07-15 14:40:40 +02:00
|
|
|
#if QUIRC_MAX_REGIONS < UINT8_MAX
|
2019-07-01 22:19:39 +02:00
|
|
|
#define QUIRC_PIXEL_ALIAS_IMAGE 1
|
2016-07-15 14:40:40 +02:00
|
|
|
typedef uint8_t quirc_pixel_t;
|
|
|
|
#elif QUIRC_MAX_REGIONS < UINT16_MAX
|
2019-07-01 22:19:39 +02:00
|
|
|
#define QUIRC_PIXEL_ALIAS_IMAGE 0
|
2016-07-15 14:40:40 +02:00
|
|
|
typedef uint16_t quirc_pixel_t;
|
|
|
|
#else
|
|
|
|
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
|
|
|
|
#endif
|
|
|
|
|
2012-05-04 02:58:42 +02:00
|
|
|
struct quirc_region {
|
|
|
|
struct quirc_point seed;
|
|
|
|
int count;
|
|
|
|
int capstone;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quirc_capstone {
|
|
|
|
int ring;
|
|
|
|
int stone;
|
|
|
|
|
|
|
|
struct quirc_point corners[4];
|
|
|
|
struct quirc_point center;
|
|
|
|
double c[QUIRC_PERSPECTIVE_PARAMS];
|
|
|
|
|
|
|
|
int qr_grid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quirc_grid {
|
|
|
|
/* Capstone indices */
|
|
|
|
int caps[3];
|
|
|
|
|
|
|
|
/* Alignment pattern region and corner */
|
|
|
|
int align_region;
|
|
|
|
struct quirc_point align;
|
|
|
|
|
|
|
|
/* Timing pattern endpoints */
|
|
|
|
struct quirc_point tpep[3];
|
|
|
|
|
|
|
|
/* Grid size and perspective transform */
|
|
|
|
int grid_size;
|
|
|
|
double c[QUIRC_PERSPECTIVE_PARAMS];
|
|
|
|
};
|
|
|
|
|
2021-03-22 02:56:51 +01:00
|
|
|
struct quirc_flood_fill_vars {
|
|
|
|
int y;
|
|
|
|
int right;
|
2021-05-11 06:46:31 +02:00
|
|
|
int left_up;
|
|
|
|
int left_down;
|
2021-03-22 02:56:51 +01:00
|
|
|
};
|
|
|
|
|
2012-05-04 02:58:42 +02:00
|
|
|
struct quirc {
|
|
|
|
uint8_t *image;
|
2016-07-15 14:40:40 +02:00
|
|
|
quirc_pixel_t *pixels;
|
2012-05-04 02:58:42 +02:00
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
|
|
|
|
int num_regions;
|
|
|
|
struct quirc_region regions[QUIRC_MAX_REGIONS];
|
|
|
|
|
|
|
|
int num_capstones;
|
|
|
|
struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES];
|
|
|
|
|
|
|
|
int num_grids;
|
|
|
|
struct quirc_grid grids[QUIRC_MAX_GRIDS];
|
2021-03-22 02:56:51 +01:00
|
|
|
|
|
|
|
size_t num_flood_fill_vars;
|
|
|
|
struct quirc_flood_fill_vars *flood_fill_vars;
|
2021-10-08 10:44:16 +02:00
|
|
|
|
|
|
|
uint8_t outer_alloc;
|
2012-05-04 02:58:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* QR-code version information database
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define QUIRC_MAX_VERSION 40
|
|
|
|
#define QUIRC_MAX_ALIGNMENT 7
|
|
|
|
|
|
|
|
struct quirc_rs_params {
|
2016-12-28 03:37:18 +01:00
|
|
|
int bs; /* Small block size */
|
|
|
|
int dw; /* Small data words */
|
|
|
|
int ns; /* Number of small blocks */
|
2012-05-04 02:58:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct quirc_version_info {
|
|
|
|
int data_bytes;
|
|
|
|
int apat[QUIRC_MAX_ALIGNMENT];
|
|
|
|
struct quirc_rs_params ecc[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1];
|
|
|
|
|
|
|
|
#endif
|