X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmRLE.cxx;h=fd2cf2b3151643fe5a553f0899d0da82ce6ea193;hb=5bf4ff55cc9887da061970902eb1effe24ede1b7;hp=bb993d4828e74053fb20b2daf926987fa4ab7aca;hpb=33413fc6fb41f4fd7efbce32083f943f252e8b6f;p=gdcm.git diff --git a/src/gdcmRLE.cxx b/src/gdcmRLE.cxx index bb993d48..fd2cf2b3 100644 --- a/src/gdcmRLE.cxx +++ b/src/gdcmRLE.cxx @@ -1,134 +1,66 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmRLE.cxx,v $ + Language: C++ + Date: $Date: 2004/10/06 22:31:31 $ + Version: $Revision: 1.24 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ #include #include "gdcmFile.h" -#include /* to declare isprint() */ +#include // For isprint() #define str2num(str, typeNum) *((typeNum *)(str)) -static int _gdcm_read_RLE_fragment (char ** image_buffer, - long lengthToDecode, - long uncompressedSegmentSize, - FILE* fp); -// static because nothing but gdcm_read_RLE_file may call it - -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- /** * \ingroup gdcmFile * \brief Reads a 'Run Length Encoded' Dicom encapsulated file + * @param fp already open File Pointer * @param image_buffer destination Address (in caller's memory space) - * at which the pixel data should be copied - * - * @return int acts as a Boolean + * at which the pixel data should be copied + * @return Boolean */ - -// This is a debug version. -// Forget the printf as they will be removed -// as soon as the last Heuristics are checked - -// pb with RLE 16 Bits : - - -int -gdcmFile::gdcm_read_RLE_file (void * image_buffer) { - long fragmentBegining; // for ftell, fseek +bool gdcmFile::gdcm_read_RLE_file (FILE* fp,void* image_buffer) { char * im = (char *)image_buffer; + long uncompressedSegmentSize = Header->GetXSize() * Header->GetYSize(); + - long RleSegmentLength[15],fragmentLength,uncompressedSegmentSize;; - long ftellRes, ln; - guint32 nbRleSegments; - guint32 RleSegmentOffsetTable[15]; - guint16 ItemTagGr,ItemTagEl; - uncompressedSegmentSize=GetXSize()*GetYSize(); - ftellRes=ftell(fp); - // Basic Offset Table with Item Value - // Item Tag - fread(&ItemTagGr,2,1,fp); // Reading (fffe):Basic Offset Table Item Tag Gr - fread(&ItemTagEl,2,1,fp); // Reading (e000):Basic Offset Table Item Tag El - if(GetSwapCode()) { - ItemTagGr=SwapShort(ItemTagGr); - ItemTagEl=SwapShort(ItemTagEl); - } - // Item Length - ftellRes=ftell(fp); - fread(&ln,4,1,fp); - if(GetSwapCode()) - ln=SwapLong(ln); // Basic Offset Table Item Lentgh - if (ln != 0) { - // What is it used for ?? - char * BasicOffsetTableItemValue= (char *)malloc(ln+1); - fread(BasicOffsetTableItemValue,ln,1,fp); - guint32 a; - for (int i=0;iRLEInfo.Frames.begin(); + it != Header->RLEInfo.Frames.end(); + ++it ) + { + std::cout << "...new frame...\n "; + // Loop on the fragments + for( unsigned int k = 1; k <= (*it)->NumberFragments; k++ ) + { + fseek( fp, (*it)->Offset[k] ,SEEK_SET); + gdcm_read_RLE_fragment( &im, (*it)->Length[k], + uncompressedSegmentSize, fp ); } + } - if (nbRleSegments>1) { - for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments - RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; - ftellRes=ftell(fp); - 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); - 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 - fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El - if(GetSwapCode()) { - ItemTagGr=SwapShort(ItemTagGr); - ItemTagEl=SwapShort(ItemTagEl); - } - } - - if (GetBitsAllocated()==16) { // try to deal with RLE 16 Bits + if (Header->GetBitsAllocated()==16) { // try to deal with RLE 16 Bits im = (char *)image_buffer; // need to make 16 Bits Pixels from Low Byte and Hight Byte 'Planes' - int l = GetXSize()*GetYSize(); - int nbFrames = GetZSize(); + int l = Header->GetXSize()*Header->GetYSize(); + int nbFrames = Header->GetZSize(); - char * newDest = (char*) malloc(l*nbFrames*2); + char * newDest = new char[l*nbFrames*2]; char *x = newDest; char * a = (char *)image_buffer; char * b = a + l; @@ -139,37 +71,25 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { *(x++) = *(b++); } } - memmove(image_buffer,newDest,lgrTotale); - free(newDest); + memmove(image_buffer,newDest,ImageDataSize); + delete[] newDest; } - return (1); + return true; } - /* -------------------------------------------------------------------- */ - // - // RLE LossLess Fragment - // - /* -------------------------------------------------------------------- */ - - // static because nothing but gdcm_read_RLE_file can call it - // DO NOT doxygen ! - -static int -_gdcm_read_RLE_fragment (char ** areaToRead, - long lengthToDecode, - long uncompressedSegmentSize, - FILE* fp) { - long ftellRes; +// ---------------------------------------------------------------------------- +// RLE LossLess Fragment +int gdcmFile::gdcm_read_RLE_fragment(char** areaToRead, long lengthToDecode, + long uncompressedSegmentSize, FILE* fp) { + (void)lengthToDecode; //FIXME int count; long numberOfOutputBytes=0; char n, car; - ftellRes =ftell(fp); - while(numberOfOutputBytes= 0 && count <= 127) { @@ -190,3 +110,5 @@ _gdcm_read_RLE_fragment (char ** areaToRead, } return 1; } + +// ----------------------------------------------------------------------------