Help Loading 8bit .act Palette Files?


GP2X_Coder

Member
Joined
May 17, 2006
Messages
220
Age
52
Location
USA
Website
mysite.verizon.net
Does anyone know how to load in an 8bit 256 color .act file ( adobe color table ) Palette file so I can use them to change the Palettes on my graphic files with SDL_SetPalette() any help would be greatly appreciated.
 
According to this.

"A 256-colour palette used by a RAW image pixmap file. All ACT are exactly 768 bytes long, consisting of 256 24-bit RBG (red, green, blue) colour values."
 
You can pretty easily see how ACT files work by opening one in a hex editor. It's just a bunch of plain RGB values, one byte per color channel, one RGB sequence for each of the 256 palette entries. 256x3 bytes makes 768 bytes in total. No header information, compression or other difficulties to worry about.

Loading such a palette for some SDL surface should be pretty easy. It goes a little something like this:

Code:
FILE *fp;
Uint8 palette[256][3];
SDL_Color colors[256];
int i;

// Open our ACT file
fp = fopen( "palette.act", "rb" );
if ( !fp )
{
	fprintf( stderr, "File could not be opened... :(" );
}

// Read the entire contents of the file into our palette array
fread( palette, 3, 256, fp );
fclose( fp );

// Copy the palette values to our SDL_Color array
for ( i = 0; i < 256; i++ )
{
	colors[i].r = palette[i][0];
	colors[i].g = palette[i][1];
	colors[i].b = palette[i][2];
}

// Set the palette for some surface
SDL_SetPalette( someSurface, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
You could do it with less code by loading the contents of the file byte for byte directly into the SDL_Color array, but loading the entire file at once into a temporary array should be a bit faster. Also, depending on the type of SDL_Surface you're using the flags parameter for SDL_SetPalette might need to be different. I haven't actually tested this code, so there might be something horribly wrong that I'm not aware of, but it should give you an idea.
 
I know I am reading in the .act file correctly I printed all of the data to a text file and they are the correct numbers but for some reason it does not change the pallete to the correct colors I just don't know what is going on :(
 
I've tried it here now, and it seems to work just fine. Here's the code of my little test project: ACTTest.zip. Also includes test image and palette files, Windows binary and Dev-C++ project file.
 
Thanks Devil N I made a stupid mistake I was applying SDL_DisplayFormat before I change the pallete file which was converting it to 16bit before it could set the 8bit pallete :p I can't believe I didn't find this before.

Works perfect now. :D
 
Back
Top