1 /*=========================================================================
4 Module: $RCSfile: TestMakeIcon.cxx,v $
6 Date: $Date: 2005/07/08 13:39:57 $
7 Version: $Revision: 1.7 $
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 *f = new gdcm::File( );
53 f->SetFileName( input );
56 if ( ! f->IsReadable() )
58 std::cout << " Failed to Open/Parse file" << input << std::endl;
62 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
63 uint8_t *pixels = fh->GetImageData();
64 uint32_t lgth = fh->GetImageDataSize();
66 gdcm::SeqEntry *icon = f->InsertSeqEntry(0x0088, 0x0200);
67 gdcm::SQItem *sqi = new gdcm::SQItem(1);
68 icon->AddSQItem(sqi, 1);
70 // icone is just define like the image
71 // The purpose is NOT to imagine an icon,
72 // just check the stuff works
74 uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
76 sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004);
77 sqi->InsertValEntry( "128", 0x0028,0x0010);
78 sqi->InsertValEntry( "8", 0x0028,0x0100);
79 sqi->InsertValEntry( "8", 0x0028,0x0101);
80 sqi->InsertValEntry( "7", 0x0028,0x0102);
81 sqi->InsertValEntry( "0", 0x0028,0x0103);
82 sqi->InsertBinEntry( (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
83 sqi->InsertBinEntry( pixels, lgth, 0x7fe0,0x0010);
84 // just to see if it's stored a the right place
85 sqi->InsertValEntry( "128", 0x0028,0x0011);
87 fh->WriteDcmExplVR(output);
91 f = new gdcm::File(output);
93 std::cout << "End of Print" << std::endl;
95 icon = f->GetSeqEntry(0x0088, 0x0200);
98 std::cout << "Sequence 0088|0200 not found" << std::endl
99 << " ... Failed" << std::endl;
104 std::cout << "Sequence 0088|0200 found" << std::endl;
106 sqi = icon->GetFirstSQItem();
110 std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
111 << " ... Failed" << std::endl;
117 std::cout << "First Item found" << std::endl;
119 // Test for entry 0028|0010
120 if ( !sqi->GetValEntry(0x0028,0x0010) )
122 std::cout << "ValEntry 0028|0010 not found" << std::endl
123 << " ... Failed" << std::endl;
128 std::cout << "First Item ->ValEntry 0028|0010 found" << std::endl;
129 if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
131 std::cout << "Value 0028|0010 don't match" << std::endl
132 << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue()
133 << " - Expected : 128" << std::endl
134 << " ... Failed" << std::endl;
140 // Test for entry 0028|0011
141 if ( !sqi->GetValEntry(0x0028,0x0011) )
143 std::cout << "ValEntry 0028|0011 not found" << std::endl
144 << " ... Failed" << std::endl;
149 std::cout << "First Item ->ValEntry 0028|0011 found" << std::endl;
150 if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
152 std::cout << "Value 0028|0011 don't match" << std::endl
153 << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue()
154 << " - Expected : 128" << std::endl
155 << " ... Failed" << std::endl;
161 // Test for entry 0028|0100
162 if ( !sqi->GetValEntry(0x0028,0x0100) )
164 std::cout << "ValEntry 0028|0100 not found" << std::endl
165 << " ... Failed" << std::endl;
170 std::cout << "First Item ->ValEntry 0028|0100 found" << std::endl;
171 if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
173 std::cout << "Value 0028|0100 don't match" << std::endl
174 << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue()
175 << " - Expected : 8" << std::endl
176 << " ... Failed" << std::endl;
182 // Test for entry 0028|0101
183 if ( !sqi->GetValEntry(0x0028,0x0101) )
185 std::cout << "ValEntry 0028|0101 not found" << std::endl
186 << " ... Failed" << std::endl;
191 std::cout << "First Item ->ValEntry 0028|0101 found" << std::endl;
192 if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
194 std::cout << "Value 0028|0101 don't match" << std::endl
195 << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue()
196 << " - Expected : 8" << std::endl
197 << " ... Failed" << std::endl;
203 // Test for entry 0028|0102
204 if ( !sqi->GetValEntry(0x0028,0x0102) )
206 std::cout << "ValEntry 0028|0102 not found" << std::endl
207 << " ... Failed" << std::endl;
212 std::cout << "First Item ->ValEntry 0028|0102 found" << std::endl;
213 if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
215 std::cout << "Value 0028|0102 don't match" << std::endl
216 << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue()
217 << " - Expected : 7" << std::endl
218 << " ... Failed" << std::endl;
224 // Test for entry 0028|0103
225 if ( !sqi->GetValEntry(0x0028,0x0103) )
227 std::cout << "ValEntry 0028|0010 not found" << std::endl
228 << " ... Failed" << std::endl;
233 std::cout << "First Item ->ValEntry 0028|0103 found" << std::endl;
234 if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
236 std::cout << "Value 0028|0103 don't match" << std::endl
237 << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue()
238 << " - Expected : 0" << std::endl
239 << " ... Failed" << std::endl;
245 // Test for entry 0005|0010
246 if ( !sqi->GetBinEntry(0x0005,0x0010) )
248 std::cout << "BinEntry 0005|0010 not found" << std::endl
249 << " ... Failed" << std::endl;
254 std::cout << "First Item ->BinEntry 0005|0010 found" << std::endl;
255 if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
257 std::cout << "BinEntry size 0005|0010 don't match" << std::endl
258 << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength()
259 << " - Expected : 6" << std::endl
260 << " ... Failed" << std::endl;
266 std::cout << "Length BinEntry 0005|0010 OK" << std::endl;
268 if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
270 std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
271 << " ... Failed" << std::endl;
276 std::cout << "Value BinEntry 0005|0010 OK" << std::endl;
280 std::cout << " ... OK" << std::endl;