ReactOS  0.4.12-dev-75-g00dd17e
bezier.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for bezier.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define BEZIERSHIFTBITS   4
 
#define BEZIERSHIFTUP(x)   ((x)<<BEZIERSHIFTBITS)
 
#define BEZIERPIXEL   BEZIERSHIFTUP(1)
 
#define BEZIERSHIFTDOWN(x)   (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
 
#define BEZIERMAXDEPTH   8
 
#define BEZIER_INITBUFSIZE   (150)
 
#define BEZIERMIDDLE(Mid, P1, P2)
 

Functions

static BOOL BezierCheck (int level, POINT *Points)
 
static void GDI_InternalBezier (POINT *Points, POINT **PtsOut, INT *dwOut, INT *nPtsOut, INT level)
 
POINTGDI_Bezier (const POINT *Points, INT count, INT *nPtsOut)
 

Macro Definition Documentation

◆ BEZIER_INITBUFSIZE

#define BEZIER_INITBUFSIZE   (150)

Definition at line 46 of file bezier.c.

Referenced by GDI_Bezier().

◆ BEZIERMAXDEPTH

#define BEZIERMAXDEPTH   8

Definition at line 42 of file bezier.c.

Referenced by GDI_Bezier().

◆ BEZIERMIDDLE

#define BEZIERMIDDLE (   Mid,
  P1,
  P2 
)
Value:
(Mid).x=((P1).x+(P2).x + 1)/2;\
(Mid).y=((P1).y+(P2).y + 1)/2;
INT INT y
Definition: msvc.h:62
INT x
Definition: msvc.h:62

Definition at line 52 of file bezier.c.

Referenced by GDI_InternalBezier().

◆ BEZIERPIXEL

#define BEZIERPIXEL   BEZIERSHIFTUP(1)

Definition at line 39 of file bezier.c.

Referenced by BezierCheck().

◆ BEZIERSHIFTBITS

#define BEZIERSHIFTBITS   4

Definition at line 37 of file bezier.c.

◆ BEZIERSHIFTDOWN

#define BEZIERSHIFTDOWN (   x)    (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)

Definition at line 40 of file bezier.c.

Referenced by BezierCheck(), and GDI_InternalBezier().

◆ BEZIERSHIFTUP

#define BEZIERSHIFTUP (   x)    ((x)<<BEZIERSHIFTBITS)

Definition at line 38 of file bezier.c.

Referenced by GDI_Bezier().

◆ NDEBUG

#define NDEBUG

Definition at line 8 of file bezier.c.

Function Documentation

◆ BezierCheck()

static BOOL BezierCheck ( int  level,
POINT Points 
)
static

Definition at line 64 of file bezier.c.

Referenced by GDI_InternalBezier().

65 {
66  INT dx, dy;
67  dx=Points[3].x-Points[0].x;
68  dy=Points[3].y-Points[0].y;
69  if(abs(dy)<=abs(dx)){/* shallow line */
70  /* check that control points are between begin and end */
71  if(Points[1].x < Points[0].x){
72  if(Points[1].x < Points[3].x)
73  return FALSE;
74  }else
75  if(Points[1].x > Points[3].x)
76  return FALSE;
77  if(Points[2].x < Points[0].x){
78  if(Points[2].x < Points[3].x)
79  return FALSE;
80  }else
81  if(Points[2].x > Points[3].x)
82  return FALSE;
83  dx=BEZIERSHIFTDOWN(dx);
84  if(!dx) return TRUE;
85  if(abs(Points[1].y-Points[0].y-(dy/dx)*
86  BEZIERSHIFTDOWN(Points[1].x-Points[0].x)) > BEZIERPIXEL ||
87  abs(Points[2].y-Points[0].y-(dy/dx)*
88  BEZIERSHIFTDOWN(Points[2].x-Points[0].x)) > BEZIERPIXEL )
89  return FALSE;
90  else
91  return TRUE;
92  }else{ /* steep line */
93  /* check that control points are between begin and end */
94  if(Points[1].y < Points[0].y){
95  if(Points[1].y < Points[3].y)
96  return FALSE;
97  }else
98  if(Points[1].y > Points[3].y)
99  return FALSE;
100  if(Points[2].y < Points[0].y){
101  if(Points[2].y < Points[3].y)
102  return FALSE;
103  }else
104  if(Points[2].y > Points[3].y)
105  return FALSE;
106  dy=BEZIERSHIFTDOWN(dy);
107  if(!dy) return TRUE;
108  if(abs(Points[1].x-Points[0].x-(dx/dy)*
109  BEZIERSHIFTDOWN(Points[1].y-Points[0].y)) > BEZIERPIXEL ||
110  abs(Points[2].x-Points[0].x-(dx/dy)*
111  BEZIERSHIFTDOWN(Points[2].y-Points[0].y)) > BEZIERPIXEL )
112  return FALSE;
113  else
114  return TRUE;
115  }
116 }
#define abs(i)
Definition: fconv.c:206
#define TRUE
Definition: types.h:120
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
int32_t INT
Definition: typedefs.h:56
INT INT y
Definition: msvc.h:62
#define BEZIERSHIFTDOWN(x)
Definition: bezier.c:40
INT INT dy
Definition: msvc.h:65
INT x
Definition: msvc.h:62
#define BEZIERPIXEL
Definition: bezier.c:39
INT dx
Definition: msvc.h:65

