gdiplus: Improve performance of GdipTranslateMatrix.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53947
This commit is contained in:
Bartosz Kosiorek 2022-12-03 00:48:53 +01:00 committed by Alexandre Julliard
parent ae0891eb64
commit 82d94219cb
2 changed files with 50 additions and 11 deletions

View file

@ -417,24 +417,23 @@ GpStatus WINGDIPAPI GdipTransformMatrixPointsI(GpMatrix *matrix, GpPoint *pts, I
GpStatus WINGDIPAPI GdipTranslateMatrix(GpMatrix *matrix, REAL offsetX,
REAL offsetY, GpMatrixOrder order)
{
REAL translate[6];
TRACE("(%p, %.2f, %.2f, %d)\n", matrix, offsetX, offsetY, order);
if(!matrix)
return InvalidParameter;
translate[0] = 1.0;
translate[1] = 0.0;
translate[2] = 0.0;
translate[3] = 1.0;
translate[4] = offsetX;
translate[5] = offsetY;
if(order == MatrixOrderAppend)
matrix_multiply(matrix->matrix, translate, matrix->matrix);
{
matrix->matrix[4] += offsetX;
matrix->matrix[5] += offsetY;
}
else if (order == MatrixOrderPrepend)
matrix_multiply(translate, matrix->matrix, matrix->matrix);
{
matrix->matrix[4] = offsetX * matrix->matrix[0] + offsetY * matrix->matrix[2]
+ matrix->matrix[4];
matrix->matrix[5] = offsetX * matrix->matrix[1] + offsetY * matrix->matrix[3]
+ matrix->matrix[5];
}
else
return InvalidParameter;

View file

@ -110,6 +110,45 @@ static void test_transform(void)
GdipDeleteMatrix(matrix);
}
static void test_translate(void)
{
GpStatus status;
GpMatrix *matrix = NULL;
REAL elems[6];
static const REAL expected_elem_append[] = {1.0, -2.0, 30.0, 40.0, -470.0, 620.0};
static const REAL expected_elem_prepend[] = {1.0, -2.0, 30.0, 40.0, 130.0, 1340.0};
GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix);
status = GdipTranslateMatrix(NULL, 30.0, 20.0, MatrixOrderAppend);
expect(InvalidParameter, status);
status = GdipTranslateMatrix(matrix, 30.0, 20.0, MatrixOrderAppend);
expect(Ok, status);
status = GdipGetMatrixElements(matrix, elems);
expect(Ok, status);
GdipDeleteMatrix(matrix);
for(INT i = 0; i < 6; i++)
ok(expected_elem_append[i] == elems[i], "Expected #%d to be (%.1f) but got (%.1f)\n", i,
expected_elem_append[i], elems[i]);
GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix);
status = GdipTranslateMatrix(matrix, 30.0, 20.0, MatrixOrderPrepend);
expect(Ok, status);
status = GdipGetMatrixElements(matrix, elems);
expect(Ok, status);
GdipDeleteMatrix(matrix);
for(INT i = 0; i < 6; i++)
ok(expected_elem_prepend[i] == elems[i], "Expected #%d to be (%.1f) but got (%.1f)\n", i,
expected_elem_prepend[i], elems[i]);
}
static void test_scale(void)
{
GpStatus status;
@ -430,6 +469,7 @@ START_TEST(matrix)
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
test_constructor_destructor();
test_translate();
test_scale();
test_transform();
test_isinvertible();