1 /*=========================================================================
4 Module: $RCSfile: gdcmBinEntry.cxx,v $
6 Date: $Date: 2005/03/02 17:15:52 $
7 Version: $Revision: 1.72 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmBinEntry.h"
20 #include "gdcmContentEntry.h"
25 #include <iostream> // for std::ios_base, since <ios> does not exist on gcc/Solaris
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
32 * \brief Constructor from a given BinEntry
34 BinEntry::BinEntry(DictEntry *e)
42 * \brief Constructor from a given BinEntry
43 * @param e Pointer to existing Doc entry
45 BinEntry::BinEntry(DocEntry *e)
46 : ContentEntry(e->GetDictEntry())
55 * \brief Canonical destructor.
59 if (BinArea && SelfArea)
62 BinArea = 0; // let's be carefull !
66 //-----------------------------------------------------------------------------
69 * \brief canonical Writer
70 * @param fp already open file pointer
71 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
73 void BinEntry::WriteContent(std::ofstream *fp, FileType filetype)
75 DocEntry::WriteContent(fp, filetype);
76 uint8_t* binArea8 = BinArea; //safe notation
77 size_t lgr = GetLength();
78 if (BinArea) // the binArea was *actually* loaded
80 /// \todo Probably, the same operation should be done if we wanted
81 /// to write image with Big Endian Transfer Syntax,
82 /// while working on Little Endian Processor
84 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)
85 /// \todo FIXME Right now, we only care of Pixels element
86 /// we should deal with *all* the BinEntries
87 /// well not really since we are not interpreting values read...
89 // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW
90 // -value forced while Reading process-
91 if (GetGroup() == 0x7fe0 && GetVR() == "OW")
93 uint16_t *binArea16 = (uint16_t*)binArea8;
94 binary_write (*fp, binArea16, lgr );
98 // For any other VR, BinEntry is re-written as-is
99 binary_write (*fp, binArea8, lgr );
102 binary_write ( *fp, binArea8, lgr ); // Elem value
103 #endif //GDCM_WORDS_BIGENDIAN
108 // nothing was loaded, but we need to skip space on disc
109 fp->seekp(lgr, std::ios::cur);
114 * \brief Sets the value (non string) of the current Dicom Header Entry
116 void BinEntry::SetBinArea( uint8_t *area, bool self )
118 if (BinArea && SelfArea)
125 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
134 * \brief Prints a BinEntry (Dicom entry)
135 * @param os ostream we want to print in
136 * @param indent Indentation string to be prepended during printing
138 void BinEntry::Print(std::ostream &os, std::string const & )
142 std::ostringstream s;
143 void* binArea = GetBinArea();
146 s << " [" << GetValue()
147 << "; length = " << GetLength() << "]";
151 if ( GetLength() == 0 )
157 s << " [" <<GetValue() << "]";
163 //-----------------------------------------------------------------------------
164 } // end namespace gdcm