- if(!palette) {
- fprintf(stderr, "Error: No palette found!\n");
- exit(1);
- }
- /* 24->32 bit conversion */
- for(i=0;i<palettelen;i++) {
- rgba[i].r = palette[i*3+0];
- rgba[i].g = palette[i*3+1];
- rgba[i].b = palette[i*3+2];
- if(alphapalette && i<alphapalettelen) {
- rgba[i].a = alphapalette[i];
- if(alphapalette[i] == 0) {
- /* if the color is fully transparent, it doesn't matter
- what it's rgb values are. furthermore, all Flash
- players up to Flash 5 can't deal with anything beyond
- one transparent color with value (00,00,00,00). */
- rgba[i].r = rgba[i].g = rgba[i].b = 0;
+ if(header.mode == 3) { // palette or grayscale?
+ rgba = (RGBA*)malloc(palettelen*sizeof(RGBA));
+ if(!palette) {
+ fprintf(stderr, "Error: No palette found!\n");
+ exit(1);
+ }
+ /* 24->32 bit conversion */
+ for(i=0;i<palettelen;i++) {
+ rgba[i].r = palette[i*3+0];
+ rgba[i].g = palette[i*3+1];
+ rgba[i].b = palette[i*3+2];
+ if(alphapalette && i<alphapalettelen) {
+ rgba[i].a = alphapalette[i];
+ rgba[i].r = ((int)rgba[i].r*rgba[i].a)/255;
+ rgba[i].g = ((int)rgba[i].g*rgba[i].a)/255;
+ rgba[i].b = ((int)rgba[i].b*rgba[i].a)/255;
+ } else {
+ rgba[i].a = 255;