X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmRLE.cxx;h=bb993d4828e74053fb20b2daf926987fa4ab7aca;hb=48c3e6379fcb2517d56c15d51e45c4c79543c16c;hp=cc9fcaa1e226a57d8c10d6db9e35c707f6dbbde6;hpb=62fb255fdeaf8d3e64b90d4c63fc0fef263e0e08;p=gdcm.git diff --git a/src/gdcmRLE.cxx b/src/gdcmRLE.cxx index cc9fcaa1..bb993d48 100644 --- a/src/gdcmRLE.cxx +++ b/src/gdcmRLE.cxx @@ -1,41 +1,192 @@ + #include #include "gdcmFile.h" -#include "jpeg/libijg8/cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jpeg/libijg8/jversion.h" /* for version message */ #include /* to declare isprint() */ -/* Create the add-on message string table. */ - -#define JMESSAGE(code,string) string , - -static const char * const cdjpeg_message_table[] = { -#include "jpeg/libijg8/cderror.h" - NULL -}; - - /* -------------------------------------------------------------------- */ - // - // RLE LossLess Files - // - /* -------------------------------------------------------------------- */ - -int -gdcmFile::gdcm_read_RLE_file (void * image_buffer) { - - - - +#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 image_buffer destination Address (in caller's memory space) + * at which the pixel data should be copied + * + * @return int acts as a 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 + char * im = (char *)image_buffer; + + 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;i1) { + 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 + + im = (char *)image_buffer; + // need to make 16 Bits Pixels from Low Byte and Hight Byte 'Planes' + + int l = GetXSize()*GetYSize(); + int nbFrames = GetZSize(); + + char * newDest = (char*) malloc(l*nbFrames*2); + char *x = newDest; + char * a = (char *)image_buffer; + char * b = a + l; + + for (int i=0;i= 0 && count <= 127) { + fread(*areaToRead,(count+1)*sizeof(char),1,fp); + *areaToRead+=count+1; + numberOfOutputBytes+=count+1; + } else { + if (count <= -1 && count >= -127) { + fread(&car,sizeof(char),1,fp); + for(int i=0; i<-count+1; i++) { + (*areaToRead)[i]=car; + } + *areaToRead+=(-count+1); + numberOfOutputBytes+=(-count+1); + } + } + // if count = 128 output nothing (See : PS 3.5-2003 Page 86) + } + return 1; }