Ejemplo n.º 1
0
void TestWinText(void)
{
	BeginTests();

	ObjectsInit();

	CWinText			cWinText;
	SWinFontInstance*	psWinFont;
	Ptr<CFont>			pcFont;
	CGlyph*				pcCel;
	CImage				cDestImage;

	cWinText.Init(NULL);
	psWinFont = cWinText.Create("Fixedsys", 0, 0, FW_DONTCARE);
	pcFont = cWinText.GenerateFont(psWinFont, "Fixedsys");

	WriteImage(&pcFont->GetImage(), "Output/Fixedsys.bmp");
	AssertFile("Input/Fixedsys.bmp", "Output/Fixedsys.bmp");

	pcCel = pcFont->GetGlyph('H');
	pcCel->GetSubImage()->SetAlignment(SUB_IMAGE_ALIGNMENT_LEFT|SUB_IMAGE_ALIGNMENT_TOP);
	cDestImage.Init(pcCel->GetFullWidth(), pcCel->GetFullHeight(), pcCel->GetSourceImage());
	cDestImage.Clear();
	CImageCopier::Copy(pcCel->GetCel(), &cDestImage, 0, 0);
	WriteImage(&cDestImage, "Output/TheLetterH.png");
	cDestImage.Kill();
	AssertFile("Input/TheLetterH.png", "Output/TheLetterH.png");

	pcFont->Kill();
	cWinText.Kill();

	ObjectsKill();

	TestStatistics();
}
void TestImageColourAccessorBytes(void)
{
	CImageColourRGB		cRGB; 
	CImageColourOpacity	cAlpha;
	CImageColourCombo2	cColour;
	CChannels*			pcChannels;
	CImageAccessor*		pcAccessor;
	CImage				cImage;
	SImageColour		sDest;
	BOOL				bResult;
	char*				pvData;

	cRGB.Init(1.0f, 0.5f, 0.25f);
	cAlpha.Init(0.333f);
	cColour.Init(&cRGB, &cAlpha);

	cImage.Init(10, 10, PT_uchar,	IMAGE_DIFFUSE_GREEN,	//0x7f
									IMAGE_NORMAL_Y,		
									IMAGE_DIFFUSE_BLUE,	//0x3f
									IMAGE_OPACITY,		//0x54
									IMAGE_DIFFUSE_RED,	//0xff
									IMAGE_MASK, 
									CHANNEL_ZERO);
	cImage.Clear();

	pcAccessor = CImageAccessorCreator::Create(&cImage, PT_uchar, IMAGE_OPACITY, IMAGE_DIFFUSE_RED, IMAGE_DIFFUSE_GREEN, IMAGE_DIFFUSE_BLUE, CHANNEL_ZERO);

	sDest.Full();
	bResult = pcAccessor->MakeColour(&sDest, &cColour);
	AssertBool(TRUE, bResult);

	//Remember ints have reverse endiannes which is why the test number below looks backwarsd.
	AssertIntHex(0x3f7fff54, *(int*)((void*)sDest.c));

	pcAccessor->Set(1, 0, &sDest);
	pcAccessor->Kill();

	pcChannels = &cImage.mcChannels;

	pvData = pcChannels->GetData();

	//First pixel.  Didn't touch it.
	AssertChar(0x00, pvData[0x0]);
	AssertChar(0x00, pvData[0x1]);
	AssertChar(0x00, pvData[0x2]);
	AssertChar(0x00, pvData[0x3]);
	AssertChar(0x00, pvData[0x4]);
	AssertChar(0x00, pvData[0x5]);

	//Second pixel.
	AssertChar(0x7f, pvData[0x6]);
	AssertChar(0x00, pvData[0x7]);
	AssertChar(0x3f, pvData[0x8]);
	AssertChar(0x54, pvData[0x9]);
	AssertChar((char)0xff, pvData[0xa]);
	AssertChar(0x00, pvData[0xb]);
}
void TestImageColourMultiAccessor(void)
{
	CImageColourNormal		cNormal;
	CImageColourOpacity		cAlpha;
	CImageColourCombo2		cColour;
	CChannels*				pcChannels;
	CImageAccessor*			pcAccessor;
	CImage					cImage;
	SImageColour			sDest;
	BOOL					bResult;

	cNormal.Init(0.7f, -0.6f, -0.5f);
	cAlpha.Init(0.333f);
	cColour.Init(&cNormal, &cAlpha);

	cImage.Init();
	cImage.BeginChange();
	cImage.AddChannel(IMAGE_DIFFUSE_GREEN, PT_uchar);
	cImage.AddChannel(IMAGE_NORMAL_Y, PT_float);
	cImage.AddChannel(IMAGE_DIFFUSE_BLUE, PT_uchar);
	cImage.AddChannel(IMAGE_OPACITY, PT_ushort);
	cImage.AddChannel(IMAGE_DIFFUSE_RED, PT_uchar);
	cImage.AddChannel(IMAGE_MASK, PT_int);
	cImage.AddChannel(IMAGE_NORMAL_Z, PT_float);
	cImage.AddChannel(IMAGE_NORMAL_X, PT_float);
	cImage.SetSize(1, 2);
	cImage.EndChange();
	cImage.Clear();

	pcAccessor = CImageAccessorCreator::Create(&cImage, IMAGE_NORMAL_X, IMAGE_NORMAL_Y, IMAGE_NORMAL_Z, IMAGE_OPACITY, CHANNEL_ZERO);

	sDest.Full();
	bResult = pcAccessor->MakeColour(&sDest, &cColour);
	AssertBool(TRUE, bResult);

	AssertFloat(0.7f, *((float*)&((sDest).c)[0x0]), 3);
	AssertFloat(-0.6f, *((float*)&((sDest).c)[0x4]), 3);
	AssertFloat(-0.5f, *((float*)&((sDest).c)[0x8]), 3);
	AssertShortHex(0x553f, *((unsigned short*)&((sDest).c)[0xc]));

	pcAccessor->Set(0, 1, &sDest);
	pcAccessor->Kill();

	pcChannels = &cImage.mcChannels;
	AssertFloat(-0.6f, *(float*)&(pcChannels->GetData()[22]), 3);
	AssertFloat( 0.7f, *(float*)&(pcChannels->GetData()[38]), 3);
	AssertFloat(-0.5f, *(float*)&(pcChannels->GetData()[34]), 3);
	AssertShortHex(0x553f, *(unsigned short*)&(pcChannels->GetData()[27]));
}
void TestImageColourAccessorFloats(void)
{
	CImageColourNormal	cNormal;
	CChannels*			pcChannels;
	CImageAccessor*		pcAccessor;
	CImage				cImage;
	SImageColour		sDest;
	BOOL				bResult;

	cNormal.Init(0.7f, 0.6f, 0.5f);
	cImage.Init();
	cImage.BeginChange();
	cImage.AddChannel(IMAGE_DIFFUSE_GREEN, PT_uchar);
	cImage.AddChannel(IMAGE_NORMAL_Y, PT_float);
	cImage.AddChannel(IMAGE_DIFFUSE_BLUE, PT_uchar);
	cImage.AddChannel(IMAGE_OPACITY, PT_short);
	cImage.AddChannel(IMAGE_DIFFUSE_RED, PT_uchar);
	cImage.AddChannel(IMAGE_MASK, PT_int);
	cImage.AddChannel(IMAGE_NORMAL_Z, PT_float);
	cImage.AddChannel(IMAGE_NORMAL_X, PT_float);
	cImage.SetSize(1, 2);
	cImage.EndChange();
	cImage.Clear();

	pcAccessor = CImageAccessorCreator::Create(&cImage, PT_float, IMAGE_NORMAL_X, IMAGE_NORMAL_Y, IMAGE_NORMAL_Z, CHANNEL_ZERO);

	sDest.Full();
	bResult = pcAccessor->MakeColour(&sDest, &cNormal);
	AssertBool(TRUE, bResult);

	AssertFloat(0.7f, *((float*)&((sDest).c)[0x0]), 3);
	AssertFloat(0.6f, *((float*)&((sDest).c)[0x4]), 3);
	AssertFloat(0.5f, *((float*)&((sDest).c)[0x8]), 3);

	pcAccessor->Set(0, 1, &sDest);
	pcAccessor->Kill();

	pcChannels = &cImage.mcChannels;
	
	AssertFloat(0.6f, *(float*)&(pcChannels->GetData()[22]), 3);
	AssertFloat(0.7f, *(float*)&(pcChannels->GetData()[38]), 3);
	AssertFloat(0.5f, *(float*)&(pcChannels->GetData()[34]), 3);
}