Annotation of hatari/src/includes/pixel_convert.h, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - pixel_convert.h
                      3: 
                      4:   Functions to convert pixels from different bit depths to 24 bits RGB or BGR.
                      5:   Used to save png screenshot and to record avi.
                      6: 
1.1.1.2   root        7:   This file is distributed under the GNU General Public License, version 2
                      8:   or at your option any later version. Read the file gpl.txt for details.
1.1       root        9: */
                     10: 
                     11: 
                     12: /*----------------------------------------------------------------------*/
                     13: /* Convert pixels to 24-bit RGB (3 bytes per pixel)                    */
                     14: /*----------------------------------------------------------------------*/
                     15: 
                     16: /**
                     17:  * Unpack 16-bit RGB pixels to 24-bit RGB pixels
                     18:  */
1.1.1.3 ! root       19: static inline void PixelConvert_16to24Bits(Uint8 *dst, Uint16 *src, int dw, SDL_Surface *surf)
1.1       root       20: {
1.1.1.3 ! root       21:        SDL_PixelFormat *fmt = surf->format;
        !            22:        Uint16 sval;
        !            23:        int dx;
        !            24: 
        !            25:        for (dx = 0; dx < dw; dx++)
        !            26:        {
        !            27:                sval = src[(dx * surf->w + dw/2) / dw];
        !            28:                *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
        !            29:                *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
        !            30:                *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
1.1       root       31:        }
                     32: }
                     33: 
                     34: /**
                     35:  *  unpack 32-bit RGBA pixels to 24-bit RGB pixels
                     36:  */
1.1.1.3 ! root       37: static inline void PixelConvert_32to24Bits(Uint8 *dst, Uint32 *src, int dw, SDL_Surface *surf)
1.1       root       38: {
1.1.1.3 ! root       39:        SDL_PixelFormat *fmt = surf->format;
        !            40:        Uint32 sval;
        !            41:        int dx;
        !            42: 
        !            43:        for (dx = 0; dx < dw; dx++)
1.1       root       44:        {
1.1.1.3 ! root       45:                sval = src[(dx * surf->w + dw/2) / dw];
        !            46:                *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
        !            47:                *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
        !            48:                *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
1.1       root       49:        }
                     50: }
                     51: 
                     52: 
                     53: 
                     54: /*----------------------------------------------------------------------*/
                     55: /* Convert pixels to 24-bit BGR (3 bytes per pixel, used in BMP format)        */
                     56: /*----------------------------------------------------------------------*/
                     57: 
                     58: /**
                     59:  * Unpack 16-bit RGB pixels to 24-bit BGR pixels
                     60:  */
1.1.1.3 ! root       61: static inline void PixelConvert_16to24Bits_BGR(Uint8 *dst, Uint16 *src, int dw, SDL_Surface *surf)
1.1       root       62: {
1.1.1.3 ! root       63:        SDL_PixelFormat *fmt = surf->format;
        !            64:        Uint16 sval;
        !            65:        int dx;
1.1       root       66: 
1.1.1.3 ! root       67:        for (dx = 0; dx < dw; dx++)
        !            68:        {
        !            69:                sval = src[(dx * surf->w + dw/2) / dw];
        !            70:                *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
        !            71:                *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
        !            72:                *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
1.1       root       73:        }
                     74: }
                     75: 
                     76: /**
                     77:  *  unpack 32-bit RGBA pixels to 24-bit BGR pixels
                     78:  */
1.1.1.3 ! root       79: static inline void PixelConvert_32to24Bits_BGR(Uint8 *dst, Uint32 *src, int dw, SDL_Surface *surf)
1.1       root       80: {
1.1.1.3 ! root       81:        SDL_PixelFormat *fmt = surf->format;
        !            82:        Uint32 sval;
        !            83:        int dx;
        !            84: 
        !            85:        for (dx = 0; dx < dw; dx++)
1.1       root       86:        {
1.1.1.3 ! root       87:                sval = src[(dx * surf->w + dw/2) / dw];
        !            88:                *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
        !            89:                *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
        !            90:                *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
1.1       root       91:        }
                     92: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.