Pass CImageInfo by reference to IGraphics::LoadPng

For consistency with other graphics functions using `CImageInfo`.
This commit is contained in:
Robert Müller 2024-04-12 17:22:52 +02:00
parent 8f7055f694
commit a743962b84
13 changed files with 28 additions and 28 deletions

View file

@ -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 dbg_assert(pFilename[0] != '\0', "Cannot load texture from file with empty filename"); // would cause Valgrind to crash otherwise
CImageInfo Img; CImageInfo Image;
if(LoadPng(&Img, pFilename, StorageType)) if(LoadPng(Image, pFilename, StorageType))
{ {
CTextureHandle Id = LoadTextureRawMove(Img, Flags, pFilename); CTextureHandle Id = LoadTextureRawMove(Image, Flags, pFilename);
if(Id.IsValid()) if(Id.IsValid())
{ {
if(g_Config.m_Debug) if(g_Config.m_Debug)
@ -571,7 +571,7 @@ bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureId, int x, int
return true; 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]; char aCompleteFilename[IO_MAX_PATH_LENGTH];
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType, aCompleteFilename, sizeof(aCompleteFilename)); 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; uint8_t *pImgBuffer = NULL;
EImageFormat ImageFormat; EImageFormat ImageFormat;
int PngliteIncompatible; 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) if(ImageFormat == IMAGE_FORMAT_RGB)
pImg->m_Format = CImageInfo::FORMAT_RGB; Image.m_Format = CImageInfo::FORMAT_RGB;
else if(ImageFormat == IMAGE_FORMAT_RGBA) else if(ImageFormat == IMAGE_FORMAT_RGBA)
pImg->m_Format = CImageInfo::FORMAT_RGBA; Image.m_Format = CImageInfo::FORMAT_RGBA;
else else
{ {
free(pImgBuffer); free(pImgBuffer);
log_error("game/png", "image had unsupported image format. filename='%s' format='%d'", pFilename, (int)ImageFormat); log_error("game/png", "image had unsupported image format. filename='%s' format='%d'", pFilename, (int)ImageFormat);
return false; return false;
} }
pImg->m_pData = pImgBuffer; Image.m_pData = pImgBuffer;
if(m_WarnPngliteIncompatibleImages && PngliteIncompatible != 0) if(m_WarnPngliteIncompatibleImages && PngliteIncompatible != 0)
{ {

View file

@ -982,7 +982,7 @@ public:
// simple uncompressed RGBA loaders // simple uncompressed RGBA loaders
IGraphics::CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) override; 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 CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) override;
bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) override; bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) override;

View file

@ -335,7 +335,7 @@ public:
virtual const TTwGraphicsGpuList &GetGpus() const = 0; 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 CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) = 0;
virtual bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) = 0; virtual bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) = 0;

View file

@ -63,7 +63,7 @@ void CCountryFlags::LoadCountryflagsIndexfile()
char aBuf[128]; char aBuf[128];
CImageInfo Info; CImageInfo Info;
str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin); 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]; char aMsg[128];
str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf); str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf);

View file

