[WIN32K]
[reactos.git] / reactos / win32ss / gdi / ntgdi / gdifloat.h
1 #pragma once
2
3 typedef struct tagFLOAT_POINT
4 {
5 FLOAT x, y;
6 } FLOAT_POINT;
7
8 /* Rounds a floating point number to integer. The world-to-viewport
9 * transformation process is done in floating point internally. This function
10 * is then used to round these coordinates to integer values.
11 */
12 static __inline INT GDI_ROUND(FLOAT val)
13 {
14 return (int)floor(val + 0.5);
15 }
16
17
18 /* FIXME: Do not use the fpu in kernel on x86, use FLOATOBJ_Xxx api instead
19 * Performs a world-to-viewport transformation on the specified point (which
20 * is in floating point format).
21 */
22 static __inline void INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
23 {
24 FLOAT x, y;
25 XFORM xformWorld2Vport;
26
27 MatrixS2XForm(&xformWorld2Vport, &dc->pdcattr->mxWorldToDevice);
28
29 /* Perform the transformation */
30 x = point->x;
31 y = point->y;
32 point->x = x * xformWorld2Vport.eM11 +
33 y * xformWorld2Vport.eM21 +
34 xformWorld2Vport.eDx;
35
36 point->y = x * xformWorld2Vport.eM12 +
37 y * xformWorld2Vport.eM22 +
38 xformWorld2Vport.eDy;
39 }
40
41 /* Performs a viewport-to-world transformation on the specified point (which
42 * is in integer format). Returns TRUE if successful, else FALSE.
43 */
44 #if 0
45 static __inline BOOL INTERNAL_DPTOLP(DC *dc, LPPOINT point)
46 {
47 FLOAT_POINT floatPoint;
48
49 /* Perform operation with floating point */
50 floatPoint.x=(FLOAT)point->x;
51 floatPoint.y=(FLOAT)point->y;
52 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
53 return FALSE;
54
55 /* Round to integers */
56 point->x = GDI_ROUND(floatPoint.x);
57 point->y = GDI_ROUND(floatPoint.y);
58
59 return TRUE;
60 }
61
62 /* Performs a world-to-viewport transformation on the specified point (which
63 * is in integer format).
64 */
65 static __inline void INTERNAL_LPTODP(DC *dc, LPPOINT point)
66 {
67 FLOAT_POINT floatPoint;
68
69 /* Perform operation with floating point */
70 floatPoint.x=(FLOAT)point->x;
71 floatPoint.y=(FLOAT)point->y;
72 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
73
74 /* Round to integers */
75 point->x = GDI_ROUND(floatPoint.x);
76 point->y = GDI_ROUND(floatPoint.y);
77 }
78
79 #endif
80
81 #define MulDiv( x, y, z ) EngMulDiv( x, y, z )
82
83 #define XDPTOLP(pdcattr,tx) \
84 (MulDiv(((tx)-(pdcattr)->ptlViewportOrg.x), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx) + (pdcattr)->ptlWindowOrg.x)
85 #define YDPTOLP(pdcattr,ty) \
86 (MulDiv(((ty)-(pdcattr)->ptlViewportOrg.y), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy) + (pdcattr)->ptlWindowOrg.y)
87 #define XLPTODP(pdcattr,tx) \
88 (MulDiv(((tx)-(pdcattr)->ptlWindowOrg.x), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx) + (pdcattr)->ptlViewportOrg.x)
89 #define YLPTODP(pdcattr,ty) \
90 (MulDiv(((ty)-(pdcattr)->ptlWindowOrg.y), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy) + (pdcattr)->ptlViewportOrg.y)
91
92 /* Device <-> logical size conversion */
93
94 #define XDSTOLS(pdcattr,tx) \
95 MulDiv((tx), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx)
96 #define YDSTOLS(DC_Attr,ty) \
97 MulDiv((ty), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy)
98 #define XLSTODS(pdcattr,tx) \
99 MulDiv((tx), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx)
100 #define YLSTODS(pdcattr,ty) \
101 MulDiv((ty), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy)