mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
fixed problems with RGB images in maps. Closes #962
This commit is contained in:
parent
0e28755475
commit
f8e114ff5a
|
@ -35,7 +35,7 @@ void CMapImages::OnMapLoad()
|
|||
m_aTextures[i] = 0;
|
||||
|
||||
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
|
||||
if(pImg->m_External)
|
||||
if(pImg->m_External || (pImg->m_Version > 1 && pImg->m_Format != CImageInfo::FORMAT_RGB && pImg->m_Format != CImageInfo::FORMAT_RGBA))
|
||||
{
|
||||
char Buf[256];
|
||||
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
||||
|
@ -45,7 +45,7 @@ void CMapImages::OnMapLoad()
|
|||
else
|
||||
{
|
||||
void *pData = pMap->GetData(pImg->m_ImageData);
|
||||
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, 0);
|
||||
m_aMenuTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Version == 1 ? CImageInfo::FORMAT_RGBA : pImg->m_Format, pData, CImageInfo::FORMAT_RGBA, 0);
|
||||
pMap->UnloadData(pImg->m_ImageData);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void CMapImages::OnMenuMapLoad(IMap *pMap)
|
|||
m_aMenuTextures[i] = 0;
|
||||
|
||||
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
|
||||
if(pImg->m_External)
|
||||
if(pImg->m_External || (pImg->m_Version > 1 && pImg->m_Format != CImageInfo::FORMAT_RGB && pImg->m_Format != CImageInfo::FORMAT_RGBA))
|
||||
{
|
||||
char Buf[256];
|
||||
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
||||
|
@ -80,7 +80,7 @@ void CMapImages::OnMenuMapLoad(IMap *pMap)
|
|||
else
|
||||
{
|
||||
void *pData = pMap->GetData(pImg->m_ImageData);
|
||||
m_aMenuTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, 0);
|
||||
m_aMenuTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Version == 1 ? CImageInfo::FORMAT_RGBA : pImg->m_Format, pData, CImageInfo::FORMAT_RGBA, 0);
|
||||
pMap->UnloadData(pImg->m_ImageData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,35 +164,42 @@ int CLayerGroup::SwapLayers(int Index0, int Index1)
|
|||
|
||||
void CEditorImage::AnalyseTileFlags()
|
||||
{
|
||||
mem_zero(m_aTileFlags, sizeof(m_aTileFlags));
|
||||
|
||||
int tw = m_Width/16; // tilesizes
|
||||
int th = m_Height/16;
|
||||
if ( tw == th )
|
||||
if(m_Format == CImageInfo::FORMAT_RGB)
|
||||
{
|
||||
unsigned char *pPixelData = (unsigned char *)m_pData;
|
||||
|
||||
int TileID = 0;
|
||||
for(int ty = 0; ty < 16; ty++)
|
||||
for(int tx = 0; tx < 16; tx++, TileID++)
|
||||
{
|
||||
bool Opaque = true;
|
||||
for(int x = 0; x < tw; x++)
|
||||
for(int y = 0; y < th; y++)
|
||||
{
|
||||
int p = (ty*tw+y)*m_Width + tx*tw+x;
|
||||
if(pPixelData[p*4+3] < 250)
|
||||
{
|
||||
Opaque = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(Opaque)
|
||||
m_aTileFlags[TileID] |= TILEFLAG_OPAQUE;
|
||||
}
|
||||
for(int i = 0; i < 256; ++i)
|
||||
m_aTileFlags[i] = TILEFLAG_OPAQUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mem_zero(m_aTileFlags, sizeof(m_aTileFlags));
|
||||
|
||||
int tw = m_Width/16; // tilesizes
|
||||
int th = m_Height/16;
|
||||
if(tw == th)
|
||||
{
|
||||
unsigned char *pPixelData = (unsigned char *)m_pData;
|
||||
|
||||
int TileID = 0;
|
||||
for(int ty = 0; ty < 16; ty++)
|
||||
for(int tx = 0; tx < 16; tx++, TileID++)
|
||||
{
|
||||
bool Opaque = true;
|
||||
for(int x = 0; x < tw; x++)
|
||||
for(int y = 0; y < th; y++)
|
||||
{
|
||||
int p = (ty*tw+y)*m_Width + tx*tw+x;
|
||||
if(pPixelData[p*4+3] < 250)
|
||||
{
|
||||
Opaque = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(Opaque)
|
||||
m_aTileFlags[TileID] |= TILEFLAG_OPAQUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CEditor::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser)
|
||||
|
|
|
@ -255,7 +255,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
pImg->AnalyseTileFlags();
|
||||
|
||||
CMapItemImage Item;
|
||||
Item.m_Version = 1;
|
||||
Item.m_Version = CMapItemImage::CURRENT_VERSION;
|
||||
|
||||
Item.m_Width = pImg->m_Width;
|
||||
Item.m_Height = pImg->m_Height;
|
||||
|
@ -264,7 +264,11 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
if(pImg->m_External)
|
||||
Item.m_ImageData = -1;
|
||||
else
|
||||
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pImg->m_pData);
|
||||
{
|
||||
int PixelSize = pImg->m_Format == CImageInfo::FORMAT_RGB ? 3 : 4;
|
||||
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*PixelSize, pImg->m_pData);
|
||||
}
|
||||
Item.m_Format = pImg->m_Format;
|
||||
df.AddItem(MAPITEMTYPE_IMAGE, i, sizeof(Item), &Item);
|
||||
}
|
||||
|
||||
|
@ -469,7 +473,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
CEditorImage *pImg = new CEditorImage(m_pEditor);
|
||||
pImg->m_External = pItem->m_External;
|
||||
|
||||
if(pItem->m_External)
|
||||
if(pItem->m_External || (pItem->m_Version > 1 && pItem->m_Format != CImageInfo::FORMAT_RGB && pItem->m_Format != CImageInfo::FORMAT_RGBA))
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf),"mapres/%s.png", pName);
|
||||
|
@ -488,12 +492,13 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
{
|
||||
pImg->m_Width = pItem->m_Width;
|
||||
pImg->m_Height = pItem->m_Height;
|
||||
pImg->m_Format = CImageInfo::FORMAT_RGBA;
|
||||
pImg->m_Format = pItem->m_Version == 1 ? CImageInfo::FORMAT_RGBA : pItem->m_Format;
|
||||
int PixelSize = pImg->m_Format == CImageInfo::FORMAT_RGB ? 3 : 4;
|
||||
|
||||
// copy image data
|
||||
void *pData = DataFile.GetData(pItem->m_ImageData);
|
||||
pImg->m_pData = mem_alloc(pImg->m_Width*pImg->m_Height*4, 1);
|
||||
mem_copy(pImg->m_pData, pData, pImg->m_Width*pImg->m_Height*4);
|
||||
pImg->m_pData = mem_alloc(pImg->m_Width*pImg->m_Height*PixelSize, 1);
|
||||
mem_copy(pImg->m_pData, pData, pImg->m_Width*pImg->m_Height*PixelSize);
|
||||
pImg->m_TexID = m_pEditor->Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Format, pImg->m_pData, CImageInfo::FORMAT_AUTO, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ struct CMapItemInfo
|
|||
int m_License;
|
||||
} ;
|
||||
|
||||
struct CMapItemImage
|
||||
struct CMapItemImage_v1
|
||||
{
|
||||
int m_Version;
|
||||
int m_Width;
|
||||
|
@ -109,6 +109,12 @@ struct CMapItemImage
|
|||
int m_ImageData;
|
||||
} ;
|
||||
|
||||
struct CMapItemImage : public CMapItemImage_v1
|
||||
{
|
||||
enum { CURRENT_VERSION=2 };
|
||||
int m_Format;
|
||||
};
|
||||
|
||||
struct CMapItemGroup_v1
|
||||
{
|
||||
int m_Version;
|
||||
|
|
Loading…
Reference in a new issue