2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* SDLImageLoader.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "SDLImageLoader.h"
|
|
|
|
|
|
|
|
#include "SDLImage.h"
|
|
|
|
|
|
|
|
#include "../../lib/Point.h"
|
|
|
|
|
|
|
|
#include <SDL_surface.h>
|
|
|
|
|
2024-07-24 15:04:45 +02:00
|
|
|
SDLImageLoader::SDLImageLoader(SDLImageShared * Img):
|
2023-10-19 16:19:09 +02:00
|
|
|
image(Img),
|
|
|
|
lineStart(nullptr),
|
|
|
|
position(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal)
|
|
|
|
{
|
|
|
|
//Init image
|
|
|
|
image->surf = SDL_CreateRGBSurface(0, SpriteSize.x, SpriteSize.y, 8, 0, 0, 0, 0);
|
|
|
|
image->margins = Margins;
|
|
|
|
image->fullSize = FullSize;
|
|
|
|
|
|
|
|
//Prepare surface
|
2024-06-04 18:09:25 +02:00
|
|
|
SDL_Palette * p = SDL_AllocPalette(DEFAULT_PALETTE_COLORS);
|
|
|
|
SDL_SetPaletteColors(p, pal, 0, DEFAULT_PALETTE_COLORS);
|
2023-10-19 16:19:09 +02:00
|
|
|
SDL_SetSurfacePalette(image->surf, p);
|
|
|
|
SDL_FreePalette(p);
|
|
|
|
|
|
|
|
SDL_LockSurface(image->surf);
|
|
|
|
lineStart = position = (ui8*)image->surf->pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SDLImageLoader::load(size_t size, const ui8 * data)
|
|
|
|
{
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
memcpy((void *)position, data, size);
|
|
|
|
position += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SDLImageLoader::load(size_t size, ui8 color)
|
|
|
|
{
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
memset((void *)position, color, size);
|
|
|
|
position += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SDLImageLoader::endLine()
|
|
|
|
{
|
|
|
|
lineStart += image->surf->pitch;
|
|
|
|
position = lineStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDLImageLoader::~SDLImageLoader()
|
|
|
|
{
|
|
|
|
SDL_UnlockSurface(image->surf);
|
|
|
|
SDL_SetColorKey(image->surf, SDL_TRUE, 0);
|
|
|
|
//TODO: RLE if compressed and bpp>1
|
|
|
|
}
|
|
|
|
|