◆ GDI_Bezier()

POINT* GDI_Bezier ( const POINT Points,
INT  count,
INT nPtsOut 
)

Definition at line 189 of file bezier.c.

Referenced by IntGdiPolyBezier(), NtGdiPolyDraw(), PATH_AddFlatBezier(), and PATH_StrokePath().

190 {
191  POINT *out;
192  INT Bezier, dwOut = BEZIER_INITBUFSIZE, i;
193 
194  if (count == 1 || (count - 1) % 3 != 0) {
195  DPRINT1("Invalid no. of points %d\n", count);
196  return NULL;
197  }
198  *nPtsOut = 0;
199 
200  out = ExAllocatePoolWithTag(PagedPool, dwOut * sizeof(POINT), TAG_BEZIER);
201  if (!out) return NULL;
202 
203  for(Bezier = 0; Bezier < (count-1)/3; Bezier++) {
204  POINT ptBuf[4];
205  memcpy(ptBuf, Points + Bezier * 3, sizeof(POINT) * 4);
206  for(i = 0; i < 4; i++) {
207  ptBuf[i].x = BEZIERSHIFTUP(ptBuf[i].x);
208  ptBuf[i].y = BEZIERSHIFTUP(ptBuf[i].y);
209  }
210  GDI_InternalBezier( ptBuf, &out, &dwOut, nPtsOut, BEZIERMAXDEPTH );
211  }
212  DPRINT("Produced %d points\n", *nPtsOut);
213  return out;
214 }
static void GDI_InternalBezier(POINT *Points, POINT **PtsOut, INT *dwOut, INT *nPtsOut, INT level)
Definition: bezier.c:121
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define BEZIERMAXDEPTH
Definition: bezier.c:42
#define BEZIER_INITBUFSIZE
Definition: bezier.c:46
#define BEZIERSHIFTUP(x)
Definition: bezier.c:38
void Bezier(HDC hdc, POINT p1, POINT p2, POINT p3, POINT p4, COLORREF color, int thickness)
Definition: drawing.cpp:95
int32_t INT
Definition: typedefs.h:56
INT INT y
Definition: msvc.h:62
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define TAG_BEZIER
Definition: tags.h:13
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static FILE * out
Definition: regtests2xml.c:44
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
INT x
Definition: msvc.h:62
#define DPRINT1
Definition: precomp.h:8

◆ GDI_InternalBezier()

static void GDI_InternalBezier ( POINT Points,
POINT **  PtsOut,
INT dwOut,
INT nPtsOut,
INT  level 
)
static
Todo:
FIXME!

Definition at line 121 of file bezier.c.

Referenced by GDI_Bezier().

123 {
124  if(*nPtsOut == *dwOut) {
125  *dwOut *= 2;
126  *PtsOut = ExAllocatePoolWithTag(PagedPool, *dwOut * sizeof(POINT), TAG_BEZIER);
127  if (*PtsOut == NULL)
128  {
130  NT_ASSERT(FALSE);
131  return;
132  }
133  }
134 
135  if(!level || BezierCheck(level, Points)) {
136  if(*nPtsOut == 0) {
137  (*PtsOut)[0].x = BEZIERSHIFTDOWN(Points[0].x);
138  (*PtsOut)[0].y = BEZIERSHIFTDOWN(Points[0].y);
139  *nPtsOut = 1;
140  }
141  (*PtsOut)[*nPtsOut].x = BEZIERSHIFTDOWN(Points[3].x);
142  (*PtsOut)[*nPtsOut].y = BEZIERSHIFTDOWN(Points[3].y);
143  (*nPtsOut) ++;
144  } else {
145  POINT Points2[4]; /* for the second recursive call */
146  Points2[3]=Points[3];
147  BEZIERMIDDLE(Points2[2], Points[2], Points[3]);
148  BEZIERMIDDLE(Points2[0], Points[1], Points[2]);
149  BEZIERMIDDLE(Points2[1],Points2[0],Points2[2]);
150 
151  BEZIERMIDDLE(Points[1], Points[0], Points[1]);
152  BEZIERMIDDLE(Points[2], Points[1], Points2[0]);
153  BEZIERMIDDLE(Points[3], Points[2], Points2[1]);
154 
155  Points2[0]=Points[3];
156 
157  /* do the two halves */
158  GDI_InternalBezier(Points, PtsOut, dwOut, nPtsOut, level-1);
159  GDI_InternalBezier(Points2, PtsOut, dwOut, nPtsOut, level-1);
160  }
161 }
static void GDI_InternalBezier(POINT *Points, POINT **PtsOut, INT *dwOut, INT *nPtsOut, INT level)
Definition: bezier.c:121
GLint level
Definition: gl.h:1546
INT INT y
Definition: msvc.h:62
#define TAG_BEZIER
Definition: tags.h:13
smooth NULL
Definition: ftsmooth.c:416
#define BEZIERSHIFTDOWN(x)
Definition: bezier.c:40
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static BOOL BezierCheck(int level, POINT *Points)
Definition: bezier.c:64
INT x
Definition: msvc.h:62
#define BEZIERMIDDLE(Mid, P1, P2)
Definition: bezier.c:52
#define NT_ASSERT
Definition: rtlfuncs.h:3312