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

Method ReadCompressedData

IO/XMLParser/vtkXMLDataParser.cxx:704–837  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

702
703//------------------------------------------------------------------------------
704size_t vtkXMLDataParser::ReadCompressedData(
705 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize)
706{
707 // Make sure there are data.
708 if (numWords == 0)
709 {
710 return 0;
711 }
712
713 // Find the begin and end offsets into the data.
714 vtkTypeUInt64 beginOffset = startWord * wordSize;
715 vtkTypeUInt64 endOffset = beginOffset + numWords * wordSize;
716
717 // Find the total size of the data.
718 vtkTypeUInt64 totalSize = this->NumberOfBlocks * this->BlockUncompressedSize;
719 if (this->PartialLastBlockUncompressedSize)
720 {
721 totalSize -= this->BlockUncompressedSize;
722 totalSize += this->PartialLastBlockUncompressedSize;
723 }
724
725 // Make sure there's even data to be read
726 if (totalSize == 0)
727 {
728 return 0;
729 }
730
731 // Adjust the size to be a multiple of the wordSize by taking
732 // advantage of integer division. This will only change the value
733 // when the input file is invalid.
734 totalSize = (totalSize / wordSize) * wordSize;
735
736 // Make sure the begin/end offsets fall within the total size.
737 if (beginOffset > totalSize)
738 {
739 return 0;
740 }
741 endOffset = std::min(endOffset, totalSize);
742
743 // Find the range of compression blocks to read.
744 vtkTypeUInt64 firstBlock = beginOffset / this->BlockUncompressedSize;
745 vtkTypeUInt64 lastBlock = endOffset / this->BlockUncompressedSize;
746
747 // Find the offset into the first block where the data begin.
748 size_t beginBlockOffset = beginOffset - firstBlock * this->BlockUncompressedSize;
749
750 // Find the offset into the last block where the data end.
751 size_t endBlockOffset = endOffset - lastBlock * this->BlockUncompressedSize;
752
753 this->UpdateProgress(0);
754 if (firstBlock == lastBlock)
755 {
756 // Everything fits in one block.
757 unsigned char* blockBuffer = this->ReadBlock(firstBlock);
758 if (!blockBuffer)
759 {
760 return 0;
761 }

Callers 1

ReadBinaryDataMethod · 0.95

Calls 5

UpdateProgressMethod · 0.95
ReadBlockMethod · 0.95
PerformByteSwapMethod · 0.95
FindBlockSizeMethod · 0.95
minFunction · 0.50

Tested by

no test coverage detected