Merge branch 'upstream' into tizen_base
[platform/upstream/libjpeg-turbo.git] / rdjpgcom.c
index 2f0115d..d9a6f85 100644 (file)
@@ -4,9 +4,10 @@
  * 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
@@ -56,7 +49,7 @@
  * 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)
@@ -68,7 +61,7 @@ static FILE * infile;           /* input JPEG file */
 
 /* Read one byte, testing for EOF */
 static int
-read_1_byte (void)
+read_1_byte(void)
 {
   int c;
 
@@ -81,7 +74,7 @@ read_1_byte (void)
 /* 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;
 
@@ -91,7 +84,7 @@ read_2_bytes (void)
   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);
 }
 
 
@@ -101,25 +94,24 @@ read_2_bytes (void)
  * 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 */
 
 
 /*
@@ -133,7 +125,7 @@ read_2_bytes (void)
  */
 
 static int
-next_marker (void)
+next_marker(void)
 {
   int c;
   int discarded_bytes = 0;
@@ -168,7 +160,7 @@ next_marker (void)
  */
 
 static int
-first_marker (void)
+first_marker(void)
 {
   int c1, c2;
 
@@ -190,7 +182,7 @@ first_marker (void)
  */
 
 static void
-skip_variable (void)
+skip_variable(void)
 /* Skip over an unknown or uninteresting variable-length marker */
 {
   unsigned int length;
@@ -203,7 +195,7 @@ skip_variable (void)
   length -= 2;
   /* Skip over the remaining bytes */
   while (length > 0) {
-    (void) read_1_byte();
+    (void)read_1_byte();
     length--;
   }
 }
@@ -216,16 +208,14 @@ skip_variable (void)
  */
 
 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();
@@ -253,7 +243,7 @@ process_COM (int raw)
     } else if (isprint(ch)) {
       putc(ch, stdout);
     } else {
-      printf("\\%03o", ch);
+      printf("\\%03o", (unsigned int)ch);
     }
     lastch = ch;
     length--;
@@ -261,9 +251,7 @@ process_COM (int raw)
   printf("\n");
 
   /* Bill Allombert: revert to C locale */
-#ifdef HAVE_LOCALE_H
   setlocale(LC_CTYPE, "C");
-#endif
 }
 
 
@@ -273,12 +261,12 @@ process_COM (int raw)
  */
 
 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 */
@@ -300,7 +288,8 @@ process_SOFn (int marker)
   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;
   }
@@ -309,13 +298,13 @@ process_SOFn (int marker)
          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 */
   }
 }
 
@@ -331,7 +320,7 @@ process_SOFn (int marker)
  */
 
 static int
-scan_JPEG_header (int verbose, int raw)
+scan_JPEG_header(int verbose, int raw)
 {
   int marker;
 
@@ -396,11 +385,11 @@ scan_JPEG_header (int verbose, int raw)
 
 /* 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");
@@ -416,7 +405,7 @@ usage (void)
 
 
 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. */
@@ -445,17 +434,12 @@ keymatch (char * arg, const char * keyword, int minchars)
  */
 
 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 */
@@ -476,7 +460,7 @@ main (int argc, char **argv)
 
   /* 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();
   }
@@ -501,7 +485,7 @@ main (int argc, char **argv)
   }
 
   /* Scan the JPEG headers. */
-  (void) scan_JPEG_header(verbose, raw);
+  (void)scan_JPEG_header(verbose, raw);
 
   /* All done. */
   exit(EXIT_SUCCESS);