43 std::shared_ptr<CompressedVectorNodeImpl> cVector,
44 std::vector<SourceDestBuffer> &sbufs,
ustring & )
47 if ( sbufs.size() != 1 )
59 #ifdef E57_MAX_VERBOSE
60 std::cout <<
"Node to encode:" <<
std::endl;
61 encodeNode->dump( 2 );
63 switch ( encodeNode->type() )
67 std::shared_ptr<IntegerNodeImpl> ini =
68 std::static_pointer_cast<IntegerNodeImpl>( encodeNode );
75 unsigned bitsPerRecord = imf->bitsNeeded( ini->minimum(), ini->maximum() );
115 std::shared_ptr<ScaledIntegerNodeImpl> sini =
116 std::static_pointer_cast<ScaledIntegerNodeImpl>( encodeNode );
123 unsigned bitsPerRecord = imf->bitsNeeded( sini->minimum(), sini->maximum() );
137 std::shared_ptr<Encoder> encoder(
139 sini->minimum(), sini->maximum(), sini->scale(), sini->offset() ) );
145 std::shared_ptr<Encoder> encoder(
147 sini->minimum(), sini->maximum(), sini->scale(), sini->offset() ) );
153 std::shared_ptr<Encoder> encoder(
155 sini->minimum(), sini->maximum(), sini->scale(), sini->offset() ) );
159 std::shared_ptr<Encoder> encoder(
161 sini->maximum(), sini->scale(), sini->offset() ) );
167 std::shared_ptr<FloatNodeImpl> fni =
168 std::static_pointer_cast<FloatNodeImpl>( encodeNode );
171 std::shared_ptr<Encoder> encoder(
178 std::shared_ptr<Encoder> encoder(
205 unsigned alignmentSize ) :
206 Encoder( bytestreamNumber ), sourceBuffer_( sbuf.impl() ), outBuffer_( outputMaxSize ), outBufferFirst_( 0 ),
207 outBufferEnd_( 0 ), outBufferAlignmentSize_( alignmentSize ), currentRecordIndex_( 0 )
228 #ifdef E57_MAX_VERBOSE
229 std::cout <<
"BitpackEncoder::outputRead() called, dest=" << dest <<
" byteCount=" << byteCount <<
std::endl;
242 #ifdef E57_MAX_VERBOSE
245 for ( i = 0; i < byteCount && i < 20; i++ )
254 std::cout <<
" " << byteCount - 1 <<
" bytes unprinted..." <<
std::endl;
275 if ( sbufs.size() != 1 )
331 if ( newFirst + byteCount >
outBuffer_.size() )
334 " byteCount=" +
toString( byteCount ) +
360 for ( i = 0; i <
outBuffer_.size() && i < 20; i++ )
362 os <<
space( indent + 4 ) <<
"outBuffer[" << i
363 <<
"]: " <<
static_cast<unsigned>(
static_cast<unsigned char>(
outBuffer_.at( i ) ) ) <<
std::endl;
377 ( precision ==
E57_SINGLE ) ? sizeof( float ) : sizeof( double ) ),
378 precision_( precision )
384 #ifdef E57_MAX_VERBOSE
385 std::cout <<
" BitpackFloatEncoder::processRecords() called, recordCount=" << recordCount <<
std::endl;
406 if ( recordCount > maxOutputRecords )
408 recordCount = maxOutputRecords;
417 for (
unsigned i = 0; i < recordCount; i++ )
420 #ifdef E57_MAX_VERBOSE
421 std::cout <<
"encoding float: " << outp[i] <<
std::endl;
431 for (
unsigned i = 0; i < recordCount; i++ )
434 #ifdef E57_MAX_VERBOSE
435 std::cout <<
"encoding double: " << outp[i] <<
std::endl;
478 unsigned outputMaxSize ) :
479 BitpackEncoder( bytestreamNumber, sbuf, outputMaxSize, 1 ), totalBytesProcessed_( 0 ), isStringActive_( false ),
480 prefixComplete_( false ), currentCharPosition_( 0 )
486 #ifdef E57_MAX_VERBOSE
487 std::cout <<
" BitpackStringEncoder::processRecords() called, recordCount=" << recordCount <<
std::endl;
499 unsigned recordsProcessed = 0;
503 while ( recordsProcessed < recordCount && bytesFree >= 8 )
511 #ifdef E57_MAX_VERBOSE
512 std::cout <<
"encoding short string: (len=" << len
521 auto lengthPrefix =
static_cast<uint8_t
>( len << 1 );
522 *outp++ = lengthPrefix;
534 #ifdef E57_MAX_VERBOSE
535 std::cout <<
"encoding long string: (len=" << len
546 uint64_t lengthPrefix = (
static_cast<uint64_t
>( len ) << 1 ) | 1LL;
547 *outp++ =
static_cast<uint8_t
>( lengthPrefix );
548 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 1 * 8 ) );
549 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 2 * 8 ) );
550 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 3 * 8 ) );
551 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 4 * 8 ) );
552 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 5 * 8 ) );
553 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 6 * 8 ) );
554 *outp++ =
static_cast<uint8_t
>( lengthPrefix >> ( 7 * 8 ) );
565 for (
size_t i = 0; i < bytesToProcess; i++ )
572 bytesFree -= bytesToProcess;
588 #ifdef E57_MAX_VERBOSE
635 template <
typename RegisterT>
638 int64_t minimum, int64_t maximum,
double scale,
640 BitpackEncoder( bytestreamNumber, sbuf, outputMaxSize, sizeof( RegisterT ) )
660 #ifdef E57_MAX_VERBOSE
661 std::cout <<
"BitpackIntegerEncoder::processRecords() called, sizeof(RegisterT)=" <<
sizeof( RegisterT )
662 <<
" recordCount=" << recordCount <<
std::endl;
668 if ( 8 *
sizeof( RegisterT ) < bitsPerRecord_ )
674 outBufferShiftDown();
679 if ( outBufferEnd_ %
sizeof( RegisterT ) )
683 size_t transferMax = ( outBuffer_.size() - outBufferEnd_ ) /
sizeof( RegisterT );
688 size_t outputWordCapacity = ( outBuffer_.size() - outBufferEnd_ ) /
sizeof( RegisterT );
689 size_t maxOutputRecords =
690 ( outputWordCapacity * 8 *
sizeof( RegisterT ) + 8 *
sizeof( RegisterT ) - registerBitsUsed_ - 1 ) /
695 recordCount =
std::min( recordCount, maxOutputRecords );
696 #ifdef E57_MAX_VERBOSE
697 std::cout <<
" outputWordCapacity=" << outputWordCapacity <<
" maxOutputRecords=" << maxOutputRecords
698 <<
" recordCount=" << recordCount <<
std::endl;
702 auto outp =
reinterpret_cast<RegisterT *
>( &outBuffer_[outBufferEnd_] );
703 unsigned outTransferred = 0;
706 for (
unsigned i = 0; i < recordCount; i++ )
712 if ( isScaledInteger_ )
714 rawValue = sourceBuffer_->getNextInt64( scale_,
offset_ );
717 rawValue = sourceBuffer_->getNextInt64();
720 if ( rawValue < minimum_ || maximum_ < rawValue )
723 " minimum=" +
toString( minimum_ ) +
724 " maximum=" +
toString( maximum_ ) );
727 auto uValue =
static_cast<uint64_t
>( rawValue - minimum_ );
729 #ifdef E57_MAX_VERBOSE
730 std::cout <<
"encoding integer rawValue=" <<
binaryString( rawValue ) <<
" = " <<
hexString( rawValue )
736 if ( uValue & ~
static_cast<uint64_t
>( sourceBitMask_ ) )
742 uValue &=
static_cast<uint64_t
>( sourceBitMask_ );
745 unsigned newRegisterBitsUsed = registerBitsUsed_ + bitsPerRecord_;
746 #ifdef E57_MAX_VERBOSE
747 std::cout <<
" registerBitsUsed=" << registerBitsUsed_ <<
" newRegisterBitsUsed=" << newRegisterBitsUsed
750 if ( newRegisterBitsUsed > 8 *
sizeof( RegisterT ) )
754 register_ |=
static_cast<RegisterT
>( uValue ) << registerBitsUsed_;
757 if ( outTransferred >= transferMax )
763 outp[outTransferred] = register_;
767 register_ =
static_cast<RegisterT
>( uValue ) >> ( 8 *
sizeof( RegisterT ) - registerBitsUsed_ );
768 registerBitsUsed_ = newRegisterBitsUsed - 8 *
sizeof( RegisterT );
770 else if ( newRegisterBitsUsed == 8 *
sizeof( RegisterT ) )
773 register_ |=
static_cast<RegisterT
>( uValue ) << registerBitsUsed_;
776 if ( outTransferred >= transferMax )
782 outp[outTransferred] = register_;
787 registerBitsUsed_ = 0;
793 register_ |=
static_cast<RegisterT
>( uValue ) << registerBitsUsed_;
794 registerBitsUsed_ = newRegisterBitsUsed;
796 #ifdef E57_MAX_VERBOSE
797 std::cout <<
" After " << outTransferred <<
" transfers and " << i + 1 <<
" records, encoder:" <<
std::endl;
803 outBufferEnd_ += outTransferred *
sizeof( RegisterT );
806 if ( outBufferEnd_ > outBuffer_.size() )
809 " outBuffersize=" +
toString( outBuffer_.size() ) );
814 currentRecordIndex_ += recordCount;
816 return ( currentRecordIndex_ );
821 #ifdef E57_MAX_VERBOSE
822 std::cout <<
"BitpackIntegerEncoder::registerFlushToOutput() called, "
829 if ( registerBitsUsed_ > 0 )
831 if ( outBufferEnd_ < outBuffer_.size() -
sizeof( RegisterT ) )
833 auto outp =
reinterpret_cast<RegisterT *
>( &outBuffer_[outBufferEnd_] );
836 registerBitsUsed_ = 0;
837 outBufferEnd_ +=
sizeof( RegisterT );
849 return (
static_cast<float>( bitsPerRecord_ ) );
856 os <<
space( indent ) <<
"isScaledInteger: " << isScaledInteger_ <<
std::endl;
861 os <<
space( indent ) <<
"bitsPerRecord: " << bitsPerRecord_ <<
std::endl;
866 os <<
space( indent ) <<
"registerBitsUsed: " << registerBitsUsed_ <<
std::endl;
873 Encoder( bytestreamNumber ), sourceBuffer_( sbuf.impl() ), currentRecordIndex_( 0 ), minimum_( minimum )
879 #ifdef E57_MAX_VERBOSE
880 std::cout <<
"ConstantIntegerEncoder::processRecords() called, recordCount=" << recordCount <<
std::endl;
885 for (
unsigned i = 0; i < recordCount; i++ )
944 if ( sbufs.size() != 1 )
std::shared_ptr< SourceDestBufferImpl > sourceBuffer_
size_t outBufferAlignmentSize_
void outputSetMaxSize(unsigned byteCount) override
uint64_t currentRecordIndex_
size_t outputAvailable() const override
void dump(int indent=0, std::ostream &os=std::cout) const override
void sourceBufferSetNew(std::vector< SourceDestBuffer > &sbufs) override
size_t outputGetMaxSize() override
unsigned sourceBufferNextIndex() override
BitpackEncoder(unsigned bytestreamNumber, SourceDestBuffer &sbuf, unsigned outputMaxSize, unsigned alignmentSize)
================
std::vector< char > outBuffer_
void outputClear() override
get data from encoder
void outputRead(char *dest, const size_t byteCount) override
number of bytes that can be read
void outBufferShiftDown()
uint64_t currentRecordIndex() override
FloatPrecision precision_
uint64_t processRecords(size_t recordCount) override
void dump(int indent=0, std::ostream &os=std::cout) const override
BitpackFloatEncoder(unsigned bytestreamNumber, SourceDestBuffer &sbuf, unsigned outputMaxSize, FloatPrecision precision)
float bitsPerRecord() override
bool registerFlushToOutput() override
void dump(int indent=0, std::ostream &os=std::cout) const override
BitpackIntegerEncoder(bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &sbuf, unsigned outputMaxSize, int64_t minimum, int64_t maximum, double scale, double offset)
bool registerFlushToOutput() override
float bitsPerRecord() override
uint64_t processRecords(size_t recordCount) override
unsigned registerBitsUsed_
size_t currentCharPosition_
float bitsPerRecord() override
bool registerFlushToOutput() override
void dump(int indent=0, std::ostream &os=std::cout) const override
uint64_t processRecords(size_t recordCount) override
uint64_t totalBytesProcessed_
BitpackStringEncoder(unsigned bytestreamNumber, SourceDestBuffer &sbuf, unsigned outputMaxSize)
ConstantIntegerEncoder(unsigned bytestreamNumber, SourceDestBuffer &sbuf, int64_t minimum)
void outputRead(char *dest, const size_t byteCount) override
number of bytes that can be read
std::shared_ptr< SourceDestBufferImpl > sourceBuffer_
size_t outputGetMaxSize() override
bool registerFlushToOutput() override
unsigned sourceBufferNextIndex() override
uint64_t currentRecordIndex_
size_t outputAvailable() const override
void dump(int indent=0, std::ostream &os=std::cout) const override
void sourceBufferSetNew(std::vector< SourceDestBuffer > &sbufs) override
uint64_t processRecords(size_t recordCount) override
uint64_t currentRecordIndex() override
float bitsPerRecord() override
void outputSetMaxSize(unsigned byteCount) override
void outputClear() override
get data from encoder
static std::shared_ptr< Encoder > EncoderFactory(unsigned bytestreamNumber, std::shared_ptr< CompressedVectorNodeImpl > cVector, std::vector< SourceDestBuffer > &sbuf, ustring &codecPath)
virtual void dump(int indent=0, std::ostream &os=std::cout) const
virtual float bitsPerRecord()=0
unsigned bytestreamNumber_
Encoder(unsigned bytestreamNumber)
unsigned bytestreamNumber() const
ustring pathName() const
Get path name in prototype that this SourceDestBuffer will transfer data to/from.
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_VALUE_OUT_OF_BOUNDS
element value out of min/max bounds
@ 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)
constexpr int DATA_PACKET_MAX
maximum size of CompressedVector binary data packet
std::string space(size_t n)
std::string hexString(uint64_t x)