#include #include #include #include "pict.h" #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif main(int argc, char **argv ) { Pict pictIn,pictOut; short int i; char gray=FALSE; char verb=FALSE; int colors=256; extern char *optarg; extern int optind,opterr,optopt; int opcion; unsigned char theError=0; while((opcion=getopt(argc,argv,"gvc:")) != EOF ) { switch(opcion) { case 'g': gray=TRUE; break; case 'v': verb=TRUE; printf("%s: version 5 mayo 1994\n",argv[0]); break; case 'c': colors = atoi(optarg); if (colors < 0) colors=0; break; default: theError ++; break; } } if (( theError != 0 ) ||(argv[optind][0]==0x00 )) { fprintf( stderr,"Uso: %s [-gvc] file [file...]\n", argv[0] ); exit(-1); } for( ; optind clr_mode) { case M_MONO: if ( verb ) printf("MONO\n"); if ( gray ) continue; break; case M_RGB8: if ( verb ) printf("RGB 8 Bits\n"); if ( !gray ) continue; break; case M_RGB24: if ( verb ) printf("RGB 24 Bits\n"); break; case M_RGBA32: if ( verb ) printf("RGBA 32 Bits\n"); break; default: fprintf(stderr, "Error. bye...\n"); exit(1); } sprintf(thefName,"%s.i",argv[optind]); pictOut = pict_24_to_8(pictIn,gray ? GRAYSCALE : OPTIMAL, 5, colors); pict_free( pictIn ); pictIn = pict_open(thefName,pictOut->file_mode, pictOut->image_H,pictOut->image_W, pictOut->clr_mode,pictOut->map ); for(i=0;iimage_H;i++) pict_put_line( pictIn, pictOut->pixels + i*pictIn->image_W ); pict_close(pictIn); free( pictIn ); } }