1 /*=========================================================================
4 Module: $RCSfile: TestMakeIcon.cxx,v $
6 Date: $Date: 2005/04/25 14:35:21 $
7 Version: $Revision: 1.5 $
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 "gdcmDebug.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmCommon.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmSeqEntry.h"
24 #include "gdcmSQItem.h"
25 #include "gdcmValEntry.h"
26 #include "gdcmBinEntry.h"
28 // 0088 0200 SQ 1 Icon Image Sequence
30 int TestMakeIcon (int argc, char *argv[])
32 // hard coded small image name
33 std::string input = GDCM_DATA_ROOT;
35 input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
37 std::string output = "testIcon.dcm";
39 gdcm::Debug::DebugOn();
48 std::cout << " Usage: " << argv[0]
49 << " input filename.dcm output Filename.dcm" << std::endl;
52 gdcm::File *f1 = new gdcm::File(input);
56 std::cout << " failed to open file" << std::endl;
59 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
60 uint8_t *pixels = fh1->GetImageData();
61 uint32_t lgth = fh1->GetImageDataSize();
63 gdcm::SeqEntry *icon = f1->InsertSeqEntry(0x0088, 0x0200);
64 gdcm::SQItem *sqi = new gdcm::SQItem(1);
65 icon->AddSQItem(sqi, 1);
67 // icone is just define like the image
68 // The purpose is NOT to imagine an icon,
69 // just check the stuff works
71 uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
73 sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004);
74 sqi->InsertValEntry( "128", 0x0028,0x0010);
75 sqi->InsertValEntry( "8", 0x0028,0x0100);
76 sqi->InsertValEntry( "8", 0x0028,0x0101);
77 sqi->InsertValEntry( "7", 0x0028,0x0102);
78 sqi->InsertValEntry( "0", 0x0028,0x0103);
79 sqi->InsertBinEntry( (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
80 sqi->InsertBinEntry( pixels, lgth, 0x7fe0,0x0010);
81 // just to see if it's stored a the right place
82 sqi->InsertValEntry( "128", 0x0028,0x0011);
84 fh1->WriteDcmExplVR(output);
88 f1 = new gdcm::File(output);
90 std::cout << "End of Print" << std::endl;
92 icon = f1->GetSeqEntry(0x0088, 0x0200);
95 std::cout << "Sequence 0088|0200 not found" << std::endl
96 << " ... Failed" << std::endl;
101 std::cout << "Sequence 0088|0200 found" << std::endl;
103 sqi = icon->GetFirstSQItem();
107 std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
108 << " ... Failed" << std::endl;
114 std::cout << "First Item found" << std::endl;
116 // Test for entry 0028|0010
117 if ( !sqi->GetValEntry(0x0028,0x0010) )
119 std::cout << "ValEntry 0028|0010 not found" << std::endl
120 << " ... Failed" << std::endl;
125 std::cout << "First Item ->ValEntry 0028|0010 found" << std::endl;
126 if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
128 std::cout << "Value 0028|0010 don't match" << std::endl
129 << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue()
130 << " - Expected : 128" << std::endl
131 << " ... Failed" << std::endl;
137 // Test for entry 0028|0011
138 if ( !sqi->GetValEntry(0x0028,0x0011) )
140 std::cout << "ValEntry 0028|0011 not found" << std::endl
141 << " ... Failed" << std::endl;
146 std::cout << "First Item ->ValEntry 0028|0011 found" << std::endl;
147 if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
149 std::cout << "Value 0028|0011 don't match" << std::endl
150 << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue()
151 << " - Expected : 128" << std::endl
152 << " ... Failed" << std::endl;
158 // Test for entry 0028|0100
159 if ( !sqi->GetValEntry(0x0028,0x0100) )
161 std::cout << "ValEntry 0028|0100 not found" << std::endl
162 << " ... Failed" << std::endl;
167 std::cout << "First Item ->ValEntry 0028|0100 found" << std::endl;
168 if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
170 std::cout << "Value 0028|0100 don't match" << std::endl
171 << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue()
172 << " - Expected : 8" << std::endl
173 << " ... Failed" << std::endl;
179 // Test for entry 0028|0101
180 if ( !sqi->GetValEntry(0x0028,0x0101) )
182 std::cout << "ValEntry 0028|0101 not found" << std::endl
183 << " ... Failed" << std::endl;
188 std::cout << "First Item ->ValEntry 0028|0101 found" << std::endl;
189 if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
191 std::cout << "Value 0028|0101 don't match" << std::endl
192 << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue()
193 << " - Expected : 8" << std::endl
194 << " ... Failed" << std::endl;
200 // Test for entry 0028|0102
201 if ( !sqi->GetValEntry(0x0028,0x0102) )
203 std::cout << "ValEntry 0028|0102 not found" << std::endl
204 << " ... Failed" << std::endl;
209 std::cout << "First Item ->ValEntry 0028|0102 found" << std::endl;
210 if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
212 std::cout << "Value 0028|0102 don't match" << std::endl
213 << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue()
214 << " - Expected : 7" << std::endl
215 << " ... Failed" << std::endl;
221 // Test for entry 0028|0103
222 if ( !sqi->GetValEntry(0x0028,0x0103) )
224 std::cout << "ValEntry 0028|0010 not found" << std::endl
225 << " ... Failed" << std::endl;
230 std::cout << "First Item ->ValEntry 0028|0103 found" << std::endl;
231 if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
233 std::cout << "Value 0028|0103 don't match" << std::endl
234 << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue()
235 << " - Expected : 0" << std::endl
236 << " ... Failed" << std::endl;
242 // Test for entry 0005|0010
243 if ( !sqi->GetBinEntry(0x0005,0x0010) )
245 std::cout << "BinEntry 0005|0010 not found" << std::endl
246 << " ... Failed" << std::endl;
251 std::cout << "First Item ->BinEntry 0005|0010 found" << std::endl;
252 if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
254 std::cout << "BinEntry size 0005|0010 don't match" << std::endl
255 << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength()
256 << " - Expected : 6" << std::endl
257 << " ... Failed" << std::endl;
263 std::cout << "Length BinEntry 0005|0010 OK" << std::endl;
265 if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
267 std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
268 << " ... Failed" << std::endl;
273 std::cout << "Value BinEntry 0005|0010 OK" << std::endl;
277 std::cout << " ... OK" << std::endl;