1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.121 2003/12/22 12:46:16 regrain Exp $
3 #include "gdcmHeader.h"
11 #include <netinet/in.h>
13 #include <cctype> // for isalpha
15 #ifdef GDCM_NO_ANSI_STRING_STREAM
17 # define ostringstream ostrstream
25 // Refer to gdcmHeader::CheckSwap()
26 #define HEADER_LENGTH_TO_READ 256
27 // Refer to gdcmHeader::SetMaxSizeLoadElementValue()
28 //#define _MaxSizeLoadElementValue_ 1024
29 #define _MaxSizeLoadElementValue_ 4096
34 void gdcmHeader::Initialise(void) {
35 dicom_vr = gdcmGlobal::GetVR();
36 dicom_ts = gdcmGlobal::GetTS();
37 Dicts = gdcmGlobal::GetDicts();
38 RefPubDict = Dicts->GetDefaultPubDict();
39 RefShaDict = (gdcmDict*)0;
46 * @param exception_on_error
48 gdcmHeader::gdcmHeader(const char *InFilename,
49 bool exception_on_error,
50 bool enable_sequences ) {
56 SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
57 filename = InFilename;
59 if ( !OpenFile(exception_on_error))
69 * @param exception_on_error
71 gdcmHeader::gdcmHeader(bool exception_on_error) {
72 SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
79 * @param exception_on_error
82 FILE *gdcmHeader::OpenFile(bool exception_on_error)
83 throw(gdcmFileError) {
84 fp=fopen(filename.c_str(),"rb");
85 if(exception_on_error) {
87 throw gdcmFileError("gdcmHeader::gdcmHeader(const char *, bool)");
92 fread(&zero, (size_t)2, (size_t)1, fp);
94 //ACR -- or DICOM with no Preamble
95 if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
99 fseek(fp, 126L, SEEK_CUR);
101 fread(dicm, (size_t)4, (size_t)1, fp);
102 if( memcmp(dicm, "DICM", 4) == 0 )
106 dbg.Verbose(0, "gdcmHeader::gdcmHeader not DICOM/ACR", filename.c_str());
109 dbg.Verbose(0, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
115 * \ingroup gdcmHeader
117 * @return TRUE if the close was successfull
119 bool gdcmHeader::CloseFile(void) {
120 int closed = fclose(fp);
128 * \ingroup gdcmHeader
129 * \brief Canonical destructor.
131 gdcmHeader::~gdcmHeader (void) {
132 dicom_vr = (gdcmVR*)0;
133 Dicts = (gdcmDictSet*)0;
134 RefPubDict = (gdcmDict*)0;
135 RefShaDict = (gdcmDict*)0;
141 // ---> Warning : This fourth field is NOT part
142 // of the 'official' Dicom Dictionnary
143 // and should NOT be used.
144 // (Not defined for all the groups
145 // may be removed in a future release)
148 // META Meta Information
160 // NMI Nuclear Medicine
162 // BFS Basic Film Session
163 // BFB Basic Film Box
164 // BIB Basic Image Box
180 * \ingroup gdcmHeader
181 * \brief Discover what the swap code is (among little endian, big endian,
182 * bad little endian, bad big endian).
185 void gdcmHeader::CheckSwap()
187 // The only guaranted way of finding the swap code is to find a
188 // group tag since we know it's length has to be of four bytes i.e.
189 // 0x00000004. Finding the swap code in then straigthforward. Trouble
190 // occurs when we can't find such group...
192 guint32 x=4; // x : for ntohs
193 bool net2host; // true when HostByteOrder is the same as NetworkByteOrder
197 char deb[HEADER_LENGTH_TO_READ];
199 // First, compare HostByteOrder and NetworkByteOrder in order to
200 // determine if we shall need to swap bytes (i.e. the Endian type).
206 // The easiest case is the one of a DICOM header, since it possesses a
207 // file preamble where it suffice to look for the string "DICM".
208 lgrLue = fread(deb, 1, HEADER_LENGTH_TO_READ, fp);
211 if(memcmp(entCur, "DICM", (size_t)4) == 0) {
212 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "looks like DICOM Version3");
213 // Next, determine the value representation (VR). Let's skip to the
214 // first element (0002, 0000) and check there if we find "UL"
215 // - or "OB" if the 1st one is (0002,0001) -,
216 // in which case we (almost) know it is explicit VR.
217 // WARNING: if it happens to be implicit VR then what we will read
218 // is the length of the group. If this ascii representation of this
219 // length happens to be "UL" then we shall believe it is explicit VR.
220 // FIXME: in order to fix the above warning, we could read the next
221 // element value (or a couple of elements values) in order to make
222 // sure we are not commiting a big mistake.
224 // * the 128 bytes of File Preamble (often padded with zeroes),
225 // * the 4 bytes of "DICM" string,
226 // * the 4 bytes of the first tag (0002, 0000),or (0002, 0001)
227 // i.e. a total of 136 bytes.
230 // Use gdcmHeader::dicom_vr to test all the possibilities
231 // instead of just checking for UL, OB and UI !?
232 if( (memcmp(entCur, "UL", (size_t)2) == 0) ||
233 (memcmp(entCur, "OB", (size_t)2) == 0) ||
234 (memcmp(entCur, "UI", (size_t)2) == 0) )
236 filetype = ExplicitVR;
237 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
238 "explicit Value Representation");
240 filetype = ImplicitVR;
241 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
242 "not an explicit Value Representation");
246 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
247 "HostByteOrder != NetworkByteOrder");
250 dbg.Verbose(1, "gdcmHeader::CheckSwap:",
251 "HostByteOrder = NetworkByteOrder");
254 // Position the file position indicator at first tag (i.e.
255 // after the file preamble and the "DICM" string).
257 fseek (fp, 132L, SEEK_SET);
261 // Alas, this is not a DicomV3 file and whatever happens there is no file
262 // preamble. We can reset the file position indicator to where the data
263 // is (i.e. the beginning of the file).
264 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "not a DICOM Version3 file");
267 // Our next best chance would be to be considering a 'clean' ACR/NEMA file.
268 // By clean we mean that the length of the first tag is written down.
269 // If this is the case and since the length of the first group HAS to be
270 // four (bytes), then determining the proper swap code is straightforward.
273 // We assume the array of char we are considering contains the binary
274 // representation of a 32 bits integer. Hence the following dirty
276 s = *((guint32 *)(entCur));
296 dbg.Verbose(0, "gdcmHeader::CheckSwap:",
297 "ACR/NEMA unfound swap info (time to raise bets)");
300 // We are out of luck. It is not a DicomV3 nor a 'clean' ACR/NEMA file.
301 // It is time for despaired wild guesses. So, let's assume this file
302 // happens to be 'dirty' ACR/NEMA, i.e. the length of the group is
303 // not present. Then the only info we have is the net2host one.
313 * \ingroup gdcmHeader
316 void gdcmHeader::SwitchSwapToBigEndian(void) {
317 dbg.Verbose(1, "gdcmHeader::SwitchSwapToBigEndian",
318 "Switching to BigEndian mode.");
336 * \ingroup gdcmHeader
337 * \brief Find the value representation of the current tag.
340 void gdcmHeader::FindVR( gdcmElValue *ElVal) {
341 if (filetype != ExplicitVR)
347 char msg[100]; // for sprintf. Sorry
349 long PositionOnEntry = ftell(fp);
350 // Warning: we believe this is explicit VR (Value Representation) because
351 // we used a heuristic that found "UL" in the first tag. Alas this
352 // doesn't guarantee that all the tags will be in explicit VR. In some
353 // cases (see e-film filtered files) one finds implicit VR tags mixed
354 // within an explicit VR file. Hence we make sure the present tag
355 // is in explicit VR and try to fix things if it happens not to be
357 bool RealExplicit = true;
359 lgrLue=fread (&VR, (size_t)2,(size_t)1, fp);
361 vr = std::string(VR);
363 // Assume we are reading a falsely explicit VR file i.e. we reached
364 // a tag where we expect reading a VR but are in fact we read the
365 // first to bytes of the length. Then we will interogate (through find)
366 // the dicom_vr dictionary with oddities like "\004\0" which crashes
367 // both GCC and VC++ implementations of the STL map. Hence when the
368 // expected VR read happens to be non-ascii characters we consider
369 // we hit falsely explicit VR tag.
371 if ( (!isalpha(VR[0])) && (!isalpha(VR[1])) )
372 RealExplicit = false;
374 // CLEANME searching the dicom_vr at each occurence is expensive.
375 // PostPone this test in an optional integrity check at the end
376 // of parsing or only in debug mode.
377 if ( RealExplicit && !dicom_vr->Count(vr) )
380 if ( RealExplicit ) {
381 if ( ElVal->IsVrUnknown() ) {
382 // When not a dictionary entry, we can safely overwrite the vr.
386 if ( ElVal->GetVR() == vr ) {
387 // The vr we just read and the dictionary agree. Nothing to do.
390 // The vr present in the file and the dictionary disagree. We assume
391 // the file writer knew best and use the vr of the file. Since it would
392 // be unwise to overwrite the vr of a dictionary (since it would
393 // compromise it's next user), we need to clone the actual DictEntry
394 // and change the vr for the read one.
395 gdcmDictEntry* NewTag = new gdcmDictEntry(ElVal->GetGroup(),
400 ElVal->SetDictEntry(NewTag);
404 // We thought this was explicit VR, but we end up with an
405 // implicit VR tag. Let's backtrack.
407 sprintf(msg,"Falsely explicit vr file (%04x,%04x)\n",
408 ElVal->GetGroup(),ElVal->GetElement());
409 dbg.Verbose(1, "gdcmHeader::FindVR: ",msg);
411 fseek(fp, PositionOnEntry, SEEK_SET);
412 // When this element is known in the dictionary we shall use, e.g. for
413 // the semantics (see the usage of IsAnInteger), the vr proposed by the
414 // dictionary entry. Still we have to flag the element as implicit since
415 // we know now our assumption on expliciteness is not furfilled.
417 if ( ElVal->IsVrUnknown() )
418 ElVal->SetVR("Implicit");
419 ElVal->SetImplicitVr();
423 * \ingroup gdcmHeader
424 * \brief Determines if the Transfer Syntax was already encountered
425 * and if it corresponds to a ImplicitVRLittleEndian one.
427 * @return True when ImplicitVRLittleEndian found. False in all other cases.
429 bool gdcmHeader::IsImplicitVRLittleEndianTransferSyntax(void) {
430 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
433 LoadElementValueSafe(Element);
434 std::string Transfer = Element->GetValue();
435 if ( Transfer == "1.2.840.10008.1.2" )
441 * \ingroup gdcmHeader
442 * \brief Determines if the Transfer Syntax was already encountered
443 * and if it corresponds to a ExplicitVRLittleEndian one.
445 * @return True when ExplicitVRLittleEndian found. False in all other cases.
447 bool gdcmHeader::IsExplicitVRLittleEndianTransferSyntax(void) {
448 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
451 LoadElementValueSafe(Element);
452 std::string Transfer = Element->GetValue();
453 if ( Transfer == "1.2.840.10008.1.2.1" )
459 * \ingroup gdcmHeader
460 * \brief Determines if the Transfer Syntax was already encountered
461 * and if it corresponds to a DeflatedExplicitVRLittleEndian one.
463 * @return True when DeflatedExplicitVRLittleEndian found. False in all other cases.
465 bool gdcmHeader::IsDeflatedExplicitVRLittleEndianTransferSyntax(void) {
466 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
469 LoadElementValueSafe(Element);
470 std::string Transfer = Element->GetValue();
471 if ( Transfer == "1.2.840.10008.1.2.1.99" )
477 * \ingroup gdcmHeader
478 * \brief Determines if the Transfer Syntax was already encountered
479 * and if it corresponds to a Explicit VR Big Endian one.
481 * @return True when big endian found. False in all other cases.
483 bool gdcmHeader::IsExplicitVRBigEndianTransferSyntax(void) {
484 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
487 LoadElementValueSafe(Element);
488 std::string Transfer = Element->GetValue();
489 if ( Transfer == "1.2.840.10008.1.2.2" ) //1.2.2 ??? A verifier !
495 * \ingroup gdcmHeader
496 * \brief Determines if the Transfer Syntax was already encountered
497 * and if it corresponds to a JPEGBaseLineProcess1 one.
499 * @return True when JPEGBaseLineProcess1found. False in all other cases.
501 bool gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(void) {
502 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
505 LoadElementValueSafe(Element);
506 std::string Transfer = Element->GetValue();
507 if ( Transfer == "1.2.840.10008.1.2.4.50" )
513 * \ingroup gdcmHeader
518 bool gdcmHeader::IsJPEGLossless(void) {
519 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
520 // faire qq chose d'intelligent a la place de ça
523 LoadElementValueSafe(Element);
524 const char * Transfert = Element->GetValue().c_str();
525 if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
526 if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
527 if (Element->GetValue() == "1.2.840.10008.1.2.4.57") return true;
534 * \ingroup gdcmHeader
535 * \brief Determines if the Transfer Syntax was already encountered
536 * and if it corresponds to a JPEGExtendedProcess2-4 one.
538 * @return True when JPEGExtendedProcess2-4 found. False in all other cases.
540 bool gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(void) {
541 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
544 LoadElementValueSafe(Element);
545 std::string Transfer = Element->GetValue();
546 if ( Transfer == "1.2.840.10008.1.2.4.51" )
552 * \ingroup gdcmHeader
553 * \brief Determines if the Transfer Syntax was already encountered
554 * and if it corresponds to a JPEGExtendeProcess3-5 one.
556 * @return True when JPEGExtendedProcess3-5 found. False in all other cases.
558 bool gdcmHeader::IsJPEGExtendedProcess3_5TransferSyntax(void) {
559 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
562 LoadElementValueSafe(Element);
563 std::string Transfer = Element->GetValue();
564 if ( Transfer == "1.2.840.10008.1.2.4.52" )
570 * \ingroup gdcmHeader
571 * \brief Determines if the Transfer Syntax was already encountered
572 * and if it corresponds to a JPEGSpectralSelectionProcess6-8 one.
574 * @return True when JPEGSpectralSelectionProcess6-8 found. False in all
577 bool gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(void) {
578 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
581 LoadElementValueSafe(Element);
582 std::string Transfer = Element->GetValue();
583 if ( Transfer == "1.2.840.10008.1.2.4.53" )
589 * \ingroup gdcmHeader
590 * \brief Determines if the Transfer Syntax was already encountered
591 * and if it corresponds to a RLE Lossless one.
593 * @return True when RLE Lossless found. False in all
596 bool gdcmHeader::IsRLELossLessTransferSyntax(void) {
597 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
600 LoadElementValueSafe(Element);
601 std::string Transfer = Element->GetValue();
602 if ( Transfer == "1.2.840.10008.1.2.5" )
608 * \ingroup gdcmHeader
609 * \brief Determines if the Transfer Syntax was already encountered
610 * and if it corresponds to a JPEG200 one.0
612 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
615 bool gdcmHeader::IsJPEG2000(void) {
616 gdcmElValue* Element = PubElValSet.GetElementByNumber(0x0002, 0x0010);
619 LoadElementValueSafe(Element);
620 std::string Transfer = Element->GetValue();
621 if ( (Transfer == "1.2.840.10008.1.2.4.90")
622 || (Transfer == "1.2.840.10008.1.2.4.91") )
628 * \ingroup gdcmHeader
629 * \brief Predicate for dicom version 3 file.
630 * @return True when the file is a dicom version 3.
632 bool gdcmHeader::IsDicomV3(void) {
633 if ( (filetype == ExplicitVR)
634 || (filetype == ImplicitVR) )
640 * \ingroup gdcmHeader
641 * \brief When the length of an element value is obviously wrong (because
642 * the parser went Jabberwocky) one can hope improving things by
643 * applying this heuristic.
645 void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
647 ElVal->SetReadLength(FoundLength); // will be updated only if a bug is found
649 if ( FoundLength == 0xffffffff) {
653 // Sorry for the patch!
654 // XMedCom did the trick to read some nasty GE images ...
655 else if (FoundLength == 13) {
656 // The following 'if' will be removed when there is no more
657 // images on Creatis HDs with a 13 length for Manufacturer...
658 if ( (ElVal->GetGroup() != 0x0008) ||
659 ( (ElVal->GetElement() != 0x0070) && (ElVal->GetElement() != 0x0080) ) ) {
660 // end of remove area
662 ElVal->SetReadLength(10); // a bug is to be fixed
665 // to fix some garbage 'Leonardo' Siemens images
666 // May be commented out to avoid overhead
667 else if ( (ElVal->GetGroup() == 0x0009)
669 ( (ElVal->GetElement() == 0x1113) || (ElVal->GetElement() == 0x1114) ) ){
671 ElVal->SetReadLength(4); // a bug is to be fixed
675 // to try to 'go inside' SeQuences (with length), and not to skip them
676 else if ( ElVal->GetVR() == "SQ") {
677 if (enableSequences) // only if the user does want to !
681 // a SeQuence Element is beginning
682 // Let's forget it's length
683 // (we want to 'go inside')
684 else if(ElVal->GetGroup() == 0xfffe){
688 ElVal->SetUsableLength(FoundLength);
692 * \ingroup gdcmHeader
697 guint32 gdcmHeader::FindLengthOB(void) {
698 // See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
701 long PositionOnEntry = ftell(fp);
702 bool FoundSequenceDelimiter = false;
703 guint32 TotalLength = 0;
706 while ( ! FoundSequenceDelimiter) {
711 TotalLength += 4; // We even have to decount the group and element
713 if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */ {
714 char msg[100]; // for sprintf. Sorry
715 sprintf(msg,"wrong group (%04x) for an item sequence (%04x,%04x)\n",g, g,n);
716 dbg.Verbose(1, "gdcmHeader::FindLengthOB: ",msg);
720 if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header */
721 FoundSequenceDelimiter = true;
722 else if ( n != 0xe000 ){
723 char msg[100]; // for sprintf. Sorry
724 sprintf(msg,"wrong element (%04x) for an item sequence (%04x,%04x)\n",
726 dbg.Verbose(1, "gdcmHeader::FindLengthOB: ",msg);
730 ItemLength = ReadInt32();
731 TotalLength += ItemLength + 4; // We add 4 bytes since we just read
732 // the ItemLength with ReadInt32
733 SkipBytes(ItemLength);
735 fseek(fp, PositionOnEntry, SEEK_SET);
740 * \ingroup gdcmHeader
745 void gdcmHeader::FindLength (gdcmElValue * ElVal) {
746 guint16 element = ElVal->GetElement();
747 guint16 group = ElVal->GetGroup();
748 std::string vr = ElVal->GetVR();
750 if( (element == 0x0010) && (group == 0x7fe0) ) {
752 dbg.Verbose(2, "gdcmHeader::FindLength: ",
753 "we reached 7fe0 0010");
756 if ( (filetype == ExplicitVR) && ! ElVal->IsImplicitVr() ) {
757 if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) {
759 // The following reserved two bytes (see PS 3.5-2001, section
760 // 7.1.2 Data element structure with explicit vr p27) must be
761 // skipped before proceeding on reading the length on 4 bytes.
762 fseek(fp, 2L, SEEK_CUR);
764 guint32 length32 = ReadInt32();
766 if ( (vr == "OB") && (length32 == 0xffffffff) ) {
767 ElVal->SetLength(FindLengthOB());
770 FixFoundLength(ElVal, length32);
774 // Length is encoded on 2 bytes.
775 length16 = ReadInt16();
777 // We can tell the current file is encoded in big endian (like
778 // Data/US-RGB-8-epicard) when we find the "Transfer Syntax" tag
779 // and it's value is the one of the encoding of a big endian file.
780 // In order to deal with such big endian encoded files, we have
781 // (at least) two strategies:
782 // * when we load the "Transfer Syntax" tag with value of big endian
783 // encoding, we raise the proper flags. Then we wait for the end
784 // of the META group (0x0002) among which is "Transfer Syntax",
785 // before switching the swap code to big endian. We have to postpone
786 // the switching of the swap code since the META group is fully encoded
787 // in little endian, and big endian coding only starts at the next
788 // group. The corresponding code can be hard to analyse and adds
789 // many additional unnecessary tests for regular tags.
790 // * the second strategy consists in waiting for trouble, that shall
791 // appear when we find the first group with big endian encoding. This
792 // is easy to detect since the length of a "Group Length" tag (the
793 // ones with zero as element number) has to be of 4 (0x0004). When we
794 // encounter 1024 (0x0400) chances are the encoding changed and we
795 // found a group with big endian encoding.
796 // We shall use this second strategy. In order to make sure that we
797 // can interpret the presence of an apparently big endian encoded
798 // length of a "Group Length" without committing a big mistake, we
799 // add an additional check: we look in the already parsed elements
800 // for the presence of a "Transfer Syntax" whose value has to be "big
801 // endian encoding". When this is the case, chances are we have got our
802 // hands on a big endian encoded file: we switch the swap code to
803 // big endian and proceed...
804 if ( (element == 0x0000) && (length16 == 0x0400) ) {
805 if ( ! IsExplicitVRBigEndianTransferSyntax() ) {
806 dbg.Verbose(0, "gdcmHeader::FindLength", "not explicit VR");
811 SwitchSwapToBigEndian();
812 // Restore the unproperly loaded values i.e. the group, the element
813 // and the dictionary entry depending on them.
814 guint16 CorrectGroup = SwapShort(ElVal->GetGroup());
815 guint16 CorrectElem = SwapShort(ElVal->GetElement());
816 gdcmDictEntry * NewTag = GetDictEntryByNumber(CorrectGroup,
819 // This correct tag is not in the dictionary. Create a new one.
820 NewTag = new gdcmDictEntry(CorrectGroup, CorrectElem);
822 // FIXME this can create a memory leaks on the old entry that be
823 // left unreferenced.
824 ElVal->SetDictEntry(NewTag);
827 // Heuristic: well some files are really ill-formed.
828 if ( length16 == 0xffff) {
830 //dbg.Verbose(0, "gdcmHeader::FindLength",
831 // "Erroneous element length fixed.");
832 // Actually, length= 0xffff means that we deal with
833 // Unknown Sequence Length
836 FixFoundLength(ElVal, (guint32)length16);
840 // Either implicit VR or a non DICOM conformal (see not below) explicit
841 // VR that ommited the VR of (at least) this element. Farts happen.
842 // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25
843 // on Data elements "Implicit and Explicit VR Data Elements shall
844 // not coexist in a Data Set and Data Sets nested within it".]
845 // Length is on 4 bytes.
846 FixFoundLength(ElVal, ReadInt32());
851 * \ingroup gdcmHeader
852 * \brief Swaps back the bytes of 4-byte long integer accordingly to
854 * @return The properly swaped 32 bits integer.
856 guint32 gdcmHeader::SwapLong(guint32 a) {
861 a=( ((a<<24) & 0xff000000) | ((a<<8) & 0x00ff0000) |
862 ((a>>8) & 0x0000ff00) | ((a>>24) & 0x000000ff) );
866 a=( ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
870 a=( ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) );
873 dbg.Error(" gdcmHeader::SwapLong : unset swap code");
880 * \ingroup gdcmHeader
881 * \brief Swaps the bytes so they agree with the processor order
882 * @return The properly swaped 16 bits integer.
884 guint16 gdcmHeader::SwapShort(guint16 a) {
885 if ( (sw==4321) || (sw==2143) )
886 a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
891 * \ingroup gdcmHeader
896 void gdcmHeader::SkipBytes(guint32 NBytes) {
897 //FIXME don't dump the returned value
898 (void)fseek(fp, (long)NBytes, SEEK_CUR);
902 * \ingroup gdcmHeader
907 void gdcmHeader::SkipElementValue(gdcmElValue * ElVal) {
908 SkipBytes(ElVal->GetLength());
912 * \ingroup gdcmHeader
917 void gdcmHeader::SetMaxSizeLoadElementValue(long NewSize) {
920 if ((guint32)NewSize >= (guint32)0xffffffff) {
921 MaxSizeLoadElementValue = 0xffffffff;
924 MaxSizeLoadElementValue = NewSize;
928 * \ingroup gdcmHeader
929 * \brief Loads the element content if it's length is not bigger
930 * than the value specified with
931 * gdcmHeader::SetMaxSizeLoadElementValue()
933 void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
935 guint16 group = ElVal->GetGroup();
936 std::string vr= ElVal->GetVR();
937 guint32 length = ElVal->GetLength();
938 bool SkipLoad = false;
940 fseek(fp, (long)ElVal->GetOffset(), SEEK_SET);
942 // FIXME Sequences not treated yet !
944 // Ne faudrait-il pas au contraire trouver immediatement
945 // une maniere 'propre' de traiter les sequences (vr = SQ)
946 // car commencer par les ignorer risque de conduire a qq chose
947 // qui pourrait ne pas etre generalisable
948 // Well, I'm expecting your code !!!
950 // the test was commented out to 'go inside' the SeQuences
951 // we don't any longer skip them !
956 // A SeQuence "contains" a set of Elements.
957 // (fffe e000) tells us an Element is beginning
958 // (fffe e00d) tells us an Element just ended
959 // (fffe e0dd) tells us the current SeQuence just ended
961 if( group == 0xfffe )
966 ElVal->SetValue("gdcm::Skipped");
970 // When the length is zero things are easy:
976 // The elements whose length is bigger than the specified upper bound
977 // are not loaded. Instead we leave a short notice of the offset of
978 // the element content and it's length.
979 if (length > MaxSizeLoadElementValue) {
980 std::ostringstream s;
981 s << "gdcm::NotLoaded.";
982 s << " Address:" << (long)ElVal->GetOffset();
983 s << " Length:" << ElVal->GetLength();
984 s << " x(" << std::hex << ElVal->GetLength() << ")";
985 ElVal->SetValue(s.str());
989 // When an integer is expected, read and convert the following two or
990 // four bytes properly i.e. as an integer as opposed to a string.
992 // Actually, elements with Value Multiplicity > 1
993 // contain a set of integers (not a single one)
994 // Any compacter code suggested (?)
996 if ( IsAnInteger(ElVal) ) {
998 std::ostringstream s;
1000 if (vr == "US" || vr == "SS") {
1002 NewInt = ReadInt16();
1005 for (int i=1; i < nbInt; i++) {
1007 NewInt = ReadInt16();
1012 } else if (vr == "UL" || vr == "SL") {
1014 NewInt = ReadInt32();
1017 for (int i=1; i < nbInt; i++) {
1019 NewInt = ReadInt32();
1024 #ifdef GDCM_NO_ANSI_STRING_STREAM
1025 s << std::ends; // to avoid oddities on Solaris
1026 #endif //GDCM_NO_ANSI_STRING_STREAM
1027 ElVal->SetValue(s.str());
1031 // We need an additional byte for storing \0 that is not on disk
1032 char* NewValue = (char*)malloc(length+1);
1034 dbg.Verbose(1, "LoadElementValue: Failed to allocate NewValue");
1037 NewValue[length]= 0;
1039 item_read = fread(NewValue, (size_t)length, (size_t)1, fp);
1040 if ( item_read != 1 ) {
1042 dbg.Verbose(1, "gdcmHeader::LoadElementValue","unread element value");
1043 ElVal->SetValue("gdcm::UnRead");
1046 ElVal->SetValue(NewValue);
1051 * \ingroup gdcmHeader
1052 * \brief Loads the element while preserving the current
1053 * underlying file position indicator as opposed to
1054 * to LoadElementValue that modifies it.
1055 * @param ElVal Element whose value shall be loaded.
1058 void gdcmHeader::LoadElementValueSafe(gdcmElValue * ElVal) {
1059 long PositionOnEntry = ftell(fp);
1060 LoadElementValue(ElVal);
1061 fseek(fp, PositionOnEntry, SEEK_SET);
1065 * \ingroup gdcmHeader
1066 * \brief Reads a supposed to be 16 Bits integer
1067 * \ (swaps it depending on processor endianity)
1069 * @return integer acts as a boolean
1071 guint16 gdcmHeader::ReadInt16(void) {
1074 item_read = fread (&g, (size_t)2,(size_t)1, fp);
1075 if ( item_read != 1 ) {
1076 // dbg.Verbose(0, "gdcmHeader::ReadInt16", " Failed to read :");
1078 // dbg.Verbose(0, "gdcmHeader::ReadInt16", " End of File encountered");
1080 dbg.Verbose(0, "gdcmHeader::ReadInt16", " File Error");
1090 * \ingroup gdcmHeader
1091 * \brief Reads a supposed to be 32 Bits integer
1092 * \ (swaps it depending on processor endianity)
1096 guint32 gdcmHeader::ReadInt32(void) {
1099 item_read = fread (&g, (size_t)4,(size_t)1, fp);
1100 if ( item_read != 1 ) {
1101 //dbg.Verbose(0, "gdcmHeader::ReadInt32", " Failed to read :");
1103 // dbg.Verbose(0, "gdcmHeader::ReadInt32", " End of File encountered");
1105 dbg.Verbose(0, "gdcmHeader::ReadInt32", " File Error");
1115 * \ingroup gdcmHeader
1120 gdcmElValue* gdcmHeader::GetElValueByNumber(guint16 Group, guint16 Elem) {
1122 gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
1124 dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
1125 "failed to Locate gdcmElValue");
1126 return (gdcmElValue*)0;
1132 * \ingroup gdcmHeader
1133 * \brief Build a new Element Value from all the low level arguments.
1134 * Check for existence of dictionary entry, and build
1135 * a default one when absent.
1136 * @param Group group of the underlying DictEntry
1137 * @param Elem element of the underlying DictEntry
1139 gdcmElValue* gdcmHeader::NewElValueByNumber(guint16 Group, guint16 Elem) {
1140 // Find out if the tag we encountered is in the dictionaries:
1141 gdcmDictEntry * NewTag = GetDictEntryByNumber(Group, Elem);
1143 NewTag = new gdcmDictEntry(Group, Elem);
1145 gdcmElValue* NewElVal = new gdcmElValue(NewTag);
1147 dbg.Verbose(1, "gdcmHeader::NewElValueByNumber",
1148 "failed to allocate gdcmElValue");
1149 return (gdcmElValue*)0;
1155 * \ingroup gdcmHeader
1160 * \return integer acts as a boolean
1162 int gdcmHeader::ReplaceOrCreateByNumber(std::string Value,
1163 guint16 Group, guint16 Elem ) {
1164 // TODO : FIXME JPRx
1166 // on (je) cree une Elvalue ne contenant pas de valeur
1167 // on l'ajoute au ElValSet
1168 // on affecte une valeur a cette ElValue a l'interieur du ElValSet
1169 // --> devrait pouvoir etre fait + simplement ???
1170 if (CheckIfExistByNumber(Group, Elem) == 0) {
1171 gdcmElValue* a =NewElValueByNumber(Group, Elem);
1176 PubElValSet.SetElValueByNumber(Value, Group, Elem);
1182 * \ingroup gdcmHeader
1183 * \brief Modify (or Creates if not found) an element
1184 * @param Value new value
1187 * \return integer acts as a boolean
1190 int gdcmHeader::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
1192 gdcmElValue* nvElValue=NewElValueByNumber(Group, Elem);
1193 PubElValSet.Add(nvElValue);
1194 std::string v = Value;
1195 PubElValSet.SetElValueByNumber(v, Group, Elem);
1201 * \ingroup gdcmHeader
1202 * \brief Set a new value if the invoked element exists
1203 * Seems to be useless !!!
1207 * \return integer acts as a boolean
1209 int gdcmHeader::ReplaceIfExistByNumber(char* Value, guint16 Group, guint16 Elem ) {
1211 //gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
1212 std::string v = Value;
1213 PubElValSet.SetElValueByNumber(v, Group, Elem);
1219 * \ingroup gdcmHeader
1220 * \brief Checks if a given ElValue (group,number)
1221 * \ exists in the Public ElValSet
1224 * @return integer acts as a boolean
1227 int gdcmHeader::CheckIfExistByNumber(guint16 Group, guint16 Elem ) {
1228 return (PubElValSet.CheckIfExistByNumber(Group, Elem));
1232 * \ingroup gdcmHeader
1233 * \brief Build a new Element Value from all the low level arguments.
1234 * Check for existence of dictionary entry, and build
1235 * a default one when absent.
1236 * @param Name Name of the underlying DictEntry
1238 gdcmElValue* gdcmHeader::NewElValueByName(std::string Name) {
1240 gdcmDictEntry * NewTag = GetDictEntryByName(Name);
1242 NewTag = new gdcmDictEntry(0xffff, 0xffff, "LO", "Unknown", Name);
1244 gdcmElValue* NewElVal = new gdcmElValue(NewTag);
1246 dbg.Verbose(1, "gdcmHeader::ObtainElValueByName",
1247 "failed to allocate gdcmElValue");
1248 return (gdcmElValue*)0;
1254 * \ingroup gdcmHeader
1255 * \brief Read the next tag but WITHOUT loading it's value
1256 * @return On succes the newly created ElValue, NULL on failure.
1258 gdcmElValue * gdcmHeader::ReadNextElement(void) {
1261 gdcmElValue * NewElVal;
1267 // We reached the EOF (or an error occured) and header parsing
1268 // has to be considered as finished.
1269 return (gdcmElValue *)0;
1271 NewElVal = NewElValueByNumber(g, n);
1273 FindLength(NewElVal);
1277 return (gdcmElValue *)0;
1279 NewElVal->SetOffset(ftell(fp));
1280 //if ( (g==0x7fe0) && (n==0x0010) )
1285 * \ingroup gdcmHeader
1286 * \brief Apply some heuristics to predict wether the considered
1287 * element value contains/represents an integer or not.
1288 * @param ElVal The element value on which to apply the predicate.
1289 * @return The result of the heuristical predicate.
1291 bool gdcmHeader::IsAnInteger(gdcmElValue * ElVal) {
1292 guint16 element = ElVal->GetElement();
1293 std::string vr = ElVal->GetVR();
1294 guint32 length = ElVal->GetLength();
1296 // When we have some semantics on the element we just read, and if we
1297 // a priori know we are dealing with an integer, then we shall be
1298 // able to swap it's element value properly.
1299 if ( element == 0 ) { // This is the group length of the group
1303 dbg.Error("gdcmHeader::IsAnInteger",
1304 "Erroneous Group Length element length.");
1307 if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") )
1314 * \ingroup gdcmHeader
1315 * \brief Recover the offset (from the beginning of the file) of the pixels.
1317 size_t gdcmHeader::GetPixelOffset(void) {
1318 // If this file complies with the norm we should encounter the
1319 // "Image Location" tag (0x0028, 0x0200). This tag contains the
1320 // the group that contains the pixel data (hence the "Pixel Data"
1321 // is found by indirection through the "Image Location").
1322 // Inside the group pointed by "Image Location" the searched element
1323 // is conventionally the element 0x0010 (when the norm is respected).
1324 // When the "Image Location" is absent we default to group 0x7fe0.
1327 std::string ImageLocation = GetPubElValByName("Image Location");
1328 if ( ImageLocation == GDCM_UNFOUND ) {
1331 grPixel = (guint16) atoi( ImageLocation.c_str() );
1333 if (grPixel != 0x7fe0)
1334 // This is a kludge for old dirty Philips imager.
1339 gdcmElValue* PixelElement = PubElValSet.GetElementByNumber(grPixel,
1342 return PixelElement->GetOffset();
1348 * \ingroup gdcmHeader
1349 * \brief Recover the pixel area length (in Bytes) .
1351 size_t gdcmHeader::GetPixelAreaLength(void) {
1352 // If this file complies with the norm we should encounter the
1353 // "Image Location" tag (0x0028, 0x0200). This tag contains the
1354 // the group that contains the pixel data (hence the "Pixel Data"
1355 // is found by indirection through the "Image Location").
1356 // Inside the group pointed by "Image Location" the searched element
1357 // is conventionally the element 0x0010 (when the norm is respected).
1358 // When the "Image Location" is absent we default to group 0x7fe0.
1361 std::string ImageLocation = GetPubElValByName("Image Location");
1362 if ( ImageLocation == GDCM_UNFOUND ) {
1365 grPixel = (guint16) atoi( ImageLocation.c_str() );
1367 if (grPixel != 0x7fe0)
1368 // This is a kludge for old dirty Philips imager.
1373 gdcmElValue* PixelElement = PubElValSet.GetElementByNumber(grPixel,
1376 return PixelElement->GetLength();
1382 * \ingroup gdcmHeader
1383 * \brief Searches both the public and the shadow dictionary (when they
1384 * exist) for the presence of the DictEntry with given
1385 * group and element. The public dictionary has precedence on the
1387 * @param group group of the searched DictEntry
1388 * @param element element of the searched DictEntry
1389 * @return Corresponding DictEntry when it exists, NULL otherwise.
1391 gdcmDictEntry * gdcmHeader::GetDictEntryByNumber(guint16 group,
1393 gdcmDictEntry * found = (gdcmDictEntry*)0;
1394 if (!RefPubDict && !RefShaDict) {
1395 dbg.Verbose(0, "gdcmHeader::GetDictEntry",
1396 "we SHOULD have a default dictionary");
1399 found = RefPubDict->GetTagByNumber(group, element);
1404 found = RefShaDict->GetTagByNumber(group, element);
1412 * \ingroup gdcmHeader
1413 * \brief Searches both the public and the shadow dictionary (when they
1414 * exist) for the presence of the DictEntry with given name.
1415 * The public dictionary has precedence on the shadow one.
1416 * @param Name name of the searched DictEntry
1417 * @return Corresponding DictEntry when it exists, NULL otherwise.
1419 gdcmDictEntry * gdcmHeader::GetDictEntryByName(std::string Name) {
1420 gdcmDictEntry * found = (gdcmDictEntry*)0;
1421 if (!RefPubDict && !RefShaDict) {
1422 dbg.Verbose(0, "gdcmHeader::GetDictEntry",
1423 "we SHOULD have a default dictionary");
1426 found = RefPubDict->GetTagByName(Name);
1431 found = RefShaDict->GetTagByName(Name);
1439 * \ingroup gdcmHeader
1440 * \brief Searches within the public dictionary for element value of
1442 * @param group Group of the researched tag.
1443 * @param element Element of the researched tag.
1444 * @return Corresponding element value when it exists, and the string
1445 * GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1447 std::string gdcmHeader::GetPubElValByNumber(guint16 group, guint16 element) {
1448 return PubElValSet.GetElValueByNumber(group, element);
1452 * \ingroup gdcmHeader
1453 * \brief Searches within the public dictionary for element value
1454 * representation of a given tag.
1456 * Obtaining the VR (Value Representation) might be needed by caller
1457 * to convert the string typed content to caller's native type
1458 * (think of C++ vs Python). The VR is actually of a higher level
1459 * of semantics than just the native C++ type.
1460 * @param group Group of the researched tag.
1461 * @param element Element of the researched tag.
1462 * @return Corresponding element value representation when it exists,
1463 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1465 std::string gdcmHeader::GetPubElValRepByNumber(guint16 group, guint16 element) {
1466 gdcmElValue* elem = PubElValSet.GetElementByNumber(group, element);
1468 return GDCM_UNFOUND;
1469 return elem->GetVR();
1473 * \ingroup gdcmHeader
1474 * \brief Searches within the public dictionary for element value of
1476 * @param TagName name of the searched element.
1477 * @return Corresponding element value when it exists, and the string
1478 * GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1480 std::string gdcmHeader::GetPubElValByName(std::string TagName) {
1481 return PubElValSet.GetElValueByName(TagName);
1485 * \ingroup gdcmHeader
1486 * \brief Searches within the elements parsed with the public dictionary for
1487 * the element value representation of a given tag.
1489 * Obtaining the VR (Value Representation) might be needed by caller
1490 * to convert the string typed content to caller's native type
1491 * (think of C++ vs Python). The VR is actually of a higher level
1492 * of semantics than just the native C++ type.
1493 * @param TagName name of the searched element.
1494 * @return Corresponding element value representation when it exists,
1495 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1497 std::string gdcmHeader::GetPubElValRepByName(std::string TagName) {
1498 gdcmElValue* elem = PubElValSet.GetElementByName(TagName);
1500 return GDCM_UNFOUND;
1501 return elem->GetVR();
1505 * \ingroup gdcmHeader
1506 * \brief Searches within elements parsed with the SHADOW dictionary
1507 * for the element value of a given tag.
1508 * @param group Group of the searched tag.
1509 * @param element Element of the searched tag.
1510 * @return Corresponding element value representation when it exists,
1511 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1513 std::string gdcmHeader::GetShaElValByNumber(guint16 group, guint16 element) {
1514 return ShaElValSet.GetElValueByNumber(group, element);
1518 * \ingroup gdcmHeader
1519 * \brief Searches within the elements parsed with the SHADOW dictionary
1520 * for the element value representation of a given tag.
1522 * Obtaining the VR (Value Representation) might be needed by caller
1523 * to convert the string typed content to caller's native type
1524 * (think of C++ vs Python). The VR is actually of a higher level
1525 * of semantics than just the native C++ type.
1526 * @param group Group of the searched tag.
1527 * @param element Element of the searched tag.
1528 * @return Corresponding element value representation when it exists,
1529 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1531 std::string gdcmHeader::GetShaElValRepByNumber(guint16 group, guint16 element) {
1532 gdcmElValue* elem = ShaElValSet.GetElementByNumber(group, element);
1534 return GDCM_UNFOUND;
1535 return elem->GetVR();
1539 * \ingroup gdcmHeader
1540 * \brief Searches within the elements parsed with the shadow dictionary
1541 * for an element value of given tag.
1542 * @param TagName name of the searched element.
1543 * @return Corresponding element value when it exists, and the string
1544 * GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1546 std::string gdcmHeader::GetShaElValByName(std::string TagName) {
1547 return ShaElValSet.GetElValueByName(TagName);
1551 * \ingroup gdcmHeader
1552 * \brief Searches within the elements parsed with the shadow dictionary for
1553 * the element value representation of a given tag.
1555 * Obtaining the VR (Value Representation) might be needed by caller
1556 * to convert the string typed content to caller's native type
1557 * (think of C++ vs Python). The VR is actually of a higher level
1558 * of semantics than just the native C++ type.
1559 * @param TagName name of the searched element.
1560 * @return Corresponding element value representation when it exists,
1561 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1563 std::string gdcmHeader::GetShaElValRepByName(std::string TagName) {
1564 gdcmElValue* elem = ShaElValSet.GetElementByName(TagName);
1566 return GDCM_UNFOUND;
1567 return elem->GetVR();
1571 * \ingroup gdcmHeader
1572 * \brief Searches within elements parsed with the public dictionary
1573 * and then within the elements parsed with the shadow dictionary
1574 * for the element value of a given tag.
1575 * @param group Group of the searched tag.
1576 * @param element Element of the searched tag.
1577 * @return Corresponding element value representation when it exists,
1578 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1580 std::string gdcmHeader::GetElValByNumber(guint16 group, guint16 element) {
1581 std::string pub = GetPubElValByNumber(group, element);
1584 return GetShaElValByNumber(group, element);
1588 * \ingroup gdcmHeader
1589 * \brief Searches within elements parsed with the public dictionary
1590 * and then within the elements parsed with the shadow dictionary
1591 * for the element value representation of a given tag.
1593 * Obtaining the VR (Value Representation) might be needed by caller
1594 * to convert the string typed content to caller's native type
1595 * (think of C++ vs Python). The VR is actually of a higher level
1596 * of semantics than just the native C++ type.
1597 * @param group Group of the searched tag.
1598 * @param element Element of the searched tag.
1599 * @return Corresponding element value representation when it exists,
1600 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1602 std::string gdcmHeader::GetElValRepByNumber(guint16 group, guint16 element) {
1603 std::string pub = GetPubElValRepByNumber(group, element);
1606 return GetShaElValRepByNumber(group, element);
1610 * \ingroup gdcmHeader
1611 * \brief Searches within elements parsed with the public dictionary
1612 * and then within the elements parsed with the shadow dictionary
1613 * for the element value of a given tag.
1614 * @param TagName name of the searched element.
1615 * @return Corresponding element value when it exists,
1616 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1618 std::string gdcmHeader::GetElValByName(std::string TagName) {
1619 std::string pub = GetPubElValByName(TagName);
1622 return GetShaElValByName(TagName);
1626 * \ingroup gdcmHeader
1627 * \brief Searches within elements parsed with the public dictionary
1628 * and then within the elements parsed with the shadow dictionary
1629 * for the element value representation of a given tag.
1631 * Obtaining the VR (Value Representation) might be needed by caller
1632 * to convert the string typed content to caller's native type
1633 * (think of C++ vs Python). The VR is actually of a higher level
1634 * of semantics than just the native C++ type.
1635 * @param TagName name of the searched element.
1636 * @return Corresponding element value representation when it exists,
1637 * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
1639 std::string gdcmHeader::GetElValRepByName(std::string TagName) {
1640 std::string pub = GetPubElValRepByName(TagName);
1643 return GetShaElValRepByName(TagName);
1647 * \ingroup gdcmHeader
1648 * \brief Accesses an existing gdcmElValue in the PubElValSet of this instance
1649 * through it's (group, element) and modifies it's content with
1651 * @param content new value to substitute with
1652 * @param group group of the ElVal to modify
1653 * @param element element of the ElVal to modify
1655 int gdcmHeader::SetPubElValByNumber(std::string content, guint16 group,
1658 //TODO : homogeneiser les noms : SetPubElValByNumber
1659 // qui appelle PubElValSet.SetElValueByNumber
1660 // pourquoi pas SetPubElValueByNumber ??
1663 return ( PubElValSet.SetElValueByNumber (content, group, element) );
1667 * \ingroup gdcmHeader
1668 * \brief Accesses an existing gdcmElValue in the PubElValSet of this instance
1669 * through tag name and modifies it's content with the given value.
1670 * @param content new value to substitute with
1671 * @param TagName name of the tag to be modified
1673 int gdcmHeader::SetPubElValByName(std::string content, std::string TagName) {
1674 return ( PubElValSet.SetElValueByName (content, TagName) );
1678 * \ingroup gdcmHeader
1679 * \brief Accesses an existing gdcmElValue in the PubElValSet of this instance
1680 * through it's (group, element) and modifies it's length with
1682 * \warning Use with extreme caution.
1683 * @param length new length to substitute with
1684 * @param group group of the ElVal to modify
1685 * @param element element of the ElVal to modify
1686 * @return 1 on success, 0 otherwise.
1689 int gdcmHeader::SetPubElValLengthByNumber(guint32 length, guint16 group,
1691 return ( PubElValSet.SetElValueLengthByNumber (length, group, element) );
1695 * \ingroup gdcmHeader
1696 * \brief Accesses an existing gdcmElValue in the ShaElValSet of this instance
1697 * through it's (group, element) and modifies it's content with
1699 * @param content new value to substitute with
1700 * @param group group of the ElVal to modify
1701 * @param element element of the ElVal to modify
1702 * @return 1 on success, 0 otherwise.
1704 int gdcmHeader::SetShaElValByNumber(std::string content,
1705 guint16 group, guint16 element) {
1706 return ( ShaElValSet.SetElValueByNumber (content, group, element) );
1710 * \ingroup gdcmHeader
1711 * \brief Accesses an existing gdcmElValue in the ShaElValSet of this instance
1712 * through tag name and modifies it's content with the given value.
1713 * @param content new value to substitute with
1714 * @param ShadowTagName name of the tag to be modified
1716 int gdcmHeader::SetShaElValByName(std::string content, std::string ShadowTagName) {
1717 return ( ShaElValSet.SetElValueByName (content, ShadowTagName) );
1721 * \ingroup gdcmHeader
1722 * \brief Parses the header of the file but WITHOUT loading element values.
1724 void gdcmHeader::ParseHeader(bool exception_on_error) throw(gdcmFormatError) {
1725 gdcmElValue * newElValue = (gdcmElValue *)0;
1729 while ( (newElValue = ReadNextElement()) ) {
1730 SkipElementValue(newElValue);
1731 PubElValSet.Add(newElValue);
1736 * \ingroup gdcmHeader
1740 FileType gdcmHeader::GetFileType(void)
1746 * \ingroup gdcmHeader
1747 * \brief This predicate, based on hopefully reasonable heuristics,
1748 * decides whether or not the current gdcmHeader was properly parsed
1749 * and contains the mandatory information for being considered as
1750 * a well formed and usable image.
1751 * @return true when gdcmHeader is the one of a reasonable Dicom file,
1754 bool gdcmHeader::IsReadable(void) {
1755 if ( GetElValByName("Image Dimensions") != GDCM_UNFOUND
1756 && atoi(GetElValByName("Image Dimensions").c_str()) > 4 ) {
1759 if ( GetElValByName("Bits Allocated") == GDCM_UNFOUND )
1761 if ( GetElValByName("Bits Stored") == GDCM_UNFOUND )
1763 if ( GetElValByName("High Bit") == GDCM_UNFOUND )
1765 if ( GetElValByName("Pixel Representation") == GDCM_UNFOUND )
1771 * \ingroup gdcmHeader
1772 * \brief Small utility function that creates a new manually crafted
1773 * (as opposed as read from the file) gdcmElValue with user
1774 * specified name and adds it to the public tag hash table.
1775 * \note A fake TagKey is generated so the PubDict can keep it's coherence.
1776 * @param NewTagName The name to be given to this new tag.
1777 * @param VR The Value Representation to be given to this new tag.
1778 * @ return The newly hand crafted Element Value.
1780 gdcmElValue* gdcmHeader::NewManualElValToPubDict(std::string NewTagName,
1782 gdcmElValue* NewElVal = (gdcmElValue*)0;
1783 guint32 StuffGroup = 0xffff; // Group to be stuffed with additional info
1784 guint32 FreeElem = 0;
1785 gdcmDictEntry* NewEntry = (gdcmDictEntry*)0;
1787 FreeElem = PubElValSet.GenerateFreeTagKeyInGroup(StuffGroup);
1788 if (FreeElem == UINT32_MAX) {
1789 dbg.Verbose(1, "gdcmHeader::NewManualElValToPubDict",
1790 "Group 0xffff in Public Dict is full");
1791 return (gdcmElValue*)0;
1793 NewEntry = new gdcmDictEntry(StuffGroup, FreeElem,
1794 VR, "GDCM", NewTagName);
1795 NewElVal = new gdcmElValue(NewEntry);
1796 PubElValSet.Add(NewElVal);
1801 * \ingroup gdcmHeader
1802 * \brief Loads the element values of all the elements present in the
1803 * public tag based hash table.
1805 void gdcmHeader::LoadElements(void) {
1808 // We don't use any longer the HashTable, since a lot a stuff is missing
1809 // when SeQuences were encountered
1811 //TagElValueHT ht = PubElValSet.GetTagHt();
1812 //for (TagElValueHT::iterator tag = ht.begin(); tag != ht.end(); ++tag) {
1813 // LoadElementValue(tag->second);
1816 for (ListTag::iterator i = GetListElem().begin();
1817 i != GetListElem().end();
1819 LoadElementValue(*i);
1824 // Load 'non string' values
1825 std::string PhotometricInterpretation = GetPubElValByNumber(0x0028,0x0004);
1826 if( PhotometricInterpretation == "PALETTE COLOR " ){
1827 LoadElementVoidArea(0x0028,0x1200); // gray LUT
1828 LoadElementVoidArea(0x0028,0x1201); // R LUT
1829 LoadElementVoidArea(0x0028,0x1202); // G LUT
1830 LoadElementVoidArea(0x0028,0x1203); // B LUT
1832 LoadElementVoidArea(0x0028,0x1221); // Segmented Red Palette Color LUT Data
1833 LoadElementVoidArea(0x0028,0x1222); // Segmented Green Palette Color LUT Data
1834 LoadElementVoidArea(0x0028,0x1223); // Segmented Blue Palette Color LUT Data
1837 // --------------------------------------------------------------
1838 // Special Patch to allow gdcm to read ACR-LibIDO formated images
1840 // if recognition code tells us we deal with a LibIDO image
1841 // we switch lineNumber and columnNumber
1843 std::string RecCode;
1844 RecCode = GetPubElValByNumber(0x0008, 0x0010);
1845 if (RecCode == "ACRNEMA_LIBIDO_1.1" ||
1846 RecCode == "CANRME_AILIBOD1_1." ) {
1847 filetype = ACR_LIBIDO;
1848 std::string rows = GetPubElValByNumber(0x0028, 0x0010);
1849 std::string columns = GetPubElValByNumber(0x0028, 0x0011);
1850 SetPubElValByNumber(columns, 0x0028, 0x0010);
1851 SetPubElValByNumber(rows , 0x0028, 0x0011);
1853 // ----------------- End of Special Patch ----------------
1857 * \ingroup gdcmHeader
1861 void gdcmHeader::PrintPubElVal(std::ostream & os) {
1862 PubElValSet.Print(os);
1866 * \ingroup gdcmHeader
1870 void gdcmHeader::PrintPubDict(std::ostream & os) {
1871 RefPubDict->Print(os);
1875 * \ingroup gdcmHeader
1877 * @return integer, acts as a Boolean
1879 int gdcmHeader::Write(FILE * fp, FileType type) {
1881 // TODO : move the following lines (and a lot of others, to be written)
1882 // to a future function CheckAndCorrectHeader
1884 if (type == ImplicitVR) {
1885 std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
1886 ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
1888 //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
1889 // values with a VR of UI shall be padded with a single trailing null
1890 // Dans le cas suivant on doit pader manuellement avec un 0
1892 PubElValSet.SetElValueLengthByNumber(18, 0x0002, 0x0010);
1895 if (type == ExplicitVR) {
1896 std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
1897 ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
1899 //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
1900 // values with a VR of UI shall be padded with a single trailing null
1901 // Dans le cas suivant on doit pader manuellement avec un 0
1903 PubElValSet.SetElValueLengthByNumber(20, 0x0002, 0x0010);
1906 return PubElValSet.Write(fp, type);
1910 // ------------------------ 'non string' elements related functions
1914 * \ingroup gdcmHeader
1915 * \brief Loads (from disk) the element content
1916 * when a string is not suitable
1918 void * gdcmHeader::LoadElementVoidArea(guint16 Group, guint16 Elem) {
1919 gdcmElValue * Element= PubElValSet.GetElementByNumber(Group, Elem);
1922 size_t o =(size_t)Element->GetOffset();
1923 fseek(fp, o, SEEK_SET);
1924 int l=Element->GetLength();
1925 void * a = malloc(l);
1929 /* int res = */ PubElValSet.SetVoidAreaByNumber(a, Group, Elem);
1930 // TODO check the result
1931 size_t l2 = fread(a, 1, l ,fp);
1940 * \ingroup gdcmHeader
1941 * \brief Gets (from Header) the offset of a 'non string' element value
1942 * \ (LoadElementValue has already be executed)
1945 * @return File Offset of the Element Value
1947 size_t gdcmHeader::GetPubElValOffsetByNumber(guint16 Group, guint16 Elem) {
1948 gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
1950 dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
1951 "failed to Locate gdcmElValue");
1954 return elValue->GetOffset();
1958 * \ingroup gdcmHeader
1959 * \brief Gets (from Header) a 'non string' element value
1960 * \ (LoadElementValue has already be executed)
1963 * @return Pointer to the 'non string' area
1966 void * gdcmHeader::GetPubElValVoidAreaByNumber(guint16 Group, guint16 Elem) {
1967 gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
1969 dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
1970 "failed to Locate gdcmElValue");
1973 return elValue->GetVoidArea();
1978 // =============================================================================
1979 // Heuristics based accessors
1980 //==============================================================================
1983 // TODO : move to an other file.
1987 * \ingroup gdcmHeader
1988 * \brief Retrieve the number of columns of image.
1989 * @return The encountered size when found, 0 by default.
1991 int gdcmHeader::GetXSize(void) {
1992 // We cannot check for "Columns" because the "Columns" tag is present
1993 // both in IMG (0028,0011) and OLY (6000,0011) sections of the dictionary.
1994 std::string StrSize = GetPubElValByNumber(0x0028,0x0011);
1995 if (StrSize == GDCM_UNFOUND)
1997 return atoi(StrSize.c_str());
2001 * \ingroup gdcmHeader
2002 * \brief Retrieve the number of lines of image.
2003 * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize()
2004 * @return The encountered size when found, 1 by default.
2006 int gdcmHeader::GetYSize(void) {
2007 // We cannot check for "Rows" because the "Rows" tag is present
2008 // both in IMG (0028,0010) and OLY (6000,0010) sections of the dictionary.
2009 std::string StrSize = GetPubElValByNumber(0x0028,0x0010);
2010 if (StrSize != GDCM_UNFOUND)
2011 return atoi(StrSize.c_str());
2015 // The Rows (0028,0010) entry is optional for ACR/NEMA. It might
2016 // hence be a signal (1d image). So we default to 1:
2021 * \ingroup gdcmHeader
2022 * \brief Retrieve the number of planes of volume or the number
2023 * of frames of a multiframe.
2024 * \warning When present we consider the "Number of Frames" as the third
2025 * dimension. When absent we consider the third dimension as
2026 * being the "Planes" tag content.
2027 * @return The encountered size when found, 1 by default.
2029 int gdcmHeader::GetZSize(void) {
2030 // Both in DicomV3 and ACR/Nema the consider the "Number of Frames"
2031 // as the third dimension.
2032 std::string StrSize = GetPubElValByNumber(0x0028,0x0008);
2033 if (StrSize != GDCM_UNFOUND)
2034 return atoi(StrSize.c_str());
2036 // We then consider the "Planes" entry as the third dimension [we
2037 // cannot retrieve by name since "Planes tag is present both in
2038 // IMG (0028,0012) and OLY (6000,0012) sections of the dictionary].
2039 StrSize = GetPubElValByNumber(0x0028,0x0012);
2040 if (StrSize != GDCM_UNFOUND)
2041 return atoi(StrSize.c_str());
2046 * \ingroup gdcmHeader
2047 * \brief Retrieve the number of Bits Stored
2048 * (as opposite to number of Bits Allocated)
2050 * @return The encountered number of Bits Stored, 0 by default.
2052 int gdcmHeader::GetBitsStored(void) {
2053 std::string StrSize = GetPubElValByNumber(0x0028,0x0101);
2054 if (StrSize == GDCM_UNFOUND)
2056 return atoi(StrSize.c_str());
2060 * \ingroup gdcmHeader
2061 * \brief Retrieve the number of Bits Allocated
2062 * (8, 12 -compacted ACR-NEMA files, 16, ...)
2064 * @return The encountered number of Bits Allocated, 0 by default.
2066 int gdcmHeader::GetBitsAllocated(void) {
2067 std::string StrSize = GetPubElValByNumber(0x0028,0x0100);
2068 if (StrSize == GDCM_UNFOUND)
2070 return atoi(StrSize.c_str());
2074 * \ingroup gdcmHeader
2075 * \brief Retrieve the number of Samples Per Pixel
2076 * (1 : gray level, 3 : RGB -1 or 3 Planes-)
2078 * @return The encountered number of Samples Per Pixel, 1 by default.
2080 int gdcmHeader::GetSamplesPerPixel(void) {
2081 std::string StrSize = GetPubElValByNumber(0x0028,0x0002);
2082 if (StrSize == GDCM_UNFOUND)
2083 return 1; // Well, it's supposed to be mandatory ...
2084 return atoi(StrSize.c_str());
2088 * \ingroup gdcmHeader
2089 * \brief Retrieve the Planar Configuration for RGB images
2090 * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
2092 * @return The encountered Planar Configuration, 0 by default.
2094 int gdcmHeader::GetPlanarConfiguration(void) {
2095 std::string StrSize = GetPubElValByNumber(0x0028,0x0006);
2096 if (StrSize == GDCM_UNFOUND)
2098 return atoi(StrSize.c_str());
2102 * \ingroup gdcmHeader
2103 * \brief Return the size (in bytes) of a single pixel of data.
2104 * @return The size in bytes of a single pixel of data.
2107 int gdcmHeader::GetPixelSize(void) {
2108 std::string PixelType = GetPixelType();
2109 if (PixelType == "8U" || PixelType == "8S")
2111 if (PixelType == "16U" || PixelType == "16S")
2113 if (PixelType == "32U" || PixelType == "32S")
2115 dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
2120 * \ingroup gdcmHeader
2121 * \brief Build the Pixel Type of the image.
2122 * Possible values are:
2123 * - 8U unsigned 8 bit,
2124 * - 8S signed 8 bit,
2125 * - 16U unsigned 16 bit,
2126 * - 16S signed 16 bit,
2127 * - 32U unsigned 32 bit,
2128 * - 32S signed 32 bit,
2129 * \warning 12 bit images appear as 16 bit.
2130 * \ 24 bit images appear as 8 bit
2133 std::string gdcmHeader::GetPixelType(void) {
2134 std::string BitsAlloc;
2135 BitsAlloc = GetElValByName("Bits Allocated");
2136 if (BitsAlloc == GDCM_UNFOUND) {
2137 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
2138 BitsAlloc = std::string("16");
2140 if (BitsAlloc == "12") // It will be unpacked
2141 BitsAlloc = std::string("16");
2142 else if (BitsAlloc == "24") // (in order no to be messed up
2143 BitsAlloc = std::string("8"); // by old RGB images)
2146 Signed = GetElValByName("Pixel Representation");
2147 if (Signed == GDCM_UNFOUND) {
2148 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
2149 BitsAlloc = std::string("0");
2152 Signed = std::string("U");
2154 Signed = std::string("S");
2156 return( BitsAlloc + Signed);
2160 * \ingroup gdcmHeader
2161 * \brief gets the info from 0002,0010 : Transfert Syntax
2163 * @return Transfert Syntax Name (as oposite to Transfert Syntax UID)
2165 std::string gdcmHeader::GetTransferSyntaxName(void) {
2166 std::string TransfertSyntax = GetPubElValByNumber(0x0002,0x0010);
2167 if (TransfertSyntax == GDCM_UNFOUND) {
2168 dbg.Verbose(0, "gdcmHeader::GetTransferSyntaxName: unfound Transfert Syntax (0002,0010)");
2169 return "Uncompressed ACR-NEMA";
2171 // we do it only when we need it
2172 gdcmTS * ts = gdcmGlobal::GetTS();
2173 std::string tsName=ts->GetValue(TransfertSyntax);
2174 //delete ts; // Seg Fault when deleted ?!
2178 // -------------------------------- Lookup Table related functions ------------
2181 * \ingroup gdcmHeader
2182 * \brief tells us if LUT are used
2183 * \warning Right now, Segmented xxx Palette Color Lookup Table Data
2184 * \ are NOT considered as LUT, since nobody knows
2185 *\ how to deal with them
2186 * @return int acts as a Boolean
2189 int gdcmHeader::HasLUT(void) {
2191 // Check the presence of the LUT Descriptors
2192 if (GetPubElValByNumber(0x0028,0x1101) == GDCM_UNFOUND)
2194 // LutDescriptorGreen
2195 if (GetPubElValByNumber(0x0028,0x1102) == GDCM_UNFOUND)
2197 // LutDescriptorBlue
2198 if (GetPubElValByNumber(0x0028,0x1103) == GDCM_UNFOUND)
2202 if (GetPubElValByNumber(0x0028,0x1201) == GDCM_UNFOUND)
2204 if (GetPubElValByNumber(0x0028,0x1202) == GDCM_UNFOUND)
2206 if (GetPubElValByNumber(0x0028,0x1203) == GDCM_UNFOUND)
2212 * \ingroup gdcmHeader
2213 * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
2215 * @return Lookup Table nBit
2216 * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
2219 int gdcmHeader::GetLUTNbits(void) {
2220 std::vector<std::string> tokens;
2224 //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue
2225 // Consistency already checked in GetLUTLength
2226 std::string LutDescription = GetPubElValByNumber(0x0028,0x1101);
2227 if (LutDescription == GDCM_UNFOUND)
2229 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
2230 Tokenize (LutDescription, tokens, "\\");
2231 //LutLength=atoi(tokens[0].c_str());
2232 //LutDepth=atoi(tokens[1].c_str());
2233 LutNbits=atoi(tokens[2].c_str());
2239 * \ingroup gdcmHeader
2240 * \brief builts Red/Green/Blue/Alpha LUT from Header
2241 * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
2242 * \ and (0028,1101),(0028,1102),(0028,1102)
2243 * \ - xxx Palette Color Lookup Table Descriptor - are found
2244 * \ and (0028,1201),(0028,1202),(0028,1202)
2245 * \ - xxx Palette Color Lookup Table Data - are found
2246 * \warning does NOT deal with :
2247 * \ 0028 1100 Gray Lookup Table Descriptor (Retired)
2248 * \ 0028 1221 Segmented Red Palette Color Lookup Table Data
2249 * \ 0028 1222 Segmented Green Palette Color Lookup Table Data
2250 * \ 0028 1223 Segmented Blue Palette Color Lookup Table Data
2251 * \ no known Dicom reader deails with them :-(
2252 * @return Lookup Table RGBA
2255 unsigned char * gdcmHeader::GetLUTRGBA(void) {
2256 // Not so easy : see
2257 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
2258 // and OT-PAL-8-face.dcm
2260 // if Photometric Interpretation # PALETTE COLOR, no LUT to be done
2262 if (gdcmHeader::GetPubElValByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
2266 int lengthR, debR, nbitsR;
2267 int lengthG, debG, nbitsG;
2268 int lengthB, debB, nbitsB;
2270 // Get info from Lut Descriptors
2271 // (the 3 LUT descriptors may be different)
2273 std::string LutDescriptionR = GetPubElValByNumber(0x0028,0x1101);
2274 if (LutDescriptionR == GDCM_UNFOUND)
2276 std::string LutDescriptionG = GetPubElValByNumber(0x0028,0x1102);
2277 if (LutDescriptionG == GDCM_UNFOUND)
2279 std::string LutDescriptionB = GetPubElValByNumber(0x0028,0x1103);
2280 if (LutDescriptionB == GDCM_UNFOUND)
2283 std::vector<std::string> tokens;
2285 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
2286 Tokenize (LutDescriptionR, tokens, "\\");
2287 lengthR=atoi(tokens[0].c_str()); // Red LUT length in Bytes
2288 debR =atoi(tokens[1].c_str()); // subscript of the first Lut Value
2289 nbitsR =atoi(tokens[2].c_str()); // Lut item size (in Bits)
2292 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
2293 Tokenize (LutDescriptionG, tokens, "\\");
2294 lengthG=atoi(tokens[0].c_str()); // Green LUT length in Bytes
2295 debG =atoi(tokens[1].c_str());
2296 nbitsG =atoi(tokens[2].c_str());
2299 tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
2300 Tokenize (LutDescriptionB, tokens, "\\");
2301 lengthB=atoi(tokens[0].c_str()); // Blue LUT length in Bytes
2302 debB =atoi(tokens[1].c_str());
2303 nbitsB =atoi(tokens[2].c_str());
2306 // Load LUTs into memory, (as they were stored on disk)
2308 unsigned char *lutR =(unsigned char *)
2309 GetPubElValVoidAreaByNumber(0x0028,0x1201);
2310 unsigned char *lutG =(unsigned char *)
2311 GetPubElValVoidAreaByNumber(0x0028,0x1202);
2312 unsigned char *lutB =(unsigned char *)
2313 GetPubElValVoidAreaByNumber(0x0028,0x1203);
2315 if (!lutR || !lutG || !lutB ) {
2318 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
2320 unsigned char *LUTRGBA = (unsigned char *)calloc(1024,1); // 256 * 4 (R, G, B, Alpha)
2324 memset(LUTRGBA, 0, 1024);
2327 std::string str_nb = GetPubElValByNumber(0x0028,0x0100);
2328 if (str_nb == GDCM_UNFOUND ) {
2331 nb = atoi(str_nb.c_str() );
2335 if (nbitsR==16 && nb==8) // when LUT item size is different than pixel size
2336 mult=2; // high byte must be = low byte
2337 else // See PS 3.3-2003 C.11.1.1.2 p 619
2341 // if we get a black image, let's just remove the '+1'
2342 // from 'i*mult+1' and check again
2343 // if it works, we shall have to check the 3 Palettes
2344 // to see which byte is ==0 (first one, or second one)
2346 // We give up the checking to avoid some overhead
2351 for(i=0;i<lengthR;i++) {
2352 *a = lutR[i*mult+1];
2356 for(i=0;i<lengthG;i++) {
2357 *a = lutG[i*mult+1];
2361 for(i=0;i<lengthB;i++) {
2362 *a = lutB[i*mult+1];
2366 for(i=0;i<256;i++) {
2367 *a = 1; // Alpha component
2371 //How to free the now useless LUTs?
2373 //free(LutR); free(LutB); free(LutG);
2378 /////////////////////////////////////////////////////////////////
2381 * \brief Sets the Pixel Area size in the Header
2382 * --> not-for-rats function
2384 * \warning WARNING doit-etre etre publique ?
2385 * TODO : y aurait il un inconvenient à fusionner ces 2 fonctions
2387 * @param ImageDataSize new Pixel Area Size
2388 * warning : nothing else is checked
2391 void gdcmHeader::SetImageDataSize(size_t ImageDataSize) {
2392 std::string content1;
2394 // Assumes ElValue (0x7fe0, 0x0010) exists ...
2395 sprintf(car,"%d",ImageDataSize);
2397 gdcmElValue *a = GetElValueByNumber(0x7fe0, 0x0010);
2398 a->SetLength(ImageDataSize);
2401 sprintf(car,"%d",ImageDataSize);
2403 SetPubElValByNumber(content1, 0x7fe0, 0x0000);