From f045e95a9d0b82e8c4bd687710bd4a15323fbf55 Mon Sep 17 00:00:00 2001 From: malaterre Date: Mon, 3 May 2004 03:30:39 +0000 Subject: [PATCH] Replace the DEBUG on the stack with a global entry in cmake interface: GDCM_DEBUG, so you can turn verbosity ON/OFF for debug statement. --- CMakeLists.txt | 1 + ChangeLog | 2 + gdcmConfigure.h.in | 2 +- src/gdcmDebug.h | 4 +- src/gdcmHeader.cxx | 215 +++++++++++++++++++++++---------------------- src/gdcmJpeg.cxx | 54 ++++++++---- src/gdcmJpeg12.cxx | 52 +++++++---- 7 files changed, 187 insertions(+), 143 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bf969e2..cd260e91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ MARK_AS_ADVANCED(GDCM_DATA_DIR) OPTION(BUILD_SHARED_LIBS "Build GDCM with shared libraries." ON) SET(GDCM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +OPTION(GDCM_DEBUG "Turn verbosity of some statement ON." OFF) #----------------------------------------------------------------------------- SET (EXECUTABLE_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.") diff --git a/ChangeLog b/ChangeLog index 813b1e90..38b881b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * Add a new test: ShowDicom, for now this is just the c++ version of checkRead.sh, later it will be able to compare the image read against a baseline. + * Replace the DEBUG on the stack with a global entry in cmake interface: + GDCM_DEBUG, so you can turn verbosity ON/OFF for debug statement. 2004-04-30 Mathieu Malaterre * Add an example subdir, with a real example on how to read + write a diff --git a/gdcmConfigure.h.in b/gdcmConfigure.h.in index 8d856d4b..08856ac9 100644 --- a/gdcmConfigure.h.in +++ b/gdcmConfigure.h.in @@ -8,4 +8,4 @@ #cmakedefine HAVE_NO_STDINT_H - +#cmakedefine GDCM_DEBUG diff --git a/src/gdcmDebug.h b/src/gdcmDebug.h index 886e2ec4..86a20022 100644 --- a/src/gdcmDebug.h +++ b/src/gdcmDebug.h @@ -3,8 +3,6 @@ #ifndef GDCMDEBUG_H #define GDCMDEBUG_H -#define GDCM_DEBUG -1 - /** * \ingroup gdcmDebug * \brief gdcmDebug is an object for debugging in program. @@ -18,7 +16,7 @@ */ class gdcmDebug { public: - gdcmDebug(int level = GDCM_DEBUG); + gdcmDebug(int level = -1); void SetDebug (int level); void Verbose(int, const char*, const char* =""); diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index bc3b906a..f0f68468 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,16 +1,13 @@ // gdcmHeader.cxx //----------------------------------------------------------------------------- -#include -#include -#include // for isalpha -#include - #include "gdcmHeader.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" #include "gdcmDebug.h" #include "gdcmTS.h" +#include + //----------------------------------------------------------------------------- // Constructor / Destructor /** @@ -46,25 +43,25 @@ gdcmHeader::gdcmHeader(const char *InFilename, // This IS the right place for the code - std::string ImageLocation = GetEntryByNumber(0x0028, 0x0200); - if ( ImageLocation == GDCM_UNFOUND ) { // Image Location - GrPixel = 0x7fe0; // default value - } else { - GrPixel = (guint16) atoi( ImageLocation.c_str() ); - } - if (GrPixel == 0xe07f) // sometimes Image Location value doesn't follow - GrPixel = 0x7fe0; // the supposed processor endianity. - // see gdcmData/cr172241.dcm - if (GrPixel != 0x7fe0) - // This is a kludge for old dirty Philips imager. - NumPixel = 0x1010; - else - NumPixel = 0x0010; + std::string ImageLocation = GetEntryByNumber(0x0028, 0x0200); + if ( ImageLocation == GDCM_UNFOUND ) { // Image Location + GrPixel = 0x7fe0; // default value + } else { + GrPixel = (guint16) atoi( ImageLocation.c_str() ); + } + if (GrPixel == 0xe07f) // sometimes Image Location value doesn't follow + GrPixel = 0x7fe0; // the supposed processor endianity. + // see gdcmData/cr172241.dcm + if (GrPixel != 0x7fe0) + // This is a kludge for old dirty Philips imager. + NumPixel = 0x1010; + else + NumPixel = 0x0010; - TagKey key = gdcmDictEntry::TranslateToKey(GrPixel, NumPixel); - countGrPixel = GetEntry().count(key); + TagKey key = gdcmDictEntry::TranslateToKey(GrPixel, NumPixel); + countGrPixel = GetEntry().count(key); - // we set the SQ Depth of each Header Entry + // we set the SQ Depth of each Header Entry int top =-1; int countSQ = 0; @@ -75,97 +72,104 @@ gdcmHeader::gdcmHeader(const char *InFilename, std::ostringstream tab; tab << " "; - int DEBUG = 0; // Sorry; Dealing with e-film breaker images - // will (certainly) cause a lot of troubles ... - // I prefer keeping my 'trace' on . + // GDCM_DEBUG + // Sorry; Dealing with e-film breaker images + // will (certainly) cause a lot of troubles ... + // I prefer keeping my 'trace' on . for (ListTag::iterator i = listEntries.begin(); - i != listEntries.end(); - ++i) { - (*i)->SetSQDepthLevel(countSQ); - if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength() != 0) { // SQ found - countSQ++; - top ++; - if ( top >= 20) { + i != listEntries.end(); + ++i) { + (*i)->SetSQDepthLevel(countSQ); + if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength() != 0) { // SQ found + countSQ++; + top ++; + if ( top >= 20) { +#ifdef GDCM_DEBUG std::cout << "Kaie ! Kaie! SQ Stack Overflow" << std::endl; - return; +#endif //GDCM_DEBUG + return; } - if (DEBUG) std::cout << "\n >>>>> empile niveau " << top - << "; Lgr SeQ: " << (*i)->GetReadLength() - << "\n" <GetReadLength(); - pile[top].alreadyParsedlength = 0; - currentParsedlength = 0; - - } else { // non SQ found - - if (countSQ != 0) { // we are 'inside a SeQuence' - if ( (*i)->GetGroup()==0xfffe && (*i)->GetElement()==0xe0dd){ - // we just found 'end of SeQuence' - - if (DEBUG) - std::cout << "fffe,e0dd : depile" << std::endl; +#ifdef GDCM_DEBUG + std::cout << "\n >>>>> empile niveau " << top + << "; Lgr SeQ: " << (*i)->GetReadLength() + << "\n" <GetReadLength(); + pile[top].alreadyParsedlength = 0; + currentParsedlength = 0; + + } else { // non SQ found + if (countSQ != 0) { // we are 'inside a SeQuence' + if ( (*i)->GetGroup()==0xfffe && (*i)->GetElement()==0xe0dd) { + // we just found 'end of SeQuence' + +#ifdef GDCM_DEBUG + std::cout << "fffe,e0dd : depile" << std::endl; +#endif //GDCM_DEBUG + currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2 - countSQ --; + countSQ --; top --; pile[top].alreadyParsedlength += currentParsedlength; } else { - // we are on a 'standard' elem - // or a Zero-length SeQuence - - totalElementlength = (*i)->GetFullLength(); - currentParsedlength += totalElementlength; + // we are on a 'standard' elem + // or a Zero-length SeQuence + + totalElementlength = (*i)->GetFullLength(); + currentParsedlength += totalElementlength; pile[top].alreadyParsedlength += totalElementlength; - + if (pile[top].totalSQlength == 0xffffffff) { - if (DEBUG) - std::cout << "totalSeQlength == 0xffffffff" - << std::endl; +#ifdef GDCM_DEBUG + std::cout << "totalSeQlength == 0xffffffff" << std::endl; +#endif //GDCM_DEBUG } else { - if (DEBUG) - std::cout << "alrdyPseLgt:" - << pile[top].alreadyParsedlength << " totSeQlgt: " - << pile[top].totalSQlength << " curPseLgt: " - << currentParsedlength - << std::endl; +#ifdef GDCM_DEBUG + std::cout << "alrdyPseLgt:" + << pile[top].alreadyParsedlength << " totSeQlgt: " + << pile[top].totalSQlength << " curPseLgt: " + << currentParsedlength + << std::endl; +#endif //GDCM_DEBUG while (pile[top].alreadyParsedlength==pile[top].totalSQlength) { - - if (DEBUG) - std::cout << " \n<<<<<< On depile niveau " << top - << " \n" << std::endl; - (*i)->SetSQDepthLevel(countSQ); - currentParsedlength = pile[top].alreadyParsedlength; - countSQ --; - top --; - if (top >=0) { - - pile[top].alreadyParsedlength += currentParsedlength +12; - // 12 : length of 'SQ embedded' SQ element - currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2 - - if (DEBUG) - std::cout << pile[top].alreadyParsedlength << " " - << pile[top].totalSQlength << " " - << currentParsedlength - << std::endl; - } - if (top == -1) { - currentParsedlength = 0; - break; - } +#ifdef GDCM_DEBUG + std::cout << " \n<<<<<< On depile niveau " << top + << " \n" << std::endl; +#endif //GDCM_DEBUG + (*i)->SetSQDepthLevel(countSQ); + currentParsedlength = pile[top].alreadyParsedlength; + countSQ --; + top --; + if (top >=0) { + pile[top].alreadyParsedlength += currentParsedlength +12; + // 12 : length of 'SQ embedded' SQ element + currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2 + +#ifdef GDCM_DEBUG + std::cout << pile[top].alreadyParsedlength << " " + << pile[top].totalSQlength << " " + << currentParsedlength + << std::endl; +#endif //GDCM_DEBUG } - } - } - } // end : 'inside a SeQuence' - } - if (DEBUG) { - for (int k=0; k<(*i)->GetSQDepthLevel();k++) { - std::cout << tab; - } - (*i)->SetPrintLevel(2); - (*i)->Print(); - } + if (top == -1) { + currentParsedlength = 0; + break; + } + } + } + } + } // end : 'inside a SeQuence' + } +#ifdef GDCM_DEBUG + for (int k=0; k<(*i)->GetSQDepthLevel();k++) { + std::cout << tab; + } + (*i)->SetPrintLevel(2); + (*i)->Print(); +#endif //GDCM_DEBUG } // end for } @@ -620,9 +624,11 @@ size_t gdcmHeader::GetPixelOffset(void) { if (PixelElement) { return PixelElement->GetOffset(); } else { -/* std::cout << "Big trouble : Pixel Element (" +#ifdef GDCM_DEBUG + std::cout << "Big trouble : Pixel Element (" << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" - << std::endl; */ + << std::endl; +#endif //GDCM_DEBUG return 0; } } @@ -649,10 +655,11 @@ size_t gdcmHeader::GetPixelAreaLength(void) { if (PixelElement) { return PixelElement->GetLength(); } else { -/* std::cout << "Big trouble : Pixel Element (" +#ifdef GDCM_DEBUG + std::cout << "Big trouble : Pixel Element (" << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" << std::endl; -*/ +#endif //GDCM_DEBUG return 0; } } diff --git a/src/gdcmJpeg.cxx b/src/gdcmJpeg.cxx index c2b93070..640522d9 100644 --- a/src/gdcmJpeg.cxx +++ b/src/gdcmJpeg.cxx @@ -5,8 +5,6 @@ #define BITS_IN_JSAMPLE 8 -#define DEBUG 0 - /* DICOM provides a mechanism for supporting the use of JPEG Image Compression through the Encapsulated Format (see PS 3.3 of the DICOM Standard). @@ -191,7 +189,9 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { int row_stride; /* physical row width in output buffer */ - if (DEBUG) printf("entree dans gdcmFile::gdcm_read_JPEG_file12, depuis gdcmJpeg\n"); +#ifdef GDCM_DEBUG + printf("entree dans gdcmFile::gdcm_read_JPEG_file12, depuis gdcmJpeg\n"); +#endif //GDCM_DEBUG /* In this example we want to open the input file before doing anything else, * so that the setjmp() error recovery below can assume the file is open. @@ -200,7 +200,9 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { */ /* Step 1: allocate and initialize JPEG decompression object */ - if (DEBUG)printf("Entree Step 1\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 1\n"); +#endif //GDCM_DEBUG /* We set up the normal JPEG error routines, then override error_exit. */ @@ -219,12 +221,16 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { jpeg_create_decompress(&cinfo); /* Step 2: specify data source (eg, a file) */ - if (DEBUG) printf("Entree Step 2\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 2\n"); +#endif //GDCM_DEBUG jpeg_stdio_src(&cinfo, fp); /* Step 3: read file parameters with jpeg_read_header() */ - if (DEBUG) printf("Entree Step 3\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 3\n"); +#endif //GDCM_DEBUG (void) jpeg_read_header(&cinfo, TRUE); @@ -234,7 +240,7 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { * See libjpeg.doc for more info. */ - if (DEBUG) { +#ifdef GDCM_DEBUG printf("--------------Header contents :----------------\n"); printf("image_width %d image_height %d\n", cinfo.image_width , cinfo.image_height); @@ -242,7 +248,7 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { cinfo.output_components); printf("nb of color components returned %d \n", cinfo.data_precision); - } +#endif //GDCM_DEBUG /* @@ -255,13 +261,17 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { */ /* Step 4: set parameters for decompression */ - if (DEBUG) printf("Entree Step 4\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 4\n"); +#endif //GDCM_DEBUG /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ - if (DEBUG) printf("Entree Step 5\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 5\n"); +#endif GDCM_DEBUG (void) jpeg_start_decompress(&cinfo); /* We can ignore the return value since suspension is not possible @@ -278,25 +288,28 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { /* JSAMPLEs per row in output buffer */ row_stride = cinfo.output_width * cinfo.output_components; - if (DEBUG) printf ("cinfo.output_width %d cinfo.output_components %d row_stride %d\n", +#ifdef GDCM_DEBUG + printf ("cinfo.output_width %d cinfo.output_components %d row_stride %d\n", cinfo.output_width, cinfo.output_components,row_stride); - +#endif //GDCM_DEBUG + /* Make a one-row-high sample array that will go away when done with image */ buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); /* Step 6: while (scan lines remain to be read) */ - if (DEBUG) printf("Entree Step 6\n"); - +#ifdef GDCM_DEBUG + printf("Entree Step 6\n"); +#endif //GDCM_DEBUG /* jpeg_read_scanlines(...); */ /* Here we use the library's state variable cinfo.output_scanline as the * loop counter, so that we don't have to keep track ourselves. */ - if (DEBUG) +#ifdef GDCM_DEBUG printf ("cinfo.output_height %d cinfo.output_width %d\n", cinfo.output_height,cinfo.output_width); - +#endif //GDCM_DEBUG pimage=(char *)image_buffer; while (cinfo.output_scanline < cinfo.output_height) { @@ -323,7 +336,10 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { } /* Step 7: Finish decompression */ - if (DEBUG) printf("Entree Step 7\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 7\n"); +#endif //GDCM_DEBUG + (void) jpeg_finish_decompress(&cinfo); /* We can ignore the return value since suspension is not possible @@ -332,7 +348,9 @@ bool gdcmFile::gdcm_read_JPEG_file (FILE *fp,void * image_buffer) { /* Step 8: Release JPEG decompression object */ - if (DEBUG) printf("Entree Step 8\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 8\n"); +#endif //GDCM_DEBUG /* This is an important step since it will release a good deal of memory. */ diff --git a/src/gdcmJpeg12.cxx b/src/gdcmJpeg12.cxx index e8b0b8b0..6b84a957 100644 --- a/src/gdcmJpeg12.cxx +++ b/src/gdcmJpeg12.cxx @@ -5,8 +5,6 @@ #define BITS_IN_JSAMPLE 12 -#define DEBUG 0 - // BITS_IN_JSAMPLE is a compile time defined options. // We need both 8 an 12; // To avoid renaming *all* the Jpeg functions, @@ -203,8 +201,9 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { // typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ int row_stride; /* physical row width in output buffer */ - - if (DEBUG) printf("entree dans gdcmFile::gdcm_read_JPEG_file12, depuis gdcmJpeg\n"); +#ifdef GDCM_DEBUG + printf("entree dans gdcmFile::gdcm_read_JPEG_file12, depuis gdcmJpeg\n"); +#endif //GDCM_DEBUG /* In this example we want to open the input file before doing anything else, * so that the setjmp() error recovery below can assume the file is open. @@ -213,7 +212,9 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { */ /* Step 1: allocate and initialize JPEG decompression object */ - if (DEBUG)printf("Entree Step 1\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 1\n"); +#endif //GDCM_DEBUG /* We set up the normal JPEG error routines, then override error_exit. */ @@ -233,11 +234,15 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { jpeg_create_decompress(&cinfo); /* Step 2: specify data source (eg, a file) */ - if (DEBUG) printf("Entree Step 2\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 2\n"); +#endif //GDCM_DEBUG jpeg_stdio_src(&cinfo, fp); /* Step 3: read file parameters with jpeg_read_header() */ - if (DEBUG) printf("Entree Step 3\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 3\n"); +#endif //GDCM_DEBUG (void) jpeg_read_header(&cinfo, TRUE); /* We can ignore the return value from jpeg_read_header since @@ -246,7 +251,7 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { * See libjpeg.doc for more info. */ - if (DEBUG) { +#ifdef GDCM_DEBUG printf("--------------Header contents :----------------\n"); printf("image_width %d image_height %d\n", cinfo.image_width , cinfo.image_height); @@ -254,7 +259,7 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { cinfo.output_components); printf("nb of color components returned %d \n", cinfo.data_precision); - } +#endif //GDCM_DEBUG /* @@ -267,14 +272,18 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { */ /* Step 4: set parameters for decompression */ - if (DEBUG) printf("Entree Step 4\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 4\n"); +#endif //GDCM_DEBUG /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ - if (DEBUG) printf("Entree Step 5\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 5\n"); +#endif //GDCM_DEBUG (void) jpeg_start_decompress(&cinfo); /* We can ignore the return value since suspension is not possible @@ -291,16 +300,19 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { /* JSAMPLEs per row in output buffer */ row_stride = cinfo.output_width * cinfo.output_components; - if (DEBUG) +#ifdef GDCM_DEBUG printf ("cinfo.output_width %d cinfo.output_components %d row_stride %d\n", cinfo.output_width, cinfo.output_components,row_stride); - +#endif //GDCM_DEBUG + /* Make a one-row-high sample array that will go away when done with image */ buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); /* Step 6: while (scan lines remain to be read) */ - if (DEBUG) printf("Entree Step 6\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 6\n"); +#endif //GDCM_DEBUG /* jpeg_read_scanlines(...); */ @@ -308,8 +320,10 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { * loop counter, so that we don't have to keep track ourselves. */ - if (DEBUG) printf ("cinfo.output_height %d cinfo.output_width %d\n", +#ifdef GDCM_DEBUG + printf ("cinfo.output_height %d cinfo.output_width %d\n", cinfo.output_height,cinfo.output_width); +#endif //GDCM_DEBUG pimage=(char *)image_buffer; @@ -331,14 +345,18 @@ bool gdcmFile::gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer) { } /* Step 7: Finish decompression */ - if (DEBUG) printf("Entree Step 7\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 7\n"); +#endif //GDCM_DEBUG (void) jpeg_finish_decompress(&cinfo); /* We can ignore the return value since suspension is not possible * with the stdio data source. */ /* Step 8: Release JPEG decompression object */ - if (DEBUG) printf("Entree Step 8\n"); +#ifdef GDCM_DEBUG + printf("Entree Step 8\n"); +#endif //GDCM_DEBUG /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_decompress(&cinfo); -- 2.45.1