GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/surfaceimagehelper.cpp Lines: 13 21 61.9 %
Date: 2019-10-12 Branches: 4 14 28.6 %

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
 *
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
#ifdef USE_SDL2
24
25
#include "resources/surfaceimagehelper.h"
26
27
#include "resources/image/image.h"
28
29
#include "utils/sdlcheckutils.h"
30
31
#include "debug.h"
32
33
bool SurfaceImageHelper::mEnableAlphaCache = false;
34
35
137
Image *SurfaceImageHelper::loadSurface(SDL_Surface *const tmpImage)
36
{
37
137
    return _SDLload(tmpImage);
38
}
39
40
Image *SurfaceImageHelper::createTextSurface(SDL_Surface *const tmpImage,
41
                                             const int width A_UNUSED,
42
                                             const int height A_UNUSED,
43
                                             const float alpha)
44
{
45
    if (!tmpImage)
46
        return nullptr;
47
48
    Image *img;
49
    bool hasAlpha = false;
50
    uint8_t *alphaChannel = nullptr;
51
    SDL_Surface *image = SDLDuplicateSurface(tmpImage);
52
53
    img = new Image(image, hasAlpha, alphaChannel);
54
    img->setAlpha(alpha);
55
    return img;
56
}
57
58
2
SDL_Surface* SurfaceImageHelper::SDLDuplicateSurface(SDL_Surface *const
59
                                                     tmpImage)
60
{
61

2
    if (!tmpImage || !tmpImage->format)
62
        return nullptr;
63
64
2
    return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
65
}
66
67
137
Image *SurfaceImageHelper::_SDLload(SDL_Surface *tmpImage) const
68
{
69
137
    if (!tmpImage)
70
        return nullptr;
71
72
137
    SDL_Surface *image = convertTo32Bit(tmpImage);
73
137
    return new Image(image, false, nullptr);
74
}
75
76
650
int SurfaceImageHelper::combineSurface(SDL_Surface *restrict const src,
77
                                       SDL_Rect *restrict const srcrect,
78
                                       SDL_Surface *restrict const dst,
79
                                       SDL_Rect *restrict const dstrect)
80
{
81
650
    SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
82
650
    SDL_BlitSurface(src, srcrect, dst, dstrect);
83
650
    return 1;
84
}
85
86
#endif  // USE_SDL2