From 391a35bd2e99ca827d44634022b060d909c5ebf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 12 Nov 2017 17:25:38 +0100 Subject: [PATCH] some cleaning --- Makefile | 7 +++++++ main.c | 16 +++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b2db521 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +SOURCES = main.c + +all: ${SOURCES} + cc ${SOURCES} -lX11 + +run: all + ./a.out diff --git a/main.c b/main.c index 665cb5e..b4fe3dc 100644 --- a/main.c +++ b/main.c @@ -24,7 +24,7 @@ int main() uint32_t width = gwa.width; uint32_t height = gwa.height; - // The first image, to measure the screen + // The first image, to measure the screen and allocate the buffer XImage *image = XGetImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap); uint8_t array[width * height * 3]; const uint32_t red_mask = image->red_mask; @@ -37,8 +37,7 @@ int main() union Color { uint32_t hex; - RGB rgb; - + RGB rgb; struct { uint8_t b; uint8_t g; @@ -46,25 +45,28 @@ int main() }; }; + // sampling steps const uint32_t xnum = 32; const uint32_t ynum = 24; const uint32_t xstep = width/xnum; const uint32_t ystep = height/ynum; + // ideally we should downscale it using nearest-neighbour + union Color *C; - while (XGetSubImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap, image, 0, 0)) { - //color.hex = XGetPixel(image, 40,40); + while (XGetSubImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap, image, 0, 0)) { +#define P_GOTO(x,y) C = ((union Color*)image->data + y*width + x); printf("\033[2J\033[H"); for (int i = 0; i < ynum; i++) { printf("\n"); for (int j = 0; j < xnum; j++) { - C = ((union Color*)image->data + i*ystep*width + j*xstep); + P_GOTO(j*xstep, i*ystep); printf("\x1b[48;2;%d;%d;%dm \x1b[m", C->r, C->g, C->b); } } - usleep(50000); + usleep(100000); } return 0;