|
|
@ -5,29 +5,51 @@
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME duplicated--ought these just be exported?
|
|
|
|
|
|
|
|
#define QR_BASE_SIZE 17
|
|
|
|
|
|
|
|
#define PER_QR_VERSION 4
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
|
|
qrcode_rows(int version){
|
|
|
|
|
|
|
|
return QR_BASE_SIZE + (version * PER_QR_VERSION / 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
|
|
qrcode_cols(int version){
|
|
|
|
|
|
|
|
return QR_BASE_SIZE + (version * PER_QR_VERSION);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qrcode_demo(struct notcurses* nc){
|
|
|
|
int qrcode_demo(struct notcurses* nc){
|
|
|
|
#ifdef USE_QRCODEGEN
|
|
|
|
#ifdef USE_QRCODEGEN
|
|
|
|
char data[128];
|
|
|
|
char data[128];
|
|
|
|
int dimy, dimx;
|
|
|
|
int dimy, dimx;
|
|
|
|
struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
|
|
|
|
struct ncplane *stdn = notcurses_stddim_yx(nc, &dimy, &dimx);
|
|
|
|
|
|
|
|
ncplane_erase(stdn);
|
|
|
|
|
|
|
|
struct ncplane* n = ncplane_dup(stdn, NULL);
|
|
|
|
for(int i = 0 ; i < 1024 ; ++i){
|
|
|
|
for(int i = 0 ; i < 1024 ; ++i){
|
|
|
|
ncplane_erase(n);
|
|
|
|
ncplane_erase(n);
|
|
|
|
size_t len = random() % sizeof(data) + 1;
|
|
|
|
size_t len = random() % sizeof(data) + 1;
|
|
|
|
#ifdef __linux__
|
|
|
|
#ifdef __linux__
|
|
|
|
ssize_t got = getrandom(data, len, 0);
|
|
|
|
ssize_t got = getrandom(data, len, 0);
|
|
|
|
if(got < 0 || (size_t)got != len){
|
|
|
|
if(got < 0 || (size_t)got != len){
|
|
|
|
|
|
|
|
ncplane_destroy(n);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
arc4rand(data, len, 0);
|
|
|
|
arc4rand(data, len, 0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if(ncplane_cursor_move_yx(n, 0, 0)){
|
|
|
|
if(ncplane_cursor_move_yx(n, 0, 0)){
|
|
|
|
|
|
|
|
ncplane_destroy(n);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ncplane_qrcode(n, 0, data, len) <= 0){
|
|
|
|
int qlen = ncplane_qrcode(n, 0, data, len);
|
|
|
|
|
|
|
|
if(qlen <= 0){
|
|
|
|
|
|
|
|
ncplane_destroy(n);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ncplane_move_yx(n, dimy / 2 - qrcode_rows(qlen) / 2,
|
|
|
|
|
|
|
|
dimx / 2 - qrcode_cols(qlen) / 2);
|
|
|
|
if(ncplane_cursor_move_yx(n, 0, 0)){
|
|
|
|
if(ncplane_cursor_move_yx(n, 0, 0)){
|
|
|
|
|
|
|
|
ncplane_destroy(n);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint64_t tl = 0, bl = 0, br = 0, tr = 0;
|
|
|
|
uint64_t tl = 0, bl = 0, br = 0, tr = 0;
|
|
|
@ -36,12 +58,13 @@ int qrcode_demo(struct notcurses* nc){
|
|
|
|
channels_set_fg_rgb(&bl, random() % 255 + 1, random() % 255 + 1, random() % 255 + 1);
|
|
|
|
channels_set_fg_rgb(&bl, random() % 255 + 1, random() % 255 + 1, random() % 255 + 1);
|
|
|
|
channels_set_fg_rgb(&br, random() % 255 + 1, random() % 255 + 1, random() % 255 + 1);
|
|
|
|
channels_set_fg_rgb(&br, random() % 255 + 1, random() % 255 + 1, random() % 255 + 1);
|
|
|
|
if(ncplane_stain(n, dimy - 1, dimx - 1, tl, tr, bl, br) <= 0){
|
|
|
|
if(ncplane_stain(n, dimy - 1, dimx - 1, tl, tr, bl, br) <= 0){
|
|
|
|
|
|
|
|
ncplane_destroy(n);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEMO_RENDER(nc);
|
|
|
|
DEMO_RENDER(nc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
ncplane_erase(notcurses_stdplane(nc));
|
|
|
|
ncplane_destroy(n);
|
|
|
|
DEMO_RENDER(nc);
|
|
|
|
DEMO_RENDER(nc);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|