Changed C API function qrcodegen_getSize() to receive array instead of int, updated runnable programs, deleted test cases for this function.
This commit is contained in:
parent
df1c49cc39
commit
454534ee33
|
@ -137,7 +137,7 @@ static void doVarietyDemo() {
|
|||
|
||||
// Prints the given QR Code to the console.
|
||||
static void printQr(const uint8_t qrcode[], int version) {
|
||||
int size = qrcodegen_getSize(version);
|
||||
int size = qrcodegen_getSize(qrcode);
|
||||
int border = 4;
|
||||
for (int y = -border; y < size + border; y++) {
|
||||
for (int x = -border; x < size + border; x++) {
|
||||
|
|
|
@ -53,22 +53,6 @@ int getAlignmentPatternPositions(int version, uint8_t result[7]);
|
|||
|
||||
/*---- Test cases ----*/
|
||||
|
||||
static void testSize(void) {
|
||||
int cases[][2] = {
|
||||
{ 1, 21},
|
||||
{ 6, 41},
|
||||
{20, 97},
|
||||
{33, 149},
|
||||
{40, 177},
|
||||
};
|
||||
for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
|
||||
int *tc = cases[i];
|
||||
assert(qrcodegen_getSize(tc[0]) == tc[1]);
|
||||
numTestCases++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void testGetTextProperties(void) {
|
||||
bool isNumeric, isAlphanumeric;
|
||||
int textLen, textBits;
|
||||
|
@ -346,7 +330,6 @@ static void testGetAlignmentPatternPositions(void) {
|
|||
/*---- Main runner ----*/
|
||||
|
||||
int main(void) {
|
||||
testSize();
|
||||
testGetTextProperties();
|
||||
testGetNumDataCodewords();
|
||||
testGetNumRawDataModules();
|
||||
|
|
|
@ -98,7 +98,7 @@ int main(void) {
|
|||
printf("-1\n");
|
||||
else {
|
||||
printf("%d\n", version);
|
||||
int size = qrcodegen_getSize(version);
|
||||
int size = qrcodegen_getSize(qrcode);
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++)
|
||||
printf("%d\n", qrcodegen_getModule(qrcode, x, y) ? 1 : 0);
|
||||
|
|
|
@ -293,9 +293,9 @@ static void encodeQrCodeTail(uint8_t dataAndQrcode[], int bitLen, uint8_t tempBu
|
|||
assert(bitLen % 8 == 0);
|
||||
|
||||
// Draw function and data codeword modules
|
||||
int qrsize = qrcodegen_getSize(version);
|
||||
appendErrorCorrection(dataAndQrcode, version, ecl, tempBuffer);
|
||||
initializeFunctionModules(version, dataAndQrcode);
|
||||
int qrsize = qrcodegen_getSize(dataAndQrcode);
|
||||
drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, dataAndQrcode, qrsize);
|
||||
drawWhiteFunctionModules(dataAndQrcode, version);
|
||||
initializeFunctionModules(version, tempBuffer);
|
||||
|
@ -459,7 +459,7 @@ testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y) {
|
|||
// version's size, then marks every function module as black.
|
||||
static void initializeFunctionModules(int version, uint8_t qrcode[]) {
|
||||
// Initialize QR Code
|
||||
int qrsize = qrcodegen_getSize(version);
|
||||
int qrsize = version * 4 + 17;
|
||||
memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0]));
|
||||
qrcode[0] = (uint8_t)qrsize;
|
||||
|
||||
|
@ -497,7 +497,7 @@ static void initializeFunctionModules(int version, uint8_t qrcode[]) {
|
|||
// marked black (namely by initializeFunctionModules()), because this may skip redrawing black function modules.
|
||||
static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
// Draw horizontal and vertical timing patterns
|
||||
int qrsize = qrcodegen_getSize(version);
|
||||
int qrsize = qrcodegen_getSize(qrcode);
|
||||
for (int i = 7; i < qrsize - 7; i += 2) {
|
||||
setModule(qrcode, 6, i, false);
|
||||
setModule(qrcode, i, 6, false);
|
||||
|
@ -600,7 +600,7 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin
|
|||
testable int getAlignmentPatternPositions(int version, uint8_t result[7]) {
|
||||
if (version == 1)
|
||||
return 0;
|
||||
int qrsize = qrcodegen_getSize(version);
|
||||
int qrsize = version * 4 + 17;
|
||||
int numAlign = version / 7 + 2;
|
||||
int step;
|
||||
if (version != 32)
|
||||
|
@ -768,9 +768,11 @@ static long getPenaltyScore(const uint8_t qrcode[], int qrsize) {
|
|||
/*---- Basic QR Code information ----*/
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
int qrcodegen_getSize(int version) {
|
||||
assert(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
|
||||
return version * 4 + 17;
|
||||
int qrcodegen_getSize(const uint8_t qrcode[]) {
|
||||
int result = qrcode[0];
|
||||
assert((qrcodegen_VERSION_MIN * 4 + 17) <= result
|
||||
&& result <= (qrcodegen_VERSION_MAX * 4 + 17));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,12 +102,12 @@ int qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode
|
|||
/*---- Low-level QR Code functions ----*/
|
||||
|
||||
/*
|
||||
* Returns the side length of any QR Code of the given version number.
|
||||
* The version must be in the range [1, 40]. The result is in the range [21, 177].
|
||||
* Note that every 'uint8_t qrcode[]' buffer must have a length of at least
|
||||
* ceil(size^2 / 8 + 1), which also equals qrcodegen_BUFFER_LEN_FOR_VERSION(version).
|
||||
* Returns the side length of the given QR Code, assuming that the buffer is valid.
|
||||
* The result is in the range [21, 177]. Note that every 'uint8_t qrcode[]' buffer
|
||||
* must have a length of at least ceil(size^2 / 8 + 1), which also equals
|
||||
* qrcodegen_BUFFER_LEN_FOR_VERSION(version).
|
||||
*/
|
||||
int qrcodegen_getSize(int version);
|
||||
int qrcodegen_getSize(const uint8_t qrcode[]);
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue