GP32 Extracting Gif Palette


pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
44
Location
New Zealand
Website
www.projectitis.com
Hi all,

I think I have narrowed down the problem with the GIF loading routine (it has garbled colours when the palette is less than 256 colours) to the function that actually extracts the colours. The function is as follows:

Code:
void gifGetPalette(tGPD_canvas *gif, tGPD_gifWork *work){
	int numColors = (1 << ((work ->pixelBits) +1));
	int i;
	unsigned char R,G,B;
	int shift = (work->colorResolutionBits + 1) - 5;
	
	if(shift<0) shift = 0;
	
	for(i=0; i< numColors; i++){
  R = (work->cmR)[i] >> shift;
  G = (work->cmG)[i] >> shift;
  B = (work->cmB)[i] >> shift;
  (work->palette)[i] = (R << 11) | (G << 6) | (B << 1);
	};
	free(work->cmR);
	free(work->cmG);
	free(work->cmB);
}

The differences that I can see are:

1) When the palette is 256 colours, the values are:
work->colorResolutionBits = 7
shift = 3

2) When the palette is less, these values change (e.g):
work->colorResolutionBits = 3
shift = -1 (then set to 0)
or
work->colorResolutionBits = 4
shift = 0

What exactly are the 'colorResolutionBits' and why would they change if the only thing that has happened to the image is that it has less colours in its palette?

EDIT: I have tried manually setting 'shift' to all values from -1 through to 6. Each time the colours are different, but still very screwed up. Instead of shades of blue, the image is red and green and purple etc. I tested each of the pixels, and they are indeed referencing the correct palette[location], its just that each colour in the palette is screwed.
 

don

AWSMOE!
Joined
Dec 23, 2003
Messages
635
Location
$$$GERMONEY$$$
Website
gp32.chemicalkungfu.de
Without checking your code... Did you possibly forget that the gp32 palette isn't defined in 24bit but in 16bit? You know, 5bit red, 5bit green, 5bit blue, 1bit brightness? I think that could be the problem, especially if you ripped that GIF routine from some machine that uses 24bit color definitions. ;)
 

pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
44
Location
New Zealand
Website
www.projectitis.com
Of course I did. It is a GIF routine I think written by (or at least used by) aquafish, and also by rov.

It works completely fine with larger images (at least with large palette sizes) but not with smaller palettes. I have scoured the code and matched it against the GIF 89a definintions, and the code that loads the gif should work fine. It is only the snippet above which converts the palette from the GIF to 16bpp colour that I am unsure about
 
Top