cleanup: indentation & redundant casts

also use 'const' bucket rect args
This commit is contained in:
Campbell Barton
2015-02-03 09:18:46 +11:00
parent 5678691fe4
commit 052a021711

View File

@@ -423,7 +423,8 @@ static int project_bucket_offset_safe(const ProjPaintState *ps, const float proj
}
}
static float VecZDepthOrtho(const float pt[2],
static float VecZDepthOrtho(
const float pt[2],
const float v1[3], const float v2[3], const float v3[3],
float w[3])
{
@@ -431,7 +432,8 @@ static float VecZDepthOrtho(const float pt[2],
return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]);
}
static float VecZDepthPersp(const float pt[2],
static float VecZDepthPersp(
const float pt[2],
const float v1[4], const float v2[4], const float v3[4],
float w[3])
{
@@ -543,7 +545,8 @@ static void uvco_to_wrapped_pxco(const float uv[2], int ibuf_x, int ibuf_y, floa
}
/* Set the top-most face color that the screen space coord 'pt' touches (or return 0 if none touch) */
static bool project_paint_PickColor(const ProjPaintState *ps, const float pt[2],
static bool project_paint_PickColor(
const ProjPaintState *ps, const float pt[2],
float *rgba_fp, unsigned char *rgba, const bool interp)
{
float w[3], uv[2];
@@ -638,7 +641,8 @@ static bool project_paint_PickColor(const ProjPaintState *ps, const float pt[2],
* 1 : occluded
* 2 : occluded with w[3] weights set (need to know in some cases) */
static int project_paint_occlude_ptv(const float pt[3],
static int project_paint_occlude_ptv(
const float pt[3],
const float v1[4], const float v2[4], const float v3[4],
float w[3], const bool is_ortho)
{
@@ -670,7 +674,8 @@ static int project_paint_occlude_ptv(const float pt[3],
}
static int project_paint_occlude_ptv_clip(const ProjPaintState *ps, const MFace *mf,
static int project_paint_occlude_ptv_clip(
const ProjPaintState *ps, const MFace *mf,
const float pt[3], const float v1[4], const float v2[4], const float v3[4],
const int side)
{
@@ -700,7 +705,8 @@ static int project_paint_occlude_ptv_clip(const ProjPaintState *ps, const MFace
/* Check if a screenspace location is occluded by any other faces
* check, pixelScreenCo must be in screenspace, its Z-Depth only needs to be used for comparison
* and doesn't need to be correct in relation to X and Y coords (this is the case in perspective view) */
static bool project_bucket_point_occluded(const ProjPaintState *ps, LinkNode *bucketFace,
static bool project_bucket_point_occluded(
const ProjPaintState *ps, LinkNode *bucketFace,
const int orig_face, const float pixelScreenCo[4])
{
MFace *mf;
@@ -913,7 +919,8 @@ static void project_face_winding_init(const ProjPaintState *ps, const int face_i
/* This function returns 1 if this face has a seam along the 2 face-vert indices
* 'orig_i1_fidx' and 'orig_i2_fidx' */
static bool check_seam(const ProjPaintState *ps,
static bool check_seam(
const ProjPaintState *ps,
const int orig_face, const int orig_i1_fidx, const int orig_i2_fidx,
int *other_face, int *orig_fidx)
{
@@ -1004,7 +1011,8 @@ BLI_INLINE float shell_v2v2_normal_dir_to_dist(float n[2], float d[2])
/* Calculate outset UV's, this is not the same as simply scaling the UVs,
* since the outset coords are a margin that keep an even distance from the original UV's,
* note that the image aspect is taken into account */
static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], const float scaler,
static void uv_image_outset(
float (*orig_uv)[2], float (*outset_uv)[2], const float scaler,
const int ibuf_x, const int ibuf_y, const bool is_quad, const bool cw)
{
float a1, a2, a3, a4 = 0.0f;
@@ -1213,7 +1221,8 @@ static void screen_px_from_persp(
}
static void project_face_pixel(const MTFace *tf_other, ImBuf *ibuf_other, const float w[3],
static void project_face_pixel(
const MTFace *tf_other, ImBuf *ibuf_other, const float w[3],
int side, unsigned char rgba_ub[4], float rgba_f[4])
{
const float *uvCo1, *uvCo2, *uvCo3;
@@ -1455,7 +1464,7 @@ static ProjPixel *project_paint_uvpixel_init(
y_px = mod_i(y_px, ibuf->y);
BLI_assert(ps->pixel_sizeof == project_paint_pixel_sizeof(ps->tool));
projPixel = (ProjPixel *)BLI_memarena_alloc(arena, ps->pixel_sizeof);
projPixel = BLI_memarena_alloc(arena, ps->pixel_sizeof);
/* calculate the undo tile offset of the pixel, used to store the original
* pixel color and accumulated mask if any */
@@ -1586,7 +1595,7 @@ static ProjPixel *project_paint_uvpixel_init(
}
static bool line_clip_rect2f(
rctf *rect,
const rctf *rect,
const float l1[2], const float l2[2],
float l1_clip[2], float l2_clip[2])
{
@@ -1801,7 +1810,7 @@ static float len_squared_v2v2_alt(const float v1[2], const float v2_1, const flo
/* note, use a squared value so we can use len_squared_v2v2
* be sure that you have done a bounds check first or this may fail */
/* only give bucket_bounds as an arg because we need it elsewhere */
static bool project_bucket_isect_circle(const float cent[2], const float radius_squared, rctf *bucket_bounds)
static bool project_bucket_isect_circle(const float cent[2], const float radius_squared, const rctf *bucket_bounds)
{
/* Would normally to a simple intersection test, however we know the bounds of these 2 already intersect
@@ -1856,7 +1865,7 @@ static bool project_bucket_isect_circle(const float cent[2], const float radius_
* however switching back to this for ortho is always an option */
static void rect_to_uvspace_ortho(
rctf *bucket_bounds,
const rctf *bucket_bounds,
const float *v1coSS, const float *v2coSS, const float *v3coSS,
const float *uv1co, const float *uv2co, const float *uv3co,
float bucket_bounds_uv[4][2],
@@ -1889,7 +1898,7 @@ static void rect_to_uvspace_ortho(
/* same as above but use barycentric_weights_v2_persp */
static void rect_to_uvspace_persp(
rctf *bucket_bounds,
const rctf *bucket_bounds,
const float *v1coSS, const float *v2coSS, const float *v3coSS,
const float *uv1co, const float *uv2co, const float *uv3co,
float bucket_bounds_uv[4][2],
@@ -1965,7 +1974,7 @@ static int float_z_sort(const void *p1, const void *p2)
/* assumes one point is within the rectangle */
static void line_rect_clip(
rctf *rect,
const rctf *rect,
const float l1[4], const float l2[4],
const float uv1[2], const float uv2[2],
float uv[2], bool is_ortho)
@@ -1997,7 +2006,7 @@ static void line_rect_clip(
static void project_bucket_clip_face(
const bool is_ortho,
rctf *bucket_bounds,
const rctf *bucket_bounds,
float *v1coSS, float *v2coSS, float *v3coSS,
const float *uv1co, const float *uv2co, const float *uv3co,
float bucket_bounds_uv[8][2],
@@ -2005,7 +2014,8 @@ static void project_bucket_clip_face(
{
int inside_bucket_flag = 0;
int inside_face_flag = 0;
const int flip = ((line_point_side_v2(v1coSS, v2coSS, v3coSS) > 0.0f) != (line_point_side_v2(uv1co, uv2co, uv3co) > 0.0f));
const int flip = ((line_point_side_v2(v1coSS, v2coSS, v3coSS) > 0.0f) !=
(line_point_side_v2(uv1co, uv2co, uv3co) > 0.0f));
bool colinear = false;
float bucket_bounds_ss[4][2];
@@ -2021,7 +2031,8 @@ static void project_bucket_clip_face(
inside_bucket_flag |= BLI_rctf_isect_pt_v(bucket_bounds, v3coSS) << 2;
if (inside_bucket_flag == ISECT_ALL3) {
/* all screenspace points are inside the bucket bounding box, this means we don't need to clip and can simply return the UVs */
/* all screenspace points are inside the bucket bounding box,
* this means we don't need to clip and can simply return the UVs */
if (flip) { /* facing the back? */
copy_v2_v2(bucket_bounds_uv[0], uv3co);
copy_v2_v2(bucket_bounds_uv[1], uv2co);
@@ -2206,7 +2217,8 @@ static void project_bucket_clip_face(
for (i = 0; i < (*tot); i++) {
v2_clipSS[0] = isectVCosSS[i][0] - cent[0];
v2_clipSS[1] = isectVCosSS[i][1] - cent[1];
isectVCosSS[i][2] = atan2f(v1_clipSS[0] * v2_clipSS[1] - v1_clipSS[1] * v2_clipSS[0], v1_clipSS[0] * v2_clipSS[0] + v1_clipSS[1] * v2_clipSS[1]);
isectVCosSS[i][2] = atan2f(v1_clipSS[0] * v2_clipSS[1] - v1_clipSS[1] * v2_clipSS[0],
v1_clipSS[0] * v2_clipSS[0] + v1_clipSS[1] * v2_clipSS[1]);
}
if (flip) qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort_flip);
@@ -2261,7 +2273,9 @@ static void project_bucket_clip_face(
int i;
if (is_ortho) rect_to_uvspace_ortho(bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip);
else rect_to_uvspace_persp(bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip);
printf("( [(%f,%f), (%f,%f), (%f,%f), (%f,%f)], ", test_uv[0][0], test_uv[0][1], test_uv[1][0], test_uv[1][1], test_uv[2][0], test_uv[2][1], test_uv[3][0], test_uv[3][1]);
printf("( [(%f,%f), (%f,%f), (%f,%f), (%f,%f)], ",
test_uv[0][0], test_uv[0][1], test_uv[1][0], test_uv[1][1],
test_uv[2][0], test_uv[2][1], test_uv[3][0], test_uv[3][1]);
printf(" [(%f,%f), (%f,%f), (%f,%f)], ", uv1co[0], uv1co[1], uv2co[0], uv2co[1], uv3co[0], uv3co[1]);
@@ -2359,9 +2373,15 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot
return 1;
}
/* One of the most important function for projection painting, since it selects the pixels to be added into each bucket.
* initialize pixels from this face where it intersects with the bucket_index, optionally initialize pixels for removing seams */
static void project_paint_face_init(const ProjPaintState *ps, const int thread_index, const int bucket_index, const int face_index, const int image_index, rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf, const short clamp_u, const short clamp_v)
/* One of the most important function for projection painting,
* since it selects the pixels to be added into each bucket.
*
* initialize pixels from this face where it intersects with the bucket_index,
* optionally initialize pixels for removing seams */
static void project_paint_face_init(
const ProjPaintState *ps,
const int thread_index, const int bucket_index, const int face_index, const int image_index,
const rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf, const short clamp_u, const short clamp_v)
{
/* Projection vars, to get the 3D locations into screen space */
MemArena *arena = ps->arena_mt[thread_index];
@@ -2825,7 +2845,7 @@ static void project_bucket_bounds(const ProjPaintState *ps, const int bucket_x,
/* Fill this bucket with pixels from the faces that intersect it.
*
* have bucket_bounds as an argument so we don't need to give bucket_x/y the rect function needs */
static void project_bucket_init(const ProjPaintState *ps, const int thread_index, const int bucket_index, rctf *bucket_bounds)
static void project_bucket_init(const ProjPaintState *ps, const int thread_index, const int bucket_index, const rctf *bucket_bounds)
{
LinkNode *node;
int face_index, image_index = 0;
@@ -3184,9 +3204,9 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di
static void proj_paint_state_seam_bleed_init(ProjPaintState *ps)
{
if (ps->seam_bleed_px > 0.0f) {
ps->vertFaces = (LinkNode **)MEM_callocN(sizeof(LinkNode *) * ps->dm_totvert, "paint-vertFaces");
ps->faceSeamFlags = (char *)MEM_callocN(sizeof(char) * ps->dm_totface, "paint-faceSeamFlags");
ps->faceWindingFlags = (char *)MEM_callocN(sizeof(char) * ps->dm_totface, "paint-faceWindindFlags");
ps->vertFaces = MEM_callocN(sizeof(LinkNode *) * ps->dm_totvert, "paint-vertFaces");
ps->faceSeamFlags = MEM_callocN(sizeof(char) * ps->dm_totface, "paint-faceSeamFlags");
ps->faceWindingFlags = MEM_callocN(sizeof(char) * ps->dm_totface, "paint-faceWindindFlags");
ps->faceSeamUVs = MEM_mallocN(sizeof(float) * ps->dm_totface * 8, "paint-faceSeamUVs");
}
}
@@ -3254,7 +3274,8 @@ static void proj_paint_state_vert_flags_init(ProjPaintState *ps)
}
#ifndef PROJ_DEBUG_NOSEAMBLEED
static void project_paint_bleed_add_face_user(const ProjPaintState *ps, MemArena *arena,
static void project_paint_bleed_add_face_user(
const ProjPaintState *ps, MemArena *arena,
const MFace *mf, const int face_index)
{
/* add face user if we have bleed enabled, set the UV seam flags later */
@@ -3321,7 +3342,8 @@ typedef struct {
TexPaintSlot *slot_clone;
} ProjPaintLayerClone;
static void proj_paint_layer_clone_init(ProjPaintState *ps,
static void proj_paint_layer_clone_init(
ProjPaintState *ps,
ProjPaintLayerClone *layer_clone)
{
MTFace *tf_clone_base = NULL;
@@ -3347,7 +3369,8 @@ static void proj_paint_layer_clone_init(ProjPaintState *ps,
}
/* Return true if face should be skipped, false otherwise */
static bool project_paint_clone_face_skip(ProjPaintState *ps,
static bool project_paint_clone_face_skip(
ProjPaintState *ps,
ProjPaintLayerClone *lc,
const TexPaintSlot *slot,
const int face_index)
@@ -3390,7 +3413,8 @@ typedef struct {
const int *index_mp_to_orig;
} ProjPaintFaceLookup;
static void proj_paint_face_lookup_init(const ProjPaintState *ps,
static void proj_paint_face_lookup_init(
const ProjPaintState *ps,
ProjPaintFaceLookup *face_lookup)
{
memset(face_lookup, 0, sizeof(*face_lookup));
@@ -3407,7 +3431,8 @@ static void proj_paint_face_lookup_init(const ProjPaintState *ps,
}
/* Return true if face should be considered selected, false otherwise */
static bool project_paint_check_face_sel(const ProjPaintState *ps,
static bool project_paint_check_face_sel(
const ProjPaintState *ps,
const ProjPaintFaceLookup *face_lookup,
const MFace *mf, const int face_index)
{
@@ -3438,7 +3463,8 @@ typedef struct {
const float *v4;
} ProjPaintFaceCoSS;
static void proj_paint_face_coSS_init(const ProjPaintState *ps, const MFace *mf,
static void proj_paint_face_coSS_init(
const ProjPaintState *ps, const MFace *mf,
ProjPaintFaceCoSS *coSS)
{
coSS->v1 = ps->screenCoords[mf->v1];
@@ -3448,7 +3474,8 @@ static void proj_paint_face_coSS_init(const ProjPaintState *ps, const MFace *mf,
}
/* Return true if face should be culled, false otherwise */
static bool project_paint_flt_max_cull(const ProjPaintState *ps,
static bool project_paint_flt_max_cull(
const ProjPaintState *ps,
const ProjPaintFaceCoSS *coSS)
{
if (!ps->is_ortho) {
@@ -3465,7 +3492,8 @@ static bool project_paint_flt_max_cull(const ProjPaintState *ps,
#ifdef PROJ_DEBUG_WINCLIP
/* Return true if face should be culled, false otherwise */
static bool project_paint_winclip(const ProjPaintState *ps, const MFace *mf,
static bool project_paint_winclip(
const ProjPaintState *ps, const MFace *mf,
const ProjPaintFaceCoSS *coSS)
{
/* ignore faces outside the view */
@@ -3493,7 +3521,8 @@ static bool project_paint_winclip(const ProjPaintState *ps, const MFace *mf,
#endif //PROJ_DEBUG_WINCLIP
/* Return true if face should be culled, false otherwise */
static bool project_paint_backface_cull(const ProjPaintState *ps, const MFace *mf,
static bool project_paint_backface_cull(
const ProjPaintState *ps, const MFace *mf,
const ProjPaintFaceCoSS *coSS)
{
if (ps->do_backfacecull) {
@@ -3520,7 +3549,8 @@ static bool project_paint_backface_cull(const ProjPaintState *ps, const MFace *m
return false;
}
static void project_paint_build_proj_ima(ProjPaintState *ps, MemArena *arena,
static void project_paint_build_proj_ima(
ProjPaintState *ps, MemArena *arena,
LinkNode *image_LinkList)
{
ProjPaintImage *projIma;
@@ -3528,7 +3558,7 @@ static void project_paint_build_proj_ima(ProjPaintState *ps, MemArena *arena,
int i;
/* build an array of images we use */
projIma = ps->projImages = (ProjPaintImage *)BLI_memarena_alloc(arena, sizeof(ProjPaintImage) * ps->image_tot);
projIma = ps->projImages = BLI_memarena_alloc(arena, sizeof(ProjPaintImage) * ps->image_tot);
for (node = image_LinkList, i = 0; node; node = node->next, i++, projIma++) {
int size;
@@ -3540,14 +3570,15 @@ static void project_paint_build_proj_ima(ProjPaintState *ps, MemArena *arena,
memset(projIma->partRedrawRect, 0, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
projIma->undoRect = (volatile void **) BLI_memarena_alloc(arena, size);
memset(projIma->undoRect, 0, size);
projIma->maskRect = (unsigned short **) BLI_memarena_alloc(arena, size);
projIma->maskRect = BLI_memarena_alloc(arena, size);
memset(projIma->maskRect, 0, size);
projIma->valid = (bool **) BLI_memarena_alloc(arena, size);
projIma->valid = BLI_memarena_alloc(arena, size);
memset(projIma->valid, 0, size);
}
}
static void project_paint_prepare_all_faces(ProjPaintState *ps, MemArena *arena,
static void project_paint_prepare_all_faces(
ProjPaintState *ps, MemArena *arena,
const ProjPaintFaceLookup *face_lookup,
ProjPaintLayerClone *layer_clone,
MTFace *tf_base)
@@ -3723,10 +3754,10 @@ static void project_paint_begin(ProjPaintState *ps)
CLAMP(ps->buckets_x, PROJ_BUCKET_RECT_MIN, PROJ_BUCKET_RECT_MAX);
CLAMP(ps->buckets_y, PROJ_BUCKET_RECT_MIN, PROJ_BUCKET_RECT_MAX);
ps->bucketRect = (LinkNode **)MEM_callocN(sizeof(LinkNode *) * ps->buckets_x * ps->buckets_y, "paint-bucketRect");
ps->bucketFaces = (LinkNode **)MEM_callocN(sizeof(LinkNode *) * ps->buckets_x * ps->buckets_y, "paint-bucketFaces");
ps->bucketRect = MEM_callocN(sizeof(LinkNode *) * ps->buckets_x * ps->buckets_y, "paint-bucketRect");
ps->bucketFaces = MEM_callocN(sizeof(LinkNode *) * ps->buckets_x * ps->buckets_y, "paint-bucketFaces");
ps->bucketFlags = (unsigned char *)MEM_callocN(sizeof(char) * ps->buckets_x * ps->buckets_y, "paint-bucketFaces");
ps->bucketFlags = MEM_callocN(sizeof(char) * ps->buckets_x * ps->buckets_y, "paint-bucketFaces");
#ifndef PROJ_DEBUG_NOSEAMBLEED
proj_paint_state_seam_bleed_init(ps);
#endif
@@ -3924,7 +3955,9 @@ static bool project_bucket_iter_init(ProjPaintState *ps, const float mval_f[2])
}
static bool project_bucket_iter_next(ProjPaintState *ps, int *bucket_index, rctf *bucket_bounds, const float mval[2])
static bool project_bucket_iter_next(
ProjPaintState *ps, int *bucket_index,
rctf *bucket_bounds, const float mval[2])
{
const int diameter = 2 * ps->brush_size;
@@ -4638,13 +4671,13 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po
/* thread specific */
handles[a].thread_index = a;
handles[a].projImages = (ProjPaintImage *)BLI_memarena_alloc(ps->arena_mt[a], ps->image_tot * sizeof(ProjPaintImage));
handles[a].projImages = BLI_memarena_alloc(ps->arena_mt[a], ps->image_tot * sizeof(ProjPaintImage));
memcpy(handles[a].projImages, ps->projImages, ps->image_tot * sizeof(ProjPaintImage));
/* image bounds */
for (i = 0; i < ps->image_tot; i++) {
handles[a].projImages[i].partRedrawRect = (ImagePaintPartialRedraw *)BLI_memarena_alloc(ps->arena_mt[a], sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
handles[a].projImages[i].partRedrawRect = BLI_memarena_alloc(ps->arena_mt[a], sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
memcpy(handles[a].projImages[i].partRedrawRect, ps->projImages[i].partRedrawRect, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
}
@@ -5120,7 +5153,9 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); array += sizeof(rv3d->winmat) / sizeof(float);
memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); array += sizeof(rv3d->viewmat) / sizeof(float);
is_ortho = ED_view3d_clip_range_get(v3d, rv3d, &array[0], &array[1], true);
array[2] = is_ortho ? 1.0f : 0.0f; /* using float for a bool is dodgy but since its an extra member in the array... easier then adding a single bool prop */
/* using float for a bool is dodgy but since its an extra member in the array...
* easier then adding a single bool prop */
array[2] = is_ortho ? 1.0f : 0.0f;
IDP_AddToGroup(idgroup, view_data);