1 /*=========================================================================
4 Module: $RCSfile: gdcmBinEntry.cxx,v $
6 Date: $Date: 2005/02/02 17:47:56 $
7 Version: $Revision: 1.63 $
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"
22 #include "gdcmDebug.h"
26 #include <iostream> // for std::ios_base, since <ios> does not exist on gcc/Solaris
30 //-----------------------------------------------------------------------------
31 // Constructor / Destructor
33 * \brief Constructor from a given BinEntry
35 BinEntry::BinEntry(DictEntry *e)
43 * \brief Constructor from a given BinEntry
44 * @param e Pointer to existing Doc entry
46 BinEntry::BinEntry(DocEntry *e)
47 : ContentEntry(e->GetDictEntry())
51 BinArea = 0; // let's be carefull !
56 * \brief Canonical destructor.
60 if (BinArea && SelfArea)
63 BinArea = 0; // let's be carefull !
67 //-----------------------------------------------------------------------------
70 * \brief canonical Writer
71 * @param fp already open file pointer
72 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
74 void BinEntry::WriteContent(std::ofstream *fp, FileType filetype)
76 #define BUFFER_SIZE 4096
77 DocEntry::WriteContent(fp, filetype);
78 void* binArea = GetBinArea();
79 int lgr = GetLength();
80 if (binArea) // the binArea was *actually* loaded
84 // Probabely, the same operation will have to be done when we want
85 // to write image with Big Endian Transfert Syntax,
86 // and we are working on Little Endian Processor
88 /*#ifdef GDCM_WORDS_BIGENDIAN
89 // TODO FIXME Right now, we only care of Pixels element
91 // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW
92 // -value forced while Reading process-
93 if (GetGroup() == 0x7fe0 && GetVR() == "OW")
95 uint16_t *buffer = new uint16_t[BUFFER_SIZE];
97 // how many BUFFER_SIZE long pieces in binArea ?
98 int nbPieces = lgr/BUFFER_SIZE/2; //(16 bits = 2 Bytes)
99 int remainingSize = lgr%BUFFER_SIZE;
101 uint16_t *binArea16 = (uint16_t*)binArea;
102 for (int j=0;j<nbPieces;j++)
104 for (int i = 0; i < BUFFER_SIZE/2; i++)
106 buffer[i] = (binArea16[i] >> 8) | (binArea16[i] << 8);
108 fp->write ( (char*)buffer, BUFFER_SIZE );
109 binArea16 += BUFFER_SIZE/2;
111 if ( remainingSize > 0)
113 for (int i = 0; i < remainingSize/2; i++)
115 buffer[i] = (binArea16[i] >> 8) | (binArea16[i] << 8);
117 fp->write ( (char*)buffer, remainingSize );
123 // For any other VR, BinEntry is re-written as-is
124 fp->write ( (char*)binArea, lgr );
127 fp->write ( (char*)binArea, lgr ); // Elem value
128 //#endif //GDCM_WORDS_BIGENDIAN
133 // nothing was loaded, but we need to skip space on disc
134 fp->seekp(lgr, std::ios::cur);
139 * \brief Sets the value (non string) of the current Dicom Header Entry
141 void BinEntry::SetBinArea( uint8_t *area, bool self )
143 if (BinArea && SelfArea)
150 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
159 * \brief Prints a BinEntry (Dicom entry)
160 * @param os ostream we want to print in
161 * @param indent Indentation string to be prepended during printing
163 void BinEntry::Print(std::ostream &os, std::string const & )
167 std::ostringstream s;
168 void* binArea = GetBinArea();
171 s << " [" << GetValue()
172 << "; length = " << GetLength() << "]";
176 if ( GetLength() == 0 )
182 s << " [" <<GetValue() << "]";
188 //-----------------------------------------------------------------------------
189 } // end namespace gdcm