]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
Fix some checking
[gdcm.git] / Testing / TestMakeIcon.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestMakeIcon.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/04/26 16:23:58 $
7   Version:   $Revision: 1.6 $
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 = GDCM_DATA_ROOT;
34    input += "/"; 
35    input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
36
37    std::string output = "testIcon.dcm";
38
39    gdcm::Debug::DebugOn();
40
41    if ( argc == 3 )
42    {
43       input  = argv[1];
44       output = argv[2];
45    }
46    else if ( argc < 3  )
47    {
48       std::cout << "   Usage: " << argv[0]
49                 << " input filename.dcm output Filename.dcm" << std::endl;
50    }
51
52    gdcm::File *f1 = new gdcm::File( );
53    f1->Load(input);
54
55    if ( ! f1->IsReadable() )
56    {
57       std::cout << " Failed to Open/Parse file" << input << std::endl;
58       delete f1;
59       return 1;
60    }  
61    gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1); 
62    uint8_t *pixels = fh1->GetImageData();
63    uint32_t lgth   = fh1->GetImageDataSize();
64
65    gdcm::SeqEntry *icon = f1->InsertSeqEntry(0x0088, 0x0200);
66    gdcm::SQItem *sqi = new gdcm::SQItem(1);
67    icon->AddSQItem(sqi, 1);
68
69    // icone is just define like the image
70    // The purpose is NOT to imagine an icon, 
71    // just check the stuff works
72
73    uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
74  
75    sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004);
76    sqi->InsertValEntry( "128", 0x0028,0x0010);
77    sqi->InsertValEntry( "8",   0x0028,0x0100);
78    sqi->InsertValEntry( "8",   0x0028,0x0101);
79    sqi->InsertValEntry( "7",   0x0028,0x0102);
80    sqi->InsertValEntry( "0",   0x0028,0x0103);
81    sqi->InsertBinEntry(  (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
82    sqi->InsertBinEntry(  pixels, lgth, 0x7fe0,0x0010);
83    // just to see if it's stored a the right place
84    sqi->InsertValEntry( "128", 0x0028,0x0011);
85     
86    fh1->WriteDcmExplVR(output);
87
88    delete f1;
89
90    f1 = new gdcm::File(output);
91    f1->Print();
92    std::cout << "End of Print" << std::endl;
93
94    icon = f1->GetSeqEntry(0x0088, 0x0200);
95    if (!icon)
96    {
97       std::cout << "Sequence 0088|0200 not found" << std::endl
98                 << "   ... Failed" << std::endl;
99       delete fh1;
100       delete f1;
101       return 1;
102    }
103    std::cout << "Sequence 0088|0200 found" << std::endl;
104    
105    sqi = icon->GetFirstSQItem();
106
107    if ( !sqi )
108    {
109       std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
110                 << "   ... Failed" << std::endl;
111       delete fh1;
112       delete f1;
113       return 1;
114    }
115
116    std::cout << "First Item found" << std::endl;
117
118    // Test for entry 0028|0010
119    if ( !sqi->GetValEntry(0x0028,0x0010) )
120    {
121       std::cout << "ValEntry 0028|0010 not found" << std::endl
122                 << "   ... Failed" << std::endl;
123       delete fh1;
124       delete f1;
125       return 1;
126    }
127    std::cout << "First Item ->ValEntry 0028|0010 found" << std::endl;
128    if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
129    {
130       std::cout << "Value 0028|0010 don't match" << std::endl
131                 << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue()
132                 << " - Expected : 128" << std::endl
133                 << "   ... Failed" << std::endl;
134       delete fh1;
135       delete f1;
136       return 1;
137    }
138
139    // Test for entry 0028|0011
140    if ( !sqi->GetValEntry(0x0028,0x0011) )
141    {
142       std::cout << "ValEntry 0028|0011 not found" << std::endl
143                 << "   ... Failed" << std::endl;
144       delete fh1;
145       delete f1;
146       return 1;
147    }
148    std::cout << "First Item ->ValEntry 0028|0011 found" << std::endl;
149    if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
150    {
151       std::cout << "Value 0028|0011 don't match" << std::endl
152                 << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue()
153                 << " - Expected : 128" << std::endl
154                 << "   ... Failed" << std::endl;
155       delete fh1;
156       delete f1;
157       return 1;
158    }
159
160    // Test for entry 0028|0100
161    if ( !sqi->GetValEntry(0x0028,0x0100) )
162    {
163       std::cout << "ValEntry 0028|0100 not found" << std::endl
164                 << "   ... Failed" << std::endl;
165       delete fh1;
166       delete f1;
167       return 1;
168    }
169    std::cout << "First Item ->ValEntry 0028|0100 found" << std::endl;
170    if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
171    {
172       std::cout << "Value 0028|0100 don't match" << std::endl
173                 << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue()
174                 << " - Expected : 8" << std::endl
175                 << "   ... Failed" << std::endl;
176       delete fh1;
177       delete f1;
178       return 1;
179    }
180
181    // Test for entry 0028|0101
182    if ( !sqi->GetValEntry(0x0028,0x0101) )
183    {
184       std::cout << "ValEntry 0028|0101 not found" << std::endl
185                 << "   ... Failed" << std::endl;
186       delete fh1;
187       delete f1;
188       return 1;
189    }
190    std::cout << "First Item ->ValEntry 0028|0101 found" << std::endl;
191    if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
192    {
193       std::cout << "Value 0028|0101 don't match" << std::endl
194                 << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue()
195                 << " - Expected : 8" << std::endl
196                 << "   ... Failed" << std::endl;
197       delete fh1;
198       delete f1;
199       return 1;
200    }
201
202    // Test for entry 0028|0102
203    if ( !sqi->GetValEntry(0x0028,0x0102) )
204    {
205       std::cout << "ValEntry 0028|0102 not found" << std::endl
206                 << "   ... Failed" << std::endl;
207       delete fh1;
208       delete f1;
209       return 1;
210    }
211    std::cout << "First Item ->ValEntry 0028|0102 found" << std::endl;
212    if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
213    {
214       std::cout << "Value 0028|0102 don't match" << std::endl
215                 << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue()
216                 << " - Expected : 7" << std::endl
217                 << "   ... Failed" << std::endl;
218       delete fh1;
219       delete f1;
220       return 1;
221    }
222
223    // Test for entry 0028|0103
224    if ( !sqi->GetValEntry(0x0028,0x0103) )
225    {
226       std::cout << "ValEntry 0028|0010 not found" << std::endl
227                 << "   ... Failed" << std::endl;
228       delete fh1;
229       delete f1;
230       return 1;
231    }
232    std::cout << "First Item ->ValEntry 0028|0103 found" << std::endl;
233    if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
234    {
235       std::cout << "Value 0028|0103 don't match" << std::endl
236                 << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue()
237                 << " - Expected : 0" << std::endl
238                 << "   ... Failed" << std::endl;
239       delete fh1;
240       delete f1;
241       return 1;
242    }
243
244    // Test for entry 0005|0010
245    if ( !sqi->GetBinEntry(0x0005,0x0010) )
246    {
247       std::cout << "BinEntry 0005|0010 not found" << std::endl
248                 << "   ... Failed" << std::endl;
249       delete fh1;
250       delete f1;
251       return 1;
252    }
253    std::cout << "First Item ->BinEntry 0005|0010 found" << std::endl;
254    if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
255    {
256       std::cout << "BinEntry size 0005|0010 don't match" << std::endl
257                 << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength()
258                 << " - Expected : 6" << std::endl
259                 << "   ... Failed" << std::endl;
260       delete fh1;
261       delete f1;
262       return 1;
263    }
264
265    std::cout << "Length BinEntry 0005|0010 OK" << std::endl;
266
267    if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
268    {
269       std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
270                 << "   ... Failed" << std::endl;
271       delete fh1;
272       delete f1;
273       return 1;
274    }
275    std::cout << "Value BinEntry 0005|0010 OK" << std::endl;
276
277    delete fh1;
278    delete f1;
279    std::cout << "   ... OK" << std::endl;
280
281    return 0;
282 }