]> Creatis software - gdcm.git/commitdiff
ENH: Adding a batch convert for Jim (dicom newsgroup)
authormalaterre <malaterre>
Mon, 12 Dec 2005 23:46:52 +0000 (23:46 +0000)
committermalaterre <malaterre>
Mon, 12 Dec 2005 23:46:52 +0000 (23:46 +0000)
Example/BatchUncompress.cxx [new file with mode: 0644]

diff --git a/Example/BatchUncompress.cxx b/Example/BatchUncompress.cxx
new file mode 100644 (file)
index 0000000..14ce4e3
--- /dev/null
@@ -0,0 +1,63 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: BatchUncompress.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/12/12 23:46:52 $
+  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.
+                                                                                
+=========================================================================*/
+/*
+ * See :
+ * http://groups.google.com/group/comp.protocols.dicom/browse_thread/thread/2c70859b49122249/3c292c6acc5603ac
+ * For the origin of this example. I think most people are looking for this kind of batch anyway.
+ * Someone at some point could update it to have more option, like not copying the private tags,
+ * sequence...
+ */
+#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
+#include "gdcmDocument.h"
+
+int main(int argc, char *argv[])
+{
+  if (argc < 3) 
+    {
+    std::cerr << "Usage :" << std::endl << argv[0] << 
+      " InputHeader OutputDicom" << std::endl;
+    return 0;
+    }
+
+  const char *inputfilename = argv[1];
+  const char *outputfilename = argv[2];
+
+  gdcm::File *input = new gdcm::File( );
+  input->SetFileName( inputfilename );
+//  input->SetLoadMode(loadMode);
+  input->Load();
+  if ( input->IsReadable() )
+    {
+    gdcm::FileHelper *output = new gdcm::FileHelper( input );
+
+    output->GetImageData(); //EXTREMELY IMPORTANT
+    //Otherwise ReadPixel == -1 -> the dicom writing fails completely
+    int dataSize       = output->GetImageDataSize();
+    uint8_t *imageData = output->GetImageData();
+
+    output->SetImageData( imageData, dataSize);
+    output->WriteDcmExplVR( outputfilename );
+
+    delete output;
+    }
+  delete input;
+
+  return 0;
+}
+