mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-12 19:18:20 +00:00
Merge pull request #8098 from Robyt3/Graphics-ImageInfo-Free
Replace `IGraphics::FreePNG` with `CImageInfo::Free`
This commit is contained in:
commit
790c73bffe
|
@ -657,12 +657,6 @@ bool CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int St
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::FreePNG(CImageInfo *pImg)
|
|
||||||
{
|
|
||||||
free(pImg->m_pData);
|
|
||||||
pImg->m_pData = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CGraphics_Threaded::CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize)
|
bool CGraphics_Threaded::CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize)
|
||||||
{
|
{
|
||||||
dbg_assert(DivX != 0 && DivY != 0, "Passing 0 to this function is not allowed.");
|
dbg_assert(DivX != 0 && DivY != 0, "Passing 0 to this function is not allowed.");
|
||||||
|
|
|
@ -983,7 +983,6 @@ 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 *pImg, const char *pFilename, int StorageType) override;
|
||||||
void FreePNG(CImageInfo *pImg) 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;
|
||||||
|
|
|
@ -97,6 +97,15 @@ public:
|
||||||
*/
|
*/
|
||||||
uint8_t *m_pData = nullptr;
|
uint8_t *m_pData = nullptr;
|
||||||
|
|
||||||
|
void Free()
|
||||||
|
{
|
||||||
|
m_Width = 0;
|
||||||
|
m_Height = 0;
|
||||||
|
m_Format = FORMAT_ERROR;
|
||||||
|
free(m_pData);
|
||||||
|
m_pData = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static size_t PixelSize(EImageFormat Format)
|
static size_t PixelSize(EImageFormat Format)
|
||||||
{
|
{
|
||||||
dbg_assert(Format != FORMAT_ERROR, "Format invalid");
|
dbg_assert(Format != FORMAT_ERROR, "Format invalid");
|
||||||
|
@ -322,7 +331,6 @@ 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 *pImg, const char *pFilename, int StorageType) = 0;
|
||||||
virtual void FreePNG(CImageInfo *pImg) = 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;
|
||||||
|
|
|
@ -286,8 +286,7 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pBuildImgData);
|
free(pBuildImgData);
|
||||||
|
ImgInfo.Free();
|
||||||
Graphics()->FreePNG(&ImgInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2249,7 +2249,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser
|
||||||
}
|
}
|
||||||
if(Info.m_Format != CImageInfo::FORMAT_RGBA)
|
if(Info.m_Format != CImageInfo::FORMAT_RGBA)
|
||||||
{
|
{
|
||||||
pSelf->Graphics()->FreePNG(&Info);
|
Info.Free();
|
||||||
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': must be an RGBA image", aPath);
|
str_format(aError, sizeof(aError), "Failed to load menu image from '%s': must be an RGBA image", aPath);
|
||||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus", aError);
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus", aError);
|
||||||
|
|
|
@ -1944,8 +1944,7 @@ CMenus::CCommunityIconLoadJob::CCommunityIconLoadJob(CMenus *pMenus, const char
|
||||||
|
|
||||||
CMenus::CCommunityIconLoadJob::~CCommunityIconLoadJob()
|
CMenus::CCommunityIconLoadJob::~CCommunityIconLoadJob()
|
||||||
{
|
{
|
||||||
free(m_ImageInfo.m_pData);
|
m_ImageInfo.Free();
|
||||||
m_ImageInfo.m_pData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CMenus::CommunityIconScan(const char *pName, int IsDir, int DirType, void *pUser)
|
int CMenus::CommunityIconScan(const char *pName, int IsDir, int DirType, void *pUser)
|
||||||
|
@ -1983,14 +1982,14 @@ bool CMenus::LoadCommunityIconFile(const char *pPath, int DirType, CImageInfo &I
|
||||||
}
|
}
|
||||||
if(Info.m_Format != CImageInfo::FORMAT_RGBA)
|
if(Info.m_Format != CImageInfo::FORMAT_RGBA)
|
||||||
{
|
{
|
||||||
Graphics()->FreePNG(&Info);
|
Info.Free();
|
||||||
str_format(aError, sizeof(aError), "Failed to load community icon from '%s': must be an RGBA image", pPath);
|
str_format(aError, sizeof(aError), "Failed to load community icon from '%s': must be an RGBA image", pPath);
|
||||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError);
|
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!Storage()->CalculateHashes(pPath, DirType, &Sha256))
|
if(!Storage()->CalculateHashes(pPath, DirType, &Sha256))
|
||||||
{
|
{
|
||||||
Graphics()->FreePNG(&Info);
|
Info.Free();
|
||||||
str_format(aError, sizeof(aError), "Failed to load community icon from '%s': could not calculate hash", pPath);
|
str_format(aError, sizeof(aError), "Failed to load community icon from '%s': could not calculate hash", pPath);
|
||||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError);
|
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -293,7 +293,7 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info)
|
||||||
for(int i = 0; i < 6; ++i)
|
for(int i = 0; i < 6; ++i)
|
||||||
Skin.m_ColorableSkin.m_aEyes[i] = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_EYE_NORMAL + i]);
|
Skin.m_ColorableSkin.m_aEyes[i] = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_EYE_NORMAL + i]);
|
||||||
|
|
||||||
Graphics()->FreePNG(&Info);
|
Info.Free();
|
||||||
|
|
||||||
if(g_Config.m_Debug)
|
if(g_Config.m_Debug)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3104,8 +3104,7 @@ void CGameClient::LoadGameSkin(const char *pPath, bool AsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_GameSkinLoaded = true;
|
m_GameSkinLoaded = true;
|
||||||
|
ImgInfo.Free();
|
||||||
Graphics()->FreePNG(&ImgInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3149,7 +3148,7 @@ void CGameClient::LoadEmoticonsSkin(const char *pPath, bool AsDir)
|
||||||
m_EmoticonsSkin.m_aSpriteEmoticons[i] = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_OOP + i]);
|
m_EmoticonsSkin.m_aSpriteEmoticons[i] = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_OOP + i]);
|
||||||
|
|
||||||
m_EmoticonsSkinLoaded = true;
|
m_EmoticonsSkinLoaded = true;
|
||||||
Graphics()->FreePNG(&ImgInfo);
|
ImgInfo.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3220,7 +3219,7 @@ void CGameClient::LoadParticlesSkin(const char *pPath, bool AsDir)
|
||||||
m_ParticlesSkin.m_aSpriteParticles[9] = m_ParticlesSkin.m_SpriteParticleHit;
|
m_ParticlesSkin.m_aSpriteParticles[9] = m_ParticlesSkin.m_SpriteParticleHit;
|
||||||
|
|
||||||
m_ParticlesSkinLoaded = true;
|
m_ParticlesSkinLoaded = true;
|
||||||
free(ImgInfo.m_pData);
|
ImgInfo.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3319,7 +3318,7 @@ void CGameClient::LoadHudSkin(const char *pPath, bool AsDir)
|
||||||
m_HudSkin.m_SpriteHudDummyCopy = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_HUD_DUMMY_COPY]);
|
m_HudSkin.m_SpriteHudDummyCopy = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_HUD_DUMMY_COPY]);
|
||||||
|
|
||||||
m_HudSkinLoaded = true;
|
m_HudSkinLoaded = true;
|
||||||
free(ImgInfo.m_pData);
|
ImgInfo.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3364,7 +3363,7 @@ void CGameClient::LoadExtrasSkin(const char *pPath, bool AsDir)
|
||||||
m_ExtrasSkin.m_SpriteParticleSnowflake = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_PART_SNOWFLAKE]);
|
m_ExtrasSkin.m_SpriteParticleSnowflake = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_PART_SNOWFLAKE]);
|
||||||
m_ExtrasSkin.m_aSpriteParticles[0] = m_ExtrasSkin.m_SpriteParticleSnowflake;
|
m_ExtrasSkin.m_aSpriteParticles[0] = m_ExtrasSkin.m_SpriteParticleSnowflake;
|
||||||
m_ExtrasSkinLoaded = true;
|
m_ExtrasSkinLoaded = true;
|
||||||
free(ImgInfo.m_pData);
|
ImgInfo.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4369,8 +4369,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup
|
||||||
|
|
||||||
std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage];
|
std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage];
|
||||||
Graphics()->UnloadTexture(&(pImg->m_Texture));
|
Graphics()->UnloadTexture(&(pImg->m_Texture));
|
||||||
free(pImg->m_pData);
|
pImg->Free();
|
||||||
pImg->m_pData = nullptr;
|
|
||||||
*pImg = ImgInfo;
|
*pImg = ImgInfo;
|
||||||
str_copy(pImg->m_aName, aBuf);
|
str_copy(pImg->m_aName, aBuf);
|
||||||
pImg->m_External = IsVanillaImage(pImg->m_aName);
|
pImg->m_External = IsVanillaImage(pImg->m_aName);
|
||||||
|
|
|
@ -2107,8 +2107,7 @@ CUi::EPopupMenuFunctionResult CEditor::PopupEvent(void *pContext, CUIRect View,
|
||||||
|
|
||||||
if(pEditor->m_PopupEventType == POPEVENT_PIXELART_BIG_IMAGE || pEditor->m_PopupEventType == POPEVENT_PIXELART_MANY_COLORS)
|
if(pEditor->m_PopupEventType == POPEVENT_PIXELART_BIG_IMAGE || pEditor->m_PopupEventType == POPEVENT_PIXELART_MANY_COLORS)
|
||||||
{
|
{
|
||||||
free(pEditor->m_TileartImageInfo.m_pData);
|
pEditor->m_TileartImageInfo.Free();
|
||||||
pEditor->m_TileartImageInfo.m_pData = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CUi::POPUP_CLOSE_CURRENT;
|
return CUi::POPUP_CLOSE_CURRENT;
|
||||||
|
|
|
@ -212,8 +212,7 @@ void CEditor::AddTileart(bool IgnoreHistory)
|
||||||
m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileArt>(this, ImageCount, m_aTileartFilename, IndexMap));
|
m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileArt>(this, ImageCount, m_aTileartFilename, IndexMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(m_TileartImageInfo.m_pData);
|
m_TileartImageInfo.Free();
|
||||||
m_TileartImageInfo.m_pData = nullptr;
|
|
||||||
m_Map.OnModify();
|
m_Map.OnModify();
|
||||||
m_Dialog = DIALOG_NONE;
|
m_Dialog = DIALOG_NONE;
|
||||||
}
|
}
|
||||||
|
@ -226,8 +225,7 @@ void CEditor::TileartCheckColors()
|
||||||
{
|
{
|
||||||
m_PopupEventType = CEditor::POPEVENT_PIXELART_TOO_MANY_COLORS;
|
m_PopupEventType = CEditor::POPEVENT_PIXELART_TOO_MANY_COLORS;
|
||||||
m_PopupEventActivated = true;
|
m_PopupEventActivated = true;
|
||||||
free(m_TileartImageInfo.m_pData);
|
m_TileartImageInfo.Free();
|
||||||
m_TileartImageInfo.m_pData = nullptr;
|
|
||||||
}
|
}
|
||||||
else if(NumColorGroups > 1)
|
else if(NumColorGroups > 1)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue