1 /*=========================================================================
4 Module: $RCSfile: TestMakeIcon.cxx,v $
6 Date: $Date: 2005/10/18 08:35:46 $
7 Version: $Revision: 1.9 $
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 "gdcmDataEntry.h"
24 #include "gdcmSeqEntry.h"
25 #include "gdcmSQItem.h"
27 // 0088 0200 SQ 1 Icon Image Sequence
29 int TestMakeIcon (int argc, char *argv[])
31 // hard coded small image name
32 std::string input = GDCM_DATA_ROOT;
34 input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
36 std::string output = "testIcon.dcm";
38 gdcm::Debug::DebugOn();
47 std::cout << " Usage: " << argv[0]
48 << " input filename.dcm output Filename.dcm" << std::endl;
51 gdcm::File *f = new gdcm::File( );
52 f->SetFileName( input );
55 if ( ! f->IsReadable() )
57 std::cout << " Failed to Open/Parse file" << input << std::endl;
61 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
62 uint8_t *pixels = fh->GetImageData();
63 uint32_t lgth = fh->GetImageDataSize();
65 gdcm::SeqEntry *icon = f->InsertSeqEntry(0x0088, 0x0200);
66 gdcm::SQItem *sqi = new gdcm::SQItem(1);
67 icon->AddSQItem(sqi, 1);
69 // icone is just define like the image
70 // The purpose is NOT to imagine an icon,
71 // just check the stuff works
73 uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
75 sqi->InsertEntryString( "MONOCHROME2", 0x0028,0x0004);
76 sqi->InsertEntryString( "128", 0x0028,0x0010);
77 sqi->InsertEntryString( "8", 0x0028,0x0100);
78 sqi->InsertEntryString( "8", 0x0028,0x0101);
79 sqi->InsertEntryString( "7", 0x0028,0x0102);
80 sqi->InsertEntryString( "0", 0x0028,0x0103);
81 sqi->InsertEntryBinArea( (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
82 sqi->InsertEntryBinArea( pixels, lgth, 0x7fe0,0x0010);
83 // just to see if it's stored a the right place
84 sqi->InsertEntryString( "128", 0x0028,0x0011);
86 fh->WriteDcmExplVR(output);
91 f->SetFileName(output);
94 std::cout << "End of Print" << std::endl;
96 icon = f->GetSeqEntry(0x0088, 0x0200);
99 std::cout << "Sequence 0088|0200 not found" << std::endl
100 << " ... Failed" << std::endl;
105 std::cout << "Sequence 0088|0200 found" << std::endl;
107 sqi = icon->GetFirstSQItem();
111 std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
112 << " ... Failed" << std::endl;
118 std::cout << "First Item found" << std::endl;
120 // Test for entry 0028|0010
121 if ( !sqi->GetDataEntry(0x0028,0x0010) )
123 std::cout << "GetDataEntry 0028|0010 not found" << std::endl
124 << " ... Failed" << std::endl;
129 std::cout << "First Item ->DataEntry 0028|0010 found" << std::endl;
130 if ( sqi->GetDataEntry(0x0028,0x0010)->GetString() != "128" )
132 std::cout << "Value 0028|0010 don't match" << std::endl
133 << "Read : " << sqi->GetDataEntry(0x0028,0x0010)->GetString()
134 << " - Expected : 128" << std::endl
135 << " ... Failed" << std::endl;
141 // Test for entry 0028|0011
142 if ( !sqi->GetDataEntry(0x0028,0x0011) )
144 std::cout << "GetDataEntry 0028|0011 not found" << std::endl
145 << " ... Failed" << std::endl;
150 std::cout << "First Item ->DataEntry 0028|0011 found" << std::endl;
151 if ( sqi->GetDataEntry(0x0028,0x0011)->GetString() != "128" )
153 std::cout << "Value 0028|0011 don't match" << std::endl
154 << "Read : " << sqi->GetDataEntry(0x0028,0x0011)->GetString()
155 << " - Expected : 128" << std::endl
156 << " ... Failed" << std::endl;
162 // Test for entry 0028|0100
163 if ( !sqi->GetDataEntry(0x0028,0x0100) )
165 std::cout << "GetDataEntry 0028|0100 not found" << std::endl
166 << " ... Failed" << std::endl;
171 std::cout << "First Item ->DataEntry 0028|0100 found" << std::endl;
172 if ( sqi->GetDataEntry(0x0028,0x0100)->GetString() != "8" )
174 std::cout << "Value 0028|0100 don't match" << std::endl
175 << "Read : " << sqi->GetDataEntry(0x0028,0x0100)->GetString()
176 << " - Expected : 8" << std::endl
177 << " ... Failed" << std::endl;
183 // Test for entry 0028|0101
184 if ( !sqi->GetDataEntry(0x0028,0x0101) )
186 std::cout << "GetDataEntry 0028|0101 not found" << std::endl
187 << " ... Failed" << std::endl;
192 std::cout << "First Item ->DataEntry 0028|0101 found" << std::endl;
193 if ( sqi->GetDataEntry(0x0028,0x0101)->GetString() != "8" )
195 std::cout << "Value 0028|0101 don't match" << std::endl
196 << "Read : " << sqi->GetDataEntry(0x0028,0x0101)->GetString()
197 << " - Expected : 8" << std::endl
198 << " ... Failed" << std::endl;
204 // Test for entry 0028|0102
205 if ( !sqi->GetDataEntry(0x0028,0x0102) )
207 std::cout << "DataEntry 0028|0102 not found" << std::endl
208 << " ... Failed" << std::endl;
213 std::cout << "First Item ->DataEntry 0028|0102 found" << std::endl;
214 if ( sqi->GetDataEntry(0x0028,0x0102)->GetString() != "7" )
216 std::cout << "Value 0028|0102 don't match" << std::endl
217 << "Read : " << sqi->GetDataEntry(0x0028,0x0102)->GetString()
218 << " - Expected : 7" << std::endl
219 << " ... Failed" << std::endl;
225 // Test for entry 0028|0103
226 if ( !sqi->GetDataEntry(0x0028,0x0103) )
228 std::cout << "GetDataEntry 0028|0010 not found" << std::endl
229 << " ... Failed" << std::endl;
234 std::cout << "First Item ->DataEntry 0028|0103 found" << std::endl;
235 if ( sqi->GetDataEntry(0x0028,0x0103)->GetString() != "0" )
237 std::cout << "Value 0028|0103 don't match" << std::endl
238 << "Read : " << sqi->GetDataEntry(0x0028,0x0103)->GetString()
239 << " - Expected : 0" << std::endl
240 << " ... Failed" << std::endl;
246 // Test for entry 0005|0010
247 if ( !sqi->GetDataEntry(0x0005,0x0010) )
249 std::cout << "GetDataEntry 0005|0010 not found" << std::endl
250 << " ... Failed" << std::endl;
255 std::cout << "First Item ->GetDataEntry 0005|0010 found" << std::endl;
256 if( sqi->GetDataEntry(0x0005,0x0010)->GetLength() != 6 )
258 std::cout << "GetDataEntry size 0005|0010 don't match" << std::endl
259 << "Read : " << sqi->GetDataEntry(0x0005,0x0010)->GetLength()
260 << " - Expected : 6" << std::endl
261 << " ... Failed" << std::endl;
267 std::cout << "Length GetDataEntry 0005|0010 OK" << std::endl;
269 if( memcmp(sqi->GetDataEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
271 std::cout << "Value 0005|0010 don't match (DataEntry)" << std::endl
272 << " ... Failed" << std::endl;
277 std::cout << "Value DataEntry 0005|0010 OK" << std::endl;
281 std::cout << " ... OK" << std::endl;