Skip to content

Commit

Permalink
tiff2img buffer copy
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Feb 9, 2025
1 parent d7ca99c commit dadba36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/tiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

namespace GdTiff {

void tiff2img( std::vector< char > & data, const char * format )
void tiff2img( std::vector< char > & data )
{
QImage img = QImage::fromData( (unsigned char *)&data.front(), data.size() );

if ( !img.isNull() ) {
QByteArray ba;
QBuffer buffer( &ba );

QBuffer buffer( &ba ); // buffer doesn't own ba
buffer.open( QIODevice::WriteOnly );

QSize screenSize = QApplication::primaryScreen()->availableSize();
QSize imgSize = img.size();
int scaleSize = qMin( imgSize.width(), screenSize.width() );
img.scaledToWidth( scaleSize ).save( &buffer, format );
buffer.setData( data.data(),data.size() );
buffer.close();
img.scaledToWidth( scaleSize ).save( &buffer, "webp" );

memcpy( data.data(), ba.data(), ba.size() );
data.resize( ba.size() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tiff.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include <vector>
namespace GdTiff {

void tiff2img( std::vector< char > & data, const char * format = "webp" );
void tiff2img( std::vector< char > & data );

}

0 comments on commit dadba36

Please sign in to comment.