summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/lib/imagecache.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/lib/imagecache.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/lib/imagecache.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/lib/imagecache.cpp b/noncore/graphics/opie-eye/lib/imagecache.cpp
new file mode 100644
index 0000000..3b74a83
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/imagecache.cpp
@@ -0,0 +1,87 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#include <iface/dirview.h>
7#include <iface/dirlister.h>
8
9#include "imagecache.h"
10
11namespace {
12 PImageCache * _imgCache = 0;
13 PPixmapCache* _pxmCache = 0;
14}
15
16
17PImageCache::PImageCache()
18 : QCache<QImage>()
19{
20 /* just to set an initial value.. 4 big images */
21 setMaxCost( (1024*1024*16)/8*4 );
22}
23
24PImageCache::~PImageCache() {
25}
26
27PImageCache* PImageCache::self() {
28 if ( !_imgCache )
29 _imgCache = new PImageCache;
30 return _imgCache;
31}
32
33QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) {
34 QString path = QString( "%1_%2:" ).arg( ori ).arg( max );
35 path += _path;
36
37 QImage* img = find( path );
38 if ( !img ) {
39// img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori), max);
40// insertImage( _path, img, ori, max );
41 currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max );
42 }
43
44
45 return img;
46}
47
48void PImageCache::insertImage( const QString& _path, const QImage* img, int ori, int max ) {
49 QString path = QString("%1_%2:" ).arg( ori ).arg( max );
50 path += _path;
51 insert( path, img, (img->height()*img->width()*img->depth())/8 );
52}
53
54
55PPixmapCache::PPixmapCache() {
56 /*
57 * 20 64x64 16 bit images
58 */
59 setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 );
60}
61
62PPixmapCache::~PPixmapCache() {
63}
64
65PPixmapCache* PPixmapCache::self() {
66 if ( !_pxmCache )
67 _pxmCache = new PPixmapCache;
68
69 return _pxmCache;
70}
71
72QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) {
73 QString path = QString( "%1_%2:" ).arg( width ).arg( height );
74 path += _path;
75
76 QPixmap* pxm = find( path );
77
78
79
80 return pxm;
81}
82
83void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) {
84 QString path = QString("%1_%2:" ).arg( width ).arg( height );
85 path += _path;
86 insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 );
87}