1 /*=========================================================================
4 Module: $RCSfile: TestMakeIcon.cxx,v $
6 Date: $Date: 2005/02/11 13:12:05 $
7 Version: $Revision: 1.3 $
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 = "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
34 std::string output = "test.dcm";
43 std::cout << " Usage: " << argv[0]
44 << " input filename.dcm output Filename.dcm" << std::endl;
47 gdcm::File *f1 = new gdcm::File(input);
51 std::cout << " failed to open file" << std::endl;
54 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
55 uint8_t *pixels = fh1->GetImageData();
56 uint32_t lgth = fh1->GetImageDataSize();
58 gdcm::SeqEntry *icon = f1->InsertSeqEntry(0x0088, 0x0200);
59 gdcm::SQItem *sqi = new gdcm::SQItem(1);
60 icon->AddSQItem(sqi, 1);
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};
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);
78 fh1->WriteDcmExplVR(output);
82 f1 = new gdcm::File(output);
85 icon = f1->GetSeqEntry(0x0088, 0x0200);
86 sqi = icon->GetFirstSQItem();
90 std::cout << "Sequence 0088|0200 not found" << std::endl
91 << " ... Failed" << std::endl;
97 // Test for entry 0028|0010
98 if ( !sqi->GetValEntry(0x0028,0x0010) )
100 std::cout << "ValEntry 0028|0010 not found" << std::endl
101 << " ... Failed" << std::endl;
106 if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
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;
117 // Test for entry 0028|0011
118 if ( !sqi->GetValEntry(0x0028,0x0011) )
120 std::cout << "ValEntry 0028|0011 not found" << std::endl
121 << " ... Failed" << std::endl;
126 if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
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;
137 // Test for entry 0028|0100
138 if ( !sqi->GetValEntry(0x0028,0x0100) )
140 std::cout << "ValEntry 0028|0100 not found" << std::endl
141 << " ... Failed" << std::endl;
146 if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
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;
157 // Test for entry 0028|0101
158 if ( !sqi->GetValEntry(0x0028,0x0101) )
160 std::cout << "ValEntry 0028|0101 not found" << std::endl
161 << " ... Failed" << std::endl;
166 if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
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;
177 // Test for entry 0028|0102
178 if ( !sqi->GetValEntry(0x0028,0x0102) )
180 std::cout << "ValEntry 0028|0102 not found" << std::endl
181 << " ... Failed" << std::endl;
186 if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
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;
197 // Test for entry 0028|0103
198 if ( !sqi->GetValEntry(0x0028,0x0103) )
200 std::cout << "ValEntry 0028|0010 not found" << std::endl
201 << " ... Failed" << std::endl;
206 if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
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;
217 // Test for entry 0005|0010
218 if ( !sqi->GetValEntry(0x0028,0x0010) )
220 std::cout << "BinEntry 0005|0010 not found" << std::endl
221 << " ... Failed" << std::endl;
226 if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
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;
237 if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
239 std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
240 << " ... Failed" << std::endl;
248 std::cout << " ... OK" << std::endl;