Exemple #1
0
void nSurface::SetupSurface( E_COLOR_FORMAT ecfType, const Core::IDimension<u32> &dim, void *Data )
{
	m_ColorFormat = ECF_A8R8G8B8;
	m_Dimension = dim;
	m_nPitch = GetBitsPerPixels() / 8;

	// bug fixed: 
	// the previous code: m_pData = 0xbe70; now: m_pData = NULL;
	m_pData = NULL;
	AllocData();
	switch (ecfType)
	{
		case ECF_A8R8G8B8:
			{
				memcpy(m_pData, Data, dim.Width * dim.Height * m_nPitch);
			}

		case ECF_R8G8B8:
			{
				IColor color;
				for (u32 y=0; y<dim.Height; y++)
					for (u32 x=0; x<dim.Width; x++)
					{
						u32 i = (y * dim.Width + x)*3;
						u8 *col = &((u8 *)Data)[i];
						color.Set(col[0], col[1], col[2], 255);
						((u32 *)m_pData)[y * m_Dimension.Width + x] = color.Color;
					}
			}
	}
}
Exemple #2
0
void nSurface::SetAlphaKey( const IColor &color )
{
	IColor keyColor(color.GetRed(), color.GetGreen(), color.GetBlue(), (u32)255);
	IColor newColor;
	if (color.GetAlpha()>0) newColor.Set(color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha());
	else newColor.Set(0, 0, 0, color.GetAlpha());

	switch (m_ColorFormat)
	{
		case ECF_A8R8G8B8:	// 32 bit
			{
				for (u32 y=0; y<m_Dimension.Height; y++)
					for (u32 x=0; x<m_Dimension.Width; x++)
					{
						if (((u32 *)m_pData)[y * m_Dimension.Width + x] == keyColor.Color)
							((u32 *)m_pData)[y * m_Dimension.Width + x] = newColor.Color;
					}
			}
	}
}