Blender  V3.3
bitmap_draw_2d.c File Reference
#include <limits.h>
#include "MEM_guardedalloc.h"
#include "BLI_bitmap_draw_2d.h"
#include "BLI_math_base.h"
#include "BLI_sort.h"
#include "BLI_utildefines.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Functions

Draw Line
void BLI_bitmap_draw_2d_line_v2v2i (const int p1[2], const int p2[2], bool(*callback)(int, int, void *), void *user_data)
 
Draw Filled Polygon
static int draw_poly_v2i_n__span_y_sort (const void *a_p, const void *b_p, void *verts_p)
 
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)
 

Draw Filled Triangle

#define ORDERED_SWAP(ty, a, b)
 
#define ORDERED_SWAP_BY(ty, a, b, by)
 
#define ORDER_VARS2(ty, a, b)
 
#define ORDER_VARS3_BY(ty, a, b, c, by)
 
static float inv_slope (const int a[2], const int b[2])
 
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)
 
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)
 

Detailed Description

Utility functions for primitive drawing operations.

Definition in file bitmap_draw_2d.c.

Macro Definition Documentation

◆ ORDER_VARS2

#define ORDER_VARS2 (   ty,
  a,
 
)
Value:
{ \
ORDERED_SWAP(ty, a, b); \
} \
((void)0)
SyclQueue void void size_t num_bytes void
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)

Definition at line 132 of file bitmap_draw_2d.c.

◆ ORDER_VARS3_BY

#define ORDER_VARS3_BY (   ty,
  a,
  b,
  c,
  by 
)
Value:
{ \
ORDERED_SWAP_BY(ty, b, c, by); \
ORDERED_SWAP_BY(ty, a, c, by); \
ORDERED_SWAP_BY(ty, a, b, by); \
} \
((void)0)
static unsigned c
Definition: RandGen.cpp:83

Definition at line 138 of file bitmap_draw_2d.c.

◆ ORDERED_SWAP

#define ORDERED_SWAP (   ty,
  a,
 
)
Value:
if (a > b) { \
SWAP(ty, a, b); \
} \
((void)0)

Fill a triangle

Standard algorithm, See: http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html

Changes to the basic implementation:

  • Reuse slope calculation when drawing the second triangle.
  • Don't calculate the 4th point at all for the triangle split.
  • Order line drawing from left to right (minor detail).
  • 1-pixel offsets are applied so adjacent triangles don't overlap.

This is not clipped, a clipped version can be added if needed.

Definition at line 120 of file bitmap_draw_2d.c.

◆ ORDERED_SWAP_BY

#define ORDERED_SWAP_BY (   ty,
  a,
  b,
  by 
)
Value:
if ((a by) > (b by)) { \
SWAP(ty, a, b); \
} \
((void)0)

Definition at line 126 of file bitmap_draw_2d.c.

Function Documentation

◆ BLI_bitmap_draw_2d_line_v2v2i()

void BLI_bitmap_draw_2d_line_v2v2i ( const int  p1[2],
const int  p2[2],
bool(*)(int, int, void *)  callback,
void user_data 
)

Plot a line from p1 to p2 (inclusive).

Note
For clipped line drawing, see: http://stackoverflow.com/a/40902741/432509

Definition at line 26 of file bitmap_draw_2d.c.

References callback, error(), user_data, x2, and y1.

Referenced by ED_view3d_depth_read_cached_seg(), and eyedropper_colorband_sample_segment().

◆ BLI_bitmap_draw_2d_poly_v2i_n()

void BLI_bitmap_draw_2d_poly_v2i_n ( int  xmin,
int  ymin,
int  xmax,
int  ymax,
const int  verts[][2],
int  verts_len,
void(*)(int x, int x_end, int y, void *)  callback,
void user_data 
)

Draws a filled polygon with support for self intersections.

Parameters
callbackTakes the x, y coords and x-span (x_end is not inclusive), note that x_end will always be greater than x, so we can use:
do {
func(x, y);
} while (++x != x_end);
_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

Definition at line 315 of file bitmap_draw_2d.c.

References BLI_assert, BLI_qsort_r(), callback, draw_poly_v2i_n__span_y_sort(), max_ii(), MEM_freeN, MEM_mallocN, min_ii(), SWAP, user_data, verts, x, and y.

Referenced by draw_filled_lasso(), DRW_select_buffer_bitmap_from_poly(), sculpt_gesture_init_from_lasso(), and track_mask_gpencil_layer_rasterize().

◆ BLI_bitmap_draw_2d_tri_v2i()

void BLI_bitmap_draw_2d_tri_v2i ( const int  p1[2],
const int  p2[2],
const int  p3[2],
void(*)(int x, int x_end, int y, void *)  callback,
void user_data 
)
Note
Unclipped (clipped version can be added if needed).

Definition at line 203 of file bitmap_draw_2d.c.

References BLI_assert, callback, draw_tri_flat_max(), draw_tri_flat_min(), inv_slope(), ORDER_VARS2, ORDER_VARS3_BY, and user_data.

◆ draw_poly_v2i_n__span_y_sort()

static int draw_poly_v2i_n__span_y_sort ( const void a_p,
const void b_p,
void verts_p 
)
static

Definition at line 281 of file bitmap_draw_2d.c.

References Freestyle::a, usdtokens::b(), and verts.

Referenced by BLI_bitmap_draw_2d_poly_v2i_n().

◆ draw_tri_flat_max()

static void draw_tri_flat_max ( const int  p[2],
const int  max_y,
const float  inv_slope1,
const float  inv_slope2,
void(*)(int x, int x_end, int y, void *)  callback,
void user_data 
)
static
*---*
\ /
  *

Definition at line 158 of file bitmap_draw_2d.c.

References callback, float(), and user_data.

Referenced by BLI_bitmap_draw_2d_tri_v2i().

◆ draw_tri_flat_min()

static void draw_tri_flat_min ( const int  p[2],
const int  min_y,
const float  inv_slope1,
const float  inv_slope2,
void(*)(int x, int x_end, int y, void *)  callback,
void user_data 
)
static
  *
 / \
*---*

Definition at line 184 of file bitmap_draw_2d.c.

References callback, float(), and user_data.

Referenced by BLI_bitmap_draw_2d_tri_v2i().

◆ inv_slope()

static float inv_slope ( const int  a[2],
const int  b[2] 
)
static

Definition at line 146 of file bitmap_draw_2d.c.

References Freestyle::a, and usdtokens::b().

Referenced by BLI_bitmap_draw_2d_tri_v2i().