1 /*=========================================================================
4 Module: $RCSfile: WriteRead.cxx,v $
6 Date: $Date: 2004/12/03 20:16:56 $
7 Version: $Revision: 1.9 $
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.
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.
17 =========================================================================*/
18 #include "gdcmHeader.h"
23 int main(int argc, char* argv[])
27 gdcm::Header* e1, *e2;
30 uint8_t* imageData, *imageData2;
31 int dataSize, dataSize2;
35 std::cerr << "Usage " << argv[0] << " image.dcm" << std::endl;
39 std::string toto = argv[1];
41 // --------------------- we read the input image
43 std::cout << argv[1] << std::endl;
45 e1 = new gdcm::Header( toto );
46 if (!e1->IsReadable()) {
47 std::cerr << "Sorry, " << toto <<" not a Readable DICOM / ACR File"
52 f1 = new gdcm::File(e1);
53 imageData= f1->GetImageData();
54 dataSize = f1->GetImageDataSize();
56 // --------------------- we write it as an Explicit VR DICOM file
59 std::cout << "WriteDCM Explicit VR" << std::endl;
60 f1->WriteDcmExplVR(zozo);
62 // --------------------- we read the written image
64 e2 = new gdcm::Header( zozo );
65 if (!e2->IsReadable()) {
66 std::cerr << "Sorry, " << zozo << " not a Readable DICOM / ACR File"
70 f2 = new gdcm::File(e2);
71 imageData2= f2->GetImageData();
72 dataSize2 = f2->GetImageDataSize();
74 // --------------------- we compare the pixel areas
76 if (dataSize != dataSize2) {
77 std::cout << " ----------------------------------------- "
78 << "Bad shot! Lengthes are different : "
79 << dataSize << " # " << dataSize2
80 << " for file : " << toto << std::endl;
84 if (int res=memcmp(imageData,imageData2,dataSize) !=0) {
85 std::cout << " ----------------------------------------- "
86 << "Bad shot! Pixels are different : "
87 << " for file : " << toto << std::endl;
88 std::cout << "memcmp(imageData,imageData2,dataSize) = " << res << std::endl;
92 //If we reach here everything is fine, return 0 then: