| 13 |
|
#include "platform.h" |
| 14 |
|
#include "color.h" |
| 15 |
|
#include "resolu.h" |
| 16 |
+ |
#include "clrtab.h" |
| 17 |
|
|
| 18 |
|
#define MAXCOLORS 256 |
| 19 |
|
|
| 22 |
|
int bmap[MAXCOLORS]; |
| 23 |
|
|
| 24 |
|
int currow; |
| 24 |
– |
|
| 25 |
– |
extern long ftell(); |
| 26 |
– |
|
| 25 |
|
long picstart; |
| 26 |
+ |
uby8 clrtab[256][3]; |
| 27 |
|
|
| 29 |
– |
BYTE clrtab[256][3]; |
| 30 |
– |
|
| 28 |
|
extern int samplefac; |
| 29 |
|
|
| 33 |
– |
extern int getgifpix(); |
| 30 |
|
|
| 31 |
|
COLR *scanln; |
| 32 |
< |
BYTE *pixscan; |
| 32 |
> |
uby8 *pixscan; |
| 33 |
|
|
| 34 |
|
int xmax, ymax; /* picture size */ |
| 39 |
– |
|
| 35 |
|
double gamv = 2.2; /* gamma correction */ |
| 41 |
– |
|
| 36 |
|
int greyscale = 0; /* convert to B&W? */ |
| 43 |
– |
|
| 37 |
|
int dither = 1; /* dither colors? */ |
| 45 |
– |
|
| 38 |
|
int bradj = 0; /* brightness adjustment */ |
| 47 |
– |
|
| 39 |
|
int ncolors = 0; /* number of colors requested */ |
| 40 |
|
|
| 41 |
|
char *progname; |
| 42 |
|
|
| 43 |
+ |
typedef int ifun_t(int x, int y); /* required by the GIF code below */ |
| 44 |
|
|
| 45 |
< |
main(argc, argv) |
| 46 |
< |
int argc; |
| 47 |
< |
char *argv[]; |
| 45 |
> |
static void getrow(int y); |
| 46 |
> |
static void mkclrmap(int nc); |
| 47 |
> |
static void mkgrymap(int nc); |
| 48 |
> |
static ifun_t getgifpix; |
| 49 |
> |
|
| 50 |
> |
static void GIFEncode(FILE *fp, int GWidth, int GHeight, int GInterlace, |
| 51 |
> |
int Background, int BitsPerPixel, int Red[], int Green[], int Blue[], |
| 52 |
> |
ifun_t* GetPixel); |
| 53 |
> |
|
| 54 |
> |
|
| 55 |
> |
int |
| 56 |
> |
main(int argc, char *argv[]) |
| 57 |
|
{ |
| 58 |
|
int bitsperpix; |
| 59 |
|
int i; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
|
| 143 |
< |
getrow(y) /* get the specified row from our image */ |
| 144 |
< |
int y; |
| 143 |
> |
static void |
| 144 |
> |
getrow( /* get the specified row from our image */ |
| 145 |
> |
int y |
| 146 |
> |
) |
| 147 |
|
{ |
| 148 |
|
if (y == currow) |
| 149 |
|
return; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
< |
mkclrmap(nc) /* make our color map */ |
| 174 |
< |
int nc; |
| 173 |
> |
static void |
| 174 |
> |
mkclrmap( /* make our color map */ |
| 175 |
> |
int nc |
| 176 |
> |
) |
| 177 |
|
{ |
| 178 |
|
register int i; |
| 179 |
|
|
| 195 |
|
gmap[i] = clrtab[i][GRN]; |
| 196 |
|
bmap[i] = clrtab[i][BLU]; |
| 197 |
|
} |
| 198 |
< |
if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL) |
| 198 |
> |
if (dither && (pixscan = (uby8 *)malloc(xmax)) == NULL) |
| 199 |
|
goto memerr; |
| 200 |
|
return; |
| 201 |
|
memerr: |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| 207 |
< |
mkgrymap(nc) |
| 208 |
< |
int nc; |
| 207 |
> |
static void |
| 208 |
> |
mkgrymap( |
| 209 |
> |
int nc |
| 210 |
> |
) |
| 211 |
|
{ |
| 212 |
|
register int i; |
| 213 |
|
|
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
< |
int |
| 223 |
< |
getgifpix(x, y) /* get a single pixel from our picture */ |
| 224 |
< |
int x, y; |
| 222 |
> |
static int |
| 223 |
> |
getgifpix( /* get a single pixel from our picture */ |
| 224 |
> |
int x, |
| 225 |
> |
int y |
| 226 |
> |
) |
| 227 |
|
{ |
| 219 |
– |
int pix; |
| 220 |
– |
|
| 228 |
|
getrow(y); |
| 229 |
|
if (greyscale) |
| 230 |
|
return((normbright(scanln[x])*ncolors)>>8); |
| 238 |
|
* SCARY GIF code follows . . . . sorry. |
| 239 |
|
* |
| 240 |
|
* Based on GIFENCOD by David Rowley <[email protected]>.A |
| 241 |
< |
* Lempel-Zim compression based on "compress". |
| 241 |
> |
* Lempel-Ziv compression based on "compress". |
| 242 |
|
* |
| 243 |
|
*/ |
| 244 |
|
|
| 250 |
|
* BitsPerPixel, Red, Green, Blue, GetPixel ) |
| 251 |
|
* |
| 252 |
|
*****************************************************************************/ |
| 246 |
– |
typedef int (* ifunptr)(); |
| 253 |
|
|
| 254 |
|
#define TRUE 1 |
| 255 |
|
#define FALSE 0 |
| 262 |
|
unsigned long cur_accum = 0; |
| 263 |
|
int cur_bits = 0; |
| 264 |
|
|
| 265 |
+ |
static void BumpPixel(void); |
| 266 |
+ |
static int GIFNextPixel(ifun_t* getpixel); |
| 267 |
+ |
static void Putword(int w, FILE *fp); |
| 268 |
+ |
static void compress(int init_bits, FILE *outfile, ifun_t* ReadValue); |
| 269 |
+ |
|
| 270 |
+ |
|
| 271 |
+ |
/* a code_int must be able to hold 2**CBITS values of type int, and also -1 */ |
| 272 |
+ |
typedef int code_int; |
| 273 |
+ |
typedef long int count_int; |
| 274 |
+ |
typedef unsigned char char_type; |
| 275 |
+ |
|
| 276 |
+ |
static void output(code_int code); |
| 277 |
+ |
static void cl_block(void); |
| 278 |
+ |
static void cl_hash(count_int hsize); |
| 279 |
+ |
static void writeerr(void); |
| 280 |
+ |
|
| 281 |
+ |
static void char_init(void); |
| 282 |
+ |
static void char_out(int c); |
| 283 |
+ |
static void flush_char(void); |
| 284 |
+ |
static void gammawarp(short *sbuf, float gam, int n); |
| 285 |
+ |
|
| 286 |
+ |
|
| 287 |
|
/* |
| 288 |
|
* Bump the 'curx' and 'cury' to point to the next pixel |
| 289 |
|
*/ |
| 290 |
< |
BumpPixel() |
| 290 |
> |
static void |
| 291 |
> |
BumpPixel(void) |
| 292 |
|
{ |
| 293 |
|
curx++; |
| 294 |
|
if( curx == Width ) { |
| 329 |
|
/* |
| 330 |
|
* Return the next pixel from the image |
| 331 |
|
*/ |
| 332 |
< |
GIFNextPixel( getpixel ) |
| 333 |
< |
ifunptr getpixel; |
| 332 |
> |
static int |
| 333 |
> |
GIFNextPixel( |
| 334 |
> |
ifun_t* getpixel |
| 335 |
> |
) |
| 336 |
|
{ |
| 337 |
|
int r; |
| 338 |
|
|
| 347 |
|
/* |
| 348 |
|
* public GIFEncode |
| 349 |
|
*/ |
| 350 |
< |
GIFEncode( fp, GWidth, GHeight, GInterlace, Background, |
| 351 |
< |
BitsPerPixel, Red, Green, Blue, GetPixel ) |
| 352 |
< |
FILE *fp; |
| 353 |
< |
int GWidth, GHeight; |
| 354 |
< |
int GInterlace; |
| 355 |
< |
int Background; |
| 356 |
< |
int BitsPerPixel; |
| 357 |
< |
int Red[], Green[], Blue[]; |
| 358 |
< |
ifunptr GetPixel; |
| 350 |
> |
static void |
| 351 |
> |
GIFEncode( |
| 352 |
> |
FILE *fp, |
| 353 |
> |
int GWidth, |
| 354 |
> |
int GHeight, |
| 355 |
> |
int GInterlace, |
| 356 |
> |
int Background, |
| 357 |
> |
int BitsPerPixel, |
| 358 |
> |
int Red[], |
| 359 |
> |
int Green[], |
| 360 |
> |
int Blue[], |
| 361 |
> |
ifun_t* GetPixel |
| 362 |
> |
) |
| 363 |
|
{ |
| 364 |
|
int B; |
| 365 |
|
int RWidth, RHeight; |
| 369 |
|
int InitCodeSize; |
| 370 |
|
int i; |
| 371 |
|
|
| 372 |
< |
long cur_accum = 0; |
| 372 |
> |
cur_accum = 0; /* globals */ |
| 373 |
|
cur_bits = 0; |
| 374 |
|
|
| 375 |
|
Interlace = GInterlace; |
| 419 |
|
/* |
| 420 |
|
* Write out a word to the GIF file |
| 421 |
|
*/ |
| 422 |
< |
Putword( w, fp ) |
| 423 |
< |
int w; |
| 424 |
< |
FILE *fp; |
| 422 |
> |
static void |
| 423 |
> |
Putword( |
| 424 |
> |
int w, |
| 425 |
> |
FILE *fp |
| 426 |
> |
) |
| 427 |
|
{ |
| 428 |
|
fputc( w & 0xff, fp ); |
| 429 |
|
fputc( (w/256) & 0xff, fp ); |
| 443 |
|
#define HSIZE 5003 /* 80% occupancy */ |
| 444 |
|
|
| 445 |
|
/* |
| 409 |
– |
* a code_int must be able to hold 2**CBITS values of type int, and also -1 |
| 410 |
– |
*/ |
| 411 |
– |
typedef int code_int; |
| 412 |
– |
typedef long int count_int; |
| 413 |
– |
typedef unsigned char char_type; |
| 414 |
– |
|
| 415 |
– |
/* |
| 446 |
|
* |
| 447 |
|
* GIF Image compression - modified 'compress' |
| 448 |
|
* |
| 517 |
|
int ClearCode; |
| 518 |
|
int EOFCode; |
| 519 |
|
|
| 520 |
< |
compress( init_bits, outfile, ReadValue ) |
| 521 |
< |
int init_bits; |
| 522 |
< |
FILE *outfile; |
| 523 |
< |
ifunptr ReadValue; |
| 520 |
> |
static void |
| 521 |
> |
compress( |
| 522 |
> |
int init_bits, |
| 523 |
> |
FILE *outfile, |
| 524 |
> |
ifun_t* ReadValue |
| 525 |
> |
) |
| 526 |
|
{ |
| 527 |
|
register long fcode; |
| 528 |
|
register code_int i = 0; |
| 561 |
|
while ( (c = GIFNextPixel( ReadValue )) != EOF ) { |
| 562 |
|
in_count++; |
| 563 |
|
fcode = (long) (((long) c << maxbits) + ent); |
| 564 |
< |
/* i = (((code_int)c << hshift) ~ ent); /* xor hashing */ |
| 564 |
> |
/* i = (((code_int)c << hshift) ~ ent); */ /* xor hashing */ |
| 565 |
|
i = (((code_int)c << hshift) ^ ent); /* xor hashing */ |
| 566 |
|
if ( HashTabOf (i) == fcode ) { |
| 567 |
|
ent = CodeTabOf (i); |
| 621 |
|
0x01FF, 0x03FF, 0x07FF, 0x0FFF, |
| 622 |
|
0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; |
| 623 |
|
|
| 624 |
< |
output( code ) |
| 625 |
< |
code_int code; |
| 624 |
> |
static void |
| 625 |
> |
output( |
| 626 |
> |
code_int code |
| 627 |
> |
) |
| 628 |
|
{ |
| 629 |
|
cur_accum &= masks[ cur_bits ]; |
| 630 |
|
if( cur_bits > 0 ) |
| 673 |
|
/* |
| 674 |
|
* Clear out the hash table |
| 675 |
|
*/ |
| 676 |
< |
cl_block () /* table clear for block compress */ |
| 676 |
> |
static void |
| 677 |
> |
cl_block (void) /* table clear for block compress */ |
| 678 |
|
{ |
| 679 |
|
cl_hash ( (count_int) hsize ); |
| 680 |
|
free_ent = ClearCode + 2; |
| 682 |
|
output( (code_int)ClearCode ); |
| 683 |
|
} |
| 684 |
|
|
| 685 |
< |
cl_hash(hsize) /* reset code table */ |
| 686 |
< |
register count_int hsize; |
| 685 |
> |
static void |
| 686 |
> |
cl_hash( /* reset code table */ |
| 687 |
> |
register count_int hsize |
| 688 |
> |
) |
| 689 |
|
{ |
| 690 |
|
register count_int *htab_p = htab+hsize; |
| 691 |
|
register long i; |
| 715 |
|
*--htab_p = m1; |
| 716 |
|
} |
| 717 |
|
|
| 718 |
< |
writeerr() |
| 718 |
> |
static void |
| 719 |
> |
writeerr(void) |
| 720 |
|
{ |
| 721 |
|
printf( "error writing output file\n" ); |
| 722 |
|
exit(1); |
| 736 |
|
/* |
| 737 |
|
* Set up the 'byte output' routine |
| 738 |
|
*/ |
| 739 |
< |
char_init() |
| 739 |
> |
static void |
| 740 |
> |
char_init(void) |
| 741 |
|
{ |
| 742 |
|
a_count = 0; |
| 743 |
|
} |
| 751 |
|
* Add a character to the end of the current packet, and if it is 254 |
| 752 |
|
* characters, flush the packet to disk. |
| 753 |
|
*/ |
| 754 |
< |
char_out( c ) |
| 755 |
< |
int c; |
| 754 |
> |
static void |
| 755 |
> |
char_out( |
| 756 |
> |
int c |
| 757 |
> |
) |
| 758 |
|
{ |
| 759 |
|
accum[ a_count++ ] = c; |
| 760 |
|
if( a_count >= 254 ) |
| 764 |
|
/* |
| 765 |
|
* Flush the packet to disk, and reset the accumulator |
| 766 |
|
*/ |
| 767 |
< |
flush_char() |
| 767 |
> |
static void |
| 768 |
> |
flush_char(void) |
| 769 |
|
{ |
| 770 |
|
if( a_count > 0 ) { |
| 771 |
|
fputc( a_count, g_outfile ); |
| 777 |
|
static float curgamma; |
| 778 |
|
static short gamtab[256]; |
| 779 |
|
|
| 780 |
< |
gammawarp(sbuf,gam,n) |
| 781 |
< |
short *sbuf; |
| 782 |
< |
float gam; |
| 783 |
< |
int n; |
| 780 |
> |
static void |
| 781 |
> |
gammawarp( |
| 782 |
> |
short *sbuf, |
| 783 |
> |
float gam, |
| 784 |
> |
int n |
| 785 |
> |
) |
| 786 |
|
{ |
| 787 |
|
int i; |
| 744 |
– |
float f; |
| 788 |
|
|
| 789 |
|
if(gam!=curgamma) { |
| 790 |
|
for(i=0; i<256; i++) |