GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sdl2softwareimagehelper.cpp Lines: 0 18 0.0 %
Date: 2019-10-15 Branches: 0 12 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
 *
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/sdl2softwareimagehelper.h"
26
27
#include "resources/image/image.h"
28
29
#include "utils/sdlcheckutils.h"
30
31
#include "debug.h"
32
33
bool SDL2SoftwareImageHelper::mEnableAlphaCache = false;
34
SDL_PixelFormat *SDL2SoftwareImageHelper::mFormat = nullptr;
35
36
Image *SDL2SoftwareImageHelper::loadSurface(SDL_Surface *const tmpImage)
37
{
38
    return _SDLload(tmpImage);
39
}
40
41
Image *SDL2SoftwareImageHelper::createTextSurface(SDL_Surface *const tmpImage,
42
                                                  const int width A_UNUSED,
43
                                                  const int height A_UNUSED,
44
                                                  const float alpha)
45
{
46
    if (!tmpImage)
47
        return nullptr;
48
49
    Image *const img = _SDLload(tmpImage);
50
    if (img)
51
        img->setAlpha(alpha);
52
    return img;
53
}
54
55
SDL_Surface* SDL2SoftwareImageHelper::SDLDuplicateSurface(SDL_Surface *const
56
                                                          tmpImage)
57
{
58
    if (!tmpImage || !tmpImage->format)
59
        return nullptr;
60
61
    return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
62
}
63
64
Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage)
65
{
66
    if (!tmpImage)
67
        return nullptr;
68
69
    SDL_Surface *image = SDL_ConvertSurface(tmpImage, mFormat, 0);
70
    return new Image(image, false, nullptr);
71
}
72
73
int SDL2SoftwareImageHelper::combineSurface(SDL_Surface *restrict const src,
74
                                            SDL_Rect *restrict const srcrect,
75
                                            SDL_Surface *restrict const dst,
76
                                            SDL_Rect *restrict const dstrect)
77
{
78
    SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
79
    SDL_BlitSurface(src, srcrect, dst, dstrect);
80
    return 1;
81
}
82
83
#endif  // USE_SDL2