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

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: 
                      7:   This file is distributed under the GNU Public License, version 2 or at your
                      8:   option any later version. Read the file gpl.txt for details.
                      9: */
                     10: 
                     11: 
                     12: /*----------------------------------------------------------------------*/
                     13: /* Convert pixels to 24-bit RGB (3 bytes per pixel)                    */
                     14: /*----------------------------------------------------------------------*/
                     15: 
                     16: /**
                     17:  * Unpack 8-bit data with RGB palette to 24-bit RGB pixels
                     18:  */
                     19: static inline void PixelConvert_8to24Bits(Uint8 *dst, Uint8 *src, int w, SDL_Color *colors)
                     20: {
                     21:        int x;
                     22:        for (x = 0; x < w; x++, src++) {
                     23:                *dst++ = colors[*src].r;
                     24:                *dst++ = colors[*src].g;
                     25:                *dst++ = colors[*src].b;
                     26:        }
                     27: }
                     28: 
                     29: /**
                     30:  * Unpack 16-bit RGB pixels to 24-bit RGB pixels
                     31:  */
                     32: static inline void PixelConvert_16to24Bits(Uint8 *dst, Uint16 *src, int w, SDL_PixelFormat *fmt)
                     33: {
                     34:        int x;
                     35:        for (x = 0; x < w; x++, src++) {
                     36:                *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
                     37:                *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
                     38:                *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
                     39:        }
                     40: }
                     41: 
                     42: /**
                     43:  *  unpack 32-bit RGBA pixels to 24-bit RGB pixels
                     44:  */
                     45: static inline void PixelConvert_32to24Bits(Uint8 *dst, Uint32 *src, int w, SDL_PixelFormat *fmt)
                     46: {
                     47:        int x;
                     48:        for (x = 0; x < w; x++, src++)
                     49:        {
                     50:                *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
                     51:                *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
                     52:                *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
                     53:        }
                     54: }
                     55: 
                     56: 
                     57: 
                     58: /*----------------------------------------------------------------------*/
                     59: /* Convert pixels to 24-bit BGR (3 bytes per pixel, used in BMP format)        */
                     60: /*----------------------------------------------------------------------*/
                     61: 
                     62: /**
                     63:  * Unpack 8-bit data with RGB palette to 24-bit BGR pixels
                     64:  */
                     65: static inline void PixelConvert_8to24Bits_BGR(Uint8 *dst, Uint8 *src, int w, SDL_Color *colors)
                     66: {
                     67:        int x;
                     68:        for (x = 0; x < w; x++, src++) {
                     69:                *dst++ = colors[*src].b;
                     70:                *dst++ = colors[*src].g;
                     71:                *dst++ = colors[*src].r;
                     72:        }
                     73: }
                     74: 
                     75: /**
                     76:  * Unpack 16-bit RGB pixels to 24-bit BGR pixels
                     77:  */
                     78: static inline void PixelConvert_16to24Bits_BGR(Uint8 *dst, Uint16 *src, int w, SDL_PixelFormat *fmt)
                     79: {
                     80:        int x;
                     81:        for (x = 0; x < w; x++, src++) {
                     82:                *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
                     83:                *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
                     84:                *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
                     85:        }
                     86: }
                     87: 
                     88: /**
                     89:  *  unpack 24-bit RGB pixels to 24-bit BGR pixels
                     90:  */
                     91: static inline void PixelConvert_24to24Bits_BGR(Uint8 *dst, Uint8 *src, int w)
                     92: {
                     93:        int x;
                     94:        for (x = 0; x < w; x++, src += 3) {
                     95: #if SDL_BYTEORDER == SDL_BIG_ENDIAN
                     96:                *dst++ = src[2];        /* B */
                     97:                *dst++ = src[1];        /* G */
                     98:                *dst++ = src[0];        /* R */
                     99: #else
                    100:                *dst++ = src[0];        /* B */
                    101:                *dst++ = src[1];        /* G */
                    102:                *dst++ = src[2];        /* R */
                    103: #endif
                    104:        }
                    105: }
                    106: 
                    107: /**
                    108:  *  unpack 32-bit RGBA pixels to 24-bit BGR pixels
                    109:  */
                    110: static inline void PixelConvert_32to24Bits_BGR(Uint8 *dst, Uint32 *src, int w, SDL_PixelFormat *fmt)
                    111: {
                    112:        int x;
                    113:        for (x = 0; x < w; x++, src++)
                    114:        {
                    115:                *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);
                    116:                *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);
                    117:                *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);
                    118:        }
                    119: }

unix.superglobalmegacorp.com

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