1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 01:43:01 +01:00

Slight improvement to qrcode printing

This commit is contained in:
Jfreegman 2015-11-09 02:28:41 -05:00
parent 39c4b7ecdd
commit 7e0b8b4870
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -34,20 +34,6 @@
#define CHAR_2 "\342\226\204" #define CHAR_2 "\342\226\204"
#define CHAR_3 "\342\226\200" #define CHAR_3 "\342\226\200"
static void add_border(FILE *fp, size_t width)
{
size_t i, j;
for (i = 0; i < BORDER_LEN; i += 2) {
fprintf(fp, BORDER_CHAR);
for (j = 0; j < BORDER_LEN + width + BORDER_LEN; ++j)
fprintf(fp, "%s", CHAR_1);
fprintf(fp, "%s\n", BORDER_CHAR);
}
}
/* Converts a tox ID string into a QRcode and prints it to the given file stream. /* Converts a tox ID string into a QRcode and prints it to the given file stream.
* *
* Returns 0 on success. * Returns 0 on success.
@ -64,19 +50,20 @@ int ID_to_QRcode(const char *tox_id, FILE *fp)
return -1; return -1;
size_t width = qr_obj->width; size_t width = qr_obj->width;
add_border(fp, width);
size_t i, j; size_t i, j;
for (i = 0; i < width + BORDER_LEN * 2; ++i)
fprintf(fp, "%s", CHAR_1);
fprintf(fp, "\n");
for (i = 0; i < width; i += 2) { for (i = 0; i < width; i += 2) {
const unsigned char *row_1 = qr_obj->data + width * i;
const unsigned char *row_2 = row_1 + width;
fprintf(fp, BORDER_CHAR);
for (j = 0; j < BORDER_LEN; ++j) for (j = 0; j < BORDER_LEN; ++j)
fprintf(fp, "%s", CHAR_1); fprintf(fp, "%s", CHAR_1);
const unsigned char *row_1 = qr_obj->data + width * i;
const unsigned char *row_2 = row_1 + width;
for (j = 0; j < width; ++j) { for (j = 0; j < width; ++j) {
bool x = row_1[j] & 1; bool x = row_1[j] & 1;
bool y = (i + 1) < width ? (row_2[j] & 1) : false; bool y = (i + 1) < width ? (row_2[j] & 1) : false;
@ -94,7 +81,7 @@ int ID_to_QRcode(const char *tox_id, FILE *fp)
for (j = 0; j < BORDER_LEN; ++j) for (j = 0; j < BORDER_LEN; ++j)
fprintf(fp, "%s", CHAR_1); fprintf(fp, "%s", CHAR_1);
fprintf(fp, "%s\n", BORDER_CHAR); fprintf(fp, "\n");
} }
QRcode_free(qr_obj); QRcode_free(qr_obj);