Add const version of PackFrameImage().

Temporary buffer needs to be handled outside of the function.
This commit is contained in:
Bartosz Taudul 2019-09-20 22:55:55 +02:00
parent b362baed5f
commit e1e5d6bd47
2 changed files with 15 additions and 0 deletions

View File

@ -5199,6 +5199,20 @@ const char* Worker::GetFailureString( Worker::Failure failure )
return s_failureReasons[(int)failure]; return s_failureReasons[(int)failure];
} }
void Worker::PackFrameImage( char*& buf, size_t& bufsz, const char* image, uint16_t w, uint16_t h, uint32_t& csz ) const
{
const auto insz = size_t( w ) * size_t( h ) / 2;
const auto maxout = LZ4_COMPRESSBOUND( insz );
if( bufsz < maxout )
{
bufsz = maxout;
delete[] buf;
buf = new char[maxout];
}
const auto outsz = LZ4_compress_default( image, buf, insz, maxout );
csz = uint32_t( outsz );
}
const char* Worker::PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz ) const char* Worker::PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz )
{ {
const auto insz = size_t( w ) * size_t( h ) / 2; const auto insz = size_t( w ) * size_t( h ) / 2;

View File

@ -393,6 +393,7 @@ public:
const FailureData& GetFailureData() const { return m_failureData; } const FailureData& GetFailureData() const { return m_failureData; }
static const char* GetFailureString( Failure failure ); static const char* GetFailureString( Failure failure );
void PackFrameImage( char*& buf, size_t& bufsz, const char* image, uint16_t w, uint16_t h, uint32_t& csz ) const;
const char* PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz ); const char* PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz );
const char* UnpackFrameImage( const FrameImage& image ); const char* UnpackFrameImage( const FrameImage& image );