I'm trying to load an unusual image file format using SDL_CreateRGBSurfaceFrom, but when I go to display the image, (blit it onto the screen) only the first file of the image is displayed, repeated over every line. (I've tried the SDL_LoadBMP function, and that does not have the problem.) However, when I look at the actual pixel data, and the other data in the SDL image, there is nothing obviously wrong.
The following is the relevant code from the program:
Code:
//Load the palette.
struct RGB { unsigned char red, green, blue; };
typedef struct RGB color;
color TPaletteTemp[256];
void *tempPic[512];
unsigned int width = 0, height = 0;
int f;
int i = 0;
int j = 0;
f = open( "CDOGS.PX", O_RDONLY);
if (f >= 0)
{
read( f, TPaletteTemp, sizeof( TPaletteTemp));
for (j=0; j<256; j++)
{
palette[j].r = TPaletteTemp[j].red*4;
palette[j].g = TPaletteTemp[j].green*4;
palette[j].b = TPaletteTemp[j].blue*4;
}
}
//Load the pictures.
unsigned short int size;
i=0;
while (f && i<512)
{
read( f, &size, 2);
if (size)
{
read( f, &width, 2);
read( f, &height, 2);
tempPic[i] = malloc( size-4);
read( f, tempPic[i], size-4);
pics[i] = *SDL_CreateRGBSurfaceFrom(tempPic[i],
width, height, 8, 0,
0xff0000, 0x00ff00, 0x0000ff, 0x000000);
SDL_SetPalette(&pics[i], SDL_LOGPAL|SDL_PHYSPAL, palette, 0, 256);
}
i++;
}
for (j=0; j<256; j++)
{
int i;
SDL_Rect dest;
dest.x = (j/16)*32;
dest.y = (j%16)*32;
dest.w = pics[j].w;
dest.h = pics[j].h;
i = SDL_BlitSurface(&pics[j], NULL, screen, &dest);
if (i < 0)
{printf("error in sprite display\n");}
}
SDL_UpdateRect(screen, 0, 0, 0, 0);
This is an example of what the problem looks like:
http://emhsoft.net/SDL_problem.png
And this is a zip file containing all of the relevant code:
http://emhsoft.net/SDL_problem.zip
CDOGS.PX=The actual file I'm trying to load.
cdogspx.txt=An english description of the file format.
palette.py=A python program that does load the image correctly.
test.c, makefile=The program in question.