summaryrefslogtreecommitdiff
path: root/imagecache.c
blob: 616064769478f2109146c549ae3f208d9ffd9cf9 (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
#include "imagecache.h"
#include "config.h"


#include "displaychannel.h"
#include "displaymenu.h"
#include "displaymessage.h"
#include "displayreplay.h"
#include "displaytracks.h"
#include "displayvolume.h"


cImageCache::cImageCache() {
    Overflow = false;
}

cImageCache::~cImageCache() {
    
}

void cImageCache::Create(void) {
    for(int i = 0; i < MAX_IMAGE_CACHE; i++) {
        CacheImage[i] = NULL;
        CacheName[i] = "";
        CacheWidth[i] = -1;
        CacheHeight[i] = -1;
    }

    InsertIndex = 0;
}

void cImageCache::Clear(void) {
    for(int i = 0; i < MAX_IMAGE_CACHE; i++) {
        if( CacheImage[i] != NULL )
            delete CacheImage[i];
    }

    InsertIndex = 0;
}

cImage* cImageCache::GetImage(std::string Name, int Width, int Height) {
    //dsyslog("imagecache search for image %s Width %d Height %d", Name.c_str(), Width, Height);
    for(int index = 0; index < MAX_IMAGE_CACHE; index++ ) {
        //dsyslog("imagecache index %d image %s Width %d Height %d", index, CacheName[index].c_str(), CacheWidth[index], CacheHeight[index]);
        if( CacheName[index] == Name && CacheWidth[index] == Width && CacheHeight[index] == Height )
            return CacheImage[index];
    }
    return NULL;
}

void cImageCache::InsertImage(cImage *Image, std::string Name, int Width, int Height) {
    CacheImage[InsertIndex] = Image;
    CacheName[InsertIndex] = Name;
    CacheWidth[InsertIndex] = Width;
    CacheHeight[InsertIndex] = Height;

    InsertIndex++;
    if( InsertIndex >= MAX_IMAGE_CACHE ) {
        isyslog("skinflatplus: imagecache overflow, increase MAX_IMAGE_CACHE");
        InsertIndex = 0;
        Overflow = true;
    }
}

void cImageCache::PreLoadImage(void) {
    uint32_t tick1 = GetMsTicks();

    cFlatDisplayChannel DisplayChannel(false);
    DisplayChannel.PreLoadImages();

    cFlatDisplayMenu DisplayMenu;
    DisplayMenu.PreLoadImages();

    cFlatDisplayReplay DisplayReplay(false);
    DisplayReplay.PreLoadImages();

    cFlatDisplayVolume DisplayVolume;
    DisplayVolume.PreLoadImages();

    uint32_t tick2 = GetMsTicks();
    dsyslog("skinflatplus imagecache pre load images time: %d ms", tick2 - tick1);
    dsyslog("skinflatplus imagecache pre loaded images %d / %d", getCacheCount(), MAX_IMAGE_CACHE);
}