Skip to content
Permalink
Browse files

Add method to QgsImageCache to retrieve original image size

  • Loading branch information
nyalldawson authored and nirvn committed Dec 3, 2018
1 parent e0a6a04 commit c1df8027698989c591d51ad686e5876a26495c92
@@ -51,6 +51,18 @@ any resampling operations.

If the resultant raster was of a sufficiently small size to store in the cache, then ``fitsInCache``
will be set to true.
%End

QSize originalSize( const QString &path ) const;
%Docstring
Returns the original size (in pixels) of the image at the specified ``path``.

``path`` may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).

If ``path`` is a remote file, then an invalid size may be returned while the image is in the process
of being fetched.

If the image could not be read then an invalid QSize is returned.
%End

signals:
@@ -137,6 +137,30 @@ QImage QgsImageCache::pathAsImage( const QString &file, const QSize size, const
return result;
}

QSize QgsImageCache::originalSize( const QString &path ) const
{
// direct read if path is a file -- maybe more efficient than going the bytearray route? (untested!)
if ( QFile::exists( path ) )
{
return QImage( path ).size();
}
else
{
QByteArray ba = getContent( path, QByteArray( "broken" ), QByteArray( "fetching" ) );

if ( ba != "broken" && ba != "fetching" )
{
QBuffer buffer( &ba );
buffer.open( QIODevice::ReadOnly );

QImageReader reader( &buffer );
QImage im = reader.read();
return im.isNull() ? QSize() : im.size();
}
}
return QSize();
}

QImage QgsImageCache::renderImage( const QString &path, QSize size, const bool keepAspectRatio ) const
{
QImage im;
@@ -113,6 +113,18 @@ class CORE_EXPORT QgsImageCache : public QgsAbstractContentCache< QgsImageCacheE
*/
QImage pathAsImage( const QString &path, QSize size, bool keepAspectRatio, bool &fitsInCache SIP_OUT );

/**
* Returns the original size (in pixels) of the image at the specified \a path.
*
* \a path may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).
*
* If \a path is a remote file, then an invalid size may be returned while the image is in the process
* of being fetched.
*
* If the image could not be read then an invalid QSize is returned.
*/
QSize originalSize( const QString &path ) const;

signals:

/**
@@ -153,6 +153,8 @@ void TestQgsImageCache::changeImage()
//render it through the cache
QImage img = cache.pathAsImage( tempImagePath, QSize( 200, 200 ), true, inCache );
QVERIFY( imageCheck( "imagecache_changed_before", img, 30 ) );
QCOMPARE( cache.originalSize( tempImagePath ).width(), 511 );
QCOMPARE( cache.originalSize( tempImagePath ).height(), 800 );

// wait a second so that modified time is different
QElapsedTimer t;
@@ -199,16 +201,20 @@ void TestQgsImageCache::base64()

// invalid base64 strings
QImage img = cache.pathAsImage( QStringLiteral( "base64:" ), QSize( 200, 200 ), true, inCache );
QVERIFY( imageCheck( QStringLiteral( "null_image" ), img, 0 ) );
QVERIFY( img.isNull() );
QVERIFY( !cache.originalSize( QStringLiteral( "base64:" ) ).isValid() );

img = cache.pathAsImage( QStringLiteral( "base64:zzzzzzzzzzzzzzzzzzzz" ), QSize( 200, 200 ), true, inCache );
QVERIFY( imageCheck( QStringLiteral( "null_image" ), img, 0 ) );
QVERIFY( img.isNull() );
QVERIFY( !cache.originalSize( QStringLiteral( "base64:zzzzzzzzzzzzzzz" ) ).isValid() );

//valid base 64
img = cache.pathAsImage( QStringLiteral( "base64:iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAuIwAALiMBeKU/dgAAENZJREFUaAXtWwt0VdWZ3vvcmyePAIHaWJEOIMFKBYq2omtGmNbRMoNTpcmqOMJYJfEBU7WixVmjmWlrKT4oWLVWIApTaEMLtda0q84A7cJaB0Gwi4VABZVKoAiSx01Ccu/Z833/Pvvcc8NNuOE1a81yY87e59//6/v/f++zz0lU6qP2/zsC+kzAM6bGe/oXq8YY7U80xowyRg1XWg1TRvXX2vRBX4T7NmN0An2TVuYdpfQe9Dv9eN4fZk/5ynata/wz4dtpA1y7ftyA1sbma43W04xSk5Qx/U/B4UYEY0PcUz+NFZe8WH3V5sZT0JUhesqAn3ih/BKtUnf5RlUAZD61a2gFaCSP6g3IlsY58GHemkX2SZJ7N3b3aSHdgbm6PGW+d8d1b28WgVO4nDTgp9aOmJD09CNAMFkQ0okAme+AADDgCnD2bAyCowkh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ht3fBKdJwseyuvvW5AKz0n5BY7zp5WeV6eKu33CRXTAWhGhzxsNlJvx4qxkU1Z82eSsm5anIi2JbdsfVib2A1Q0841JJsWbqjX/oAG5TKG8xl08nSlZdxTh5XH4/DiZMJfN2cZfzFv25JZ3Mj0YuEhn8im+45UpzrU9GccgpIyJy9A4JHjMGzjLD2io9nHJmxbToDJumTWlp/ETP4liNG2EDSNu5/QmQCgo7MX0BF6wBt8I8NhAw5ix7e9+XRLyqy7OQJ62aw3vsZfvFtbsiEAULrvSCXVwcYGlcQuC3Jojzy8j7acAVPo2apN288fMPKzAP0f2GzwB95Woe1ZvpF7zFmnbM9fZKfv7ZGVcuJUoIelTVAAP8ZPmvW3Lb/8Y6IUl9qqLfgzKvU98ls+B4wySnX6Hepg0/sAzUxbHsdnH59CzK2kLau98lWrtuqNh3RevBxrZAVKJimZgRX5zbzLlLAHFYA5dxx0ztjSzHSavzEIq8eoi9ra29ZFQT9fvfVuyC+MgrZe2SpKsryb96tkKiX27AuPTYTD0KsMOyH2tV/dtO+5qjdmYIscgQX8KHZaHFQcQDrusodxsL7FAXnltPPcVBxwl117H8j76qLWtra6urr0nxSuqN56D+QWSnBYDYEdJ9+J8j7UbDNNGtMt56PA+ZMG7MAvr9783vLbtswtMN7H8XiYAgi1CMJ7rpy6AqKcA0Vn8Z9k1WbNjgFoL+SX4iF7zfBRJV9wn1idzRXVWwA69rjoog78pHWhvAPQncg49Uf35sx8y+Tpudy87NKhncdSEz1Pl+PUNAJaPwkQ/XEK6oNlUAR6G/LYAm/xP3l47yD7fwJtV4EXf3XJrNfkEXIiT258esKjOJx8Xc71YIY+xAohZwTQYjquhvQvU3Ed/+aCG9Y8SNoZA0zlZ6MB9HewSioI0h5grNUQtBfXA/sOXvTEjfWLz4Y/H9n4KAJnOQL/C8Ko4jCW8i6JAAAAAElFTkSuQmCC" ),
QSize( 200, 200 ), true, inCache );
QVERIFY( imageCheck( QStringLiteral( "imagecache_base64" ), img, 30 ) );

QSize size = cache.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Ksryb96tkKiX27AuPTYTD0KsMOyH2tV/dtO+5qjdmYIscgQX8KHZaHFQcQDrusodxsL7FAXnltPPcVBxwl117H8j76qLWtra6urr0nxSuqN56D+QWSnBYDYEdJ9+J8j7UbDNNGtMt56PA+ZMG7MAvr9783vLbtswtMN7H8XiYAgi1CMJ7rpy6AqKcA0Vn8Z9k1WbNjgFoL+SX4iF7zfBRJV9wn1idzRXVWwA69rjoog78pHWhvAPQncg49Uf35sx8y+Tpudy87NKhncdSEz1Pl+PUNAJaPwkQ/XEK6oNlUAR6G/LYAm/xP3l47yD7fwJtV4EXf3XJrNfkEXIiT258esKjOJx8Xc71YIY+xAohZwTQYjquhvQvU3Ed/+aCG9Y8SNoZA0zlZ6MB9HewSioI0h5grNUQtBfXA/sOXvTEjfWLz4Y/H9n4KAJnOQL/C8Ko4jCW8i6JAAAAAElFTkSuQmCC" ) );
QCOMPARE( size.width(), 60 );
QCOMPARE( size.height(), 60 );
}

bool TestQgsImageCache::imageCheck( const QString &testName, QImage &image, int mismatchCount )
@@ -70,19 +70,21 @@ def testRemoteImage(self):

# first should be waiting image
self.assertTrue(self.imageCheck('Remote Image', 'waiting_image', image))
self.assertFalse(QgsApplication.imageCache().originalSize(url).isValid())
self.waitForFetch()

# second should be correct image
image, in_cache = QgsApplication.imageCache().pathAsImage(url, QSize(100, 100), True)

self.assertTrue(self.imageCheck('Remote Image', 'remote_image', image))
self.assertEqual(QgsApplication.imageCache().originalSize(url), QSize(511, 800))

def testRemoteSvgMissing(self):
def testRemoteImageMissing(self):
"""Test fetching remote image with bad url"""
url = 'http://localhost:{}/qgis_local_server/xxx.png'.format(str(TestQgsImageCache.port)) # oooo naughty
image, in_cache = QgsApplication.imageCache().pathAsImage(url, QSize(100, 100), True)

self.assertTrue(self.imageCheck('Remote SVG missing', 'waiting_image', image))
self.assertTrue(self.imageCheck('Remote image missing', 'waiting_image', image))

def imageCheck(self, name, reference_image, image):
self.report += "<h2>Render {}</h2>\n".format(name)
Binary file not shown.

0 comments on commit c1df802

Please sign in to comment.
You can’t perform that action at this time.