示例#1
0
VGUErrorCode vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
{
	if(!matrix || ((ptrdiff_t)matrix) & 3)
		return VGU_ILLEGAL_ARGUMENT_ERROR;
	
	VGfloat qtos[9];
	VGUErrorCode ret1 = vguComputeWarpQuadToSquare(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, qtos);
	if(ret1 == VGU_BAD_WARP_ERROR)
		return VGU_BAD_WARP_ERROR;
	
	VGfloat stoq[9];
	VGUErrorCode ret2 = vguComputeWarpSquareToQuad(dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3, stoq);
	if(ret2 == VGU_BAD_WARP_ERROR)
		return VGU_BAD_WARP_ERROR;
	
	Matrix3x3 m1(qtos[0], qtos[3], qtos[6],
				 qtos[1], qtos[4], qtos[7],
				 qtos[2], qtos[5], qtos[8]);
	Matrix3x3 m2(stoq[0], stoq[3], stoq[6],
				 stoq[1], stoq[4], stoq[7],
				 stoq[2], stoq[5], stoq[8]);
	Matrix3x3 r = m2 * m1;
	
	matrix[0] = r[0][0];
	matrix[1] = r[1][0];
	matrix[2] = r[2][0];
	matrix[3] = r[0][1];
	matrix[4] = r[1][1];
	matrix[5] = r[2][1];
	matrix[6] = r[0][2];
	matrix[7] = r[1][2];
	matrix[8] = r[2][2];
	return VGU_NO_ERROR;
}
示例#2
0
VGUErrorCode vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
{
	if(!matrix || ((ptrdiff_t)matrix) & 3)
		return VGU_ILLEGAL_ARGUMENT_ERROR;
	
	VGfloat mat[9];
	VGUErrorCode ret = vguComputeWarpSquareToQuad(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, mat);
	if(ret == VGU_BAD_WARP_ERROR)
		return VGU_BAD_WARP_ERROR;
	Matrix3x3 m(mat[0], mat[3], mat[6],
				mat[1], mat[4], mat[7],
				mat[2], mat[5], mat[8]);
	bool nonsingular = m.invert();
	if(!nonsingular)
		return VGU_BAD_WARP_ERROR;
	matrix[0] = m[0][0];
	matrix[1] = m[1][0];
	matrix[2] = m[2][0];
	matrix[3] = m[0][1];
	matrix[4] = m[1][1];
	matrix[5] = m[2][1];
	matrix[6] = m[0][2];
	matrix[7] = m[1][2];
	matrix[8] = m[2][2];
	return VGU_NO_ERROR;
}
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToQuad(
	VGfloat DestinationX0,
	VGfloat DestinationY0,
	VGfloat DestinationX1,
	VGfloat DestinationY1,
	VGfloat DestinationX2,
	VGfloat DestinationY2,
	VGfloat DestinationX3,
	VGfloat DestinationY3,
	VGfloat SourceX0,
	VGfloat SourceY0,
	VGfloat SourceX1,
	VGfloat SourceY1,
	VGfloat SourceX2,
	VGfloat SourceY2,
	VGfloat SourceX3,
	VGfloat SourceY3,
	VGfloat * Matrix
	)
{
	VGUErrorCode result = VGU_BAD_HANDLE_ERROR;

	vgmENTERAPI(vguComputeWarpQuadToQuad)
	{
		vgsMATRIX q2s;
		vgsMATRIX s2q;
		vgsMATRIX product;

#if gcdENABLE_PERFORMANCE_PRIOR
		gctFLOAT m1[9], m2[9];
#endif
		/* Validate the input matrix. */
		if (vgmIS_INVALID_PTR(Matrix, 4))
		{
			result = VGU_ILLEGAL_ARGUMENT_ERROR;
			break;
		}

		/* Reset matrices. */
		vgfInvalidateMatrix(&q2s);
		vgfInvalidateMatrix(&s2q);

#if gcdENABLE_PERFORMANCE_PRIOR
		result = vguComputeWarpQuadToSquare(
			SourceX0, SourceY0,
			SourceX1, SourceY1,
			SourceX2, SourceY2,
			SourceX3, SourceY3,
			m1
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		vgmCONVERTMAT(gctFIXED, gctFLOAT, vgmFLOAT_TO_FIXED_SPECIAL, &q2s, m1);

		result = vguComputeWarpSquareToQuad(
			DestinationX0, DestinationY0,
			DestinationX1, DestinationY1,
			DestinationX2, DestinationY2,
			DestinationX3, DestinationY3,
			m2
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		vgmCONVERTMAT(gctFIXED, gctFLOAT, vgmFLOAT_TO_FIXED_SPECIAL, &s2q, m2);

		/* Find the product. */
		vgfMultiplyMatrix3x3(&s2q, &q2s, &product);

		/* Set the result. */
		vgmCONVERTMAT(gctFLOAT, gctFIXED, vgmFIXED_TO_FLOAT_SPECIAL, Matrix, &product);
#else
		result = vguComputeWarpQuadToSquare(
			SourceX0, SourceY0,
			SourceX1, SourceY1,
			SourceX2, SourceY2,
			SourceX3, SourceY3,
			vgmGETMATRIXVALUES(&q2s)
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		result = vguComputeWarpSquareToQuad(
			DestinationX0, DestinationY0,
			DestinationX1, DestinationY1,
			DestinationX2, DestinationY2,
			DestinationX3, DestinationY3,
			vgmGETMATRIXVALUES(&s2q)
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		/* Find the product. */
		vgfMultiplyMatrix3x3(&s2q, &q2s, &product);

		/* Set the result. */
		gcoOS_MemCopy(
			Matrix,
			vgmGETMATRIXVALUES(&product),
			sizeof(vgtMATRIXVALUES)
			);
#endif
	}
	vgmLEAVEAPI(vguComputeWarpQuadToQuad);

	/* Return result. */
	return result;
}
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToSquare(
	VGfloat SourceX0,
	VGfloat SourceY0,
	VGfloat SourceX1,
	VGfloat SourceY1,
	VGfloat SourceX2,
	VGfloat SourceY2,
	VGfloat SourceX3,
	VGfloat SourceY3,
	VGfloat * Matrix
	)
{
	VGUErrorCode result = VGU_BAD_HANDLE_ERROR;

	vgmENTERAPI(vguComputeWarpQuadToSquare)
	{
		vgsMATRIX projective;
		vgsMATRIX warped;

		/* Validate the input matrix. */
		if (vgmIS_INVALID_PTR(Matrix, 4))
		{
			result = VGU_ILLEGAL_ARGUMENT_ERROR;
			break;
		}

		/* Reset the projective matrix. */
		vgfInvalidateMatrix(&projective);

#if gcdENABLE_PERFORMANCE_PRIOR
		/* Get projective transformation matrix. */
		result = vguComputeWarpSquareToQuad(
			SourceX0, SourceY0,
			SourceX1, SourceY1,
			SourceX2, SourceY2,
			SourceX3, SourceY3,
			Matrix
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		/*convert to fixed-point*/
		vgmCONVERTMAT(gctFIXED, gctFLOAT, vgmFLOAT_TO_FIXED_SPECIAL, &projective, Matrix);

		/* Invert the matrix. */
		if (!vgfInvertMatrix(&projective, &warped))
		{
			result = VGU_BAD_WARP_ERROR;
			break;
		}

		/* Set the result matrix. */
		vgmCONVERTMAT(gctFLOAT, gctFIXED, vgmFIXED_TO_FLOAT_SPECIAL, Matrix, &warped);
#else
		/* Get projective transformation matrix. */
		result = vguComputeWarpSquareToQuad(
			SourceX0, SourceY0,
			SourceX1, SourceY1,
			SourceX2, SourceY2,
			SourceX3, SourceY3,
			vgmGETMATRIXVALUES(&projective)
			);

		/* Error? */
		if (result != VGU_NO_ERROR)
		{
			break;
		}

		/* Invert the matrix. */
		if (!vgfInvertMatrix(&projective, &warped))
		{
			result = VGU_BAD_WARP_ERROR;
			break;
		}

		/* Set the result matrix. */
		gcoOS_MemCopy(
			Matrix,
			vgmGETMATRIXVALUES(&warped),
			sizeof(vgtMATRIXVALUES)
			);
#endif
	}
	vgmLEAVEAPI(vguComputeWarpQuadToSquare);

	/* Return result. */
	return result;
}