mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 15:03:03 +01:00
QR PNG: convert some variables to macros
This commit is contained in:
parent
abb39ea6b5
commit
6bc5d8c543
2
Makefile
2
Makefile
@ -60,7 +60,7 @@ all: $(BUILD_DIR)/toxic
|
|||||||
|
|
||||||
$(BUILD_DIR)/toxic: $(OBJ)
|
$(BUILD_DIR)/toxic: $(OBJ)
|
||||||
@echo " LD $(@:$(BUILD_DIR)/%=%)"
|
@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)
|
$(BUILD_DIR)/osx_video.o: $(SRC_DIR)/$(OSX_VIDEO)
|
||||||
@echo " CC $(@:$(BUILD_DIR)/)osx_video.o"
|
@echo " CC $(@:$(BUILD_DIR)/)osx_video.o"
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#ifdef QRPNG
|
#ifdef QRPNG
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
#define INCHES_PER_METER (100.0/2.54)
|
#define INCHES_PER_METER (100.0/2.54)
|
||||||
|
#define DPI 72
|
||||||
|
#define SQUARE_SIZE 5
|
||||||
#endif /* QRPNG */
|
#endif /* QRPNG */
|
||||||
|
|
||||||
#define BORDER_LEN 1
|
#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 *p;
|
||||||
unsigned char black[4] = {0, 0, 0, 255};
|
unsigned char black[4] = {0, 0, 0, 255};
|
||||||
size_t x, y, xx, yy, real_width;
|
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_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
|
|
||||||
@ -127,7 +126,7 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
|
|||||||
return -1;
|
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;
|
size_t row_size = real_width * 4;
|
||||||
unsigned char row[row_size];
|
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_set_IHDR(png_ptr, info_ptr, real_width, real_width, 8,
|
||||||
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
||||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
png_set_pHYs(png_ptr, info_ptr, dpi * INCHES_PER_METER,
|
png_set_pHYs(png_ptr, info_ptr, DPI * INCHES_PER_METER,
|
||||||
dpi * INCHES_PER_METER, PNG_RESOLUTION_METER);
|
DPI * INCHES_PER_METER, PNG_RESOLUTION_METER);
|
||||||
png_write_info(png_ptr, info_ptr);
|
png_write_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
/* top margin */
|
/* top margin */
|
||||||
memset(row, 0xff, row_size);
|
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);
|
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);
|
memset(row, 0xff, row_size);
|
||||||
|
|
||||||
for (x = 0; x < qr_obj->width; x++) {
|
for (x = 0; x < qr_obj->width; x++) {
|
||||||
for (xx = 0; xx < size; xx++) {
|
for (xx = 0; xx < SQUARE_SIZE; xx++) {
|
||||||
if (*p & 1) {
|
if (*p & 1) {
|
||||||
memcpy(&row[((margin + x) * size + xx) * 4], black, 4);
|
memcpy(&row[((BORDER_LEN + x) * SQUARE_SIZE + xx) * 4], black, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (yy = 0; yy < size; yy++) {
|
for (yy = 0; yy < SQUARE_SIZE; yy++) {
|
||||||
png_write_row(png_ptr, row);
|
png_write_row(png_ptr, row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +192,7 @@ int ID_to_QRcode_png(const char *tox_id, const char *outfile)
|
|||||||
/* bottom margin */
|
/* bottom margin */
|
||||||
memset(row, 0xff, row_size);
|
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);
|
png_write_row(png_ptr, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user