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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
#include <string>
#include <sstream>
#include <map>
#include <fstream>
#include <iostream>
#include <sys/stat.h>
#include "imagecache.h"
#include "cairoimage.h"
#include "../config.h"
#include "helpers.h"
cMutex cImageCache::mutex;
string cImageCache::items[16] = { "Schedule", "Channels", "Timers", "Recordings", "Setup", "Commands",
"OSD", "EPG", "DVB", "LNB", "CAM", "Recording", "Replay", "Miscellaneous", "Plugins", "Restart"};
cImageCache::cImageCache() {
tempStaticLogo = NULL;
}
cImageCache::~cImageCache() {
Clear();
if (tempStaticLogo) {
delete tempStaticLogo;
tempStaticLogo = NULL;
}
}
void cImageCache::SetPathes(void) {
cString skinPath = config.GetSkinPath(Setup.OSDSkin);
string logoPathSkin = *cString::sprintf("%s%s/themes/%s/logos/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
if (FolderExists(logoPathSkin)) {
logoPath = logoPathSkin;
} else {
logoPath = *config.logoPath;
}
iconPathSkin = *cString::sprintf("%s%s/", *skinPath, Setup.OSDSkin);
skinPartsPathSkin = *cString::sprintf("%s%s/skinparts/", *skinPath, Setup.OSDSkin);
iconPathTheme = *cString::sprintf("%s%s/themes/%s/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
skinPartsPathTheme = *cString::sprintf("%s%s/themes/%s/skinparts/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
svgTemplatePath = *cString::sprintf("%s%s/svgtemplates/", *skinPath, Setup.OSDSkin);
dsyslog("skindesigner: using channel logo path %s", logoPath.c_str());
dsyslog("skindesigner: using icon path %s", iconPathTheme.c_str());
dsyslog("skindesigner: using skinparts path %s", skinPartsPathTheme.c_str());
dsyslog("skindesigner: using svgtemplate path %s", svgTemplatePath.c_str());
}
void cImageCache::CacheLogo(int width, int height) {
if (config.numLogosPerSizeInitial == 0)
return;
if (width == 0 || height == 0)
return;
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
const cChannels* channels = &Channels;
#endif
int logosCached = 0;
if (config.numLogosMax && config.numLogosMax < (int)channelLogoCache.size())
return;
for (const cChannel *channel = channels->First(); channel; channel = channels->Next(channel)) {
if (logosCached >= config.numLogosPerSizeInitial)
break;
if (channel->GroupSep()) {
continue;
}
stringstream logoName;
logoName << *channel->GetChannelID().ToString() << "_" << width << "x" << height;
map<string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) {
continue;
}
bool success = LoadLogo(channel);
if (success) {
logosCached++;
cImage *image = CreateImage(width, height);
channelLogoCache.insert(pair<string, cImage*>(logoName.str(), image));
}
if (config.numLogosMax && config.numLogosMax < (int)channelLogoCache.size())
return;
}
}
cImage *cImageCache::GetLogo(string channelID, int width, int height) {
cMutexLock MutexLock(&mutex);
stringstream logoName;
logoName << channelID << "_" << width << "x" << height;
std::map<std::string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) {
return (cImage*)hit->second;
} else {
tChannelID chanID = tChannelID::FromString(channelID.c_str());
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
cChannels* channels = &Channels;
#endif
const cChannel *channel = channels->GetByChannelID(chanID);
if (!channel)
return NULL;
bool success = LoadLogo(channel);
if (success) {
if (config.limitLogoCache && ((int)channelLogoCache.size() >= config.numLogosMax)) {
//logo cache is full, don't cache anymore
if (tempStaticLogo) {
delete tempStaticLogo;
tempStaticLogo = NULL;
}
tempStaticLogo = CreateImage(width, height);
return tempStaticLogo;
} else {
//add requested logo to cache
cImage *image = CreateImage(width, height);
channelLogoCache.insert(pair<string, cImage*>(logoName.str(), image));
hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) {
return (cImage*)hit->second;
}
}
}
}
return NULL;
}
cImage *cImageCache::GetSeparatorLogo(string name, int width, int height) {
cMutexLock MutexLock(&mutex);
stringstream logoName;
logoName << name << "_" << width << "x" << height;
std::map<std::string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) {
return (cImage*)hit->second;
} else {
bool success = LoadSeparatorLogo(name);
if (success) {
//add requested logo to cache
cImage *image = CreateImage(width, height);
channelLogoCache.insert(pair<string, cImage*>(logoName.str(), image));
hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) {
return (cImage*)hit->second;
}
}
}
return NULL;
}
bool cImageCache::LogoExists(string channelID) {
tChannelID chanID = tChannelID::FromString(channelID.c_str());
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
cChannels* channels = &Channels;
#endif
const cChannel *channel = channels->GetByChannelID(chanID);
if (!channel)
return false;
string logoLower = StrToLowerCase(channel->Name());
string channelIDLower = StrToLowerCase(channelID.c_str());
return (FileExists(logoPath.c_str(), logoLower, "svg") ||
FileExists(logoPath.c_str(), logoLower, "png") ||
FileExists(logoPath.c_str(), channelIDLower, "svg") ||
FileExists(logoPath.c_str(), channelIDLower, "png"));
}
bool cImageCache::SeparatorLogoExists(string name) {
string separatorPath = *cString::sprintf("%sseparatorlogos/", logoPath.c_str());
string nameLower = StrToLowerCase(name.c_str());
return (FileExists(separatorPath, nameLower, "svg") ||
FileExists(separatorPath, nameLower, "png"));
}
void cImageCache::CacheIcon(eImageType type, string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080)
return;
GetIcon(type, name, width, height);
}
cCachedImage *cImageCache::GetIcon(eImageType type, string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080)
return NULL;
cMutexLock MutexLock(&mutex);
stringstream iconName;
iconName << name << "_" << width << "x" << height;
map<string, cCachedImage*>::iterator hit = iconCache.find(iconName.str());
if (hit != iconCache.end()) {
return (cCachedImage*)hit->second;
} else {
bool success = LoadIcon(type, name);
if (!success)
return NULL;
cImage *image = CreateImage(width, height, true);
cCachedImage *cachedImg = new cCachedImage();
cachedImg->size = image->Width() * image->Height() * sizeof(tColor);
int handle = cOsdProvider::StoreImage(*image);
if (handle) {
cachedImg->handle = handle;
delete image;
} else {
cachedImg->image = image;
}
iconCache.insert(pair<string, cCachedImage*>(iconName.str(), cachedImg));
hit = iconCache.find(iconName.str());
if (hit != iconCache.end()) {
return (cCachedImage*)hit->second;
}
}
return NULL;
}
string cImageCache::GetIconName(string label, eMenuCategory cat, string plugName) {
//if cat is set, use standard menu entries
switch (cat) {
case mcSchedule:
case mcScheduleNow:
case mcScheduleNext:
case mcEvent:
return "standardicons/Schedule";
case mcChannel:
case mcChannelEdit:
return "standardicons/Channels";
case mcTimer:
case mcTimerEdit:
return "standardicons/Timers";
case mcRecording:
case mcRecordingInfo:
case mcSetupRecord:
case mcSetupReplay:
return "standardicons/Recordings";
case mcPlugin: {
//check for Plugins
for (int i = 0; ; i++) {
cPlugin *p = cPluginManager::GetPlugin(i);
if (p) {
const char *mainMenuEntry = p->MainMenuEntry();
if (mainMenuEntry) {
string plugMainEntry = mainMenuEntry;
try {
if (label.substr(0, plugMainEntry.size()) == plugMainEntry) {
return *cString::sprintf("pluginicons/%s", p->Name());
}
} catch (...) {}
}
} else
break;
}
return "standardicons/Plugins";
}
case mcPluginSetup:
case mcSetupPlugins:
return "standardicons/Plugins";
case mcSetup:
return "standardicons/Setup";
case mcSetupOsd:
return "standardicons/OSD";
case mcSetupEpg:
return "standardicons/EPG";
case mcSetupDvb:
return "standardicons/DVB";
case mcSetupLnb:
return "standardicons/LNB";
case mcSetupCam:
return "standardicons/CAM";
case mcSetupMisc:
return "standardicons/Miscellaneous";
case mcCommand:
return "standardicons/Commands";
default:
break;
}
//check for standard menu entries
for (int i=0; i<16; i++) {
string s = trVDR(items[i].c_str());
if (s == label) {
return *cString::sprintf("standardicons/%s", items[i].c_str());
}
}
//check for special main menu entries "stop recording", "stop replay"
string stopRecording = skipspace(trVDR(" Stop recording "));
string stopReplay = skipspace(trVDR(" Stop replaying"));
try {
if (label.substr(0, stopRecording.size()) == stopRecording) {
return "standardicons/StopRecording";
}
if (label.substr(0, stopReplay.size()) == stopReplay) {
return "standardicons/StopReplay";
}
} catch (...) {}
//check for Plugins
if (plugName.size() > 0) {
return *cString::sprintf("pluginicons/%s", plugName.c_str());
}
for (int i = 0; ; i++) {
cPlugin *p = cPluginManager::GetPlugin(i);
if (p) {
const char *mainMenuEntry = p->MainMenuEntry();
if (mainMenuEntry) {
string plugMainEntry = mainMenuEntry;
try {
if (label.substr(0, plugMainEntry.size()) == plugMainEntry) {
return *cString::sprintf("pluginicons/%s", p->Name());
}
} catch (...) {}
}
} else
break;
}
return *cString::sprintf("customicons/%s", label.c_str());
}
bool cImageCache::MenuIconExists(string name) {
//first check in theme specific icon folder
cString iconThemePath = cString::sprintf("%smenuicons/", iconPathTheme.c_str());
if (FileExists(*iconThemePath, name, "svg")) {
return true;
}
if (FileExists(*iconThemePath, name, "png")) {
return true;
}
//then check skin icon folder
cString iconSkinPath = cString::sprintf("%smenuicons/", iconPathSkin.c_str());
if (FileExists(*iconSkinPath, name, "svg")) {
return true;
}
if (FileExists(*iconSkinPath, name, "png")) {
return true;
}
//finally check svg templates
cString iconTemplatePath = cString::sprintf("%smenuicons/", svgTemplatePath.c_str());
if (FileExists(*iconTemplatePath, name, "svg")) {
return true;
}
return false;
}
void cImageCache::CacheSkinpart(string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080)
return;
GetSkinpart(name, width, height);
}
cCachedImage *cImageCache::GetSkinpart(string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080)
return NULL;
cMutexLock MutexLock(&mutex);
stringstream iconName;
iconName << name << "_" << width << "x" << height;
map<string, cCachedImage*>::iterator hit = skinPartsCache.find(iconName.str());
if (hit != skinPartsCache.end()) {
return (cCachedImage*)hit->second;
} else {
bool success = LoadSkinpart(name);
if (!success)
return NULL;
cImage *image = CreateImage(width, height, false);
cCachedImage *cachedImg = new cCachedImage();
cachedImg->size = image->Width() * image->Height() * sizeof(tColor);
int handle = cOsdProvider::StoreImage(*image);
if (handle) {
cachedImg->handle = handle;
delete image;
} else {
cachedImg->image = image;
}
skinPartsCache.insert(pair<string, cCachedImage*>(iconName.str(), cachedImg));
hit = skinPartsCache.find(iconName.str());
if (hit != skinPartsCache.end()) {
return (cCachedImage*)hit->second;
}
}
return NULL;
}
cImage *cImageCache::GetVerticalText(string text, tColor color, string font, int size, int direction) {
cMutexLock MutexLock(&mutex);
stringstream buf;
buf << text << "_" << size << "_" << direction;
string imgName = buf.str();
map<string, cImage*>::iterator hit = cairoImageCache.find(imgName);
if (hit != cairoImageCache.end()) {
return (cImage*)hit->second;
} else {
cCairoImage c;
c.DrawTextVertical(text, color, font, size, direction);
cImage *image = c.GetImage();
cairoImageCache.insert(pair<string, cImage*>(imgName, image));
hit = cairoImageCache.find(imgName);
if (hit != cairoImageCache.end()) {
return (cImage*)hit->second;
}
}
return NULL;
}
bool cImageCache::LoadIcon(eImageType type, string name) {
cString subdir("");
if (type == eImageType::menuicon)
subdir = "menuicons";
else if (type == eImageType::icon)
subdir = "icons";
//first check in theme specific icon path
cString subIconThemePath = cString::sprintf("%s%s/", iconPathTheme.c_str(), *subdir);
if (FileExists(*subIconThemePath, name, "svg"))
return LoadImage(*subIconThemePath, name, "svg");
else if (FileExists(*subIconThemePath, name, "png"))
return LoadImage(*subIconThemePath, name, "png");
//then check in skin icon path
cString subIconSkinPath = cString::sprintf("%s%s/", iconPathSkin.c_str(), *subdir);
if (FileExists(*subIconSkinPath, name, "svg"))
return LoadImage(*subIconSkinPath, name, "svg");
else if (FileExists(*subIconSkinPath, name, "png"))
return LoadImage(*subIconSkinPath, name, "png");
//and finally check if a svg template exists
cSVGTemplate svgTemplate(name, *subdir, svgTemplatePath);
if (!svgTemplate.Exists())
return false;
svgTemplate.ReadTemplate();
if (!svgTemplate.ParseTemplate())
return false;
string tmpImageName = svgTemplate.WriteImage();
return LoadImage(tmpImageName.c_str());
}
bool cImageCache::LoadLogo(const cChannel *channel) {
if (!channel)
return false;
string channelID = StrToLowerCase(*(channel->GetChannelID().ToString()));
string logoLower = StrToLowerCase(channel->Name());
if (FileExists(logoPath.c_str(), channelID.c_str(), "svg"))
return LoadImage(logoPath.c_str(), channelID.c_str(), "svg");
if (FileExists(logoPath.c_str(), channelID.c_str(), "png"))
return LoadImage(logoPath.c_str(), channelID.c_str(), "png");
if (FileExists(logoPath.c_str(), logoLower.c_str(), "svg"))
return LoadImage(logoPath.c_str(), logoLower.c_str(), "svg");
if (FileExists(logoPath.c_str(), logoLower.c_str(), "png"))
return LoadImage(logoPath.c_str(), logoLower.c_str(), "png");
return false;
}
bool cImageCache::LoadSeparatorLogo(string name) {
string separatorPath = *cString::sprintf("%sseparatorlogos/", logoPath.c_str());
string nameLower = StrToLowerCase(name.c_str());
if (FileExists(separatorPath, nameLower.c_str(), "svg"))
return LoadImage(separatorPath, nameLower.c_str(), "svg");
else
return LoadImage(separatorPath, nameLower.c_str(), "png");
}
bool cImageCache::LoadSkinpart(string name) {
if (FileExists(skinPartsPathTheme.c_str(), name, "svg"))
return LoadImage(skinPartsPathTheme.c_str(), name, "svg");
else if (FileExists(skinPartsPathTheme.c_str(), name, "png"))
return LoadImage(skinPartsPathTheme.c_str(), name, "png");
else if (FileExists(skinPartsPathSkin.c_str(), name, "svg"))
return LoadImage(skinPartsPathSkin.c_str(), name, "svg");
else if (FileExists(skinPartsPathSkin.c_str(), name, "png"))
return LoadImage(skinPartsPathSkin.c_str(), name, "png");
//check if a svg template exists
cSVGTemplate svgTemplate(name, "skinparts", svgTemplatePath);
if (!svgTemplate.Exists())
return false;
svgTemplate.ReadTemplate();
if (!svgTemplate.ParseTemplate())
return false;
string tmpImageName = svgTemplate.WriteImage();
return LoadImage(tmpImageName.c_str());
}
void cImageCache::Clear(void) {
for(map<string, cCachedImage*>::const_iterator it = iconCache.begin(); it != iconCache.end(); it++) {
cCachedImage *img = (cCachedImage*)it->second;
delete img;
}
iconCache.clear();
for(map<string, cImage*>::const_iterator it = channelLogoCache.begin(); it != channelLogoCache.end(); it++) {
cImage *img = (cImage*)it->second;
delete img;
}
channelLogoCache.clear();
for(map<string, cCachedImage*>::const_iterator it = skinPartsCache.begin(); it != skinPartsCache.end(); it++) {
cCachedImage *img = (cCachedImage*)it->second;
delete img;
}
skinPartsCache.clear();
for(map<string, cImage*>::const_iterator it = cairoImageCache.begin(); it != cairoImageCache.end(); it++) {
cImage *img = (cImage*)it->second;
delete img;
}
cairoImageCache.clear();
}
void cImageCache::Debug(bool full) {
float sizeIconCacheInternal = 0;
float sizeIconCacheExternal = 0;
int numIcons = 0;
GetIconCacheSize(numIcons, sizeIconCacheInternal, sizeIconCacheExternal);
dsyslog("skindesigner: cached %d icons - size internal mem %.2fMB, high level mem %.2fMB", numIcons, sizeIconCacheInternal, sizeIconCacheExternal);
if (full) {
for(std::map<std::string, cCachedImage*>::const_iterator it = iconCache.begin(); it != iconCache.end(); it++) {
string name = it->first;
cCachedImage *img = (cCachedImage*)it->second;
dsyslog("skindesigner: cached icon %s, handle %d", name.c_str(), img->handle);
}
}
float sizeLogoCache = 0;
int numLogos = 0;
GetLogoCacheSize(numLogos, sizeLogoCache);
dsyslog("skindesigner: cached %d logos - size %.2fMB internal mem", numLogos, sizeLogoCache);
if (full) {
for(std::map<std::string, cImage*>::const_iterator it = channelLogoCache.begin(); it != channelLogoCache.end(); it++) {
string name = it->first;
dsyslog("skindesigner: cached logo %s", name.c_str());
}
}
float sizeSkinpartCacheInternal = 0;
float sizeSkinpartCacheExternal = 0;
int numSkinparts = 0;
GetSkinpartsCacheSize(numSkinparts, sizeSkinpartCacheInternal, sizeSkinpartCacheExternal);
dsyslog("skindesigner: cached %d skinparts - size internal mem %.2fMB, high level mem %.2fMB", numSkinparts, sizeSkinpartCacheInternal, sizeSkinpartCacheExternal);
if (full) {
for(std::map<std::string, cCachedImage*>::const_iterator it = skinPartsCache.begin(); it != skinPartsCache.end(); it++) {
string name = it->first;
dsyslog("skindesigner: cached skinpart %s", name.c_str());
}
}
}
void cImageCache::GetIconCacheSize(int &num, float &sizeInternal, float &sizeExternal) {
num = iconCache.size();
int sizeByteInternal = 0;
int sizeByteExternal = 0;
for (map<string, cCachedImage*>::iterator icon = iconCache.begin(); icon != iconCache.end(); icon++) {
cCachedImage* img = icon->second;
if (img->image)
sizeByteInternal += img->size;
else
sizeByteExternal += img->size;
}
sizeInternal = sizeByteInternal / 1024.0f / 1024.0f;
sizeExternal = sizeByteExternal / 1024.0f / 1024.0f;
}
void cImageCache::GetLogoCacheSize(int &num, float &size) {
num = channelLogoCache.size();
int sizeByte = 0;
for (map<string, cImage*>::iterator logo = channelLogoCache.begin(); logo != channelLogoCache.end(); logo++) {
cImage* img = logo->second;
sizeByte += img->Width() * img->Height() * sizeof(tColor);
}
size = sizeByte / 1024.0f;
}
void cImageCache::GetSkinpartsCacheSize(int &num, float &sizeInternal, float &sizeExternal) {
num = skinPartsCache.size();
int sizeByteInternal = 0;
int sizeByteExternal = 0;
for (map<string, cCachedImage*>::iterator skinpart = skinPartsCache.begin(); skinpart != skinPartsCache.end(); skinpart++) {
cCachedImage* img = skinpart->second;
if (img->image)
sizeByteInternal += img->size;
else
sizeByteExternal += img->size;
}
sizeInternal = sizeByteInternal / 1024.0f / 1024.0f;
sizeExternal = sizeByteExternal / 1024.0f / 1024.0f;
}
|