14 #define JPEG_CJPEG_DJPEG 34 #ifdef DONT_USE_B_MODE 35 #define READ_BINARY "r" 38 #define READ_BINARY "rb", "ctx=stm" 40 #define READ_BINARY "rb" 45 #define EXIT_FAILURE 1 49 #define EXIT_SUCCESS 1 51 #define EXIT_SUCCESS 0 64 #define NEXTBYTE() getc(infile) 68 #define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) 79 ERREXIT(
"Premature EOF in JPEG file");
92 ERREXIT(
"Premature EOF in JPEG file");
95 ERREXIT(
"Premature EOF in JPEG file");
96 return (((
unsigned int) c1) << 8) + ((
unsigned int) c2);
141 int discarded_bytes = 0;
156 if (discarded_bytes != 0) {
157 fprintf(stderr,
"Warning: garbage data found in JPEG file\n");
179 if (c1 != 0xFF || c2 !=
M_SOI)
201 length = read_2_bytes();
204 ERREXIT(
"Erroneous JPEG marker length");
208 (
void) read_1_byte();
228 length = read_2_bytes();
231 ERREXIT(
"Erroneous JPEG marker length");
243 }
else if (ch ==
'\n') {
246 }
else if (ch ==
'\\') {
248 }
else if (isprint(ch)) {
251 printf(
"\\%03o", ch);
270 int data_precision, num_components;
271 const char * process;
274 length = read_2_bytes();
276 data_precision = read_1_byte();
277 image_height = read_2_bytes();
278 image_width = read_2_bytes();
279 num_components = read_1_byte();
282 case M_SOF0: process =
"Baseline";
break;
283 case M_SOF1: process =
"Extended sequential";
break;
284 case M_SOF2: process =
"Progressive";
break;
285 case M_SOF3: process =
"Lossless";
break;
286 case M_SOF5: process =
"Differential sequential";
break;
287 case M_SOF6: process =
"Differential progressive";
break;
288 case M_SOF7: process =
"Differential lossless";
break;
289 case M_SOF9: process =
"Extended sequential, arithmetic coding";
break;
290 case M_SOF10: process =
"Progressive, arithmetic coding";
break;
291 case M_SOF11: process =
"Lossless, arithmetic coding";
break;
292 case M_SOF13: process =
"Differential sequential, arithmetic coding";
break;
293 case M_SOF14: process =
"Differential progressive, arithmetic coding";
break;
294 case M_SOF15: process =
"Differential lossless, arithmetic coding";
break;
295 default: process =
"Unknown";
break;
298 printf(
"JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
299 image_width, image_height, num_components, data_precision);
300 printf(
"JPEG process: %s\n", process);
302 if (length != (
unsigned int) (8 + num_components * 3))
303 ERREXIT(
"Bogus SOF marker length");
305 for (ci = 0; ci < num_components; ci++) {
306 (
void) read_1_byte();
307 (
void) read_1_byte();
308 (
void) read_1_byte();
324 scan_JPEG_header (
int verbose)
330 ERREXIT(
"Expected SOI marker first");
353 process_SOFn(marker);
373 printf(
"APP12 contains:\n");
389 static const char * progname;
396 fprintf(stderr,
"rdjpgcom displays any textual comments in a JPEG file.\n");
398 fprintf(stderr,
"Usage: %s [switches] [inputfile]\n", progname);
400 fprintf(stderr,
"Switches (names may be abbreviated):\n");
401 fprintf(stderr,
" -verbose Also display dimensions of JPEG image\n");
414 register int nmatched = 0;
416 while ((ca = *
arg++) !=
'\0') {
426 if (nmatched < minchars)
445 argc = ccommand(&argv);
449 if (progname ==
NULL || progname[0] == 0)
450 progname =
"rdjpgcom";
453 for (argn = 1; argn < argc; argn++) {
467 fprintf(stderr,
"%s: only one input file\n", progname);
472 fprintf(stderr,
"%s: can't open %s\n", progname, argv[argn]);
478 setmode(fileno(stdin), O_BINARY);
482 fprintf(stderr,
"%s: can't open stdin\n", progname);
491 (
void) scan_JPEG_header(verbose);
GLenum GLuint GLenum GLsizei length
first_marker(j_decompress_ptr cinfo)
int main(int argc, char **argv)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
skip_variable(j_decompress_ptr cinfo)
GLsizeiptr const GLvoid GLenum usage
keymatch(char *arg, const char *keyword, int minchars)
next_marker(j_decompress_ptr cinfo)