]> Creatis software - gdcm.git/blob - Example/BatchUncompress.cxx
ENH: Adding a batch convert for Jim (dicom newsgroup)
[gdcm.git] / Example / BatchUncompress.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: BatchUncompress.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/12/12 23:46:52 $
7   Version:   $Revision: 1.1 $
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 /*
19  * See :
20  * http://groups.google.com/group/comp.protocols.dicom/browse_thread/thread/2c70859b49122249/3c292c6acc5603ac
21  * For the origin of this example. I think most people are looking for this kind of batch anyway.
22  * Someone at some point could update it to have more option, like not copying the private tags,
23  * sequence...
24  */
25 #include "gdcmFile.h"
26 #include "gdcmFileHelper.h"
27 #include "gdcmDocument.h"
28
29 int main(int argc, char *argv[])
30 {
31   if (argc < 3) 
32     {
33     std::cerr << "Usage :" << std::endl << argv[0] << 
34       " InputHeader OutputDicom" << std::endl;
35     return 0;
36     }
37
38   const char *inputfilename = argv[1];
39   const char *outputfilename = argv[2];
40
41   gdcm::File *input = new gdcm::File( );
42   input->SetFileName( inputfilename );
43 //  input->SetLoadMode(loadMode);
44   input->Load();
45   if ( input->IsReadable() )
46     {
47     gdcm::FileHelper *output = new gdcm::FileHelper( input );
48
49     output->GetImageData(); //EXTREMELY IMPORTANT
50     //Otherwise ReadPixel == -1 -> the dicom writing fails completely
51     int dataSize       = output->GetImageDataSize();
52     uint8_t *imageData = output->GetImageData();
53
54     output->SetImageData( imageData, dataSize);
55     output->WriteDcmExplVR( outputfilename );
56
57     delete output;
58     }
59   delete input;
60
61   return 0;
62 }
63