]> Creatis software - gdcm.git/blobdiff - src/gdcmjpegls/Decoder/decoder.c
COMP: Attempt to please icc
[gdcm.git] / src / gdcmjpegls / Decoder / decoder.c
index 99745ff8ec86890991aa04944087d98b35e1c098..3da8dd8a172f2586eab4892db21fcc71d7936662 100644 (file)
 #include <string.h>
 #include "jpegmark.h"
 
+
+void usage();
+
+
 #define  PGMNAME PGMPREFIX "d"
 #define  EPGMNAME PGMPREFIX "e"
 
-static char *banner="\n\
+/* define color mode strings */
+char plane_int_string[] = "plane by plane",
+   line_int_string[] = "line intlv",
+   pixel_int_string[] = "sample intlv";
+
+static char banner[]="\n\
 =============================================\n\
 SPMG/JPEG-LS DECOMPRESSOR " JPEGLSVERSION "\n\
 =============================================\n\
@@ -100,8 +109,6 @@ int bpp16;            /* Indicates if 16 bits per pixel mode or not */
 int lutmax;            /* lutmax is either 256 or 4501 */
 
 
-
-
 /* reset */
 #ifndef FIXRESET
 int  RESET;
@@ -121,12 +128,9 @@ int     highmask;
 
 
 
