ManaPlus
sdl2softwareimagehelper.cpp
Go to the documentation of this file.
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 
27 
28 #include "resources/image/image.h"
29 
30 #include "utils/sdlcheckutils.h"
31 
32 #include "debug.h"
33 
34 bool SDL2SoftwareImageHelper::mEnableAlphaCache = false;
35 SDL_PixelFormat *SDL2SoftwareImageHelper::mFormat = nullptr;
36 
37 Image *SDL2SoftwareImageHelper::loadSurface(SDL_Surface *const tmpImage)
38 {
39  return _SDLload(tmpImage);
40 }
41 
42 Image *SDL2SoftwareImageHelper::createTextSurface(SDL_Surface *const tmpImage,
43  const int width A_UNUSED,
44  const int height A_UNUSED,
45  const float alpha)
46 {
47  if (!tmpImage)
48  return nullptr;
49 
50  Image *const img = _SDLload(tmpImage);
51  if (img)
52  img->setAlpha(alpha);
53  return img;
54 }
55 
56 SDL_Surface* SDL2SoftwareImageHelper::SDLDuplicateSurface(SDL_Surface *const
57  tmpImage)
58 {
59  if (!tmpImage || !tmpImage->format)
60  return nullptr;
61 
62  return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
63 }
64 
65 Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage)
66 {
67  if (!tmpImage)
68  return nullptr;
69 
70  SDL_Surface *image = SDL_ConvertSurface(tmpImage, mFormat, 0);
71  return new Image(image, false, nullptr);
72 }
73 
74 int SDL2SoftwareImageHelper::combineSurface(SDL_Surface *restrict const src,
75  SDL_Rect *restrict const srcrect,
76  SDL_Surface *restrict const dst,
77  SDL_Rect *restrict const dstrect)
78 {
79  SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
80  SDL_BlitSurface(src, srcrect, dst, dstrect);
81  return 1;
82 }
83 
84 #endif // USE_SDL2
#define MSDL_ConvertSurface(src, fmt, flags)
Definition: debug.h:57
#define restrict
Definition: localconsts.h:165
#define A_UNUSED
Definition: localconsts.h:160