5 #pragma warning(disable:28110) // disable "Drivers must protect floating point hardware state" warning
8 typedef struct tagFLOAT_POINT
13 /* Rounds a floating point number to integer. The world-to-viewport
14 * transformation process is done in floating point internally. This function
15 * is then used to round these coordinates to integer values.
17 static __inline INT
GDI_ROUND(FLOAT val
)
19 return (int)floor(val
+ 0.5);
23 /* FIXME: Do not use the fpu in kernel on x86, use FLOATOBJ_Xxx api instead
24 * Performs a world-to-viewport transformation on the specified point (which
25 * is in floating point format).
27 static __inline
void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
30 XFORM xformWorld2Vport
;
32 MatrixS2XForm(&xformWorld2Vport
, &dc
->pdcattr
->mxWorldToDevice
);
34 /* Perform the transformation */
37 point
->x
= x
* xformWorld2Vport
.eM11
+
38 y
* xformWorld2Vport
.eM21
+
41 point
->y
= x
* xformWorld2Vport
.eM12
+
42 y
* xformWorld2Vport
.eM22
+
46 /* Performs a viewport-to-world transformation on the specified point (which
47 * is in integer format). Returns TRUE if successful, else FALSE.
50 static __inline BOOL
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
52 FLOAT_POINT floatPoint
;
54 /* Perform operation with floating point */
55 floatPoint
.x
=(FLOAT
)point
->x
;
56 floatPoint
.y
=(FLOAT
)point
->y
;
57 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
60 /* Round to integers */
61 point
->x
= GDI_ROUND(floatPoint
.x
);
62 point
->y
= GDI_ROUND(floatPoint
.y
);
67 /* Performs a world-to-viewport transformation on the specified point (which
68 * is in integer format).
70 static __inline
void INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
72 FLOAT_POINT floatPoint
;
74 /* Perform operation with floating point */
75 floatPoint
.x
=(FLOAT
)point
->x
;
76 floatPoint
.y
=(FLOAT
)point
->y
;
77 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
79 /* Round to integers */
80 point
->x
= GDI_ROUND(floatPoint
.x
);
81 point
->y
= GDI_ROUND(floatPoint
.y
);
86 #define MulDiv( x, y, z ) EngMulDiv( x, y, z )
88 #define XDPTOLP(pdcattr,tx) \
89 (MulDiv(((tx)-(pdcattr)->ptlViewportOrg.x), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx) + (pdcattr)->ptlWindowOrg.x)
90 #define YDPTOLP(pdcattr,ty) \
91 (MulDiv(((ty)-(pdcattr)->ptlViewportOrg.y), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy) + (pdcattr)->ptlWindowOrg.y)
92 #define XLPTODP(pdcattr,tx) \
93 (MulDiv(((tx)-(pdcattr)->ptlWindowOrg.x), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx) + (pdcattr)->ptlViewportOrg.x)
94 #define YLPTODP(pdcattr,ty) \
95 (MulDiv(((ty)-(pdcattr)->ptlWindowOrg.y), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy) + (pdcattr)->ptlViewportOrg.y)
97 /* Device <-> logical size conversion */
99 #define XDSTOLS(pdcattr,tx) \
100 MulDiv((tx), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx)
101 #define YDSTOLS(DC_Attr,ty) \
102 MulDiv((ty), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy)
103 #define XLSTODS(pdcattr,tx) \
104 MulDiv((tx), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx)
105 #define YLSTODS(pdcattr,ty) \
106 MulDiv((ty), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy)