GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/loaders/imagesetloader.cpp Lines: 18 19 94.7 %
Date: 2017-11-29 Branches: 9 20 45.0 %

Line Branch Exec Source
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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "resources/imageset.h"
24
25
#include "resources/image/image.h"
26
27
#include "resources/loaders/imageloader.h"
28
#include "resources/loaders/imagesetloader.h"
29
30
#include "resources/resourcemanager/resourcemanager.h"
31
32
#include "utils/checkutils.h"
33
#include "utils/stringutils.h"
34
35
#include "debug.h"
36
37
5264
struct ImageSetLoader final
38
{
39
    const std::string path;
40
    const int w;
41
    const int h;
42
43
    A_DEFAULT_COPY(ImageSetLoader)
44
45
2594
    static Resource *load(const void *const v)
46
    {
47
2594
        if (v == nullptr)
48
            return nullptr;
49
50
        const ImageSetLoader *const
51
2594
            rl = static_cast<const ImageSetLoader *>(v);
52
53
2594
        Image *const img = Loader::getImage(rl->path);
54
2594
        if (img == nullptr)
55
        {
56
            reportAlways("Image loading error: %s", rl->path.c_str());
57
            return nullptr;
58
        }
59
2594
        ImageSet *const res = new ImageSet(img, rl->w, rl->h);
60
2594
        img->decRef();
61
2594
        return res;
62
    }
63
};
64
65
2632
ImageSet *Loader::getImageSet(const std::string &imagePath,
66
                              const int w,
67
                              const int h)
68
{
69
5264
    ImageSetLoader rl = { imagePath, w, h };
70
5264
    const std::string str = std::string(
71
        imagePath).append(
72

5264
        "[").append(toString(
73
2632
        w)).append(
74

5264
        "x").append(toString(
75
2632
        h)).append(
76
7896
        "]");
77
    return static_cast<ImageSet*>(ResourceManager::get(str,
78
5264
        ImageSetLoader::load, &rl));
79
}