summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/lib/imagecache.cpp
blob: f1042a42aa8034bdb669d163f23c6c3a28a6ad3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * GPLv2 zecke@handhelds.org
 * No WArranty...
 */

#include <iface/dirview.h>
#include <iface/dirlister.h>

#include "imagecache.h"

namespace {
    PImageCache * _imgCache = 0;
    PPixmapCache* _pxmCache = 0;
}


PImageCache::PImageCache()
    : QCache<QImage>()
{
    /* just to set an initial value.. 4 big images */
    setMaxCost( (1024*1024*16)/8*4 );
}

PImageCache::~PImageCache() {
}

PImageCache* PImageCache::self() {
    if ( !_imgCache )
        _imgCache = new PImageCache;
    return _imgCache;
}

QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) {
    QString path = QString( "%1_%2:" ).arg( ori ).arg( max );
    path += _path;

    QImage* img = find( path );
    if ( !img ) {
//        img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori),  max);
//        insertImage(  _path, img, ori, max );
        currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max );
    }


    return  img;
}

void PImageCache::insertImage(  const QString& _path,  const QImage* img, int ori, int max ) {
    QString path = QString("%1_%2:" ).arg( ori ).arg( max );
    path += _path;
    insert( path, img, (img->height()*img->width()*img->depth())/8 );
}


PPixmapCache::PPixmapCache() {
  /*
   * 20 64x64 16 bit images
   */
    setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 );
}

PPixmapCache::~PPixmapCache() {
}

void PPixmapCache::setMaxImages(unsigned int aMax)
{
    m_MaxImages = aMax;
    setMaxCost( 64*64*QPixmap::defaultDepth()/8*m_MaxImages);
}

PPixmapCache* PPixmapCache::self() {
    if ( !_pxmCache )
        _pxmCache = new PPixmapCache;

    return _pxmCache;
}

QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) {
    QString path = QString( "%1_%2:" ).arg( width ).arg( height );
    path += _path;

    QPixmap* pxm = find( path );



    return  pxm;
}

void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) {
    QString path = QString("%1_%2:" ).arg( width ).arg( height );
    path += _path;
    insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 );
}