static int scan_JPEG_header (int verbose) { int marker; /* Expect SOI at start of file */ if (first_marker() != M_SOI) ERREXIT("Expected SOI marker first"); /* Scan miscellaneous markers until we reach SOS. */ for (;;) { marker = next_marker(); switch (marker) { case M_SOF0: /* Baseline */ case M_SOF1: /* Extended sequential, Huffman */ case M_SOF2: /* Progressive, Huffman */ case M_SOF3: /* Lossless, Huffman */ case M_SOF5: /* Differential sequential, Huffman */ case M_SOF6: /* Differential progressive, Huffman */ case M_SOF7: /* Differential lossless, Huffman */ case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF10: /* Progressive, arithmetic */ case M_SOF11: /* Lossless, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */ if (verbose) process_SOFn(marker); else skip_variable(); break; case M_SOS: /* stop before hitting compressed data */ return marker; case M_EOI: /* in case it's a tables-only JPEG stream */ return marker; case M_COM: process_COM(); break; default: /* Anything else just gets skipped */ skip_variable(); /* we assume it has a parameter count... */ break; } } /* end loop */ }
static int get_jpeg_image_dimensions(ImageSize *is, int *width, int *height) { int marker = -1, jpeg_ok = 0; *width = *height = -1; if (is->infile || !is->file) { /* Expect SOI at start of file */ if (first_marker(is) == M_SOI) { jpeg_ok = 1; /* Scan miscellaneous markers until we reach SOS. */ for (; marker != M_SOS && marker != M_EOI; ) { marker = next_marker(is); switch (marker) { /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, * treated as SOFn. C4 in particular is actually DHT. */ case M_SOF0: /* Baseline */ case M_SOF1: /* Extended sequential, Huffman */ case M_SOF2: /* Progressive, Huffman */ case M_SOF3: /* Lossless, Huffman */ case M_SOF5: /* Differential sequential, Huffman */ case M_SOF6: /* Differential progressive, Huffman */ case M_SOF7: /* Differential lossless, Huffman */ case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF10: /* Progressive, arithmetic */ case M_SOF11: /* Lossless, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */ get_image_dimensions(is, width, height); break; default: /* Anything else just gets skipped */ if (skip_variable(is) < 0) return -1; break; } } } } return jpeg_ok; }
static int scan_JPEG_header (int verbose) { int marker; /* Expect SOI at start of file */ if (first_marker() != M_SOI) ERREXIT("Expected SOI marker first"); /* Scan miscellaneous markers until we reach SOS. */ for (;;) { marker = next_marker(); switch (marker) { /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, * treated as SOFn. C4 in particular is actually DHT. */ case M_SOF0: /* Baseline */ case M_SOF1: /* Extended sequential, Huffman */ case M_SOF2: /* Progressive, Huffman */ case M_SOF3: /* Lossless, Huffman */ case M_SOF5: /* Differential sequential, Huffman */ case M_SOF6: /* Differential progressive, Huffman */ case M_SOF7: /* Differential lossless, Huffman */ case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF10: /* Progressive, arithmetic */ case M_SOF11: /* Lossless, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */ if (verbose) process_SOFn(marker); else skip_variable(); break; case M_SOS: /* stop before hitting compressed data */ return marker; case M_EOI: /* in case it's a tables-only JPEG stream */ return marker; case M_COM: process_COM(); break; case M_APP12: /* Some digital camera makers put useful textual information into * APP12 markers, so we print those out too when in -verbose mode. */ if (verbose) { printf("APP12 contains:\n"); process_COM(); } else skip_variable(); break; default: /* Anything else just gets skipped */ skip_variable(); /* we assume it has a parameter count... */ break; } } /* end loop */ }