1 /*=========================================================================
4 Module: $RCSfile: gdcmBinEntry.cxx,v $
6 Date: $Date: 2005/09/21 09:44:59 $
7 Version: $Revision: 1.78 $
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
81 // The same operation should be done if we wanted
82 // to write image with Big Endian Transfer Syntax,
83 // while working on Little Endian Processor
84 // --> forget Big Endian Transfer Syntax writting!
85 // Next DICOM version will give it up ...
90 // The stuff looks nice, but it's probably bugged,
91 // since troubles occur on big endian processors (SunSparc, Motorola)
92 // while reading the pixels of a
93 // gdcm-written Little-Endian 16 bits per pixel image
95 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)
97 /// \todo FIXME : Right now, we only care of Pixels element
98 /// we should deal with *all* the BinEntries
99 /// Well, not really since we are not interpreting values read...
101 // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW
102 // -value forced while Reading process-
103 if (GetGroup() == 0x7fe0 && GetVR() == "OW")
105 uint16_t *binArea16 = (uint16_t*)binArea8;
106 binary_write (*fp, binArea16, lgr );
110 // For any other VR, BinEntry is re-written as-is
111 binary_write (*fp, binArea8, lgr );
114 binary_write ( *fp, binArea8, lgr ); // Elem value
115 #endif //GDCM_WORDS_BIGENDIAN
120 // nothing was loaded, but we need to skip space on disc
121 fp->seekp(lgr, std::ios::cur);
126 * \brief Sets the value (non string) of the current Dicom Header Entry
128 void BinEntry::SetBinArea( uint8_t *area, bool self )
130 if (BinArea && SelfArea)
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
146 * \brief Prints a BinEntry (Dicom entry)
147 * @param os ostream we want to print in
148 * @param indent Indentation string to be prepended during printing
150 void BinEntry::Print(std::ostream &os, std::string const & )
154 std::ostringstream s;
155 void* binArea = GetBinArea();
158 if ( GetVR() == "FL" )
160 int l = GetReadLength()/4 - 1;
161 float *beg = (float *)GetBinArea();
164 for (int i=0;i<l;i++)
171 else if ( GetVR() == "FD" )
173 int l = GetReadLength()/8 - 1;
174 double *beg = (double *)GetBinArea();
177 for (int i=0;i<l;i++)
186 if ( Util::IsCleanArea( GetBinArea(),GetLength() ) )
188 std::string cleanString =
189 Util::CreateCleanString( GetBinArea(),GetLength() );
190 s << " [" << cleanString << "]";
194 //s << " [" << GetValue()
195 s << " [" << GDCM_BINLOADED << ";"
196 << "length = " << GetLength() << "]";
202 if ( GetLength() == 0 )
208 s << " [" <<GetValue() << "]";
214 //-----------------------------------------------------------------------------
215 } // end namespace gdcm