#include #include #include #include "pict.h" #ifdef THINK_C #include #endif main(int argc,char *argv[]) { char *fname; Pict pictIn,pictOut; int fi,ti,fj,tj,i,j,n; U_char *pi,*po; #ifdef THINK_C argc = ccommand(&argv); #endif if (argc<6) { fprintf(stderr,"Uso: %s pict xmin xmax ymin ymax\n",argv[0]); fprintf(stderr,"%s: 22 octubre 1993\n",argv[0]); exit(1); } fname = argv[1]; fi = atoi(argv[2]); ti = atoi(argv[3]); fj = atoi(argv[4]); tj = atoi(argv[5]); pictIn = pict_open((char *)fname,P_READ,0,0,0,NULL); if( (fi<0) || ( ti > pictIn->image_W ) || ( fi >= ti ) || (tj<0) || ( tj > pictIn->image_H ) || ( fj >= tj ) ) { fprintf(stderr,"Error en los limites: la imagen de partida es de %dx%d\n", pictIn->image_W, pictIn->image_H ); pict_close(pictIn); exit(-1); } strcat(fname,".crop"); pictOut = pict_open((char *)fname,P_WRITE, tj-fj+1,ti-fi+1,pictIn->clr_mode,pictIn->map); if ((pictIn->pixels = (U_char*)malloc((size_t)(pictIn->image_W *pictIn->n_comp+1)))==NULL) exit(1); if ((pictOut->pixels = (U_char*)malloc((size_t)(pictOut->image_W*pictOut->n_comp+1)))==NULL) exit(1); for(j=0;j<=tj;j++) { pict_get_line(pictIn,pictIn->pixels); if (jpixels+fi; po=pictOut->pixels; for(n=0;nn_comp;n++) { memcpy(po,pi,(size_t)pictOut->image_W); pi += (size_t)pictIn->image_W; po += (size_t)pictOut->image_W; } pict_put_line(pictOut,pictOut->pixels); } pict_close(pictIn); pict_close(pictOut); pict_free(pictIn); pict_free(pictOut); }