From 4970958253fecca19499b1e7ba3ddca7716bfd4b Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Apr 2022 23:50:33 +0800 Subject: [PATCH] fix:mdx dictionary support tiff image --- mdx.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mdx.cc b/mdx.cc index fc2941e7..4ed63382 100644 --- a/mdx.cc +++ b/mdx.cc @@ -40,6 +40,7 @@ #include +#include "tiff.hh" #include "utils.hh" namespace Mdx @@ -971,6 +972,37 @@ void MddResourceRequest::run() data.resize( bytes.size() ); memcpy( &data.front(), bytes.constData(), bytes.size() ); } + if( Filetype::isNameOfTiff( u8ResourceName ) ) + { + // Convert it + + dataMutex.lock(); + + QImage img = QImage::fromData( (unsigned char *)&data.front(), data.size() ); + +#ifdef MAKE_EXTRA_TIFF_HANDLER + if( img.isNull() ) + GdTiff::tiffToQImage( &data.front(), data.size(), img ); +#endif + + dataMutex.unlock(); + + if( !img.isNull() ) + { + // Managed to load -- now store it back as BMP + + QByteArray ba; + QBuffer buffer( &ba ); + buffer.open( QIODevice::WriteOnly ); + img.save( &buffer, "png" ); + + Mutex::Lock _( dataMutex ); + + data.resize( buffer.size() ); + + memcpy( &data.front(), buffer.data(), data.size() ); + } + } } break; }