X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FTestWriteSimple.cxx;h=ee4f15f976c831b46a54cc730992b65c68f637b5;hb=f711022dedd779e5e58e649af8c440a4a58bdba1;hp=12d111d066f2efd5d9f95fed5146fe4a9f1d6a0d;hpb=a1632352fa2c6d5bbc306d8bbf70511eac325324;p=gdcm.git diff --git a/Example/TestWriteSimple.cxx b/Example/TestWriteSimple.cxx index 12d111d0..ee4f15f9 100644 --- a/Example/TestWriteSimple.cxx +++ b/Example/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2005/01/20 16:31:42 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/02/02 10:06:32 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -15,44 +15,43 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "gdcmHeader.h" +#include "gdcmFile.h" #include "gdcmFileHelper.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { + if (argc < 3) + { + std::cerr << "Usage :" << std::endl << argv[0] + << " InputFile OutputDicom" << std::endl; + return 0; + } - if (argc < 3) - { - std::cerr << "Usage :" << std::endl << argv[0] << - " InputHeader OutputDicom" << std::endl; - return 0; - } - - std::string header = argv[1]; - const char *output = argv[2]; - - gdcm::Header *f1 = new gdcm::Header( header ); - gdcm::FileHelper *f2 = new gdcm::FileHelper( f1 ); - - // If the following call is important, then the API sucks. Why is it - // required to allocate PixelData when we are not using it !? - uint8_t* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT - //Otherwise ReadPixel == -1 -> the dicom writing fails completely - - int dataSize = f2->GetImageDataSize(); - // unsigned char cast is necessary to be able to delete the buffer - // since deleting a void* is not allowed in c++ - uint8_t *imageData = (uint8_t *)f2->GetImageData(); - - f2->SetImageData( imageData, dataSize ); - - f2->WriteDcmExplVR( output ); - - delete f1; - delete f2; - //delete PixelData; //Does GetImageData return the same pointer ? - (void)PixelData; - - return 0; + std::string header = argv[1]; + const char *output = argv[2]; + + gdcm::File *f1 = new gdcm::File( header ); + gdcm::FileHelper *f2 = new gdcm::FileHelper( f1 ); + + // If the following call is important, then the API sucks. Why is it + // required to allocate PixelData when we are not using it !? + uint8_t* PixelData = f2->GetImageData(); //EXTREMELY IMPORTANT + //Otherwise ReadPixel == -1 -> the dicom writing fails completely + + int dataSize = f2->GetImageDataSize(); + // unsigned char cast is necessary to be able to delete the buffer + // since deleting a void* is not allowed in c++ + uint8_t *imageData = (uint8_t *)f2->GetImageData(); + + f2->SetImageData( imageData, dataSize ); + + f2->WriteDcmExplVR( output ); + + delete f1; + delete f2; + //delete PixelData; //Does GetImageData return the same pointer ? + (void)PixelData; + + return 0; }