Introduction
Introduction Statistics Contact Development Disclaimer Help
add 16-bit colour support (only 5-6-5 format). - xscreenshot - screen capture t…
git clone git://git.codemadness.org/xscreenshot
Log
Files
Refs
README
LICENSE
---
commit 895ec4bf5e0ff2ff52e27d62a88f7927d8fc470c
parent d8f8fff9489a4e0521b682d2d9ab0698ad2b6422
Author: Hiltjo Posthuma <[email protected]>
Date: Wed, 24 Feb 2016 20:01:13 +0100
add 16-bit colour support (only 5-6-5 format).
Add 16-bit bpp colour support, only 5-6-6 format is assumed and supported.
Check explcitly for 16-bit, 24-bit and 32-bit.
Thanks Dwight Hower for the idea/feedback!
Diffstat:
M xscreenshot.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/xscreenshot.c b/xscreenshot.c
@@ -21,6 +21,7 @@ main(int argc, char *argv[])
XWindowAttributes attr;
uint32_t tmp, w, h;
uint16_t rgba[4];
+ int sr, sg, fr, fg, fb;
char *ep;
if (!(dpy = XOpenDisplay(NULL)))
@@ -53,7 +54,24 @@ main(int argc, char *argv[])
XUngrabServer(dpy);
XCloseDisplay(dpy);
if (!img)
- die("Can't XGetImage");
+ errx(1, "XGetImage\n");
+
+ switch (img->bits_per_pixel) {
+ case 16: /* only 5-6-5 format supported */
+ sr = 11;
+ sg = 5;
+ fr = fb = 2047;
+ fg = 1023;
+ break;
+ case 24:
+ case 32: /* ignore alpha in case of 32-bit */
+ sr = 16;
+ sg = 8;
+ fr = fg = fb = 257;
+ break;
+ default:
+ errx(1, "unsupported bpp: %d\n", img->bits_per_pixel);
+ }
/* write header with big endian width and height-values */
fprintf(stdout, "farbfeld");
@@ -66,9 +84,9 @@ main(int argc, char *argv[])
for (h = 0; h < (uint32_t)img->height; h++) {
for (w = 0; w < (uint32_t)img->width; w++) {
tmp = XGetPixel(img, w, h);
- rgba[0] = htons(((tmp & img->red_mask) >> 16) * 257);
- rgba[1] = htons(((tmp & img->green_mask) >> 8) * 257);
- rgba[2] = htons((tmp & img->blue_mask) * 257);
+ rgba[0] = htons(((tmp & img->red_mask) >> sr) * fr);
+ rgba[1] = htons(((tmp & img->green_mask) >> sg) * fg);
+ rgba[2] = htons((tmp & img->blue_mask) * fb);
rgba[3] = htons(65535);
if (fwrite(&rgba, 4 * sizeof(uint16_t), 1, stdout) != …
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.