/* * (c) SPDsoft 1993 + ATIC * Display a PICT2 file using Silicon Graphics gl */ #include #include #include #include #include #include #define ALPHA_OPAC 0x00 #define SCREEN_W G_prefs.screen_w #define SCREEN_H G_prefs.screen_h #define Boolean int #define Output if (G_prefs.Verbose) printf #define IH pictIn->image_H #define IW pictIn->image_W #define MIN(a,b) ((a)>(b)?(b):(a)) typedef struct { char *AppName; Boolean Foreground; Boolean FullScreen; Boolean FillScreen; Boolean Growable; Boolean KeepAspectRatio; Boolean Verbose; Boolean Alfa; long screen_w; long screen_h; } pref; void init_graphics(void); void redraw(Pict image); void usage(char *name); void fatalError(char *str); Boolean get_options(int argc,char *argv[]); extern char *optarg; extern int optind,opterr; pref G_prefs; static char __ident[] = "@(#)(c) SPDsoft, 04 Jul 1995"; #define VERS_STR ((char*)&__ident[4]) Boolean get_options(int argc,char *argv[]) { int opcion; int theError=0; G_prefs.AppName = argv[0]; G_prefs.Foreground = 0; G_prefs.FullScreen = 0; G_prefs.FillScreen = 0; G_prefs.Growable = 0; G_prefs.KeepAspectRatio = 1; G_prefs.Verbose=0; G_prefs.Alfa=0; while ( (opcion=getopt(argc,argv,"afbFgGvh")) != EOF ) { switch(opcion) { case 'a': G_prefs.Alfa = 1; break; case 'f': G_prefs.Foreground = 1; break; case 'b': G_prefs.FullScreen = 1; break; case 'F': G_prefs.FullScreen = 1; G_prefs.FillScreen = 1; break; case 'g': G_prefs.Growable = 1; break; case 'G': G_prefs.Growable = 1; G_prefs.KeepAspectRatio = 0; break; case 'v': printf("%s:%s\n",argv[0],VERS_STR); G_prefs.Verbose=1; break; default: usage(argv[0]); } if ( theError!=0) usage(argv[0]); } } void usage(char *name) { fprintf(stderr, "usage: %s [-b|-F|-g|-G][-f][-v][-a][-h][files...]" "\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", name, "-a: Alpha channel", "-f: Don't fork (run in foreground)", "-b: Full screen", "-F: Fill full screen", "-g: Growable, Keep aspect ratio", "-G: Growable", "-v: Version, debbug", "-h: This text. Note: Press to go to next image" ); exit(-1); } void fatalError(char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",G_prefs.AppName,str); exit(-2); } main(int argc,char *argv[]) { Pict pictIn; int ReadMode = P_READ; Boolean Fill; int f,i,j; U_char *pix; U_char *unpacked,*r_ptr,*g_ptr,*b_ptr,*a_ptr; long gwid; long gw_x, gw_y; long MyEvent; short val; Boolean quitting=0; Boolean NeedRedraw=1; char tmpStr[64]; get_options(argc,argv); init_graphics(); if(G_prefs.FullScreen) { prefposition( 0, SCREEN_W, 0, SCREEN_H ); gwid=winopen(""); RGBmode(); gconfig(); } if (optind==argc) { argc ++; ReadMode = P_STDI; } Fill = G_prefs.FillScreen; for(f=optind; fclr_mode,IH,IW ); if((( IW > SCREEN_W ) || ( IH > SCREEN_H))&&(G_prefs.FullScreen)) G_prefs.FillScreen=1; pictIn->pixels = (U_char *)calloc( (size_t)IH * (size_t)IW , (size_t)4); unpacked = (U_char *)malloc((size_t)IW*(size_t)pictIn->n_comp+1); if ((pictIn->pixels==NULL) || ( unpacked==NULL)) fatalError("Se acabo la memoria"); pix = pictIn->pixels + (size_t)4*IW*(IH-1); if(G_prefs.Alfa) pictIn->clr_mode = -1; for (i=0; i < IH; i++) { a_ptr = unpacked; r_ptr = a_ptr+IW; g_ptr = r_ptr+IW; b_ptr = g_ptr+IW; pict_get_line(pictIn,unpacked); switch(pictIn->clr_mode) { case M_MONO: case M_RGB8: for (j=0; jmap[*a_ptr][2]; *pix++ = pictIn->map[*a_ptr][1]; *pix++ = pictIn->map[*a_ptr++][0]; } break; case M_RGB24: for (j=0; jpixels); } else lrectwrite( (SCREEN_W-IW+1)/2,(SCREEN_H+IH-1)/2, (SCREEN_W+IW-1)/2,(SCREEN_H-IH+1)/2, (unsigned long *)pictIn->pixels); } else { if(G_prefs.Growable) { getsize(&gw_x, &gw_y); viewport(0,gw_x-1,0,gw_y-1); rectzoom( (float)gw_x/(float)IW, (float)gw_y/(float)IH); } lrectwrite( 0,(IH-1),(IW-1),0, (unsigned long *)pictIn->pixels); } }