pea
developer
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:
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.
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.