You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
|
7 years ago
|
#include "DiabloUI/art.h"
|
||
|
5 years ago
|
#include "storm/storm.h"
|
||
|
5 years ago
|
#include "utils/display.h"
|
||
|
|
#include "utils/sdl_compat.h"
|
||
|
7 years ago
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
|
||
|
6 years ago
|
void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette)
|
||
|
7 years ago
|
{
|
||
|
|
if (art == NULL || art->surface != NULL)
|
||
|
|
return;
|
||
|
|
|
||
|
7 years ago
|
art->frames = frames;
|
||
|
|
|
||
|
7 years ago
|
DWORD width, height, bpp;
|
||
|
5 years ago
|
if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, &bpp)) {
|
||
|
|
SDL_Log("Failed to load image meta");
|
||
|
7 years ago
|
return;
|
||
|
5 years ago
|
}
|
||
|
7 years ago
|
|
||
|
|
Uint32 format;
|
||
|
|
switch (bpp) {
|
||
|
|
case 8:
|
||
|
|
format = SDL_PIXELFORMAT_INDEX8;
|
||
|
|
break;
|
||
|
|
case 24:
|
||
|
|
format = SDL_PIXELFORMAT_RGB888;
|
||
|
|
break;
|
||
|
|
case 32:
|
||
|
|
format = SDL_PIXELFORMAT_RGBA8888;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
format = 0;
|
||
|
|
break;
|
||
|
|
}
|
||
|
5 years ago
|
SDLSurfaceUniquePtr art_surface { SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, format) };
|
||
|
7 years ago
|
|
||
|
|
if (!SBmpLoadImage(pszFile, pPalette, static_cast<BYTE *>(art_surface->pixels),
|
||
|
|
art_surface->pitch * art_surface->format->BytesPerPixel * height, 0, 0, 0)) {
|
||
|
|
SDL_Log("Failed to load image");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
art->logical_width = art_surface->w;
|
||
|
7 years ago
|
art->frame_height = height / frames;
|
||
|
6 years ago
|
|
||
|
5 years ago
|
art->surface = ScaleSurfaceToOutput(std::move(art_surface));
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
7 years ago
|
void LoadMaskedArt(const char *pszFile, Art *art, int frames, int mask)
|
||
|
|
{
|
||
|
|
LoadArt(pszFile, art, frames);
|
||
|
6 years ago
|
if (art->surface != NULL)
|
||
|
5 years ago
|
SDLC_SetColorKey(art->surface.get(), mask);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
7 years ago
|
void LoadArt(Art *art, const BYTE *artData, int w, int h, int frames)
|
||
|
|
{
|
||
|
|
art->frames = frames;
|
||
|
5 years ago
|
art->surface = ScaleSurfaceToOutput(SDLSurfaceUniquePtr{SDL_CreateRGBSurfaceWithFormatFrom(
|
||
|
|
const_cast<BYTE *>(artData), w, h, 8, w, SDL_PIXELFORMAT_INDEX8)});
|
||
|
6 years ago
|
art->logical_width = w;
|
||
|
7 years ago
|
art->frame_height = h / frames;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|