From 9edf5074230d714b5a25ded5652877a1bac46d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 12 Nov 2017 17:19:46 +0100 Subject: [PATCH] initial work --- main.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..665cb5e --- /dev/null +++ b/main.c @@ -0,0 +1,100 @@ +#include +#include +#include + +#include +#include +#include +#include + +typedef struct RGB_struct { + uint8_t b; + uint8_t g; + uint8_t r; +} RGB; + +int main() +{ + Display *display = XOpenDisplay(NULL); + Window root = DefaultRootWindow(display); + + XWindowAttributes gwa; + + XGetWindowAttributes(display, root, &gwa); + uint32_t width = gwa.width; + uint32_t height = gwa.height; + + // The first image, to measure the screen + 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; + const uint32_t green_mask = image->green_mask; + const uint32_t blue_mask = image->blue_mask; + + printf("mask: %p %p %p\nbyte_order: %d\nunit: %d\nbit_order: %d\npad: %d\ndepth: %d\nBPL: %d\nbPPx: %d\n", + red_mask, green_mask, blue_mask, image->byte_order, image->bitmap_unit, + image->bitmap_bit_order, image->bitmap_pad, image->depth, image->bytes_per_line, image->bits_per_pixel); + + union Color { + uint32_t hex; + RGB rgb; + + struct { + uint8_t b; + uint8_t g; + uint8_t r; + }; + }; + + const uint32_t xnum = 32; + const uint32_t ynum = 24; + const uint32_t xstep = width/xnum; + const uint32_t ystep = height/ynum; + + union Color *C; + while (XGetSubImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap, image, 0, 0)) { + //color.hex = XGetPixel(image, 40,40); + + 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); + printf("\x1b[48;2;%d;%d;%dm \x1b[m", C->r, C->g, C->b); + } + } + + usleep(50000); + } + + return 0; +} + +#if 0 +typedef struct _XImage { + int width, height; /* size of image */ + int xoffset; /* number of pixels offset in X direction */ + int format; /* XYBitmap, XYPixmap, ZPixmap */ + char *data; /* pointer to image data */ + int byte_order; /* data byte order, LSBFirst, MSBFirst */ + int bitmap_unit; /* quant. of scanline 8, 16, 32 */ + int bitmap_bit_order; /* LSBFirst, MSBFirst */ + int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */ + int depth; /* depth of image */ + int bytes_per_line; /* accelerator to next scanline */ + int bits_per_pixel; /* bits per pixel (ZPixmap) */ + unsigned long red_mask; /* bits in z arrangement */ + unsigned long green_mask; + unsigned long blue_mask; + XPointer obdata; /* hook for the object routines to hang on */ + struct funcs { /* image manipulation routines */ + struct _XImage *(*create_image)(); + int (*destroy_image)(); + unsigned long (*get_pixel)(); + int (*put_pixel)(); + struct _XImage *(*sub_image)(); + int (*add_pixel)(); + } f; +} XImage; +#endif +