]> Creatis software - gdcm.git/commitdiff
* src/gdcmPixelWriteConvert.[h|cxx] : new class to write datas (and in the
authorregrain <regrain>
Fri, 3 Dec 2004 11:55:37 +0000 (11:55 +0000)
committerregrain <regrain>
Fri, 3 Dec 2004 11:55:37 +0000 (11:55 +0000)
     future, with convertion)
   * src/gdcmFile.[h|cxx] : the PixelWriteConverter instance replace Pixel_Data
     and ImageDataSize values. Remove the method to get the PixelReadConverter
     from the output of the class
   -- BeNours

ChangeLog
Example/PrintFile.cxx
Example/TestWrite.cxx
Example/Write.cxx
src/CMakeLists.txt
src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmPixelReadConvert.h
src/gdcmPixelWriteConvert.cxx [new file with mode: 0644]
src/gdcmPixelWriteConvert.h [new file with mode: 0644]

index 5bb70d02d87dea4888107c2978d2da05c0189d3e..a8ec06e0dadca9fc85f6c698bb536bf36cd0f315 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
+2004-12-03 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * src/gdcmPixelWriteConvert.[h|cxx] : new class to write datas (and in the
+     future, with convertion)
+   * src/gdcmFile.[h|cxx] : the PixelWriteConverter instance replace Pixel_Data
+     and ImageDataSize values. Remove the method to get the PixelReadConverter
+     from the output of the class
+
 2004-12-03 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * Rename src/gdcmPixelConvert.[h|cxx] to src/gdcmPixelReadConvert.[h|cxx]
-   
+
 2004-12-02 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * vtk/vtkGdcmReader.cxx : correct error in vtkDebugMacro, vtkWarningMacro
      and vtkErrorMacro use.
index aae83a4cfbe6a8e0b5a782e039429ba925c90d26..2d2f671f995ff049dc41508f84b1a614dbf05d38 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PrintFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:53 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2004/12/03 11:55:37 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -86,7 +86,7 @@ int main(int argc, char* argv[])
    std::string transferSyntaxName = e1->GetTransfertSyntaxName();
    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
    
