From 7eb1703f36bd59bd6bd34057a5085fe7d69a3767 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 8 May 2018 23:42:13 +0100 Subject: [PATCH] Remove old bitmap code via UiContext --- src/openrct2-ui/UiContext.cpp | 63 ------------------------ src/openrct2-ui/drawing/BitmapReader.cpp | 2 + src/openrct2/Context.cpp | 5 -- src/openrct2/ui/DummyUiContext.cpp | 3 -- src/openrct2/ui/UiContext.h | 5 -- 5 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 7696ca05cb..da87bb3562 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -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); diff --git a/src/openrct2-ui/drawing/BitmapReader.cpp b/src/openrct2-ui/drawing/BitmapReader.cpp index 80d1fcc14a..754531f182 100644 --- a/src/openrct2-ui/drawing/BitmapReader.cpp +++ b/src/openrct2-ui/drawing/BitmapReader.cpp @@ -35,6 +35,8 @@ static std::vector 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); diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 605c37f586..098b870f84 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -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(); diff --git a/src/openrct2/ui/DummyUiContext.cpp b/src/openrct2/ui/DummyUiContext.cpp index 036b81b60e..a640447119 100644 --- a/src/openrct2/ui/DummyUiContext.cpp +++ b/src/openrct2/ui/DummyUiContext.cpp @@ -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; } diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index b80c725ea2..86f63482ec 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -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; };