X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=2b09d36d2aadcc76671dde736a5fadac633d794f;hb=0fa193d8b312b90f2ee822e1ee87f6e2fbd1dcb5;hp=c103e111bfe3711ef8e087351dd9e4e4507d0e1d;hpb=4a0c2407ec81e041c2e43781acec4c78c83fc487;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index c103e111..2b09d36d 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,6 +3,7 @@ #include "gdcmFile.h" #include "gdcmUtil.h" #include "iddcmjpeg.h" +using namespace std; ///////////////////////////////////////////////////////////////// /** @@ -34,8 +35,6 @@ gdcmFile::gdcmFile(const char * filename) SetPixelDataSizeFromHeader(); } - -///////////////////////////////////////////////////////////////// /** * \ingroup gdcmFile * \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les @@ -46,7 +45,6 @@ gdcmFile::gdcmFile(const char * filename) * * @return longueur a allouer */ - void gdcmFile::SetPixelDataSizeFromHeader(void) { int nb; string str_nb; @@ -63,13 +61,14 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { /** * \ingroup gdcmFile - * \brief Accessor + * \brief Returns the size (in bytes) of required memory to hold + * the pixel data represented in this file. + * @return The size of pixel data in bytes. */ size_t gdcmFile::GetImageDataSize(void) { return (lgrTotale); } - /** * \ingroup gdcmFile * \brief Read pixel data from disk (optionaly decompressing) into the @@ -80,29 +79,66 @@ size_t gdcmFile::GetImageDataSize(void) { bool gdcmFile::ReadPixelData(void* destination) { if ( !OpenFile()) return false; - if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { + + if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { CloseFile(); return false; - } - if (IsJPEGLossless()) { - destination = _IdDcmJpegRead(fp); - } else { + } + + if ( !IsDicomV3() || + IsImplicitVRLittleEndianTransferSyntax() || + IsExplicitVRLittleEndianTransferSyntax() || + IsExplicitVRBigEndianTransferSyntax() || + IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { + size_t ItemRead = fread(destination, lgrTotale, 1, fp); if ( ItemRead != 1 ) { CloseFile(); return false; + } else { + CloseFile(); + return true; } } - CloseFile(); - return true; + + if (IsJPEGLossless()) { + int ln; + fseek(fp,4,SEEK_CUR); + fread(&ln,4,1,fp); + if(GetSwapCode()) + ln=SwapLong(ln); + //if (DEBUG) + printf ("ln %d\n",ln); + fseek(fp,ln,SEEK_CUR); + fseek(fp,4,SEEK_CUR); + fread(&ln,4,1,fp); + if(GetSwapCode()) + ln=SwapLong(ln); + //if (DEBUG) + printf ("ln image comprimée %d\n",ln); + + ClbJpeg* jpg = _IdDcmJpegRead(fp); + if(jpg == NULL) { + CloseFile(); + return false; + } + memcpy(destination,jpg->DataImg,lgrTotale); + _IdDcmJpegFree (jpg); + CloseFile(); + return true; + } + + printf ("Sorry, TransfertSyntax not yet taken into account ...\n"); + CloseFile(); + return false; + } -///////////////////////////////////////////////////////////////// /** * \ingroup gdcmFile * \brief Allocates necessary memory, copies the pixel data - * (image[s]/volume[s]) to newly allocated zone and return a - * pointer to it: + * (image[s]/volume[s]) to newly allocated zone. + * @return Pointer to newly allocated pixel data. */ void * gdcmFile::GetImageData (void) { PixelData = (void *) malloc(lgrTotale); @@ -110,16 +146,17 @@ void * gdcmFile::GetImageData (void) { return(PixelData); } -///////////////////////////////////////////////////////////////// /** - * \ingroup gdcmFile - * \brief amene en mémoire dans une zone précisee par l'utilisateur - * les Pixels d'une image - * - * @param destination - * @param MaxSize - * - * @return The number of bytes actually copied. + * \ingroup gdcmFile + * \brief Copies at most MaxSize bytes of pixel data to caller's + * memory space. + * @param destination Address (in caller's memory space) at which the + * pixel data should be copied + * @param MaxSize Maximum number of bytes to be copied. When MaxSize + * is not sufficient to hold the pixel data the copy is not + * executed (i.e. no partial copy). + * @return On success, the number of bytes actually copied. Zero on + * failure e.g. MaxSize is lower than necessary. */ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { @@ -279,8 +316,9 @@ return; * \ingroup gdcmFile * \brief TODO JPR * \warning doit-etre etre publique ? FIXME JPR + * TODO : y a-t-il un inconvenient à fusioner ces 2 fonctions * - * @param Data TODO JPR + * @param inData TODO JPR * @param ExpectedSize TODO JPR * * @return TODO JPR @@ -289,6 +327,8 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) { SetImageDataSize(ExpectedSize); PixelData = inData; lgrTotale = ExpectedSize; + + return(1); } @@ -299,6 +339,7 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) { * \brief TODO JPR * \ * \warning WARNING doit-etre etre publique ? FIXME JPR + * TODO : y aurait il un inconvenient à fusionner ces 2 fonctions * * @param ImageDataSize TODO JPR * @@ -307,15 +348,15 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) { void gdcmFile::SetImageDataSize(size_t ImageDataSize) { string content1; - string content2; char car[20]; // suppose que le ElValue (0x7fe0, 0x0010) existe ... sprintf(car,"%d",ImageDataSize); - content2=car; - SetPubElValByNumber(content2, 0x7fe0, 0x0010); - + + gdcmElValue*a = GetElValueByNumber(0x7fe0, 0x0010); + a->SetLength(ImageDataSize); + ImageDataSize+=8; sprintf(car,"%d",ImageDataSize); content1=car;