-
-
 /* Write one row of pixel values */
 inline void write_one_line(pixel* line, int cols, FILE* outfile)
 {
-
   int i, index;
   unsigned int* maptable;
       
@@ -138,7 +142,7 @@ inline void write_one_line(pixel* line, int cols, FILE* outfile)
       line8 = (unsigned char*)safealloc(cols);
   
       for (i=0; i< cols; i++)
-        *(line8+i)=ENDIAN8(*(line+i));
+        *(line8+i)=(unsigned char)ENDIAN8(*(line+i));
     
       fwrite(line8, sizeof(unsigned char), cols, outfile);
 
@@ -226,7 +230,8 @@ inline void write_one_line(pixel* line, int cols, FILE* outfile)
 
 
 
-void initbuffers(int multi, int comp) {
+void initbuffers(int multi, int comp)
+{
 
   int  i;
 
@@ -261,7 +266,7 @@ void initbuffers(int multi, int comp) {
 
 }
 
-swaplines()
+void swaplines()
 {
   pixel *temp;
   temp = pscanl0;
@@ -271,7 +276,7 @@ swaplines()
   cscanline = cscanl0 + components*(LEFTMARGIN-1);
 }
 
-c_swaplines(int i)
+void c_swaplines(int i)
 {
   pixel *temp;
   temp = c_pscanl0[i];
@@ -281,29 +286,29 @@ c_swaplines(int i)
   c_cscanline[i] = c_cscanl0[i] + (LEFTMARGIN-1);
 }
 
-void closebuffers(int multi) {
+void closebuffers(int multi)
+{
 
-  int     i;
+  int i;
 
   fclose(in);
   if (multi==0)
-     fclose(out);
-        else
-           for (i=0;i<components;i++)
-         fclose(c_out[i]);
+    fclose(out);
+  else
+    for (i=0;i<components;i++)
+      fclose(c_out[i]);
 
-        free(pscanl0);
-        free(cscanl0);
+  free(pscanl0);
+  free(cscanl0);
 }
 
 
-
-
-int initialize(int argc, char *argv[]) {
-  char line[256],tmp_char[1],   
-    *infilename = NULL,
-    *outfilename = OUTFILE ".out",
-    *c_outfilename[MAX_COMPONENTS],
+/* command line argument parsing */
+int initialize(int argc, char *argv[])
+{
+  char *infilename = NULL;
+  const char *outfilename = OUTFILE ".out";
+  char *c_outfilename[MAX_COMPONENTS],
     *color_mode_string;
   int i, max_samp_columns, max_samp_rows, mk, n_s,
     end_of_seek=0,
@@ -315,7 +320,7 @@ int initialize(int argc, char *argv[]) {
   int pos;   /* position in the file, after the header */
 
   for (i=0;i<MAX_COMPONENTS;i++) {
-    c_outfilename[i]=malloc(strlen(OUTFILE)+20);
+    c_outfilename[i]=(char*)malloc(strlen(OUTFILE)+20);
     sprintf(c_outfilename[i],"%s%d.out",OUTFILE,i+1);
   }
 
@@ -554,9 +559,11 @@ int initialize(int argc, char *argv[]) {
   }
 
   if ((!multi) && (color_mode==PLANE_INT))
+    {
     if (components>1) {
       fprintf(stderr,"\nERROR: Cannot use -P (PPM output) with plane intereleaved mode\n");
       exit(10);
+      }
     }
   else multi=1;
 
@@ -570,7 +577,7 @@ int initialize(int argc, char *argv[]) {
   }
 
   if ((multi) && (out_files) && (out_files!=components)) {
-    fprintf(stderr,"ERROR: Number of files, %d%, for output must be equal to number of image components, %d\n",out_files,components);
+    fprintf(stderr,"ERROR: Number of files, %d, for output must be equal to number of image components, %d\n",out_files,components);
     exit(10);
   }
 
@@ -613,6 +620,8 @@ int initialize(int argc, char *argv[]) {
   }
 
 
+  /* msgfile seems to start being used here, let's initialize it here */
+  if ( !msgfile ) msgfile = stdout;
   /* Open out file */
   if ( outfilename == NULL ) {
     usage();
@@ -865,17 +874,18 @@ int initialize(int argc, char *argv[]) {
 int main (int argc, char *argv[]) {
   int n,n_c,n_r,my_i,n_s,mk,seek_return;
   int found_EOF = 0;
-  double t0, t1, get_utime();
+  double t0, t1; /*, get_utime();*/
   long pos0, pos1,    
     tot_in = 0,
     tot_out = 0;
   pixel *local_scanl0,*local_scanl1,*local_pscanline,*local_cscanline;
   int MCUs_counted;
+  local_cscanline = local_pscanline = NULL;
   
   
   /* Parse the parameters, initialize */
   /* Not yet fully implemented */
-  bufiinit();
+  bufiinit(NULL);
   pos0 = initialize(argc, argv); 
 
 
@@ -1439,7 +1449,7 @@ int main (int argc, char *argv[]) {
   }
 
   if (head_scan[0]->need_table)
-    fprintf(msgfile,"A mapping table was used which had %i entries of %i bytes each.\n",head_scan[0]->MAXTAB, head_scan[0]->Wt);
+    fprintf(msgfile,"A mapping table was used which had %d entries of %d bytes each.\n",head_scan[0]->MAXTAB, head_scan[0]->Wt);
 
   if (got_restart)
     fprintf(msgfile,"Restart markers were found with a restart interval of %i.\n",restart_interval);
@@ -1460,9 +1470,9 @@ int main (int argc, char *argv[]) {
 
 
   t1 = get_utime();
-  fprintf(msgfile,"Total bits  in: %ld  Symbols out: %ld  %5.3lf bps\n",
+  fprintf(msgfile,"Total bits  in: %ld  Symbols out: %ld  %5.3f bps\n",
            tot_in,tot_out,tot_in/(double)tot_out);
-  fprintf(msgfile,"Time = %1.3lf secs : %1.0lf KSymbols/sec\n",t1-t0,
+  fprintf(msgfile,"Time = %1.3f secs : %1.0f KSymbols/sec\n",t1-t0,
           (tot_out)/(1024*(t1-t0)));
 
   if ( found_EOF )
@@ -1474,36 +1484,36 @@ int main (int argc, char *argv[]) {
 
 
 
-usage()
+void usage()
 {
   fprintf(stderr,"Usage: %s [flags] [infile] [outfile1 [outfile2, ...]]\n\
-DEFAULTS:\n\
-infile   = %s.\n\
-outfile1 = %s for color image in a single (PPM) output file.\n\
-outfile1 = %s for monochrome image in a single (PGM) output file.\n\
-outfile[1,2,...] = %s for multiple (PGM) output files \n\
-     in plane or line interleaved modes.\n",
+    DEFAULTS:\n\
+    infile   = %s.\n\
+    outfile1 = %s for color image in a single (PPM) output file.\n\
+    outfile1 = %s for monochrome image in a single (PGM) output file.\n\
+    outfile[1,2,...] = %s for multiple (PGM) output files \n\
+    in plane or line interleaved modes.\n",
     "locod", "specified JLS file", OUTFILE ".out", 
     OUTFILE "1.out",
     OUTFILE "[1,2,...].out");
-fprintf(stderr,"FLAGS:\n\
-outfile2, ... : Multiple output specification for plane or line int. mode.\n\
--i<infile>    : Alternate input specification, use -i- for stdin.\n\
--o<outfile>   : Alternate output specification, use -o- for stdout.\n\
--P            : Generate single (.ppm) output file for sample/line int. mode.\n\
-");
-    fprintf(stderr,"\
--h            : Print this help.\n\
-*** No spaces allowed between a flag and its argument.\n\
-");
+  fprintf(stderr,"FLAGS:\n\
+    outfile2, ... : Multiple output specification for plane or line int. mode.\n\
+    -i<infile>    : Alternate input specification, use -i- for stdin.\n\
+    -o<outfile>   : Alternate output specification, use -o- for stdout.\n\
+    -P            : Generate single (.ppm) output file for sample/line int. mode.\n\
+    ");
+  fprintf(stderr,"\
+    -h            : Print this help.\n\
+    *** No spaces allowed between a flag and its argument.\n\
+    ");
   
 }
 
 
-bad_flag(char *s)
+void bad_flag(char *s)
 {
-    fprintf(stderr,"Bad flag %s\n",s);
-    usage();
-    exit(10);
+  fprintf(stderr,"Bad flag %s\n",s);
+  usage();
+  exit(10);
 }