From ad99287f8a8a31476fc5e01825e607dcbe45cf98 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Thu, 16 Jun 2011 23:41:19 +0100 Subject: [PATCH] Pixel format conversion --- src/graphics.c | 70 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/src/graphics.c b/src/graphics.c index 1c40a0e40..036a7439d 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -282,11 +282,33 @@ void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch) if (SDL_LockSurface(sdl_scrn)<0) return; dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; - for (j=0; jformat,0x33,0x55,0x77)!=PIXPACK(0x335577)) { - memcpy(dst, src, w*PIXELSIZE); - dst+=sdl_scrn->pitch/PIXELSIZE; - src+=pitch; + //pixel format conversion + int i; + pixel px; + SDL_PixelFormat *fmt = sdl_scrn->format; + for (j=0; j>fmt->Rloss)<Rshift)| + ((PIXG(px)>>fmt->Gloss)<Gshift)| + ((PIXB(px)>>fmt->Bloss)<Bshift); + } + dst+=sdl_scrn->pitch/PIXELSIZE; + src+=pitch; + } + } + else + { + for (j=0; jpitch/PIXELSIZE; + src+=pitch; + } } if (SDL_MUSTLOCK(sdl_scrn)) SDL_UnlockSurface(sdl_scrn); @@ -302,18 +324,44 @@ void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch) if (SDL_LockSurface(sdl_scrn)<0) return; dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; - for (j=0; jformat,0x33,0x55,0x77)!=PIXPACK(0x335577)) { - for (k=0; kformat; + for (j=0; j>fmt->Rloss)<Rshift)| + ((PIXG(px)>>fmt->Gloss)<Gshift)| + ((PIXB(px)>>fmt->Bloss)<Bshift); + dst[i*2]=px; + dst[i*2+1]=px; + } + dst+=sdl_scrn->pitch/PIXELSIZE; } - dst+=sdl_scrn->pitch/PIXELSIZE; + src+=pitch; + } + } + else + { + for (j=0; jpitch/PIXELSIZE; + } + src+=pitch; } - src+=pitch; } if (SDL_MUSTLOCK(sdl_scrn)) SDL_UnlockSurface(sdl_scrn);