MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteBinaryDataBlock

Method WriteBinaryDataBlock

IO/XML/vtkXMLWriter.cxx:1201–1262  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1199
1200//------------------------------------------------------------------------------
1201int vtkXMLWriter::WriteBinaryDataBlock(unsigned char* in_data, size_t numWords, int wordType)
1202{
1203 unsigned char* data = in_data;
1204#ifdef VTK_USE_64BIT_IDS
1205 // If the type is vtkIdType, it may need to be converted to the type
1206 // requested for output.
1207 if ((wordType == VTK_ID_TYPE) && (this->IdType == vtkXMLWriter::Int32))
1208 {
1209 vtkIdType* idBuffer = reinterpret_cast<vtkIdType*>(in_data);
1210
1211 for (size_t i = 0; i < numWords; ++i)
1212 {
1213 this->Int32IdTypeBuffer[i] = static_cast<Int32IdType>(idBuffer[i]);
1214 }
1215
1216 data = reinterpret_cast<unsigned char*>(this->Int32IdTypeBuffer);
1217 }
1218#endif
1219
1220 // Get the word size of the data buffer. This is now the size that
1221 // will be written.
1222 size_t wordSize = this->GetOutputWordTypeSize(wordType);
1223
1224 // If we need to byte swap, do it now.
1225 if (this->ByteSwapBuffer)
1226 {
1227 // If we are converting vtkIdType to 32-bit integer data, the data
1228 // are already in the byte swap buffer because we share the
1229 // conversion buffer. Otherwise, we need to copy the data before
1230 // byte swapping.
1231 if (data != this->ByteSwapBuffer)
1232 {
1233 memcpy(this->ByteSwapBuffer, data, numWords * wordSize);
1234 data = this->ByteSwapBuffer;
1235 }
1236 this->PerformByteSwap(this->ByteSwapBuffer, numWords, wordSize);
1237 }
1238
1239 // Now pass the data to the next write phase.
1240 if (this->Compressor)
1241 {
1242 int res = this->WriteCompressionBlock(data, numWords * wordSize);
1243 this->Stream->flush();
1244 if (this->Stream->fail())
1245 {
1246 this->SetErrorCode(vtkErrorCode::GetLastSystemError());
1247 return 0;
1248 }
1249 return res;
1250 }
1251 else
1252 {
1253 int res = this->DataStream->Write(data, numWords * wordSize);
1254 this->Stream->flush();
1255 if (this->Stream->fail())
1256 {
1257 this->SetErrorCode(vtkErrorCode::GetLastSystemError());
1258 return 0;

Callers 1

WriteBinaryDataBlockFunction · 0.80

Calls 5

GetOutputWordTypeSizeMethod · 0.95
PerformByteSwapMethod · 0.95
WriteCompressionBlockMethod · 0.95
flushMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected