Skip to content
Permalink
Browse files

Actual fix for crash with RGB images, convert them to RGBA instead

  • Loading branch information
def- committed Apr 4, 2015
1 parent 9c05803 commit 0945e24ce40e9ff8462b6d94fa213f9537a8a302
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/game/editor/io.cpp
@@ -282,9 +282,23 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
else
{
if(pImg->m_Format == CImageInfo::FORMAT_RGB)
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*3, pImg->m_pData);
{
// Convert to RGBA
unsigned char *pData = (unsigned char*) mem_alloc(Item.m_Width*Item.m_Height*4, 1);
for(int i = 0; i < Item.m_Width*Item.m_Height; i++)
{
pData[i*4] = ((unsigned char*)(pImg->m_pData))[i*3];
pData[i*4+1] = ((unsigned char*)(pImg->m_pData))[i*3+1];
pData[i*4+2] = ((unsigned char*)(pImg->m_pData))[i*3+2];
pData[i*4+3] = 255;
}
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pData);
mem_free(pData);
}
else
{
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pImg->m_pData);
}
}
df.AddItem(MAPITEMTYPE_IMAGE, i, sizeof(Item), &Item);
}

0 comments on commit 0945e24

Please sign in to comment.
You can’t perform that action at this time.