diff -u gif2png-2.3.0/gif2png.c ./gif2png.c --- gif2png-2.3.0/gif2png.c Sat Dec 4 14:43:34 1999 +++ ./gif2png.c Sat Jan 22 00:53:12 2000 @@ -19,6 +19,7 @@ struct GIFelement first={NULL}; struct GIFelement *current; +FILE *overlay = NULL; int delete = FALSE; int optimize = FALSE; int histogram = FALSE; @@ -35,6 +36,19 @@ long numgifs = 0L; long numpngs = 0L; +int get_next_overlay_bit(void) +{ + static int overlay_mask = 0; + static int overlay_value = 0; + + if (!(overlay_mask >>= 1)) { + overlay_value = fgetc(overlay); + if (overlay_value < 0) + return -1; + overlay_mask = 128; + } + return (overlay_value & overlay_mask)? 1:0; +} int interlace_line(int height, int line) /* return the actual line # used to store an interlaced line */ @@ -197,6 +211,7 @@ if (last_color<16) bitdepth = 4; if (last_color<4) bitdepth = 2; if (last_color<2) bitdepth = 1; + if (overlay) bitdepth = 8; if (gray) { remapping = TRUE; @@ -264,6 +279,16 @@ } } + if (overlay && last_color >127) { + fprintf(stderr, "gif2png: too many colors\n"); + free(png_ptr); + free(info_ptr); + return 1; + } else { + colors_used *= 2; + last_color += last_color+1; + } + if (verbose > 1) fprintf(stderr, "gif2png: %d colors used, highest color %d, %s, bitdepth %d\n", colors_used, last_color, gray ? "gray":"palette", bitdepth); @@ -391,12 +416,27 @@ pal_rgb[i].blue = current->imagestruct->colors[remap[i]].blue; } info_ptr->palette = pal_rgb; - } else { + } else if (overlay) { + if (verbose > 2) + fprintf(stderr, "Making two copies of the Palette...\n"); + for (i = 0; i <= last_color; i++) { + pal_rgb[i].red = current->imagestruct->colors[i].red; + pal_rgb[i].green = current->imagestruct->colors[i].green; + pal_rgb[i].blue = current->imagestruct->colors[i].blue; + pal_rgb[i + last_color + 1].red = current->imagestruct->colors[i].red; + pal_rgb[i + last_color + 1].green = current->imagestruct->colors[i].green; + pal_rgb[i + last_color + 1].blue = current->imagestruct->colors[i].blue; + } + info_ptr->palette = pal_rgb; + } else { if (verbose > 2) fprintf(stderr, "Palette copied from GIF colors...\n"); info_ptr->palette = current->imagestruct->colors; } - info_ptr->num_palette = last_color+1; + if (overlay) + info_ptr->num_palette = 2*(last_color+1); + else + info_ptr->num_palette = last_color+1; info_ptr->valid |= PNG_INFO_PLTE; if (verbose > 2) { @@ -491,6 +531,12 @@ data[j] = remap[data[j]]; } } + if (overlay) { + for (j = 0; j < img->width; j++) { + if (get_next_overlay_bit()) + data[j] += last_color + 1; + } + } png_write_row(png_ptr, data); } break; @@ -814,6 +860,21 @@ webconvert = TRUE; break; + case 'o': + if (ac >= argc - 1) + { + fputs("gif2png: missing background-matte argument\n", + stderr); + exit(1); + } + overlay = fopen(argv[++ac], "rb"); + if (!overlay){ + fputs("gif2png: unable to open overlay file\n", + stderr); + exit(1); + } + goto skiparg; + case 'O': optimize = TRUE; break; @@ -831,6 +892,7 @@ " -h generate PNG histogram chunks into color output files\n" " -i force conversion to interlaced PNG files\n" " -n force conversion to noninterlaced PNG files\n" + " -o overlay file\n" " -p display progress of PNG writing in %%\n" " -r try to recover corrupted GIF files\n" " -s do not write Software text chunk\n" @@ -890,6 +952,9 @@ } } } + + if (overlay && get_next_overlay_bit() >= 0) + fprintf(stderr, "Not enough image data to hold the overlay.\n"); if (verbose) fprintf(stderr, "Done (%s). Converted %ld GIF%s into %ld PNG%s.\n",