/* * (c) SPDsoft 1993 + ATIC * Display a JFIF file using Silicon Graphics gl */ #include #include #include #include #include #include #include #ifndef PATH_SEP # define PATH_SEP '/' #endif #define Boolean int #define Output if (G_prefs.Verbose) printf #ifndef MIN #define MIN(a,b) ((a)>(b)?(b):(a)) #endif typedef struct { char *AppName; Boolean Verbose; } pref; /* * Prototypes */ void usage(char *name); void fatalError(char *str); Boolean get_options(int argc,char *argv[]); /* * JPEG Prototypes */ static void my_error_exit (j_common_ptr cinfo); int read_JPEG_file (char * filename); extern char *optarg; extern int optind,opterr; pref G_prefs; static char __ident[] = "@(#)(c) SPDsoft, 07 Feb 1996"; #define VERS_STR ((char*)&__ident[4]) /*****************************************************/ void usage(char *name) { fprintf(stderr, "usage: %s [-v][-h][files...]" "\n%s\n%s\n", name, "-v: Version, debbug", "-h: This text." ); exit(-1); } void fatalError(char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",G_prefs.AppName,str); fprintf(stderr, "%s: %s\n",G_prefs.AppName,strerror(errno)); exit(-2); } struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */ }; typedef struct my_error_mgr * my_error_ptr; static void my_error_exit (j_common_ptr cinfo) { my_error_ptr myerr = (my_error_ptr) cinfo->err; (*cinfo->err->output_message) (cinfo); longjmp(myerr->setjmp_buffer, 1); } int read_JPEG_file (char * filename) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; FILE *infile; /* source file */ JSAMPARRAY buffer; /* Output row buffer */ int row_stride; /* physical row width in output buffer */ register JSAMPROW inptr; int i, j; if (filename != NULL) { if ((infile = fopen(filename, "rb")) == NULL) { fatalError(filename); } } else infile = stdin; cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ jpeg_destroy_decompress(&cinfo); fclose(infile); return NULL; } jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, infile); (void) jpeg_read_header(&cinfo, TRUE); fprintf(stderr,"%s\t%d\t%d\t%d\n", filename, cinfo.image_width, cinfo.image_height, cinfo.num_components ); jpeg_destroy_decompress(&cinfo); fclose(infile); return 0; } /*****************************************************/ Boolean get_options(int argc,char *argv[]) { int opcion; int theError=0; if ((G_prefs.AppName = strrchr(argv[0], PATH_SEP)) != NULL) G_prefs.AppName = G_prefs.AppName+1; else G_prefs.AppName = argv[0]; G_prefs.Verbose=0; while ( (opcion=getopt(argc,argv,"vh")) != EOF ) { switch(opcion) { case 'v': printf("%s:%s\n",G_prefs.AppName,VERS_STR); G_prefs.Verbose=1; break; default: usage(G_prefs.AppName); } if ( theError!=0) usage(G_prefs.AppName); } } main(int argc,char *argv[]) { int f; get_options(argc,argv); if (optind==argc) { argc ++; } for(f=optind; f