42 const int sign_x = (
x2 > x1) ? 1 : -1;
43 const int sign_y = (y2 >
y1) ? 1 : -1;
45 const int delta_x = (sign_x == 1) ? (
x2 - x1) : (x1 -
x2);
46 const int delta_y = (sign_y == 1) ? (y2 -
y1) : (
y1 - y2);
48 const int delta_x_step = delta_x * 2;
49 const int delta_y_step = delta_y * 2;
51 if (delta_x >= delta_y) {
53 int error = delta_y_step - delta_x;
57 if (
error || (sign_x == 1)) {
59 error -= delta_x_step;
66 error += delta_y_step;
75 int error = delta_x_step - delta_y;
79 if (
error || (sign_y == 1)) {
81 error -= delta_y_step;
88 error += delta_x_step;
120 #define ORDERED_SWAP(ty, a, b) \
126 #define ORDERED_SWAP_BY(ty, a, b, by) \
127 if ((a by) > (b by)) { \
132 #define ORDER_VARS2(ty, a, b) \
134 ORDERED_SWAP(ty, a, b); \
138 #define ORDER_VARS3_BY(ty, a, b, c, by) \
140 ORDERED_SWAP_BY(ty, b, c, by); \
141 ORDERED_SWAP_BY(ty, a, c, by); \
142 ORDERED_SWAP_BY(ty, a, b, by); \
148 return ((
float)(
a[0] -
b[0]) / (
float)(
a[1] -
b[1]));
160 const float inv_slope1,
161 const float inv_slope2,
162 void (*
callback)(
int x,
int x_end,
int y,
void *),
165 float cur_x1 = (
float)p[0];
166 float cur_x2 = cur_x1;
168 const int min_y = p[1];
169 const int max_y_end = max_y + 1;
170 for (
int scanline_y = min_y; scanline_y != max_y_end; scanline_y += 1) {
172 cur_x1 += inv_slope1;
173 cur_x2 += inv_slope2;
186 const float inv_slope1,
187 const float inv_slope2,
188 void (*
callback)(
int x,
int x_end,
int y,
void *),
191 float cur_x1 = (
float)p[0];
192 float cur_x2 = cur_x1;
194 const int max_y = p[1];
195 const int min_y_end = min_y - 1;
196 for (
int scanline_y = max_y; scanline_y != min_y_end; scanline_y -= 1) {
198 cur_x1 -= inv_slope1;
199 cur_x2 -= inv_slope2;
208 void (*
callback)(
int x,
int x_end,
int y,
void *),
217 if (p2[1] == p3[1]) {
224 else if (p1[1] == p2[1]) {
239 const float inv_slope_p21 =
inv_slope(p2, p1);
240 const float inv_slope_p31 =
inv_slope(p3, p1);
241 const float inv_slope_p32 =
inv_slope(p3, p2);
243 float inv_slope1_max, inv_slope2_max;
244 float inv_slope2_min, inv_slope1_min;
246 if (inv_slope_p21 < inv_slope_p31) {
247 inv_slope1_max = inv_slope_p21;
248 inv_slope2_max = inv_slope_p31;
249 inv_slope2_min = inv_slope_p31;
250 inv_slope1_min = inv_slope_p32;
253 inv_slope1_max = inv_slope_p31;
254 inv_slope2_max = inv_slope_p21;
255 inv_slope2_min = inv_slope_p32;
256 inv_slope1_min = inv_slope_p31;
270 #undef ORDERED_SWAP_BY
272 #undef ORDER_VARS3_BY
283 const int(*
verts)[2] = verts_p;
286 const int *co_a =
verts[
a[0]];
287 const int *co_b =
verts[
b[0]];
289 if (co_a[1] < co_b[1]) {
292 if (co_a[1] > co_b[1]) {
295 if (co_a[0] < co_b[0]) {
298 if (co_a[0] > co_b[0]) {
302 const int *co = co_a;
305 int ord = (((co_b[0] - co[0]) * (co_a[1] - co[1])) - ((co_a[0] - co[0]) * (co_b[1] - co[1])));
319 const int verts[][2],
321 void (*
callback)(
int x,
int x_end,
int y,
void *),
327 int(*span_y)[2] =
MEM_mallocN(
sizeof(*span_y) * (
size_t)verts_len, __func__);
330 for (
int i_curr = 0, i_prev = verts_len - 1; i_curr < verts_len; i_prev = i_curr++) {
331 const int *co_prev =
verts[i_prev];
332 const int *co_curr =
verts[i_curr];
334 if (co_prev[1] != co_curr[1]) {
336 if ((
min_ii(co_prev[1], co_curr[1]) >= ymax) || (
max_ii(co_prev[1], co_curr[1]) < ymin)) {
340 int *s = span_y[span_y_len++];
341 if (co_prev[1] < co_curr[1]) {
358 } *node_x =
MEM_mallocN(
sizeof(*node_x) * (
size_t)(verts_len + 1), __func__);
361 int span_y_index = 0;
362 if (span_y_len != 0 &&
verts[span_y[0][0]][1] < ymin) {
363 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] < ymin)) {
365 if (
verts[span_y[span_y_index][1]][1] >= ymin) {
366 struct NodeX *n = &node_x[node_x_len++];
367 n->span_y_index = span_y_index;
374 for (
int pixel_y = ymin; pixel_y < ymax; pixel_y++) {
375 bool is_sorted =
true;
376 bool do_remove =
false;
378 for (
int i = 0, x_ix_prev = INT_MIN; i < node_x_len; i++) {
379 struct NodeX *n = &node_x[i];
380 const int *s = span_y[n->span_y_index];
381 const int *co_prev =
verts[s[0]];
382 const int *co_curr =
verts[s[1]];
384 BLI_assert(co_prev[1] < pixel_y && co_curr[1] >= pixel_y);
386 const double x = (co_prev[0] - co_curr[0]);
387 const double y = (co_prev[1] - co_curr[1]);
388 const double y_px = (pixel_y - co_curr[1]);
389 const int x_ix = (int)((
double)co_curr[0] + ((y_px /
y) *
x));
392 if (is_sorted && (x_ix_prev > x_ix)) {
395 if (do_remove ==
false && co_curr[1] == pixel_y) {
402 if (is_sorted ==
false) {
404 const int node_x_end = node_x_len - 1;
405 while (i < node_x_end) {
406 if (node_x[i].
x > node_x[i + 1].
x) {
407 SWAP(
struct NodeX, node_x[i], node_x[i + 1]);
419 for (
int i = 0; i < node_x_len; i += 2) {
420 int x_src = node_x[i].x;
421 int x_dst = node_x[i + 1].x;
443 if (do_remove ==
true) {
445 for (
int i_src = 0; i_src < node_x_len; i_src += 1) {
446 const int *s = span_y[node_x[i_src].span_y_index];
447 const int *co =
verts[s[1]];
448 if (co[1] != pixel_y) {
449 if (i_dst != i_src) {
451 node_x[i_dst].span_y_index = node_x[i_src].span_y_index;
460 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] == pixel_y)) {
465 struct NodeX *n = &node_x[node_x_len++];
466 n->span_y_index = span_y_index;
typedef float(TangentPoint)[2]
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
void BLI_qsort_r(void *a, size_t n, size_t es, BLI_sort_cmp_t cmp, void *thunk)
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble y1
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
Read Guarded memory(de)allocation.
void BLI_bitmap_draw_2d_poly_v2i_n(const int xmin, const int ymin, const int xmax, const int ymax, const int verts[][2], const int verts_len, void(*callback)(int x, int x_end, int y, void *), void *user_data)
static int draw_poly_v2i_n__span_y_sort(const void *a_p, const void *b_p, void *verts_p)
static float inv_slope(const int a[2], const int b[2])
void BLI_bitmap_draw_2d_line_v2v2i(const int p1[2], const int p2[2], bool(*callback)(int, int, void *), void *user_data)
void BLI_bitmap_draw_2d_tri_v2i(const int p1[2], const int p2[2], const int p3[2], void(*callback)(int x, int x_end, int y, void *), void *user_data)
static void draw_tri_flat_max(const int p[2], const int max_y, const float inv_slope1, const float inv_slope2, void(*callback)(int x, int x_end, int y, void *), void *user_data)
static void draw_tri_flat_min(const int p[2], const int min_y, const float inv_slope1, const float inv_slope2, void(*callback)(int x, int x_end, int y, void *), void *user_data)
#define ORDER_VARS3_BY(ty, a, b, c, by)
#define ORDER_VARS2(ty, a, b)
DEGForeachIDComponentCallback callback
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
static void error(const char *str)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)