]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
* Testing/TestMAkeIcon.cxx : complete the test
[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 13:12:05 $
7   Version:   $Revision: 1.3 $
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 #include "gdcmBinEntry.h"
27
28 // 0088 0200 SQ 1 Icon Image Sequence 
29
30 int TestMakeIcon (int argc, char *argv[])
31 {
32    // hard 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    }
46
47    gdcm::File *f1 = new gdcm::File(input);
48
49    if (f1 == 0)
50    {
51       std::cout << " failed to open file" << std::endl;
52       return 1;
53    }  
54    gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1); 
55    uint8_t *pixels = fh1->GetImageData();
56    uint32_t lgth = fh1->GetImageDataSize();
57
58    gdcm::SeqEntry *icon = f1->InsertSeqEntry(0x0088, 0x0200);
59    gdcm::SQItem *sqi = new gdcm::SQItem(1);
60    icon->AddSQItem(sqi, 1);
61
62    // icone is just define like the image
63    // The purpose is NOT to imagine an icon, 
64    // just check the stuff works
65    uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
66  
67    sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004);
68    sqi->InsertValEntry( "128", 0x0028,0x0010);
69    sqi->InsertValEntry( "8",   0x0028,0x0100);
70    sqi->InsertValEntry( "8",   0x0028,0x0101);
71    sqi->InsertValEntry( "7",   0x0028,0x0102);
72    sqi->InsertValEntry( "0",   0x0028,0x0103);
73    sqi->InsertBinEntry(  (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
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 )
89    {
90       std::cout << "Sequence 0088|0200 not found" << std::endl
91                 << "   ... Failed" << std::endl;
92       delete fh1;
93       delete f1;
94       return 1;
95    }
96
97    // Test for entry 0028|0010
98    if ( !sqi->GetValEntry(0x0028,0x0010) )
99    {
100       std::cout << "ValEntry 0028|0010 not found" << std::endl
101                 << "   ... Failed" << std::endl;
102       delete fh1;
103       delete f1;
104       return 1;
105    }
106    if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
107    {
108       std::cout << "Value 0028|0010 don't match" << std::endl
109                 << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue()
110                 << " - Expected : 128" << std::endl
111                 << "   ... Failed" << std::endl;
112       delete fh1;
113       delete f1;
114       return 1;
115    }
116
117    // Test for entry 0028|0011
118    if ( !sqi->GetValEntry(0x0028,0x0011) )
119    {
120       std::cout << "ValEntry 0028|0011 not found" << std::endl
121                 << "   ... Failed" << std::endl;
122       delete fh1;
123       delete f1;
124       return 1;
125    }
126    if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
127    {
128       std::cout << "Value 0028|0011 don't match" << std::endl
129                 << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue()
130                 << " - Expected : 128" << std::endl
131                 << "   ... Failed" << std::endl;
132       delete fh1;
133       delete f1;
134       return 1;
135    }
136
137    // Test for entry 0028|0100
138    if ( !sqi->GetValEntry(0x0028,0x0100) )
139    {
140       std::cout << "ValEntry 0028|0100 not found" << std::endl
141                 << "   ... Failed" << std::endl;
142       delete fh1;
143       delete f1;
144       return 1;
145    }
146    if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
147    {
148       std::cout << "Value 0028|0100 don't match" << std::endl
149                 << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue()
150                 << " - Expected : 8" << std::endl
151                 << "   ... Failed" << std::endl;
152       delete fh1;
153       delete f1;
154       return 1;
155    }
156
157    // Test for entry 0028|0101
158    if ( !sqi->GetValEntry(0x0028,0x0101) )
159    {
160       std::cout << "ValEntry 0028|0101 not found" << std::endl
161                 << "   ... Failed" << std::endl;
162       delete fh1;
163       delete f1;
164       return 1;
165    }
166    if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
167    {
168       std::cout << "Value 0028|0101 don't match" << std::endl
169                 << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue()
170                 << " - Expected : 8" << std::endl
171                 << "   ... Failed" << std::endl;
172       delete fh1;
173       delete f1;
174       return 1;
175    }
176
177    // Test for entry 0028|0102
178    if ( !sqi->GetValEntry(0x0028,0x0102) )
179    {
180       std::cout << "ValEntry 0028|0102 not found" << std::endl
181                 << "   ... Failed" << std::endl;
182       delete fh1;
183       delete f1;
184       return 1;
185    }
186    if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
187    {
188       std::cout << "Value 0028|0102 don't match" << std::endl
189                 << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue()
190                 << " - Expected : 7" << std::endl
191                 << "   ... Failed" << std::endl;
192       delete fh1;
193       delete f1;
194       return 1;
195    }
196
197    // Test for entry 0028|0103
198    if ( !sqi->GetValEntry(0x0028,0x0103) )
199    {
200       std::cout << "ValEntry 0028|0010 not found" << std::endl
201                 << "   ... Failed" << std::endl;
202       delete fh1;
203       delete f1;
204       return 1;
205    }
206    if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
207    {
208       std::cout << "Value 0028|0103 don't match" << std::endl
209                 << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue()
210                 << " - Expected : 0" << std::endl
211                 << "   ... Failed" << std::endl;
212       delete fh1;
213       delete f1;
214       return 1;
215    }
216
217    // Test for entry 0005|0010
218    if ( !sqi->GetValEntry(0x0028,0x0010) )
219    {
220       std::cout << "BinEntry 0005|0010 not found" << std::endl
221                 << "   ... Failed" << std::endl;
222       delete fh1;
223       delete f1;
224       return 1;
225    }
226    if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
227    {
228       std::cout << "BinEntry size 0005|0010 don't match" << std::endl
229                 << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength()
230                 << " - Expected : 6" << std::endl
231                 << "   ... Failed" << std::endl;
232       delete fh1;
233       delete f1;
234       return 1;
235    }
236
237    if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
238    {
239       std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
240                 << "   ... Failed" << std::endl;
241       delete fh1;
242       delete f1;
243       return 1;
244    }
245
246    delete fh1;
247    delete f1;
248    std::cout << "   ... OK" << std::endl;
249
250    return 0;
251 }