mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 07:33:25 +01:00
Slight improvement to qrcode printing
This commit is contained in:
parent
39c4b7ecdd
commit
7e0b8b4870
@ -34,20 +34,6 @@
|
||||
#define CHAR_2 "\342\226\204"
|
||||
#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.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
@ -64,19 +50,20 @@ int ID_to_QRcode(const char *tox_id, FILE *fp)
|
||||
return -1;
|
||||
|
||||
size_t width = qr_obj->width;
|
||||
add_border(fp, width);
|
||||
|
||||
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) {
|
||||
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)
|
||||
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) {
|
||||
bool x = row_1[j] & 1;
|
||||
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)
|
||||
fprintf(fp, "%s", CHAR_1);
|
||||
|
||||
fprintf(fp, "%s\n", BORDER_CHAR);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
QRcode_free(qr_obj);
|
||||
|
Loading…
Reference in New Issue
Block a user