xscreenshot

suckless screen capture tool
git clone git://git.2f30.org/xscreenshot.git
Log | Files | Refs | README | LICENSE

commit 1f1d1ce39921ed510d6927243da836a906f0f26d
parent d027bcf68df72a92e3b0f6d2b7b97e73e736f4ed
Author: Laslo Hunhold <dev@frign.de>
Date:   Mon Jul 28 18:35:39 +0000

Refactor pixel-calculation

patch slightly adjusted to avoid type warnings.

Diffstat:
xscreenshot.c | 18+++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/xscreenshot.c b/xscreenshot.c @@ -31,9 +31,7 @@ main(int argc, char *argv[]) Display *dpy; Window win; XWindowAttributes attr; - uint32_t tmp, pix; - uint8_t rgba[4] = {0, 0, 0, 255}; - int w, h; + uint32_t tmp, w, h; dpy = XOpenDisplay(NULL); if(!dpy) @@ -68,17 +66,15 @@ main(int argc, char *argv[]) fwrite(&tmp, sizeof(uint32_t), 1, stdout); /* write pixels */ - for(h = 0; h < img->height; ++h) { - for(w = 0; w < img->width; ++w) { - pix = XGetPixel(img, w, h); - rgba[0] = (pix & img->red_mask) >> 16; - rgba[1] = (pix & img->green_mask) >> 8; - rgba[2] = (pix & img->blue_mask) >> 0; - if(fwrite(&rgba, sizeof(uint8_t), 4, stdout) != 4) + for(h = 0; h < (uint32_t)img->height; h++) { + for(w = 0; w < (uint32_t)img->width; w++) { + tmp = XGetPixel(img, w, h); + tmp = ((tmp & img->red_mask) >> 16) | (tmp & img->green_mask) + | ((tmp & img->blue_mask) << 16) | (255 << 24); + if(fwrite(&tmp, sizeof(uint32_t), 1, stdout) != 1) die("fwrite() failed"); } } - XDestroyImage(img); return EXIT_SUCCESS;