author | sandman <sandman> | 2002-12-10 23:18:22 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-10 23:18:22 (UTC) |
commit | 763b6ad10dbb7a23c446347cb7fb88cfbadd3e27 (patch) (unidiff) | |
tree | 0da5085b632bcd5084065c7814007e413600a7d4 | |
parent | 967fa32fa3eb3296f675c9d7af8cce838c6b592b (diff) | |
download | opie-763b6ad10dbb7a23c446347cb7fb88cfbadd3e27.zip opie-763b6ad10dbb7a23c446347cb7fb88cfbadd3e27.tar.gz opie-763b6ad10dbb7a23c446347cb7fb88cfbadd3e27.tar.bz2 |
added a little debug output to the image loading routine to aid in finding
application startup time problems
-rw-r--r-- | library/resource.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index 0920b67..6f164c7 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -9,192 +9,194 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | 21 | #define QTOPIA_INTERNAL_MIMEEXT |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include "resource.h" | 23 | #include "resource.h" |
24 | #include "mimetype.h" | 24 | #include "mimetype.h" |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qregexp.h> | 27 | #include <qregexp.h> |
28 | #include <qpixmapcache.h> | 28 | #include <qpixmapcache.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | 30 | ||
31 | // this namespace is just a workaround for a gcc bug | 31 | // this namespace is just a workaround for a gcc bug |
32 | // gcc exports inline functions in the generated file | 32 | // gcc exports inline functions in the generated file |
33 | // inlinepics_p.h | 33 | // inlinepics_p.h |
34 | 34 | ||
35 | namespace { | 35 | namespace { |
36 | #include "inlinepics_p.h" | 36 | #include "inlinepics_p.h" |
37 | } | 37 | } |
38 | 38 | ||
39 | /*! | 39 | /*! |
40 | \class Resource resource.h | 40 | \class Resource resource.h |
41 | \brief The Resource class provides access to named resources. | 41 | \brief The Resource class provides access to named resources. |
42 | 42 | ||
43 | The resources may be provided from files or other sources. | 43 | The resources may be provided from files or other sources. |
44 | 44 | ||
45 | The allSounds() function returns a list of all the sounds available. | 45 | The allSounds() function returns a list of all the sounds available. |
46 | A particular sound can be searched for using findSound(). | 46 | A particular sound can be searched for using findSound(). |
47 | 47 | ||
48 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 48 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
49 | and loadIconSet(). | 49 | and loadIconSet(). |
50 | 50 | ||
51 | \ingroup qtopiaemb | 51 | \ingroup qtopiaemb |
52 | */ | 52 | */ |
53 | 53 | ||
54 | /*! | 54 | /*! |
55 | \fn Resource::Resource() | 55 | \fn Resource::Resource() |
56 | \internal | 56 | \internal |
57 | */ | 57 | */ |
58 | 58 | ||
59 | /*! | 59 | /*! |
60 | Returns the QPixmap called \a pix. You should avoid including | 60 | Returns the QPixmap called \a pix. You should avoid including |
61 | any filename type extension (e.g. .png, .xpm). | 61 | any filename type extension (e.g. .png, .xpm). |
62 | */ | 62 | */ |
63 | QPixmap Resource::loadPixmap( const QString &pix ) | 63 | QPixmap Resource::loadPixmap( const QString &pix ) |
64 | { | 64 | { |
65 | QPixmap pm; | 65 | QPixmap pm; |
66 | QString key="QPE_"+pix; | 66 | QString key="QPE_"+pix; |
67 | if ( !QPixmapCache::find(key,pm) ) { | 67 | if ( !QPixmapCache::find(key,pm) ) { |
68 | pm.convertFromImage(loadImage(pix)); | 68 | pm.convertFromImage(loadImage(pix)); |
69 | QPixmapCache::insert(key,pm); | 69 | QPixmapCache::insert(key,pm); |
70 | } | 70 | } |
71 | return pm; | 71 | return pm; |
72 | } | 72 | } |
73 | 73 | ||
74 | /*! | 74 | /*! |
75 | Returns the QBitmap called \a pix. You should avoid including | 75 | Returns the QBitmap called \a pix. You should avoid including |
76 | any filename type extension (e.g. .png, .xpm). | 76 | any filename type extension (e.g. .png, .xpm). |
77 | */ | 77 | */ |
78 | QBitmap Resource::loadBitmap( const QString &pix ) | 78 | QBitmap Resource::loadBitmap( const QString &pix ) |
79 | { | 79 | { |
80 | QBitmap bm; | 80 | QBitmap bm; |
81 | bm = loadPixmap(pix); | 81 | bm = loadPixmap(pix); |
82 | return bm; | 82 | return bm; |
83 | } | 83 | } |
84 | 84 | ||
85 | /*! | 85 | /*! |
86 | Returns the filename of a pixmap called \a pix. You should avoid including | 86 | Returns the filename of a pixmap called \a pix. You should avoid including |
87 | any filename type extension (e.g. .png, .xpm). | 87 | any filename type extension (e.g. .png, .xpm). |
88 | 88 | ||
89 | Normally you will use loadPixmap() rather than this function. | 89 | Normally you will use loadPixmap() rather than this function. |
90 | */ | 90 | */ |
91 | QString Resource::findPixmap( const QString &pix ) | 91 | QString Resource::findPixmap( const QString &pix ) |
92 | { | 92 | { |
93 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 93 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
94 | 94 | ||
95 | QString f; | 95 | QString f; |
96 | 96 | ||
97 | // Common case optimizations... | 97 | // Common case optimizations... |
98 | f = picsPath + pix + ".png"; | 98 | f = picsPath + pix + ".png"; |
99 | if ( QFile( f ).exists() ) | 99 | if ( QFile( f ).exists() ) |
100 | return f; | 100 | return f; |
101 | f = picsPath + pix + ".xpm"; | 101 | f = picsPath + pix + ".xpm"; |
102 | if ( QFile( f ).exists() ) | 102 | if ( QFile( f ).exists() ) |
103 | return f; | 103 | return f; |
104 | 104 | ||
105 | qDebug ( "\nLoading of image '%s' is not ideal (either it doesn't exist or an extension was specified)\n", pix.latin1()); | ||
106 | |||
105 | // All formats... | 107 | // All formats... |
106 | QStrList fileFormats = QImageIO::inputFormats(); | 108 | QStrList fileFormats = QImageIO::inputFormats(); |
107 | QString ff = fileFormats.first(); | 109 | QString ff = fileFormats.first(); |
108 | while ( fileFormats.current() ) { | 110 | while ( fileFormats.current() ) { |
109 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 111 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
110 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 112 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
111 | QString f = picsPath + pix + "." + *it; | 113 | QString f = picsPath + pix + "." + *it; |
112 | if ( QFile(f).exists() ) | 114 | if ( QFile(f).exists() ) |
113 | return f; | 115 | return f; |
114 | } | 116 | } |
115 | ff = fileFormats.next(); | 117 | ff = fileFormats.next(); |
116 | } | 118 | } |
117 | 119 | ||
118 | // Finally, no (or existing) extension... | 120 | // Finally, no (or existing) extension... |
119 | if ( QFile( picsPath + pix ).exists() ) | 121 | if ( QFile( picsPath + pix ).exists() ) |
120 | return picsPath + pix; | 122 | return picsPath + pix; |
121 | 123 | ||
122 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 124 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
123 | return QString(); | 125 | return QString(); |
124 | } | 126 | } |
125 | 127 | ||
126 | /*! | 128 | /*! |
127 | Returns a sound file for a sound called \a name. | 129 | Returns a sound file for a sound called \a name. |
128 | 130 | ||
129 | You should avoid including any filename type extension (e.g. .wav), | 131 | You should avoid including any filename type extension (e.g. .wav), |
130 | as the system will search for only those fileformats which are supported | 132 | as the system will search for only those fileformats which are supported |
131 | by the library. | 133 | by the library. |
132 | 134 | ||
133 | Currently, only WAV files are supported. | 135 | Currently, only WAV files are supported. |
134 | */ | 136 | */ |
135 | QString Resource::findSound( const QString &name ) | 137 | QString Resource::findSound( const QString &name ) |
136 | { | 138 | { |
137 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 139 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
138 | 140 | ||
139 | QString result; | 141 | QString result; |
140 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 142 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
141 | return result; | 143 | return result; |
142 | 144 | ||
143 | return QString(); | 145 | return QString(); |
144 | } | 146 | } |
145 | 147 | ||
146 | /*! | 148 | /*! |
147 | Returns a list of all sound names. | 149 | Returns a list of all sound names. |
148 | */ | 150 | */ |
149 | QStringList Resource::allSounds() | 151 | QStringList Resource::allSounds() |
150 | { | 152 | { |
151 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 153 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
152 | QStringList entries = resourcedir.entryList(); | 154 | QStringList entries = resourcedir.entryList(); |
153 | QStringList result; | 155 | QStringList result; |
154 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 156 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
155 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 157 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
156 | return result; | 158 | return result; |
157 | } | 159 | } |
158 | 160 | ||
159 | static QImage load_image(const QString &name) | 161 | static QImage load_image(const QString &name) |
160 | { | 162 | { |
161 | QImage img = qembed_findImage(name.latin1()); | 163 | QImage img = qembed_findImage(name.latin1()); |
162 | if ( img.isNull() ) { | 164 | if ( img.isNull() ) { |
163 | // No inlined image, try file | 165 | // No inlined image, try file |
164 | QString f = Resource::findPixmap(name); | 166 | QString f = Resource::findPixmap(name); |
165 | if ( !f.isEmpty() ) | 167 | if ( !f.isEmpty() ) |
166 | img.load(f); | 168 | img.load(f); |
167 | } | 169 | } |
168 | return img; | 170 | return img; |
169 | } | 171 | } |
170 | 172 | ||
171 | /*! | 173 | /*! |
172 | Returns the QImage called \a name. You should avoid including | 174 | Returns the QImage called \a name. You should avoid including |
173 | any filename type extension (e.g. .png, .xpm). | 175 | any filename type extension (e.g. .png, .xpm). |
174 | */ | 176 | */ |
175 | QImage Resource::loadImage( const QString &name) | 177 | QImage Resource::loadImage( const QString &name) |
176 | { | 178 | { |
177 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 179 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
178 | static QImage last_enabled; | 180 | static QImage last_enabled; |
179 | static QString last_enabled_name; | 181 | static QString last_enabled_name; |
180 | if ( name == last_enabled_name ) | 182 | if ( name == last_enabled_name ) |
181 | return last_enabled; | 183 | return last_enabled; |
182 | #endif | 184 | #endif |
183 | QImage img = load_image(name); | 185 | QImage img = load_image(name); |
184 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 186 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
185 | if ( img.isNull() ) { | 187 | if ( img.isNull() ) { |
186 | // No file, try generating | 188 | // No file, try generating |
187 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 189 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
188 | last_enabled_name = name.left(name.length()-9); | 190 | last_enabled_name = name.left(name.length()-9); |
189 | last_enabled = load_image(last_enabled_name); | 191 | last_enabled = load_image(last_enabled_name); |
190 | if ( last_enabled.isNull() ) { | 192 | if ( last_enabled.isNull() ) { |
191 | last_enabled_name = QString::null; | 193 | last_enabled_name = QString::null; |
192 | } else { | 194 | } else { |
193 | img.detach(); | 195 | img.detach(); |
194 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 196 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
195 | for ( int y = 0; y < img.height(); y++ ) { | 197 | for ( int y = 0; y < img.height(); y++ ) { |
196 | for ( int x = 0; x < img.width(); x++ ) { | 198 | for ( int x = 0; x < img.width(); x++ ) { |
197 | QRgb p = last_enabled.pixel( x, y ); | 199 | QRgb p = last_enabled.pixel( x, y ); |
198 | int a = qAlpha(p)/3; | 200 | int a = qAlpha(p)/3; |
199 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 201 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
200 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 202 | img.setPixel( x, y, qRgba(g,g,g,a) ); |