2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* SDLImageLoader.cpp, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2014-07-13 20:53:37 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "SDLImageLoader.h"
|
2022-09-18 14:47:49 +02:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "SDLImage.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../../lib/Point.h"
|
2011-10-08 04:23:46 +03:00
|
|
|
|
2023-01-30 19:55:32 +02:00
|
|
|
#include <SDL_surface.h>
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
SDLImageLoader::SDLImageLoader(SDLImage * Img):
|
|
|
|
image(Img),
|
2013-06-26 14:18:27 +03:00
|
|
|
lineStart(nullptr),
|
|
|
|
position(nullptr)
|
2011-02-06 19:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal)
|
2011-02-06 19:26:27 +02:00
|
|
|
{
|
|
|
|
//Init image
|
2018-07-25 00:36:48 +02:00
|
|
|
image->surf = SDL_CreateRGBSurface(0, SpriteSize.x, SpriteSize.y, 8, 0, 0, 0, 0);
|
2011-02-06 19:26:27 +02:00
|
|
|
image->margins = Margins;
|
|
|
|
image->fullSize = FullSize;
|
|
|
|
|
|
|
|
//Prepare surface
|
2020-01-26 10:01:48 +02:00
|
|
|
SDL_Palette * p = SDL_AllocPalette(SDLImage::DEFAULT_PALETTE_COLORS);
|
|
|
|
SDL_SetPaletteColors(p, pal, 0, SDLImage::DEFAULT_PALETTE_COLORS);
|
2015-09-05 14:03:37 +02:00
|
|
|
SDL_SetSurfacePalette(image->surf, p);
|
2016-01-29 16:16:14 +02:00
|
|
|
SDL_FreePalette(p);
|
2015-09-05 14:03:37 +02:00
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
SDL_LockSurface(image->surf);
|
|
|
|
lineStart = position = (ui8*)image->surf->pixels;
|
|
|
|
}
|
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
inline void SDLImageLoader::load(size_t size, const ui8 * data)
|
2011-02-06 19:26:27 +02:00
|
|
|
{
|
|
|
|
if (size)
|
2010-10-18 18:08:59 +03:00
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
memcpy((void *)position, data, size);
|
|
|
|
position += size;
|
2010-10-18 18:08:59 +03:00
|
|
|
}
|
2011-02-06 19:26:27 +02:00
|
|
|
}
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
inline void SDLImageLoader::load(size_t size, ui8 color)
|
2011-02-06 19:26:27 +02:00
|
|
|
{
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
memset((void *)position, color, size);
|
|
|
|
position += size;
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
inline void SDLImageLoader::endLine()
|
2011-02-06 19:26:27 +02:00
|
|
|
{
|
|
|
|
lineStart += image->surf->pitch;
|
|
|
|
position = lineStart;
|
|
|
|
}
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
SDLImageLoader::~SDLImageLoader()
|
|
|
|
{
|
|
|
|
SDL_UnlockSurface(image->surf);
|
2015-06-21 00:38:05 +02:00
|
|
|
SDL_SetColorKey(image->surf, SDL_TRUE, 0);
|
2011-02-06 19:26:27 +02:00
|
|
|
//TODO: RLE if compressed and bpp>1
|
|
|
|
}
|
|
|
|
|