Pixel format conversion
This commit is contained in:
parent
dbf6dcd35b
commit
ad99287f8a
@ -282,12 +282,34 @@ void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch)
|
|||||||
if (SDL_LockSurface(sdl_scrn)<0)
|
if (SDL_LockSurface(sdl_scrn)<0)
|
||||||
return;
|
return;
|
||||||
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
||||||
|
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
|
||||||
|
{
|
||||||
for (j=0; j<h; j++)
|
for (j=0; j<h; j++)
|
||||||
{
|
{
|
||||||
memcpy(dst, src, w*PIXELSIZE);
|
memcpy(dst, src, w*PIXELSIZE);
|
||||||
dst+=sdl_scrn->pitch/PIXELSIZE;
|
dst+=sdl_scrn->pitch/PIXELSIZE;
|
||||||
src+=pitch;
|
src+=pitch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (SDL_MUSTLOCK(sdl_scrn))
|
if (SDL_MUSTLOCK(sdl_scrn))
|
||||||
SDL_UnlockSurface(sdl_scrn);
|
SDL_UnlockSurface(sdl_scrn);
|
||||||
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
||||||
@ -302,6 +324,31 @@ void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch)
|
|||||||
if (SDL_LockSurface(sdl_scrn)<0)
|
if (SDL_LockSurface(sdl_scrn)<0)
|
||||||
return;
|
return;
|
||||||
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
||||||
|
if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
|
||||||
|
{
|
||||||
|
//pixel format conversion
|
||||||
|
pixel px;
|
||||||
|
SDL_PixelFormat *fmt = sdl_scrn->format;
|
||||||
|
for (j=0; j<h; j++)
|
||||||
|
{
|
||||||
|
for (k=0; k<sdl_scale; k++)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
src+=pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (j=0; j<h; j++)
|
for (j=0; j<h; j++)
|
||||||
{
|
{
|
||||||
for (k=0; k<sdl_scale; k++)
|
for (k=0; k<sdl_scale; k++)
|
||||||
@ -315,6 +362,7 @@ void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch)
|
|||||||
}
|
}
|
||||||
src+=pitch;
|
src+=pitch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (SDL_MUSTLOCK(sdl_scrn))
|
if (SDL_MUSTLOCK(sdl_scrn))
|
||||||
SDL_UnlockSurface(sdl_scrn);
|
SDL_UnlockSurface(sdl_scrn);
|
||||||
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
||||||
|
Reference in New Issue
Block a user