1 /*=========================================================================
4 Module: $RCSfile: gdcmBinEntry.cxx,v $
6 Date: $Date: 2005/10/11 14:48:19 $
7 Version: $Revision: 1.80 $
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-
107 // --> the following lines *looked* very clever,
108 // --> but they don't work on big endian processors.
109 // --> since I've no access for the moment to a big endian proc :-(
110 // --> I comment them out, to see the result on the dash board
113 // --> Revert to initial code : TestWriteSimple hangs on Darwin :-(
114 if (GetGroup() == 0x7fe0 && GetVR() == "OW")
116 uint16_t *binArea16 = (uint16_t*)binArea8;
117 binary_write (*fp, binArea16, lgr );
121 // For any other VR, BinEntry is re-written as-is
122 binary_write (*fp, binArea8, lgr );
128 // --> remove the following line, an uncomment the previous ones,
129 // --> if it doesn't work better
131 /*binary_write ( *fp, binArea8, lgr ); // Elem value*/
134 binary_write ( *fp, binArea8, lgr ); // Elem value
135 #endif //GDCM_WORDS_BIGENDIAN
140 // nothing was loaded, but we need to skip space on disc
142 // --> WARNING : nothing is written;
143 // --> the initial data (on the the source image) is lost
144 // --> user is *not* informed !
146 fp->seekp(lgr, std::ios::cur);
151 * \brief Sets the value (non string) of the current Dicom Header Entry
153 void BinEntry::SetBinArea( uint8_t *area, bool self )
155 if (BinArea && SelfArea)
162 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
171 * \brief Prints a BinEntry (Dicom entry)
172 * @param os ostream we want to print in
173 * @param indent Indentation string to be prepended during printing
175 void BinEntry::Print(std::ostream &os, std::string const & )
179 std::ostringstream s;
180 void* binArea = GetBinArea();
183 if ( GetVR() == "FL" )
185 int l = GetReadLength()/4 - 1;
186 float *beg = (float *)GetBinArea();
189 for (int i=0;i<l;i++)
196 else if ( GetVR() == "FD" )
198 int l = GetReadLength()/8 - 1;
199 double *beg = (double *)GetBinArea();
202 for (int i=0;i<l;i++)
211 if ( Util::IsCleanArea( GetBinArea(),GetLength() ) )
213 std::string cleanString =
214 Util::CreateCleanString( GetBinArea(),GetLength() );
215 s << " [" << cleanString << "]";
219 //s << " [" << GetValue()
220 s << " [" << GDCM_BINLOADED << ";"
221 << "length = " << GetLength() << "]";
227 if ( GetLength() == 0 )
233 s << " [" <<GetValue() << "]";
239 //-----------------------------------------------------------------------------
240 } // end namespace gdcm