GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/imagehelper.h Lines: 3 9 33.3 %
Date: 2021-03-17 Branches: 0 0 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-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
#ifndef RESOURCES_IMAGEHELPER_H
25
#define RESOURCES_IMAGEHELPER_H
26
27
#include "localconsts.h"
28
29
#include "enums/render/rendertype.h"
30
31
PRAGMA48(GCC diagnostic push)
32
PRAGMA48(GCC diagnostic ignored "-Wshadow")
33
#include <SDL_video.h>
34
PRAGMA48(GCC diagnostic pop)
35
36
class Dye;
37
class Image;
38
39
/**
40
 * Defines a class for loading and storing images.
41
 */
42
class ImageHelper notfinal
43
{
44
    friend class CompoundSprite;
45
    friend class Image;
46
47
    public:
48
        A_DELETE_COPY(ImageHelper)
49
50
        virtual ~ImageHelper()
51
        { }
52
53
        /**
54
         * Loads an image from an SDL_RWops structure.
55
         *
56
         * @param rw         The SDL_RWops to load the image from.
57
         *
58
         * @return <code>NULL</code> if an error occurred, a valid pointer
59
         *         otherwise.
60
         */
61
        Image *load(SDL_RWops *const rw) A_WARN_UNUSED;
62
63
        virtual Image *load(SDL_RWops *const rw, Dye const &dye) A_WARN_UNUSED;
64
65
#ifdef __GNUC__
66
        virtual Image *loadSurface(SDL_Surface *const) A_WARN_UNUSED = 0;
67
68
        virtual Image *createTextSurface(SDL_Surface *const tmpImage,
69
                                         const int width, const int height,
70
                                         float alpha) A_WARN_UNUSED = 0;
71
#else  // __GNUC__
72
73
        virtual Image *loadSurface(SDL_Surface *const) A_WARN_UNUSED
74
        { return nullptr; }
75
76
        virtual Image *createTextSurface(SDL_Surface *const tmpImage,
77
                                         const int width, const int height,
78
                                         const float alpha) const A_WARN_UNUSED
79
        { return nullptr; }
80
#endif  // __GNUC__
81
82
        virtual SDL_Surface *create32BitSurface(int width,
83
                                                int height)
84
                                                const A_WARN_UNUSED;
85
86
        virtual void copySurfaceToImage(const Image *const image A_UNUSED,
87
                                        const int x A_UNUSED,
88
                                        const int y A_UNUSED,
89
                                        SDL_Surface *const surface A_UNUSED)
90
                                        const
91
        { }
92
93
        static SDL_Surface *convertTo32Bit(SDL_Surface *const tmpImage)
94
                                           A_WARN_UNUSED;
95
96
        static void dumpSurfaceFormat(const SDL_Surface *const image);
97
98
        constexpr2 static void setEnableAlpha(const bool n) noexcept2
99
        { mEnableAlpha = n; }
100
101
        static SDL_Surface *loadPng(SDL_RWops *const rw);
102
103
        constexpr2 static void setOpenGlMode(const RenderType useOpenGL)
104
                                            noexcept2
105
        { mUseOpenGL = useOpenGL; }
106
107
129
        virtual RenderType useOpenGL() const noexcept2 A_WARN_UNUSED
108
129
        { return mUseOpenGL; }
109
110
        virtual void postInit()
111
        { }
112
113
    protected:
114
        ImageHelper()
115
245
        { }
116
117
        static bool mEnableAlpha;
118
        static RenderType mUseOpenGL;
119
};
120
121
extern ImageHelper *imageHelper A_NONNULLPOINTER;
122
extern ImageHelper *surfaceImageHelper A_NONNULLPOINTER;
123
#endif  // RESOURCES_IMAGEHELPER_H