]> Creatis software - gdcm.git/blob - Example/TestWriteSimple.cxx
First stage of name normalisation : gdcm::File replace by gdcm::FileHelper
[gdcm.git] / Example / TestWriteSimple.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestWriteSimple.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/20 16:16:58 $
7   Version:   $Revision: 1.7 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmHeader.h"
19 #include "gdcmFile.h"
20
21 int main(int argc, char* argv[])
22 {
23
24   if (argc < 3) 
25     {
26     std::cerr << "Usage :" << std::endl << argv[0] << 
27       " InputHeader OutputDicom" << std::endl;
28     return 0;
29     }
30
31   std::string header = argv[1];
32   const char *output = argv[2];
33
34   gdcm::Header       *f1 = new gdcm::Header( header );
35   gdcm::FileHelper   *f2 = new gdcm::FileHelper( f1 );
36
37   // If the following call is important, then the API sucks. Why is it
38   // required to allocate PixelData when we are not using it !?
39   uint8_t* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT
40   //Otherwise ReadPixel == -1 -> the dicom writing fails completely
41   
42   int dataSize    = f2->GetImageDataSize();
43   // unsigned char cast is necessary to be able to delete the buffer
44   // since deleting a void* is not allowed in c++
45   uint8_t *imageData = (uint8_t *)f2->GetImageData();
46
47   f2->SetImageData( imageData, dataSize );
48
49   f2->WriteDcmExplVR( output );
50   
51   delete f1;
52   delete f2;
53   //delete PixelData; //Does GetImageData return the same pointer ?
54   (void)PixelData;
55
56   return 0;
57 }
58