Example #1
0
	//! returns a pixel
	ColourValue CImage::getPixel(UINT32 x, UINT32 y) const
	{
		ColourValue c;
		if (x >= Size.Width || y >= Size.Height)
			return c;
		
		switch (Format)
		{
		case ECF_A1R5G5B5:
			c.setAsARGB(A1R5G5B5toA8R8G8B8(((UINT16*)Data)[y*Size.Width + x]));
			return c; //A1R5G5B5toA8R8G8B8(((UINT16*)Data)[y*Size.Width + x]);
		case ECF_R5G6B5:
			c.setAsARGB(R5G6B5toA8R8G8B8(((UINT16*)Data)[y*Size.Width + x]));
			return c;//R5G6B5toA8R8G8B8(((UINT16*)Data)[y*Size.Width + x]);
		case ECF_A8R8G8B8:
			c.setAsARGB(((UINT32*)Data)[y*Size.Width + x]);
			return c;// ((UINT32*)Data)[y*Size.Width + x];
		case ECF_R8G8B8:
		{
			UINT8* p = Data + (y * 3)*Size.Width + (x * 3);
			c.setAlpha(255);
			c.setRed(p[0]);
			c.setBlue(p[1]);
			c.setGreen(p[2]);
			return c;
		}
#ifndef _DEBUG
		default:
			break;
#endif
		}

		return ColourValue(0);
	}
void CColorConverter::convert_R5G6B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
{
	u16* sB = (u16*)sP;
	u32* dB = (u32*)dP;

	for (s32 x = 0; x < sN; ++x)
		*dB++ = R5G6B5toA8R8G8B8(*sB++);
}
Example #3
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;
		}
	}
}
Example #4
0
//! returns a pixel
SColor SImage::getPixel(u32 x, u32 y) const
{
	if (x >= (u32)Size.Width || y >= (u32)Size.Height)
		return SColor(0);

	switch(Format)
	{
	case ECF_A1R5G5B5:
		return A1R5G5B5toA8R8G8B8(((u16*)Data)[y*Size.Width + x]);
	case ECF_R5G6B5:
		return R5G6B5toA8R8G8B8(((u16*)Data)[y*Size.Width + x]);
	case ECF_A8R8G8B8:
		return ((u32*)Data)[y*Size.Width + x];
	case ECF_R8G8B8:
		{
			u8* p = &((u8*)Data)[(y*3)*Size.Width + (x*3)];
			return SColor(255,p[0],p[1],p[2]);
		}
	}

	return SColor(0);
}