#include #include #include #include #ifdef THINK_C #include #endif #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif void scalepict(char *,char *); unsigned int w = 0, h = 0; double scale = 0.0; char verb=0; void usage(char *name) { fprintf(stderr,"Uso: %s [-o output] -w -h | -s file [file...]\n",name); exit(1); } main( int argc, char *argv[] ) { int i,opcion; char scname[256]; int theError=0; int OutputOpt=0; extern char *optarg; extern int optind,opterr; #ifdef THINK_C argc = ccommand(&argv); #endif while ( (opcion=getopt(argc,argv,"o:w:h:s:v")) != EOF ) { switch(opcion) { case 'w': theError += ( *optarg==0x00 ); w = atoi(optarg); scale = 0.0; break; case 'h': theError += ( *optarg==0x00 ); h = atoi(optarg); scale = 0.0; break; case 's': theError += ( *optarg==0x00 ); scale = atof(optarg); w = h = 0; break; case 'v': printf("%s: vers. 14 agosto 1993\n",argv[0]); verb=1; break; case 'o': theError += ( *optarg==0x00 ); OutputOpt=optind-1; break; defatult: usage(argv[0]); } } if ((optind==argc)||(theError!=0)) usage(argv[0]); for (i=optind; i\t%s\n",argv[0],argv[i],scname); fflush(stdout); } scalepict(argv[i],scname); } } void set_whs(int pw,int ph) { if (scale!=0.0) { w = (int)(scale*pw); h = (int)(scale*ph); } else { if (w==0 && h==0) { usage("scpict"); exit(1); } if (h==0) h = (int)((double)w*((double)ph/(double)pw)); if (w==0) w = (int)((double)h*((double)pw/(double)ph)); } } void scalepict(char *orgname,char *dstname) { int oldw,oldh; double oldscale; U_char r00,g00,b00; U_char r01,g01,b01; U_char r10,g10,b10; U_char r11,g11,b11; U_char *r,*g,*b; U_char *buff; double ki,kj; double ri,rj,ri1,rj1; int oi,oj,di,dj; Pict org,dst; oldh = h; oldw = w; oldscale = scale; org = pict_read_pict(orgname); set_whs(org->image_W,org->image_H); dst = pict_open(dstname,P_WRITE,h,w,M_RGB24,NULL); if ( verb ) printf("Scaling:\t%dx%d\t->\t%dx%d\n", org->image_W,org->image_H,w,h); buff = (U_char *)malloc(3*(size_t)w+10); if ( buff == NULL ) { fprintf(stderr,"No memory! Bye...\n"); exit(-1); } ki = (double)(org->image_W-1.0)/(double)(dst->image_W-1.0); kj = (double)(org->image_H-1.0)/(double)(dst->image_H-1.0); for (dj=0; dj