1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "resources/imagehelper.h" |
25 |
|
|
|
26 |
|
|
#include "fs/virtfs/rwops.h" |
27 |
|
|
|
28 |
|
|
#include "resources/image/image.h" |
29 |
|
|
|
30 |
|
|
#include "resources/loaders/imageloader.h" |
31 |
|
|
|
32 |
|
|
#include "resources/resourcemanager/resourcemanager.h" |
33 |
|
|
|
34 |
|
|
#include "resources/dye/dye.h" |
35 |
|
|
|
36 |
|
|
#include "utils/checkutils.h" |
37 |
|
|
|
38 |
|
|
#include "debug.h" |
39 |
|
|
|
40 |
|
|
namespace |
41 |
|
|
{ |
42 |
|
24674 |
struct DyedImageLoader final |
43 |
|
|
{ |
44 |
|
|
A_DEFAULT_COPY(DyedImageLoader) |
45 |
|
|
|
46 |
|
|
std::string path; |
47 |
|
1549 |
static Resource *load(const void *const v) |
48 |
|
|
{ |
49 |
|
|
BLOCK_START("DyedImageLoader::load") |
50 |
✓✗ |
1549 |
if (v == nullptr) |
51 |
|
|
{ |
52 |
|
|
BLOCK_END("DyedImageLoader::load") |
53 |
|
|
return nullptr; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
const DyedImageLoader *const rl |
57 |
|
1549 |
= static_cast<const DyedImageLoader *>(v); |
58 |
|
|
|
59 |
|
3098 |
std::string path1 = rl->path; |
60 |
|
1549 |
const size_t p = path1.find('|'); |
61 |
|
1549 |
Dye *d = nullptr; |
62 |
✓✓ |
1549 |
if (p != std::string::npos) |
63 |
|
|
{ |
64 |
✓✗✓✗ ✓✗ |
10 |
d = new Dye(path1.substr(p + 1)); |
65 |
✓✗ |
10 |
path1 = path1.substr(0, p); |
66 |
|
|
} |
67 |
✓✗ |
1549 |
SDL_RWops *const rw = VirtFs::rwopsOpenRead(path1); |
68 |
✗✓ |
1549 |
if (rw == nullptr) |
69 |
|
|
{ |
70 |
|
|
delete d; |
71 |
|
|
reportAlways("Image loading error: %s", path1.c_str()) |
72 |
|
|
BLOCK_END("DyedImageLoader::load") |
73 |
|
|
return nullptr; |
74 |
|
|
} |
75 |
|
5 |
Resource *const res = d != nullptr ? imageHelper->load(rw, *d) |
76 |
✓✓✓✗ ✓✗ |
1554 |
: imageHelper->load(rw); |
77 |
✓✓ |
1549 |
delete d; |
78 |
✗✓ |
1549 |
if (res == nullptr) |
79 |
|
|
reportAlways("Image loading error: %s", path1.c_str()) |
80 |
|
|
BLOCK_END("DyedImageLoader::load") |
81 |
|
1549 |
return res; |
82 |
|
|
} |
83 |
|
|
}; |
84 |
|
|
} // namespace |
85 |
|
|
|
86 |
|
12337 |
Image *Loader::getImage(const std::string &idPath) |
87 |
|
|
{ |
88 |
|
24674 |
DyedImageLoader rl = { idPath }; |
89 |
|
|
return static_cast<Image*>(ResourceManager::get(idPath, |
90 |
✓✗ |
24674 |
DyedImageLoader::load, &rl)); |
91 |
|
|
} |