ddnet/src/game/editor/mapitems/image.cpp

41 lines
837 B
C++
Raw Normal View History

#include <game/editor/editor.h>
CEditorImage::~CEditorImage()
{
m_pEditor->Graphics()->UnloadTexture(&m_Texture);
free(m_pData);
m_pData = nullptr;
}
void CEditorImage::AnalyseTileFlags()
{
mem_zero(m_aTileFlags, sizeof(m_aTileFlags));
int tw = m_Width / 16; // tilesizes
int th = m_Height / 16;
if(tw == th && m_Format == CImageInfo::FORMAT_RGBA)
{
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;
}
}
}