]> Creatis software - gdcm.git/commitdiff
ENH: Start working again on the MPEG2 stuff. Gather the stdio mess in a single place
authormalaterre <malaterre>
Wed, 26 Oct 2005 19:17:30 +0000 (19:17 +0000)
committermalaterre <malaterre>
Wed, 26 Oct 2005 19:17:30 +0000 (19:17 +0000)
14 files changed:
src/gdcmmpeg2/src/mpeg2dec/CMakeLists.txt
src/gdcmmpeg2/src/mpeg2dec/getbits.c
src/gdcmmpeg2/src/mpeg2dec/getblk.c
src/gdcmmpeg2/src/mpeg2dec/gethdr.c
src/gdcmmpeg2/src/mpeg2dec/getpic.c
src/gdcmmpeg2/src/mpeg2dec/getvlc.c
src/gdcmmpeg2/src/mpeg2dec/motion.c
src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c
src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.h
src/gdcmmpeg2/src/mpeg2dec/recon.c
src/gdcmmpeg2/src/mpeg2dec/spatscal.c
src/gdcmmpeg2/src/mpeg2dec/store.c
src/gdcmmpeg2/src/mpeg2dec/subspic.c
src/gdcmmpeg2/src/mpeg2dec/systems.c

index 942e5fa2866279e7a4cb3f865696d269a401efdd..e30205e9f7244b51ec34828bf49ac2a7a9db0881 100644 (file)
@@ -18,11 +18,11 @@ SET(GDCM_MPEG2DEC_SOURCES
   #  verify.c
   )
 
-ADD_LIBRARY(gdcmmpeg2 ${GDCM_MPEG2DEC_SOURCES} mpeg2dec.c)
-IF(UNIX)
-  TARGET_LINK_LIBRARIES(gdcmmpeg2 -lm)
-ENDIF(UNIX)
+#ADD_LIBRARY(gdcmmpeg2 ${GDCM_MPEG2DEC_SOURCES} mpeg2dec.c)
+#IF(UNIX)
+#  TARGET_LINK_LIBRARIES(gdcmmpeg2 -lm)
+#ENDIF(UNIX)
 
 #ADD_DEFINITIONS(-DGDCM_BUILD_MPEG2DEC)
-#ADD_EXECUTABLE(mpeg2decode mpeg2dec.c)
-#TARGET_LINK_LIBRARIES(mpeg2decode gdcmmpeg2)
+ADD_EXECUTABLE(mpeg2decode ${GDCM_MPEG2DEC_SOURCES} mpeg2dec.c)
+TARGET_LINK_LIBRARIES(mpeg2decode -lm)
index 837190bb5ebb0ccb12cb1dff92330944e6532a85..3a779b860d7d12fc314d09ec974ccd08435fdbe4 100644 (file)
@@ -32,9 +32,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #include "config.h"
 #include "global.h"
 
index 33734168b0107d6bb7ef85a38e785ee108b00c2a..e218989814d80046e1650a839c300e25b5030824 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 
index 4b64a0e56d76732ca386e7d043dd8f1965ea3476..30ffa5a2fcd1cb5fbd0a87994987c780d2e685bb 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 
index 2610ad1b33df311d0e6f17875d186a547e07f0f5..c8e8594039ddc643005f98956703a645d3412f60 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 
index ff18191b67605646db003da4ae4feea9fc940615..0b847c4460ac43754052f5f4a450389516126520 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 #include "getvlc.h"
index c0957780ab7c3560773c75407c0c2447b5b0027f..3c058e85f653d2eaaf619affc2f28604687ed0e9 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 
index f5f7dc43f1740c6cc6b6a171865bf0ad561ea960..9cf11c9ec8915d976203fc5a11308e9f1e1366f9 100644 (file)
@@ -28,7 +28,6 @@
  *
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -58,6 +57,7 @@ static void Clear_Options();
 static void Print_Options();
 #endif
 
+
 int my_open(char *filename)
 {
   return open(filename,O_RDONLY|O_BINARY);
@@ -75,7 +75,82 @@ int my_close(int infile)
   return close(infile);
 }
 
