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

Method ReadCompressionHeader

IO/XMLParser/vtkXMLDataParser.cxx:518–578  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

516
517//------------------------------------------------------------------------------
518int vtkXMLDataParser::ReadCompressionHeader()
519{
520 std::unique_ptr<vtkXMLDataHeader> ch(vtkXMLDataHeader::New(this->HeaderType, 3));
521
522 this->DataStream->StartReading();
523
524 // Read the standard part of the header.
525 size_t const headerSize = ch->DataSize();
526 size_t r = this->DataStream->Read(ch->Data(), headerSize);
527 if (r < headerSize)
528 {
529 vtkErrorMacro("Error reading beginning of compression header. Read "
530 << r << " of " << headerSize << " bytes.");
531 return 0;
532 }
533
534 // Byte swap the header to make sure the values are correct.
535 this->PerformByteSwap(ch->Data(), ch->WordCount(), ch->WordSize());
536
537 // Get the standard values.
538 this->NumberOfBlocks = size_t(ch->Get(0));
539 this->BlockUncompressedSize = size_t(ch->Get(1));
540 this->PartialLastBlockUncompressedSize = size_t(ch->Get(2));
541
542 // Allocate the size and offset parts of the header.
543 ch->Resize(this->NumberOfBlocks);
544 delete[] this->BlockCompressedSizes;
545 this->BlockCompressedSizes = nullptr;
546 delete[] this->BlockStartOffsets;
547 this->BlockStartOffsets = nullptr;
548 if (this->NumberOfBlocks > 0)
549 {
550 this->BlockCompressedSizes = new size_t[this->NumberOfBlocks];
551 this->BlockStartOffsets = new vtkTypeInt64[this->NumberOfBlocks];
552
553 // Read the compressed block sizes.
554 size_t len = ch->DataSize();
555 if (this->DataStream->Read(ch->Data(), len) < len)
556 {
557 vtkErrorMacro("Error reading compression header.");
558 return 0;
559 }
560
561 // Byte swap the sizes to make sure the values are correct.
562 this->PerformByteSwap(ch->Data(), ch->WordCount(), ch->WordSize());
563 }
564
565 this->DataStream->EndReading();
566
567 // Use the compressed block sizes to calculate the starting offset
568 // of each block.
569 vtkTypeInt64 offset = 0;
570 for (size_t i = 0; i < this->NumberOfBlocks; ++i)
571 {
572 size_t const sz = size_t(ch->Get(i));
573 this->BlockCompressedSizes[i] = sz;
574 this->BlockStartOffsets[i] = offset;
575 offset += sz;

Callers 1

ReadBinaryDataMethod · 0.95

Calls 10

PerformByteSwapMethod · 0.95
WordCountMethod · 0.80
WordSizeMethod · 0.80
NewFunction · 0.50
StartReadingMethod · 0.45
ReadMethod · 0.45
DataMethod · 0.45
GetMethod · 0.45
ResizeMethod · 0.45
EndReadingMethod · 0.45

Tested by

no test coverage detected