简体   繁体   中英

Weighted Blend in GEGL library

Can someone post a code example on how to use the "gegl:weighted-blend" operations in c Code not gegl (terminal) with xml files (filters) .
I started using gegl library, it fit my needs perfectly, but I can't seem to find a good documentation (the website is good but not detailed). Is there a forum or a place where you can ask for help in programming with the gegl library?
If it helps here is my trial of using gegl:weighted-blend :

GeglNode *gegl = gegl_node_new ();

GeglNode *display     = gegl_node_create_child (gegl, "gegl:display");
GeglNode *over        = gegl_node_new_child (gegl,"operation", "gegl:over",NULL);
GeglNode *c2g         = gegl_node_new_child (gegl,"operation", "gegl:c2g",NULL);
GeglNode *blur        = gegl_node_new_child (gegl,"operation", "gegl:gaussian-blur","std-    dev-x",1.0,"std-dev-y",1.0,NULL);


GeglNode *img         = gegl_node_new_child (gegl,"operation", "gegl:load","path","test.jpg",NULL);
GeglBuffer *buffer    = NULL;
GeglNode *sink        = gegl_node_new_child (gegl,"operation", "gegl:buffer-sink","buffer", &buffer,NULL);
gegl_node_link_many (img , c2g , sink, NULL);
gegl_node_process (sink);
GeglNode *blend       = gegl_node_new_child (gegl,"operation", "gegl:weighted-blend","aux",buffer,"value",0.0,NULL);

gegl_node_link_many(img, blend, display, NULL);
//gegl_node_process (blend);
//gegl_node_link_many(blend, display, NULL);
gegl_node_process (display);

A bit info, in this example I have a test.jpg image. I applied a c2g filter on it, then I tried to blend it with itself without the c2g filter.
The c2g and gegl:buffer-sink parts work, meaning I can display the image with grayscale and the buffer is filled with the image in grayscale colors.
What am I doing wrong? Because the output of this with the combination of gegl:weighted-blend is a blank screen .

There are a few small issues with your code right now.

  1. You're connecting to the "aux" pad of the weighted-blend operation incorrectly. The correct way to connect the c2g output to the weighted-blend input is gegl_node_connect_to (c2g, "output", blend, "aux"); . Right now you're trying to set it as a property of the weighted-blend node, but input pads (images) and properties are different concepts in gegl.
  2. The weighted-blend node does not have a value property, and using it might be tricky in this case, if you need to adjust the amount of blending. A better way to construct the graph would be to apply gegl:opacity to set the transparency of the top image and then use svg:src-over to blend them together (which is roughly what the layer stack in gimp does).

So, fixing your example might look like this:

GeglNode *gegl = gegl_node_new ();

GeglNode *img     = gegl_node_new_child (gegl,
                                         "operation", "gegl:load",
                                         "path", "test.jpg",
                                         NULL);

GeglNode *save    = gegl_node_new_child (gegl,
                                         "operation", "gegl:save",
                                         "path","result.jpg",
                                         NULL);

GeglNode *over    = gegl_node_new_child (gegl,
                                         "operation", "gegl:over",
                                         NULL);

GeglNode *c2g     = gegl_node_new_child (gegl,
                                         "operation", "gegl:c2g",
                                         NULL);

GeglNode *opacity = gegl_node_new_child (gegl,
                                         "operation", "gegl:opacity",
                                         "value", 0.4, NULL);

GeglNode *blend   = gegl_node_new_child (gegl,
                                         "operation", "svg:src-over",
                                         NULL);

gegl_node_link_many (img, c2g, opacity, NULL);
gegl_node_connect_to (opacity, "output", blend, "aux");
gegl_node_link_many (img, blend, save, NULL);

gegl_node_process (save);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM