|
|
|
|
@ -4,7 +4,6 @@
|
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <cstring> |
|
|
|
|
|
|
|
|
|
#include <SDL.h> |
|
|
|
|
#include <smacker.h> |
|
|
|
|
|
|
|
|
|
#ifndef NOSOUND |
|
|
|
|
@ -22,6 +21,7 @@
|
|
|
|
|
#include "utils/display.h" |
|
|
|
|
#include "utils/log.hpp" |
|
|
|
|
#include "utils/sdl_compat.h" |
|
|
|
|
#include "utils/sdl_wrap.h" |
|
|
|
|
#include "utils/stdcompat/optional.hpp" |
|
|
|
|
|
|
|
|
|
namespace devilution { |
|
|
|
|
@ -40,7 +40,7 @@ bool SVidLoop;
|
|
|
|
|
smk SVidSMK; |
|
|
|
|
SDL_Color SVidPreviousPalette[256]; |
|
|
|
|
SDL_Palette *SVidPalette; |
|
|
|
|
SDL_Surface *SVidSurface; |
|
|
|
|
SDLSurfaceUniquePtr SVidSurface; |
|
|
|
|
|
|
|
|
|
#ifndef DEVILUTIONX_STORM_FILE_WRAPPER_AVAILABLE |
|
|
|
|
std::unique_ptr<uint8_t[]> SVidBuffer; |
|
|
|
|
@ -225,22 +225,19 @@ bool SVidPlayBegin(const char *filename, int flags)
|
|
|
|
|
std::memcpy(SVidPreviousPalette, orig_palette, sizeof(SVidPreviousPalette)); |
|
|
|
|
|
|
|
|
|
// Copy frame to buffer
|
|
|
|
|
SVidSurface = SDL_CreateRGBSurfaceWithFormatFrom( |
|
|
|
|
SVidSurface = SDLWrap::CreateRGBSurfaceWithFormatFrom( |
|
|
|
|
(unsigned char *)smk_get_video(SVidSMK), |
|
|
|
|
SVidWidth, |
|
|
|
|
SVidHeight, |
|
|
|
|
8, |
|
|
|
|
SVidWidth, |
|
|
|
|
SDL_PIXELFORMAT_INDEX8); |
|
|
|
|
if (SVidSurface == nullptr) { |
|
|
|
|
ErrSdl(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SVidPalette = SDL_AllocPalette(256); |
|
|
|
|
if (SVidPalette == nullptr) { |
|
|
|
|
ErrSdl(); |
|
|
|
|
} |
|
|
|
|
if (SDLC_SetSurfaceColors(SVidSurface, SVidPalette) <= -1) { |
|
|
|
|
if (SDLC_SetSurfaceColors(SVidSurface.get(), SVidPalette) <= -1) { |
|
|
|
|
ErrSdl(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -269,7 +266,7 @@ bool SVidPlayContinue()
|
|
|
|
|
} |
|
|
|
|
memcpy(logical_palette, orig_palette, sizeof(logical_palette)); |
|
|
|
|
|
|
|
|
|
if (SDLC_SetSurfaceAndPaletteColors(SVidSurface, SVidPalette, colors, 0, 256) <= -1) { |
|
|
|
|
if (SDLC_SetSurfaceAndPaletteColors(SVidSurface.get(), SVidPalette, colors, 0, 256) <= -1) { |
|
|
|
|
Log("{}", SDL_GetError()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -297,7 +294,7 @@ bool SVidPlayContinue()
|
|
|
|
|
|
|
|
|
|
#ifndef USE_SDL1 |
|
|
|
|
if (renderer != nullptr) { |
|
|
|
|
if (SDL_BlitSurface(SVidSurface, nullptr, GetOutputSurface(), nullptr) <= -1) { |
|
|
|
|
if (SDL_BlitSurface(SVidSurface.get(), nullptr, GetOutputSurface(), nullptr) <= -1) { |
|
|
|
|
Log("{}", SDL_GetError()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -329,16 +326,16 @@ bool SVidPlayContinue()
|
|
|
|
|
if (isIndexedOutputFormat |
|
|
|
|
|| outputSurface->w == static_cast<int>(SVidWidth) |
|
|
|
|
|| outputSurface->h == static_cast<int>(SVidHeight)) { |
|
|
|
|
if (SDL_BlitSurface(SVidSurface, nullptr, outputSurface, &outputRect) <= -1) { |
|
|
|
|
if (SDL_BlitSurface(SVidSurface.get(), nullptr, outputSurface, &outputRect) <= -1) { |
|
|
|
|
ErrSdl(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// The source surface is always 8-bit, and the output surface is never 8-bit in this branch.
|
|
|
|
|
// We must convert to the output format before calling SDL_BlitScaled.
|
|
|
|
|
#ifdef USE_SDL1 |
|
|
|
|
SDLSurfaceUniquePtr converted { SDL_ConvertSurface(SVidSurface, ghMainWnd->format, 0) }; |
|
|
|
|
SDLSurfaceUniquePtr converted { SDL_ConvertSurface(SVidSurface.get(), ghMainWnd->format, 0) }; |
|
|
|
|
#else |
|
|
|
|
SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(SVidSurface, wndFormat, 0) }; |
|
|
|
|
SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(SVidSurface.get(), wndFormat, 0) }; |
|
|
|
|
#endif |
|
|
|
|
if (SDL_BlitScaled(converted.get(), nullptr, outputSurface, &outputRect) <= -1) { |
|
|
|
|
Log("{}", SDL_GetError()); |
|
|
|
|
@ -376,7 +373,6 @@ void SVidPlayEnd()
|
|
|
|
|
SDL_FreePalette(SVidPalette); |
|
|
|
|
SVidPalette = nullptr; |
|
|
|
|
|
|
|
|
|
SDL_FreeSurface(SVidSurface); |
|
|
|
|
SVidSurface = nullptr; |
|
|
|
|
|
|
|
|
|
memcpy(orig_palette, SVidPreviousPalette, sizeof(orig_palette)); |
|
|
|
|
|