xscreen

X11 screenshot utility
git clone https://porkepik.fr/xscreen
Log | Files | Refs | README | LICENSE

commit e297f211e067fc763882f84ba1b949342c645506
parent b62b52e906b0200441fea94d20a0c57a57e2165f
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Mon, 29 Jul 2019 16:05:20 +0200

add support for 16 bpp

Diffstat:
Mxscreen.c | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/xscreen.c b/xscreen.c @@ -254,6 +254,7 @@ delay(int delay_sec) static void capture(Window win, struct screenshot *img) { + int sr, sg; XWindowAttributes attr; XImage *ximg; @@ -274,13 +275,27 @@ capture(Window win, struct screenshot *img) if (!img->data) failure("malloc failure\n"); + switch (ximg->bits_per_pixel) { + case 16: + sr = 11; + sg = 5; + break; + case 24: + case 32: + sr = 16; + sg = 8; + break; + default: + failure("unsupported bits per pixel.\n"); + } + for (int x = 0; x < img->width; x++) { for (int y = 0; y < img->height ; y++) { unsigned long xpixel = XGetPixel(ximg, x, y); size_t pix_pos = (x + img->width * y) * 3; - img->data[pix_pos] = (xpixel & ximg->red_mask) >> 16; - img->data[pix_pos + 1] = (xpixel & ximg->green_mask) >> 8; + img->data[pix_pos] = (xpixel & ximg->red_mask) >> sr; + img->data[pix_pos + 1] = (xpixel & ximg->green_mask) >> sg; img->data[pix_pos + 2] = xpixel & ximg->blue_mask; } }