+ostream *my_fopen(const char *path, const char *mode)
+{
+  FILE *fd = fopen(path, mode);
+  ostream *os = (ostream*)malloc(sizeof(ostream));
+  os->Fd = fd;
+  return os;
+}
+
+int my_fseek(ostream *stream, long offset, int whence)
+{
+  return fseek(stream->Fd, offset, whence);
+}
+
+size_t my_fread(void *ptr, size_t size, size_t nmemb, ostream *stream)
+{
+  return fread(ptr, size, nmemb, stream->Fd);
+}
+
+size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, ostream *stream)
+{
+  return fwrite(ptr, size, nmemb, stream->Fd);
+}
+
+int my_fclose(ostream *fp)
+{
+  FILE *fd = fp->Fd;
+  free(fp);
+  return fclose(fd);
+}
+#include <stdarg.h>
+
+int my_printf(const char *format, ...)
+{
+  //return printf(format, ...);
+  va_list argptr;
+  int ret;
+
+  va_start(argptr, format);
+  ret = vprintf(format, argptr);
+  va_end(argptr);
+
+  return ret;
+}
+
+int my_sprintf(char *str, const char *format, ...)
+{
+  //return sprintf(str, format, ...);
+  va_list argptr;
+  int ret;
+
+  va_start(argptr, format);
+  ret = vsprintf(str,format, argptr);
+  va_end(argptr);
+
+  return ret;
+}
+
+int my_fprintf(const char *format, ...)
+{
+  //return fprintf(stderr, format, ...);
+  va_list argptr;
+  int ret;
+
+  va_start(argptr, format);
+  ret = vfprintf(stderr,format, argptr);
+  va_end(argptr);
+
+  return ret;
+}
+void my_exit(int status)
+{
+  exit(status);
+}
+
 
+#define GDCM_BUILD_MPEG2DEC
 
 #ifdef GDCM_BUILD_MPEG2DEC
 int main(argc,argv)
index 059b86104a5b640cdf8e47e27122edb8f7719c25..e80686780ae4b5a1576f2d0fe427af9edbf273b9 100644 (file)
 #define MB_WEIGHT                  32
 #define MB_CLASS4                  64
 
+#include <stdio.h>
+typedef struct
+{
+  FILE* Fd;
+} ostream;
+
+int my_open(char *filename);
+int my_printf(const char *format, ...);
+int my_fprintf(const char *format, ...);
+int my_sprintf(char *str, const char *format, ...);
+void my_exit(int status);
+ostream *my_fopen(const char *path, const char *mode);
+int my_fseek(ostream *stream, long offset, int whence);
+size_t my_fread(void *ptr, size_t size, size_t nmemb, ostream *stream);
+int my_fclose(ostream *fp);
+
index 4a21264bdd8a966e8a621de1b3513442b7fcd329..9ea3dc0e3479d37954f118e85a6e73baeb845f0c 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-
 #include "config.h"
 #include "global.h"
 
index d6629a987db9ddbc461fec5337a45402652d7391..08e78cdf8c5eed73009c3609756e41ee155e49dc 100644 (file)
@@ -1,7 +1,33 @@
+/* spatscal.c, ????                                                         */
+
+/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
+
+/*
+ * Disclaimer of Warranty
+ *
+ * These software programs are available to the user without any license fee or
+ * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
+ * any and all warranties, whether express, implied, or statuary, including any
+ * implied warranties or merchantability or of fitness for a particular
+ * purpose.  In no event shall the copyright-holder be liable for any
+ * incidental, punitive, or consequential damages of any kind whatsoever
+ * arising from the use of these programs.
+ *
+ * This disclaimer of warranty extends to the user of these programs and user's
+ * customers, employees, agents, transferees, successors, and assigns.
+ *
+ * The MPEG Software Simulation Group does not represent or warrant that the
+ * programs furnished hereunder are free of infringement of any third-party
+ * patents.
+ *
+ * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
+ * are subject to royalty fees to patent holders.  Many of these patents are
+ * general enough such that they are unavoidable regardless of implementation
+ * design.
+ *
+ */
 
-#include <stdio.h>
 #include <string.h> /* for strcat */
-#include <stdlib.h> /* for exit */
 #include "config.h"
 #include "global.h"
 
@@ -96,7 +122,7 @@ static void Read_Lower_Layer_Component_Framewise(comp,lw,lh)
     printf("reading %s\n",fname);
 #endif /* VERBOSE */
   fd=fopen(fname,"rb");
-  if (fd==NULL) exit(-1);
+  if (fd==NULL) my_exit(-1);
   for (j=0; j<lh; j++) {
      for (i=0; i<lw; i++)
        llframe0[comp][lw*j+i]=getc(fd);
@@ -127,7 +153,7 @@ static void Read_Lower_Layer_Component_Fieldwise(comp,lw,lh)
     printf("reading %s\n",fname);
 #endif /* VERBOSE */
   fd=fopen(fname,"rb");
-  if (fd==NULL) exit(-1);
+  if (fd==NULL) my_exit(-1);
   for (j=0; j<lh; j+=lower_layer_progressive_frame?1:2)
     for (i=0; i<lw; i++)
       llframe0[comp][lw*j+i]=getc(fd);
@@ -141,7 +167,7 @@ static void Read_Lower_Layer_Component_Fieldwise(comp,lw,lh)
       printf("reading %s\n",fname);
 #endif /* VERBOSE */
     fd=fopen(fname,"rb");
-    if (fd==NULL) exit(-1);
+    if (fd==NULL) my_exit(-1);
     for (j=1; j<lh; j+=2)
       for (i=0; i<lw; i++)
         llframe1[comp][lw*j+i]=getc(fd);
index 9c9b7d9456a36277e2d89340c6fcd29556440f4b..7bc9906bb6f32dd674b073e9d9117d18b3ad765d 100644 (file)
@@ -27,8 +27,7 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h> /* for malloc */
 #include <fcntl.h>
 #include <string.h> /* for strcat */
 
@@ -68,16 +67,16 @@ int frame;
   if (progressive_sequence || progressive_frame || Frame_Store_Flag)
   {
     /* progressive */
-    sprintf(outname,Output_Picture_Filename,frame,'f');
+    my_sprintf(outname,Output_Picture_Filename,frame,'f');
     store_one(outname,src,0,Coded_Picture_Width,vertical_size);
   }
   else
   {
     /* interlaced */
-    sprintf(outname,Output_Picture_Filename,frame,'a');
+    my_sprintf(outname,Output_Picture_Filename,frame,'a');
     store_one(outname,src,0,Coded_Picture_Width<<1,vertical_size>>1);
 
-    sprintf(outname,Output_Picture_Filename,frame,'b');
+    my_sprintf(outname,Output_Picture_Filename,frame,'b');
     store_one(outname,src,
       Coded_Picture_Width,Coded_Picture_Width<<1,vertical_size>>1);
   }
@@ -126,7 +125,7 @@ int offset,incr,height;
 
   hsize = horizontal_size;
 
-  sprintf(tmpname,"%s.Y",outname);
+  my_sprintf(tmpname,"%s.Y",outname);
   store_yuv1(tmpname,src[0],offset,incr,hsize,height);
 
   if (chroma_format!=CHROMA444)
@@ -139,10 +138,10 @@ int offset,incr,height;
     height>>=1;
   }
 
-  sprintf(tmpname,"%s.U",outname);
+  my_sprintf(tmpname,"%s.U",outname);
   store_yuv1(tmpname,src[1],offset,incr,hsize,height);
 
-  sprintf(tmpname,"%s.V",outname);
+  my_sprintf(tmpname,"%s.V",outname);
   store_yuv1(tmpname,src[2],offset,incr,hsize,height);
 }
 
@@ -156,11 +155,11 @@ int offset,incr,width,height;
   unsigned char *p;
 
   if (!Quiet_Flag)
