43 std::vector<SourceDestBuffer> &dbufs,
const ustring & )
52 #ifdef E57_MAX_VERBOSE
53 std::cout <<
"Node to decode:" <<
std::endl;
54 decodeNode->dump( 2 );
57 uint64_t maxRecordCount = cVector->
childCount();
59 switch ( decodeNode->type() )
63 std::shared_ptr<IntegerNodeImpl> ini =
64 std::static_pointer_cast<IntegerNodeImpl>( decodeNode );
71 unsigned bitsPerRecord = imf->bitsNeeded( ini->minimum(), ini->maximum() );
76 if ( bitsPerRecord == 0 )
79 ini->minimum(), 1.0, 0.0, maxRecordCount ) );
83 if ( bitsPerRecord <= 8 )
86 false,
bytestreamNumber, dbufs.at( 0 ), ini->minimum(), ini->maximum(), 1.0, 0.0, maxRecordCount ) );
90 if ( bitsPerRecord <= 16 )
93 false,
bytestreamNumber, dbufs.at( 0 ), ini->minimum(), ini->maximum(), 1.0, 0.0, maxRecordCount ) );
97 if ( bitsPerRecord <= 32 )
100 false,
bytestreamNumber, dbufs.at( 0 ), ini->minimum(), ini->maximum(), 1.0, 0.0, maxRecordCount ) );
105 false,
bytestreamNumber, dbufs.at( 0 ), ini->minimum(), ini->maximum(), 1.0, 0.0, maxRecordCount ) );
111 std::shared_ptr<ScaledIntegerNodeImpl> sini =
112 std::static_pointer_cast<ScaledIntegerNodeImpl>( decodeNode );
119 unsigned bitsPerRecord = imf->bitsNeeded( sini->minimum(), sini->maximum() );
124 if ( bitsPerRecord == 0 )
127 sini->minimum(), sini->scale(),
128 sini->offset(), maxRecordCount ) );
132 if ( bitsPerRecord <= 8 )
134 std::shared_ptr<Decoder> decoder(
136 sini->maximum(), sini->scale(), sini->offset(), maxRecordCount ) );
140 if ( bitsPerRecord <= 16 )
142 std::shared_ptr<Decoder> decoder(
144 sini->maximum(), sini->scale(), sini->offset(), maxRecordCount ) );
148 if ( bitsPerRecord <= 32 )
150 std::shared_ptr<Decoder> decoder(
152 sini->maximum(), sini->scale(), sini->offset(), maxRecordCount ) );
156 std::shared_ptr<Decoder> decoder(
158 sini->maximum(), sini->scale(), sini->offset(), maxRecordCount ) );
164 std::shared_ptr<FloatNodeImpl> fni =
165 std::static_pointer_cast<FloatNodeImpl>( decodeNode );
167 std::shared_ptr<Decoder> decoder(
174 std::shared_ptr<Decoder> decoder(
192 uint64_t maxRecordCount ) :
193 Decoder( bytestreamNumber ), maxRecordCount_( maxRecordCount ), destBuffer_( dbuf.impl() ),
195 inBufferAlignmentSize_( alignmentSize ), bitsPerWord_( 8 * alignmentSize ), bytesPerWord_( alignmentSize )
201 if ( dbufs.size() != 1 )
211 #ifdef E57_MAX_VERBOSE
212 std::cout <<
"BitpackDecoder::inputprocess() called, source=" << ( source ? source :
"none" )
213 <<
" availableByteCount=" << availableByteCount <<
std::endl;
215 size_t bytesUnsaved = availableByteCount;
216 size_t bitsEaten = 0;
230 bytesUnsaved -= byteCount;
233 #ifdef E57_MAX_VERBOSE
237 for ( i = 0; i < byteCount && i < 20; i++ )
239 std::cout <<
" inBuffer[" << firstByte + i <<
"]=" << (unsigned)(
unsigned char)(
inBuffer_[firstByte + i] )
244 std::cout <<
" " << byteCount - i <<
"source bytes unprinted..." <<
std::endl;
260 #ifdef E57_MAX_VERBOSE
264 endBit - firstNaturalBit );
265 #ifdef E57_MAX_VERBOSE
266 std::cout <<
" bitsEaten=" << bitsEaten <<
" firstWord=" << firstWord <<
" firstNaturalBit=" << firstNaturalBit
285 }
while ( bytesUnsaved > 0 && bitsEaten > 0 );
288 return ( availableByteCount - bytesUnsaved );
338 for ( i = 0; i <
inBuffer_.size() && i < 20; i++ )
340 os <<
space( indent + 4 ) <<
"inBuffer[" << i
341 <<
"]: " <<
static_cast<unsigned>(
static_cast<unsigned char>(
inBuffer_.at( i ) ) ) <<
std::endl;
353 uint64_t maxRecordCount ) :
356 precision_( precision )
362 #ifdef E57_MAX_VERBOSE
363 std::cout <<
"BitpackFloatDecoder::inputProcessAligned() called, inbuf=" << inbuf <<
" firstBit=" << firstBit
377 if (
reinterpret_cast<unsigned>(inbuf) % typeSize) {
379 "inbuf=" +
toString(
reinterpret_cast<unsigned>(inbuf))
380 +
" typeSize=" +
toString(typeSize));
391 size_t maxInputRecords = ( endBit - firstBit ) / ( 8 * typeSize );
394 if ( n > maxInputRecords )
405 #ifdef E57_MAX_VERBOSE
412 auto inp =
reinterpret_cast<const float *
>( inbuf );
415 for (
unsigned i = 0; i < n; i++ )
419 #ifdef E57_MAX_VERBOSE
420 std::cout <<
" got float value=" << value <<
std::endl;
429 auto inp =
reinterpret_cast<const double *
>( inbuf );
432 for (
unsigned i = 0; i < n; i++ )
436 #ifdef E57_MAX_VERBOSE
437 std::cout <<
" got double value=" << value <<
std::endl;
448 return ( n * 8 * typeSize );
469 uint64_t maxRecordCount ) :
470 BitpackDecoder( bytestreamNumber, dbuf, sizeof( char ), maxRecordCount )
476 #ifdef E57_MAX_VERBOSE
477 std::cout <<
"BitpackStringDecoder::inputProcessAligned() called, inbuf=" << inbuf <<
" firstBit=" << firstBit
492 size_t nBytesAvailable = ( endBit - firstBit ) >> 3;
493 size_t nBytesRead = 0;
499 #ifdef E57_MAX_VERBOSE
528 #ifdef E57_MAX_VERBOSE
550 (
static_cast<uint64_t
>(
prefixBytes_[1] ) << ( 1 * 8 - 1 ) ) +
551 (
static_cast<uint64_t
>(
prefixBytes_[2] ) << ( 2 * 8 - 1 ) ) +
552 (
static_cast<uint64_t
>(
prefixBytes_[3] ) << ( 3 * 8 - 1 ) ) +
553 (
static_cast<uint64_t
>(
prefixBytes_[4] ) << ( 4 * 8 - 1 ) ) +
554 (
static_cast<uint64_t
>(
prefixBytes_[5] ) << ( 5 * 8 - 1 ) ) +
555 (
static_cast<uint64_t
>(
prefixBytes_[6] ) << ( 6 * 8 - 1 ) ) +
556 (
static_cast<uint64_t
>(
prefixBytes_[7] ) << ( 7 * 8 - 1 ) );
566 #ifdef E57_MAX_VERBOSE
581 size_t nBytesProcess = nBytesAvailable - nBytesRead;
582 if ( nBytesNeeded <
static_cast<uint64_t
>( nBytesProcess ) )
584 nBytesProcess =
static_cast<unsigned>( nBytesNeeded );
589 inbuf += nBytesProcess;
590 nBytesRead += nBytesProcess;
613 return ( nBytesRead * 8 );
622 os <<
space( indent ) <<
"prefixBytes[8]: " <<
static_cast<unsigned>(
prefixBytes_[0] ) <<
" "
629 os <<
space( indent )
642 template <
typename RegisterT>
645 double scale,
double offset, uint64_t maxRecordCount ) :
646 BitpackDecoder( bytestreamNumber, dbuf, sizeof( RegisterT ), maxRecordCount ), isScaledInteger_( isScaledInteger ),
647 minimum_( minimum ), maximum_( maximum ), scale_( scale ),
offset_(
offset )
657 template <
typename RegisterT>
659 const size_t endBit )
661 #ifdef E57_MAX_VERBOSE
662 std::cout <<
"BitpackIntegerDecoder::inputProcessAligned() called, inbuf=" << (
void *)( inbuf )
663 <<
" firstBit=" << firstBit <<
" endBit=" << endBit <<
std::endl;
673 if ((
reinterpret_cast<unsigned>(inbuf)) %
sizeof(RegisterT))
677 if ( firstBit >= 8 *
sizeof( RegisterT ) )
683 size_t destRecords = destBuffer_->capacity() - destBuffer_->nextIndex();
688 size_t bitCount = endBit - firstBit;
689 size_t maxInputRecords = bitCount / bitsPerRecord_;
693 size_t recordCount =
std::min( destRecords, maxInputRecords );
696 if (
static_cast<uint64_t
>( recordCount ) > maxRecordCount_ - currentRecordIndex_ )
698 recordCount =
static_cast<unsigned>( maxRecordCount_ - currentRecordIndex_ );
701 #ifdef E57_MAX_VERBOSE
702 std::cout <<
" recordCount=" << recordCount <<
std::endl;
705 auto inp =
reinterpret_cast<const RegisterT *
>( inbuf );
706 unsigned wordPosition = 0;
720 size_t bitOffset = firstBit;
722 for (
size_t i = 0; i < recordCount; i++ )
725 RegisterT low = inp[wordPosition];
727 #ifdef E57_MAX_VERBOSE
728 std::cout <<
" bitOffset: " << bitOffset <<
std::endl;
736 RegisterT high = inp[wordPosition + 1];
738 #ifdef E57_MAX_VERBOSE
745 w = ( high << ( 8 *
sizeof( RegisterT ) - bitOffset ) ) | ( low >> bitOffset );
754 #ifdef E57_MAX_VERBOSE
762 int64_t value = minimum_ +
static_cast<uint64_t
>( w );
764 #ifdef E57_MAX_VERBOSE
765 std::cout <<
" Storing value=" << value <<
std::endl;
770 if ( isScaledInteger_ )
772 destBuffer_->setNextInt64( value, scale_,
offset_ );
776 destBuffer_->setNextInt64( value );
782 bitOffset += bitsPerRecord_;
783 if ( bitOffset >= 8 *
sizeof( RegisterT ) )
785 bitOffset -= 8 *
sizeof( RegisterT );
788 #ifdef E57_MAX_VERBOSE
789 std::cout <<
" Processed " << i + 1 <<
" records, wordPosition=" << wordPosition <<
" decoder:" <<
std::endl;
795 currentRecordIndex_ += recordCount;
798 return ( recordCount * bitsPerRecord_ );
805 os <<
space( indent ) <<
"isScaledInteger: " << isScaledInteger_ <<
std::endl;
810 os <<
space( indent ) <<
"bitsPerRecord: " << bitsPerRecord_ <<
std::endl;
819 int64_t minimum,
double scale,
double offset,
820 uint64_t maxRecordCount ) :
821 Decoder( bytestreamNumber ), maxRecordCount_( maxRecordCount ), destBuffer_( dbuf.impl() ),
822 isScaledInteger_( isScaledInteger ), minimum_( minimum ), scale_( scale ),
offset_(
offset )
828 if ( dbufs.size() != 1 )
838 #ifdef E57_MAX_VERBOSE
839 std::cout <<
"ConstantIntegerDecoder::inputprocess() called, source=" << (
void *)( source )
840 <<
" availableByteCount=" << availableByteCount <<
std::endl;
849 if (
static_cast<uint64_t
>(
count ) > remainingRecordCount )
851 count =
static_cast<unsigned>( remainingRecordCount );
856 for (
size_t i = 0; i <
count; i++ )
863 for (
size_t i = 0; i <
count; i++ )
std::vector< char > inBuffer_
virtual size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit)=0
void stateReset() override
std::shared_ptr< SourceDestBufferImpl > destBuffer_
BitpackDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, unsigned alignmentSize, uint64_t maxRecordCount)
unsigned int inBufferAlignmentSize_
uint64_t currentRecordIndex_
void dump(int indent=0, std::ostream &os=std::cout) override
size_t inputProcess(const char *source, const size_t availableByteCount) override
void destBufferSetNew(std::vector< SourceDestBuffer > &dbufs) override
unsigned int bytesPerWord_
unsigned int bitsPerWord_
void dump(int indent=0, std::ostream &os=std::cout) override
FloatPrecision precision_
BitpackFloatDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, FloatPrecision precision, uint64_t maxRecordCount)
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
BitpackIntegerDecoder(bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum, int64_t maximum, double scale, double offset, uint64_t maxRecordCount)
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
void dump(int indent=0, std::ostream &os=std::cout) override
BitpackStringDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, uint64_t maxRecordCount)
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
void dump(int indent=0, std::ostream &os=std::cout) override
uint64_t nBytesStringRead_
int64_t childCount() const
NodeImplSharedPtr getPrototype() const
size_t inputProcess(const char *source, const size_t availableByteCount) override
void destBufferSetNew(std::vector< SourceDestBuffer > &dbufs) override
std::shared_ptr< SourceDestBufferImpl > destBuffer_
ConstantIntegerDecoder(bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum, double scale, double offset, uint64_t maxRecordCount)
void stateReset() override
uint64_t currentRecordIndex_
void dump(int indent=0, std::ostream &os=std::cout) override
static std::shared_ptr< Decoder > DecoderFactory(unsigned bytestreamNumber, const CompressedVectorNodeImpl *cVector, std::vector< SourceDestBuffer > &dbufs, const ustring &codecPath)
unsigned bytestreamNumber() const
unsigned int bytestreamNumber_
QTextStream & endl(QTextStream &stream)
static const std::string path
std::string binaryString(uint64_t x)
std::shared_ptr< class NodeImpl > NodeImplSharedPtr
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
FloatPrecision
The IEEE floating point number precisions supported.
@ E57_SINGLE
32 bit IEEE floating point number format
@ E57_ERROR_INTERNAL
An unrecoverable inconsistent internal state was detected.
@ E57_ERROR_BAD_PROTOTYPE
bad prototype in CompressedVectorNode
std::string ustring
UTF-8 encodeded Unicode string.
@ E57_INTEGER
IntegerNode class.
@ E57_SCALED_INTEGER
ScaledIntegerNode class.
@ E57_FLOAT
FloatNode class.
@ E57_STRING
StringNode class.
std::string toString(T x)
std::string space(size_t n)
std::string hexString(uint64_t x)