|
Blender
V3.3
|
#include "CLG_log.h"#include "MEM_guardedalloc.h"#include "DNA_mask_types.h"#include "DNA_scene_types.h"#include "DNA_vec_types.h"#include "BLI_memarena.h"#include "BLI_scanfill.h"#include "BLI_utildefines.h"#include "BLI_linklist.h"#include "BLI_listbase.h"#include "BLI_math.h"#include "BLI_rect.h"#include "BLI_task.h"#include "BKE_mask.h"#include "BLI_strict_flags.h"Go to the source code of this file.
Classes | |
| struct | MaskRasterLayer |
| struct | MaskRasterSplineInfo |
| struct | MaskRasterHandle |
| struct | MaskRasterizeBufferData |
Macros | |
| #define | USE_SCANFILL_EDGE_WORKAROUND |
| #define | SPLINE_RESOL_CAP_PER_PIXEL 2 |
| #define | SPLINE_RESOL_CAP_MIN 8 |
| #define | SPLINE_RESOL_CAP_MAX 64 |
| #define | BUCKET_PIXELS_PER_CELL 4 |
| #define | SF_EDGE_IS_BOUNDARY 0xff |
| #define | SF_KEYINDEX_TEMP_ID ((unsigned int)-1) |
| #define | TRI_TERMINATOR_ID ((unsigned int)-1) |
| #define | TRI_VERT ((unsigned int)-1) |
| #define | FACE_ASSERT(face, vert_max) |
| #define | CALC_CAP_RESOL |
Typedefs | |
| typedef struct MaskRasterLayer | MaskRasterLayer |
| typedef struct MaskRasterSplineInfo | MaskRasterSplineInfo |
| typedef struct MaskRasterizeBufferData | MaskRasterizeBufferData |
Functions | |
| static void | rotate_point_v2 (float r_p[2], const float p[2], const float cent[2], const float angle, const float asp[2]) |
| BLI_INLINE unsigned int | clampis_uint (const unsigned int v, const unsigned int min, const unsigned int max) |
| static ScanFillVert * | scanfill_vert_add_v2_with_depth (ScanFillContext *sf_ctx, const float co_xy[2], const float co_z) |
| MaskRasterHandle * | BKE_maskrasterize_handle_new (void) |
| void | BKE_maskrasterize_handle_free (MaskRasterHandle *mr_handle) |
| static void | maskrasterize_spline_differentiate_point_outset (float(*diff_feather_points)[2], float(*diff_points)[2], const unsigned int tot_diff_point, const float ofs, const bool do_test) |
| static bool | layer_bucket_isect_test (const MaskRasterLayer *layer, unsigned int face_index, const unsigned int bucket_x, const unsigned int bucket_y, const float bucket_size_x, const float bucket_size_y, const float bucket_max_rad_squared) |
| static void | layer_bucket_init_dummy (MaskRasterLayer *layer) |
| static void | layer_bucket_init (MaskRasterLayer *layer, const float pixel_size) |
| void | BKE_maskrasterize_handle_init (MaskRasterHandle *mr_handle, struct Mask *mask, const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather) |
| static float | maskrasterize_layer_z_depth_quad (const float pt[2], const float v1[3], const float v2[3], const float v3[3], const float v4[3]) |
| static float | maskrasterize_layer_isect (const unsigned int *face, float(*cos)[3], const float dist_orig, const float xy[2]) |
| BLI_INLINE unsigned int | layer_bucket_index_from_xy (MaskRasterLayer *layer, const float xy[2]) |
| static float | layer_bucket_depth_from_xy (MaskRasterLayer *layer, const float xy[2]) |
| float | BKE_maskrasterize_handle_sample (MaskRasterHandle *mr_handle, const float xy[2]) |
| static void | maskrasterize_buffer_cb (void *__restrict userdata, const int y, const TaskParallelTLS *__restrict UNUSED(tls)) |
| void | BKE_maskrasterize_buffer (MaskRasterHandle *mr_handle, const unsigned int width, const unsigned int height, float *buffer) |
| Rasterize a buffer from a single mask (threaded execution). More... | |
Variables | |
| static CLG_LogRef | LOG = {"bke.mask_rasterize"} |
This module exposes a rasterizer that works as a black box - implementation details are confined to this file.
The basic method to access is:
This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability, though it is commented - so shouldn't be so hard to see what's going on.
Implementation:
To rasterize the mask its converted into geometry that use a ray-cast for each pixel lookup.
Initially 'kdopbvh' was used but this ended up being too slow.
To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically.
Other Details:
This is getting a bit complicated with the addition of unfilled splines and end capping - If large changes are needed here we would be better off using an iterable BLI_mempool for triangles and converting to a contiguous array afterwards.
Definition in file mask_rasterize.c.
| #define BUCKET_PIXELS_PER_CELL 4 |
Definition at line 83 of file mask_rasterize.c.
| #define CALC_CAP_RESOL |
| #define FACE_ASSERT | ( | face, | |
| vert_max | |||
| ) |
Definition at line 94 of file mask_rasterize.c.
| #define SF_EDGE_IS_BOUNDARY 0xff |
Definition at line 85 of file mask_rasterize.c.
| #define SF_KEYINDEX_TEMP_ID ((unsigned int)-1) |
Definition at line 86 of file mask_rasterize.c.
| #define SPLINE_RESOL_CAP_MAX 64 |
Definition at line 80 of file mask_rasterize.c.
| #define SPLINE_RESOL_CAP_MIN 8 |
Definition at line 79 of file mask_rasterize.c.
| #define SPLINE_RESOL_CAP_PER_PIXEL 2 |
Definition at line 78 of file mask_rasterize.c.
| #define TRI_TERMINATOR_ID ((unsigned int)-1) |
Definition at line 88 of file mask_rasterize.c.
| #define TRI_VERT ((unsigned int)-1) |
Definition at line 89 of file mask_rasterize.c.
| #define USE_SCANFILL_EDGE_WORKAROUND |
Definition at line 76 of file mask_rasterize.c.
| typedef struct MaskRasterizeBufferData MaskRasterizeBufferData |
| typedef struct MaskRasterLayer MaskRasterLayer |
A single MaskRasterHandle contains multiple MaskRasterLayer's, each MaskRasterLayer does its own lookup which contributes to the final pixel with its own blending mode and the final pixel is blended between these.
| typedef struct MaskRasterSplineInfo MaskRasterSplineInfo |
| void BKE_maskrasterize_buffer | ( | MaskRasterHandle * | mr_handle, |
| const unsigned int | width, | ||
| const unsigned int | height, | ||
| float * | buffer | ||
| ) |
Rasterize a buffer from a single mask (threaded execution).
Definition at line 1457 of file mask_rasterize.c.
References BLI_parallel_range_settings_defaults(), BLI_task_parallel_range(), buffer, data, float(), height, maskrasterize_buffer_cb(), TaskParallelSettings::use_threading, and width.
Referenced by edit_uv_mask_texture(), mask_rasterize(), and seq_render_mask().
| void BKE_maskrasterize_handle_free | ( | MaskRasterHandle * | mr_handle | ) |
Definition at line 218 of file mask_rasterize.c.
References MaskRasterLayer::buckets_face, MaskRasterLayer::buckets_x, MaskRasterLayer::buckets_y, MaskRasterLayer::face_array, MaskRasterLayer::face_coords, MaskRasterHandle::layers, MaskRasterHandle::layers_tot, and MEM_freeN.
Referenced by blender::compositor::MaskOperation::deinit_execution(), edit_uv_mask_texture(), mask_rasterize(), and seq_render_mask().
| void BKE_maskrasterize_handle_init | ( | MaskRasterHandle * | mr_handle, |
| struct Mask * | mask, | ||
| const int | width, | ||
| const int | height, | ||
| const bool | do_aspect_correct, | ||
| const bool | do_mask_aa, | ||
| const bool | do_feather | ||
| ) |
Definition at line 564 of file mask_rasterize.c.
References add_v2_v2v2(), MaskRasterLayer::alpha, MaskLayer::alpha, angle(), BKE_mask_spline_differentiate_with_resolution(), BKE_mask_spline_feather_collapse_inner_loops(), BKE_mask_spline_feather_differentiated_points_with_resolution(), BKE_mask_spline_feather_resolution(), BKE_mask_spline_resolution(), MaskRasterLayer::blend, MaskLayer::blend, MaskRasterLayer::blend_flag, MaskLayer::blend_flag, BLI_assert, BLI_listbase_count(), BLI_memarena_free(), BLI_memarena_new(), BLI_movelisttolist(), BLI_rctf_do_minmax_v(), BLI_rctf_init_minmax(), BLI_rctf_isect(), BLI_rctf_union(), BLI_remlink(), BLI_SCANFILL_ARENA_SIZE, BLI_scanfill_begin_arena(), BLI_scanfill_calc_ex(), BLI_SCANFILL_CALC_HOLES, BLI_SCANFILL_CALC_POLYS, BLI_scanfill_calc_self_isect(), BLI_scanfill_edge_add(), BLI_scanfill_end_arena(), bounds(), MaskRasterLayer::bounds, MaskRasterHandle::bounds, ScanFillEdge::c, CALC_CAP_RESOL, CLAMPIS, ScanFillVert::co, copy_v3_v3(), KDL::cos(), MaskRasterLayer::face_array, FACE_ASSERT, MaskRasterLayer::face_coords, MaskRasterLayer::face_tot, MaskRasterLayer::falloff, MaskLayer::falloff, ScanFillContext::filledgebase, ScanFillContext::fillfacebase, ScanFillContext::fillvertbase, ListBase::first, MaskSpline::flag, MaskLayer::flag, float(), height, MaskRasterSplineInfo::is_cyclic, is_cyclic(), ScanFillVert::keyindex, ListBase::last, layer_bucket_init(), layer_bucket_init_dummy(), MaskRasterHandle::layers, MaskRasterHandle::layers_tot, M_PI, mask(), MASK_HIDE_RENDER, MASK_LAYERFLAG_FILL_DISCRETE, MASK_LAYERFLAG_FILL_OVERLAP, MASK_SPLINE_CYCLIC, MASK_SPLINE_NOFILL, MASK_SPLINE_NOINTERSECT, maskrasterize_spline_differentiate_point_outset(), MAX2, MEM_callocN, MEM_freeN, MEM_mallocN, MEM_reallocN, min_ii(), ScanFillVert::next, ScanFillEdge::next, ScanFillFace::next, MaskSpline::next, MaskLayer::next, NULL, ScanFillContext::poly_nr, rotate_point_v2(), scanfill_vert_add_v2_with_depth(), SF_EDGE_IS_BOUNDARY, SF_KEYINDEX_TEMP_ID, MaskLayer::splines, sub_v2_v2v2(), ScanFillVert::tmp, ScanFillEdge::tmp, TRI_VERT, ScanFillVert::u, ScanFillEdge::v1, ScanFillFace::v1, ScanFillEdge::v2, ScanFillFace::v2, ScanFillFace::v3, MaskRasterSplineInfo::vertex_offset, MaskRasterSplineInfo::vertex_total, MaskRasterSplineInfo::vertex_total_cap_head, MaskRasterSplineInfo::vertex_total_cap_tail, MaskLayer::visibility_flag, void, and width.
Referenced by edit_uv_mask_texture(), blender::compositor::MaskOperation::init_execution(), mask_rasterize(), and seq_render_mask().
| MaskRasterHandle* BKE_maskrasterize_handle_new | ( | void | ) |
Definition at line 209 of file mask_rasterize.c.
References MEM_callocN.
Referenced by edit_uv_mask_texture(), blender::compositor::MaskOperation::init_execution(), mask_rasterize(), and seq_render_mask().
| float BKE_maskrasterize_handle_sample | ( | MaskRasterHandle * | mr_handle, |
| const float | xy[2] | ||
| ) |
Definition at line 1328 of file mask_rasterize.c.
References MaskRasterLayer::alpha, MaskRasterLayer::blend, MaskRasterLayer::blend_flag, BLI_assert, BLI_rctf_isect_pt_v(), MaskRasterLayer::bounds, CLAMP, CLOG_ERROR, fabsf, MaskRasterLayer::falloff, layer_bucket_depth_from_xy(), MaskRasterHandle::layers, MaskRasterHandle::layers_tot, LOG, MASK_BLEND_ADD, MASK_BLEND_DARKEN, MASK_BLEND_DIFFERENCE, MASK_BLEND_LIGHTEN, MASK_BLEND_MERGE_ADD, MASK_BLEND_MERGE_SUBTRACT, MASK_BLEND_MUL, MASK_BLEND_REPLACE, MASK_BLEND_SUBTRACT, MASK_BLENDFLAG_INVERT, max_ff(), min_ff(), PROP_INVSQUARE, PROP_LIN, PROP_ROOT, PROP_SHARP, PROP_SMOOTH, PROP_SPHERE, sqrtf, and xy.
Referenced by blender::compositor::MaskOperation::execute_pixel_sampled(), maskrasterize_buffer_cb(), and blender::compositor::MaskOperation::update_memory_buffer_partial().
| BLI_INLINE unsigned int clampis_uint | ( | const unsigned int | v, |
| const unsigned int | min, | ||
| const unsigned int | max | ||
| ) |
Definition at line 130 of file mask_rasterize.c.
|
static |
Definition at line 1300 of file mask_rasterize.c.
References MaskRasterLayer::buckets_face, KDL::cos(), MaskRasterLayer::face_array, MaskRasterLayer::face_coords, float(), layer_bucket_index_from_xy(), maskrasterize_layer_isect(), TRI_TERMINATOR_ID, and xy.
Referenced by BKE_maskrasterize_handle_sample().
| BLI_INLINE unsigned int layer_bucket_index_from_xy | ( | MaskRasterLayer * | layer, |
| const float | xy[2] | ||
| ) |
Definition at line 1291 of file mask_rasterize.c.
References BLI_assert, BLI_rctf_isect_pt_v(), MaskRasterLayer::bounds, MaskRasterLayer::buckets_x, MaskRasterLayer::buckets_xy_scalar, rctf::xmin, xy, and rctf::ymin.
Referenced by layer_bucket_depth_from_xy().
|
static |
Definition at line 399 of file mask_rasterize.c.
References BLI_assert, BLI_linklist_prepend_arena(), BLI_memarena_free(), BLI_memarena_new(), BLI_rctf_size_x(), BLI_rctf_size_y(), MaskRasterLayer::bounds, BUCKET_PIXELS_PER_CELL, MaskRasterLayer::buckets_face, MaskRasterLayer::buckets_x, MaskRasterLayer::buckets_xy_scalar, MaskRasterLayer::buckets_y, CLAMP, KDL::cos(), MaskRasterLayer::face_array, MaskRasterLayer::face_coords, MaskRasterLayer::face_tot, float(), layer_bucket_isect_test(), LinkNode::link, M_SQRT2, max_ff(), MEM_callocN, MEM_freeN, MEM_mallocN, MEM_SIZE_OPTIMAL, min_ff(), LinkNode::next, NULL, POINTER_AS_UINT, POINTER_FROM_UINT, TRI_TERMINATOR_ID, TRI_VERT, v1, v2, rctf::xmin, and rctf::ymin.
Referenced by BKE_maskrasterize_handle_init().
|
static |
Definition at line 382 of file mask_rasterize.c.
References BLI_rctf_init(), MaskRasterLayer::bounds, MaskRasterLayer::buckets_face, MaskRasterLayer::buckets_x, MaskRasterLayer::buckets_xy_scalar, MaskRasterLayer::buckets_y, MaskRasterLayer::face_array, MaskRasterLayer::face_coords, MaskRasterLayer::face_tot, and NULL.
Referenced by BKE_maskrasterize_handle_init().
|
static |
Definition at line 322 of file mask_rasterize.c.
References MaskRasterLayer::bounds, KDL::cos(), dist_squared_to_line_segment_v2(), MaskRasterLayer::face_array, MaskRasterLayer::face_coords, float(), isect_point_tri_v2(), TRI_VERT, v1, v2, rctf::xmin, and rctf::ymin.
Referenced by layer_bucket_init().
|
static |
Definition at line 1434 of file mask_rasterize.c.
References BKE_maskrasterize_handle_sample(), buffer, data, float(), width, x, xy, and y.
Referenced by BKE_maskrasterize_buffer().
|
static |
Definition at line 1232 of file mask_rasterize.c.
References KDL::cos(), isect_point_tri_v2(), isect_point_tri_v2_cw(), maskrasterize_layer_z_depth_quad(), TRI_VERT, and xy.
Referenced by layer_bucket_depth_from_xy().
|
static |
Definition at line 1223 of file mask_rasterize.c.
References barycentric_weights_v2_quad(), v1, v2, and w().
Referenced by maskrasterize_layer_isect().
|
static |
Definition at line 251 of file mask_rasterize.c.
References add_v2_v2v2(), copy_v2_v2(), len_squared_v2v2(), normalize_v2(), and sub_v2_v2v2().
Referenced by BKE_maskrasterize_handle_init().
|
static |
Definition at line 110 of file mask_rasterize.c.
References angle(), Freestyle::c, cosf, and sinf.
Referenced by BKE_maskrasterize_handle_init().
|
static |
Definition at line 137 of file mask_rasterize.c.
References BLI_scanfill_vert_add().
Referenced by BKE_maskrasterize_handle_init().
|
static |
Definition at line 108 of file mask_rasterize.c.
Referenced by BKE_maskrasterize_handle_sample().