mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 07:43:03 +01:00
Merge branch 'master' into new_groupchats
This commit is contained in:
commit
9dfa455561
@ -34,6 +34,12 @@ ifneq ($(DESK_NOTIFY), disabled)
|
||||
-include $(CHECKS_DIR)/desktop_notifications.mk
|
||||
endif
|
||||
|
||||
# Check if we want build QR exported as PNG support
|
||||
QR_PNG = $(shell if [ -z "$(DISABLE_QRPNG)" ] || [ "$(DISABLE_QRPNG)" = "0" ] ; then echo enabled ; else echo disabled ; fi)
|
||||
ifneq ($(QR_PNG), disabled)
|
||||
-include $(CHECKS_DIR)/qr_png.mk
|
||||
endif
|
||||
|
||||
# Check if we can build Toxic
|
||||
CHECK_LIBS = $(shell $(PKG_CONFIG) --exists $(LIBS) || echo -n "error")
|
||||
ifneq ($(CHECK_LIBS), error)
|
||||
|
15
cfg/checks/qr_png.mk
Normal file
15
cfg/checks/qr_png.mk
Normal file
@ -0,0 +1,15 @@
|
||||
# Variables for QR exported as PNG support
|
||||
PNG_LIBS = libpng
|
||||
PNG_CFLAGS = -DQRPNG
|
||||
|
||||
# Check if we can build QR exported as PNG support
|
||||
CHECK_PNG_LIBS = $(shell pkg-config --exists $(PNG_LIBS) || echo -n "error")
|
||||
ifneq ($(CHECK_PNG_LIBS), error)
|
||||
LIBS += $(PNG_LIBS)
|
||||
CFLAGS += $(PNG_CFLAGS)
|
||||
else ifneq ($(MAKECMDGOALS), clean)
|
||||
MISSING_PNG_LIBS = $(shell for lib in $(PNG_LIBS) ; do if ! $(PKG_CONFIG) --exists $$lib ; then echo $$lib ; fi ; done)
|
||||
$(warning WARNING -- Toxic will be compiled without QR exported as PNG support)
|
||||
$(warning WARNING -- You need these libraries for QR exported as PNG support)
|
||||
$(warning WARNING -- $(MISSING_PNG_LIBS))
|
||||
endif
|
@ -8,13 +8,13 @@ else
|
||||
endif
|
||||
|
||||
# Check if we can build video support
|
||||
CHECK_VIDEO_LIBS = $(shell pkg-config --exists $(VIDEO_LIBS) || echo -n "error")
|
||||
CHECK_VIDEO_LIBS = $(shell $(PKG_CONFIG) --exists $(VIDEO_LIBS) || echo -n "error")
|
||||
ifneq ($(CHECK_VIDEO_LIBS), error)
|
||||
LIBS += $(VIDEO_LIBS)
|
||||
CFLAGS += $(VIDEO_CFLAGS)
|
||||
OBJ += $(VIDEO_OBJ)
|
||||
else ifneq ($(MAKECMDGOALS), clean)
|
||||
MISSING_VIDEO_LIBS = $(shell for lib in $(VIDEO_LIBS) ; do if ! pkg-config --exists $$lib ; then echo $$lib ; fi ; done)
|
||||
MISSING_VIDEO_LIBS = $(shell for lib in $(VIDEO_LIBS) ; do if ! $(PKG_CONFIG) --exists $$lib ; then echo $$lib ; fi ; done)
|
||||
$(warning WARNING -- Toxic will be compiled without video support)
|
||||
$(warning WARNING -- You will need these libraries for video support)
|
||||
$(warning WARNING -- $(MISSING_VIDEO_LIBS))
|
||||
|
@ -14,6 +14,7 @@ help:
|
||||
@echo " DISABLE_AV: Set to \"1\" to force building without audio call support"
|
||||
@echo " DISABLE_SOUND_NOTIFY: Set to \"1\" to force building without sound notification support"
|
||||
@echo " DISABLE_DESKTOP_NOTIFY: Set to \"1\" to force building without desktop notifications support"
|
||||
@echo " DISABLE_QRPNG: Set to \"1\" to force building without QR exported as PNG support"
|
||||
@echo " USER_CFLAGS: Add custom flags to default CFLAGS"
|
||||
@echo " USER_LDFLAGS: Add custom flags to default LDFLAGS"
|
||||
@echo " PREFIX: Specify a prefix directory for binaries, data files,... (default is \"$(abspath $(PREFIX))\")"
|
||||
|
@ -542,25 +542,42 @@ void cmd_myqr(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
char dir[data_file_len + 1];
|
||||
size_t dir_len = get_base_dir(DATA_FILE, data_file_len, dir);
|
||||
|
||||
#ifdef QRPNG
|
||||
|
||||
if (argc == 0) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Required 'txt' or 'png'");
|
||||
return;
|
||||
} else if (!strcmp(argv[1], "txt")) {
|
||||
|
||||
#endif /* QRPNG */
|
||||
char qr_path[dir_len + nick_len + strlen(QRCODE_FILENAME_EXT) + 1];
|
||||
snprintf(qr_path, sizeof(qr_path), "%s%s%s", dir, nick, QRCODE_FILENAME_EXT);
|
||||
|
||||
FILE *output = fopen(qr_path, "wb");
|
||||
|
||||
if (output == NULL) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ID_to_QRcode(id_string, output) == -1) {
|
||||
fclose(output);
|
||||
if (ID_to_QRcode_txt(id_string, qr_path) == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
||||
return;
|
||||
}
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "QR code has been printed to the file '%s'", qr_path);
|
||||
|
||||
fclose(output);
|
||||
#ifdef QRPNG
|
||||
} else if (!strcmp(argv[1], "png")) {
|
||||
char qr_path[dir_len + nick_len + strlen(QRCODE_FILENAME_EXT_PNG) + 1];
|
||||
snprintf(qr_path, sizeof(qr_path), "%s%s%s", dir, nick, QRCODE_FILENAME_EXT_PNG);
|
||||
|
||||
if (ID_to_QRcode_png(id_string, qr_path) == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
||||
return;
|
||||
}
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "QR code has been printed to the file '%s'", qr_path);
|
||||
|
||||
} else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Unknown option '%s' -- Required 'txt' or 'png'", argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* QRPNG */
|
||||
}
|
||||
|
||||
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
|
@ -159,7 +159,11 @@ static void help_draw_global(ToxWindow *self)
|
||||
wprintw(win, " /nospam <value> : Change part of your Tox ID to stop spam\n");
|
||||
wprintw(win, " /log <on> or <off> : Enable/disable logging\n");
|
||||
wprintw(win, " /myid : Print your Tox ID\n");
|
||||
#ifdef QRPNG
|
||||
wprintw(win, " /myqr <txt> or <png> : Print your Tox ID's QR code to a file.\n");
|
||||
#else
|
||||
wprintw(win, " /myqr : Print your Tox ID's QR code to a file.\n");
|
||||
#endif /* QRPNG */
|
||||
wprintw(win, " /clear : Clear window history\n");
|
||||
wprintw(win, " /close : Close the current chat window\n");
|
||||
wprintw(win, " /quit or /exit : Exit Toxic\n");
|
||||
|
@ -26,9 +26,13 @@
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "toxic.h"
|
||||
#include "windows.h"
|
||||
|
@ -128,7 +128,8 @@ void bgrxtoyuv420(uint8_t *plane_y, uint8_t *plane_u, uint8_t *plane_v, uint8_t
|
||||
|
||||
- (instancetype)initWithDeviceNames:
|
||||
(char **)device_names AmtDevices:
|
||||
(int *)size {
|
||||
(int *)size
|
||||
{
|
||||
_session = [[AVCaptureSession alloc] init];
|
||||
|
||||
NSArray *devices = [AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo];
|
||||
@ -151,7 +152,8 @@ strcpy(video_input_name, (char *)[localizedName cStringUsingEncoding: NSUTF8Stri
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
- (void)dealloc
|
||||
{
|
||||
pthread_mutex_destroy(&_frameLock);
|
||||
[_session release];
|
||||
[_linkerVideo release];
|
||||
@ -162,7 +164,8 @@ strcpy(video_input_name, (char *)[localizedName cStringUsingEncoding: NSUTF8Stri
|
||||
- (int)openVideoDeviceIndex:
|
||||
(uint32_t)device_idx Width:
|
||||
(uint16_t *)width Height:
|
||||
(uint16_t *)height {
|
||||
(uint16_t *)height
|
||||
{
|
||||
pthread_mutex_init(&_frameLock, NULL);
|
||||
pthread_mutex_lock(&_frameLock);
|
||||
_processingQueue = dispatch_queue_create("Toxic processing queue", DISPATCH_QUEUE_SERIAL);
|
||||
@ -212,6 +215,7 @@ AVCaptureInput *input = [[AVCaptureDeviceInput alloc] initWithDevice: device err
|
||||
} else {
|
||||
[_linkerVideo setVideoSettings: @ {(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}];
|
||||
}
|
||||
|
||||
[_session addOutput: _linkerVideo];
|
||||
[_session startRunning];
|
||||
|
||||
@ -220,7 +224,8 @@ AVCaptureInput *input = [[AVCaptureDeviceInput alloc] initWithDevice: device err
|
||||
}
|
||||
|
||||
- (void)closeVideoDeviceIndex:
|
||||
(uint32_t)device_idx {
|
||||
(uint32_t)device_idx
|
||||
{
|
||||
NSArray *devices = [AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo];
|
||||
AVCaptureDevice *device = [devices objectAtIndex: device_idx];
|
||||
NSError *error = NULL;
|
||||
@ -234,7 +239,8 @@ AVCaptureInput *input = [[AVCaptureDeviceInput alloc] initWithDevice: device err
|
||||
- (void)captureOutput:
|
||||
(AVCaptureOutput *)captureOutput didOutputSampleBuffer:
|
||||
(CMSampleBufferRef)sampleBuffer fromConnection:
|
||||
(AVCaptureConnection *)connection {
|
||||
(AVCaptureConnection *)connection
|
||||
{
|
||||
pthread_mutex_lock(&_frameLock);
|
||||
CVImageBufferRef img = CMSampleBufferGetImageBuffer(sampleBuffer);
|
||||
|
||||
@ -248,6 +254,7 @@ AVCaptureInput *input = [[AVCaptureDeviceInput alloc] initWithDevice: device err
|
||||
// we're not going to do anything to it, so it's safe to lock it always
|
||||
CVPixelBufferLockBaseAddress(_currentFrame, kCVPixelBufferLock_ReadOnly);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&_frameLock);
|
||||
}
|
||||
|
||||
@ -256,7 +263,8 @@ AVCaptureInput *input = [[AVCaptureDeviceInput alloc] initWithDevice: device err
|
||||
(uint8_t *)u V:
|
||||
(uint8_t *)v Width:
|
||||
(uint16_t *)width Height:
|
||||
(uint16_t *)height {
|
||||
(uint16_t *)height
|
||||
{
|
||||
if (!_currentFrame) {
|
||||
return -1;
|
||||
}
|
||||
|
126
src/qr_code.c
126
src/qr_code.c
@ -28,25 +28,36 @@
|
||||
#include "windows.h"
|
||||
#include "qr_code.h"
|
||||
|
||||
#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
|
||||
#define CHAR_1 "\342\226\210"
|
||||
#define CHAR_2 "\342\226\204"
|
||||
#define CHAR_3 "\342\226\200"
|
||||
|
||||
/* 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 into the given filename.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int ID_to_QRcode(const char *tox_id, FILE *fp)
|
||||
int ID_to_QRcode_txt(const char *tox_id, const char *outfile)
|
||||
{
|
||||
FILE *fp = fopen(outfile, "wb");
|
||||
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
|
||||
QRcode *qr_obj = QRcode_encodeString(tox_id, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
|
||||
|
||||
if (qr_obj == NULL)
|
||||
if (qr_obj == NULL) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t width = qr_obj->width;
|
||||
size_t i, j;
|
||||
@ -83,7 +94,116 @@ int ID_to_QRcode(const char *tox_id, FILE *fp)
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
QRcode_free(qr_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef QRPNG
|
||||
/* Converts a tox ID string into a QRcode and prints it into the given filename as png.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int ID_to_QRcode_png(const char *tox_id, const char *outfile)
|
||||
{
|
||||
static FILE *fp;
|
||||
unsigned char *p;
|
||||
unsigned char black[4] = {0, 0, 0, 255};
|
||||
size_t x, y, xx, yy, real_width;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
||||
fp = fopen(outfile, "wb");
|
||||
|
||||
if (fp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
QRcode *qr_obj = QRcode_encodeString(tox_id, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
|
||||
|
||||
if (qr_obj == NULL) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
real_width = (qr_obj->width + BORDER_LEN * 2) * SQUARE_SIZE;
|
||||
size_t row_size = real_width * 4;
|
||||
unsigned char row[row_size];
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
if (png_ptr == NULL) {
|
||||
fclose(fp);
|
||||
QRcode_free(qr_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
|
||||
if (info_ptr == NULL) {
|
||||
fclose(fp);
|
||||
QRcode_free(qr_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
fclose(fp);
|
||||
QRcode_free(qr_obj);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
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_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* top margin */
|
||||
memset(row, 0xff, row_size);
|
||||
|
||||
for (y = 0; y < BORDER_LEN * SQUARE_SIZE; y++) {
|
||||
png_write_row(png_ptr, row);
|
||||
}
|
||||
|
||||
/* data */
|
||||
p = qr_obj->data;
|
||||
|
||||
for (y = 0; y < qr_obj->width; y++) {
|
||||
memset(row, 0xff, row_size);
|
||||
|
||||
for (x = 0; x < qr_obj->width; x++) {
|
||||
for (xx = 0; xx < SQUARE_SIZE; xx++) {
|
||||
if (*p & 1) {
|
||||
memcpy(&row[((BORDER_LEN + x) * SQUARE_SIZE + xx) * 4], black, 4);
|
||||
}
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
for (yy = 0; yy < SQUARE_SIZE; yy++) {
|
||||
png_write_row(png_ptr, row);
|
||||
}
|
||||
}
|
||||
|
||||
/* bottom margin */
|
||||
memset(row, 0xff, row_size);
|
||||
|
||||
for (y = 0; y < BORDER_LEN * SQUARE_SIZE; y++) {
|
||||
png_write_row(png_ptr, row);
|
||||
}
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
fclose(fp);
|
||||
QRcode_free(qr_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* QRPNG */
|
||||
|
@ -25,11 +25,21 @@
|
||||
|
||||
#define QRCODE_FILENAME_EXT ".QRcode"
|
||||
|
||||
/* 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 into the given filename.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int ID_to_QRcode(const char *tox_id, FILE *fp);
|
||||
int ID_to_QRcode_txt(const char *tox_id, const char *outfile);
|
||||
|
||||
#ifdef QRPNG
|
||||
#define QRCODE_FILENAME_EXT_PNG ".QRcode.png"
|
||||
/* Converts a tox ID string into a QRcode and prints it into the given filename as png.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int ID_to_QRcode_png(const char *tox_id, const char *outfile);
|
||||
#endif /* QRPNG */
|
||||
|
||||
#endif /* QR_CODE */
|
||||
|
Loading…
Reference in New Issue
Block a user