00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmBinEntry.h"
00020 #include "gdcmContentEntry.h"
00021
00022 #include "gdcmDebug.h"
00023
00024 #include <fstream>
00025 #include <sstream>
00026 #include <iostream>
00027
00028 namespace gdcm
00029 {
00030
00031
00035 BinEntry::BinEntry(DictEntry *e)
00036 :ContentEntry(e)
00037 {
00038 BinArea = 0;
00039 SelfArea = true;
00040 }
00041
00046 BinEntry::BinEntry(DocEntry *e)
00047 : ContentEntry(e->GetDictEntry())
00048 {
00049 Copy(e);
00050
00051 BinArea = 0;
00052 SelfArea = true;
00053 }
00054
00058 BinEntry::~BinEntry()
00059 {
00060 if (BinArea && SelfArea)
00061 {
00062 delete[] BinArea;
00063 BinArea = 0;
00064 }
00065 }
00066
00067
00068
00074 void BinEntry::WriteContent(std::ofstream *fp, FileType filetype)
00075 {
00076 DocEntry::WriteContent(fp, filetype);
00077 void* binArea = GetBinArea();
00078 int lgr = GetLength();
00079 if (binArea)
00080 {
00081
00082
00083
00084
00085
00086
00087 #ifdef GDCM_WORDS_BIGENDIAN
00088 const int BUFFER_SIZE = 4096;
00089
00090
00091
00092
00093 if (GetGroup() == 0x7fe0 && GetVR() == "OW")
00094 {
00095 uint16_t *buffer = new uint16_t[BUFFER_SIZE/2];
00096
00097
00098 int nbPieces = lgr/BUFFER_SIZE;
00099 int remainingSize = lgr%BUFFER_SIZE;
00100
00101 uint16_t *binArea16 = (uint16_t*)binArea;
00102 for (int j=0;j<nbPieces;j++)
00103 {
00104 for (int i = 0; i < BUFFER_SIZE/2; i++)
00105 {
00106
00107 uint16_t val = binArea16[i];
00108 buffer[i] = ((( val << 8 ) & 0xff00 ) | (( val >> 8 ) & 0x00ff ) );
00109 }
00110 fp->write ( (char*)buffer, BUFFER_SIZE );
00111 binArea16 += BUFFER_SIZE/2;
00112 }
00113 if ( remainingSize > 0)
00114 {
00115 for (int i = 0; i < remainingSize/2; i++)
00116 {
00117
00118 uint16_t val = binArea16[i];
00119 buffer[i] = ((( val << 8 ) & 0xff00 ) | (( val >> 8 ) & 0x00ff ) );
00120 }
00121 fp->write ( (char*)buffer, remainingSize );
00122 }
00123 delete[] buffer;
00124 }
00125 else
00126 {
00127
00128 fp->write ( (char*)binArea, lgr );
00129 }
00130 #else
00131 fp->write ( (char*)binArea, lgr );
00132 #endif //GDCM_WORDS_BIGENDIAN
00133
00134 }
00135 else
00136 {
00137
00138 fp->seekp(lgr, std::ios::cur);
00139 }
00140 }
00141
00145 void BinEntry::SetBinArea( uint8_t *area, bool self )
00146 {
00147 if (BinArea && SelfArea)
00148 delete[] BinArea;
00149
00150 BinArea = area;
00151 SelfArea=self;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00167 void BinEntry::Print(std::ostream &os, std::string const & )
00168 {
00169 os << "B ";
00170 DocEntry::Print(os);
00171 std::ostringstream s;
00172 void* binArea = GetBinArea();
00173 if (binArea)
00174 {
00175 s << " [" << GetValue()
00176 << "; length = " << GetLength() << "]";
00177 }
00178 else
00179 {
00180 if ( GetLength() == 0 )
00181 {
00182 s << " []";
00183 }
00184 else
00185 {
00186 s << " [" <<GetValue() << "]";
00187 }
00188 }
00189 os << s.str();
00190 }
00191
00192
00193 }