diff options
Diffstat (limited to 'source/blender/blenkernel')
27 files changed, 381 insertions, 504 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 405b052f477..d389b557503 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -87,7 +87,7 @@ void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt); void fcurve_free_driver(struct FCurve *fcu); struct ChannelDriver *fcurve_copy_driver(const struct ChannelDriver *driver); -void driver_variables_copy(struct ListBase *dst_list, const struct ListBase *src_list); +void driver_variables_copy(struct ListBase *dst_vars, const struct ListBase *src_vars); void BKE_driver_target_matrix_to_rot_channels( float mat[4][4], int auto_order, int rotation_mode, int channel, bool angles, float r_buf[4]); @@ -280,7 +280,7 @@ struct FCurve *rna_get_fcurve_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, - struct AnimData **r_adt, + struct AnimData **r_animdata, struct bAction **r_action, bool *r_driven, bool *r_special); diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 65c3725d994..93840db49c9 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -77,6 +77,7 @@ typedef struct Global { * * 799: Enable some mysterious new depsgraph behavior (05/2015). * * 1112: Disable new Cloth internal springs handling (09/2014). * * 1234: Disable new dyntopo code fixing skinny faces generation (04/2015). + * * 3001: Enable additional Fluid modifier (Mantaflow) options (02/2020). * * 16384 and above: Reserved for python (add-ons) usage. */ short debug_value; diff --git a/source/blender/blenkernel/BKE_library_idmap.h b/source/blender/blenkernel/BKE_main_idmap.h index 0285699dea3..d95f32b162a 100644 --- a/source/blender/blenkernel/BKE_library_idmap.h +++ b/source/blender/blenkernel/BKE_main_idmap.h @@ -13,8 +13,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __BKE_LIBRARY_IDMAP_H__ -#define __BKE_LIBRARY_IDMAP_H__ +#ifndef __BKE_MAIN_IDMAP_H__ +#define __BKE_MAIN_IDMAP_H__ /** \file * \ingroup bke @@ -42,4 +42,4 @@ struct ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_typemap, const struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); -#endif /* __BKE_LIBRARY_IDMAP_H__ */ +#endif /* __BKE_MAIN_IDMAP_H__ */ diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 570541eb990..d6934e8a7da 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -91,9 +91,7 @@ struct Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap( float (*vertexCos)[3], const struct Mesh *me_settings); -int poly_find_loop_from_vert(const struct MPoly *poly, - const struct MLoop *loopstart, - unsigned vert); +int poly_find_loop_from_vert(const struct MPoly *poly, const struct MLoop *loopstart, uint vert); int poly_get_adj_loops_from_vert(const struct MPoly *poly, const struct MLoop *mloop, unsigned int vert, diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index b599e1e1b2c..1c479c92ef5 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -387,7 +387,8 @@ struct bNodeTree *ntreeCopyTree(struct Main *bmain, const struct bNodeTree *ntre void ntreeUserIncrefID(struct bNodeTree *ntree); void ntreeUserDecrefID(struct bNodeTree *ntree); -struct bNodeTree *ntreeFromID(const struct ID *id); +struct bNodeTree **BKE_ntree_ptr_from_id(struct ID *id); +struct bNodeTree *ntreeFromID(struct ID *id); struct ID *BKE_node_tree_find_owner_ID(struct Main *bmain, struct bNodeTree *ntree); void ntreeMakeLocal(struct Main *bmain, diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index dd7931cfe0e..b7bb8434613 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -204,10 +204,7 @@ bool paint_is_grid_face_hidden(const unsigned int *grid_hidden, int gridsize, in bool paint_is_bmesh_face_hidden(struct BMFace *f); /* paint masks */ -float paint_grid_paint_mask(const struct GridPaintMask *gpm, - unsigned level, - unsigned x, - unsigned y); +float paint_grid_paint_mask(const struct GridPaintMask *gpm, uint level, uint x, uint y); /* stroke related */ bool paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 0aa4f0fe677..2f839aafa2c 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -136,7 +136,6 @@ set(SRC intern/layer.c intern/layer_utils.c intern/library.c - intern/library_idmap.c intern/library_override.c intern/library_query.c intern/library_remap.c @@ -144,6 +143,7 @@ set(SRC intern/lightprobe.c intern/linestyle.c intern/main.c + intern/main_idmap.c intern/mask.c intern/mask_evaluate.c intern/mask_rasterize.c @@ -299,7 +299,6 @@ set(SRC BKE_lattice.h BKE_layer.h BKE_library.h - BKE_library_idmap.h BKE_library_override.h BKE_library_query.h BKE_library_remap.h @@ -307,6 +306,7 @@ set(SRC BKE_lightprobe.h BKE_linestyle.h BKE_main.h + BKE_main_idmap.h BKE_mask.h BKE_material.h BKE_mball.h diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index a17a09297c5..708d0600e91 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4557,9 +4557,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase MovieTracking *tracking; MovieTrackingTrack *track; MovieTrackingObject *tracking_object; - - Object *camob_eval = DEG_get_evaluated_object(depsgraph, - data->camera ? data->camera : scene->camera); + Object *camob = data->camera ? data->camera : scene->camera; float ctime = DEG_get_ctime(depsgraph); float framenr; @@ -4568,7 +4566,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase clip = scene->clip; } - if (!clip || !data->track[0] || !camob_eval) { + if (!clip || !data->track[0] || !camob) { return; } @@ -4602,7 +4600,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) { float imat[4][4]; - copy_m4_m4(mat, camob_eval->obmat); + copy_m4_m4(mat, camob->obmat); BKE_tracking_camera_get_reconstructed_interpolate( tracking, tracking_object, framenr, imat); @@ -4613,7 +4611,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]); } else { - BKE_tracking_get_camera_object_matrix(cob->scene, camob_eval, mat); + BKE_tracking_get_camera_object_matrix(cob->scene, camob, mat); mul_m4_m4m4(cob->matrix, obmat, mat); translate_m4( @@ -4626,7 +4624,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); float len, d; - BKE_object_where_is_calc_mat4(camob_eval, mat); + BKE_object_where_is_calc_mat4(camob, mat); /* camera axis */ vec[0] = 0.0f; @@ -4694,7 +4692,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase } BKE_camera_params_init(¶ms); - BKE_camera_params_from_object(¶ms, camob_eval); + BKE_camera_params_from_object(¶ms, camob); if (params.is_ortho) { vec[0] = params.ortho_scale * (pos[0] - 0.5f + params.shiftx); @@ -4708,9 +4706,9 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase vec[0] *= aspect; } - mul_v3_m4v3(disp, camob_eval->obmat, vec); + mul_v3_m4v3(disp, camob->obmat, vec); - copy_m4_m4(rmat, camob_eval->obmat); + copy_m4_m4(rmat, camob->obmat); zero_v3(rmat[3]); mul_m4_m4m4(cob->matrix, cob->matrix, rmat); @@ -4730,10 +4728,10 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase vec[0] *= aspect; } - mul_v3_m4v3(disp, camob_eval->obmat, vec); + mul_v3_m4v3(disp, camob->obmat, vec); /* apply camera rotation so Z-axis would be co-linear */ - copy_m4_m4(rmat, camob_eval->obmat); + copy_m4_m4(rmat, camob->obmat); zero_v3(rmat[3]); mul_m4_m4m4(cob->matrix, cob->matrix, rmat); @@ -4751,7 +4749,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase invert_m4_m4(imat, depth_ob->obmat); - mul_v3_m4v3(ray_start, imat, camob_eval->obmat[3]); + mul_v3_m4v3(ray_start, imat, camob->obmat[3]); mul_v3_m4v3(ray_end, imat, cob->matrix[3]); sub_v3_v3v3(ray_nor, ray_end, ray_start); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 833b8409f7d..5708cb0379b 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -204,29 +204,31 @@ FCurve *id_data_find_fcurve( RNA_pointer_create(id, type, data, &ptr); prop = RNA_struct_find_property(&ptr, prop_name); + if (prop == NULL) { + return NULL; + } - if (prop) { - path = RNA_path_from_ID_to_property(&ptr, prop); - - if (path) { - /* animation takes priority over drivers */ - if ((adt->action) && (adt->action->curves.first)) { - fcu = list_find_fcurve(&adt->action->curves, path, index); - } + path = RNA_path_from_ID_to_property(&ptr, prop); + if (path == NULL) { + return NULL; + } - /* if not animated, check if driven */ - if ((fcu == NULL) && (adt->drivers.first)) { - fcu = list_find_fcurve(&adt->drivers, path, index); - if (fcu && r_driven) { - *r_driven = true; - } - fcu = NULL; - } + /* animation takes priority over drivers */ + if (adt->action && adt->action->curves.first) { + fcu = list_find_fcurve(&adt->action->curves, path, index); + } - MEM_freeN(path); + /* if not animated, check if driven */ + if (fcu == NULL && adt->drivers.first) { + fcu = list_find_fcurve(&adt->drivers, path, index); + if (fcu && r_driven) { + *r_driven = true; } + fcu = NULL; } + MEM_freeN(path); + return fcu; } @@ -309,26 +311,28 @@ int list_find_data_fcurves(ListBase *dst, /* search each F-Curve one by one */ for (fcu = src->first; fcu; fcu = fcu->next) { /* check if quoted string matches the path */ - if ((fcu->rna_path) && strstr(fcu->rna_path, dataPrefix)) { - char *quotedName = BLI_str_quoted_substrN(fcu->rna_path, dataPrefix); + if (fcu->rna_path == NULL || !strstr(fcu->rna_path, dataPrefix)) { + continue; + } - if (quotedName) { - /* check if the quoted name matches the required name */ - if (STREQ(quotedName, dataName)) { - LinkData *ld = MEM_callocN(sizeof(LinkData), __func__); + char *quotedName = BLI_str_quoted_substrN(fcu->rna_path, dataPrefix); + if (quotedName == NULL) { + continue; + } - ld->data = fcu; - BLI_addtail(dst, ld); + /* check if the quoted name matches the required name */ + if (STREQ(quotedName, dataName)) { + LinkData *ld = MEM_callocN(sizeof(LinkData), __func__); - matches++; - } + ld->data = fcu; + BLI_addtail(dst, ld); - /* always free the quoted string, since it needs freeing */ - MEM_freeN(quotedName); - } + matches++; } - } + /* always free the quoted string, since it needs freeing */ + MEM_freeN(quotedName); + } /* return the number of matches */ return matches; } @@ -397,53 +401,58 @@ FCurve *rna_get_fcurve_context_ui(bContext *C, /* Standard F-Curve - Animation (Action) or Drivers */ while (adt && step--) { - if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) { - /* XXX this function call can become a performance bottleneck */ - if (step) { - path = RNA_path_from_ID_to_property(&tptr, prop); - } + if ((adt->action == NULL || adt->action->curves.first == NULL) && + (adt->drivers.first == NULL)) { + continue; + } - // XXX: the logic here is duplicated with a function up above - if (path) { - /* animation takes priority over drivers */ - if (adt->action && adt->action->curves.first) { - fcu = list_find_fcurve(&adt->action->curves, path, rnaindex); + /* XXX this function call can become a performance bottleneck */ + if (step) { + path = RNA_path_from_ID_to_property(&tptr, prop); + } + if (path == NULL) { + continue; + } - if (fcu && r_action) { - *r_action = adt->action; - } - } + // XXX: the logic here is duplicated with a function up above + /* animation takes priority over drivers */ + if (adt->action && adt->action->curves.first) { + fcu = list_find_fcurve(&adt->action->curves, path, rnaindex); - /* if not animated, check if driven */ - if (!fcu && (adt->drivers.first)) { - fcu = list_find_fcurve(&adt->drivers, path, rnaindex); + if (fcu && r_action) { + *r_action = adt->action; + } + } - if (fcu) { - if (r_animdata) { - *r_animdata = adt; - } - *r_driven = true; - } - } + /* if not animated, check if driven */ + if (!fcu && (adt->drivers.first)) { + fcu = list_find_fcurve(&adt->drivers, path, rnaindex); - if (fcu && r_action) { - if (r_animdata) { - *r_animdata = adt; - } - *r_action = adt->action; - break; - } - else if (step) { - char *tpath = BKE_animdata_driver_path_hack(C, &tptr, prop, path); - if (tpath && tpath != path) { - MEM_freeN(path); - path = tpath; - adt = BKE_animdata_from_id(tptr.owner_id); - } - else { - adt = NULL; - } + if (fcu) { + if (r_animdata) { + *r_animdata = adt; } + *r_driven = true; + } + } + + if (fcu && r_action) { + if (r_animdata) { + *r_animdata = adt; + } + *r_action = adt->action; + break; + } + + if (step) { + char *tpath = BKE_animdata_driver_path_hack(C, &tptr, prop, path); + if (tpath && tpath != path) { + MEM_freeN(path); + path = tpath; + adt = BKE_animdata_from_id(tptr.owner_id); + } + else { + adt = NULL; } } } @@ -476,29 +485,28 @@ static int binarysearch_bezt_index_ex( CLOG_WARN(&LOG, "encountered invalid array"); return 0; } - else { - /* check whether to add before/after/on */ - float framenum; - /* 'First' Keyframe (when only one keyframe, this case is used) */ - framenum = array[0].vec[1][0]; - if (IS_EQT(frame, framenum, threshold)) { - *r_replace = true; - return 0; - } - else if (frame < framenum) { - return 0; - } + /* check whether to add before/after/on */ + float framenum; - /* 'Last' Keyframe */ - framenum = array[(arraylen - 1)].vec[1][0]; - if (IS_EQT(frame, framenum, threshold)) { - *r_replace = true; - return (arraylen - 1); - } - else if (frame > framenum) { - return arraylen; - } + /* 'First' Keyframe (when only one keyframe, this case is used) */ + framenum = array[0].vec[1][0]; + if (IS_EQT(frame, framenum, threshold)) { + *r_replace = true; + return 0; + } + if (frame < framenum) { + return 0; + } + + /* 'Last' Keyframe */ + framenum = array[(arraylen - 1)].vec[1][0]; + if (IS_EQT(frame, framenum, threshold)) { + *r_replace = true; + return (arraylen - 1); + } + if (frame > framenum) { + return arraylen; } /* most of the time, this loop is just to find where to put it @@ -1171,41 +1179,42 @@ void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_ha */ void sort_time_fcurve(FCurve *fcu) { + if (fcu->bezt == NULL) { + return; + } /* keep adjusting order of beztriples until nothing moves (bubble-sort) */ - if (fcu->bezt) { - BezTriple *bezt; - uint a; - - bool ok = true; - while (ok) { - ok = 0; - /* currently, will only be needed when there are beztriples */ - - /* loop over ALL points to adjust position in array and recalculate handles */ - for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { - /* check if thee's a next beztriple which we could try to swap with current */ - if (a < (fcu->totvert - 1)) { - /* swap if one is after the other (and indicate that order has changed) */ - if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) { - SWAP(BezTriple, *bezt, *(bezt + 1)); - ok = 1; - } + BezTriple *bezt; + uint a; + + bool ok = true; + while (ok) { + ok = 0; + /* currently, will only be needed when there are beztriples */ + + /* loop over ALL points to adjust position in array and recalculate handles */ + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { + /* check if thee's a next beztriple which we could try to swap with current */ + if (a < (fcu->totvert - 1)) { + /* swap if one is after the other (and indicate that order has changed) */ + if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) { + SWAP(BezTriple, *bezt, *(bezt + 1)); + ok = 1; } } } + } - for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { - /* if either one of both of the points exceeds crosses over the keyframe time... */ - if ((bezt->vec[0][0] > bezt->vec[1][0]) && (bezt->vec[2][0] < bezt->vec[1][0])) { - /* swap handles if they have switched sides for some reason */ - swap_v2_v2(bezt->vec[0], bezt->vec[2]); - } - else { - /* clamp handles */ - CLAMP_MAX(bezt->vec[0][0], bezt->vec[1][0]); - CLAMP_MIN(bezt->vec[2][0], bezt->vec[1][0]); - } + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { + /* if either one of both of the points exceeds crosses over the keyframe time... */ + if ((bezt->vec[0][0] > bezt->vec[1][0]) && (bezt->vec[2][0] < bezt->vec[1][0])) { + /* swap handles if they have switched sides for some reason */ + swap_v2_v2(bezt->vec[0], bezt->vec[2]); + } + else { + /* clamp handles */ + CLAMP_MAX(bezt->vec[0][0], bezt->vec[1][0]); + CLAMP_MIN(bezt->vec[2][0], bezt->vec[1][0]); } } } @@ -2539,11 +2548,10 @@ static int findzero(float x, float q0, float q1, float q2, float q3, float *o) if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - else { - return 0; - } + return 0; } - else if (d == 0.0) { + + if (d == 0.0) { t = sqrt3d(-q); o[0] = (float)(2 * t - a); @@ -2555,87 +2563,78 @@ static int findzero(float x, float q0, float q1, float q2, float q3, float *o) if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { return nr + 1; } - else { - return nr; - } + return nr; } - else { - phi = acos(-q / sqrt(-(p * p * p))); - t = sqrt(-p); - p = cos(phi / 3); - q = sqrt(3 - 3 * p * p); - o[0] = (float)(2 * t * p - a); - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - nr++; - } - o[nr] = (float)(-t * (p + q) - a); + phi = acos(-q / sqrt(-(p * p * p))); + t = sqrt(-p); + p = cos(phi / 3); + q = sqrt(3 - 3 * p * p); + o[0] = (float)(2 * t * p - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - nr++; - } - o[nr] = (float)(-t * (p - q) - a); + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { + nr++; + } + o[nr] = (float)(-t * (p + q) - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - return nr + 1; - } - else { - return nr; - } + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + nr++; } - } - else { - a = c2; - b = c1; - c = c0; + o[nr] = (float)(-t * (p - q) - a); - if (a != 0.0) { - /* discriminant */ - p = b * b - 4 * a * c; + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + return nr + 1; + } + return nr; + } + a = c2; + b = c1; + c = c0; - if (p > 0) { - p = sqrt(p); - o[0] = (float)((-b - p) / (2 * a)); + if (a != 0.0) { + /* discriminant */ + p = b * b - 4 * a * c; - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - nr++; - } - o[nr] = (float)((-b + p) / (2 * a)); + if (p > 0) { + p = sqrt(p); + o[0] = (float)((-b - p) / (2 * a)); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - return nr + 1; - } - else { - return nr; - } + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { + nr++; } - else if (p == 0) { - o[0] = (float)(-b / (2 * a)); - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - return 1; - } - else { - return 0; - } + o[nr] = (float)((-b + p) / (2 * a)); + + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + return nr + 1; } + return nr; } - else if (b != 0.0) { - o[0] = (float)(-c / b); + if (p == 0) { + o[0] = (float)(-b / (2 * a)); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - else { - return 0; - } } - else if (c == 0.0) { - o[0] = 0.0; + + return 0; + } + + if (b != 0.0) { + o[0] = (float)(-c / b); + + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - return 0; } + + if (c == 0.0) { + o[0] = 0.0; + return 1; + } + + return 0; } static void berekeny(float f1, float f2, float f3, float f4, float *o, int b) @@ -3244,19 +3243,18 @@ float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, float evaltime) /* only calculate + set curval (overriding the existing value) if curve has * any data which warrants this... */ - if (!BKE_fcurve_is_empty(fcu)) { - /* calculate and set curval (evaluates driver too if necessary) */ - float curval; - if (fcu->driver) { - curval = evaluate_fcurve_driver(anim_rna, fcu, fcu->driver, evaltime); - } - else { - curval = evaluate_fcurve(fcu, evaltime); - } - fcu->curval = curval; /* debug display only, not thread safe! */ - return curval; + if (BKE_fcurve_is_empty(fcu)) { + return 0.0f; + } + + /* calculate and set curval (evaluates driver too if necessary) */ + float curval; + if (fcu->driver) { + curval = evaluate_fcurve_driver(anim_rna, fcu, fcu->driver, evaltime); } else { - return 0.0f; + curval = evaluate_fcurve(fcu, evaltime); } + fcu->curval = curval; /* debug display only, not thread safe! */ + return curval; } diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index f35aebbae16..8b959e30aff 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -3505,10 +3505,14 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, manta_needs_realloc(mds->fluid, mmd)) { BKE_fluid_reallocate_fluid(mds, mds->res, 1); } - has_noise = manta_read_noise(mds->fluid, mmd, noise_frame); + if (!baking_data && !baking_noise && !mode_replay) { + has_data = manta_update_noise_structures(mds->fluid, mmd, noise_frame); + } + else { + has_noise = manta_read_noise(mds->fluid, mmd, noise_frame); + } - /* In case of using the adaptive domain, copy all data that was read to a new fluid object. - */ + /* When using the adaptive domain, copy all data that was read to a new fluid object. */ if (with_adaptive && baking_noise) { /* Adaptive domain needs to know about current state, so save it, then copy. */ copy_v3_v3_int(o_res, mds->res); @@ -3521,7 +3525,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, mds, o_res, mds->res, o_min, mds->res_min, o_max, o_shift, mds->shift); } } - has_data = manta_read_data(mds->fluid, mmd, data_frame); + if (!baking_data && !baking_noise && !mode_replay) { + /* There is no need to call manta_update_smoke_structures() here. + * The noise cache has already been read with manta_update_noise_structures(). */ + } + else { + has_data = manta_read_data(mds->fluid, mmd, data_frame); + } } /* Read data cache only */ else { @@ -3532,7 +3542,12 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, BKE_fluid_reallocate_fluid(mds, mds->res, 1); } /* Read data cache */ - has_data = manta_read_data(mds->fluid, mmd, data_frame); + if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { + has_data = manta_update_smoke_structures(mds->fluid, mmd, data_frame); + } + else { + has_data = manta_read_data(mds->fluid, mmd, data_frame); + } } if (with_liquid) { if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 243c63a8f03..a09e97d4fed 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -783,7 +783,7 @@ void curve_deform_verts(Object *cuOb, if (cu->flag & CU_DEFORM_BOUNDS_OFF) { for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { @@ -800,7 +800,7 @@ void curve_deform_verts(Object *cuOb, INIT_MINMAX(cd.dmin, cd.dmax); for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { mul_m4_v3(cd.curvespace, vert_coords[a]); @@ -809,7 +809,7 @@ void curve_deform_verts(Object *cuOb, } for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { @@ -899,8 +899,9 @@ static void lattice_deform_vert_task(void *__restrict userdata, const LatticeDeformUserdata *data = userdata; if (data->dvert != NULL) { - const float weight = data->invert_vgroup? 1.0f - defvert_find_weight(data->dvert + index, data->defgrp_index) : - defvert_find_weight(data->dvert + index, data->defgrp_index); + const float weight = data->invert_vgroup ? + 1.0f - defvert_find_weight(data->dvert + index, data->defgrp_index) : + defvert_find_weight(data->dvert + index, data->defgrp_index); if (weight > 0.0f) { calc_latt_deform(data->lattice_deform_data, data->vert_coords[index], weight * data->fac); } diff --git a/source/blender/blenkernel/intern/library_idmap.c b/source/blender/blenkernel/intern/main_idmap.c index ab0ff5b0096..a210961b212 100644 --- a/source/blender/blenkernel/intern/library_idmap.c +++ b/source/blender/blenkernel/intern/main_idmap.c @@ -26,8 +26,8 @@ #include "DNA_ID.h" #include "BKE_idcode.h" -#include "BKE_library_idmap.h" /* own include */ #include "BKE_main.h" +#include "BKE_main_idmap.h" /* own include */ /** \file * \ingroup bke diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index f4f93fcb698..cb8b3b5ecc9 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -198,7 +198,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, float (*BKE_mask_spline_differentiate( MaskSpline *spline, int width, int height, unsigned int *tot_diff_point))[2] { - int unsigned resol = BKE_mask_spline_resolution(spline, width, height); + uint resol = BKE_mask_spline_resolution(spline, width, height); return BKE_mask_spline_differentiate_with_resolution(spline, tot_diff_point, resol); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 3835e405630..098da997d8f 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1200,7 +1200,7 @@ void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth) * Find the index of the loop in 'poly' which references vertex, * returns -1 if not found */ -int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, unsigned vert) +int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, uint vert) { int j; for (j = 0; j < poly->totloop; j++, loopstart++) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 75e0d044c7c..94c06e46cb9 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2242,27 +2242,37 @@ void ntreeSetOutput(bNodeTree *ntree) * might be different for editor or for "real" use... */ } -/* Returns the private NodeTree object of the datablock, if it has one. */ -bNodeTree *ntreeFromID(const ID *id) +/** Get address of potential nodetree pointer of given ID. + * + * \warning Using this function directly is potentially dangerous, if you don't know or are not + * sure, please use `ntreeFromID()` instead. */ +bNodeTree **BKE_ntree_ptr_from_id(ID *id) { switch (GS(id->name)) { case ID_MA: - return ((const Material *)id)->nodetree; + return &((Material *)id)->nodetree; case ID_LA: - return ((const Light *)id)->nodetree; + return &((Light *)id)->nodetree; case ID_WO: - return ((const World *)id)->nodetree; + return &((World *)id)->nodetree; case ID_TE: - return ((const Tex *)id)->nodetree; + return &((Tex *)id)->nodetree; case ID_SCE: - return ((const Scene *)id)->nodetree; + return &((Scene *)id)->nodetree; case ID_LS: - return ((const FreestyleLineStyle *)id)->nodetree; + return &((FreestyleLineStyle *)id)->nodetree; default: return NULL; } } +/* Returns the private NodeTree object of the datablock, if it has one. */ +bNodeTree *ntreeFromID(ID *id) +{ + bNodeTree **nodetree = BKE_ntree_ptr_from_id(id); + return (nodetree != NULL) ? *nodetree : NULL; +} + /* Finds and returns the datablock that privately owns the given tree, or NULL. */ ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree) { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5e30c7c5e96..42e4921795c 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -1065,7 +1065,7 @@ bool paint_is_face_hidden(const MLoopTri *lt, const MVert *mvert, const MLoop *m /* returns non-zero if any of the corners of the grid * face whose inner corner is at (x, y) are hidden, * zero otherwise */ -bool paint_is_grid_face_hidden(const unsigned int *grid_hidden, int gridsize, int x, int y) +bool paint_is_grid_face_hidden(const uint *grid_hidden, int gridsize, int x, int y) { /* skip face if any of its corners are hidden */ return (BLI_BITMAP_TEST(grid_hidden, y * gridsize + x) || @@ -1090,7 +1090,7 @@ bool paint_is_bmesh_face_hidden(BMFace *f) return false; } -float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level, unsigned x, unsigned y) +float paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y) { int factor = BKE_ccg_factor(level, gpm->level); int gridsize = BKE_ccg_gridsize(gpm->level); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 7a352f8c9f8..d68c7a947ae 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3638,12 +3638,14 @@ void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob } } - /* clear modifier */ + /* Clear modifier, skip empty ones. */ psmd = psys_get_modifier(ob, psys); - BLI_remlink(&ob->modifiers, psmd); - modifier_free((ModifierData *)psmd); + if (psmd) { + BLI_remlink(&ob->modifiers, psmd); + modifier_free((ModifierData *)psmd); + } - /* clear particle system */ + /* Clear particle system. */ BLI_remlink(&ob->particlesystem, psys); if (psys->part) { id_us_min(&psys->part->id); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index ec520e188f1..141e93183fb 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1410,7 +1410,7 @@ void BKE_pbvh_get_grid_updates(PBVH *bvh, bool clear, void ***r_gridfaces, int * while ((node = pbvh_iter_next(&iter))) { if (node->flag & PBVH_UpdateNormals) { - for (unsigned i = 0; i < node->totprim; i++) { + for (uint i = 0; i < node->totprim; i++) { void *face = bvh->gridfaces[node->prim_indices[i]]; BLI_gset_add(face_set, face); } diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c index 9008348ed3b..4a69fcfa9d0 100644 --- a/source/blender/blenkernel/intern/studiolight.c +++ b/source/blender/blenkernel/intern/studiolight.c @@ -56,17 +56,6 @@ static int last_studiolight_id = 0; #define STUDIOLIGHT_IRRADIANCE_EQUIRECT_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT * 2) #define STUDIOLIGHT_PASSNAME_DIFFUSE "diffuse" #define STUDIOLIGHT_PASSNAME_SPECULAR "specular" -/* - * The method to calculate the irradiance buffers - * The irradiance buffer is only shown in the background when in LookDev. - * - * STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE is very slow, but very accurate - * STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS is faster but has artifacts - * Cannot have both enabled at the same time!!! - */ -// #define STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE -#define STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS - /* Temporarily disabled due to the creation of textures with -nan(ind)s */ #define STUDIOLIGHT_SH_WINDOWING 0.0f /* 0.0 is disabled */ @@ -1024,40 +1013,6 @@ BLI_INLINE void studiolight_evaluate_specular_radiance_buffer(ImBuf *radiance_bu madd_v3_v3fl(color, accum, 1.0f / accum_weight); } -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE -static void studiolight_irradiance_eval(StudioLight *sl, float color[3], const float normal[3]) -{ - copy_v3_fl(color, 0.0f); - - /* XXX: This is madness, iterating over all cubemap pixels for each destination pixels - * even if their weight is 0.0f. - * It should use hemisphere, cosine sampling at least. */ - - /* back */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Y_POS], normal, color, 0, 2, 1, 1); - /* front */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Y_NEG], normal, color, 0, 2, 1, -1); - - /* left */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_X_POS], normal, color, 1, 2, 0, 1); - /* right */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_X_NEG], normal, color, 1, 2, 0, -1); - - /* top */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Z_POS], normal, color, 0, 1, 2, 1); - /* bottom */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Z_NEG], normal, color, 0, 1, 2, -1); - - mul_v3_fl(color, 1.0 / M_PI); -} -#endif - static float brdf_approx(float spec_color, float roughness, float NV) { /* Very rough own approx. We don't need it to be correct, just fast. @@ -1185,11 +1140,7 @@ static bool studiolight_load_spherical_harmonics_coefficients(StudioLight *sl) static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) { if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) { -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED); -#else BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED); -#endif float *colbuf = MEM_mallocN(STUDIOLIGHT_IRRADIANCE_EQUIRECT_WIDTH * STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT * sizeof(float[4]), @@ -1202,11 +1153,7 @@ static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT) { float dir[3]; equirect_to_direction(dir, x, y); -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - studiolight_irradiance_eval(sl, pixel, dir); -#else studiolight_spherical_harmonics_eval(sl, pixel, dir); -#endif pixel[3] = 1.0f; } ITER_PIXELS_END; @@ -1217,15 +1164,6 @@ static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT, 4); MEM_freeN(colbuf); - -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - /* - * Only store cached files when using STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - */ - if (sl->flag & STUDIOLIGHT_USER_DEFINED) { - IMB_saveiff(sl->equirect_irradiance_buffer, sl->path_irr_cache, IB_rectfloat); - } -#endif } sl->flag |= STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED; } diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 1e7b3af53d5..86fb2ab58bc 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -80,9 +80,7 @@ static struct { /* Free the whole list of tracks, list's head and tail are set to NULL. */ static void tracking_tracks_free(ListBase *tracks) { - MovieTrackingTrack *track; - - for (track = tracks->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { BKE_tracking_track_free(track); } @@ -92,9 +90,7 @@ static void tracking_tracks_free(ListBase *tracks) /* Free the whole list of plane tracks, list's head and tail are set to NULL. */ static void tracking_plane_tracks_free(ListBase *plane_tracks) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks) { BKE_tracking_plane_track_free(plane_track); } @@ -128,10 +124,8 @@ static void tracking_object_free(MovieTrackingObject *object) /* Free list of tracking objects, list's head and tail is set to NULL. */ static void tracking_objects_free(ListBase *objects) { - MovieTrackingObject *object; - /* Free objects contents. */ - for (object = objects->first; object; object = object->next) { + LISTBASE_FOREACH (MovieTrackingObject *, object, objects) { tracking_object_free(object); } @@ -191,13 +185,11 @@ static void tracking_tracks_copy(ListBase *tracks_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingTrack *track_dst, *track_src; - BLI_listbase_clear(tracks_dst); BLI_ghash_clear(tracks_mapping, NULL, NULL); - for (track_src = tracks_src->first; track_src != NULL; track_src = track_src->next) { - track_dst = MEM_dupallocN(track_src); + LISTBASE_FOREACH (MovieTrackingTrack *, track_src, tracks_src) { + MovieTrackingTrack *track_dst = MEM_dupallocN(track_src); if (track_src->markers) { track_dst->markers = MEM_dupallocN(track_src->markers); } @@ -217,13 +209,10 @@ static void tracking_plane_tracks_copy(ListBase *plane_tracks_list_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingPlaneTrack *plane_track_dst, *plane_track_src; - BLI_listbase_clear(plane_tracks_list_dst); - for (plane_track_src = plane_tracks_list_src->first; plane_track_src != NULL; - plane_track_src = plane_track_src->next) { - plane_track_dst = MEM_dupallocN(plane_track_src); + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track_src, plane_tracks_list_src) { + MovieTrackingPlaneTrack *plane_track_dst = MEM_dupallocN(plane_track_src); if (plane_track_src->markers) { plane_track_dst->markers = MEM_dupallocN(plane_track_src->markers); } @@ -278,12 +267,10 @@ static void tracking_objects_copy(ListBase *objects_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingObject *object_dst, *object_src; - BLI_listbase_clear(objects_dst); - for (object_src = objects_src->first; object_src != NULL; object_src = object_src->next) { - object_dst = MEM_mallocN(sizeof(*object_dst), __func__); + LISTBASE_FOREACH (MovieTrackingObject *, object_src, objects_src) { + MovieTrackingObject *object_dst = MEM_mallocN(sizeof(*object_dst), __func__); tracking_object_copy(object_dst, object_src, tracks_mapping, flag); BLI_addtail(objects_dst, object_dst); } @@ -844,7 +831,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking, MovieTrackingMarker *marker_a, *marker_b; int start_a = a, start_b = b, len = 0, frame = src_track->markers[a].framenr; - int j, inverse = 0; + int inverse = 0; inverse = (b == 0) || (dst_track->markers[b - 1].flag & MARKER_DISABLED) || (dst_track->markers[b - 1].framenr != frame - 1); @@ -872,7 +859,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking, b = start_b; /* linear interpolation for intersecting frames */ - for (j = 0; j < len; j++) { + for (int j = 0; j < len; j++) { float fac = 0.5f; if (len > 1) { @@ -1180,9 +1167,7 @@ void BKE_tracking_track_deselect(MovieTrackingTrack *track, int area) void BKE_tracking_tracks_deselect_all(ListBase *tracksbase) { - MovieTrackingTrack *track; - - for (track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if ((track->flag & TRACK_HIDDEN) == 0) { BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); } @@ -1269,13 +1254,12 @@ void BKE_tracking_marker_delete(MovieTrackingTrack *track, int framenr) void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) { - int a; float pat_min[2], pat_max[2]; BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); if (event == CLAMP_PAT_DIM) { - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]); marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]); @@ -1286,23 +1270,22 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) sub_v2_v2v2(dim, pat_max, pat_min); - for (a = 0; a < 2; a++) { - int b; + for (int a = 0; a < 2; a++) { /* pattern shouldn't be moved outside of search */ if (pat_min[a] < marker->search_min[a]) { - for (b = 0; b < 4; b++) { + for (int b = 0; b < 4; b++) { marker->pattern_corners[b][a] += marker->search_min[a] - pat_min[a]; } } if (pat_max[a] > marker->search_max[a]) { - for (b = 0; b < 4; b++) { + for (int b = 0; b < 4; b++) { marker->pattern_corners[b][a] -= pat_max[a] - marker->search_max[a]; } } } } else if (event == CLAMP_SEARCH_DIM) { - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]); marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]); @@ -1313,7 +1296,7 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) sub_v2_v2v2(dim, marker->search_max, marker->search_min); - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be moved inside pattern */ if (marker->search_min[a] > pat_min[a]) { marker->search_min[a] = pat_min[a]; @@ -1457,15 +1440,14 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking, { MovieTrackingPlaneTrack *plane_track; MovieTrackingPlaneMarker plane_marker; - MovieTrackingTrack *track; float tracks_min[2], tracks_max[2]; - int track_index, num_selected_tracks = 0; + int num_selected_tracks = 0; (void)tracking; /* Ignored. */ /* Use bounding box of selected markers as an initial size of plane. */ INIT_MINMAX2(tracks_min, tracks_max); - for (track = tracks->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { if (TRACK_SELECTED(track)) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); float pattern_min[2], pattern_max[2]; @@ -1493,7 +1475,8 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking, /* Use selected tracks from given list as a plane. */ plane_track->point_tracks = MEM_mallocN(sizeof(MovieTrackingTrack *) * num_selected_tracks, "new plane tracks array"); - for (track = tracks->first, track_index = 0; track; track = track->next) { + int track_index = 0; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { if (TRACK_SELECTED(track)) { plane_track->point_tracks[track_index] = track; track_index++; @@ -1552,9 +1535,8 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(MovieTracking *track const char *name) { ListBase *plane_tracks_base = BKE_tracking_object_get_plane_tracks(tracking, object); - MovieTrackingPlaneTrack *plane_track; - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (STREQ(plane_track->name, name)) { return plane_track; } @@ -1565,13 +1547,11 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(MovieTracking *track MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTracking *tracking) { - ListBase *plane_tracks_base; - if (tracking->act_plane_track == NULL) { return NULL; } - plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); + ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); /* Check that active track is in current plane tracks list */ if (BLI_findindex(plane_tracks_base, tracking->act_plane_track) != -1) { @@ -1583,9 +1563,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTrackin void BKE_tracking_plane_tracks_deselect_all(ListBase *plane_tracks_base) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { plane_track->flag &= ~SELECT; } } @@ -1593,8 +1571,7 @@ void BKE_tracking_plane_tracks_deselect_all(ListBase *plane_tracks_base) bool BKE_tracking_plane_track_has_point_track(MovieTrackingPlaneTrack *plane_track, MovieTrackingTrack *track) { - int i; - for (i = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] == track) { return true; } @@ -1605,17 +1582,14 @@ bool BKE_tracking_plane_track_has_point_track(MovieTrackingPlaneTrack *plane_tra bool BKE_tracking_plane_track_remove_point_track(MovieTrackingPlaneTrack *plane_track, MovieTrackingTrack *track) { - int i, track_index; - MovieTrackingTrack **new_point_tracks; - if (plane_track->point_tracksnr <= 4) { return false; } - new_point_tracks = MEM_mallocN(sizeof(*new_point_tracks) * (plane_track->point_tracksnr - 1), - "new point tracks array"); + MovieTrackingTrack **new_point_tracks = MEM_mallocN( + sizeof(*new_point_tracks) * (plane_track->point_tracksnr - 1), "new point tracks array"); - for (i = 0, track_index = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0, track_index = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] != track) { new_point_tracks[track_index++] = plane_track->point_tracks[i]; } @@ -1631,10 +1605,8 @@ bool BKE_tracking_plane_track_remove_point_track(MovieTrackingPlaneTrack *plane_ void BKE_tracking_plane_tracks_remove_point_track(MovieTracking *tracking, MovieTrackingTrack *track) { - MovieTrackingPlaneTrack *plane_track, *next_plane_track; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); - for (plane_track = plane_tracks_base->first; plane_track; plane_track = next_plane_track) { - next_plane_track = plane_track->next; + LISTBASE_FOREACH_MUTABLE (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (BKE_tracking_plane_track_has_point_track(plane_track, track)) { if (!BKE_tracking_plane_track_remove_point_track(plane_track, track)) { /* Delete planes with less than 3 point tracks in it. */ @@ -1649,8 +1621,7 @@ void BKE_tracking_plane_track_replace_point_track(MovieTrackingPlaneTrack *plane MovieTrackingTrack *old_track, MovieTrackingTrack *new_track) { - int i; - for (i = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] == old_track) { plane_track->point_tracks[i] = new_track; break; @@ -1662,9 +1633,8 @@ void BKE_tracking_plane_tracks_replace_point_track(MovieTracking *tracking, MovieTrackingTrack *old_track, MovieTrackingTrack *new_track) { - MovieTrackingPlaneTrack *plane_track; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (BKE_tracking_plane_track_has_point_track(plane_track, old_track)) { BKE_tracking_plane_track_replace_point_track(plane_track, old_track, new_track); } @@ -1838,23 +1808,22 @@ void BKE_tracking_plane_marker_get_subframe_corners(MovieTrackingPlaneTrack *pla { MovieTrackingPlaneMarker *marker = BKE_tracking_plane_marker_get(plane_track, (int)framenr); MovieTrackingPlaneMarker *marker_last = plane_track->markers + (plane_track->markersnr - 1); - int i; if (marker != marker_last) { MovieTrackingPlaneMarker *marker_next = marker + 1; if (marker_next->framenr == marker->framenr + 1) { float fac = (framenr - (int)framenr) / (marker_next->framenr - marker->framenr); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { interp_v2_v2v2(corners[i], marker->corners[i], marker_next->corners[i], fac); } } else { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { copy_v2_v2(corners[i], marker->corners[i]); } } } else { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { copy_v2_v2(corners[i], marker->corners[i]); } } @@ -2399,7 +2368,6 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, bool undistort, float delta[2]) { - int a; float pos[2], warped_pos[2]; const int coord_delta = 5; void (*apply_distortion)(MovieTracking * tracking, const float pos[2], float out[2]); @@ -2413,7 +2381,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, delta[0] = delta[1] = -FLT_MAX; - for (a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) { + for (int a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) { if (a > rect->xmax) { a = rect->xmax; } @@ -2441,7 +2409,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, } } - for (a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) { + for (int a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) { if (a > rect->ymax) { a = rect->ymax; } @@ -2515,9 +2483,7 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, * fractional part of offset */ if (from_anchor) { - int a; - - for (a = 0; a < 5; a++) { + for (int a = 0; a < 5; a++) { src_pixel_x[a] += (double)((track->offset[0] * frame_width) - ((int)(track->offset[0] * frame_width))); src_pixel_y[a] += (double)((track->offset[1] * frame_height) - @@ -2664,9 +2630,6 @@ ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, void BKE_tracking_disable_channels( ImBuf *ibuf, bool disable_red, bool disable_green, bool disable_blue, bool grayscale) { - int x, y; - float scale; - if (!disable_red && !disable_green && !disable_blue && !grayscale) { return; } @@ -2674,11 +2637,11 @@ void BKE_tracking_disable_channels( /* if only some components are selected, it's important to rescale the result * appropriately so that e.g. if only blue is selected, it's not zeroed out. */ - scale = (disable_red ? 0.0f : 0.2126f) + (disable_green ? 0.0f : 0.7152f) + - (disable_blue ? 0.0f : 0.0722f); + float scale = (disable_red ? 0.0f : 0.2126f) + (disable_green ? 0.0f : 0.7152f) + + (disable_blue ? 0.0f : 0.0722f); - for (y = 0; y < ibuf->y; y++) { - for (x = 0; x < ibuf->x; x++) { + for (int y = 0; y < ibuf->y; y++) { + for (int x = 0; x < ibuf->x; x++) { int pixel = ibuf->x * y + x; if (ibuf->rect_float) { @@ -2916,7 +2879,6 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) { MovieTrackingObject *object = BKE_tracking_object_get_active(tracking); MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; - MovieTrackingTrack *track; MovieTrackingReconstruction *reconstruction = BKE_tracking_object_get_reconstruction(tracking, object); ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); @@ -2924,9 +2886,7 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) bool sel_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0; bool show_hidden = (dopesheet->flag & TRACKING_DOPE_SHOW_HIDDEN) != 0; - for (track = tracksbase->first; track; track = track->next) { - MovieTrackingDopesheetChannel *channel; - + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!show_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; } @@ -2935,7 +2895,8 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) continue; } - channel = MEM_callocN(sizeof(MovieTrackingDopesheetChannel), "tracking dopesheet channel"); + MovieTrackingDopesheetChannel *channel = MEM_callocN(sizeof(MovieTrackingDopesheetChannel), + "tracking dopesheet channel"); channel->track = track; if (reconstruction->flag & TRACKING_RECONSTRUCTED) { @@ -3012,13 +2973,12 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; MovieTrackingObject *object = BKE_tracking_object_get_active(tracking); ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); - MovieTrackingTrack *track; int frames, start_frame = INT_MAX, end_frame = -INT_MAX; int *per_frame_counter; int prev_coverage, last_segment_frame; /* find frame boundaries */ - for (track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { start_frame = min_ii(start_frame, track->markers[0].framenr); end_frame = max_ii(end_frame, track->markers[track->markersnr - 1].framenr); } @@ -3029,7 +2989,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) per_frame_counter = MEM_callocN(sizeof(int) * frames, "per frame track counter"); /* find per-frame markers count */ - for (track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c index fad928c12fe..9d8395defcd 100644 --- a/source/blender/blenkernel/intern/tracking_auto.c +++ b/source/blender/blenkernel/intern/tracking_auto.c @@ -127,13 +127,12 @@ static void dna_marker_to_libmv_marker(/*const*/ MovieTrackingTrack *track, libmv_Marker *libmv_marker) { const int frame_dimensions[2] = {frame_width, frame_height}; - int i; libmv_marker->clip = clip; libmv_marker->frame = marker->framenr; libmv_marker->track = track_index; normalized_to_libmv_frame(marker->pos, frame_dimensions, libmv_marker->center); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { normalized_relative_to_libmv_frame( marker->pattern_corners[i], marker->pos, frame_dimensions, libmv_marker->patch[i]); } @@ -183,11 +182,10 @@ static void libmv_marker_to_dna_marker(libmv_Marker *libmv_marker, MovieTrackingMarker *marker) { const int frame_dimensions[2] = {frame_width, frame_height}; - int i; marker->framenr = libmv_marker->frame; libmv_frame_to_normalized(libmv_marker->center, frame_dimensions, marker->pos); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { libmv_frame_to_normalized_relative(libmv_marker->patch[i], libmv_marker->center, frame_dimensions, @@ -260,7 +258,7 @@ static void fill_autotrack_tracks(const int frame_width, { /* Count number of markers to be put to a context. */ size_t num_trackable_markers = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { const MovieTrackingMarker *marker = track->markers + i; if ((marker->flag & MARKER_DISABLED) == 0) { @@ -277,7 +275,7 @@ static void fill_autotrack_tracks(const int frame_width, "libmv markers array"); /* Fill in markers array. */ int track_index = 0, num_filled_libmv_markers = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = track->markers + i; if ((marker->flag & MARKER_DISABLED) != 0) { @@ -307,7 +305,7 @@ static void create_per_track_tracking_options(const MovieClip *clip, AutoTrackContext *context) { /* Count number of trackable tracks. */ - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (check_track_trackable(clip, track, user)) { context->num_tracks++; } @@ -317,7 +315,7 @@ static void create_per_track_tracking_options(const MovieClip *clip, "auto track options"); /* Fill in all the settings. */ int i = 0, track_index = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!check_track_trackable(clip, track, user)) { track_index++; continue; @@ -461,17 +459,16 @@ bool BKE_autotrack_context_step(AutoTrackContext *context) void BKE_autotrack_context_sync(AutoTrackContext *context) { int newframe, frame_delta = context->backwards ? -1 : 1; - int frame; BLI_spin_lock(&context->spin_lock); newframe = context->user.framenr; - for (frame = context->sync_frame; frame != (context->backwards ? newframe - 1 : newframe + 1); + for (int frame = context->sync_frame; + frame != (context->backwards ? newframe - 1 : newframe + 1); frame += frame_delta) { MovieTrackingMarker marker; libmv_Marker libmv_marker; int clip = 0; - int track; - for (track = 0; track < context->num_tracks; track++) { + for (int track = 0; track < context->num_tracks; track++) { AutoTrackOptions *options = &context->options[track]; int track_frame = BKE_movieclip_remap_scene_to_clip_frame( context->clips[options->clip_index], frame); @@ -522,17 +519,13 @@ void BKE_autotrack_context_sync_user(AutoTrackContext *context, MovieClipUser *u void BKE_autotrack_context_finish(AutoTrackContext *context) { - int clip_index; - - for (clip_index = 0; clip_index < context->num_clips; clip_index++) { + for (int clip_index = 0; clip_index < context->num_clips; clip_index++) { MovieClip *clip = context->clips[clip_index]; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking); - MovieTrackingPlaneTrack *plane_track; - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) { - int track; - for (track = 0; track < context->num_tracks; track++) { + for (int track = 0; track < context->num_tracks; track++) { if (BKE_tracking_plane_track_has_point_track(plane_track, context->options[track].track)) { BKE_tracking_track_plane_from_existing_motion(plane_track, context->first_frame); diff --git a/source/blender/blenkernel/intern/tracking_detect.c b/source/blender/blenkernel/intern/tracking_detect.c index ec044f14fa8..08719161e1a 100644 --- a/source/blender/blenkernel/intern/tracking_detect.c +++ b/source/blender/blenkernel/intern/tracking_detect.c @@ -38,7 +38,6 @@ /* Check whether point is inside grease pencil stroke. */ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) { - int i, prev; int count = 0; bGPDspoint *points = stroke->points; @@ -50,9 +49,7 @@ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) * work, but such situation is crappy anyway. */ - prev = stroke->totpoints - 1; - - for (i = 0; i < stroke->totpoints; i++) { + for (int i = 0, prev = stroke->totpoints - 1; i < stroke->totpoints; prev = i, i++) { if ((points[i].y < y && points[prev].y >= y) || (points[prev].y < y && points[i].y >= y)) { float fac = (y - points[i].y) / (points[prev].y - points[i].y); @@ -60,8 +57,6 @@ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) count++; } } - - prev = i; } return (count % 2) ? true : false; diff --git a/source/blender/blenkernel/intern/tracking_plane_tracker.c b/source/blender/blenkernel/intern/tracking_plane_tracker.c index 602243a7d50..e0e8a68bb1e 100644 --- a/source/blender/blenkernel/intern/tracking_plane_tracker.c +++ b/source/blender/blenkernel/intern/tracking_plane_tracker.c @@ -39,13 +39,13 @@ typedef double Vec2[2]; static int point_markers_correspondences_on_both_image( MovieTrackingPlaneTrack *plane_track, int frame1, int frame2, Vec2 **x1_r, Vec2 **x2_r) { - int i, correspondence_index; Vec2 *x1, *x2; *x1_r = x1 = MEM_mallocN(sizeof(*x1) * plane_track->point_tracksnr, "point correspondences x1"); *x2_r = x2 = MEM_mallocN(sizeof(*x1) * plane_track->point_tracksnr, "point correspondences x2"); - for (i = 0, correspondence_index = 0; i < plane_track->point_tracksnr; i++) { + int correspondence_index = 0; + for (int i = 0; i < plane_track->point_tracksnr; i++) { MovieTrackingTrack *point_track = plane_track->point_tracks[i]; MovieTrackingMarker *point_marker1, *point_marker2; @@ -77,11 +77,11 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac start_frame); MovieTrackingPlaneMarker *keyframe_plane_marker = NULL; MovieTrackingPlaneMarker new_plane_marker; - int current_frame, frame_delta = direction > 0 ? 1 : -1; + int frame_delta = direction > 0 ? 1 : -1; if (plane_track->flag & PLANE_TRACK_AUTOKEY) { /* Find a keyframe in given direction. */ - for (current_frame = start_frame;; current_frame += frame_delta) { + for (int current_frame = start_frame;; current_frame += frame_delta) { MovieTrackingPlaneMarker *next_plane_marker = BKE_tracking_plane_marker_get_exact( plane_track, current_frame + frame_delta); @@ -102,11 +102,10 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac new_plane_marker = *start_plane_marker; new_plane_marker.flag |= PLANE_MARKER_TRACKED; - for (current_frame = start_frame;; current_frame += frame_delta) { + for (int current_frame = start_frame;; current_frame += frame_delta) { MovieTrackingPlaneMarker *next_plane_marker = BKE_tracking_plane_marker_get_exact( plane_track, current_frame + frame_delta); Vec2 *x1, *x2; - int i, num_correspondences; double H_double[3][3]; float H[3][3]; @@ -118,13 +117,11 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac } } - num_correspondences = point_markers_correspondences_on_both_image( + const int num_correspondences = point_markers_correspondences_on_both_image( plane_track, current_frame, current_frame + frame_delta, &x1, &x2); - if (num_correspondences < 4) { MEM_freeN(x1); MEM_freeN(x2); - break; } @@ -132,7 +129,7 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac copy_m3_m3d(H, H_double); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { float vec[3] = {0.0f, 0.0f, 1.0f}, vec2[3]; copy_v2_v2(vec, new_plane_marker.corners[i]); @@ -155,7 +152,7 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac fac = 3 * fac * fac - 2 * fac * fac * fac; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { interp_v2_v2v2(new_plane_marker.corners[i], new_plane_marker.corners[i], next_plane_marker->corners[i], diff --git a/source/blender/blenkernel/intern/tracking_region_tracker.c b/source/blender/blenkernel/intern/tracking_region_tracker.c index 1d6bb88c3f4..967642c03a8 100644 --- a/source/blender/blenkernel/intern/tracking_region_tracker.c +++ b/source/blender/blenkernel/intern/tracking_region_tracker.c @@ -50,9 +50,7 @@ static void float_rgba_to_gray(const float *rgba, float weight_green, float weight_blue) { - int i; - - for (i = 0; i < num_pixels; i++) { + for (int i = 0; i < num_pixels; i++) { const float *pixel = rgba + 4 * i; gray[i] = weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2]; @@ -66,9 +64,7 @@ static void uint8_rgba_to_float_gray(const unsigned char *rgba, float weight_green, float weight_blue) { - int i; - - for (i = 0; i < num_pixels; i++) { + for (int i = 0; i < num_pixels; i++) { const unsigned char *pixel = rgba + i * 4; gray[i] = (weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2]) / 255.0f; diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index ab741eed410..527a2f59491 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -90,13 +90,10 @@ static struct libmv_Tracks *libmv_tracks_new(MovieClip *clip, track = tracksbase->first; while (track) { - FCurve *weight_fcurve; - int a = 0; - - weight_fcurve = id_data_find_fcurve( + FCurve *weight_fcurve = id_data_find_fcurve( &clip->id, track, &RNA_MovieTrackingTrack, "weight", 0, NULL); - for (a = 0; a < track->markersnr; a++) { + for (int a = 0; a < track->markersnr; a++) { MovieTrackingMarker *marker = &track->markers[a]; if ((marker->flag & MARKER_DISABLED) == 0) { @@ -149,7 +146,7 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context, MovieReconstructedCamera *reconstructed; MovieTrackingTrack *track; ListBase *tracksbase = NULL; - int tracknr = 0, a; + int tracknr = 0; bool ok = true; bool origin_set = false; int sfra = context->sfra, efra = context->efra; @@ -200,16 +197,16 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context, reconstructed = MEM_callocN((efra - sfra + 1) * sizeof(MovieReconstructedCamera), "temp reconstructed camera"); - for (a = sfra; a <= efra; a++) { + for (int a = sfra; a <= efra; a++) { double matd[4][4]; if (libmv_reprojectionCameraForImage(libmv_reconstruction, a, matd)) { - int i, j; float mat[4][4]; float error = libmv_reprojectionErrorForImage(libmv_reconstruction, a); - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { + /* TODO(sergey): Use transpose utility. */ + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { mat[i][j] = matd[i][j]; } } @@ -591,21 +588,19 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, MovieTrackingReconstruction *reconstruction, const float scale[3]) { - MovieTrackingTrack *track; - int i; float first_camera_delta[3] = {0.0f, 0.0f, 0.0f}; if (reconstruction->camnr > 0) { mul_v3_v3v3(first_camera_delta, reconstruction->cameras[0].mat[3], scale); } - for (i = 0; i < reconstruction->camnr; i++) { + for (int i = 0; i < reconstruction->camnr; i++) { MovieReconstructedCamera *camera = &reconstruction->cameras[i]; mul_v3_v3(camera->mat[3], scale); sub_v3_v3(camera->mat[3], first_camera_delta); } - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { if (track->flag & TRACK_HAS_BUNDLE) { mul_v3_v3(track->bundle_pos, scale); sub_v3_v3(track->bundle_pos, first_camera_delta); @@ -618,14 +613,10 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, */ void BKE_tracking_reconstruction_scale(MovieTracking *tracking, float scale[3]) { - MovieTrackingObject *object; - - for (object = tracking->objects.first; object; object = object->next) { - ListBase *tracksbase; - MovieTrackingReconstruction *reconstruction; - - tracksbase = BKE_tracking_object_get_tracks(tracking, object); - reconstruction = BKE_tracking_object_get_reconstruction(tracking, object); + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); + MovieTrackingReconstruction *reconstruction = BKE_tracking_object_get_reconstruction(tracking, + object); tracking_scale_reconstruction(tracksbase, reconstruction, scale); } diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index 2c270f10908..b5b33353ed7 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -34,6 +34,7 @@ #include "BLI_sort_utils.h" #include "BLI_ghash.h" #include "BLI_math_vector.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_task.h" @@ -332,8 +333,7 @@ static void find_next_working_frames(StabContext *ctx, int *next_lower, int *next_higher) { - for (MovieTrackingTrack *track = ctx->tracking->tracks.first; track != NULL; - track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &ctx->tracking->tracks) { if (is_usable_for_stabilization(ctx, track)) { int startpoint = search_closest_marker_index(track, framenr); retrieve_next_higher_usable_frame(ctx, track, startpoint, framenr, next_higher); @@ -545,7 +545,6 @@ static bool average_track_contributions(StabContext *ctx, { bool ok; float weight_sum; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; MovieTrackingStabilization *stab = &tracking->stabilization; float ref_pos[2]; @@ -559,7 +558,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -597,7 +596,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -652,12 +651,11 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ { bool ok = false; float weight_sum; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; zero_v2(r_ref_pos); weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (track->flag & TRACK_USE_2D_STAB) { float weight = 0.0f; MovieTrackingMarker *marker = get_tracking_data_point(ctx, track, framenr, &weight); @@ -680,7 +678,7 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ int next_lower = MINAFRAME; int next_higher = MAXFRAME; use_values_from_fcurves(ctx, true); - for (track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { /* Note: we deliberately do not care if this track * is already initialized for stabilization. */ if (track->flag & TRACK_USE_2D_STAB) { @@ -771,11 +769,10 @@ static bool interpolate_averaged_track_contributions(StabContext *ctx, static int establish_track_initialization_order(StabContext *ctx, TrackInitOrder *order) { size_t tracknr = 0; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; int anchor_frame = tracking->stabilization.anchor_frame; - for (track = tracking->tracks.first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { MovieTrackingMarker *marker; order[tracknr].data = track; marker = get_closest_marker(ctx, track, anchor_frame); @@ -880,10 +877,9 @@ static void initialize_track_for_stabilization(StabContext *ctx, static void initialize_all_tracks(StabContext *ctx, float aspect) { - size_t i, track_len = 0; + size_t track_len = 0; MovieClip *clip = ctx->clip; MovieTracking *tracking = ctx->tracking; - MovieTrackingTrack *track; TrackInitOrder *order; /* Attempt to start initialization at anchor_frame. @@ -896,7 +892,7 @@ static void initialize_all_tracks(StabContext *ctx, float aspect) zero_v2(pivot); /* Initialize private working data. */ - for (track = tracking->tracks.first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { TrackStabilizationBase *local_data = access_stabilization_baseline_data(ctx, track); if (!local_data) { local_data = MEM_callocN(sizeof(TrackStabilizationBase), @@ -927,8 +923,8 @@ static void initialize_all_tracks(StabContext *ctx, float aspect) average_marker_positions(ctx, reference_frame, average_pos); setup_pivot(average_pos, pivot); - for (i = 0; i < track_len; i++) { - track = order[i].data; + for (int i = 0; i < track_len; i++) { + MovieTrackingTrack *track = order[i].data; if (reference_frame != order[i].reference_frame) { reference_frame = order[i].reference_frame; average_track_contributions(ctx, @@ -1142,12 +1138,11 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect float pixel_aspect = ctx->tracking->camera.pixel_aspect; int height = size, width = aspect * size; - int sfra = INT_MAX, efra = INT_MIN, cfra; + int sfra = INT_MAX, efra = INT_MIN; float scale = 1.0f, scale_step = 0.0f; - MovieTrackingTrack *track; /* Calculate maximal frame range of tracks where stabilization is active. */ - for (track = ctx->tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &ctx->tracking->tracks) { if ((track->flag & TRACK_USE_2D_STAB) || ((stab->flag & TRACKING_STABILIZE_ROTATION) && (track->flag & TRACK_USE_2D_STAB_ROT))) { int first_frame = track->markers[0].framenr; @@ -1158,7 +1153,7 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect } use_values_from_fcurves(ctx, true); - for (cfra = sfra; cfra <= efra; cfra++) { + for (int cfra = sfra; cfra <= efra; cfra++) { float translation[2], pivot[2], angle, tmp_scale; float mat[4][4]; const float points[4][2] = {{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; diff --git a/source/blender/blenkernel/intern/tracking_util.c b/source/blender/blenkernel/intern/tracking_util.c index ed582dc5b94..ada6ce96d58 100644 --- a/source/blender/blenkernel/intern/tracking_util.c +++ b/source/blender/blenkernel/intern/tracking_util.c @@ -126,7 +126,6 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) MovieTrackingTrack *track; ListBase tracks = {NULL, NULL}, new_tracks = {NULL, NULL}; ListBase *old_tracks; - int a; if (map->is_camera) { old_tracks = &tracking->tracks; @@ -146,7 +145,7 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) * this is needed to keep names in unique state and it's faster to change names * of currently operating tracks (if needed) */ - for (a = 0; a < map->num_tracks; a++) { + for (int a = 0; a < map->num_tracks; a++) { MovieTrackingTrack *old_track; bool mapped_to_old = false; @@ -221,11 +220,9 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) void tracks_map_free(TracksMap *map, void (*customdata_free)(void *customdata)) { - int i = 0; - BLI_ghash_free(map->hash, NULL, NULL); - for (i = 0; i < map->num_tracks; i++) { + for (int i = 0; i < map->num_tracks; i++) { if (map->customdata && customdata_free) { customdata_free(&map->customdata[i * map->customdata_size]); } @@ -345,12 +342,11 @@ void tracking_get_marker_coords_for_tracking(int frame_width, double search_pixel_x[5], double search_pixel_y[5]) { - int i; float unified_coords[2]; float pixel_coords[2]; /* Convert the corners into search space coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { marker_unified_to_search_pixel( frame_width, frame_height, marker, marker->pattern_corners[i], pixel_coords); search_pixel_x[i] = pixel_coords[0] - 0.5f; @@ -373,12 +369,11 @@ void tracking_set_marker_coords_from_tracking(int frame_width, const double search_pixel_x[5], const double search_pixel_y[5]) { - int i; float marker_unified[2]; float search_pixel[2]; /* Convert the corners into search space coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { search_pixel[0] = search_pixel_x[i] + 0.5; search_pixel[1] = search_pixel_y[i] + 0.5; search_pixel_to_marker_unified( @@ -394,7 +389,7 @@ void tracking_set_marker_coords_from_tracking(int frame_width, * Otherwise, the entire patch shifted, and that delta should be applied to * all the coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { marker->pattern_corners[i][0] -= marker_unified[0]; marker->pattern_corners[i][1] -= marker_unified[1]; } @@ -672,8 +667,6 @@ static ImBuf *accessor_get_preprocessed_ibuf(TrackingImageAccessor *accessor, static ImBuf *make_grayscale_ibuf_copy(ImBuf *ibuf) { ImBuf *grayscale = IMB_allocImBuf(ibuf->x, ibuf->y, 32, 0); - size_t size; - int i; BLI_assert(ibuf->channels == 3 || ibuf->channels == 4); @@ -682,13 +675,13 @@ static ImBuf *make_grayscale_ibuf_copy(ImBuf *ibuf) * * Will generalize it later. */ - size = (size_t)grayscale->x * (size_t)grayscale->y * sizeof(float); + const size_t size = (size_t)grayscale->x * (size_t)grayscale->y * sizeof(float); grayscale->channels = 1; if ((grayscale->rect_float = MEM_mapallocN(size, "tracking grayscale image")) != NULL) { grayscale->mall |= IB_rectfloat; grayscale->flags |= IB_rectfloat; - for (i = 0; i < grayscale->x * grayscale->y; i++) { + for (int i = 0; i < grayscale->x * grayscale->y; i++) { const float *pixel = ibuf->rect_float + ibuf->channels * i; grayscale->rect_float[i] = 0.2126f * pixel[0] + 0.7152f * pixel[1] + 0.0722f * pixel[2]; @@ -785,14 +778,12 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor, clamped_height); } else { - int y; /* TODO(sergey): We don't do any color space or alpha conversion * here. Probably Libmv is better to work in the linear space, * but keep sRGB space here for compatibility for now. */ - for (y = 0; y < clamped_height; y++) { - int x; - for (x = 0; x < clamped_width; x++) { + for (int y = 0; y < clamped_height; y++) { + for (int x = 0; x < clamped_width; x++) { int src_x = x + clamped_origin_x, src_y = y + clamped_origin_y; int dst_x = x + dst_offset_x, dst_y = y + dst_offset_y; int dst_index = (dst_y * width + dst_x) * 4, |