1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #include "gdcmSequenceOfItems.h"
15 #include "gdcmReader.h"
16 #include "gdcmTesting.h"
17 #include "gdcmPrivateTag.h"
18 
TestSequenceOfItems2(int,char * [])19 int TestSequenceOfItems2(int, char *[])
20 {
21   const char *dataroot = gdcm::Testing::GetDataRoot();
22   // gdcmData/AMIInvalidPrivateDefinedLengthSQasUN.dcm
23   std::string filename = dataroot;
24   filename += "/AMIInvalidPrivateDefinedLengthSQasUN.dcm";
25   gdcm::Reader reader;
26   reader.SetFileName( filename.c_str() );
27   if( !reader.Read() )
28     {
29     std::cerr << "Failed to read: " << filename << std::endl;
30     return 1;
31     }
32 
33   gdcm::PrivateTag pt(0x0009,0x10,"GEIIS");
34   const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
35 
36   if( !ds.FindDataElement( pt ) )
37     {
38     return 1;
39     }
40 
41   const gdcm::DataElement &de = ds.GetDataElement( pt );
42   if( de.IsEmpty() ) return 1;
43 
44   std::cout << de << std::endl;
45 
46   gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = de.GetValueAsSQ();
47   if( !sqi ) return 1;
48 
49   //std::cout << *sqi << std::endl;
50   //sqi->Print( std::cout );
51   gdcm::SequenceOfItems::SizeType n = sqi->GetNumberOfItems();
52   if( n != 1 ) return 1;
53 
54   const gdcm::Item & item = sqi->GetItem( 1 );
55   const gdcm::DataSet &subds = item.GetNestedDataSet();
56 
57   // std::cout << subds << std::endl;
58   gdcm::Tag ticonpixeldata(0x7fe0,0x0010);
59   //const gdcm::DataElement &iconpixeldata = subds.GetDataElement( ticonpixeldata );
60 //  const gdcm::ByteValue *bv = iconpixeldata.GetByteValue();//unused unless that lower #def is set to true
61 
62   // I could test that gdcm::JPEGCodec::GetHeaderInfo return JPEG file:
63   // JPEG image data, JFIF standard 1.01
64 
65   gdcm::PrivateTag tgeiiscompressiontype(0x7fd1,0x10,"GEIIS");
66   const gdcm::DataElement &geiiscompressiontype = subds.GetDataElement( tgeiiscompressiontype );
67   gdcm::Element<gdcm::VR::UL,gdcm::VM::VM1> el;
68   el.SetFromDataElement( geiiscompressiontype );
69 
70   unsigned int v = el.GetValue();
71   if( v != 26 ) return 1;
72 
73 #if 0
74   std::ofstream of( "/tmp/o.jpg", std::ios::binary );
75   of.write( bv->GetPointer(), bv->GetLength() );
76   of.close();
77 #endif
78 
79   return 0;
80 }
81