GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/loaders/rescaledloader.cpp Lines: 0 13 0.0 %
Date: 2017-11-29 Branches: 0 14 0.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/image/image.h"
24
25
#include "resources/loaders/rescaledloader.h"
26
27
#include "resources/resourcemanager/resourcemanager.h"
28
29
#include "utils/checkutils.h"
30
#include "utils/stringutils.h"
31
32
#include "debug.h"
33
34
namespace
35
{
36
    struct RescaledLoader final
37
    {
38
        A_DEFAULT_COPY(RescaledLoader)
39
40
        const Image *const image;
41
        const int width;
42
        const int height;
43
        static Resource *load(const void *const v)
44
        {
45
            if (v == nullptr)
46
                return nullptr;
47
            const RescaledLoader *const rl
48
                = static_cast<const RescaledLoader *>(v);
49
            if (rl->image == nullptr)
50
                return nullptr;
51
            Image *const rescaled = rl->image->SDLgetScaledImage(
52
                rl->width, rl->height);
53
            if (rescaled == nullptr)
54
            {
55
                reportAlways("Rescale image failed: %s",
56
                    rl->image->mIdPath.c_str());
57
                return nullptr;
58
            }
59
            return rescaled;
60
        }
61
    };
62
}  // namespace
63
64
Image *Loader::getRescaled(const Image *const image,
65
                           const int width,
66
                           const int height)
67
{
68
    if (image == nullptr)
69
        return nullptr;
70
71
    const std::string idPath = image->mIdPath + strprintf(
72
        "_rescaled%dx%d", width, height);
73
    const RescaledLoader rl = { image, width, height };
74
    return static_cast<Image *>(
75
        ResourceManager::get(idPath, RescaledLoader::load, &rl));
76
}