mirror of https://github.com/GNOME/gimp.git
app: formatting; move variables to local scopes
This commit is contained in:
parent
6bf13efbc8
commit
3ac37bbff0
|
@ -31,42 +31,43 @@
|
||||||
#include "gimpcageconfig.h"
|
#include "gimpcageconfig.h"
|
||||||
|
|
||||||
|
|
||||||
static void gimp_operation_cage_transform_finalize (GObject *object);
|
static void gimp_operation_cage_transform_finalize (GObject *object);
|
||||||
static void gimp_operation_cage_transform_get_property (GObject *object,
|
static void gimp_operation_cage_transform_get_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
static void gimp_operation_cage_transform_set_property (GObject *object,
|
static void gimp_operation_cage_transform_set_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
static void gimp_operation_cage_transform_prepare (GeglOperation *operation);
|
static void gimp_operation_cage_transform_prepare (GeglOperation *operation);
|
||||||
static gboolean gimp_operation_cage_transform_process (GeglOperation *operation,
|
static gboolean gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
GeglBuffer *in_buf,
|
GeglBuffer *in_buf,
|
||||||
GeglBuffer *aux_buf,
|
GeglBuffer *aux_buf,
|
||||||
GeglBuffer *out_buf,
|
GeglBuffer *out_buf,
|
||||||
const GeglRectangle *roi);
|
const GeglRectangle *roi);
|
||||||
static void gimp_operation_cage_transform_interpolate_source_coords_recurs
|
static void gimp_operation_cage_transform_interpolate_source_coords_recurs
|
||||||
(GimpOperationCageTransform *oct,
|
(GimpOperationCageTransform *oct,
|
||||||
GeglBuffer *out_buf,
|
GeglBuffer *out_buf,
|
||||||
const GeglRectangle *roi,
|
const GeglRectangle *roi,
|
||||||
GimpVector2 p1_s,
|
GimpVector2 p1_s,
|
||||||
GimpVector2 p1_d,
|
GimpVector2 p1_d,
|
||||||
GimpVector2 p2_s,
|
GimpVector2 p2_s,
|
||||||
GimpVector2 p2_d,
|
GimpVector2 p2_d,
|
||||||
GimpVector2 p3_s,
|
GimpVector2 p3_s,
|
||||||
GimpVector2 p3_d,
|
GimpVector2 p3_d,
|
||||||
gint recursion_depth,
|
gint recursion_depth,
|
||||||
gfloat *coords);
|
gfloat *coords);
|
||||||
static GimpVector2 gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
static GimpVector2 gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
GeglBuffer *coef_buf,
|
GeglBuffer *coef_buf,
|
||||||
GimpVector2 coords);
|
GimpVector2 coords);
|
||||||
GeglRectangle gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
|
GeglRectangle gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
|
||||||
const GeglRectangle *roi);
|
const GeglRectangle *roi);
|
||||||
GeglRectangle gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
GeglRectangle gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
||||||
const gchar *input_pad,
|
const gchar *input_pad,
|
||||||
const GeglRectangle *roi);
|
const GeglRectangle *roi);
|
||||||
GeglRectangle gimp_operation_cage_transform_get_bounding_box (GeglOperation *operation);
|
GeglRectangle gimp_operation_cage_transform_get_bounding_box (GeglOperation *operation);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
|
G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
|
||||||
GEGL_TYPE_OPERATION_COMPOSER)
|
GEGL_TYPE_OPERATION_COMPOSER)
|
||||||
|
@ -74,8 +75,6 @@ G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
|
||||||
#define parent_class gimp_operation_cage_transform_parent_class
|
#define parent_class gimp_operation_cage_transform_parent_class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass)
|
gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass)
|
||||||
{
|
{
|
||||||
|
@ -206,16 +205,14 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
{
|
{
|
||||||
GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
|
GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
|
||||||
GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
|
GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
|
||||||
|
GeglRectangle cage_bb;
|
||||||
gint x, y;
|
gfloat *coords;
|
||||||
GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
|
GimpVector2 plain_color;
|
||||||
gfloat *coords = g_slice_alloc ( 2 * sizeof (gfloat));
|
GeglBufferIterator *it;
|
||||||
GimpVector2 p1_d, p2_d, p3_d, p4_d;
|
gint x, y;
|
||||||
GimpVector2 p1_s, p2_s, p3_s, p4_s;
|
|
||||||
GimpVector2 plain_color;
|
|
||||||
|
|
||||||
/* pre-fill the out buffer with no-displacement coordinate */
|
/* pre-fill the out buffer with no-displacement coordinate */
|
||||||
GeglBufferIterator *it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
|
it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
|
||||||
|
|
||||||
plain_color.x = (gint) config->cage_vertices[0].x;
|
plain_color.x = (gint) config->cage_vertices[0].x;
|
||||||
plain_color.y = (gint) config->cage_vertices[0].y;
|
plain_color.y = (gint) config->cage_vertices[0].y;
|
||||||
|
@ -223,15 +220,16 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
while (gegl_buffer_iterator_next (it))
|
while (gegl_buffer_iterator_next (it))
|
||||||
{
|
{
|
||||||
/* iterate inside the roi */
|
/* iterate inside the roi */
|
||||||
gint n_pixels = it->length;
|
gint n_pixels = it->length;
|
||||||
gint x = it->roi->x; /* initial x */
|
gfloat *output = it->data[0];
|
||||||
gint y = it->roi->y; /* and y coordinates */
|
|
||||||
|
|
||||||
gfloat *output = it->data[0];
|
x = it->roi->x; /* initial x */
|
||||||
|
y = it->roi->y; /* and y coordinates */
|
||||||
|
|
||||||
while(n_pixels--)
|
while (n_pixels--)
|
||||||
{
|
{
|
||||||
if (oct->fill_plain_color && gimp_cage_config_point_inside(config, x, y))
|
if (oct->fill_plain_color &&
|
||||||
|
gimp_cage_config_point_inside (config, x, y))
|
||||||
{
|
{
|
||||||
output[0] = plain_color.x;
|
output[0] = plain_color.x;
|
||||||
output[1] = plain_color.y;
|
output[1] = plain_color.y;
|
||||||
|
@ -255,8 +253,14 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute, reverse and interpolate the transformation */
|
/* compute, reverse and interpolate the transformation */
|
||||||
|
cage_bb = gimp_cage_config_get_bounding_box (config);
|
||||||
|
coords = g_slice_alloc (2 * sizeof (gfloat));
|
||||||
|
|
||||||
for (x = cage_bb.x; x < cage_bb.x + cage_bb.width - 1; x++)
|
for (x = cage_bb.x; x < cage_bb.x + cage_bb.width - 1; x++)
|
||||||
{
|
{
|
||||||
|
GimpVector2 p1_d, p2_d, p3_d, p4_d;
|
||||||
|
GimpVector2 p1_s, p2_s, p3_s, p4_s;
|
||||||
|
|
||||||
p1_s.x = x;
|
p1_s.x = x;
|
||||||
p2_s.x = x+1;
|
p2_s.x = x+1;
|
||||||
p3_s.x = x+1;
|
p3_s.x = x+1;
|
||||||
|
@ -279,25 +283,25 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
|
p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
|
||||||
p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
|
p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
|
||||||
|
|
||||||
if (gimp_cage_config_point_inside(config, x, y))
|
if (gimp_cage_config_point_inside (config, x, y))
|
||||||
{
|
{
|
||||||
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
||||||
out_buf,
|
out_buf,
|
||||||
roi,
|
roi,
|
||||||
p1_s, p1_d,
|
p1_s, p1_d,
|
||||||
p2_s, p2_d,
|
p2_s, p2_d,
|
||||||
p3_s, p3_d,
|
p3_s, p3_d,
|
||||||
0,
|
0,
|
||||||
coords);
|
coords);
|
||||||
|
|
||||||
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
||||||
out_buf,
|
out_buf,
|
||||||
roi,
|
roi,
|
||||||
p1_s, p1_d,
|
p1_s, p1_d,
|
||||||
p3_s, p3_d,
|
p3_s, p3_d,
|
||||||
p4_s, p4_d,
|
p4_s, p4_d,
|
||||||
0,
|
0,
|
||||||
coords);
|
coords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,20 +313,20 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCageTransform *oct,
|
gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCageTransform *oct,
|
||||||
GeglBuffer *out_buf,
|
GeglBuffer *out_buf,
|
||||||
const GeglRectangle *roi,
|
const GeglRectangle *roi,
|
||||||
GimpVector2 p1_s,
|
GimpVector2 p1_s,
|
||||||
GimpVector2 p1_d,
|
GimpVector2 p1_d,
|
||||||
GimpVector2 p2_s,
|
GimpVector2 p2_s,
|
||||||
GimpVector2 p2_d,
|
GimpVector2 p2_d,
|
||||||
GimpVector2 p3_s,
|
GimpVector2 p3_s,
|
||||||
GimpVector2 p3_d,
|
GimpVector2 p3_d,
|
||||||
gint recursion_depth,
|
gint recursion_depth,
|
||||||
gfloat *coords)
|
gfloat *coords)
|
||||||
{
|
{
|
||||||
gint xmin, xmax, ymin, ymax;
|
|
||||||
GeglRectangle rect = { 0, 0, 1, 1 };
|
GeglRectangle rect = { 0, 0, 1, 1 };
|
||||||
|
gint xmin, xmax, ymin, ymax;
|
||||||
|
|
||||||
if (p1_d.x > roi->x + roi->width) return;
|
if (p1_d.x > roi->x + roi->width) return;
|
||||||
if (p2_d.x > roi->x + roi->width) return;
|
if (p2_d.x > roi->x + roi->width) return;
|
||||||
|
@ -362,7 +366,10 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* test if the triangle is small enough.
|
/* test if the triangle is small enough.
|
||||||
* if yes, we compute the coefficient of the barycenter for the pixel (x,y) and see if a pixel is inside (ie the 3 coef have the same sign).
|
*
|
||||||
|
* if yes, we compute the coefficient of the barycenter for the
|
||||||
|
* pixel (x,y) and see if a pixel is inside (ie the 3 coef have the
|
||||||
|
* same sign).
|
||||||
*/
|
*/
|
||||||
if (xmax - xmin == 1 && ymax - ymin == 1)
|
if (xmax - xmin == 1 && ymax - ymin == 1)
|
||||||
{
|
{
|
||||||
|
@ -379,7 +386,9 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
|
||||||
b = - ((p1_d.x - x) * p3_d.y + (x - p3_d.x) * p1_d.y + (p3_d.x - p1_d.x) * y) / denom;
|
b = - ((p1_d.x - x) * p3_d.y + (x - p3_d.x) * p1_d.y + (p3_d.x - p1_d.x) * y) / denom;
|
||||||
c = 1.0 - a - b;
|
c = 1.0 - a - b;
|
||||||
|
|
||||||
/* if a pixel is inside, we compute his source coordinate and set it in the output buffer */
|
/* if a pixel is inside, we compute its source coordinate and
|
||||||
|
* set it in the output buffer
|
||||||
|
*/
|
||||||
if ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0))
|
if ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0))
|
||||||
{
|
{
|
||||||
coords[0] = (a * p1_s.x + b * p2_s.x + c * p3_s.x);
|
coords[0] = (a * p1_s.x + b * p2_s.x + c * p3_s.x);
|
||||||
|
@ -407,8 +416,7 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
|
||||||
|
|
||||||
GimpVector2 pm1_d, pm2_d, pm3_d;
|
GimpVector2 pm1_d, pm2_d, pm3_d;
|
||||||
GimpVector2 pm1_s, pm2_s, pm3_s;
|
GimpVector2 pm1_s, pm2_s, pm3_s;
|
||||||
|
gint next_depth = recursion_depth + 1;
|
||||||
gint next_depth = recursion_depth + 1;
|
|
||||||
|
|
||||||
pm1_d.x = (p1_d.x + p2_d.x) / 2.0;
|
pm1_d.x = (p1_d.x + p2_d.x) / 2.0;
|
||||||
pm1_d.y = (p1_d.y + p2_d.y) / 2.0;
|
pm1_d.y = (p1_d.y + p2_d.y) / 2.0;
|
||||||
|
@ -473,11 +481,11 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
{
|
{
|
||||||
gfloat *coef;
|
gfloat *coef;
|
||||||
gdouble pos_x, pos_y;
|
gdouble pos_x, pos_y;
|
||||||
gint i;
|
|
||||||
GeglRectangle rect;
|
GeglRectangle rect;
|
||||||
GimpVector2 result;
|
GimpVector2 result;
|
||||||
gint cvn = config->n_cage_vertices;
|
gint cvn = config->n_cage_vertices;
|
||||||
Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
|
Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
|
||||||
|
gint i;
|
||||||
|
|
||||||
rect.height = 1;
|
rect.height = 1;
|
||||||
rect.width = 1;
|
rect.width = 1;
|
||||||
|
|
Loading…
Reference in New Issue