--- hatari/src/includes/pixel_convert.h 2019/04/09 08:53:18 1.1.1.2 +++ hatari/src/includes/pixel_convert.h 2019/04/09 08:58:13 1.1.1.3 @@ -14,42 +14,38 @@ /*----------------------------------------------------------------------*/ /** - * Unpack 8-bit data with RGB palette to 24-bit RGB pixels - */ -static inline void PixelConvert_8to24Bits(Uint8 *dst, Uint8 *src, int w, SDL_Color *colors) -{ - int x; - for (x = 0; x < w; x++, src++) { - *dst++ = colors[*src].r; - *dst++ = colors[*src].g; - *dst++ = colors[*src].b; - } -} - -/** * Unpack 16-bit RGB pixels to 24-bit RGB pixels */ -static inline void PixelConvert_16to24Bits(Uint8 *dst, Uint16 *src, int w, SDL_PixelFormat *fmt) +static inline void PixelConvert_16to24Bits(Uint8 *dst, Uint16 *src, int dw, SDL_Surface *surf) { - int x; - for (x = 0; x < w; x++, src++) { - *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); - *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); - *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); + SDL_PixelFormat *fmt = surf->format; + Uint16 sval; + int dx; + + for (dx = 0; dx < dw; dx++) + { + sval = src[(dx * surf->w + dw/2) / dw]; + *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); + *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); + *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); } } /** * unpack 32-bit RGBA pixels to 24-bit RGB pixels */ -static inline void PixelConvert_32to24Bits(Uint8 *dst, Uint32 *src, int w, SDL_PixelFormat *fmt) +static inline void PixelConvert_32to24Bits(Uint8 *dst, Uint32 *src, int dw, SDL_Surface *surf) { - int x; - for (x = 0; x < w; x++, src++) + SDL_PixelFormat *fmt = surf->format; + Uint32 sval; + int dx; + + for (dx = 0; dx < dw; dx++) { - *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); - *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); - *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); + sval = src[(dx * surf->w + dw/2) / dw]; + *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); + *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); + *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); } } @@ -60,60 +56,37 @@ static inline void PixelConvert_32to24Bi /*----------------------------------------------------------------------*/ /** - * Unpack 8-bit data with RGB palette to 24-bit BGR pixels - */ -static inline void PixelConvert_8to24Bits_BGR(Uint8 *dst, Uint8 *src, int w, SDL_Color *colors) -{ - int x; - for (x = 0; x < w; x++, src++) { - *dst++ = colors[*src].b; - *dst++ = colors[*src].g; - *dst++ = colors[*src].r; - } -} - -/** * Unpack 16-bit RGB pixels to 24-bit BGR pixels */ -static inline void PixelConvert_16to24Bits_BGR(Uint8 *dst, Uint16 *src, int w, SDL_PixelFormat *fmt) +static inline void PixelConvert_16to24Bits_BGR(Uint8 *dst, Uint16 *src, int dw, SDL_Surface *surf) { - int x; - for (x = 0; x < w; x++, src++) { - *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); - *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); - *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); - } -} + SDL_PixelFormat *fmt = surf->format; + Uint16 sval; + int dx; -/** - * unpack 24-bit RGB pixels to 24-bit BGR pixels - */ -static inline void PixelConvert_24to24Bits_BGR(Uint8 *dst, Uint8 *src, int w) -{ - int x; - for (x = 0; x < w; x++, src += 3) { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - *dst++ = src[2]; /* B */ - *dst++ = src[1]; /* G */ - *dst++ = src[0]; /* R */ -#else - *dst++ = src[0]; /* B */ - *dst++ = src[1]; /* G */ - *dst++ = src[2]; /* R */ -#endif + for (dx = 0; dx < dw; dx++) + { + sval = src[(dx * surf->w + dw/2) / dw]; + *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); + *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); + *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); } } /** * unpack 32-bit RGBA pixels to 24-bit BGR pixels */ -static inline void PixelConvert_32to24Bits_BGR(Uint8 *dst, Uint32 *src, int w, SDL_PixelFormat *fmt) +static inline void PixelConvert_32to24Bits_BGR(Uint8 *dst, Uint32 *src, int dw, SDL_Surface *surf) { - int x; - for (x = 0; x < w; x++, src++) + SDL_PixelFormat *fmt = surf->format; + Uint32 sval; + int dx; + + for (dx = 0; dx < dw; dx++) { - *dst++ = (((*src & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); - *dst++ = (((*src & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); - *dst++ = (((*src & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); + sval = src[(dx * surf->w + dw/2) / dw]; + *dst++ = (((sval & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss); + *dst++ = (((sval & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss); + *dst++ = (((sval & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss); } }