@ -240,20 +240,20 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit
CImageInfo ImgInfo; CImageInfo ImgInfo;
char aPath[IO_MAX_PATH_LENGTH]; char aPath[IO_MAX_PATH_LENGTH];
str_format(aPath, sizeof(aPath), "%s/%s.png", m_aEntitiesPath, gs_apModEntitiesNames[EntitiesModType]); 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 // try as single ddnet replacement
if(ImgInfo.m_pData == nullptr && EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET) if(ImgInfo.m_pData == nullptr && EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET)
{ {
str_format(aPath, sizeof(aPath), "%s.png", m_aEntitiesPath); 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 // try default
if(ImgInfo.m_pData == nullptr) if(ImgInfo.m_pData == nullptr)
{ {
str_format(aPath, sizeof(aPath), "editor/entities_clear/%s.png", gs_apModEntitiesNames[EntitiesModType]); 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) if(ImgInfo.m_pData != nullptr)

View file

@ -2314,7 +2314,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser
str_format(aPath, sizeof(aPath), "menuimages/%s", pName); str_format(aPath, sizeof(aPath), "menuimages/%s", pName);
CImageInfo Info; CImageInfo Info;
if(!pSelf->Graphics()->LoadPng(&Info, aPath, DirType)) if(!pSelf->Graphics()->LoadPng(Info, aPath, DirType))
{ {
char aError[IO_MAX_PATH_LENGTH + 64]; char aError[IO_MAX_PATH_LENGTH + 64];
str_format(aError, sizeof(aError), "Failed to load menu image from '%s'", aPath); str_format(aError, sizeof(aError), "Failed to load menu image from '%s'", aPath);

View file

@ -1946,7 +1946,7 @@ const SCommunityIcon *CMenus::FindCommunityIcon(const char *pCommunityId)
bool CMenus::LoadCommunityIconFile(const char *pPath, int DirType, CImageInfo &Info, SHA256_DIGEST &Sha256) bool CMenus::LoadCommunityIconFile(const char *pPath, int DirType, CImageInfo &Info, SHA256_DIGEST &Sha256)
{ {
char aError[IO_MAX_PATH_LENGTH + 128]; 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); str_format(aError, sizeof(aError), "Failed to load community icon from '%s'", pPath);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError);

View file

@ -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) 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); log_error("skins", "Failed to load skin PNG: %s", pName);
return false; return false;

View file

@ -3030,7 +3030,7 @@ void CGameClient::LoadGameSkin(const char *pPath, bool AsDir)
} }
CImageInfo ImgInfo; CImageInfo ImgInfo;
bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL);
if(!PngLoaded && !IsDefault) if(!PngLoaded && !IsDefault)
{ {
if(AsDir) if(AsDir)
@ -3191,7 +3191,7 @@ void CGameClient::LoadEmoticonsSkin(const char *pPath, bool AsDir)
} }
CImageInfo ImgInfo; CImageInfo ImgInfo;
bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL);
if(!PngLoaded && !IsDefault) if(!PngLoaded && !IsDefault)
{ {
if(AsDir) if(AsDir)
@ -3245,7 +3245,7 @@ void CGameClient::LoadParticlesSkin(const char *pPath, bool AsDir)
} }
CImageInfo ImgInfo; CImageInfo ImgInfo;
bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL);
if(!PngLoaded && !IsDefault) if(!PngLoaded && !IsDefault)
{ {
if(AsDir) if(AsDir)
@ -3333,7 +3333,7 @@ void CGameClient::LoadHudSkin(const char *pPath, bool AsDir)
} }
CImageInfo ImgInfo; CImageInfo ImgInfo;
bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL);
if(!PngLoaded && !IsDefault) if(!PngLoaded && !IsDefault)
{ {
if(AsDir) if(AsDir)
@ -3407,7 +3407,7 @@ void CGameClient::LoadExtrasSkin(const char *pPath, bool AsDir)
} }
CImageInfo ImgInfo; CImageInfo ImgInfo;
bool PngLoaded = Graphics()->LoadPng(&ImgInfo, aPath, IStorage::TYPE_ALL); bool PngLoaded = Graphics()->LoadPng(ImgInfo, aPath, IStorage::TYPE_ALL);
if(!PngLoaded && !IsDefault) if(!PngLoaded && !IsDefault)
{ {
if(AsDir) if(AsDir)

View file

@ -4361,7 +4361,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup
} }
CEditorImage ImgInfo(this); CEditorImage ImgInfo(this);
if(!Graphics()->LoadPng(&ImgInfo, pFileName, StorageType)) if(!Graphics()->LoadPng(ImgInfo, pFileName, StorageType))
{ {
ShowFileDialogError("Failed to load image from file '%s'.", pFileName); ShowFileDialogError("Failed to load image from file '%s'.", pFileName);
return false; return false;
@ -4424,7 +4424,7 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser)
} }
CEditorImage ImgInfo(pEditor); 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); pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFileName);
return false; return false;
@ -5139,7 +5139,7 @@ void CEditor::RenderFileDialog()
{ {
char aBuffer[IO_MAX_PATH_LENGTH]; char aBuffer[IO_MAX_PATH_LENGTH];
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_pFileDialogPath, m_vpFilteredFileList[m_FilesSelectedIndex]->m_aFilename); 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); Graphics()->UnloadTexture(&m_FilePreviewImage);
m_FilePreviewImage = Graphics()->LoadTextureRawMove(m_FilePreviewImageInfo, 0, aBuffer); m_FilePreviewImage = Graphics()->LoadTextureRawMove(m_FilePreviewImageInfo, 0, aBuffer);

View file

@ -1243,7 +1243,7 @@ void CEditorActionTileArt::Undo()
void CEditorActionTileArt::Redo() 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); m_pEditor->ShowFileDialogError("Failed to load image from file '%s'.", m_aTileArtFile);
return; return;

View file

@ -516,7 +516,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio
// load external // load external
CImageInfo ImgInfo; 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_Width = ImgInfo.m_Width;
pImg->m_Height = ImgInfo.m_Height; pImg->m_Height = ImgInfo.m_Height;

View file

@ -238,7 +238,7 @@ bool CEditor::CallbackAddTileart(const char *pFilepath, int StorageType, void *p
{ {
CEditor *pEditor = (CEditor *)pUser; 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); pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFilepath);
return false; return false;