2014-02-11 14:02:00 +00:00
|
|
|
/* This file is (c) 2014 Abs62
|
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
2014-02-16 10:22:13 +00:00
|
|
|
|
2023-04-15 23:00:58 +00:00
|
|
|
#include "tiff.hh"
|
2014-02-11 14:02:00 +00:00
|
|
|
#include <QBuffer>
|
2022-04-17 10:28:01 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QScreen>
|
2014-02-11 14:02:00 +00:00
|
|
|
|
2023-04-15 23:00:58 +00:00
|
|
|
namespace GdTiff {
|
2014-02-11 14:02:00 +00:00
|
|
|
|
2023-04-15 23:00:58 +00:00
|
|
|
void tiff2img( std::vector< char > & data, const char * format )
|
2022-04-05 13:25:07 +00:00
|
|
|
{
|
|
|
|
QImage img = QImage::fromData( (unsigned char *)&data.front(), data.size() );
|
|
|
|
|
2023-04-15 23:00:58 +00:00
|
|
|
if ( !img.isNull() ) {
|
2022-04-05 13:25:07 +00:00
|
|
|
QByteArray ba;
|
|
|
|
QBuffer buffer( &ba );
|
|
|
|
buffer.open( QIODevice::WriteOnly );
|
2022-04-17 10:28:01 +00:00
|
|
|
QSize screenSize = QApplication::primaryScreen()->availableSize();
|
|
|
|
QSize imgSize = img.size();
|
|
|
|
int scaleSize = qMin( imgSize.width(), screenSize.width() );
|
|
|
|
|
|
|
|
img.scaledToWidth( scaleSize ).save( &buffer, format );
|
2022-04-05 13:25:07 +00:00
|
|
|
|
|
|
|
data.resize( buffer.size() );
|
|
|
|
memcpy( &data.front(), buffer.data(), data.size() );
|
|
|
|
buffer.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-15 23:00:58 +00:00
|
|
|
} // namespace GdTiff
|