-   if (  transferSyntaxName != "Implicit VR - Little Endian"
+/*   if (  transferSyntaxName != "Implicit VR - Little Endian"
       && transferSyntaxName != "Explicit VR - Little Endian"     
       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
       && transferSyntaxName != "Explicit VR - Big Endian"
@@ -97,7 +97,7 @@ int main(int argc, char* argv[])
          f1->GetPixelReadConverter()->Print();
       std::cout << std::endl << "==========================================="
                   << std::endl; 
-   }
+   }*/
    
    if(e1->IsReadable())
       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
index b308dad1d0bb53bb8a67694e93878339fed8f810..3355ed4339b55d8478329c0448f5c167fab1a99e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestWrite.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:53 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/12/03 11:55:37 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -102,7 +102,7 @@ int main(int argc, char* argv[])
    transferSyntaxName = e1->GetTransfertSyntaxName();
    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
    
-   if (  transferSyntaxName != "Implicit VR - Little Endian"
+/*   if (  transferSyntaxName != "Implicit VR - Little Endian"
       && transferSyntaxName != "Explicit VR - Little Endian"     
       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
       && transferSyntaxName != "Explicit VR - Big Endian"
@@ -112,7 +112,7 @@ int main(int argc, char* argv[])
       f1->GetPixelReadConverter()->Print();
       std::cout << std::endl << "==========================================="
                 << std::endl; 
-   }
+   }*/
    imageData= f1->GetImageData();
 
    switch (argv[2][0]) {
index 6e2f1e3ec459457086855a0c09e1d0baa58be027..7c1d0e2efcf64fc3e7c8bed1ca1bc5488656d676 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: Write.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:53 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/12/03 11:55:37 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -97,7 +97,7 @@ int main(int argc, char* argv[])
    transferSyntaxName = e1->GetTransfertSyntaxName();
    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
    
-   if (  transferSyntaxName != "Implicit VR - Little Endian"
+/*   if (  transferSyntaxName != "Implicit VR - Little Endian"
       && transferSyntaxName != "Explicit VR - Little Endian"     
       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
       && transferSyntaxName != "Explicit VR - Big Endian"
@@ -107,7 +107,7 @@ int main(int argc, char* argv[])
       f1->GetPixelReadConverter()->Print();
       std::cout << std::endl << "==========================================="
                 << std::endl; 
-   }
+   }*/
    imageData= f1->GetImageData();
    (void)imageData;  // to avoid warnings
 
index 541ba16042f71cd3c2c1e55178b13c977dd83263..9544053e854e4c375ab9576deee27209e143b438 100644 (file)
@@ -43,6 +43,7 @@ SET(libgdcm_la_SOURCES
    gdcmJpeg16.cxx
    gdcmJpeg2000.cxx
    gdcmPixelReadConvert.cxx
+   gdcmPixelWriteConvert.cxx
    gdcmRLEFrame.cxx
    gdcmRLEFramesInfo.cxx
    gdcmSeqEntry.cxx
index 6d596da72c7d5447280c4e59770073f2c58703b0..f582c483d5074b45d051bc97d5c7a68689322d05 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:54 $
-  Version:   $Revision: 1.168 $
+  Date:      $Date: 2004/12/03 11:55:38 $
+  Version:   $Revision: 1.169 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -80,15 +80,13 @@ void File::Initialise()
    WriteType = WTYPE_IMPL_VR;
 
    PixelReadConverter = new PixelReadConvert;
+   PixelWriteConverter = new PixelWriteConvert;
    Archive = new DocEntryArchive( HeaderInternal );
 
    if ( HeaderInternal->IsReadable() )
    {
       PixelReadConverter->GrabInformationsFromHeader( HeaderInternal );
    }
-
-   Pixel_Data = 0;
-   ImageDataSize = 0;
 }
 
 /**
@@ -102,6 +100,10 @@ File::~File()
    {
       delete PixelReadConverter;
    }
+   if( PixelWriteConverter )
+   {
+      delete PixelWriteConverter;
+   }
    if( Archive )
    {
       delete Archive;
@@ -270,7 +272,7 @@ uint8_t* File::GetDecompressed()
 }
 
 /**
- * \brief   Points the internal Pixel_Data pointer to the callers inData
+ * \brief   Points the internal pointer to the callers inData
  *          image representation, BUT WITHOUT COPYING THE DATA.
  *          'image' Pixels are presented as C-like 2D arrays : line per line.
  *          'volume'Pixels are presented as C-like 3D arrays : plane per plane 
@@ -284,10 +286,8 @@ uint8_t* File::GetDecompressed()
  */
 bool File::SetImageData(uint8_t* inData, size_t expectedSize)
 {
-// FIXME : if already allocated, memory leak !
-   Pixel_Data     = inData;
-   ImageDataSize = expectedSize;
-// FIXME : 7fe0, 0010 IS NOT set ...
+   PixelWriteConverter->SetUserData(inData,expectedSize);
+
    return true;
 }
 
@@ -308,7 +308,14 @@ bool File::WriteRawData(std::string const & fileName)
       dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str());
       return false;
    }
-   fp1.write((char*)Pixel_Data, ImageDataSize);
+
+   if(PixelWriteConverter->GetUserData())
+      fp1.write((char*)PixelWriteConverter->GetUserData(), PixelWriteConverter->GetUserDataSize());
+   else if(PixelReadConverter->GetRGB())
+      fp1.write((char*)PixelReadConverter->GetRGB(), PixelReadConverter->GetRGBSize());
+   else if(PixelReadConverter->GetDecompressed())
+      fp1.write((char*)PixelReadConverter->GetDecompressed(), PixelReadConverter->GetDecompressedSize());
+
    fp1.close();
 
    return true;
@@ -471,7 +478,7 @@ bool File::WriteBase (std::string const & fileName, FileType type)
  */
 bool File::CheckWriteIntegrity()
 {
-   if(Pixel_Data)
+   if(PixelWriteConverter->GetUserData())
    {
       int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
       if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
@@ -491,18 +498,16 @@ bool File::CheckWriteIntegrity()
       switch(WriteMode)
       {
          case WMODE_DECOMPRESSED :
-            if( decSize!=ImageDataSize )
+            if( decSize!=PixelWriteConverter->GetUserDataSize() )
             {
                dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
-               //std::cerr<<"Dec : "<<decSize<<" | "<<ImageDataSize<<std::endl;
                return false;
             }
             break;
          case WMODE_RGB :
-            if( rgbSize!=ImageDataSize )
+            if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
             {
                dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
-               //std::cerr<<"RGB : "<<decSize<<" | "<<ImageDataSize<<std::endl;
                return false;
             }
             break;
@@ -512,19 +517,6 @@ bool File::CheckWriteIntegrity()
    return true;
 }
 
-/*void File::SetWriteToNative()
-{
-   if(Pixel_Data)
-   {
-      BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
-      pixel->SetValue(GDCM_BINLOADED);
-      pixel->SetBinArea(Pixel_Data,false);
-      pixel->SetLength(ImageDataSize);
-
-      Archive->Push(pixel);
-   }
-}*/
-
 void File::SetWriteToDecompressed()
 {
    if(HeaderInternal->GetNumberOfScalarComponents()==3 && !HeaderInternal->HasLUT())
@@ -547,10 +539,10 @@ void File::SetWriteToDecompressed()
 
       BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
       pixel->SetValue(GDCM_BINLOADED);
-      if(Pixel_Data)
+      if(PixelWriteConverter->GetUserData())
       {
-         pixel->SetBinArea(Pixel_Data,false);
-         pixel->SetLength(ImageDataSize);
+         pixel->SetBinArea(PixelWriteConverter->GetUserData(),false);
+         pixel->SetLength(PixelWriteConverter->GetUserDataSize());
       }
       else
       {
@@ -583,10 +575,10 @@ void File::SetWriteToRGB()
 
       BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
       pixel->SetValue(GDCM_BINLOADED);
-      if(Pixel_Data)
+      if(PixelWriteConverter->GetUserData())
       {
-         pixel->SetBinArea(Pixel_Data,false);
-         pixel->SetLength(ImageDataSize);
+         pixel->SetBinArea(PixelWriteConverter->GetUserData(),false);
+         pixel->SetLength(PixelWriteConverter->GetUserDataSize());
       }
       else if(PixelReadConverter->GetRGB())
       {
index 01b638c497934786550c948f85c6b7e91a28224f..c9bb596e3170cc4658e8ac2f4ca12b28c5d3cff3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:54 $
-  Version:   $Revision: 1.80 $
+  Date:      $Date: 2004/12/03 11:55:38 $
+  Version:   $Revision: 1.81 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,6 +22,7 @@
 #include "gdcmCommon.h"
 #include "gdcmHeader.h"
 #include "gdcmPixelReadConvert.h"
+#include "gdcmPixelWriteConvert.h"
 #include "gdcmDocEntryArchive.h"
 
 namespace gdcm 
@@ -60,9 +61,6 @@ public:
    size_t GetImageDataSize();
    size_t GetImageDataRawSize();
 
-   /// Accessor to \ref PixelReadConverter
-   PixelReadConvert* GetPixelReadConverter() { return PixelReadConverter; };
-
    uint8_t* GetImageData();
    uint8_t* GetImageDataRaw();
    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
@@ -141,6 +139,7 @@ private:
 
    /// Utility pixel converter
    PixelReadConvert* PixelReadConverter;
+   PixelWriteConvert* PixelWriteConverter;
 
    // Utility header archive
    DocEntryArchive *Archive;
@@ -148,25 +147,6 @@ private:
    // Write variables
    unsigned int WriteMode;
    unsigned int WriteType;
-
-/// FIXME
-// --------------- Will be moved to a PixelData class
-//
-
-   /// \brief to hold the Pixels (when read)
-   uint8_t* Pixel_Data;  // (was PixelData)
-   
-   /// \brief Size (in bytes) of requited memory to hold the the pixels
-   ///        of this image in it's RGB convertion either from:
-   ///        - Plane R, Plane G, Plane B 
-   ///        - Grey Plane + Palette Color
-   ///        - YBR Pixels (or from RGB Pixels, as well) 
-   size_t ImageDataSize;
-       
-//
-// --------------- end of future PixelData class
-// 
-
 };
 } // end namespace gdcm
 
index 72bdf526fe1a9ee6d294d2e1adcc1fd44daad5b5..2be2bc8e994aa25c1337258797eb48b96c0d23dd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
   Language:  C++
-  Date:      $Date: 2004/12/03 10:21:55 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2004/12/03 11:55:38 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,7 +36,7 @@ class GDCM_EXPORT PixelReadConvert
 {
 public:
    PixelReadConvert();
-   ~PixelReadConvert();
+   virtual ~PixelReadConvert();
 
    //// Getter accessors:
    uint8_t* GetRGB() { return RGB; }
diff --git a/src/gdcmPixelWriteConvert.cxx b/src/gdcmPixelWriteConvert.cxx
new file mode 100644 (file)
index 0000000..a4f8cec
--- /dev/null
@@ -0,0 +1,71 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmPixelWriteConvert.cxx,v $
+  Language:  C++
+  Date:      $Date: 2004/12/03 11:55:38 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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.
+                                                                                
+=========================================================================*/
+
+//////////////////   TEMPORARY NOTE
+// look for "fixMem" and convert that to a member of this class
+// Removing the prefix fixMem and dealing with allocations should do the trick
+//
+// grep PixelWriteConvert everywhere and clean up !
+
+#include "gdcmDebug.h"
+#include "gdcmPixelWriteConvert.h"
+#include <stdio.h>
+
+namespace gdcm
+{
+//-----------------------------------------------------------------------------
+// Constructor / Destructor
+PixelWriteConvert::PixelWriteConvert() 
+{
+   ReadData = 0;
+   ReadDataSize = 0;
+
+   UserData = 0;
+   UserDataSize = 0;
+}
+
+PixelWriteConvert::~PixelWriteConvert() 
+{
+}
+
+//-----------------------------------------------------------------------------
+// Public
+void PixelWriteConvert::SetReadData(uint8_t* data,size_t size)
+{
+   ReadData = data;
+   ReadDataSize = size;
+}
+
+void PixelWriteConvert::SetUserData(uint8_t* data,size_t size)
+{
+   UserData = data;
+   UserDataSize = size;
+}
+
+//-----------------------------------------------------------------------------
+} // end namespace gdcm
+
+// NOTES on File internal calls
+// User
+// ---> GetImageData
+//     ---> GetImageDataIntoVector
+//        |---> GetImageDataIntoVectorRaw
+//        | lut intervention
+// User
+// ---> GetImageDataRaw
+//     ---> GetImageDataIntoVectorRaw
diff --git a/src/gdcmPixelWriteConvert.h b/src/gdcmPixelWriteConvert.h
new file mode 100644 (file)
index 0000000..3568b25
--- /dev/null
@@ -0,0 +1,61 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmPixelWriteConvert.h,v $
+  Language:  C++
+  Date:      $Date: 2004/12/03 11:55:38 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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.
+                                                                                
+=========================================================================*/
+
+
+#ifndef GDCMPIXELWRITECONVERT_H
+#define GDCMPIXELWRITECONVERT_H
+
+#include "gdcmCommon.h"
+
+namespace gdcm
+{
+/*
+ * \brief Utility container for gathering the various forms the pixel data
+ *        migth take during the user demanded processes.
+ */
+class GDCM_EXPORT PixelWriteConvert
+{
+public:
+   PixelWriteConvert();
+   virtual ~PixelWriteConvert();
+
+   // Set/Get of images and their size
+   void SetReadData(uint8_t* data,size_t size);
+   uint8_t* GetReadData() { return ReadData; }
+   size_t   GetReadDataSize() { return ReadDataSize; }
+
+   void SetUserData(uint8_t* data,size_t size);
+   uint8_t* GetUserData() { return UserData; }
+   size_t   GetUserDataSize() { return UserDataSize; }
+
+private:
+// Variables
+   /// Pixel data represented as RGB after LUT color interpretation.
+   uint8_t* ReadData;
+   /// Size of \ref RGB image.
+   size_t   ReadDataSize;
+
+   /// User pixel data
+   uint8_t* UserData;
+   /// Size of \ref User image.
+   size_t   UserDataSize;
+};
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------
+#endif