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 |
|
|
#ifdef USE_SDL2 |
25 |
|
|
|
26 |
|
|
#include "resources/surfaceimagehelper.h" |
27 |
|
|
|
28 |
|
|
#include "resources/image/image.h" |
29 |
|
|
|
30 |
|
|
#include "utils/sdlcheckutils.h" |
31 |
|
|
|
32 |
|
|
#include "debug.h" |
33 |
|
|
|
34 |
|
|
bool SurfaceImageHelper::mEnableAlphaCache = false; |
35 |
|
|
|
36 |
|
137 |
Image *SurfaceImageHelper::loadSurface(SDL_Surface *const tmpImage) |
37 |
|
|
{ |
38 |
|
137 |
return _SDLload(tmpImage); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
Image *SurfaceImageHelper::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 *img; |
50 |
|
|
bool hasAlpha = false; |
51 |
|
|
uint8_t *alphaChannel = nullptr; |
52 |
|
|
SDL_Surface *image = SDLDuplicateSurface(tmpImage); |
53 |
|
|
|
54 |
|
|
img = new Image(image, hasAlpha, alphaChannel); |
55 |
|
|
img->setAlpha(alpha); |
56 |
|
|
return img; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
2 |
SDL_Surface* SurfaceImageHelper::SDLDuplicateSurface(SDL_Surface *const |
60 |
|
|
tmpImage) |
61 |
|
|
{ |
62 |
✓✗✓✗ ✗✗ |
2 |
if (!tmpImage || !tmpImage->format) |
63 |
|
|
return nullptr; |
64 |
|
|
|
65 |
|
2 |
return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
137 |
Image *SurfaceImageHelper::_SDLload(SDL_Surface *tmpImage) const |
69 |
|
|
{ |
70 |
✓✗ |
137 |
if (!tmpImage) |
71 |
|
|
return nullptr; |
72 |
|
|
|
73 |
|
137 |
SDL_Surface *image = convertTo32Bit(tmpImage); |
74 |
✓✗ |
137 |
return new Image(image, false, nullptr); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
650 |
int SurfaceImageHelper::combineSurface(SDL_Surface *restrict const src, |
78 |
|
|
SDL_Rect *restrict const srcrect, |
79 |
|
|
SDL_Surface *restrict const dst, |
80 |
|
|
SDL_Rect *restrict const dstrect) |
81 |
|
|
{ |
82 |
|
650 |
SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND); |
83 |
|
650 |
SDL_BlitSurface(src, srcrect, dst, dstrect); |
84 |
|
650 |
return 1; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
#endif // USE_SDL2 |