File: image_cache.cpp

package info (click to toggle)
literki 0.0.0+20100113.git1da40724-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 3,444 kB
  • ctags: 1,153
  • sloc: cpp: 5,263; makefile: 72
file content (27 lines) | stat: -rw-r--r-- 607 bytes parent folder | download
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
#include <string.h>
#include "image_cache.h"


#include "logger.h"

using namespace std;

ImageCache image_cache;

PngImage& ImageCache::GetImage(const string& name){ 
    for (int i=0; i<images.size(); ++i)
	if (name == images[i].name)
	    return images[i].png;
    LOG(INFO) << "Loading new image " << name;
    string suf;
    if (name.substr(name.size() - 4) != ".png")
	suf = ".png";
    string image_path = path + "/" +name + suf;
    images.push_back(Image(name, PngImage(image_path.c_str())));
    return images.back().png;
}

void ImageCache::SetImagesPath(const std::string& p){
    path = p;
}