]> Creatis software - gdcm.git/blob - Testing/TestWriteSimple.cxx
* Test/TestWriteSimple.cxx: fix to gdcmHeader-gdcmHeaderHelper revamping.
[gdcm.git] / Testing / TestWriteSimple.cxx
1 #include "gdcmHeader.h"
2 #include "gdcmFile.h"
3 #include "gdcmDebug.h"
4
5
6 int TestWriteSimple(int argc, char* argv[])
7 {
8
9   if (argc < 3) 
10     {
11     std::cerr << "Usage :" << std::endl << argv[0] << 
12       " InputHeader OutputDicom" << std::endl;
13     return 0;   
14     }
15
16   std::string header = argv[1];
17   const char *output = argv[2];
18
19   gdcmHeader *f1 = new gdcmHeader( header );
20   gdcmFile   *f2 = new gdcmFile( f1 );
21         
22   // If the following call is important, then the API sucks. Why is it
23   // required to allocate PixelData when we are not using it !?
24   void* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT
25   //Otherwise ReadPixel == -1 -> the dicom writing fails completely
26   
27   int dataSize    = f2->GetImageDataSize();
28   // unsigned char cast is necessary to be able to delete the buffer
29   // since deleting a void* is not allowed in c++
30   char *imageData = (char*)f2->GetImageData();
31
32   f2->SetImageData( imageData, dataSize);
33
34   f2->WriteDcmExplVR( output );
35   
36   delete[] imageData;
37   delete f1;
38   delete f2;
39   //delete PixelData; //Does GetImageData return the same pointer ?
40   (void)PixelData;
41
42   return 0;
43 }
44