diff --git a/app/gegl/gimpcageconfig.c b/app/gegl/gimpcageconfig.c index 069aeba372..602f2d4479 100644 --- a/app/gegl/gimpcageconfig.c +++ b/app/gegl/gimpcageconfig.c @@ -68,10 +68,10 @@ print_cage (GimpCageConfig *gcc) bounding_box = gimp_cage_config_get_bounding_box (gcc); - for (i = 0; i < gcc->cage_vertice_number; i++) - { - printf("cgx: %.0f cgy: %.0f cvdx: %.0f cvdy: %.0f sf: %.2f normx: %.2f normy: %.2f\n", gcc->cage_vertices[i].x, gcc->cage_vertices[i].y, gcc->cage_vertices_d[i].x, gcc->cage_vertices_d[i].y, gcc->scaling_factor[i], gcc->normal_d[i].x, gcc->normal_d[i].y); - } + for (i = 0; i < gcc->n_cage_vertices; i++) + { + printf("cgx: %.0f cgy: %.0f cvdx: %.0f cvdy: %.0f sf: %.2f normx: %.2f normy: %.2f\n", gcc->cage_vertices[i].x, gcc->cage_vertices[i].y, gcc->cage_vertices_d[i].x, gcc->cage_vertices_d[i].y, gcc->scaling_factor[i], gcc->normal_d[i].x, gcc->normal_d[i].y); + } printf("bounding box: x: %d y: %d width: %d height: %d\n", bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height); printf("offsets: (%d, %d)", gcc->offset_x, gcc->offset_y); printf("done\n"); @@ -92,13 +92,13 @@ gimp_cage_config_class_init (GimpCageConfigClass *klass) static void gimp_cage_config_init (GimpCageConfig *self) { - self->cage_vertice_number = 0; - self->cage_vertices_max = 50; /*pre-allocation for 50 vertices for the cage.*/ + self->n_cage_vertices = 0; + self->max_cage_vertices = 50; /*pre-allocation for 50 vertices for the cage.*/ - self->cage_vertices = g_new0 (GimpVector2, self->cage_vertices_max); - self->cage_vertices_d = g_new0 (GimpVector2, self->cage_vertices_max); - self->scaling_factor = g_malloc0 (self->cage_vertices_max * sizeof (gdouble)); - self->normal_d = g_new0 (GimpVector2, self->cage_vertices_max); + self->cage_vertices = g_new0 (GimpVector2, self->max_cage_vertices); + self->cage_vertices_d = g_new0 (GimpVector2, self->max_cage_vertices); + self->scaling_factor = g_malloc0 (self->max_cage_vertices * sizeof (gdouble)); + self->normal_d = g_new0 (GimpVector2, self->max_cage_vertices); } static void @@ -159,33 +159,33 @@ gimp_cage_config_add_cage_point (GimpCageConfig *gcc, g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); /* reallocate memory if needed */ - if (gcc->cage_vertice_number >= gcc->cage_vertices_max) + if (gcc->n_cage_vertices >= gcc->max_cage_vertices) { - gcc->cage_vertices_max += N_ITEMS_PER_ALLOC; + gcc->max_cage_vertices += N_ITEMS_PER_ALLOC; gcc->cage_vertices = g_renew (GimpVector2, gcc->cage_vertices, - gcc->cage_vertices_max); + gcc->max_cage_vertices); gcc->cage_vertices_d = g_renew (GimpVector2, gcc->cage_vertices_d, - gcc->cage_vertices_max); + gcc->max_cage_vertices); gcc->scaling_factor = g_realloc (gcc->scaling_factor, - gcc->cage_vertices_max * sizeof (gdouble)); + gcc->max_cage_vertices * sizeof (gdouble)); gcc->normal_d = g_renew (GimpVector2, gcc->normal_d, - gcc->cage_vertices_max); + gcc->max_cage_vertices); } - gcc->cage_vertices[gcc->cage_vertice_number].x = x + DELTA - gcc->offset_x; - gcc->cage_vertices[gcc->cage_vertice_number].y = y + DELTA - gcc->offset_y; + gcc->cage_vertices[gcc->n_cage_vertices].x = x + DELTA - gcc->offset_x; + gcc->cage_vertices[gcc->n_cage_vertices].y = y + DELTA - gcc->offset_y; - gcc->cage_vertices_d[gcc->cage_vertice_number].x = x + DELTA - gcc->offset_x; - gcc->cage_vertices_d[gcc->cage_vertice_number].y = y + DELTA - gcc->offset_y; + gcc->cage_vertices_d[gcc->n_cage_vertices].x = x + DELTA - gcc->offset_x; + gcc->cage_vertices_d[gcc->n_cage_vertices].y = y + DELTA - gcc->offset_y; - gcc->cage_vertice_number++; + gcc->n_cage_vertices++; gimp_cage_config_compute_scaling_factor (gcc); gimp_cage_config_compute_edge_normal (gcc); @@ -202,8 +202,8 @@ gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc) { g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); - if (gcc->cage_vertice_number >= 1) - gcc->cage_vertice_number--; + if (gcc->n_cage_vertices >= 1) + gcc->n_cage_vertices--; gimp_cage_config_compute_scaling_factor (gcc); gimp_cage_config_compute_edge_normal (gcc); @@ -228,7 +228,7 @@ gimp_cage_config_move_cage_point (GimpCageConfig *gcc, gdouble y) { g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); - g_return_if_fail (point_number < gcc->cage_vertice_number); + g_return_if_fail (point_number < gcc->n_cage_vertices); g_return_if_fail (point_number >= 0); if (mode == GIMP_CAGE_MODE_CAGE_CHANGE) @@ -261,14 +261,14 @@ gimp_cage_config_get_bounding_box (GimpCageConfig *gcc) gint i; g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), bounding_box); - g_return_val_if_fail (gcc->cage_vertice_number >= 0, bounding_box); + g_return_val_if_fail (gcc->n_cage_vertices >= 0, bounding_box); bounding_box.x = gcc->cage_vertices[0].x; bounding_box.y = gcc->cage_vertices[0].y; bounding_box.height = 0; bounding_box.width = 0; - for (i = 1; i < gcc->cage_vertice_number; i++) + for (i = 1; i < gcc->n_cage_vertices; i++) { gdouble x,y; @@ -317,15 +317,15 @@ gimp_cage_config_reverse_cage (GimpCageConfig *gcc) g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); - for (i = 0; i < gcc->cage_vertice_number / 2; i++) + for (i = 0; i < gcc->n_cage_vertices / 2; i++) { temp = gcc->cage_vertices[i]; - gcc->cage_vertices[i] = gcc->cage_vertices[gcc->cage_vertice_number - i -1]; - gcc->cage_vertices[gcc->cage_vertice_number - i -1] = temp; + gcc->cage_vertices[i] = gcc->cage_vertices[gcc->n_cage_vertices - i - 1]; + gcc->cage_vertices[gcc->n_cage_vertices - i - 1] = temp; temp = gcc->cage_vertices_d[i]; - gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->cage_vertice_number - i -1]; - gcc->cage_vertices_d[gcc->cage_vertice_number - i -1] = temp; + gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->n_cage_vertices - i - 1]; + gcc->cage_vertices_d[gcc->n_cage_vertices - i - 1] = temp; } gimp_cage_config_compute_scaling_factor (gcc); @@ -354,14 +354,14 @@ gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc) /* this is a bit crappy, but should works most of the case */ /* we do the sum of the projection of each point to the previous segment, and see the final sign */ - for (i = 0; i < gcc->cage_vertice_number ; i++) + for (i = 0; i < gcc->n_cage_vertices ; i++) { GimpVector2 P1, P2, P3; gdouble z; P1 = gcc->cage_vertices[i]; - P2 = gcc->cage_vertices[(i+1) % gcc->cage_vertice_number]; - P3 = gcc->cage_vertices[(i+2) % gcc->cage_vertice_number]; + P2 = gcc->cage_vertices[(i+1) % gcc->n_cage_vertices]; + P3 = gcc->cage_vertices[(i+2) % gcc->n_cage_vertices]; z = P1.x * (P2.y - P3.y) + P2.x * (P3.y - P1.y) + P3.x * (P1.y - P2.y); @@ -395,12 +395,16 @@ gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc) g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); - for (i = 0; i < gcc->cage_vertice_number; i++) + for (i = 0; i < gcc->n_cage_vertices; i++) { - gimp_vector2_sub ( &edge, &gcc->cage_vertices[i], &gcc->cage_vertices[(i+1) % gcc->cage_vertice_number]); + gimp_vector2_sub (&edge, + &gcc->cage_vertices[i], + &gcc->cage_vertices[(i + 1) % gcc->n_cage_vertices]); length = gimp_vector2_length (&edge); - gimp_vector2_sub ( &edge, &gcc->cage_vertices_d[i], &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number]); + gimp_vector2_sub (&edge, + &gcc->cage_vertices_d[i], + &gcc->cage_vertices_d[(i + 1) % gcc->n_cage_vertices]); length_d = gimp_vector2_length (&edge); gcc->scaling_factor[i] = length_d / length; @@ -419,10 +423,10 @@ gimp_cage_config_compute_edge_normal (GimpCageConfig *gcc) g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); - for (i = 0; i < gcc->cage_vertice_number; i++) + for (i = 0; i < gcc->n_cage_vertices; i++) { gimp_vector2_sub (&normal, - &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number], + &gcc->cage_vertices_d[(i + 1) % gcc->n_cage_vertices], &gcc->cage_vertices_d[i]); gcc->normal_d[i] = gimp_vector2_normal (&normal); @@ -442,8 +446,8 @@ gimp_cage_config_point_inside (GimpCageConfig *gcc, cv = gcc->cage_vertices; - for (i = 0, j = gcc->cage_vertice_number - 1; - i < gcc->cage_vertice_number; + for (i = 0, j = gcc->n_cage_vertices - 1; + i < gcc->n_cage_vertices; j = i++) { if ((((cv[i].y <= y) && (y < cv[j].y)) diff --git a/app/gegl/gimpcageconfig.h b/app/gegl/gimpcageconfig.h index e4fb7e84ab..fa5b085f98 100644 --- a/app/gegl/gimpcageconfig.h +++ b/app/gegl/gimpcageconfig.h @@ -38,14 +38,14 @@ struct _GimpCageConfig { GimpImageMapConfig parent_instance; - gint cage_vertice_number; /* number of vertices used by the cage */ - gint cage_vertices_max; /* number of vertices allocated in memory */ + gint n_cage_vertices; /* vertices used by the cage */ + gint max_cage_vertices; /* vertices allocated */ gint offset_x; gint offset_y; - GimpVector2 *cage_vertices; /* cage before deformation */ - GimpVector2 *cage_vertices_d; /* cage after deformation */ + GimpVector2 *cage_vertices; /* cage before deformation */ + GimpVector2 *cage_vertices_d; /* cage after deformation */ gdouble *scaling_factor; GimpVector2 *normal_d; }; diff --git a/app/gegl/gimpoperationcagecoefcalc.c b/app/gegl/gimpoperationcagecoefcalc.c index 76c6cec90f..2a3e172ce7 100644 --- a/app/gegl/gimpoperationcagecoefcalc.c +++ b/app/gegl/gimpoperationcagecoefcalc.c @@ -97,7 +97,7 @@ gimp_operation_cage_coef_calc_prepare (GeglOperation *operation) gegl_operation_set_format (operation, "output", babl_format_n (babl_type ("float"), - 2 * config->cage_vertice_number)); + 2 * config->n_cage_vertices)); } static void @@ -194,7 +194,7 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation, GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation); GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config); - Babl *format = babl_format_n (babl_type ("float"), 2 * config->cage_vertice_number); + Babl *format = babl_format_n (babl_type ("float"), 2 * config->n_cage_vertices); GeglBufferIterator *it; @@ -217,13 +217,13 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation, { if (gimp_cage_config_point_inside(config, x, y)) { - for( j = 0; j < config->cage_vertice_number; j++) + for( j = 0; j < config->n_cage_vertices; j++) { GimpVector2 v1,v2,a,b,p; gdouble BA,SRT,L0,L1,A0,A1,A10,L10, Q,S,R, absa; v1 = config->cage_vertices[j]; - v2 = config->cage_vertices[(j+1)%config->cage_vertice_number]; + v2 = config->cage_vertices[(j+1)%config->n_cage_vertices]; p.x = x; p.y = y; a.x = v2.x - v1.x; @@ -246,23 +246,23 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation, L10 = L1 - L0; /* edge coef */ - coef[j + config->cage_vertice_number] = (-absa / (4.0 * M_PI)) * ((4.0*S-(R*R)/Q) * A10 + (R / (2.0 * Q)) * L10 + L1 - 2.0); + coef[j + config->n_cage_vertices] = (-absa / (4.0 * M_PI)) * ((4.0*S-(R*R)/Q) * A10 + (R / (2.0 * Q)) * L10 + L1 - 2.0); - if (isnan(coef[j + config->cage_vertice_number])) + if (isnan(coef[j + config->n_cage_vertices])) { - coef[j + config->cage_vertice_number] = 0.0; + coef[j + config->n_cage_vertices] = 0.0; } /* vertice coef */ if (!gimp_operation_cage_coef_calc_is_on_straight (&v1, &v2, &p)) { coef[j] += (BA / (2.0 * M_PI)) * (L10 /(2.0*Q) - A10 * (2.0 + R / Q)); - coef[(j+1)%config->cage_vertice_number] -= (BA / (2.0 * M_PI)) * (L10 / (2.0 * Q) - A10 * (R / Q)); + coef[(j+1)%config->n_cage_vertices] -= (BA / (2.0 * M_PI)) * (L10 / (2.0 * Q) - A10 * (R / Q)); } } } - coef += 2 * config->cage_vertice_number; + coef += 2 * config->n_cage_vertices; /* update x and y coordinates */ x++; diff --git a/app/gegl/gimpoperationcagetransform.c b/app/gegl/gimpoperationcagetransform.c index 5ed7bf392a..188014f300 100644 --- a/app/gegl/gimpoperationcagetransform.c +++ b/app/gegl/gimpoperationcagetransform.c @@ -192,7 +192,7 @@ gimp_operation_cage_transform_prepare (GeglOperation *operation) gegl_operation_set_format (operation, "input", babl_format_n (babl_type ("float"), - 2 * config->cage_vertice_number)); + 2 * config->n_cage_vertices)); gegl_operation_set_format (operation, "output", babl_format_n (babl_type ("float"), 2)); } @@ -476,7 +476,7 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config, gint i; GeglRectangle rect; GimpVector2 result; - gint cvn = config->cage_vertice_number; + gint cvn = config->n_cage_vertices; Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn); rect.height = 1; @@ -484,7 +484,7 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config, rect.x = coords.x; rect.y = coords.y; - coef = g_malloc (config->cage_vertice_number * 2 * sizeof(gfloat)); + coef = g_malloc (config->n_cage_vertices * 2 * sizeof(gfloat)); gegl_buffer_get (coef_buf, 1, &rect, format_coef, coef, GEGL_AUTO_ROWSTRIDE); diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c index b41657db82..f8929fc70b 100644 --- a/app/tools/gimpcagetool.c +++ b/app/tools/gimpcagetool.c @@ -402,7 +402,7 @@ gimp_cage_tool_button_press (GimpTool *tool, /* user is clicking on the first handle, we close the cage and * switch to deform mode */ - if (ct->handle_moved == 0 && config->cage_vertice_number > 2 && ! ct->coef) + if (ct->handle_moved == 0 && config->n_cage_vertices > 2 && ! ct->coef) { ct->cage_complete = TRUE; gimp_cage_tool_switch_to_deform (ct); @@ -505,8 +505,9 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool) gint i = 0; gint on_handle = -1; GimpVector2 *vertices; + gint n_vertices; - if (config->cage_vertice_number <= 0) + if (config->n_cage_vertices <= 0) return; if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE) @@ -514,24 +515,26 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool) else vertices = config->cage_vertices_d; + n_vertices = config->n_cage_vertices; + /*gimp_draw_tool_add_lines (draw_tool, vertices, - config->cage_vertice_number, + config->n_cage_vertices, FALSE);*/ if (! ct->cage_complete && ct->cursor_position.x != -1000) { gimp_draw_tool_add_line (draw_tool, - vertices[config->cage_vertice_number - 1].x + ct->config->offset_x, - vertices[config->cage_vertice_number - 1].y + ct->config->offset_y, + vertices[n_vertices - 1].x + ct->config->offset_x, + vertices[n_vertices - 1].y + ct->config->offset_y, ct->cursor_position.x, ct->cursor_position.y); } else { gimp_draw_tool_add_line (draw_tool, - vertices[config->cage_vertice_number - 1].x + ct->config->offset_x, - vertices[config->cage_vertice_number - 1].y + ct->config->offset_y, + vertices[n_vertices - 1].x + ct->config->offset_x, + vertices[n_vertices - 1].y + ct->config->offset_y, vertices[0].x + ct->config->offset_x, vertices[0].y + ct->config->offset_y); } @@ -544,7 +547,7 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool) ct->cursor_position.y, HANDLE_SIZE); - for (i = 0; i < config->cage_vertice_number; i++) + for (i = 0; i < n_vertices; i++) { GimpHandleType handle = GIMP_HANDLE_CIRCLE; @@ -583,10 +586,10 @@ gimp_cage_tool_is_on_handle (GimpCageConfig *gcc, g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), -1); - if (gcc->cage_vertice_number == 0) + if (gcc->n_cage_vertices == 0) return -1; - for (i = 0; i < gcc->cage_vertice_number; i++) + for (i = 0; i < gcc->n_cage_vertices; i++) { if (mode == GIMP_CAGE_MODE_CAGE_CHANGE) { @@ -652,7 +655,7 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct, } format = babl_format_n (babl_type ("float"), - config->cage_vertice_number * 2); + config->n_cage_vertices * 2); progress = gimp_progress_start (GIMP_PROGRESS (display), _("Coefficient computation"),