1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 21:43:06 +01:00

Remove old bitmap code via UiContext

This commit is contained in:
Ted John
2018-05-08 23:42:13 +01:00
parent 229c50dff9
commit 7eb1703f36
5 changed files with 2 additions and 76 deletions

View File

@@ -577,69 +577,6 @@ public:
return _windowManager;
}
bool ReadBMP(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const std::string &path) override
{
auto bitmap = SDL_LoadBMP(path.c_str());
if (bitmap != nullptr)
{
sint32 numChannels = bitmap->format->BytesPerPixel;
if (numChannels < 3 || bitmap->format->BitsPerPixel < 24)
{
context_show_error(STR_HEIGHT_MAP_ERROR, STR_ERROR_24_BIT_BITMAP);
SDL_FreeSurface(bitmap);
return false;
}
// Copy pixels over, then discard the surface
*outPixels = nullptr;
*outWidth = bitmap->w;
*outHeight = bitmap->h;
if (SDL_LockSurface(bitmap) == 0)
{
*outPixels = malloc(bitmap->w * bitmap->h * 4);
memset(*outPixels, 0xFF, bitmap->w * bitmap->h);
auto src = (const uint8 *)bitmap->pixels;
auto dst = (uint8 *)*outPixels;
if (numChannels == 4)
{
for (sint32 y = 0; y < bitmap->h; y++)
{
memcpy(dst, src, bitmap->w);
src += bitmap->pitch;
dst += bitmap->w;
}
}
else
{
for (sint32 y = 0; y < bitmap->h; y++)
{
for (sint32 x = 0; x < bitmap->w; x++)
{
memcpy(dst, src, 3);
src += 3;
dst += 4;
}
src += bitmap->pitch - (bitmap->w * 3);
}
}
SDL_UnlockSurface(bitmap);
}
else
{
return false;
}
SDL_FreeSurface(bitmap);
return true;
}
else
{
log_warning("Failed to load bitmap: %s", SDL_GetError());
context_show_error(STR_HEIGHT_MAP_ERROR, STR_ERROR_READING_BITMAP);
return false;
}
}
bool SetClipboardText(const utf8* target) override
{
return (SDL_SetClipboardText(target) == 0);

View File

@@ -35,6 +35,8 @@ static std::vector<uint8> ReadToVector(std::istream &stream)
return result;
}
// TODO Bitmaps aren't very complicated to read so we should probably just write our
// own implementation in libopenrct2 and spare the AOT implementation registration.
static Image ReadBitmap(std::istream &istream, IMAGE_FORMAT format)
{
auto buffer = ReadToVector(istream);

View File

@@ -1127,11 +1127,6 @@ void context_input_handle_keyboard(bool isTitle)
windowManager->HandleKeyboard(isTitle);
}
bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path)
{
return GetContext()->GetUiContext()->ReadBMP(outPixels, outWidth, outHeight, std::string(path));
}
void context_quit()
{
GetContext()->Quit();

View File

@@ -91,9 +91,6 @@ namespace OpenRCT2::Ui
return _windowManager;
}
// Misc
bool ReadBMP(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const std::string &path) override { return false; }
// Clipboard
bool SetClipboardText(const utf8* target) override { return false; }

View File

@@ -140,11 +140,6 @@ namespace OpenRCT2
// In-game UI
virtual IWindowManager * GetWindowManager() abstract;
// Misc.
// HACK: This should either be implemented ourselves in libopenrct2
// or the mapgen height map code is moved to libopenrct2ui.
virtual bool ReadBMP(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const std::string &path) abstract;
// Clipboard
virtual bool SetClipboardText(const utf8* target) abstract;
};