]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
* src/gdcmFileHelper.cxx : bug fix when having RGB ACR files... there is
[gdcm.git] / src / gdcmFileHelper.cxx
index bde7e0f936c1511c7ffaf8411c4a6e0c8239e8c7..789ca75230fe8055ea35fa5edad7f59790a9182b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/04 14:49:01 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2005/02/09 18:35:30 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -320,7 +320,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
    {
       if ( PixelReadConverter->GetRGBSize() > maxSize )
       {
-         gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
+         gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
          return 0;
       }
       memcpy( destination,
@@ -332,7 +332,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
    // Either no LUT conversion necessary or LUT conversion failed
    if ( PixelReadConverter->GetRawSize() > maxSize )
    {
-      gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
+      gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
       return 0;
    }
    memcpy( destination,
@@ -450,7 +450,7 @@ bool FileHelper::WriteRawData(std::string const &fileName)
   std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
    if (!fp1)
    {
-      gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str());
+      gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
       return false;
    }
 
@@ -635,7 +635,7 @@ bool FileHelper::CheckWriteIntegrity()
          case WMODE_RAW :
             if( decSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be " 
+               gdcmWarningMacro( "Data size (Raw) is incorrect. Should be " 
                            << decSize << " / Found :" 
                            << PixelWriteConverter->GetUserDataSize() );
                return false;
@@ -644,7 +644,7 @@ bool FileHelper::CheckWriteIntegrity()
          case WMODE_RGB :
             if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be " 
+               gdcmWarningMacro( "Data size (RGB) is incorrect. Should be " 
                           << decSize << " / Found " 
                           << PixelWriteConverter->GetUserDataSize() );
                return false;
@@ -681,8 +681,13 @@ void FileHelper::SetWriteToRaw()
       PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
                                        PixelReadConverter->GetRawSize());
 
+      std::string vr = "OB";
+      if( FileInternal->GetBitsAllocated()>8 )
+         vr = "OW";
+      if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
+         vr = "OB";
       BinEntry *pixel = 
-         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
+         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
       pixel->SetValue(GDCM_BINLOADED);
       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
       pixel->SetLength(PixelWriteConverter->GetDataSize());
@@ -721,8 +726,13 @@ void FileHelper::SetWriteToRGB()
                                           PixelReadConverter->GetRawSize());
       }
 
+      std::string vr = "OB";
+      if( FileInternal->GetBitsAllocated()>8 )
+         vr = "OW";
+      if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
+         vr = "OB";
       BinEntry *pixel = 
-         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
+         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
       pixel->SetValue(GDCM_BINLOADED);
       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
       pixel->SetLength(PixelWriteConverter->GetDataSize());
@@ -906,7 +916,7 @@ ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
    DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
    ValEntry *newE;
 
-   if(oldE)
+   if( oldE )
    {
       newE = new ValEntry(oldE->GetDictEntry());
       newE->Copy(oldE);
@@ -927,19 +937,23 @@ ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
  * \return  pointer to the modified/created Bin Entry (NULL when creation
  *          failed).
  */ 
-BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem)
+BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem,const std::string &vr)
 {
    DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
    BinEntry *newE;
 
-   if(oldE)
+   if( oldE )
+      if( oldE->GetVR()!=vr )
+         oldE = NULL;
+
+   if( oldE )
    {
       newE = new BinEntry(oldE->GetDictEntry());
       newE->Copy(oldE);
    }
    else
    {
-      newE = GetFile()->NewBinEntry(group,elem);
+      newE = GetFile()->NewBinEntry(group,elem,vr);
    }
 
    return newE;
@@ -982,7 +996,7 @@ uint8_t *FileHelper::GetRaw()
       raw = PixelReadConverter->GetRaw();
       if ( ! raw )
       {
-         gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong.");
+         gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
          return 0;
       }
    }