/usr/include/gdcm-2.6/gdcmCP246ExplicitDataElement.txx is in libgdcm2-dev 2.6.3-3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | /*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMCP246EXPLICITDATAELEMENT_TXX
#define GDCMCP246EXPLICITDATAELEMENT_TXX
#include "gdcmSequenceOfItems.h"
#include "gdcmSequenceOfFragments.h"
#include "gdcmVL.h"
#include "gdcmParseException.h"
#include "gdcmImplicitDataElement.h"
#include "gdcmValueIO.h"
#include "gdcmSwapper.h"
namespace gdcm
{
//-----------------------------------------------------------------------------
template <typename TSwap>
std::istream &CP246ExplicitDataElement::Read(std::istream &is)
{
ReadPreValue<TSwap>(is);
return ReadValue<TSwap>(is);
}
//-----------------------------------------------------------------------------
template <typename TSwap>
std::istream &CP246ExplicitDataElement::ReadPreValue(std::istream &is)
{
TagField.Read<TSwap>(is);
// See PS 3.5, Data Element Structure With CP246Explicit VR
// Read Tag
if( !is )
{
if( !is.eof() ) // FIXME This should not be needed
{
assert(0 && "Should not happen" );
}
return is;
}
assert( TagField != Tag(0xfffe,0xe0dd) );
const Tag itemDelItem(0xfffe,0xe00d);
if( TagField == itemDelItem )
{
if( !ValueLengthField.Read<TSwap>(is) )
{
assert(0 && "Should not happen");
return is;
}
if( ValueLengthField != 0 )
{
gdcmDebugMacro(
"Item Delimitation Item has a length different from 0" );
}
// Set pointer to NULL to avoid user error
ValueField = 0;
return is;
}
// Read VR
try
{
if( !VRField.Read(is) )
{
assert(0 && "Should not happen" );
return is;
}
}
catch( std::exception & )
{
// gdcm-MR-PHILIPS-16-Multi-Seq.dcm
// assert( TagField == Tag(0xfffe, 0xe000) );
// -> For some reason VR is written as {44,0} well I guess this is a VR...
// Technically there is a second bug, dcmtk assume other things when reading this tag,
// so I need to change this tag too, if I ever want dcmtk to read this file. oh well
// 0019004_Baseline_IMG1.dcm
// -> VR is garbage also...
// assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338))
gdcmWarningMacro( "Assuming 16 bits VR for Tag=" <<
TagField << " in order to read a buggy DICOM file." );
VRField = VR::INVALID;
}
// Read Value Length
if( VR::GetLength(VRField) == 4 )
{
if( !ValueLengthField.Read<TSwap>(is) )
{
assert(0 && "Should not happen");
return is;
}
}
else
{
// 16bits only
if( !ValueLengthField.template Read16<TSwap>(is) )
{
//gdcmAssertAlwaysMacro(0 && "Should not happen");
// The following is occurs with gdcm 2.0.17 when two
// seq del item marker are found
// See UnexpectedSequenceDelimiterInFixedLengthSequence.dcm
throw Exception("Should not happen CP246");
return is;
}
}
return is;
}
//-----------------------------------------------------------------------------
template <typename TSwap>
std::istream &CP246ExplicitDataElement::ReadValue(std::istream &is, bool readvalues)
{
if( is.eof() ) return is;
if( ValueLengthField == 0 )
{
// Simple fast path
ValueField = 0;
return is;
}
//std::cerr << "exp cur tag=" << TagField << " VR=" << VRField << " VL=" << ValueLengthField << std::endl;
// Read the Value
//assert( ValueField == 0 );
if( VRField == VR::SQ )
{
// Check whether or not this is an undefined length sequence
assert( TagField != Tag(0x7fe0,0x0010) );
ValueField = new SequenceOfItems;
}
else if( ValueLengthField.IsUndefined() )
{
if( VRField == VR::UN )
{
// Support cp246 conforming file:
// Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal)
// vs
// undefined_length_un_vr.dcm
assert( TagField != Tag(0x7fe0,0x0010) );
ValueField = new SequenceOfItems;
ValueField->SetLength(ValueLengthField); // perform realloc
try
{
if( !ValueIO<CP246ExplicitDataElement,TSwap>::Read(is,*ValueField,readvalues) ) // non cp246
{
assert(0);
}
}
catch( std::exception &)
{
// Must be one of those non-cp246 file...
// but for some reason seekg back to previous offset + Read
// as CP246Explicit does not work...
ParseException pe;
pe.SetLastElement(*this);
throw pe;
}
return is;
}
else
{
// Ok this is Pixel Data fragmented...
assert( TagField == Tag(0x7fe0,0x0010) );
assert( VRField & VR::OB_OW );
ValueField = new SequenceOfFragments;
}
}
else
{
//assert( TagField != Tag(0x7fe0,0x0010) );
ValueField = new ByteValue;
}
// We have the length we should be able to read the value
ValueField->SetLength(ValueLengthField); // perform realloc
#ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
if( TagField == Tag(0x2001,0xe05f)
|| TagField == Tag(0x2001,0xe100)
|| TagField == Tag(0x2005,0xe080)
|| TagField == Tag(0x2005,0xe083)
|| TagField == Tag(0x2005,0xe084)
//TagField.IsPrivate() && VRField == VR::SQ
//-> Does not work for 0029
//we really need to read item marker
)
{
gdcmWarningMacro( "ByteSwaping Private SQ: " << TagField );
assert( VRField == VR::SQ );
try
{
if( !ValueIO<CP246ExplicitDataElement,SwapperDoOp>::Read(is,*ValueField,readvalues) )
{
assert(0 && "Should not happen");
}
}
catch( std::exception & )
{
ValueLengthField = ValueField->GetLength();
}
return is;
}
#endif
//if( !ValueField->Read<TSwap>(is) )
if( !ValueIO<CP246ExplicitDataElement,TSwap>::Read(is,*ValueField,readvalues) )
{
// Might be the famous UN 16bits
ParseException pe;
pe.SetLastElement( *this );
throw pe;
return is;
}
return is;
}
template <typename TSwap>
std::istream &CP246ExplicitDataElement::ReadWithLength(std::istream &is, VL & length)
{
(void)length;
return Read<TSwap>(is);
}
} // end namespace gdcm
#endif // GDCMCP246EXPLICITDATAELEMENT_TXX
|