From a743962b84f89f89c225c289da0dc1ed82a6163a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Apr 2024 17:22:52 +0200 Subject: [PATCH] Pass `CImageInfo` by reference to `IGraphics::LoadPng` For consistency with other graphics functions using `CImageInfo`. --- src/engine/client/graphics_threaded.cpp | 16 ++++++++-------- src/engine/client/graphics_threaded.h | 2 +- src/engine/graphics.h | 2 +- src/game/client/components/countryflags.cpp | 2 +- src/game/client/components/mapimages.cpp | 6 +++--- src/game/client/components/menus.cpp | 2 +- src/game/client/components/menus_browser.cpp | 2 +- src/game/client/components/skins.cpp | 2 +- src/game/client/gameclient.cpp | 10 +++++----- src/game/editor/editor.cpp | 6 +++--- src/game/editor/editor_actions.cpp | 2 +- src/game/editor/mapitems/map_io.cpp | 2 +- src/game/editor/tileart.cpp | 2 +- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index f57c312dd..b056502d7 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -499,10 +499,10 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename, { dbg_assert(pFilename[0] != '\0', "Cannot load texture from file with empty filename"); // would cause Valgrind to crash otherwise - CImageInfo Img; - if(LoadPng(&Img, pFilename, StorageType)) + CImageInfo Image; + if(LoadPng(Image, pFilename, StorageType)) { - CTextureHandle Id = LoadTextureRawMove(Img, Flags, pFilename); + CTextureHandle Id = LoadTextureRawMove(Image, Flags, pFilename); if(Id.IsValid()) { if(g_Config.m_Debug) @@ -571,7 +571,7 @@ bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureId, int x, int return true; } -bool CGraphics_Threaded::LoadPng(CImageInfo *pImg, const char *pFilename, int StorageType) +bool CGraphics_Threaded::LoadPng(CImageInfo &Image, const char *pFilename, int StorageType) { char aCompleteFilename[IO_MAX_PATH_LENGTH]; IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType, aCompleteFilename, sizeof(aCompleteFilename)); @@ -598,19 +598,19 @@ bool CGraphics_Threaded::LoadPng(CImageInfo *pImg, const char *pFilename, int St uint8_t *pImgBuffer = NULL; EImageFormat ImageFormat; int PngliteIncompatible; - if(::LoadPng(ImageByteBuffer, pFilename, PngliteIncompatible, pImg->m_Width, pImg->m_Height, pImgBuffer, ImageFormat)) + if(::LoadPng(ImageByteBuffer, pFilename, PngliteIncompatible, Image.m_Width, Image.m_Height, pImgBuffer, ImageFormat)) { if(ImageFormat == IMAGE_FORMAT_RGB) - pImg->m_Format = CImageInfo::FORMAT_RGB; + Image.m_Format = CImageInfo::FORMAT_RGB; else if(ImageFormat == IMAGE_FORMAT_RGBA) - pImg->m_Format = CImageInfo::FORMAT_RGBA; + Image.m_Format = CImageInfo::FORMAT_RGBA; else { free(pImgBuffer); log_error("game/png", "image had unsupported image format. filename='%s' format='%d'", pFilename, (int)ImageFormat); return false; } - pImg->m_pData = pImgBuffer; + Image.m_pData = pImgBuffer; if(m_WarnPngliteIncompatibleImages && PngliteIncompatible != 0) { diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index d7bd6e798..8d55ff37b 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -982,7 +982,7 @@ public: // simple uncompressed RGBA loaders IGraphics::CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) override; - bool LoadPng(CImageInfo *pImg, const char *pFilename, int StorageType) override; + bool LoadPng(CImageInfo &Image, const char *pFilename, int StorageType) override; bool CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) override; bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) override; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 06291938b..98d3548ec 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -335,7 +335,7 @@ public: virtual const TTwGraphicsGpuList &GetGpus() const = 0; - virtual bool LoadPng(CImageInfo *pImg, const char *pFilename, int StorageType) = 0; + virtual bool LoadPng(CImageInfo &Image, const char *pFilename, int StorageType) = 0; virtual bool CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) = 0; virtual bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) = 0; diff --git a/src/game/client/components/countryflags.cpp b/src/game/client/components/countryflags.cpp index 46d06b5e9..8de2024ea 100644 --- a/src/game/client/components/countryflags.cpp +++ b/src/game/client/components/countryflags.cpp @@ -63,7 +63,7 @@ void CCountryFlags::LoadCountryflagsIndexfile() char aBuf[128]; CImageInfo Info; str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin); - if(!Graphics()->LoadPng(&Info, aBuf, IStorage::TYPE_ALL)) + if(!Graphics()->LoadPng(Info, aBuf, IStorage::TYPE_ALL)) { char aMsg[128]; str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf); diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index d259dc6bc..5a62a08d3 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -240,20 +240,20 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit CImageInfo ImgInfo; char aPath[IO_MAX_PATH_LENGTH]; str_format(aPath, sizeof(aPath), "%s/%s.png", m_aEntitiesPath, gs_apModEntitiesNames[EntitiesModType]); - Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); // try as single ddnet replacement if(ImgInfo.m_pData == nullptr && EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET) { str_format(aPath, sizeof(aPath), "%s.png", m_aEntitiesPath); - Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); } // try default if(ImgInfo.m_pData == nullptr) { str_format(aPath, sizeof(aPath), "editor/entities_clear/%s.png", gs_apModEntitiesNames[EntitiesModType]); - Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); } if(ImgInfo.m_pData != nullptr) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 9bfaa5cb6..e08549215 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2314,7 +2314,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser str_format(aPath, sizeof(aPath), "menuimages/%s", pName); CImageInfo Info; - if(!pSelf->Graphics()->LoadPng(&Info, aPath, DirType)) + if(!pSelf->Graphics()->LoadPng(Info, aPath, DirType)) { char aError[IO_MAX_PATH_LENGTH + 64]; str_format(aError, sizeof(aError), "Failed to load menu image from '%s'", aPath); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index d612099ff..3f52d7a2c 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1946,7 +1946,7 @@ const SCommunityIcon *CMenus::FindCommunityIcon(const char *pCommunityId) bool CMenus::LoadCommunityIconFile(const char *pPath, int DirType, CImageInfo &Info, SHA256_DIGEST &Sha256) { char aError[IO_MAX_PATH_LENGTH + 128]; - if(!Graphics()->LoadPng(&Info, pPath, DirType)) + if(!Graphics()->LoadPng(Info, pPath, DirType)) { str_format(aError, sizeof(aError), "Failed to load community icon from '%s'", pPath); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError); diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index c37c2eb6b..082d04d99 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -141,7 +141,7 @@ const CSkin *CSkins::LoadSkin(const char *pName, const char *pPath, int DirType) bool CSkins::LoadSkinPng(CImageInfo &Info, const char *pName, const char *pPath, int DirType) { - if(!Graphics()->LoadPng(&Info, pPath, DirType)) + if(!Graphics()->LoadPng(Info, pPath, DirType)) { log_error("skins", "Failed to load skin PNG: %s", pName); return false; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 99516680a..81f479712 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -3030,7 +3030,7 @@ void CGameClient::LoadGameSkin(const char *pPath, bool AsDir) } CImageInfo ImgInfo; - bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); if(!PngLoaded && !IsDefault) { if(AsDir) @@ -3191,7 +3191,7 @@ void CGameClient::LoadEmoticonsSkin(const char *pPath, bool AsDir) } CImageInfo ImgInfo; - bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); if(!PngLoaded && !IsDefault) { if(AsDir) @@ -3245,7 +3245,7 @@ void CGameClient::LoadParticlesSkin(const char *pPath, bool AsDir) } CImageInfo ImgInfo; - bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); if(!PngLoaded && !IsDefault) { if(AsDir) @@ -3333,7 +3333,7 @@ void CGameClient::LoadHudSkin(const char *pPath, bool AsDir) } CImageInfo ImgInfo; - bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); if(!PngLoaded && !IsDefault) { if(AsDir) @@ -3407,7 +3407,7 @@ void CGameClient::LoadExtrasSkin(const char *pPath, bool AsDir) } CImageInfo ImgInfo; - bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); + bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL); if(!PngLoaded && !IsDefault) { if(AsDir) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index bc28f6da7..47091a0c8 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4361,7 +4361,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup } CEditorImage ImgInfo(this); - if(!Graphics()->LoadPng(&ImgInfo, pFileName, StorageType)) + if(!Graphics()->LoadPng(ImgInfo, pFileName, StorageType)) { ShowFileDialogError("Failed to load image from file '%s'.", pFileName); return false; @@ -4424,7 +4424,7 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) } CEditorImage ImgInfo(pEditor); - if(!pEditor->Graphics()->LoadPng(&ImgInfo, pFileName, StorageType)) + if(!pEditor->Graphics()->LoadPng(ImgInfo, pFileName, StorageType)) { pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFileName); return false; @@ -5139,7 +5139,7 @@ void CEditor::RenderFileDialog() { char aBuffer[IO_MAX_PATH_LENGTH]; str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_pFileDialogPath, m_vpFilteredFileList[m_FilesSelectedIndex]->m_aFilename); - if(Graphics()->LoadPng(&m_FilePreviewImageInfo, aBuffer, m_vpFilteredFileList[m_FilesSelectedIndex]->m_StorageType)) + if(Graphics()->LoadPng(m_FilePreviewImageInfo, aBuffer, m_vpFilteredFileList[m_FilesSelectedIndex]->m_StorageType)) { Graphics()->UnloadTexture(&m_FilePreviewImage); m_FilePreviewImage = Graphics()->LoadTextureRawMove(m_FilePreviewImageInfo, 0, aBuffer); diff --git a/src/game/editor/editor_actions.cpp b/src/game/editor/editor_actions.cpp index 231716589..67f2924bf 100644 --- a/src/game/editor/editor_actions.cpp +++ b/src/game/editor/editor_actions.cpp @@ -1243,7 +1243,7 @@ void CEditorActionTileArt::Undo() void CEditorActionTileArt::Redo() { - if(!m_pEditor->Graphics()->LoadPng(&m_pEditor->m_TileartImageInfo, m_aTileArtFile, IStorage::TYPE_ALL)) + if(!m_pEditor->Graphics()->LoadPng(m_pEditor->m_TileartImageInfo, m_aTileArtFile, IStorage::TYPE_ALL)) { m_pEditor->ShowFileDialogError("Failed to load image from file '%s'.", m_aTileArtFile); return; diff --git a/src/game/editor/mapitems/map_io.cpp b/src/game/editor/mapitems/map_io.cpp index 2476f0f8e..ba91960ce 100644 --- a/src/game/editor/mapitems/map_io.cpp +++ b/src/game/editor/mapitems/map_io.cpp @@ -516,7 +516,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio // load external CImageInfo ImgInfo; - if(m_pEditor->Graphics()->LoadPng(&ImgInfo, aBuf, IStorage::TYPE_ALL)) + if(m_pEditor->Graphics()->LoadPng(ImgInfo, aBuf, IStorage::TYPE_ALL)) { pImg->m_Width = ImgInfo.m_Width; pImg->m_Height = ImgInfo.m_Height; diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index 37cb7c9f2..92db0506a 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -238,7 +238,7 @@ bool CEditor::CallbackAddTileart(const char *pFilepath, int StorageType, void *p { CEditor *pEditor = (CEditor *)pUser; - if(!pEditor->Graphics()->LoadPng(&pEditor->m_TileartImageInfo, pFilepath, StorageType)) + if(!pEditor->Graphics()->LoadPng(pEditor->m_TileartImageInfo, pFilepath, StorageType)) { pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFilepath); return false;