Commit eec66096 authored by Øyvind Kolås's avatar Øyvind Kolås

s/calc_have_rect_/defined_region/

parent 77e50b7e
2006-09-03 Øyvind Kolås <pippin@gimp.org>
s/calc_have_rect/defined_region/, this new virtual method for
operations returns (over the stack) a GeglRect. The graph evaluation
manager is responsible for updating the operation (and node)'s state.
* gegl/gegl-chant.h:
* gegl/gegl-eval-mgr.c: (gegl_eval_mgr_apply):
* gegl/gegl-have-visitor.c: (visit_node):
* gegl/gegl-operation-composer.c:
(gegl_operation_composer_class_init), (defined_region):
* gegl/gegl-operation-filter.c: (gegl_operation_filter_class_init),
(defined_region):
* gegl/gegl-operation-source.c: (gegl_operation_source_class_init),
(defined_region):
* gegl/gegl-operation.c: (gegl_operation_class_init),
(gegl_operation_defined_region), (defined_region):
* gegl/gegl-operation.h:
* operations/blur/box-blur.c: (defined_region), (class_init):
* operations/blur/gaussian-blur.c: (defined_region), (class_init):
* operations/core/crop.c: (defined_region), (class_init):
* operations/core/shift.c: (defined_region), (class_init):
* operations/file-io/jpg-load.c: (defined_region):
* operations/file-io/load.c: (prepare):
* operations/file-io/magick-load.c: (defined_region):
* operations/file-io/png-load.c: (defined_region):
* operations/file-io/raw-load.c: (defined_region):
* operations/render/blank.c: (defined_region):
* operations/render/checkerboard.c: (defined_region):
* operations/render/noise.c: (defined_region):
* operations/render/text.c: (defined_region):
* operations/transform/affine.c: (op_affine_class_init),
(defined_region):
2006-09-02 Kevin Cozens <kcozens@cvs.gnome.org>
* operations/render/checkerboard.c: Applied slightly modified patch
......
......@@ -383,7 +383,7 @@ static void class_init (GeglOperationClass *operation_class);
#endif
#ifdef GEGL_CHANT_SOURCE
static gboolean calc_have_rect (GeglOperation *self);
static GeglRect defined_region (GeglOperation *self);
#endif
static void
......@@ -411,7 +411,7 @@ gegl_chant_class_init (ChantClass * klass)
#endif
#ifdef GEGL_CHANT_SOURCE
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
#endif
#define M_GEGL_CHANT_SET_NAME_EXTENDED(name) \
......
......@@ -91,9 +91,15 @@ gegl_eval_mgr_apply (GeglEvalMgr *self,
root = pad->node;
g_object_ref (root);
{
gint i;
for (i=0;i<2;i++)
{
prepare_visitor = g_object_new (GEGL_TYPE_PREPARE_VISITOR, NULL);
gegl_visitor_dfs_traverse (prepare_visitor, GEGL_VISITABLE(root));
g_object_unref (prepare_visitor);
}
}
have_visitor = g_object_new (GEGL_TYPE_HAVE_VISITOR, NULL);
gegl_visitor_dfs_traverse (have_visitor, GEGL_VISITABLE(root));
......
......@@ -56,9 +56,11 @@ static void
visit_node (GeglVisitor *self,
GeglNode *node)
{
GeglRect rect;
GeglOperation *operation = node->operation;
GEGL_VISITOR_CLASS (gegl_have_visitor_parent_class)->visit_node (self, node);
gegl_operation_calc_have_rect (operation);
rect = gegl_operation_defined_region (operation);
gegl_operation_set_have_rect (operation, rect.x, rect.y, rect.w, rect.h);
}
......@@ -47,7 +47,7 @@ static gboolean evaluate (GeglOperation *operation,
static void associate (GeglOperation *operation);
static void clean_pads (GeglOperation *operation);
static gboolean calc_have_rect (GeglOperation *self);
static GeglRect defined_region (GeglOperation *self);
static gboolean calc_need_rect (GeglOperation *self);
......@@ -67,7 +67,7 @@ gegl_operation_composer_class_init (GeglOperationComposerClass * klass)
operation_class->evaluate = evaluate;
operation_class->associate = associate;
operation_class->clean_pads = clean_pads;
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
g_object_class_install_property (object_class, PROP_OUTPUT,
......@@ -219,28 +219,23 @@ evaluate (GeglOperation *operation,
return success;
}
static gboolean
calc_have_rect (GeglOperation *self)
static GeglRect
defined_region (GeglOperation *self)
{
GeglRect result = {0,0,0,0};
GeglRect *in_rect = gegl_operation_get_have_rect (self, "input");
GeglRect *aux_rect = gegl_operation_get_have_rect (self, "aux");
if (!in_rect)
return FALSE;
return result;
if (aux_rect)
{
GeglRect result;
gegl_rect_bounding_box (&result, in_rect, aux_rect);
gegl_operation_set_have_rect (self,
result.x, result.y,
result.w, result.h);
}
else
{
gegl_operation_set_have_rect (self,
in_rect->x, in_rect->y,
in_rect->w, in_rect->h);
result = *in_rect;
}
return TRUE;
return result;
}
static gboolean
......
......@@ -44,7 +44,7 @@ static gboolean evaluate (GeglOperation *operation,
static void associate (GeglOperation *operation);
static gboolean calc_have_rect (GeglOperation *self);
static GeglRect defined_region (GeglOperation *self);
static gboolean calc_need_rect (GeglOperation *self);
static void clean_pads (GeglOperation *operation);
......@@ -64,7 +64,7 @@ gegl_operation_filter_class_init (GeglOperationFilterClass * klass)
operation_class->evaluate = evaluate;
operation_class->associate = associate;
operation_class->clean_pads = clean_pads;
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
g_object_class_install_property (object_class, PROP_OUTPUT,
......@@ -192,20 +192,19 @@ evaluate (GeglOperation *operation,
return success;
}
static gboolean
calc_have_rect (GeglOperation *self)
static GeglRect
defined_region (GeglOperation *self)
{
GeglRect result = {0,0,0,0};
GeglRect *in_rect;
in_rect = gegl_operation_get_have_rect (self, "input");
if (!in_rect)
return FALSE;
gegl_operation_set_have_rect (self,
in_rect->x, in_rect->y,
in_rect->w, in_rect->h);
if (in_rect)
{
result = *in_rect;
}
return TRUE;
return result;
}
static gboolean
......
......@@ -44,7 +44,7 @@ static void clean_pads (GeglOperation *operation);
G_DEFINE_TYPE (GeglOperationSource, gegl_operation_source, GEGL_TYPE_OPERATION)
static gboolean calc_have_rect (GeglOperation *self);
static GeglRect defined_region (GeglOperation *self);
static gboolean calc_need_rect (GeglOperation *self);
static void
......@@ -61,7 +61,7 @@ gegl_operation_source_class_init (GeglOperationSourceClass * klass)
operation_class->associate = associate;
operation_class->clean_pads = clean_pads;
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
g_object_class_install_property (gobject_class, PROP_OUTPUT,
......@@ -156,12 +156,13 @@ evaluate (GeglOperation *operation,
return success;
}
static gboolean
calc_have_rect (GeglOperation *self)
static GeglRect
defined_region (GeglOperation *self)
{
GeglRect result = {0,0,0,0};
g_warning ("Gegl Source '%s' has no proper have_rect function",
G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS(self)));
return FALSE;
return result;
}
static gboolean
......
......@@ -36,7 +36,7 @@ static void gegl_operation_init (GeglOperation *self);
static void associate (GeglOperation *self);
static void clean_pads (GeglOperation *self);
static gboolean calc_have_rect (GeglOperation *self);
static GeglRect defined_region (GeglOperation *self);
static gboolean calc_need_rect (GeglOperation *self);
static gboolean calc_result_rect (GeglOperation *self);
......@@ -52,7 +52,7 @@ gegl_operation_class_init (GeglOperationClass * klass)
klass->associate = associate;
klass->prepare = NULL;
klass->clean_pads = clean_pads;
klass->calc_have_rect = calc_have_rect;
klass->defined_region = defined_region;
klass->calc_need_rect = calc_need_rect;
klass->calc_result_rect = calc_result_rect;
}
......@@ -104,15 +104,18 @@ gegl_operation_evaluate (GeglOperation *self,
return klass->evaluate (self, output_pad);
}
gboolean
gegl_operation_calc_have_rect (GeglOperation *self)
GeglRect
gegl_operation_defined_region (GeglOperation *self)
{
GeglRect rect = {0,0,0,0};
GeglOperationClass *klass;
klass = GEGL_OPERATION_GET_CLASS (self);
if (klass->calc_have_rect)
return klass->calc_have_rect (self);
return FALSE;
g_warning ("'%s'.defined_region",
G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS(self)));
if (klass->defined_region)
return klass->defined_region (self);
return rect;
}
gboolean
......@@ -328,12 +331,13 @@ gegl_operation_set_result_rect (GeglOperation *operation,
gegl_node_set_result_rect (operation->node, x, y, width, height);
}
static gboolean
calc_have_rect (GeglOperation *self)
static GeglRect
defined_region (GeglOperation *self)
{
GeglRect rect = {0,0,0,0};
g_warning ("Op '%s' has no proper have_rect function",
G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS(self)));
return FALSE;
return rect;
}
static gboolean
......
......@@ -65,7 +65,8 @@ struct _GeglOperationClass
void (*prepare) (GeglOperation *self);
void (*clean_pads) (GeglOperation *self);
gboolean (*calc_have_rect) (GeglOperation *self);
GeglRect (*defined_region) (GeglOperation *self);
gboolean (*calc_need_rect) (GeglOperation *self);
gboolean (*calc_result_rect) (GeglOperation *self);
};
......@@ -90,7 +91,7 @@ void gegl_operation_create_pad (GeglOperation *self,
gboolean gegl_operation_register (GeglOperation *self,
GeglNode *node);
void gegl_operation_clean_pads (GeglOperation *self);
gboolean gegl_operation_calc_have_rect (GeglOperation *self);
GeglRect gegl_operation_defined_region (GeglOperation *self);
gboolean gegl_operation_calc_need_rect (GeglOperation *self);
gboolean gegl_operation_calc_result_rect (GeglOperation *self);
......
......@@ -221,21 +221,24 @@ ver_blur (GeglBuffer *src,
}
#include <math.h>
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result;
GeglRect *in_rect = gegl_operation_get_have_rect (operation, "input");
ChantInstance *blur = GEGL_CHANT_INSTANCE (operation);
gint radius = ceil(blur->radius);
if (!in_rect)
return FALSE;
return result;
gegl_operation_set_have_rect (operation,
in_rect->x-radius, in_rect->y-radius,
in_rect->w+radius*2, in_rect->h+radius*2);
return TRUE;
}
result = *in_rect;
result.x-=radius;
result.y-=radius;
result.w+=radius*2;
result.h+=radius*2;
return result;
}
static gboolean
calc_need_rect (GeglOperation *self)
......@@ -252,7 +255,7 @@ calc_need_rect (GeglOperation *self)
static void class_init (GeglOperationClass *operation_class)
{
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
}
......
......@@ -285,22 +285,26 @@ ver_blur (GeglBuffer *src,
g_free (w);
}
static gboolean
calc_have_rect (GeglOperation *operation)
#include <math.h>
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result;
GeglRect *in_rect = gegl_operation_get_have_rect (operation, "input");
ChantInstance* self = GEGL_CHANT_INSTANCE(operation);
gint radius_x = ceil(self->radius_x+0.5);
gint radius_y = ceil(self->radius_y+0.5);
if(!in_rect)
return FALSE;
ChantInstance *blur = GEGL_CHANT_INSTANCE (operation);
gint radius_x = ceil(blur->radius_x+0.5);
gint radius_y = ceil(blur->radius_y+0.5);
if (!in_rect)
return result;
gegl_operation_set_have_rect (operation,
in_rect->x-radius_x, in_rect->y-radius_y,
in_rect->w+radius_x*2, in_rect->h+radius_y*2);
return TRUE;
}
result = *in_rect;
result.x-=radius_x;
result.y-=radius_y;
result.w+=radius_x*2;
result.h+=radius_y*2;
return result;
}
static gboolean
calc_need_rect (GeglOperation *self)
......@@ -318,9 +322,8 @@ calc_need_rect (GeglOperation *self)
static void class_init (GeglOperationClass *operation_class)
{
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
}
#endif
......@@ -71,18 +71,23 @@ evaluate (GeglOperation *operation,
return TRUE;
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result;
ChantInstance *op_crop = (ChantInstance*)(operation);
GeglRect *in_rect = gegl_operation_get_have_rect (operation, "input");
if (!in_rect)
return FALSE;
return result;
gegl_operation_set_have_rect (operation,
op_crop->x, op_crop->y,
op_crop->width, op_crop->height);
return TRUE;
result.x=op_crop->x;
result.y=op_crop->y;
result.w=op_crop->width;
result.h=op_crop->height;
return result;
}
static gboolean
......@@ -99,7 +104,7 @@ calc_need_rect (GeglOperation *self)
static void class_init (GeglOperationClass *operation_class)
{
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
}
......
......@@ -67,19 +67,20 @@ evaluate (GeglOperation *operation,
return TRUE;
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *op_shift = (ChantInstance*)(operation);
GeglRect *in_rect = gegl_operation_get_have_rect (operation, "input");
if (!in_rect)
return FALSE;
return result;
gegl_operation_set_have_rect (operation,
in_rect->x + op_shift->x,
in_rect->y + op_shift->y,
in_rect->w, in_rect->h);
return TRUE;
result = *in_rect;
result.x += op_shift->x;
result.y += op_shift->y;
return result;
}
static gboolean
......@@ -97,7 +98,7 @@ calc_need_rect (GeglOperation *self)
static void class_init (GeglOperationClass *operation_class)
{
operation_class->calc_have_rect = calc_have_rect;
operation_class->defined_region = defined_region;
operation_class->calc_need_rect = calc_need_rect;
}
......
......@@ -101,9 +101,10 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *self = GEGL_CHANT_INSTANCE (operation);
gint width, height;
gint status;
......@@ -112,13 +113,16 @@ calc_have_rect (GeglOperation *operation)
if (status)
{
g_warning ("calc have rect of %s failed", self->path);
gegl_operation_set_have_rect (operation, 0, 0, 10, 10);
return TRUE;
result.w = 10;
result.h = 10;
}
else
{
result.w = width;
result.h = height;
}
gegl_operation_set_have_rect (operation, 0, 0, width, height);
return TRUE;
return result;
}
static gint
......
......@@ -59,9 +59,11 @@ prepare (GeglOperation *operation)
if (extension)
handler = gegl_extension_handler_get (extension);
g_warning ("%s %s", handler, self->path);
gegl_node_set (priv->load,
"operation", handler,
NULL);
gegl_node_set (priv->load,
"path", self->path,
NULL);
}
......
......@@ -93,9 +93,10 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *self = GEGL_CHANT_INSTANCE (operation);
gint width, height;
......@@ -104,9 +105,10 @@ calc_have_rect (GeglOperation *operation)
width = GEGL_BUFFER (self->cached)->width;
height = GEGL_BUFFER (self->cached)->height;
gegl_operation_set_have_rect (operation, 0, 0, width, height);
result.w = width;
result.h = height;
return TRUE;
return result;
}
static void dispose (GObject *gobject)
......
......@@ -115,9 +115,10 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *self = GEGL_CHANT_INSTANCE (operation);
GeglOperationSource *source = GEGL_OPERATION_SOURCE (operation);
gint width, height;
......@@ -136,13 +137,11 @@ calc_have_rect (GeglOperation *operation)
if (status)
{
g_warning ("calc have rect of %s failed", self->path);
return FALSE;
}
}
gegl_operation_set_have_rect (operation, 0, 0, width, height);
return TRUE;
result.w = width;
result.h = height;
return result;
}
static gint
......
......@@ -73,20 +73,17 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *self = GEGL_CHANT_INSTANCE (operation);
gint width, height;
load_cache (self);
width = GEGL_BUFFER (self->cached)->width;
height = GEGL_BUFFER (self->cached)->height;
gegl_operation_set_have_rect (operation, 0, 0, width, height);
return TRUE;
result.w = GEGL_BUFFER (self->cached)->width;
result.h = GEGL_BUFFER (self->cached)->height;
return result;
}
static void dispose (GObject *gobject)
......
......@@ -64,11 +64,11 @@ evaluate (GeglOperation *operation,
return TRUE;
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
gegl_operation_set_have_rect (operation, -1000000, -1000000, 2000000, 2000000);
return TRUE;
GeglRect result = {-10000000,-10000000,20000000,20000000};
return result;
}
#endif
......@@ -92,16 +92,11 @@ evaluate (GeglOperation *operation,
return TRUE;
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
/*OpNoise *self = (OpNoise*)(operation);*/
gegl_operation_set_have_rect (operation, -1000000, -1000000, 2000000, 2000000);
return TRUE;
GeglRect result = {-10000000,-10000000, 20000000, 20000000};
return result;
}
#endif
......@@ -94,14 +94,11 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
/*OpNoise *self = (OpNoise*)(operation);*/
gegl_operation_set_have_rect (operation, -1000000, -1000000, 2000000, 2000000);
return TRUE;
GeglRect result = {-10000000, -10000000, 20000000, 20000000};
return result;
}
static void dispose (GObject *gobject)
......
......@@ -144,21 +144,24 @@ evaluate (GeglOperation *operation,
}
static gboolean
calc_have_rect (GeglOperation *operation)
static GeglRect
defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
ChantInstance *self = GEGL_CHANT_INSTANCE (operation);
gdouble width, height;
gint status = FALSE;
{ /* get extents */
cairo_t *cr;
gdouble width, height;
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1, 1);
cr = cairo_create (surface);
cairo_set_font_size (cr, self->size);
text_layout_text (cr, self->string, 0, &width, &height);
result.w = width;
result.h = height;
cairo_destroy (cr);
cairo_surface_destroy (surface);
......@@ -167,12 +170,12 @@ calc_have_rect (GeglOperation *operation)
if (status)
{
g_warning ("calc have rect of text '%s' failed", self->string);
return FALSE;
}
else
{
}
gegl_operation_set_have_rect (operation, 0, 0, width, height);
return TRUE;
return result;
}
static void dispose (GObject *gobject)
......
......@@ -60,7 +60,7 @@ static gboolean is_intermediate_node (OpAffine *affine);
static gboolean is_composite_node (OpAffine *affine);
static void get_source_matrix (OpAffine *affine,
Matrix3 output);
static gboolean calc_have_rect (GeglOperation *op);
static GeglRect defined_region (GeglOperation *op);
static gboolean calc_need_rect (GeglOperation *op);
static gboolean evaluate (GeglOperation *op,
const gchar *output_prop);
......@@ -119,7 +119,7 @@ op_affine_class_init (OpAffineClass *klass)
gobject_class->set_property = set_property;
gobject_class->get_property = get_property;
op_class->calc_have_rect = calc_have_rect;
op_class->defined_region = defined_region;
op_class->calc_need_rect = calc_need_rect;
op_class->categories = "geometry";
......@@ -311,8 +311,8 @@ get_source_matrix (OpAffine *affine,
matrix3_copy (output, OP_AFFINE (source)->matrix);
}
static gboolean
calc_have_rect (GeglOperation *op)
static GeglRect
defined_region (GeglOperation *op)
{
OpAffine *affine = (OpAffine *) op;
OpAffineClass *klass = OP_AFFINE_GET_CLASS (affine);
......@@ -339,10 +339,7 @@ calc_have_rect (GeglOperation *op)
if (is_intermediate_node (affine) ||
matrix3_is_identity (affine->matrix))