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

QR PNG: convert some variables to macros

This commit is contained in:
Ansa89 2016-10-06 11:50:21 +02:00
parent abb39ea6b5
commit 6bc5d8c543
No known key found for this signature in database
GPG Key ID: 19B3DFBF159E800E
2 changed files with 11 additions and 12 deletions

View File

@ -60,7 +60,7 @@ all: $(BUILD_DIR)/toxic
$(BUILD_DIR)/toxic: $(OBJ)
@echo " LD $(@:$(BUILD_DIR)/%=%)"
$(CC) $(CFLAGS) -o $(BUILD_DIR)/toxic $(OBJ) $(LDFLAGS)
@$(CC) $(CFLAGS) -o $(BUILD_DIR)/toxic $(OBJ) $(LDFLAGS)
$(BUILD_DIR)/osx_video.o: $(SRC_DIR)/$(OSX_VIDEO)
@echo " CC $(@:$(BUILD_DIR)/)osx_video.o"

View File

@ -31,6 +31,8 @@
#ifdef QRPNG
#include <png.h>
#define INCHES_PER_METER (100.0/2.54)
#define DPI 72
#define SQUARE_SIZE 5
#endif /* QRPNG */
#define BORDER_LEN 1
@ -108,9 +110,6 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
unsigned char *p;
unsigned char black[4] = {0, 0, 0, 255};
size_t x, y, xx, yy, real_width;
size_t margin = BORDER_LEN;
size_t size = 5;
size_t dpi = 72;
png_structp png_ptr;
png_infop info_ptr;
@ -127,7 +126,7 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
return -1;
}
real_width = (qr_obj->width + margin * 2) * size;
real_width = (qr_obj->width + BORDER_LEN * 2) * SQUARE_SIZE;
size_t row_size = real_width * 4;
unsigned char row[row_size];
@ -158,14 +157,14 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
png_set_IHDR(png_ptr, info_ptr, real_width, real_width, 8,
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_pHYs(png_ptr, info_ptr, dpi * INCHES_PER_METER,
dpi * INCHES_PER_METER, PNG_RESOLUTION_METER);
png_set_pHYs(png_ptr, info_ptr, DPI * INCHES_PER_METER,
DPI * INCHES_PER_METER, PNG_RESOLUTION_METER);
png_write_info(png_ptr, info_ptr);
/* top margin */
memset(row, 0xff, row_size);
for (y = 0; y < margin * size; y++) {
for (y = 0; y < BORDER_LEN * SQUARE_SIZE; y++) {
png_write_row(png_ptr, row);
}
@ -176,16 +175,16 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
memset(row, 0xff, row_size);
for (x = 0; x < qr_obj->width; x++) {
for (xx = 0; xx < size; xx++) {
for (xx = 0; xx < SQUARE_SIZE; xx++) {
if (*p & 1) {
memcpy(&row[((margin + x) * size + xx) * 4], black, 4);
memcpy(&row[((BORDER_LEN + x) * SQUARE_SIZE + xx) * 4], black, 4);
}
}
p++;
}
for (yy = 0; yy < size; yy++) {
for (yy = 0; yy < SQUARE_SIZE; yy++) {
png_write_row(png_ptr, row);
}
}
@ -193,7 +192,7 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
/* bottom margin */
memset(row, 0xff, row_size);
for (y = 0; y < margin * size; y++) {
for (y = 0; y < BORDER_LEN * SQUARE_SIZE; y++) {
png_write_row(png_ptr, row);
}