]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
Add a test : creating an "Icon Image Sequence"
[gdcm.git] / Testing / TestMakeIcon.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestMakeIcon.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/11 12:14:26 $
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 #include "gdcmDebug.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmCommon.h"
21 #include "gdcmFile.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmSeqEntry.h"
24 #include "gdcmSQItem.h"
25 #include "gdcmValEntry.h"
26
27 // 0088 0200 SQ 1 Icon Image Sequence 
28
29 int TestMakeIcon (int , char )
30 {
31
32    //ard coded small image name
33    std::string input = "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
34    std::string output = "test.dcm";
35 /*
36    if ( argc == 3 )
37    {
38       input  = argv[1];
39       output = argv[2];
40    }
41    else if ( argc < 3  )
42    {
43       std::cout << "   Usage: " << argv[0]
44                 << " input filename.dcm output Filename.dcm" << std::endl;
45       return 1;
46    }
47 */
48
49    gdcm::File *f1 = new gdcm::File(input);
50
51    if (f1 == 0)
52    {
53       std::cout << " failed to open file" << std::endl;
54       return 1;
55    }  
56    gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1); 
57    uint8_t *pixels = fh1->GetImageData();
58    uint32_t lgth = fh1->GetImageDataSize();
59
60    gdcm::SeqEntry *icon = f1->InsertSeqEntry(0x0088, 0x0200);
61    gdcm::SQItem *sqi = new gdcm::SQItem(1);
62    icon->AddSQItem(sqi, 1);
63
64    // icone is just define like the image
65    // The purpose is NOT to imagine an icon, 
66    // just check the stuff works
67  
68    sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004);
69    sqi->InsertValEntry( "128", 0x0028,0x0010);
70    sqi->InsertValEntry( "8", 0x0028,0x0100);
71    sqi->InsertValEntry( "8", 0x0028,0x0101);
72    sqi->InsertValEntry( "7", 0x0028,0x0102);
73    sqi->InsertValEntry( "0", 0x0028,0x0103);
74    sqi->InsertBinEntry(  pixels, lgth, 0x7fe0,0x0010);
75    // just to see if it's stored a the right place
76    sqi->InsertValEntry( "128", 0x0028,0x0011);
77     
78    fh1->WriteDcmExplVR(output);
79
80    delete f1;
81
82    f1 = new gdcm::File(output);
83    f1->Print();
84
85    icon = f1->GetSeqEntry(0x0088, 0x0200);
86    sqi = icon->GetFirstSQItem();
87
88    if ( (sqi->GetValEntry(0x0028,0x0010))->GetValue() != "128" )
89       return 1;
90
91    if ( (sqi->GetValEntry(0x0028,0x0011))->GetValue() != "128" )
92       return 1;
93
94    if ( (sqi->GetValEntry(0x0028,0x0100))->GetValue() != "8" )
95       return 1;
96
97    if ( (sqi->GetValEntry(0x0028,0x0101))->GetValue() != "8" )
98       return 1;
99
100    if ( (sqi->GetValEntry(0x0028,0x0102))->GetValue() != "7" )
101       return 1;
102
103    if ( (sqi->GetValEntry(0x0028,0x0103))->GetValue() != "0" )
104       return 1;
105
106    delete fh1;
107    delete F1;
108
109    return 0;
110 }