Optimize pixmap loading
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1973 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
2009-01-25 Paul Giblock <drfaygo/at/gmail/dot/com>
|
||||
2009-01-28 Paul Giblock <drfaygo/at/gmail/dot/com>
|
||||
|
||||
* src/gui/embed.cpp:
|
||||
Cache pixmaps instead of loading new ones each time
|
||||
|
||||
2009-01-26 Paul Giblock <drfaygo/at/gmail/dot/com>
|
||||
|
||||
* src/tracks/bb_track.cpp:
|
||||
Integrate broken BB-clone bug from pitanga
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* embed.cpp - misc stuff for using embedded resources (linked into binary)
|
||||
*
|
||||
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
|
||||
#include <QtGui/QImage>
|
||||
#include <QHash>
|
||||
|
||||
#include "embed.h"
|
||||
#include "config_mgr.h"
|
||||
@@ -39,6 +40,10 @@ namespace PLUGIN_NAME
|
||||
#endif
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
static QHash<QString, QPixmap> s_pixmapCache;
|
||||
}
|
||||
|
||||
#include "embedded_resources.h"
|
||||
|
||||
@@ -47,15 +52,22 @@ QPixmap getIconPixmap( const char * _name, int _w, int _h )
|
||||
{
|
||||
if( _w == -1 || _h == -1 )
|
||||
{
|
||||
// Return cached pixmap
|
||||
QPixmap cached = s_pixmapCache.value( _name );
|
||||
if( !cached.isNull() )
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
// Or try to load it
|
||||
QString name = QString( _name ) + ".png";
|
||||
|
||||
#ifdef PLUGIN_NAME
|
||||
QPixmap p( configManager::inst()->artworkDir() + "plugins/" +
|
||||
STRINGIFY( PLUGIN_NAME ) + "_" + name );
|
||||
STRINGIFY( PLUGIN_NAME ) + "_" + name );
|
||||
if( p.isNull() )
|
||||
{
|
||||
p = QPixmap( configManager::inst()->artworkDir() +
|
||||
name );
|
||||
p = QPixmap( configManager::inst()->artworkDir() + name );
|
||||
}
|
||||
#else
|
||||
// look whether icon is in artwork-dir
|
||||
@@ -64,13 +76,12 @@ QPixmap getIconPixmap( const char * _name, int _w, int _h )
|
||||
if( p.isNull() )
|
||||
{
|
||||
// nothing found, so look in default-artwork-dir
|
||||
p =
|
||||
QPixmap( configManager::inst()->defaultArtworkDir() + name );
|
||||
p = QPixmap( configManager::inst()->defaultArtworkDir() + name );
|
||||
}
|
||||
if( p.isNull() )
|
||||
{
|
||||
if( p.isNull() )
|
||||
{
|
||||
const embed::descriptor & e = findEmbeddedData(
|
||||
name.toAscii().constData() );
|
||||
name.toAscii().constData() );
|
||||
// found?
|
||||
if( QString( e.name ) == name )
|
||||
{
|
||||
@@ -81,15 +92,17 @@ QPixmap getIconPixmap( const char * _name, int _w, int _h )
|
||||
p = QPixmap( 1, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// Save to cache and return
|
||||
s_pixmapCache.insert( _name, p );
|
||||
return( p );
|
||||
}
|
||||
|
||||
return( getIconPixmap( _name ).scaled( _w, _h, Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation ) );
|
||||
Qt::SmoothTransformation ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QString getText( const char * _name )
|
||||
{
|
||||
const embed::descriptor & e = findEmbeddedData( _name );
|
||||
|
||||
Reference in New Issue
Block a user