* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
- * For conditions of distribution and use, see the accompanying README file.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
+ * For conditions of distribution and use, see the accompanying README.ijg
+ * file.
*
* This file contains a very simple stand-alone application that displays
* the text in COM (comment) markers in a JFIF file.
* JPEG markers.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
-#ifdef HAVE_LOCALE_H
#include <locale.h> /* Bill Allombert: use locale for isprint */
-#endif
#include <ctype.h> /* to declare isupper(), tolower() */
#ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */
#include <io.h> /* to declare setmode() */
#endif
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#else
* To reuse this code in another application, you might need to change these.
*/
-static FILE * infile; /* input JPEG file */
+static FILE *infile; /* input JPEG file */
/* Return next input byte, or EOF if no more */
#define NEXTBYTE() getc(infile)
/* Read one byte, testing for EOF */
static int
-read_1_byte (void)
+read_1_byte(void)
{
int c;
/* Read 2 bytes, convert to unsigned int */
/* All 2-byte quantities in JPEG markers are MSB first */
static unsigned int
-read_2_bytes (void)
+read_2_bytes(void)
{
int c1, c2;
c2 = NEXTBYTE();
if (c2 == EOF)
ERREXIT("Premature EOF in JPEG file");
- return (((unsigned int) c1) << 8) + ((unsigned int) c2);
+ return (((unsigned int)c1) << 8) + ((unsigned int)c2);
}
* in this program. (See jdmarker.c for a more complete list.)
*/
-#define M_SOF0 0xC0 /* Start Of Frame N */
-#define M_SOF1 0xC1 /* N indicates which compression process */
-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
-#define M_SOF3 0xC3
-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
-#define M_SOF6 0xC6
-#define M_SOF7 0xC7
-#define M_SOF9 0xC9
-#define M_SOF10 0xCA
-#define M_SOF11 0xCB
-#define M_SOF13 0xCD
-#define M_SOF14 0xCE
-#define M_SOF15 0xCF
-#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
-#define M_EOI 0xD9 /* End Of Image (end of datastream) */
-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
-#define M_APP0 0xE0 /* Application-specific marker, type N */
-#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
-#define M_COM 0xFE /* COMment */
+#define M_SOF0 0xC0 /* Start Of Frame N */
+#define M_SOF1 0xC1 /* N indicates which compression process */
+#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
+#define M_SOF3 0xC3
+#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
+#define M_SOF6 0xC6
+#define M_SOF7 0xC7
+#define M_SOF9 0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
+#define M_EOI 0xD9 /* End Of Image (end of datastream) */
+#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
+#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
+#define M_COM 0xFE /* COMment */
/*
*/
static int
-next_marker (void)
+next_marker(void)
{
int c;
int discarded_bytes = 0;
*/
static int
-first_marker (void)
+first_marker(void)
{
int c1, c2;
*/
static void
-skip_variable (void)
+skip_variable(void)
/* Skip over an unknown or uninteresting variable-length marker */
{
unsigned int length;
length -= 2;
/* Skip over the remaining bytes */
while (length > 0) {
- (void) read_1_byte();
+ (void)read_1_byte();
length--;
}
}
*/
static void
-process_COM (int raw)
+process_COM(int raw)
{
unsigned int length;
int ch;
int lastch = 0;
/* Bill Allombert: set locale properly for isprint */
-#ifdef HAVE_LOCALE_H
setlocale(LC_CTYPE, "");
-#endif
/* Get the marker parameter length count */
length = read_2_bytes();
} else if (isprint(ch)) {
putc(ch, stdout);
} else {
- printf("\\%03o", ch);
+ printf("\\%03o", (unsigned int)ch);
}
lastch = ch;
length--;
printf("\n");
/* Bill Allombert: revert to C locale */
-#ifdef HAVE_LOCALE_H
setlocale(LC_CTYPE, "C");
-#endif
}
*/
static void
-process_SOFn (int marker)
+process_SOFn(int marker)
{
unsigned int length;
unsigned int image_height, image_width;
int data_precision, num_components;
- const char * process;
+ const char *process;
int ci;
length = read_2_bytes(); /* usual parameter length count */
case M_SOF10: process = "Progressive, arithmetic coding"; break;
case M_SOF11: process = "Lossless, arithmetic coding"; break;
case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
- case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
+ case M_SOF14:
+ process = "Differential progressive, arithmetic coding"; break;
case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
default: process = "Unknown"; break;
}
image_width, image_height, num_components, data_precision);
printf("JPEG process: %s\n", process);
- if (length != (unsigned int) (8 + num_components * 3))
+ if (length != (unsigned int)(8 + num_components * 3))
ERREXIT("Bogus SOF marker length");
for (ci = 0; ci < num_components; ci++) {
- (void) read_1_byte(); /* Component ID code */
- (void) read_1_byte(); /* H, V sampling factors */
- (void) read_1_byte(); /* Quantization table number */
+ (void)read_1_byte(); /* Component ID code */
+ (void)read_1_byte(); /* H, V sampling factors */
+ (void)read_1_byte(); /* Quantization table number */
}
}
*/
static int
-scan_JPEG_header (int verbose, int raw)
+scan_JPEG_header(int verbose, int raw)
{
int marker;
/* Command line parsing code */
-static const char * progname; /* program name for error messages */
+static const char *progname; /* program name for error messages */
static void
-usage (void)
+usage(void)
/* complain about bad command line */
{
fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
static int
-keymatch (char * arg, const char * keyword, int minchars)
+keymatch(char *arg, const char *keyword, int minchars)
/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
/* keyword is the constant keyword (must be lower case already), */
/* minchars is length of minimum legal abbreviation. */
*/
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
int argn;
- char * arg;
+ char *arg;
int verbose = 0, raw = 0;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "rdjpgcom"; /* in case C library doesn't provide it */
/* Open the input file. */
/* Unix style: expect zero or one file name */
- if (argn < argc-1) {
+ if (argn < argc - 1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
}
/* Scan the JPEG headers. */
- (void) scan_JPEG_header(verbose, raw);
+ (void)scan_JPEG_header(verbose, raw);
/* All done. */
exit(EXIT_SUCCESS);