X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmRLE.cxx;h=ae9149c3a5ca643c186ab09fdfe2b71cdca04e12;hb=a18a9f20d96301e1c91be637415599e5fdc1ca43;hp=3a0f2ed0ab2581cd496dac496ce2ff783be8304a;hpb=412e45113080662e115ad6a5771ae607fab2e7ea;p=gdcm.git diff --git a/src/gdcmRLE.cxx b/src/gdcmRLE.cxx index 3a0f2ed0..ae9149c3 100644 --- a/src/gdcmRLE.cxx +++ b/src/gdcmRLE.cxx @@ -1,12 +1,3 @@ -//This is needed when compiling in debug mode -#ifdef _MSC_VER -// 'identifier' : class 'type' needs to have dll-interface to be used by -// clients of class 'type2' -#pragma warning ( disable : 4251 ) -// 'identifier' : identifier was truncated to 'number' characters in the -// debug information -#pragma warning ( disable : 4786 ) -#endif //_MSC_VER #include #include "gdcmFile.h" @@ -20,6 +11,9 @@ static int _gdcm_read_RLE_fragment (char ** image_buffer, FILE* fp); // static because nothing but gdcm_read_RLE_file may call it +#define DEBUG 0 +// Will be removed + // ---------------------------------------------------------------------------- /** * \ingroup gdcmFile @@ -36,8 +30,9 @@ static int _gdcm_read_RLE_fragment (char ** image_buffer, int gdcmFile::gdcm_read_RLE_file (void * image_buffer) { + long fragmentBegining; // for ftell, fseek char * im = (char *)image_buffer; - std::cout << "RLE image" << std::endl; + if (DEBUG)std::cout << "RLE image" << std::endl; long RleSegmentLength[15],fragmentLength,uncompressedSegmentSize;; long ftellRes, ln; @@ -45,7 +40,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { guint32 RleSegmentOffsetTable[15]; guint16 ItemTagGr,ItemTagEl; uncompressedSegmentSize=GetXSize()*GetYSize(); - printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize); + if (DEBUG)printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize); ftellRes=ftell(fp); // Basic Offset Table with Item Value // Item Tag @@ -55,14 +50,14 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { ItemTagGr=SwapShort(ItemTagGr); ItemTagEl=SwapShort(ItemTagEl); } - printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", + if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", ftellRes,ItemTagGr,ItemTagEl ); // Item Length ftellRes=ftell(fp); fread(&ln,4,1,fp); if(GetSwapCode()) ln=SwapLong(ln); // Basic Offset Table Item Lentgh - printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", + if (DEBUG)printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", ftellRes,ln,ln); if (ln != 0) { // What is it used for ?? @@ -71,7 +66,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { guint32 a; for (int i=0;i1) { - for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments - RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - k,RleSegmentLength[k], ftellRes); - _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp); - //fseek(fp,RleSegmentLength[k],SEEK_CUR); - - } - } - RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments]; // + 4; - // 4 : bytes for number of RLE Segments (WHY ???); - // TODO : Check the value - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes); - _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp); - //fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); - - - // end of scanning fragment pixels + if (nbRleSegments>1) { + for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments + RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; + ftellRes=ftell(fp); + if (DEBUG)printf (" (in) Segment %d : Length = %d x(%x) Start at %x\n", + k,RleSegmentLength[k],RleSegmentLength[k], ftellRes); + fragmentBegining=ftell(fp); + _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp); + fseek(fp,fragmentBegining,SEEK_SET); + fseek(fp,RleSegmentLength[k],SEEK_CUR); + } + } + RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments]; + ftellRes=ftell(fp); + if (DEBUG)printf (" (out)Segment %d : Length = %d x(%x) Start at %x\n", + nbRleSegments, + RleSegmentLength[nbRleSegments],RleSegmentLength[nbRleSegments], + ftellRes); + fragmentBegining=ftell(fp); + _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp); + fseek(fp,fragmentBegining,SEEK_SET); + fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); + + // end of scanning fragment pixels ftellRes=ftell(fp); fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr @@ -141,7 +138,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { ItemTagGr=SwapShort(ItemTagGr); ItemTagEl=SwapShort(ItemTagEl); } - printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", + if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", ftellRes,ItemTagGr,ItemTagEl ); } return (1); @@ -167,14 +164,12 @@ _gdcm_read_RLE_fragment (char ** areaToRead, long numberOfOutputBytes=0; char n, car; ftellRes =ftell(fp); - printf ("Fragment begin : %x lengthToDecode %d\n",ftellRes,lengthToDecode); while(numberOfOutputBytes= 0 && count <= 127) { fread(*areaToRead,(count+1)*sizeof(char),1,fp); *areaToRead+=count+1;