3 #include <reactos/win32k/ntgdityp.h>
4 #include <reactos/win32k/ntgdihdl.h>
10 typedef struct tagFLOAT_POINT
15 /* Rounds a floating point number to integer. The world-to-viewport
16 * transformation process is done in floating point internally. This function
17 * is then used to round these coordinates to integer values.
19 static __inline INT
GDI_ROUND(FLOAT val
)
21 return (int)floor(val
+ 0.5);
25 /* FIXME: Do not use the fpu in kernel on x86, use FLOATOBJ_Xxx api instead
26 * Performs a world-to-viewport transformation on the specified point (which
27 * is in floating point format).
29 static __inline
void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
32 XFORM xformWorld2Vport
;
34 MatrixS2XForm(&xformWorld2Vport
, &dc
->dclevel
.mxWorldToDevice
);
36 /* Perform the transformation */
39 point
->x
= x
* xformWorld2Vport
.eM11
+
40 y
* xformWorld2Vport
.eM21
+
43 point
->y
= x
* xformWorld2Vport
.eM12
+
44 y
* xformWorld2Vport
.eM22
+
48 /* Performs a viewport-to-world transformation on the specified point (which
49 * is in integer format). Returns TRUE if successful, else FALSE.
52 static __inline BOOL
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
54 FLOAT_POINT floatPoint
;
56 /* Perform operation with floating point */
57 floatPoint
.x
=(FLOAT
)point
->x
;
58 floatPoint
.y
=(FLOAT
)point
->y
;
59 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
62 /* Round to integers */
63 point
->x
= GDI_ROUND(floatPoint
.x
);
64 point
->y
= GDI_ROUND(floatPoint
.y
);
69 /* Performs a world-to-viewport transformation on the specified point (which
70 * is in integer format).
72 static __inline
void INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
74 FLOAT_POINT floatPoint
;
76 /* Perform operation with floating point */
77 floatPoint
.x
=(FLOAT
)point
->x
;
78 floatPoint
.y
=(FLOAT
)point
->y
;
79 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
81 /* Round to integers */
82 point
->x
= GDI_ROUND(floatPoint
.x
);
83 point
->y
= GDI_ROUND(floatPoint
.y
);
88 #define MulDiv( x, y, z ) EngMulDiv( x, y, z )
90 #define XDPTOLP(pdcattr,tx) \
91 (MulDiv(((tx)-(pdcattr)->ptlViewportOrg.x), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx) + (pdcattr)->ptlWindowOrg.x)
92 #define YDPTOLP(pdcattr,ty) \
93 (MulDiv(((ty)-(pdcattr)->ptlViewportOrg.y), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy) + (pdcattr)->ptlWindowOrg.y)
94 #define XLPTODP(pdcattr,tx) \
95 (MulDiv(((tx)-(pdcattr)->ptlWindowOrg.x), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx) + (pdcattr)->ptlViewportOrg.x)
96 #define YLPTODP(pdcattr,ty) \
97 (MulDiv(((ty)-(pdcattr)->ptlWindowOrg.y), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy) + (pdcattr)->ptlViewportOrg.y)
99 /* Device <-> logical size conversion */
101 #define XDSTOLS(pdcattr,tx) \
102 MulDiv((tx), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx)
103 #define YDSTOLS(DC_Attr,ty) \
104 MulDiv((ty), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy)
105 #define XLSTODS(pdcattr,tx) \
106 MulDiv((tx), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx)
107 #define YLSTODS(pdcattr,ty) \
108 MulDiv((ty), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy)