From 39d002e137415b6cd47d928c7b2b14275cd5bcd0 Mon Sep 17 00:00:00 2001 From: malaterre Date: Sat, 21 May 2005 20:03:48 +0000 Subject: [PATCH] ENH: Trying to OO this C code something close to the ijg approach --- src/gdcmMpeg.cxx | 5 +-- src/gdcmmpeg2/src/mpeg2dec/getbits.c | 6 ++-- src/gdcmmpeg2/src/mpeg2dec/global.h | 8 +++++ src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c | 46 +++++++++++++++++++++++---- src/gdcmmpeg2/src/mpeg2dec/subspic.c | 2 ++ 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/gdcmMpeg.cxx b/src/gdcmMpeg.cxx index 52183719..c684cd92 100644 --- a/src/gdcmMpeg.cxx +++ b/src/gdcmMpeg.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmMpeg.cxx,v $ Language: C++ - Date: $Date: 2005/05/21 18:43:52 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/05/21 20:03:48 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -306,6 +306,7 @@ namespace gdcm * @param statesuspension Suspension State basically it should be 3 otherwise more complex to handle * @return 1 on success, 0 on error */ + bool ReadMPEGFile (std::ifstream *fp, void *image_buffer) { int ret, code; diff --git a/src/gdcmmpeg2/src/mpeg2dec/getbits.c b/src/gdcmmpeg2/src/mpeg2dec/getbits.c index 9b9b593c..0de7e5fc 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/getbits.c +++ b/src/gdcmmpeg2/src/mpeg2dec/getbits.c @@ -63,7 +63,8 @@ void Fill_Buffer() { int Buffer_Level; - Buffer_Level = read(ld->Infile,ld->Rdbfr,2048); + //Buffer_Level = read(ld->Infile,ld->Rdbfr,2048); + Buffer_Level = ld->read_stream(ld->Infile,ld->Rdbfr,2048); ld->Rdptr = ld->Rdbfr; if (System_Stream_Flag) @@ -99,7 +100,8 @@ int Get_Byte() { while(ld->Rdptr >= ld->Rdbfr+2048) { - read(ld->Infile,ld->Rdbfr,2048); + //read(ld->Infile,ld->Rdbfr,2048); + ld->read_stream(ld->Infile,ld->Rdbfr,2048); ld->Rdptr -= 2048; ld->Rdmax -= 2048; } diff --git a/src/gdcmmpeg2/src/mpeg2dec/global.h b/src/gdcmmpeg2/src/mpeg2dec/global.h index a8cc422a..8f2e798d 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/global.h +++ b/src/gdcmmpeg2/src/mpeg2dec/global.h @@ -417,10 +417,18 @@ EXTERN int broken_link; +//FIXME +#include +#include + /* layer specific variables (needed for SNR and DP scalability) */ EXTERN struct layer_data { /* bit input */ int Infile; + int (*open_stream) (char *filename); + off_t (*seek_stream) (int infile, off_t offset,int whence); + ssize_t (*read_stream) (int infile, void *buf, size_t count); + int (*close_stream) (int infile); unsigned char Rdbfr[2048]; unsigned char *Rdptr; unsigned char Inbfr[16]; diff --git a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c index 209013d6..ea7d5516 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c +++ b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c @@ -39,7 +39,7 @@ /* private prototypes */ static int video_sequence _ANSI_ARGS_((int *framenum)); -static int Decode_Bitstream _ANSI_ARGS_((void)); +static int Decode_Bitstream _ANSI_ARGS_((void)); static int Headers _ANSI_ARGS_((void)); static void Initialize_Sequence _ANSI_ARGS_((void)); static void Initialize_Decoder _ANSI_ARGS_((void)); @@ -58,11 +58,34 @@ static void Clear_Options(); static void Print_Options(); #endif +int my_open(char *filename) +{ + return open(filename,O_RDONLY|O_BINARY); +} +off_t my_seek(int infile, off_t offset,int whence) +{ + return lseek(infile, offset, whence); +} +ssize_t my_read(int infile,void *buf,size_t count) +{ + return read(infile,buf,count); +} +int my_close(int infile) +{ + return close(infile); +} + + + int main(argc,argv) int argc; char *argv[]; { int ret, code; + base.open_stream = my_open; + base.seek_stream = my_seek; + base.read_stream = my_read; + base.close_stream = my_close; Clear_Options(); @@ -77,7 +100,9 @@ char *argv[]; /* open MPEG base layer bitstream file(s) */ /* NOTE: this is either a base layer stream or a spatial enhancement stream */ - if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) +// if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) + base.Infile = ld->open_stream(Main_Bitstream_Filename); + if( base.Infile < 0 ) { fprintf(stderr,"Base layer input file %s not found\n", Main_Bitstream_Filename); exit(1); @@ -112,13 +137,15 @@ char *argv[]; break; } - lseek(base.Infile, 0l, SEEK_SET); + //lseek(base.Infile, 0l, SEEK_SET); + ld->seek_stream(base.Infile,0l,SEEK_SET); Initialize_Buffer(); } if(base.Infile!=0) { - lseek(base.Infile, 0l, SEEK_SET); + //lseek(base.Infile, 0l, SEEK_SET); + ld->seek_stream(base.Infile,0l,SEEK_SET); } Initialize_Buffer(); @@ -127,7 +154,9 @@ char *argv[]; { ld = &enhan; /* select enhancement layer context */ - if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0) + //if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0) + enhan.Infile = ld->open_stream(Enhancement_Layer_Bitstream_Filename); + if (enhan.Infile<0) { sprintf(Error_Text,"enhancment layer bitstream file %s not found\n", Enhancement_Layer_Bitstream_Filename); @@ -143,10 +172,12 @@ char *argv[]; ret = Decode_Bitstream(); - close(base.Infile); + //close(base.Infile); + ld->close_stream(base.Infile); if (Two_Streams) - close(enhan.Infile); + //close(enhan.Infile); + ld->close_stream(enhan.Infile); return ret; } @@ -763,3 +794,4 @@ static void Print_Options() } #endif + diff --git a/src/gdcmmpeg2/src/mpeg2dec/subspic.c b/src/gdcmmpeg2/src/mpeg2dec/subspic.c index fbe238b6..30ae35e9 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/subspic.c +++ b/src/gdcmmpeg2/src/mpeg2dec/subspic.c @@ -260,6 +260,7 @@ int Height; return(-1); } + abort(); Bytes_Read = read(Infile, Frame, Size); if(Bytes_Read!=Size) @@ -288,6 +289,7 @@ int framenum; FILE *fd; int line; int size, offset; + abort(); if (!(fd = fopen(filename,"rb"))) -- 2.46.1