-    fprintf(stderr,"saving %s\n",name);
+    my_fprintf("saving %s\n",name);
 
   if ((outfile = open(name,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
   {
-    sprintf(Error_Text,"Couldn't create %s\n",name);
+    my_sprintf(Error_Text,"Couldn't create %s\n",name);
     Error(Error_Text);
   }
 
@@ -218,11 +217,11 @@ int offset, incr, height;
   strcat(outname,".SIF");
 
   if (!Quiet_Flag)
-    fprintf(stderr,"saving %s\n",outname);
+    my_fprintf("saving %s\n",outname);
 
   if ((outfile = open(outname,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
   {
-    sprintf(Error_Text,"Couldn't create %s\n",outname);
+    my_sprintf(Error_Text,"Couldn't create %s\n",outname);
     Error(Error_Text);
   }
 
@@ -311,11 +310,11 @@ int tgaflag;
   strcat(outname,tgaflag ? ".tga" : ".ppm");
 
   if (!Quiet_Flag)
-    fprintf(stderr,"saving %s\n",outname);
+    my_fprintf("saving %s\n",outname);
 
   if ((outfile = open(outname,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))==-1)
   {
-    sprintf(Error_Text,"Couldn't create %s\n",outname);
+    my_sprintf(Error_Text,"Couldn't create %s\n",outname);
     Error(Error_Text);
   }
 
@@ -333,7 +332,7 @@ int tgaflag;
   else
   {
     /* PPM header */
-    sprintf(header,"P6\n%d %d\n255\n",horizontal_size,height);
+    my_sprintf(header,"P6\n%d %d\n255\n",horizontal_size,height);
 
     for (i=0; header[i]!=0; i++)
       putbyte(header[i]);
index 30ae35e9fa0a0d93018c175537b03b54e69bac57..702b9beb94c2b624121ea847ebcf6c8f563f75fc 100644 (file)
@@ -1,4 +1,3 @@
-/* #define DEBUG */
 /* subspic.c, Frame buffer substitution routines */
 
 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
@@ -28,9 +27,7 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
+//#include <fcntl.h>
 
 #include "config.h"
 #include "global.h"
@@ -66,7 +63,7 @@ int sequence_framenum;
 
 
 #ifdef DEBUG
-  printf("SUB: seq fn(%d) bitfn(%d) tempref(%d) picstr(%d) type(%d)\n", 
+  my_printf("SUB: seq fn(%d) bitfn(%d) tempref(%d) picstr(%d) type(%d)\n", 
     sequence_framenum, bitstream_framenum, temporal_reference, 
     picture_structure, picture_coding_type);
 #endif
@@ -118,7 +115,7 @@ int sequence_framenum;
 #ifdef DEBUG
     else if((picture_coding_type!=B_TYPE)||(picture_coding_type!=D_TYPE))
     {
-      printf("NO SUBS FOR THIS PICTURE\n");
+      my_printf("NO SUBS FOR THIS PICTURE\n");
     }
 #endif
   }
@@ -162,7 +159,7 @@ int framenum;
   int field_mode;
 
   if(framenum<0)
-    printf("ERROR: framenum (%d) is less than zero\n", framenum);
+    my_printf("ERROR: framenum (%d) is less than zero\n", framenum);
 
 
   if(Big_Picture_Flag)
@@ -172,7 +169,7 @@ int framenum;
 
   if(rerr!=0)
   {
-    printf("was unable to substitute frame\n");
+    my_printf("was unable to substitute frame\n");
   }
 
   /* now copy to the appropriate buffer */
@@ -204,7 +201,7 @@ int framenum;
 
 #ifdef VERBOSE
   if(Verbose_Flag > NO_LAYER)
-    printf("substituted %s %d\n",
+    my_printf("substituted %s %d\n",
       (field_mode ? (parity?"bottom field":"bottom field"):"frame"), framenum);
 #endif
 }
@@ -221,17 +218,17 @@ int framenum;
   char outname[FILENAME_LENGTH];
   char name[FILENAME_LENGTH];
 
-  sprintf(outname,filename,framenum);
+  my_sprintf(outname,filename,framenum);
 
 
-  sprintf(name,"%s.Y",outname);
+  my_sprintf(name,"%s.Y",outname);
   err += Read_Component(name, frame[0], Coded_Picture_Width, 
     Coded_Picture_Height);
 
-  sprintf(name,"%s.U",outname);
+  my_sprintf(name,"%s.U",outname);
   err += Read_Component(name, frame[1], Chroma_Width, Chroma_Height);
 
-  sprintf(name,"%s.V",outname);
+  my_sprintf(name,"%s.V",outname);
   err += Read_Component(name, frame[2], Chroma_Width, Chroma_Height);
 
   return(err);
@@ -251,21 +248,21 @@ int Height;
   Size = Width*Height;
 
 #ifdef DEBUG
-  printf("SUBS: reading %s\n", filename);
+  my_printf("SUBS: reading %s\n", filename);
 #endif
 
-  if(!(Infile=open(Filename,O_RDONLY|O_BINARY))<0)
+  if(!(Infile=my_open(Filename))<0)
   {
-    printf("ERROR: unable to open reference filename (%s)\n", Filename);
+    my_printf("ERROR: unable to open reference filename (%s)\n", Filename);
     return(-1);
   }
 
-  abort();
+  /*abort();*/
   Bytes_Read = read(Infile, Frame, Size);
   
   if(Bytes_Read!=Size)
   {
-    printf("was able to read only %d bytes of %d of file %s\n",
+    my_printf("was able to read only %d bytes of %d of file %s\n",
       Bytes_Read, Size, Filename);
   }
  
@@ -286,15 +283,16 @@ unsigned char *frame[3];
 int framenum;
 {
 /*  int err = 0; */
-  FILE *fd;
+  //FILE *fd;
+  ostream *fd;
   int line;
   int size, offset;
-  abort();
+  /*abort();*/
 
 
-  if (!(fd = fopen(filename,"rb")))
+  if (!(fd = my_fopen(filename,"rb")))
   {
-    sprintf(Error_Text,"Couldn't open %s\n",filename);
+    my_sprintf(Error_Text,"Couldn't open %s\n",filename);
     return(-1);
   }
 
@@ -308,42 +306,42 @@ int framenum;
   else if(chroma_format==CHROMA420)
     size = ((size*3)>>1);
   else
-    printf("ERROR: chroma_format (%d) not recognized\n", chroma_format);
+    my_printf("ERROR: chroma_format (%d) not recognized\n", chroma_format);
 
 
   /* compute distance into "big" file */
   offset = size*framenum;
 
 #ifdef DEBUG
-  printf("EXTRACTING: frame(%d) offset(%d), size (%d) from %s\n", 
+  my_printf("EXTRACTING: frame(%d) offset(%d), size (%d) from %s\n", 
     framenum, offset, size, filename);
 #endif
 
   /* seek to location in big file where desired frame begins */
   /* note: this offset cannot exceed a few billion bytes due to the */
   /*       obvious limitations of 32-bit integers */
-  fseek(fd, offset, SEEK_SET);
+  my_fseek(fd, offset, SEEK_SET);
 
   /* Y  */
   for (line=0; line<Coded_Picture_Height; line++)
   {
-    fread(frame[0]+(line*Coded_Picture_Width),1,Coded_Picture_Width,fd);
+    my_fread(frame[0]+(line*Coded_Picture_Width),1,Coded_Picture_Width,fd);
   }
 
   /* Cb */
   for (line=0; line<Chroma_Height; line++)
   {
-    fread(frame[1]+(line*Chroma_Width),1,Chroma_Width,fd);
+    my_fread(frame[1]+(line*Chroma_Width),1,Chroma_Width,fd);
   }
 
   /* Cr */
   for (line=0; line<Chroma_Height; line++)
   {
-    fread(frame[2]+(line*Chroma_Width),1,Chroma_Width,fd);
+    my_fread(frame[2]+(line*Chroma_Width),1,Chroma_Width,fd);
   }
 
 
-  fclose(fd);
+  my_fclose(fd);
   return(0);
 }
 
@@ -363,7 +361,7 @@ int field_mode;    /* 0 = frame, 1 = field                      */
   s = d = 0;
 
 #ifdef DEBUG
-  printf("COPYING (w=%d, h=%d, parity=%d, field_mode=%d)\n",
+  my_printf("COPYING (w=%d, h=%d, parity=%d, field_mode=%d)\n",
     width,height,parity,field_mode);
 #endif /* DEBUG */
 
index 0601014972465566658a926853dece716594818b..57598fee0d6ca9342eb18bb3451628128ba9e719 100644 (file)
@@ -27,9 +27,6 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #include "config.h"
 #include "global.h"
 
@@ -66,7 +63,7 @@ void Next_Packet()
         ld->Rdptr++;
         code=Get_Byte();  /* parse PES_header_data_length */
         ld->Rdptr+=code;    /* advance pointer by PES_header_data_length */
-        printf("MPEG-2 PES packet\n");
+        my_printf("MPEG-2 PES packet\n");
         return;
       }
       else if(code==0xff)
@@ -80,8 +77,8 @@ void Next_Packet()
       {
         if(code>=0x80)
         {
-          fprintf(stderr,"Error in packet header\n");
-          exit(1);
+          my_fprintf("Error in packet header\n");
+          my_exit(1);
         }
         /* skip STD_buffer_scale */
         ld->Rdptr++;
@@ -92,8 +89,8 @@ void Next_Packet()
       {
         if(code>=0x40)
         {
-          fprintf(stderr,"Error in packet header\n");
-          exit(1);
+          my_fprintf("Error in packet header\n");
+          my_exit(1);
         }
         /* skip presentation and decoding time stamps */
         ld->Rdptr += 9;
@@ -105,8 +102,8 @@ void Next_Packet()
       }
       else if(code!=0x0f)
       {
-        fprintf(stderr,"Error in packet header\n");
-        exit(1);
+        my_fprintf("Error in packet header\n");
+        my_exit(1);
       }
       return;
     case ISO_END_CODE: /* end */
@@ -131,8 +128,8 @@ void Next_Packet()
       }
       else
       {
-        fprintf(stderr,"Unexpected startcode %08x in system layer\n",code);
-        exit(1);
+        my_fprintf("Unexpected startcode %08x in system layer\n",code);
+        my_exit(1);
       }
       break;
     }