mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
optimize: tiff method refactor
This commit is contained in:
parent
64d989f9c5
commit
67c74136e8
29
dsl.cc
29
dsl.cc
|
@ -1919,33 +1919,8 @@ void DslResourceRequest::run()
|
|||
{
|
||||
// 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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
|
29
gls.cc
29
gls.cc
|
@ -1287,33 +1287,8 @@ void GlsResourceRequest::run()
|
|||
{
|
||||
// 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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
|
||||
if( Filetype::isNameOfCSS( resourceName ) )
|
||||
|
|
31
mdx.cc
31
mdx.cc
|
@ -975,33 +975,8 @@ void MddResourceRequest::run()
|
|||
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, "webp" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1096,8 +1071,6 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar
|
|||
QString id = QString::fromStdString( getId() );
|
||||
QString uniquePrefix = QString::fromLatin1( "g" ) + id + "_" + articleId + "_";
|
||||
|
||||
|
||||
|
||||
QString articleNewText;
|
||||
int linkPos = 0;
|
||||
QRegularExpressionMatchIterator it = mdxRx.allLinksRe.globalMatch( article );
|
||||
|
|
28
slob.cc
28
slob.cc
|
@ -1589,32 +1589,8 @@ void SlobResourceRequest::run()
|
|||
{
|
||||
// Convert it
|
||||
|
||||
dataMutex.lock();
|
||||
|
||||
QImage img = QImage::fromData( reinterpret_cast< const uchar * >( resource.data() ), resource.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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
29
stardict.cc
29
stardict.cc
|
@ -1731,33 +1731,8 @@ void StardictResourceRequest::run()
|
|||
{
|
||||
// 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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
|
||||
if( Filetype::isNameOfCSS( resourceName ) )
|
||||
|
|
22
tiff.cc
22
tiff.cc
|
@ -139,6 +139,28 @@ bool tiffToQImage( const char * data, int size, QImage & image )
|
|||
return false;
|
||||
}
|
||||
|
||||
void tiff2img( vector< char > & data, const char * format )
|
||||
{
|
||||
QImage img = QImage::fromData( (unsigned char *)&data.front(), data.size() );
|
||||
|
||||
#ifdef MAKE_EXTRA_TIFF_HANDLER
|
||||
if( img.isNull() )
|
||||
tiffToQImage( &data.front(), data.size(), img );
|
||||
#endif
|
||||
|
||||
if( !img.isNull() )
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer( &ba );
|
||||
buffer.open( QIODevice::WriteOnly );
|
||||
img.save( &buffer, format );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
buffer.close();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
|
5
tiff.hh
5
tiff.hh
|
@ -4,7 +4,8 @@
|
|||
#ifdef MAKE_EXTRA_TIFF_HANDLER
|
||||
|
||||
#include <QImage>
|
||||
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
namespace GdTiff
|
||||
{
|
||||
|
||||
|
@ -12,7 +13,7 @@ namespace GdTiff
|
|||
// We will handle such 1-bit b/w images with default photometric
|
||||
|
||||
bool tiffToQImage( const char * data, int size, QImage & image );
|
||||
|
||||
void tiff2img( vector< char > & data, const char * format = "webp" );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
30
xdxf.cc
30
xdxf.cc
|
@ -1091,34 +1091,8 @@ void XdxfResourceRequest::run()
|
|||
if ( Filetype::isNameOfTiff( resourceName ) )
|
||||
{
|
||||
// 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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
|
29
zim.cc
29
zim.cc
|
@ -1424,33 +1424,8 @@ void ZimResourceRequest::run()
|
|||
if ( Filetype::isNameOfTiff( resourceName ) )
|
||||
{
|
||||
// Convert it
|
||||
|
||||
dataMutex.lock();
|
||||
|
||||
QImage img = QImage::fromData( reinterpret_cast< const uchar * >( resource.data() ), resource.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, "BMP" );
|
||||
|
||||
Mutex::Lock _( dataMutex );
|
||||
|
||||
data.resize( buffer.size() );
|
||||
|
||||
memcpy( &data.front(), buffer.data(), data.size() );
|
||||
}
|
||||
Mutex::Lock _( dataMutex );
|
||||
GdTiff::tiff2img( data );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue