summaryrefslogtreecommitdiff
path: root/src/graphics.c
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-06-16 22:41:19 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-06-25 14:50:21 (GMT)
commitad99287f8a8a31476fc5e01825e607dcbe45cf98 (patch)
treeb2e1055ec923b4cd9d989d3612fdb2f994d4be82 /src/graphics.c
parentdbf6dcd35b76aea13464642a8d9f786e7cb84d65 (diff)
downloadpowder-ad99287f8a8a31476fc5e01825e607dcbe45cf98.zip
powder-ad99287f8a8a31476fc5e01825e607dcbe45cf98.tar.gz
Pixel format conversion
Diffstat (limited to 'src/graphics.c')
-rw-r--r--src/graphics.c70
1 files changed, 59 insertions, 11 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 1c40a0e..036a743 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; j<h; j++)
+ if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
+ {
+ //pixel format conversion
+ int i;
+ pixel px;
+ SDL_PixelFormat *fmt = sdl_scrn->format;
+ for (j=0; j<h; j++)
+ {
+ for (i=0; i<w; i++)
+ {
+ px = src[i];
+ dst[i] = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)|
+ ((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)|
+ ((PIXB(px)>>fmt->Bloss)<<fmt->Bshift);
+ }
+ dst+=sdl_scrn->pitch/PIXELSIZE;
+ src+=pitch;
+ }
+ }
+ else
{
- memcpy(dst, src, w*PIXELSIZE);
- dst+=sdl_scrn->pitch/PIXELSIZE;
- src+=pitch;
+ for (j=0; j<h; j++)
+ {
+ memcpy(dst, src, w*PIXELSIZE);
+ dst+=sdl_scrn->pitch/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; j<h; j++)
+ if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
{
- for (k=0; k<sdl_scale; k++)
+ //pixel format conversion
+ pixel px;
+ SDL_PixelFormat *fmt = sdl_scrn->format;
+ for (j=0; j<h; j++)
{
- for (i=0; i<w; i++)
+ for (k=0; k<sdl_scale; k++)
{
- dst[i*2]=src[i];
- dst[i*2+1]=src[i];
+ for (i=0; i<w; i++)
+ {
+ px = src[i];
+ px = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)|
+ ((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)|
+ ((PIXB(px)>>fmt->Bloss)<<fmt->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; j<h; j++)
+ {
+ for (k=0; k<sdl_scale; k++)
+ {
+ for (i=0; i<w; i++)
+ {
+ dst[i*2]=src[i];
+ dst[i*2+1]=src[i];
+ }
+ dst+=sdl_scrn->pitch/PIXELSIZE;
+ }
+ src+=pitch;
}
- src+=pitch;
}
if (SDL_MUSTLOCK(sdl_scrn))
SDL_UnlockSurface(sdl_scrn);