7 #include <netinet/in.h>
9 #include <cctype> // for isalpha
14 #define HEADER_LENGHT_TO_READ 256 // on ne lit plus que le debut
17 struct FileReadError {
18 FileReadError(FILE* fp, const char* Mesg) {
20 dbg.Verbose(1, "EOF encountered :", Mesg);
22 dbg.Verbose(1, "Error on reading :", Mesg);
27 //FIXME: this looks dirty to me...
28 #define str2num(str, typeNum) *((typeNum *)(str))
30 VRHT * gdcmHeader::dicom_vr = (VRHT*)0;
31 gdcmDictSet* gdcmHeader::Dicts = new gdcmDictSet();
33 void gdcmHeader::Initialise(void) {
34 if (!gdcmHeader::dicom_vr)
36 RefPubDict = gdcmHeader::Dicts->GetDefaultPublicDict();
37 RefShaDict = (gdcmDict*)0;
40 gdcmHeader::gdcmHeader (const char* InFilename) {
41 SetMaxSizeLoadElementValue(1024);
42 filename = InFilename;
44 fp=fopen(InFilename,"rw");
45 dbg.Error(!fp, "gdcmHeader::gdcmHeader cannot open file", InFilename);
49 gdcmHeader::~gdcmHeader (void) {
54 void gdcmHeader::InitVRDict (void) {
56 dbg.Verbose(0, "gdcmHeader::InitVRDict:", "VR dictionary allready set");
60 (*vr)["AE"] = "Application Entity"; // At most 16 bytes
61 (*vr)["AS"] = "Age String"; // Exactly 4 bytes
62 (*vr)["AT"] = "Attribute Tag"; // 2 16-bit unsigned short integers
63 (*vr)["CS"] = "Code String"; // At most 16 bytes
64 (*vr)["DA"] = "Date"; // Exactly 8 bytes
65 (*vr)["DS"] = "Decimal String"; // At most 16 bytes
66 (*vr)["DT"] = "Date Time"; // At most 26 bytes
67 (*vr)["FL"] = "Floating Point Single"; // 32-bit IEEE 754:1985 float
68 (*vr)["FD"] = "Floating Point Double"; // 64-bit IEEE 754:1985 double
69 (*vr)["IS"] = "Integer String"; // At most 12 bytes
70 (*vr)["LO"] = "Long String"; // At most 64 chars
71 (*vr)["LT"] = "Long Text"; // At most 10240 chars
72 (*vr)["OB"] = "Other Byte String"; // String of bytes (vr independant)
73 (*vr)["OW"] = "Other Word String"; // String of 16-bit words (vr dep)
74 (*vr)["PN"] = "Person Name"; // At most 64 chars
75 (*vr)["SH"] = "Short String"; // At most 16 chars
76 (*vr)["SL"] = "Signed Long"; // Exactly 4 bytes
77 (*vr)["SQ"] = "Sequence of Items"; // Not Applicable
78 (*vr)["SS"] = "Signed Short"; // Exactly 2 bytes
79 (*vr)["ST"] = "Short Text"; // At most 1024 chars
80 (*vr)["TM"] = "Time"; // At most 16 bytes
81 (*vr)["UI"] = "Unique Identifier"; // At most 64 bytes
82 (*vr)["UL"] = "Unsigned Long "; // Exactly 4 bytes
83 (*vr)["UN"] = "Unknown"; // Any length of bytes
84 (*vr)["US"] = "Unsigned Short "; // Exactly 2 bytes
85 (*vr)["UT"] = "Unlimited Text"; // At most 2^32 -1 chars
91 * \brief La seule maniere sure que l'on aie pour determiner
92 * si on est en LITTLE_ENDIAN, BIG-ENDIAN,
93 * BAD-LITTLE-ENDIAN, BAD-BIG-ENDIAN
94 * est de trouver l'element qui donne la longueur d'un 'GROUP'
95 * (on sait que la longueur de cet element vaut 0x00000004)
96 * et de regarder comment cette longueur est codee en memoire
98 * Le probleme vient de ce que parfois, il n'y en a pas ...
100 * On fait alors le pari qu'on a a faire a du LITTLE_ENDIAN propre.
101 * (Ce qui est la norme -pas respectee- depuis ACR-NEMA)
102 * Si ce n'est pas le cas, on ne peut rien faire.
104 * (il faudrait avoir des fonctions auxquelles
105 * on passe le code Swap en parametre, pour faire des essais 'manuels')
107 void gdcmHeader::CheckSwap()
110 guint32 x=4; // x : pour ntohs
111 bool net2host; // true when HostByteOrder is the same as NetworkByteOrder
115 char deb[HEADER_LENGHT_TO_READ];
117 // First, compare HostByteOrder and NetworkByteOrder in order to
118 // determine if we shall need to swap bytes (i.e. the Endian type).
124 // The easiest case is the one of a DICOM header, since it possesses a
125 // file preamble where it suffice to look for the sting "DICM".
126 lgrLue = fread(deb, 1, HEADER_LENGHT_TO_READ, fp);
129 if(memcmp(entCur, "DICM", (size_t)4) == 0) {
130 filetype = TrueDicom;
131 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "looks like DICOM Version3");
134 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "not a DICOM Version3 file");
137 if(filetype == TrueDicom) {
138 // Next, determine the value representation (VR). Let's skip to the
139 // first element (0002, 0000) and check there if we find "UL", in
140 // which case we (almost) know it is explicit VR.
141 // WARNING: if it happens to be implicit VR then what we will read
142 // is the length of the group. If this ascii representation of this
143 // length happens to be "UL" then we shall believe it is explicit VR.
144 // FIXME: in order to fix the above warning, we could read the next
145 // element value (or a couple of elements values) in order to make
146 // sure we are not commiting a big mistake.
148 // * the 128 bytes of File Preamble (often padded with zeroes),
149 // * the 4 bytes of "DICM" string,
150 // * the 4 bytes of the first tag (0002, 0000),
151 // i.e. a total of 136 bytes.
153 if(memcmp(entCur, "UL", (size_t)2) == 0) {
154 filetype = ExplicitVR;
155 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
156 "explicit Value Representation");
158 filetype = ImplicitVR;
159 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
160 "not an explicit Value Representation");
165 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
166 "HostByteOrder != NetworkByteOrder");
169 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
170 "HostByteOrder = NetworkByteOrder");
173 // Position the file position indicator at first tag (i.e.
174 // after the file preamble and the "DICM" string).
176 fseek (fp, 132L, SEEK_SET);
178 } // End of TrueDicom
180 // Alas, this is not a DicomV3 file and whatever happens there is no file
181 // preamble. We can reset the file position indicator to where the data
182 // is (i.e. the beginning of the file).
185 // Our next best chance would be to be considering a 'clean' ACR/NEMA file.
186 // By clean we mean that the length of the first tag is written down.
187 // If this is the case and since the length of the first group HAS to be
188 // four (bytes), then determining the proper swap code is straightforward.
191 s = str2num(entCur, guint32);
211 dbg.Verbose(0, "gdcmHeader::CheckSwap:",
212 "ACE/NEMA unfound swap info (time to raise bets)");
215 // We are out of luck. It is not a DicomV3 nor a 'clean' ACR/NEMA file.
216 // It is time for despaired wild guesses. So, let's assume this file
217 // happens to be 'dirty' ACR/NEMA, i.e. the length of the group is
218 // not present. Then the only info we have is the net2host one.
219 //FIXME Si c'est du RAW, ca degagera + tard
228 void gdcmHeader::SwitchSwapToBigEndian(void) {
229 dbg.Verbose(1, "gdcmHeader::SwitchSwapToBigEndian",
230 "Switching to BigEndian mode.");
248 * \ingroup gdcmHeader
249 * \brief recupere la longueur d'un champ DICOM.
251 * 1/ le fichier doit deja avoir ete ouvert,
252 * 2/ CheckSwap() doit avoir ete appele
253 * 3/ la partie 'group' ainsi que la partie 'elem'
254 * de l'acr_element doivent avoir ete lues.
256 * ACR-NEMA : we allways get
257 * GroupNumber (2 Octets)
258 * ElementNumber (2 Octets)
259 * ElementSize (4 Octets)
260 * DICOM en implicit Value Representation :
261 * GroupNumber (2 Octets)
262 * ElementNumber (2 Octets)
263 * ElementSize (4 Octets)
265 * DICOM en explicit Value Representation :
266 * GroupNumber (2 Octets)
267 * ElementNumber (2 Octets)
268 * ValueRepresentation (2 Octets)
269 * ElementSize (2 Octets)
271 * ATTENTION : dans le cas ou ValueRepresentation = OB, OW, SQ, UN
272 * GroupNumber (2 Octets)
273 * ElementNumber (2 Octets)
274 * ValueRepresentation (2 Octets)
275 * zone reservee (2 Octets)
276 * ElementSize (4 Octets)
278 * @param sw code swap
279 * @param skippedLength pointeur sur nombre d'octets que l'on a saute qd
280 * la lecture est finie
281 * @param longueurLue pointeur sur longueur (en nombre d'octets)
283 * @return longueur retenue pour le champ
286 void gdcmHeader::FindVR( ElValue *ElVal) {
287 if (filetype != ExplicitVR)
293 long PositionOnEntry = ftell(fp);
294 // Warning: we believe this is explicit VR (Value Representation) because
295 // we used a heuristic that found "UL" in the first tag. Alas this
296 // doesn't guarantee that all the tags will be in explicit VR. In some
297 // cases (see e-film filtered files) one finds implicit VR tags mixed
298 // within an explicit VR file. Hence we make sure the present tag
299 // is in explicit VR and try to fix things if it happens not to be
301 bool RealExplicit = true;
303 lgrLue=fread (&VR, (size_t)2,(size_t)1, fp);
307 // Assume we are reading a falsely explicit VR file i.e. we reached
308 // a tag where we expect reading a VR but are in fact we read the
309 // first to bytes of the length. Then we will interogate (through find)
310 // the dicom_vr dictionary with oddities like "\004\0" which crashes
311 // both GCC and VC++ implentations of the STL map. Hence when the
312 // expected VR read happens to be non-ascii characters we consider
313 // we hit falsely explicit VR tag.
315 if ( (!isalpha(VR[0])) && (!isalpha(VR[1])) )
316 RealExplicit = false;
318 // CLEANME searching the dicom_vr at each occurence is expensive.
319 // PostPone this test in an optional integrity check at the end
320 // of parsing or only in debug mode.
321 if ( RealExplicit && !dicom_vr->count(vr) )
322 RealExplicit = false;
324 if ( RealExplicit ) {
325 if ( ElVal->IsVrUnknown() ) {
326 // When not a dictionary entry, we can safely overwrite the vr.
330 if ( ElVal->GetVR() == vr ) {
331 // The vr we just read and the dictionary agree. Nothing to do.
334 // The vr present in the file and the dictionary disagree. We assume
335 // the file writer knew best and use the vr of the file. Since it would
336 // be unwise to overwrite the vr of a dictionary (since it would
337 // compromise it's next user), we need to clone the actual DictEntry
338 // and change the vr for the read one.
339 gdcmDictEntry* NewTag = new gdcmDictEntry(ElVal->GetGroup(),
344 ElVal->SetDictEntry(NewTag);
348 // We thought this was explicit VR, but we end up with an
349 // implicit VR tag. Let's backtrack.
350 dbg.Verbose(1, "gdcmHeader::FindVR:", "Falsely explicit vr file");
351 fseek(fp, PositionOnEntry, SEEK_SET);
352 // When this element is known in the dictionary we shall use, e.g. for
353 // the semantics (see the usage of IsAnInteger), the vr proposed by the
354 // dictionary entry. Still we have to flag the element as implicit since
355 // we know now our assumption on expliciteness is not furfilled.
357 if ( ElVal->IsVrUnknown() )
358 ElVal->SetVR("Implicit");
359 ElVal->SetImplicitVr();
363 * \ingroup gdcmHeader
364 * \brief Determines if the Transfer Syntax was allready encountered
365 * and if it corresponds to a Big Endian one.
367 * @return True when big endian found. False in all other cases.
369 bool gdcmHeader::IsBigEndianTransferSyntax(void) {
370 ElValue* Element = PubElVals.GetElement(0x0002, 0x0010);
373 LoadElementValueSafe(Element);
374 string Transfer = Element->GetValue();
375 if ( Transfer == "1.2.840.10008.1.2.2" )
380 void gdcmHeader::FixFoundLength(ElValue * ElVal, guint32 FoudLength) {
381 // Heuristic: a final fix.
382 if ( FoudLength == 0xffffffff)
384 ElVal->SetLength(FoudLength);
387 guint32 gdcmHeader::FindLengthOB(void) {
388 // See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
391 long PositionOnEntry = ftell(fp);
392 bool FoundSequenceDelimiter = false;
393 guint32 TotalLength = 0;
396 while ( ! FoundSequenceDelimiter) {
399 TotalLength += 4; // We even have to decount the group and element
401 dbg.Verbose(1, "gdcmHeader::FindLengthOB: ",
402 "wrong group for an item sequence.");
403 throw Error::FileReadError(fp, "gdcmHeader::FindLengthOB");
406 FoundSequenceDelimiter = true;
407 else if ( n != 0xe000) {
408 dbg.Verbose(1, "gdcmHeader::FindLengthOB: ",
409 "wrong element for an item sequence.");
410 throw Error::FileReadError(fp, "gdcmHeader::FindLengthOB");
412 ItemLength = ReadInt32();
413 TotalLength += ItemLength + 4; // We add 4 bytes since we just read
414 // the ItemLength with ReadInt32
415 SkipBytes(ItemLength);
417 fseek(fp, PositionOnEntry, SEEK_SET);
421 void gdcmHeader::FindLength(ElValue * ElVal) {
422 guint16 element = ElVal->GetElement();
423 string vr = ElVal->GetVR();
426 if ( (filetype == ExplicitVR) && ! ElVal->IsImplicitVr() ) {
428 if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) {
429 // The following reserved two bytes (see PS 3.5-2001, section
430 // 7.1.2 Data element structure with explicit vr p27) must be
431 // skipped before proceeding on reading the length on 4 bytes.
432 fseek(fp, 2L, SEEK_CUR);
433 guint32 length32 = ReadInt32();
434 if ( (vr == "OB") && (length32 == 0xffffffff) ) {
435 ElVal->SetLength(FindLengthOB());
438 FixFoundLength(ElVal, length32);
442 // Length is encoded on 2 bytes.
443 length16 = ReadInt16();
445 // We can tell the current file is encoded in big endian (like
446 // Data/US-RGB-8-epicard) when we find the "Transfer Syntax" tag
447 // and it's value is the one of the encoding of a big endian file.
448 // In order to deal with such big endian encoded files, we have
449 // (at least) two strategies:
450 // * when we load the "Transfer Syntax" tag with value of big endian
451 // encoding, we raise the proper flags. Then we wait for the end
452 // of the META group (0x0002) among which is "Transfer Syntax",
453 // before switching the swap code to big endian. We have to postpone
454 // the switching of the swap code since the META group is fully encoded
455 // in little endian, and big endian coding only starts at the next
456 // group. The corresponding code can be hard to analyse and adds
457 // many additional unnecessary tests for regular tags.
458 // * the second strategy consist in waiting for trouble, that shall appear
459 // when we find the first group with big endian encoding. This is
460 // easy to detect since the length of a "Group Length" tag (the
461 // ones with zero as element number) has to be of 4 (0x0004). When we
462 // encouter 1024 (0x0400) chances are the encoding changed and we
463 // found a group with big endian encoding.
464 // We shall use this second strategy. In order make sure that we
465 // can interpret the presence of an apparently big endian encoded
466 // length of a "Group Length" without committing a big mistake, we
467 // add an additional check: we look in the allready parsed elements
468 // for the presence of a "Transfer Syntax" whose value has to be "big
469 // endian encoding". When this is the case, chances are we got our
470 // hands on a big endian encoded file: we switch the swap code to
471 // big endian and proceed...
472 if ( (element == 0) && (length16 == 1024) ) {
473 if ( ! IsBigEndianTransferSyntax() )
474 throw Error::FileReadError(fp, "gdcmHeader::FindLength");
476 SwitchSwapToBigEndian();
477 // Restore the unproperly loaded values i.e. the group, the element
478 // and the dictionary entry depending on them.
479 guint16 CorrectGroup = SwapShort(ElVal->GetGroup());
480 guint16 CorrectElem = SwapShort(ElVal->GetElement());
481 gdcmDictEntry * NewTag = IsInDicts(CorrectGroup, CorrectElem);
483 // This correct tag is not in the dictionary. Create a new one.
484 NewTag = new gdcmDictEntry(CorrectGroup, CorrectElem);
486 // FIXME this can create a memory leaks on the old entry that be
487 // left unreferenced.
488 ElVal->SetDictEntry(NewTag);
491 // Heuristic: well some files are really ill-formed.
492 if ( length16 == 0xffff) {
494 dbg.Verbose(0, "gdcmHeader::FindLength",
495 "Erroneous element length fixed.");
497 FixFoundLength(ElVal, (guint32)length16);
501 // Either implicit VR or a non DICOM conformal (see not below) explicit
502 // VR that ommited the VR of (at least) this element. Farts happen.
503 // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25
504 // on Data elements "Implicit and Explicit VR Data Elements shall
505 // not coexist in a Data Set and Data Sets nested within it".]
506 // Length is on 4 bytes.
507 FixFoundLength(ElVal, ReadInt32());
511 * \ingroup gdcmHeader
512 * \brief Swaps back the bytes of 4-byte long integer accordingly to
515 * @return The suggested integer.
517 guint32 gdcmHeader::SwapLong(guint32 a) {
518 // FIXME: il pourrait y avoir un pb pour les entiers negatifs ...
523 a=( ((a<<24) & 0xff000000) | ((a<<8) & 0x00ff0000) |
524 ((a>>8) & 0x0000ff00) | ((a>>24) & 0x000000ff) );
528 a=( ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
532 a=( ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) );
535 dbg.Error(" gdcmHeader::SwapLong : unset swap code");
542 * \ingroup gdcmHeader
543 * \brief Swaps the bytes so they agree with the processor order
544 * @return The properly swaped 16 bits integer.
546 guint16 gdcmHeader::SwapShort(guint16 a) {
547 if ( (sw==4321) || (sw==2143) )
548 a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
552 void gdcmHeader::SkipBytes(guint32 NBytes) {
553 //FIXME don't dump the returned value
554 (void)fseek(fp, (long)NBytes, SEEK_CUR);
557 void gdcmHeader::SkipElementValue(ElValue * ElVal) {
558 SkipBytes(ElVal->GetLength());
561 void gdcmHeader::SetMaxSizeLoadElementValue(long NewSize) {
564 if ((guint32)NewSize >= (guint32)0xffffffff) {
565 MaxSizeLoadElementValue = 0xffffffff;
568 MaxSizeLoadElementValue = NewSize;
572 * \ingroup gdcmHeader
573 * \brief Loads the element if it's size is not to big.
574 * @param ElVal Element whose value shall be loaded.
575 * @param MaxSize Size treshold above which the element value is not
576 * loaded in memory. The element value is allways loaded
577 * when MaxSize is equal to UINT32_MAX.
580 void gdcmHeader::LoadElementValue(ElValue * ElVal) {
582 guint16 group = ElVal->GetGroup();
583 guint16 elem = ElVal->GetElement();
584 string vr = ElVal->GetVR();
585 guint32 length = ElVal->GetLength();
586 bool SkipLoad = false;
588 fseek(fp, (long)ElVal->GetOffset(), SEEK_SET);
590 // Sequences not treated yet !
594 // Heuristic : a sequence "contains" a set of tags (called items). It looks
595 // like the last tag of a sequence (the one that terminates the sequence)
596 // has a group of 0xfffe (with a dummy length).
597 if( group == 0xfffe )
600 // The group length doesn't represent data to be loaded in memory, since
601 // each element of the group shall be loaded individualy.
606 // FIXME the following skip is not necessary
607 SkipElementValue(ElVal);
609 ElVal->SetValue("gdcm::Skipped");
613 // When the length is zero things are easy:
619 // Values bigger than specified are not loaded.
620 if (length > MaxSizeLoadElementValue) {
622 s << "gdcm::NotLoaded.";
623 s << " Address:" << (long)ElVal->GetOffset();
624 s << " Length:" << ElVal->GetLength();
625 //mesg += " Length:" + ElVal->GetLength();
626 ElVal->SetValue(s.str());
630 // When an integer is expected, read and convert the following two or
631 // four bytes properly i.e. as an integer as opposed to a string.
632 if ( IsAnInteger(ElVal) ) {
635 NewInt = ReadInt16();
636 } else if( length == 4 ) {
637 NewInt = ReadInt32();
639 dbg.Error(true, "LoadElementValue: Inconsistency when reading Int.");
641 //FIXME: make the following an util fonction
644 ElVal->SetValue(s.str());
648 // FIXME The exact size should be length if we move to strings or whatever
649 char* NewValue = (char*)g_malloc(length+1);
651 dbg.Verbose(1, "LoadElementValue: Failed to allocate NewValue");
656 item_read = fread(NewValue, (size_t)length, (size_t)1, fp);
657 if ( item_read != 1 ) {
659 Error::FileReadError(fp, "gdcmHeader::LoadElementValue");
660 ElVal->SetValue("gdcm::UnRead");
663 ElVal->SetValue(NewValue);
667 * \ingroup gdcmHeader
668 * \brief Loads the element while preserving the current
669 * underlying file position indicator as opposed to
670 * to LoadElementValue that modifies it.
671 * @param ElVal Element whose value shall be loaded.
674 void gdcmHeader::LoadElementValueSafe(ElValue * ElVal) {
675 long PositionOnEntry = ftell(fp);
676 LoadElementValue(ElVal);
677 fseek(fp, PositionOnEntry, SEEK_SET);
681 guint16 gdcmHeader::ReadInt16(void) {
684 item_read = fread (&g, (size_t)2,(size_t)1, fp);
685 if ( item_read != 1 )
686 throw Error::FileReadError(fp, "gdcmHeader::ReadInt16");
691 guint32 gdcmHeader::ReadInt32(void) {
694 item_read = fread (&g, (size_t)4,(size_t)1, fp);
695 if ( item_read != 1 )
696 throw Error::FileReadError(fp, "gdcmHeader::ReadInt32");
702 * \ingroup gdcmHeader
703 * \brief Read the next tag without loading it's value
704 * @return On succes the newly created ElValue, NULL on failure.
707 ElValue * gdcmHeader::ReadNextElement(void) {
716 catch ( Error::FileReadError ) {
717 // We reached the EOF (or an error occured) and header parsing
718 // has to be considered as finished.
722 // Find out if the tag we encountered is in the dictionaries:
723 gdcmDictEntry * NewTag = IsInDicts(g, n);
725 NewTag = new gdcmDictEntry(g, n);
727 NewElVal = new ElValue(NewTag);
729 dbg.Verbose(1, "ReadNextElement: failed to allocate ElValue");
734 try { FindLength(NewElVal); }
735 catch ( Error::FileReadError ) { // Call it quits
738 NewElVal->SetOffset(ftell(fp));
742 bool gdcmHeader::IsAnInteger(ElValue * ElVal) {
743 guint16 group = ElVal->GetGroup();
744 guint16 element = ElVal->GetElement();
745 string vr = ElVal->GetVR();
746 guint32 length = ElVal->GetLength();
748 // When we have some semantics on the element we just read, and if we
749 // a priori know we are dealing with an integer, then we shall be
750 // able to swap it's element value properly.
751 if ( element == 0 ) { // This is the group length of the group
755 dbg.Error("gdcmHeader::IsAnInteger",
756 "Erroneous Group Length element length.");
759 if ( group % 2 != 0 )
760 // We only have some semantics on documented elements, which are
764 if ( (length != 4) && ( length != 2) )
765 // Swapping only make sense on integers which are 2 or 4 bytes long.
768 if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") )
771 if ( (group == 0x0028) && (element == 0x0005) )
772 // This tag is retained from ACR/NEMA
773 // CHECKME Why should "Image Dimensions" be a single integer ?
776 if ( (group == 0x0028) && (element == 0x0200) )
777 // This tag is retained from ACR/NEMA
784 * \ingroup gdcmHeader
785 * \brief Recover the offset (from the beginning of the file) of the pixels.
787 size_t gdcmHeader::GetPixelOffset(void) {
788 // If this file complies with the norm we should encounter the
789 // "Image Location" tag (0x0028, 0x0200). This tag contains the
790 // the group that contains the pixel data (hence the "Pixel Data"
791 // is found by indirection through the "Image Location").
792 // Inside the group pointed by "Image Location" the searched element
793 // is conventionally the element 0x0010 (when the norm is respected).
794 // When the "Image Location" is absent we default to group 0x7fe0.
797 string ImageLocation = GetPubElValByName("Image Location");
798 if ( ImageLocation == "UNFOUND" ) {
801 grPixel = (guint16) atoi( ImageLocation.c_str() );
803 if (grPixel != 0x7fe0)
804 // FIXME is this still necessary ?
805 // Now, this looks like an old dirty fix for Philips imager
809 ElValue* PixelElement = PubElVals.GetElement(grPixel, numPixel);
811 return PixelElement->GetOffset();
816 gdcmDictEntry * gdcmHeader::IsInDicts(guint32 group, guint32 element) {
817 gdcmDictEntry * found = (gdcmDictEntry*)0;
818 if (!RefPubDict && !RefShaDict) {
819 //FIXME build a default dictionary !
820 printf("FIXME in gdcmHeader::IsInDicts\n");
823 found = RefPubDict->GetTag(group, element);
828 found = RefShaDict->GetTag(group, element);
835 string gdcmHeader::GetPubElValByNumber(guint16 group, guint16 element) {
836 return PubElVals.GetElValue(group, element);
839 string gdcmHeader::GetPubElValByName(string TagName) {
840 return PubElVals.GetElValue(TagName);
844 * \ingroup gdcmHeader
845 * \brief Parses the header of the file but does NOT load element values.
847 void gdcmHeader::ParseHeader(void) {
848 ElValue * newElValue = (ElValue *)0;
852 while ( (newElValue = ReadNextElement()) ) {
853 SkipElementValue(newElValue);
854 PubElVals.Add(newElValue);
859 * \ingroup gdcmHeader
860 * \brief Loads the element values of all the elements present in the
861 * public tag based hash table.
863 void gdcmHeader::LoadElements(void) {
865 TagElValueHT ht = PubElVals.GetTagHt();
866 for (TagElValueHT::iterator tag = ht.begin(); tag != ht.end(); ++tag)
867 LoadElementValue(tag->second);
870 void gdcmHeader::PrintPubElVal(ostream & os) {
874 void gdcmHeader::PrintPubDict(ostream & os) {
875 RefPubDict->Print(os);