I have some old code for work, it uses vfw functions to extract frames from avi file, then create sdl surface.
The code looks like below:
LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(iframe,i);
calData.animationTarget.animation_frames = SDL_CreateRGBSurface(SDL_SWSURFACE,aviinfo.dwWidth,aviinfo.dwHeight,lpbi- >biBitCount,0,0,0,0);
if(color_key.unused == 255)
SDL_SetColorKey(calData.animationTarget.animation_frames,SDL_RLEACCEL|SDL_SRCCOLORKEY,
SDL_MapRGB(calData.animationTarget.animation_frames->format, color_key.r, color_key.g, color_key.b));
else if(color_key.unused == 0)
SDL_SetColorKey(calData.animationTarget.animation_frames,0,0);
{// copy surface up-side-down
int pitch = aviinfo.dwWidth *((lpbi->biBitCount+7)/8);
char *src = (char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD)+ (aviinfo.dwHeight-1)*(pitch);
char *dst = calData.animationTarget.animation_frames->pixels;
for(int i =0; i <aviinfo.dwHeight; i++)
{
memcpy(dst,src,pitch);
src -= pitch;
dst += pitch;
}
Then , use SDL_BlitSurface() to display the frame. It looks ok except I think the color is wrong. The original color is orange, but it shows green. I guess somewhere the color order is wrong (like r g b, should be b g r).
Two things confused me in the code,
1, the bitcount of the frame is 8 (I check it using mediaInfo) , it means it uses color table, so in the first place, the code should not work. because it copies pixels, instead of palette?
2, It should not have color order issue because it uses color table. then why the color is wrong?
Any idea will be appreciated. Forgive me if the questions are too naive.
Thanks.
L