Refactor pixel-calculation - xscreenshot - screen capture tool
 (HTM) git clone git://git.codemadness.org/xscreenshot
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1f1d1ce39921ed510d6927243da836a906f0f26d
 (DIR) parent d027bcf68df72a92e3b0f6d2b7b97e73e736f4ed
 (HTM) Author: Laslo Hunhold <dev@frign.de>
       Date:   Mon, 28 Jul 2014 18:35:39 +0000
       
       Refactor pixel-calculation
       
       patch slightly adjusted to avoid type warnings.
       
       Diffstat:
         M xscreenshot.c                       |      18 +++++++-----------
       
       1 file changed, 7 insertions(+), 11 deletions(-)
       ---
 (DIR) 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;