gboolean gegl_can_do_inplace_processing (GeglOperation *operation, GeglBuffer *input, const GeglRectangle *result) { if (!input) return FALSE; if (gegl_object_get_has_forked (G_OBJECT (input))) return FALSE; if (gegl_buffer_get_format (input) == gegl_operation_get_format (operation, "output") && gegl_rectangle_contains (gegl_buffer_get_extent (input), result)) return TRUE; return FALSE; }
static gboolean gegl_crop_process (GeglOperation *operation, GeglOperationContext *context, const gchar *output_prop, const GeglRectangle *result, gint level) { GeglProperties *o = GEGL_PROPERTIES (operation); GeglBuffer *input; gboolean success = FALSE; GeglRectangle extent; extent.x = o->x; extent.y = o->y; extent.width = o->width; extent.height = o->height; input = gegl_operation_context_get_source (context, "input"); if (input) { GeglBuffer *output = gegl_buffer_create_sub_buffer (input, &extent); if (gegl_object_get_has_forked (G_OBJECT (input))) gegl_object_set_has_forked (G_OBJECT (output)); gegl_operation_context_take_object (context, "output", G_OBJECT (output)); g_object_unref (input); success = TRUE; } else { g_warning ("%s got NULL input pad", gegl_node_get_operation (operation->node)); } return success; }
static gboolean gegl_affine_process (GeglOperation *operation, GeglOperationContext *context, const gchar *output_prop, const GeglRectangle *result) { GeglBuffer *input; GeglBuffer *output; GeglMatrix3 matrix; OpAffine *affine = (OpAffine *) operation; gegl_affine_create_composite_matrix (affine, &matrix); if (gegl_affine_is_intermediate_node (affine) || gegl_matrix3_is_identity (&matrix)) { /* passing straight through (like gegl:nop) */ input = gegl_operation_context_get_source (context, "input"); if (!input) { g_warning ("transform received NULL input"); return FALSE; } gegl_operation_context_take_object (context, "output", G_OBJECT (input)); } else if (gegl_affine_matrix3_allow_fast_translate (&matrix) || (gegl_matrix3_is_translate (&matrix) && ! strcmp (affine->filter, "nearest"))) { /* doing a buffer shifting trick, (enhanced nop) */ input = gegl_operation_context_get_source (context, "input"); output = g_object_new (GEGL_TYPE_BUFFER, "source", input, "shift-x", (int)-matrix.coeff[0][2], "shift-y", (int)-matrix.coeff[1][2], "abyss-width", -1, /* turn of abyss (relying on abyss of source) */ NULL); if (gegl_object_get_has_forked (input)) gegl_object_set_has_forked (output); gegl_operation_context_take_object (context, "output", G_OBJECT (output)); if (input != NULL) g_object_unref (input); } else if (gegl_affine_matrix3_allow_fast_reflect_x (&matrix)) { GeglRectangle src_rect; GeglSampler *sampler; GeglRectangle context_rect; input = gegl_operation_context_get_source (context, "input"); if (!input) { g_warning ("transform received NULL input"); return FALSE; } output = gegl_operation_context_get_target (context, "output"); src_rect = gegl_operation_get_required_for_output (operation, "output", result); src_rect.y += 1; sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"), gegl_sampler_type_from_string (affine->filter)); context_rect = *gegl_sampler_get_context_rect (sampler); src_rect.width -= context_rect.width; src_rect.height -= context_rect.height; gegl_affine_fast_reflect_x (output, input, result, &src_rect); g_object_unref (sampler); if (input != NULL) g_object_unref (input); } else if (gegl_affine_matrix3_allow_fast_reflect_y (&matrix)) { GeglRectangle src_rect; GeglSampler *sampler; GeglRectangle context_rect; input = gegl_operation_context_get_source (context, "input"); if (!input) { g_warning ("transform received NULL input"); return FALSE; } output = gegl_operation_context_get_target (context, "output"); src_rect = gegl_operation_get_required_for_output (operation, "output", result); src_rect.x += 1; sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"), gegl_sampler_type_from_string (affine->filter)); context_rect = *gegl_sampler_get_context_rect (sampler); src_rect.width -= context_rect.width; src_rect.height -= context_rect.height; gegl_affine_fast_reflect_y (output, input, result, &src_rect); g_object_unref (sampler); if (input != NULL) g_object_unref (input); } else { /* for all other cases, do a proper resampling */ GeglSampler *sampler; input = gegl_operation_context_get_source (context, "input"); output = gegl_operation_context_get_target (context, "output"); sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"), gegl_sampler_type_from_string (affine->filter)); affine_generic (output, input, &matrix, sampler); g_object_unref (sampler); if (input != NULL) g_object_unref (input); } return TRUE; }