65 const int sign_x = (
x2 > x1) ? 1 : -1;
66 const int sign_y = (y2 >
y1) ? 1 : -1;
68 const int delta_x = (sign_x == 1) ? (
x2 - x1) : (x1 -
x2);
69 const int delta_y = (sign_y == 1) ? (y2 -
y1) : (
y1 - y2);
71 const int delta_x_step = delta_x * 2;
72 const int delta_y_step = delta_y * 2;
74 if (delta_x >= delta_y) {
76 int error = delta_y_step - delta_x;
80 if (
error || (sign_x == 1)) {
82 error -= delta_x_step;
89 error += delta_y_step;
98 int error = delta_x_step - delta_y;
102 if (
error || (sign_y == 1)) {
104 error -= delta_y_step;
111 error += delta_x_step;
143 #define ORDERED_SWAP(ty, a, b) \
149 #define ORDERED_SWAP_BY(ty, a, b, by) \
150 if ((a by) > (b by)) { \
155 #define ORDER_VARS2(ty, a, b) \
157 ORDERED_SWAP(ty, a, b); \
161 #define ORDER_VARS3_BY(ty, a, b, c, by) \
163 ORDERED_SWAP_BY(ty, b, c, by); \
164 ORDERED_SWAP_BY(ty, a, c, by); \
165 ORDERED_SWAP_BY(ty, a, b, by); \
171 return ((
float)(
a[0] - b[0]) / (
float)(
a[1] - b[1]));
183 const float inv_slope1,
184 const float inv_slope2,
185 void (*
callback)(
int x,
int x_end,
int y,
void *),
188 float cur_x1 = (
float)p[0];
189 float cur_x2 = cur_x1;
191 const int min_y = p[1];
192 const int max_y_end = max_y + 1;
193 for (
int scanline_y = min_y; scanline_y != max_y_end; scanline_y += 1) {
195 cur_x1 += inv_slope1;
196 cur_x2 += inv_slope2;
209 const float inv_slope1,
210 const float inv_slope2,
211 void (*
callback)(
int x,
int x_end,
int y,
void *),
214 float cur_x1 = (
float)p[0];
215 float cur_x2 = cur_x1;
217 const int max_y = p[1];
218 const int min_y_end = min_y - 1;
219 for (
int scanline_y = max_y; scanline_y != min_y_end; scanline_y -= 1) {
221 cur_x1 -= inv_slope1;
222 cur_x2 -= inv_slope2;
234 void (*
callback)(
int x,
int x_end,
int y,
void *),
243 if (p2[1] == p3[1]) {
250 else if (p1[1] == p2[1]) {
265 const float inv_slope_p21 =
inv_slope(p2, p1);
266 const float inv_slope_p31 =
inv_slope(p3, p1);
267 const float inv_slope_p32 =
inv_slope(p3, p2);
269 float inv_slope1_max, inv_slope2_max;
270 float inv_slope2_min, inv_slope1_min;
272 if (inv_slope_p21 < inv_slope_p31) {
273 inv_slope1_max = inv_slope_p21;
274 inv_slope2_max = inv_slope_p31;
275 inv_slope2_min = inv_slope_p31;
276 inv_slope1_min = inv_slope_p32;
279 inv_slope1_max = inv_slope_p31;
280 inv_slope2_max = inv_slope_p21;
281 inv_slope2_min = inv_slope_p32;
282 inv_slope1_min = inv_slope_p31;
296 #undef ORDERED_SWAP_BY
298 #undef ORDER_VARS3_BY
309 const int(*
verts)[2] = verts_p;
312 const int *co_a =
verts[
a[0]];
313 const int *co_b =
verts[b[0]];
315 if (co_a[1] < co_b[1]) {
318 if (co_a[1] > co_b[1]) {
321 if (co_a[0] < co_b[0]) {
324 if (co_a[0] > co_b[0]) {
328 const int *co = co_a;
331 int ord = (((co_b[0] - co[0]) * (co_a[1] - co[1])) - ((co_a[0] - co[0]) * (co_b[1] - co[1])));
357 const int verts[][2],
359 void (*
callback)(
int x,
int x_end,
int y,
void *),
365 int(*span_y)[2] =
MEM_mallocN(
sizeof(*span_y) * (
size_t)verts_len, __func__);
368 for (
int i_curr = 0, i_prev = verts_len - 1; i_curr < verts_len; i_prev = i_curr++) {
369 const int *co_prev =
verts[i_prev];
370 const int *co_curr =
verts[i_curr];
372 if (co_prev[1] != co_curr[1]) {
374 if ((
min_ii(co_prev[1], co_curr[1]) >= ymax) || (
max_ii(co_prev[1], co_curr[1]) < ymin)) {
378 int *s = span_y[span_y_len++];
379 if (co_prev[1] < co_curr[1]) {
396 } *node_x =
MEM_mallocN(
sizeof(*node_x) * (
size_t)(verts_len + 1), __func__);
399 int span_y_index = 0;
400 if (span_y_len != 0 &&
verts[span_y[0][0]][1] < ymin) {
401 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] < ymin)) {
403 if (
verts[span_y[span_y_index][1]][1] >= ymin) {
404 struct NodeX *n = &node_x[node_x_len++];
405 n->span_y_index = span_y_index;
412 for (
int pixel_y = ymin; pixel_y < ymax; pixel_y++) {
413 bool is_sorted =
true;
414 bool do_remove =
false;
416 for (
int i = 0, x_ix_prev = INT_MIN; i < node_x_len; i++) {
417 struct NodeX *n = &node_x[i];
418 const int *s = span_y[n->span_y_index];
419 const int *co_prev =
verts[s[0]];
420 const int *co_curr =
verts[s[1]];
422 BLI_assert(co_prev[1] < pixel_y && co_curr[1] >= pixel_y);
424 const double x = (co_prev[0] - co_curr[0]);
425 const double y = (co_prev[1] - co_curr[1]);
426 const double y_px = (pixel_y - co_curr[1]);
427 const int x_ix = (int)((
double)co_curr[0] + ((y_px /
y) *
x));
430 if (is_sorted && (x_ix_prev > x_ix)) {
433 if (do_remove ==
false && co_curr[1] == pixel_y) {
440 if (is_sorted ==
false) {
442 const int node_x_end = node_x_len - 1;
443 while (i < node_x_end) {
444 if (node_x[i].
x > node_x[i + 1].
x) {
445 SWAP(
struct NodeX, node_x[i], node_x[i + 1]);
457 for (
int i = 0; i < node_x_len; i += 2) {
458 int x_src = node_x[i].x;
459 int x_dst = node_x[i + 1].x;
481 if (do_remove ==
true) {
483 for (
int i_src = 0; i_src < node_x_len; i_src += 1) {
484 const int *s = span_y[node_x[i_src].span_y_index];
485 const int *co =
verts[s[1]];
486 if (co[1] != pixel_y) {
487 if (i_dst != i_src) {
489 node_x[i_dst].span_y_index = node_x[i_src].span_y_index;
498 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] == pixel_y)) {
503 struct NodeX *n = &node_x[node_x_len++];
504 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 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
_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
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)