void select_color (GtkButton *widget, gpointer user_data) { GtkColorSelectionDialog* dialog = GTK_COLOR_SELECTION_DIALOG(gtk_color_selection_dialog_new("Select Color")); //todo put the old color selection in gint result = gtk_dialog_run(GTK_DIALOG(dialog)); // if(result == GTK_RESPONSE_OK) { select_color_info* info = (select_color_info*)user_data; GtkColorSelection* colsel = GTK_COLOR_SELECTION(dialog->colorsel); GdkColor* sel_color = malloc(sizeof(GdkColor)); gtk_color_selection_get_current_color(colsel, sel_color); GeglColor* color = gegl_color_new(NULL); gegl_color_set_rgba(color, (double)sel_color->red/65535.0, (double)sel_color->green/65535.0, (double)sel_color->blue/65535.0, (double)gtk_color_selection_get_current_alpha(colsel)/65535.0); free(sel_color); gegl_node_set(info->node, info->property, color, NULL); refresh_images(info->layer); } gtk_widget_destroy(GTK_WIDGET(dialog)); }
static gboolean paint_press (GtkWidget *widget, GdkEventButton *event) { if (event->button == 1) { vector = gegl_path_new (); over = gegl_node_new_child (gegl, "operation", "gegl:over", NULL); stroke = gegl_node_new_child (gegl, "operation", "gegl:path", "d", vector, "fill-opacity", 0.0, "stroke", gegl_color_new (COLOR), "stroke-width", LINEWIDTH, "stroke-hardness", HARDNESS, NULL); gegl_node_link_many (top, over, out, NULL); gegl_node_connect_to (stroke, "output", over, "aux"); gegl_path_append (vector, 'M', event->x, event->y); pen_down = TRUE; return TRUE; } return FALSE; }
static void gimp_gegl_tool_map (GimpImageMapTool *image_map_tool) { GimpGeglTool *tool = GIMP_GEGL_TOOL (image_map_tool); GParamSpec **pspecs; guint n_pspecs; gint i; if (! tool->config) return; pspecs = gegl_list_properties (tool->operation, &n_pspecs); for (i = 0; i < n_pspecs; i++) { GParamSpec *gegl_pspec = pspecs[i]; GParamSpec *gimp_pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (tool->config), gegl_pspec->name); if (gimp_pspec) { GValue value = { 0, }; g_value_init (&value, gimp_pspec->value_type); g_object_get_property (G_OBJECT (tool->config), gimp_pspec->name, &value); if (GIMP_IS_PARAM_SPEC_RGB (gimp_pspec)) { GeglColor *gegl_color = gegl_color_new (NULL); GimpRGB gimp_color; gimp_value_get_rgb (&value, &gimp_color); g_value_unset (&value); gegl_color_set_rgba (gegl_color, gimp_color.r, gimp_color.g, gimp_color.b, gimp_color.a); g_value_init (&value, gegl_pspec->value_type); g_value_take_object (&value, gegl_color); } gegl_node_set_property (image_map_tool->operation, gegl_pspec->name, &value); g_value_unset (&value); } } g_free (pspecs); }
GeglColor * gimp_gegl_color_new (const GimpRGB *rgb) { GeglColor *color; g_return_val_if_fail (rgb != NULL, NULL); color = gegl_color_new (NULL); gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), rgb); return color; }
gint main (gint argc, gchar **argv) { GeglNode *gegl, *sink; if (argc != 4) { g_print ("Usage: %s <input image> \"string\" <output image>\n\n", argv[0]); return -1; } g_thread_init (NULL); gegl_init (&argc, &argv); gegl = gegl_graph ( sink = gegl_node ("gegl:png-save", "path", argv[3], NULL, gegl_node ("gegl:over", NULL, gegl_node ("gegl:scale", "x", 0.4, "y", 0.4, NULL, gegl_node ("gegl:invert", NULL, gegl_node ("gegl:load", "path", argv[1], NULL ))), gegl_node ("gegl:translate", "x", 50.0, "y", 50.0, NULL, gegl_node ("gegl:dropshadow", "opacity", 1.0, "radius", 3.0, "x", 3.0, "y", 3.0, NULL, gegl_node ("gegl:text", "size", 40.0, "font", "sans bold", "string", argv[2], "color", gegl_color_new("green"), NULL )))))); gegl_node_process (sink); g_object_unref (gegl); gegl_exit (); return 0; }
static void pixelize_noalloc (GeglBuffer *input, GeglBuffer *output, const GeglRectangle *roi, const GeglRectangle *whole_region, GeglProperties *o) { gint start_x = block_index (roi->x, o->size_x) * o->size_x; gint start_y = block_index (roi->y, o->size_y) * o->size_y; gint x, y; gint off_shape_x, off_shape_y; GeglColor *color = gegl_color_new ("white"); GeglRectangle rect_shape; rect_shape.width = ceilf (o->size_x * (gfloat)o->ratio_x); rect_shape.height = ceilf (o->size_y * (gfloat)o->ratio_y); off_shape_x = floorf ((o->size_x - (gfloat)o->ratio_x * o->size_x) / 2.0f); off_shape_y = floorf ((o->size_y - (gfloat)o->ratio_y * o->size_y) / 2.0f); for (y = start_y; y < roi->y + roi->height; y += o->size_y) for (x = start_x; x < roi->x + roi->width; x += o->size_x) { GeglRectangle rect = {x, y, o->size_x, o->size_y}; gegl_rectangle_intersect (&rect, whole_region, &rect); if (rect.width < 1 || rect.height < 1) continue; mean_rectangle_noalloc (input, &rect, color); gegl_rectangle_intersect (&rect, roi, &rect); rect_shape.x = x + off_shape_x; rect_shape.y = y + off_shape_y; set_rectangle_noalloc (output, &rect, &rect_shape, color, o->norm); } g_object_unref (color); }
/* in attach we hook into graph adding the needed nodes */ static void attach (GeglOperation *operation) { GeglNode *gegl = operation->node; GeglNode *input, *output, *over, *translate, *opacity, *blur, *darken, *color; GeglColor *black_color = gegl_color_new ("rgb(0.0,0.0,0.0)"); input = gegl_node_get_input_proxy (gegl, "input"); output = gegl_node_get_output_proxy (gegl, "output"); over = gegl_node_new_child (gegl, "operation", "gegl:over", NULL); translate = gegl_node_new_child (gegl, "operation", "gegl:translate", NULL); opacity = gegl_node_new_child (gegl, "operation", "gegl:opacity", NULL); blur = gegl_node_new_child (gegl, "operation", "gegl:gaussian-blur", "clip-extent", FALSE, "abyss-policy", 0, NULL); darken = gegl_node_new_child (gegl, "operation", "gegl:src-in", NULL); color = gegl_node_new_child (gegl, "operation", "gegl:color", "value", black_color, NULL); g_object_unref (black_color); gegl_node_link_many (input, darken, blur, opacity, translate, over, output, NULL); gegl_node_connect_from (over, "aux", input, "output"); gegl_node_connect_from (darken, "aux", color, "output"); gegl_operation_meta_redirect (operation, "radius", blur, "std-dev-x"); gegl_operation_meta_redirect (operation, "radius", blur, "std-dev-y"); gegl_operation_meta_redirect (operation, "x", translate, "x"); gegl_operation_meta_redirect (operation, "y", translate, "y"); gegl_operation_meta_redirect (operation, "color", color, "value"); gegl_operation_meta_redirect (operation, "opacity", opacity, "value"); gegl_operation_meta_watch_nodes (operation, over, translate, opacity, blur, darken, color, NULL); }
static gboolean gvalue_from_string(GValue *value, GType target_type, GValue *dest_value) { const gchar *iip; /* Custom conversion from string */ if (!G_VALUE_HOLDS_STRING(value)) { return FALSE; } iip = g_value_get_string(value); if (g_type_is_a(target_type, G_TYPE_DOUBLE)) { gdouble d = g_ascii_strtod(iip, NULL); g_value_set_double(dest_value, d); } else if (g_type_is_a(target_type, G_TYPE_INT)) { gint i = g_ascii_strtoll(iip, NULL, 10); g_value_set_int(dest_value, i); } else if (g_type_is_a(target_type, G_TYPE_INT64)) { gint64 i = g_ascii_strtoll(iip, NULL, 10); g_value_set_int64(dest_value, i); } else if (g_type_is_a(target_type, GEGL_TYPE_COLOR)) { GeglColor *color = gegl_color_new(iip); if (!color || !GEGL_IS_COLOR(color)) { return FALSE; } g_value_set_object(dest_value, color); } else if (g_type_is_a(target_type, G_TYPE_ENUM)) { GEnumClass *klass = (GEnumClass *)g_type_class_ref(target_type); GEnumValue *val = g_enum_get_value_by_nick(klass, iip); g_return_val_if_fail(val, FALSE); g_value_set_enum(dest_value, val->value); g_type_class_unref((gpointer)klass); } else if (g_type_is_a(target_type, G_TYPE_BOOLEAN)) { gboolean b = g_ascii_strcasecmp("true", iip) == 0; g_value_set_boolean(dest_value, b); } else { return FALSE; } return TRUE; }
static gboolean test_operation (const char *operation_name) { gboolean result = FALSE; const Babl *format = babl_format ("RGBA u8"); const gint bpp = babl_format_get_bytes_per_pixel (format); const gint out_width = 5 + 10; const gint out_height = 5 + 10; guchar *output_with_abyss = gegl_malloc (out_width * out_height * bpp); guchar *output_no_abyss = gegl_malloc (out_width * out_height * bpp); GeglColor *upper_color = gegl_color_new ("rgb(0.2, 0.8, 0.2)"); GeglColor *lower_color = gegl_color_new ("rgb(0.0, 0.0, 0.0)"); GeglColor *transparent = gegl_color_new ("rgba(0.0, 0.0, 0.0, 0.0)"); { /* Using abyss */ GeglNode *ptn = gegl_node_new(); GeglNode *test_op, *upper_rect, *lower_rect; test_op = gegl_node_new_child (ptn, "operation", operation_name, NULL); upper_rect = gegl_node_new_child (ptn, "operation", "gegl:rectangle", "color", upper_color, "x", 5.0, "y", 5.0, "width", 10.0, "height", 10.0, NULL); lower_rect = gegl_node_new_child (ptn, "operation", "gegl:rectangle", "color", lower_color, "x", 0.0, "y", 0.0, "width", 10.0, "height", 10.0, NULL); gegl_node_connect_to (lower_rect, "output", test_op, "input"); gegl_node_connect_to (upper_rect, "output", test_op, "aux"); { int i; guchar *out = output_with_abyss; for (i = 0; i < out_height; i++) { gegl_node_blit (test_op, 1.0, GEGL_RECTANGLE (0, i, out_width, 1), format, out, GEGL_AUTO_ROWSTRIDE, 0); out += out_width * bpp; } } g_object_unref (ptn); } { /* Explicit transparency */ GeglNode *ptn = gegl_node_new(); GeglNode *test_op, *upper_rect, *lower_rect; GeglNode *upper_over, *lower_over; GeglNode *background; test_op = gegl_node_new_child (ptn, "operation", operation_name, NULL); background = gegl_node_new_child (ptn, "operation", "gegl:rectangle", "color", transparent, "x", 0.0, "y", 0.0, "width", 10.0 + 5.0, "height", 10.0 + 5.0, NULL); upper_rect = gegl_node_new_child (ptn, "operation", "gegl:rectangle", "color", upper_color, "x", 5.0, "y", 5.0, "width", 10.0, "height", 10.0, NULL); upper_over = gegl_node_new_child (ptn, "operation", "gegl:over", NULL); lower_rect = gegl_node_new_child (ptn, "operation", "gegl:rectangle", "color", lower_color, "x", 0.0, "y", 0.0, "width", 10.0, "height", 10.0, NULL); lower_over = gegl_node_new_child (ptn, "operation", "gegl:over", NULL); gegl_node_connect_to (lower_rect, "output", lower_over, "aux"); gegl_node_connect_to (upper_rect, "output", upper_over, "aux"); gegl_node_connect_to (background, "output", lower_over, "input"); gegl_node_connect_to (background, "output", upper_over, "input"); gegl_node_connect_to (lower_over, "output", test_op, "input"); gegl_node_connect_to (upper_over, "output", test_op, "aux"); { int i; guchar *out = output_no_abyss; for (i = 0; i < out_height; i++) { gegl_node_blit (test_op, 1.0, GEGL_RECTANGLE (0, i, out_width, 1), format, out, GEGL_AUTO_ROWSTRIDE, 0); out += out_width * bpp; } } g_object_unref (ptn); } if (0 == memcmp (output_with_abyss, output_no_abyss, out_width * out_height * bpp)) { printf ("."); fflush(stdout); result = TRUE; } else { printf ("\n %s ... FAIL\n", operation_name); result = FALSE; } if (!result) { GeglBuffer *linear; gchar *filename; filename = g_strconcat (operation_name, " - with abyss.png", NULL); linear = gegl_buffer_linear_new_from_data (output_with_abyss, format, GEGL_RECTANGLE (0, 0, out_width, out_height), GEGL_AUTO_ROWSTRIDE, NULL, NULL); dump_to_png (filename, linear); g_free (filename); g_object_unref (linear); filename = g_strconcat (operation_name, " - no abyss.png", NULL); linear = gegl_buffer_linear_new_from_data (output_no_abyss, format, GEGL_RECTANGLE (0, 0, out_width, out_height), GEGL_AUTO_ROWSTRIDE, NULL, NULL); dump_to_png (filename, linear); g_free (filename); g_object_unref (linear); } gegl_free (output_with_abyss); gegl_free (output_no_abyss); return result; }
int main(int argc, char *argv[]) { int result = SUCCESS; GeglNode *graph = NULL; GeglNode *color_in_graph = NULL; GeglNode *crop_in_graph = NULL; GeglNode *graph_output_proxy = NULL; GeglNode *crop_outside_graph = NULL; GeglRectangle roi = { 0, 0, 1, 1 }; guchar result_buffer[3] = { 0, 0, 0 }; GeglColor *color1 = NULL; GeglColor *color2 = NULL; /* Init */ g_thread_init (NULL); gegl_init (&argc, &argv); color1 = gegl_color_new ("rgb(1.0, 0.0, 1.0)"); color2 = gegl_color_new ("rgb(0.0, 0.0, 1.0)"); /* Construct graph */ graph = gegl_node_new (); color_in_graph = gegl_node_new_child (graph, "operation", "gegl:color", "value", color1, NULL); crop_in_graph = gegl_node_new_child (graph, "operation", "gegl:crop", "x", 0.0, "y", 0.0, "width", 1.0, "height", 1.0, NULL); graph_output_proxy = gegl_node_get_output_proxy (graph, "output"); gegl_node_link_many (color_in_graph, crop_in_graph, graph_output_proxy, NULL); /* Make sure the implicit connection to the graph output proxy works * by connecting an additional crop directly to the graph node */ crop_outside_graph = gegl_node_new_child (graph, "operation", "gegl:crop", "x", 0.0, "y", 0.0, "width", 1.0, "height", 1.0, NULL); gegl_node_connect_to (graph, "output", crop_outside_graph, "input"); /* Process the graph and make sure we get the expected result */ memset (result_buffer, 0, sizeof (result_buffer)); gegl_node_blit (crop_outside_graph, 1.0, &roi, babl_format ("RGB u8"), result_buffer, GEGL_AUTO_ROWSTRIDE, GEGL_BLIT_DEFAULT); if (!(result_buffer[RED] == 255 && result_buffer[GREEN] == 0 && result_buffer[BLUE] == 255)) { result = FAILURE; g_printerr ("Initial processing failed, you messed up GEGL pretty badly :("); goto abort; } /* Process the graph again with a different color and make sure we * get the expected result */ gegl_node_set (color_in_graph, "value", color2, NULL); memset (result_buffer, 0, sizeof (result_buffer)); gegl_node_blit (crop_outside_graph, 1.0, &roi, babl_format ("RGB u8"), result_buffer, GEGL_AUTO_ROWSTRIDE, GEGL_BLIT_DEFAULT); if (!(result_buffer[RED] == 0 && result_buffer[GREEN] == 0 && result_buffer[BLUE] == 255)) { result = FAILURE; g_printerr ("Second processing failed, i.e. changing color didn't work properly"); goto abort; } /* Process the graph again but without changing anything since this * puts some stress on the caching mechanisms */ memset (result_buffer, 0, sizeof (result_buffer)); gegl_node_blit (crop_outside_graph, 1.0, &roi, babl_format ("RGB u8"), result_buffer, GEGL_AUTO_ROWSTRIDE, GEGL_BLIT_DEFAULT); if (!(result_buffer[RED] == 0 && result_buffer[GREEN] == 0 && result_buffer[BLUE] == 255)) { result = FAILURE; g_printerr ("Third processing failed, looks like you messed up caching"); goto abort; } abort: /* Cleanup */ g_object_unref (graph); g_object_unref (color1); g_object_unref (color2); gegl_exit (); return result; }
static GeglBuffer * gradient_precalc_shapeburst (GimpImage *image, GimpDrawable *drawable, const GeglRectangle *region, gdouble dist, GimpProgress *progress) { GimpChannel *mask; GeglBuffer *dist_buffer; GeglBuffer *temp_buffer; GeglNode *shapeburst; gimp_progress_set_text (progress, _("Calculating distance map")); /* allocate the distance map */ dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); /* allocate the selection mask copy */ temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); mask = gimp_image_get_mask (image); /* If the image mask is not empty, use it as the shape burst source */ if (! gimp_channel_is_empty (mask)) { gint x, y, width, height; gint off_x, off_y; gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); /* copy the mask to the temp mask */ gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), GEGL_RECTANGLE (x + off_x, y + off_y, width, height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); } else { /* If the intended drawable has an alpha channel, use that */ if (gimp_drawable_has_alpha (drawable)) { const Babl *component_format; component_format = babl_format ("A float"); /* extract the aplha into the temp mask */ gegl_buffer_set_format (temp_buffer, component_format); gegl_buffer_copy (gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (region->x, region->y, region->width, region->height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gegl_buffer_set_format (temp_buffer, NULL); } else { GeglColor *white = gegl_color_new ("white"); /* Otherwise, just fill the shapeburst to white */ gegl_buffer_set_color (temp_buffer, NULL, white); g_object_unref (white); } } shapeburst = gegl_node_new_child (NULL, "operation", "gimp:shapeburst", "normalize", TRUE, NULL); gimp_gegl_progress_connect (shapeburst, progress, NULL); gimp_gegl_apply_operation (temp_buffer, NULL, NULL, shapeburst, dist_buffer, NULL); g_object_unref (shapeburst); g_object_unref (temp_buffer); return dist_buffer; }
int main(int argc, char *argv[]) { gint result = SUCCESS; GeglRectangle rect1 = { 0, 0, 1, 1 }; GeglRectangle rect2 = { 1, 0, 1, 1 }; GeglRectangle rect3 = { 1, 1, 1, 1 }; GeglRectangle rect4 = { 0, 1, 1, 1 }; GeglColor *color_white = NULL; GeglColor *color_black = NULL; GeglNode *gegl = NULL; GeglNode *white = NULL; GeglNode *translate = NULL; GeglNode *over = NULL; GeglNode *black = NULL; GeglNode *crop = NULL; GeglNode *sink = NULL; GeglProcessor *processor = NULL; /* Convenient line to keep around: g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); */ gegl_init (&argc, &argv); color_white = gegl_color_new ("rgb(1.0, 1.0, 1.0)"); color_black = gegl_color_new ("rgb(0.0, 0.0, 0.0)"); gegl = gegl_node_new (); white = gegl_node_new_child (gegl, "operation", "gegl:color", "value", color_white, NULL); translate = gegl_node_new_child (gegl, "operation", "gegl:translate", "x", -50.0, "y", -20.0, NULL); over = gegl_node_new_child (gegl, "operation", "gegl:over", NULL); black = gegl_node_new_child (gegl, "operation", "gegl:color", "value", color_black, NULL); crop = gegl_node_new_child (gegl, "operation", "gegl:crop", "x", 10.0, "y", 10.0, "width", 100.0, "height", 100.0, NULL); sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", NULL); /* We build our graph for processing complexity, not for compositing * complexity */ gegl_node_link_many (black, over, sink, NULL); gegl_node_link_many (white, crop, translate, NULL); gegl_node_connect_to (translate, "output", over, "aux"); /* Create a processor */ processor = gegl_node_new_processor (sink, NULL); /* Do the tests */ if (!test_change_processor_rect_do_test (processor, &rect1, sink)) { g_printerr ("test-change-processor-rect: First compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect2, sink)) { g_printerr ("test-change-processor-rect: Second compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect3, sink)) { g_printerr ("test-change-processor-rect: Third compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect4, sink)) { g_printerr ("test-change-processor-rect: Fourth compare failed\n"); result = FAILURE; goto abort; } /* Cleanup */ abort: g_object_unref (processor); g_object_unref (color_white); g_object_unref (color_black); g_object_unref (gegl); gegl_exit (); return result; }
int main(int argc, char *argv[]) { gint result = SUCCESS; GeglRectangle rect1 = { 0, 0, 1, 1 }; GeglRectangle rect2 = { 1, 0, 1, 1 }; GeglRectangle rect3 = { 1, 1, 1, 1 }; GeglRectangle rect4 = { 0, 1, 1, 1 }; GeglColor *common_color = NULL; GeglNode *gegl = NULL; GeglNode *color = NULL; GeglNode *layer = NULL; GeglNode *text = NULL; GeglNode *sink = NULL; GeglProcessor *processor = NULL; /* Convenient line to keep around: g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); */ g_thread_init (NULL); gegl_init (&argc, &argv); common_color = gegl_color_new ("rgb(1.0, 1.0, 1.0)"); gegl = gegl_node_new (); color = gegl_node_new_child (gegl, "operation", "gegl:color", "value", common_color, NULL); layer = gegl_node_new_child (gegl, "operation", "gegl:layer", "x", 0.0, "y", 0.0, NULL); text = gegl_node_new_child (gegl, "operation", "gegl:text", "color", common_color, "string", "█████████████████████████", "size", 200.0, NULL); sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", NULL); /* We build our graph for processing complexity, not for compositing * complexity */ gegl_node_link_many (color, layer, sink, NULL); gegl_node_connect_to (text, "output", layer, "aux"); /* Create a processor */ processor = gegl_node_new_processor (sink, NULL); /* Do the tests */ if (!test_change_processor_rect_do_test (processor, &rect1, sink)) { g_printerr ("test-change-processor-rect: First compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect2, sink)) { g_printerr ("test-change-processor-rect: Second compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect3, sink)) { g_printerr ("test-change-processor-rect: Third compare failed\n"); result = FAILURE; goto abort; } if (!test_change_processor_rect_do_test (processor, &rect4, sink)) { g_printerr ("test-change-processor-rect: Fourth compare failed\n"); result = FAILURE; goto abort; } /* Cleanup */ abort: g_object_unref (processor); g_object_unref (common_color); g_object_unref (gegl); gegl_exit (); return result; }
static void standard_output (const gchar *op_name) { GeglNode *composition, *input, *aux, *operation, *crop, *output, *translate; GeglNode *background, *over; gchar *input_path = g_build_path (G_DIR_SEPARATOR_S, data_dir, "standard-input.png", NULL); gchar *aux_path = g_build_path (G_DIR_SEPARATOR_S, data_dir, "standard-aux.png", NULL); gchar *output_path = operation_to_path (op_name, FALSE); composition = gegl_node_new (); operation = gegl_node_create_child (composition, op_name); if (gegl_node_has_pad (operation, "output")) { input = gegl_node_new_child (composition, "operation", "gegl:load", "path", input_path, NULL); translate = gegl_node_new_child (composition, "operation", "gegl:translate", "x", 0.0, "y", 80.0, NULL); aux = gegl_node_new_child (composition, "operation", "gegl:load", "path", aux_path, NULL); crop = gegl_node_new_child (composition, "operation", "gegl:crop", "width", 200.0, "height", 200.0, NULL); output = gegl_node_new_child (composition, "operation", "gegl:png-save", "compression", 9, "path", output_path, NULL); background = gegl_node_new_child (composition, "operation", "gegl:checkerboard", "color1", gegl_color_new ("rgb(0.75,0.75,0.75)"), "color2", gegl_color_new ("rgb(0.25,0.25,0.25)"), NULL); over = gegl_node_new_child (composition, "operation", "gegl:over", NULL); if (gegl_node_has_pad (operation, "input")) gegl_node_link (input, operation); if (gegl_node_has_pad (operation, "aux")) { gegl_node_connect_to (aux, "output", translate, "input"); gegl_node_connect_to (translate, "output", operation, "aux"); } gegl_node_connect_to (background, "output", over, "input"); gegl_node_connect_to (operation, "output", over, "aux"); gegl_node_connect_to (over, "output", crop, "input"); gegl_node_connect_to (crop, "output", output, "input"); gegl_node_process (output); } g_free (input_path); g_free (aux_path); g_free (output_path); g_object_unref (composition); }
int main(int argc, char *argv[]) { int result = SUCCESS; GeglNode *graph = NULL; GeglNode *node = NULL; GeglColor *color = NULL; double x = -5; double y = -5; char *name = NULL; gboolean cache = TRUE; /* Init */ gegl_init (&argc, &argv); color = gegl_color_new ("rgb(0.0, 1.0, 0.0)"); graph = gegl_node_new (); node = gegl_node_new_child (graph, "operation", "gegl:color", "value", color, NULL); gegl_node_get (node, "operation", &name, NULL); if (!(!strcmp (name, "gegl:color"))) { result = FAILURE; printf ("operation: %s\n", name); goto abort; } gegl_node_set (node, "operation", "gegl:translate", "x", 50.0, "y", 100.0, NULL); gegl_node_get (node, "operation", &name, "x", &x, "y", &y, NULL); if (!(!strcmp (name, "gegl:translate") && (int)x == 50 && (int)y == 100)) { result = FAILURE; printf ("operation: %s\n", name); printf ("x, y: %f, %f\n", x, y); goto abort; } gegl_node_set (node, "x", 5.0, "y", 10.0, NULL); gegl_node_get (node, "y", &y, "operation", &name, "x", &x, NULL); if (!(!strcmp (name, "gegl:translate") && (int)x == 5 && (int)y == 10)) { result = FAILURE; printf ("operation: %s\n", name); printf ("x, y: %f, %f\n", x, y); goto abort; } gegl_node_set (node, "operation", "gegl:doesnt-exist", NULL); gegl_node_get (node, "operation", &name, NULL); if (!(!strcmp (name, "gegl:nop"))) { result = FAILURE; printf ("operation: %s\n", name); goto abort; } gegl_node_set (node, "operation", "gegl:nop", NULL); gegl_node_get (node, "operation", &name, NULL); if (!(!strcmp (name, "gegl:nop"))) { result = FAILURE; printf ("operation: %s\n", name); goto abort; } gegl_node_set (node, "operation", "gegl:translate", NULL); gegl_node_get (node, "operation", &name, "x", &x, "y", &y, NULL); if (!(!strcmp (name, "gegl:translate") && (int)x == 0 && (int)y == 0)) { result = FAILURE; printf ("operation: %s\n", name); printf ("x, y: %f, %f\n", x, y); goto abort; } gegl_node_set (node, "operation", "gegl:translate", "name", "Brian", "dont-cache", FALSE, NULL); gegl_node_get (node, "name", &name, "dont-cache", &cache, NULL); if (!(!strcmp (name, "Brian") && cache == FALSE)) { result = FAILURE; printf ("name: %s\n", name); printf ("cache: %d\n", cache); goto abort; } gegl_node_set (node, "dont-cache", TRUE, "name", "Steve", NULL); gegl_node_get (node, "name", &name, "dont-cache", &cache, NULL); if (!(!strcmp (name, "Steve") && cache == TRUE)) { result = FAILURE; printf ("name: %s\n", name); printf ("cache: %d\n", cache); goto abort; } abort: /* Cleanup */ g_object_unref (graph); g_object_unref (color); gegl_exit (); return result; }
gint main (gint argc, gchar **argv) { gegl_init (&argc, &argv); /* initialize the GEGL library */ /* license for this application, needed by fractal-explorer */ g_object_set (gegl_config (), "application-license", "GPL3", NULL); { /* instantiate a graph */ GeglNode *gegl = gegl_node_new (); /* This is the graph we're going to construct: .-----------. | display | `-----------' | .--------. | crop | `--------' | .--------. | over | `--------' | \ | \ | \ | | | .------. | | text | | `------' .------------------. | fractal-explorer | `------------------' */ /*< The image nodes representing operations we want to perform */ GeglNode *display = gegl_node_create_child (gegl, "gegl:ff-save"); GeglNode *crop = gegl_node_new_child (gegl, "operation", "gegl:crop", "width", 512.0, "height", 384.0, NULL); GeglNode *over = gegl_node_new_child (gegl, "operation", "gegl:over", NULL); GeglNode *text = gegl_node_new_child (gegl, "operation", "gegl:text", "size", 10.0, "color", gegl_color_new ("rgb(1.0,1.0,1.0)"), NULL); GeglNode *mandelbrot = gegl_node_new_child (gegl, "operation", "gegl:fractal-explorer", "shiftx", -256.0, NULL); gegl_node_link_many (mandelbrot, over, crop, display, NULL); gegl_node_connect_to (text, "output", over, "aux"); /* request that the save node is processed, all dependencies will * be processed as well */ { gint frame; gint frames = 200; for (frame=0; frame<frames; frame++) { gchar string[512]; gdouble t = frame * 1.0/frames; #define INTERPOLATE(min,max) ((max)*(t)+(min)*(1.0-t)) gdouble shiftx = INTERPOLATE(-256.0, -512.0); gdouble shifty = INTERPOLATE(0.0, -256.0); gdouble zoom = INTERPOLATE(300.0, 400.0); gegl_node_set (mandelbrot, "shiftx", shiftx, "shifty", shifty, "zoom", zoom, NULL); g_sprintf (string, "x=%1.3f y=%1.3f z=%1.3f", shiftx, shifty, zoom); gegl_node_set (text, "string", string, NULL); gegl_node_process (display); } } /* free resources used by the graph and the nodes it owns */ g_object_unref (gegl); } /* free resources globally used by GEGL */ gegl_exit (); return 0; }
static void set_background (GeglProperties *o, const GeglRectangle *rect, GeglBuffer *input, GeglBuffer *output, gint division_x, gint division_y, gint offset_x, gint offset_y) { const Babl *format = babl_format ("RGBA float"); if (o->background_type == GEGL_BACKGROUND_TYPE_TRANSPARENT) { GeglColor *color = gegl_color_new ("rgba(0.0,0.0,0.0,0.0)"); gegl_buffer_set_color (output, rect, color); g_object_unref (color); } else if (o->background_type == GEGL_BACKGROUND_TYPE_COLOR) { gegl_buffer_set_color (output, rect, o->bg_color); } else if (o->background_type == GEGL_BACKGROUND_TYPE_IMAGE) { gegl_buffer_copy (input, NULL, GEGL_ABYSS_NONE, output, NULL); } else { /* GEGL_BACKGROUND_TYPE_INVERT */ GeglBufferIterator *iter; GeglRectangle clear = *rect; if (o->fractional_type == GEGL_FRACTIONAL_TYPE_IGNORE) { clear.x = offset_x; clear.y = offset_y; clear.width = o->tile_width * (rect->width / o->tile_width); clear.height = o->tile_height * (rect->height / o->tile_height); } iter = gegl_buffer_iterator_new (input, &clear, 0, format, GEGL_ACCESS_READ, GEGL_ABYSS_NONE); gegl_buffer_iterator_add (iter, output, &clear, 0, format, GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE); while (gegl_buffer_iterator_next (iter)) { gfloat *src = iter->data[0]; gfloat *dst = iter->data[1]; glong n_pixels = iter->length; while (n_pixels--) { *dst++ = 1.f - *src++; *dst++ = 1.f - *src++; *dst++ = 1.f - *src++; *dst++ = *src++; } } } }
static GeglBuffer * gradient_precalc_shapeburst (GimpImage *image, GimpDrawable *drawable, const GeglRectangle *region, gdouble dist, GimpProgress *progress) { GimpChannel *mask; GeglBuffer *dist_buffer; GeglBuffer *temp_buffer; GeglNode *shapeburst; gdouble max; gfloat max_iteration; gimp_progress_set_text (progress, _("Calculating distance map")); /* allocate the distance map */ dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); /* allocate the selection mask copy * XXX: its format should be the same of gimp:shapeburst input buffer * porting the op to 'float' should be reflected here as well */ temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y u8")); mask = gimp_image_get_mask (image); /* If the image mask is not empty, use it as the shape burst source */ if (! gimp_channel_is_empty (mask)) { gint x, y, width, height; gint off_x, off_y; gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); /* copy the mask to the temp mask */ gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), GEGL_RECTANGLE (x + off_x, y + off_y, width, height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); } else { /* If the intended drawable has an alpha channel, use that */ if (gimp_drawable_has_alpha (drawable)) { const Babl *component_format; component_format = babl_format ("A u8"); /* extract the aplha into the temp mask */ gegl_buffer_set_format (temp_buffer, component_format); gegl_buffer_copy (gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (region->x, region->y, region->width, region->height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gegl_buffer_set_format (temp_buffer, NULL); } else { GeglColor *white = gegl_color_new ("white"); /* Otherwise, just fill the shapeburst to white */ gegl_buffer_set_color (temp_buffer, NULL, white); g_object_unref (white); } } shapeburst = gegl_node_new_child (NULL, "operation", "gimp:shapeburst", NULL); gimp_gegl_progress_connect (shapeburst, progress, NULL); gimp_gegl_apply_operation (temp_buffer, NULL, NULL, shapeburst, dist_buffer, NULL); gegl_node_get (shapeburst, "max-iterations", &max, NULL); g_object_unref (shapeburst); max_iteration = max; g_object_unref (temp_buffer); /* normalize the shapeburst with the max iteration */ if (max_iteration > 0) { GeglBufferIterator *iter; iter = gegl_buffer_iterator_new (dist_buffer, NULL, 0, NULL, GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE); while (gegl_buffer_iterator_next (iter)) { gint count = iter->length; gfloat *data = iter->data[0]; while (count--) *data++ /= max_iteration; } } return dist_buffer; }
static void set_background (GeglProperties *o, const GeglRectangle *rect, GeglBuffer *input, GeglBuffer *output, gint division_x, gint division_y, gint offset_x, gint offset_y) { const Babl *format; gfloat *dest_buf; gfloat *buf; gint x; gint y; gint index; gint clear_x0; gint clear_y0; gint clear_x1; gint clear_y1; format = babl_format ("RGBA float"); dest_buf = g_new0 (gfloat, 4 * rect->width * rect->height); if (o->fractional_type == GEGL_FRACTIONAL_TYPE_IGNORE) { clear_x0 = offset_x; clear_y0 = offset_y; clear_x1 = clear_x0 + o->tile_width * (rect->width / o->tile_width); clear_y1 = clear_y0 + o->tile_height * (rect->height / o->tile_height); } else { clear_x0 = 0; clear_y0 = 0; clear_x1 = clear_x0 + rect->width; clear_y1 = clear_y0 + rect->height; } switch (o->background_type) { case GEGL_BACKGROUND_TYPE_TRANSPARENT: gegl_buffer_set_color (output, rect, gegl_color_new ("rgba(0.0,0.0,0.0,0.0)")); break; case GEGL_BACKGROUND_TYPE_COLOR: gegl_buffer_set_color (output, rect, o->bg_color); break; case GEGL_BACKGROUND_TYPE_INVERT: gegl_buffer_get (input, rect, 1.0, format, dest_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); buf = dest_buf; for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { index = 4 * (y * rect->width + x); buf[index] = 1 - buf[index]; buf[index+1] = 1 - buf[index+1]; buf[index+2] = 1 - buf[index+2]; } } gegl_buffer_set (output, rect, 0, format, dest_buf, GEGL_AUTO_ROWSTRIDE); break; case GEGL_BACKGROUND_TYPE_IMAGE: gegl_buffer_get (input, rect, 1.0, format, dest_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (output, rect, 0, format, dest_buf, GEGL_AUTO_ROWSTRIDE); break; } g_free (dest_buf); }