示例#1
0
	//! fills the surface with given color
	void CImage::fill(const ColourValue &color)
	{
		UINT32 c;

		switch (Format)
		{
		case ECF_A1R5G5B5:
			c = A8R8G8B8toA1R5G5B5(color.getAsARGB());
			c |= c << 16;
			break;
		case ECF_R5G6B5:
			c = A8R8G8B8toR5G6B5(color.getAsARGB());
			c |= c << 16;
			break;
		case ECF_A8R8G8B8:
			c = color.getAsARGB();
			break;
		case ECF_R8G8B8:
		{
			UINT8 rgb[3];
			CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb);
			const UINT32 size = getImageDataSizeInBytes();
			for (UINT32 i = 0; i<size; i += 3)
			{
				memcpy(Data + i, rgb, 3);
			}
			return;
		}
		break;
		default:
			// TODO: Handle other formats
			return;
		}
		memset32(Data, c, getImageDataSizeInBytes());
	}
示例#2
0
void CD3D9Texture::copy16BitMipMap(char* src, char* tgt,
				   s32 width, s32 height,
				   s32 pitchsrc, s32 pitchtgt) const
{
	for (s32 y=0; y<height; ++y)
	{
		for (s32 x=0; x<width; ++x)
		{
			u32 a=0, r=0, g=0, b=0;

			for (s32 dy=0; dy<2; ++dy)
			{
				const s32 tgy = (y*2)+dy;
				for (s32 dx=0; dx<2; ++dx)
				{
					const s32 tgx = (x*2)+dx;

					SColor c;
					if (ColorFormat == ECF_A1R5G5B5)
						c = A1R5G5B5toA8R8G8B8(*(u16*)(&src[(tgx*2)+(tgy*pitchsrc)]));
					else
						c = R5G6B5toA8R8G8B8(*(u16*)(&src[(tgx*2)+(tgy*pitchsrc)]));

					a += c.getAlpha();
					r += c.getRed();
					g += c.getGreen();
					b += c.getBlue();
				}
			}

			a /= 4;
			r /= 4;
			g /= 4;
			b /= 4;

			u16 c;
			if (ColorFormat == ECF_A1R5G5B5)
				c = RGBA16(r,g,b,a);
			else
				c = A8R8G8B8toR5G6B5(SColor(a,r,g,b).color);
			*(u16*)(&tgt[(x*2)+(y*pitchtgt)]) = c;
		}
	}
}
示例#3
0
	//! sets a pixel
	void CImage::setPixel(UINT32 x, UINT32 y, const ColourValue &color, bool blend)
	{
		ColourValue c = color;
		if (x >= Size.Width || y >= Size.Height)
			return;

		switch (Format)
		{
		case ECF_A1R5G5B5:
		{
			UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1));
			*dest = A8R8G8B8toA1R5G5B5(color.getAsARGB());
		} break;

		case ECF_R5G6B5:
		{
			UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1));
			*dest = A8R8G8B8toR5G6B5(color.getAsARGB());
		} break;

		case ECF_R8G8B8:
		{
			UINT8* dest = Data + (y * Pitch) + (x * 3);
			
			dest[0] = (UINT8)c.getRed();
			dest[1] = (UINT8)c.getGreen();
			dest[2] = (UINT8)c.getBlue();
		} break;

		case ECF_A8R8G8B8:
		{
			UINT32 * dest = (UINT32*)(Data + (y * Pitch) + (x << 2));
			*dest = blend ? PixelBlend32(*dest, color.getAsARGB()) : color.getAsARGB();
		} break;
#ifndef _DEBUG
		default:
			break;
#endif
		}
	}