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