446 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2022 by Andreas Theofilu <andreas@theosys.at>
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef __TIMGCACHE_H__
|
|
|
20 |
#define __TIMGCACHE_H__
|
|
|
21 |
|
|
|
22 |
#include <string>
|
|
|
23 |
#include <vector>
|
|
|
24 |
|
|
|
25 |
#include <include/core/SkBitmap.h>
|
|
|
26 |
|
|
|
27 |
#if defined(__ANDROID__) || defined(__MACH__)
|
|
|
28 |
typedef unsigned long ulong;
|
|
|
29 |
#endif
|
|
|
30 |
|
|
|
31 |
typedef enum _IMGCACHE_BMTYPE
|
|
|
32 |
{
|
|
|
33 |
_BMTYPE_NONE,
|
|
|
34 |
_BMTYPE_CHAMELEON,
|
|
|
35 |
_BMTYPE_BITMAP,
|
|
|
36 |
_BMTYPE_ICON,
|
|
|
37 |
_BMTYPE_URL
|
|
|
38 |
}_IMGCACHE_BMTYPE;
|
|
|
39 |
|
|
|
40 |
typedef struct _IMGCACHE
|
|
|
41 |
{
|
|
|
42 |
_IMGCACHE_BMTYPE bmType{_BMTYPE_NONE};
|
|
|
43 |
std::string name;
|
|
|
44 |
SkBitmap bitmap;
|
|
|
45 |
uint32_t handle{0};
|
|
|
46 |
}_IMGCACHE;
|
|
|
47 |
|
|
|
48 |
class TImgCache
|
|
|
49 |
{
|
|
|
50 |
public:
|
|
|
51 |
static bool addImage(const std::string& name, SkBitmap& bm, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
52 |
static bool addImage(const std::string& name, SkBitmap& bm, ulong handle=0, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
53 |
static bool getBitmap(const std::string& name, SkBitmap *bm, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE, int *width=nullptr, int *height=nullptr);
|
|
|
54 |
static bool getBitmap(SkBitmap *bm, ulong handle, int *width=nullptr, int *height=nullptr, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
55 |
static bool delBitmap(const std::string& name, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
56 |
static bool delBitmap(ulong handle, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
57 |
static bool existBitmap(const std::string& name, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
58 |
static bool existBitmap(ulong handle, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
59 |
static bool replaceBitmap(const std::string& name, SkBitmap& bm, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
60 |
static bool replaceBitmap(ulong handle, SkBitmap& bm, _IMGCACHE_BMTYPE bmType=_BMTYPE_NONE);
|
|
|
61 |
|
|
|
62 |
protected:
|
|
|
63 |
static bool addImage(_IMGCACHE ic);
|
|
|
64 |
|
|
|
65 |
private:
|
|
|
66 |
static void shrinkCache();
|
|
|
67 |
// This should never be used
|
|
|
68 |
TImgCache() {}
|
|
|
69 |
~TImgCache();
|
|
|
70 |
|
|
|
71 |
static std::string handleToString(ulong handle)
|
|
|
72 |
{
|
|
|
73 |
ulong part1 = (handle >> 16) & 0x0000ffff;
|
|
|
74 |
ulong part2 = handle & 0x0000ffff;
|
|
|
75 |
return std::to_string(part1)+":"+std::to_string(part2);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// Internal variables
|
|
|
79 |
static std::vector<_IMGCACHE> mImgCache;
|
|
|
80 |
static size_t size;
|
|
|
81 |
SkBitmap mDummyBM;
|
|
|
82 |
};
|
|
|
83 |
|
|
|
84 |
#endif
|