]> Creatis software - gdcm.git/blob - Example/TestWriteSimple.cxx
* bug fix for compilation on MSVC6
[gdcm.git] / Example / TestWriteSimple.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestWriteSimple.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/22 12:39:11 $
7   Version:   $Revision: 1.10 $
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 "gdcmFile.h"
19 #include "gdcmFileHelper.h"
20
21 int main(int argc, char* argv[])
22 {
23    if (argc < 3) 
24    {
25       std::cerr << "Usage :" << std::endl << argv[0]
26                 << " InputFile OutputDicom" << std::endl;
27       return 0;
28    }
29
30    std::string header = argv[1];
31    const char *output = argv[2];
32
33    gdcm::File       *f1 = new gdcm::File( header );
34    gdcm::FileHelper   *f2 = new gdcm::FileHelper( f1 );
35
36    // If the following call is important, then the API sucks. Why is it
37    // required to allocate PixelData when we are not using it !?
38    uint8_t* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT
39    //Otherwise ReadPixel == -1 -> the dicom writing fails completely
40
41    int dataSize    = f2->GetImageDataSize();
42    // unsigned char cast is necessary to be able to delete the buffer
43    // since deleting a void* is not allowed in c++
44    uint8_t *imageData = (uint8_t *)f2->GetImageData();
45
46    f2->SetImageData( imageData, dataSize );
47
48    f2->WriteDcmExplVR( output );
49
50    delete f1;
51    delete f2;
52    //delete PixelData; //Does GetImageData return the same pointer ?
53    (void)PixelData;
54
55    return 0;
56 }
57