예제 #1
0
def main():

    # Parse options

    parser = argparse.ArgumentParser(description='An argparse snippet.')

    parser.add_argument("--infile",  "-i",  help="the input file",  required=True, metavar="STRING")
    parser.add_argument("--outfile", "-o",  help="the output file", required=True, metavar="STRING")

    args = parser.parse_args()
    infile = args.infile
    outfile = args.outfile

    # GEGL ######################################

    gegl.init([])

    #print(gegl.list_operations())

    # Make nodes

    node1 = gegl.Node()
    node2 = gegl.Node() # png-load
    node3 = gegl.Node() # invert
    node4 = gegl.Node() # png-save

    # Set properties

    node2.set_property("operation", "gegl:png-load")
    node2.set_property("path", infile)

    node3.set_property("operation", "gegl:invert")

    node4.set_property("operation", "gegl:png-save")
    node4.set_property("path", outfile)

    # Make the graph

    node1.add_child(node2)
    node1.add_child(node3)
    node1.add_child(node4)

    node2.connect_to("output", node3, "input")
    node3.connect_to("output", node4, "input")

    # Process

    node4.process()
예제 #2
0
    def test_create_graph(self):
        graph = Gegl.Node()
        color_node = graph.create_child("gegl:color")
        crop_node = graph.create_child("gegl:crop")

        self.assertEqual(color_node.get_operation(), "gegl:color")
        self.assertEqual(crop_node.get_operation(), "gegl:crop")

        crop_rect = Gegl.Rectangle.new(10, 20, 5, 15)

        crop_node.set_property("x", crop_rect.x)
        crop_node.set_property("y", crop_rect.y)
        crop_node.set_property("width", crop_rect.width)
        crop_node.set_property("height", crop_rect.height)

        color_node.connect_to("output", crop_node, "input")

        self.assertTrue(crop_rect.equal(crop_node.get_bounding_box()))

        trans_node = graph.create_child("gegl:translate")

        crop_node.connect_to("output", trans_node, "input")

        self.assertTrue(crop_rect.equal(trans_node.get_bounding_box()))

        trans_node.set_property("x", 10)

        self.assertFalse(crop_rect.equal(trans_node.get_bounding_box()))

        trans_rect = crop_rect.dup()
        trans_rect.x += 10

        self.assertTrue(trans_rect.equal(trans_node.get_bounding_box()))
예제 #3
0
    def test_node_properties(self):
        graph = Gegl.Node()
        node  = graph.create_child("gegl:nop")

        self.assertEqual("gegl:nop", node.get_property("operation"))

        node.set_property("operation", "gegl:translate")
        self.assertEqual("gegl:translate", node.get_property("operation"))

        default_x = node.get_property("x")
        default_sampler = node.get_property("sampler")

        self.assertIsNotNone(default_x)
        self.assertIsNotNone(default_sampler)

        node.set_property("x", 10)
        self.assertEqual(node.get_property("x"), 10)

        node.set_property("x", -10)
        self.assertEqual(node.get_property("x"), -10)

        node.set_property("sampler", Gegl.SamplerType.NEAREST)
        self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.NEAREST)

        node.set_property("sampler", "linear")
        self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.LINEAR)

        node.set_property("operation", "gegl:nop")
        self.assertEqual("gegl:nop", node.get_property("operation"))

        node.set_property("operation", "gegl:translate")
        self.assertEqual("gegl:translate", node.get_property("operation"))

        self.assertEqual(node.get_property("x"), default_x)
        self.assertEqual(node.get_property("sampler"), default_sampler)
예제 #4
0
    def create_graph(self):
        self.graph = Gegl.Node()

        self.background_node = self.graph.create_child("gegl:rectangle")
        self.background_node.set_property('color', Gegl.Color.new("#fff"))

        self.over = self.graph.create_child("gegl:over")
        self.over2 = self.graph.create_child("gegl:over")
        self.opacity = self.graph.create_child("gegl:opacity")
        self.opacity.set_property('value', 0.5)
        self.over3 = self.graph.create_child("gegl:over")
        self.add_prev = self.graph.create_child("gegl:add")
        self.add_next = self.graph.create_child("gegl:add")
        self.color_prev = self.graph.create_child("gegl:rectangle")
        self.color_prev.set_property('color', Gegl.Color.new("#f00"))
        self.color_next = self.graph.create_child("gegl:rectangle")
        self.color_next.set_property('color', Gegl.Color.new("#00f"))

        self.background_node.connect_to("output", self.over, "input")
        self.over2.connect_to("output", self.over, "aux")
        self.opacity.connect_to("output", self.over2, "aux")
        self.over3.connect_to("output", self.opacity, "input")

        self.add_prev.connect_to("output", self.over3, "input")
        self.add_next.connect_to("output", self.over3, "aux")

        self.color_prev.connect_to("output", self.add_prev, "aux")
        self.color_next.connect_to("output", self.add_next, "aux")

        self.update_graph()
예제 #5
0
    def create_graph(self):
        self.graph = Gegl.Node()

        main_over = self.graph.create_child("gegl:over")
        self.nodes['main_over'] = main_over

        layer_overs = []
        for l in range(self.xsheet.layers_length):
            over = self.graph.create_child("gegl:over")
            layer_overs.append(over)

        self.nodes['layer_overs'] = layer_overs

        layer_overs[0].connect_to("output", main_over, "input")

        for over, next_over in zip(layer_overs, layer_overs[1:]):
            next_over.connect_to("output", over, "input")

        background_node = self.graph.create_child("gegl:rectangle")
        background_node.set_property('color', Gegl.Color.new("#fff"))
        background_node.connect_to("output", layer_overs[-1], "input")
        self.nodes['background'] = background_node

        layer_nodes = []
        for l in range(self.xsheet.layers_length):
            nodes = {}
            current_cel_over = self.graph.create_child("gegl:over")
            current_cel_over.connect_to("output", layer_overs[l], "aux")
            nodes['current_cel_over'] = current_cel_over

            onionskin_overs = []
            onionskin_opacities = []
            for i in range(self.onionskin_length):
                over = self.graph.create_child("gegl:over")
                onionskin_overs.append(over)

                opacity = self.graph.create_child("gegl:opacity")
                opacity.set_property('value', 1 - self.onionskin_falloff)
                onionskin_opacities.append(opacity)

                over.connect_to("output", opacity, "input")

                for over, next_opacity in zip(onionskin_overs,
                                              onionskin_opacities[1:]):
                    next_opacity.connect_to("output", over, "aux")

                onionskin_opacities[0].connect_to("output", current_cel_over,
                                                  "aux")

            nodes['onionskin'] = {}
            nodes['onionskin']['overs'] = onionskin_overs
            nodes['onionskin']['opacities'] = onionskin_opacities
            layer_nodes.append(nodes)

        self.nodes['layer_nodes'] = layer_nodes

        self.update_graph()
예제 #6
0
    def test_color_op(self):
      node = Gegl.Node()
      node.set_property("operation", "gegl:color")

      node.set_property("format", Gegl.format("RGBA u8"))
      self.assertEqual(Gegl.format("RGBA u8"), node.get_property("format"))
      self.assertEqual("RGBA u8", Gegl.format_get_name(node.get_property("format")))

      node.set_property("format", Gegl.format("RGBA float"))
      self.assertEqual(Gegl.format("RGBA float"), node.get_property("format"))
      self.assertEqual("RGBA float", Gegl.format_get_name(node.get_property("format")))
예제 #7
0
    def create_graph(self):
        self.graph = Gegl.Node()

        self.add = self.graph.create_child("gegl:add")

        self.color = self.graph.create_child("gegl:rectangle")
        self.color.set_property('color', Gegl.Color.new("#f00"))

        self.image_node = self.graph.create_child("gegl:load")
        self.image_node.set_property('path', 'test.png')

        self.color.connect_to("output", self.add, "aux")
        self.image_node.connect_to("output", self.add, "input")
예제 #8
0
    def __init__(self):

        self.brush = MyPaint.Brush()
        self.brush.from_defaults()
        self.gegl_surface = MyPaintGegl.TiledSurface()
        self.surface = self.gegl_surface.interface()

        self.graph = Gegl.Node()

        self.button_pressed = False
        self.last_event = (0.0, 0.0, 0.0)  # (x, y, time)

        self.init_ui()
예제 #9
0
    def __init__(self):
        self.brush_info = brush.BrushInfo(
            open('tests/brushes/charcoal.myb').read())
        self.brush_info.set_color_rgb((0.0, 0.0, 0.0))

        self.brush = brush.Brush(self.brush_info)
        self.surface = tiledsurface.GeglSurface()
        self.display_node = self.surface.get_node()
        self.graph = Gegl.Node()

        self.button_pressed = False
        self.last_event = (0.0, 0.0, 0.0)  # (x, y, time)

        self.init_ui()
예제 #10
0
    def __init__(self):

        self.brush = MyPaint.Brush()
        self.gegl_surface = MyPaintGegl.TiledSurface()
        self.surface = self.gegl_surface.interface()

        self.graph = Gegl.Node()
        self.display_node = self.graph.create_child("gegl:buffer-source")

        # FIXME: does not seem to have any effect
        print self.gegl_surface.get_buffer()
        #self.display_node.set_property("buffer", self.gegl_surface.get_buffer())

        self.button_pressed = False
        self.last_event = (0.0, 0.0, 0.0)  # (x, y, time)

        self.init_ui()
예제 #11
0
    def create_graph(self):
        self.graph = Gegl.Node()

        self.background_node = self.graph.create_child("gegl:rectangle")
        self.background_node.set_property('color', Gegl.Color.new("#fff"))

        self.over = self.graph.create_child("gegl:over")
        self.over2 = self.graph.create_child("gegl:over")
        self.opacity_prev1 = self.graph.create_child("gegl:opacity")
        self.opacity_prev1.set_property('value', 0.5)
        self.over3 = self.graph.create_child("gegl:over")
        self.opacity_prev2 = self.graph.create_child("gegl:opacity")
        self.opacity_prev2.set_property('value', 0.5)

        self.background_node.connect_to("output", self.over, "input")
        self.over2.connect_to("output", self.over, "aux")
        self.opacity_prev1.connect_to("output", self.over2, "aux")
        self.over3.connect_to("output", self.opacity_prev1, "input")
        self.opacity_prev2.connect_to("output", self.over3, "aux")

        self.update_graph()
예제 #12
0
    def run(self, procedure, args, data):
        runmode = args.index(0)

        if runmode == Gimp.RunMode.INTERACTIVE:
            gi.require_version('Gtk', '3.0')
            from gi.repository import Gtk
            gi.require_version('Gdk', '3.0')
            from gi.repository import Gdk

            Gimp.ui_init("palette-offset.py", False)

            dialog = Gimp.Dialog(use_header_bar=True,
                                 title=_("Exercise a goat (Python 3)"),
                                 role="goat-exercise-Python3")

            dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
            dialog.add_button("_Source", Gtk.ResponseType.APPLY)
            dialog.add_button("_OK", Gtk.ResponseType.OK)

            geometry = Gdk.Geometry();
            geometry.min_aspect = 0.5;
            geometry.max_aspect = 1.0;
            dialog.set_geometry_hints(None, geometry, Gdk.WindowHints.ASPECT);

            box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
            dialog.get_content_area().add(box)
            box.show()

            # XXX We use printf-style string for sharing the localized
            # string. You may just use recommended Python format() or
            # any style you like in your plug-ins.
            head_text=("This plug-in is an exercise in '%s' to "
                       "demo plug-in creation.\nCheck out the last "
                       "version of the source code online by clicking "
                       "the \"Source\" button." % ("Python 3"))
            label = Gtk.Label(label=head_text)
            box.pack_start(label, False, False, 1)
            label.show()

            contents = None
            # Get the file contents Python-style instead of using
            # GLib.file_get_contents() which returns bytes result, and
            # when converting to string, get newlines as text contents.
            # Rather than wasting time to figure this out, use Python
            # core API!
            with open(os.path.realpath(__file__), 'r') as f:
                contents = f.read()

            if contents is not None:
                scrolled = Gtk.ScrolledWindow()
                scrolled.set_vexpand (True)
                box.pack_start(scrolled, True, True, 1)
                scrolled.show()

                view = Gtk.TextView()
                view.set_wrap_mode(Gtk.WrapMode.WORD)
                view.set_editable(False)
                buffer = view.get_buffer()
                buffer.set_text(contents, -1)
                scrolled.add(view)
                view.show()

            while (True):
                response = dialog.run()
                if response == Gtk.ResponseType.OK:
                    dialog.destroy()
                    break
                elif response == Gtk.ResponseType.APPLY:
                    Gio.app_info_launch_default_for_uri(url, None)
                    continue
                else:
                    dialog.destroy()
                    return procedure.new_return_values(Gimp.PDBStatusType.CANCEL,
                                                       GLib.Error())

        # Parameters are not working fine yet because properties should
        # be Gimp.ImageID/Gimp.DrawableID but we can't make these with
        # pygobject. Until I figure out how to make it work, you could
        # uncomment the following lines instead of using the args value.
        #images = Gimp.image_list()
        #image_id = images[0]
        #drawable_id = Gimp.image_get_active_drawable(image_id)
        drawable_id = args.index(2)

        success, x, y, width, height = Gimp.drawable_mask_intersect(drawable_id);
        if success:
            Gegl.init(None);

            buffer = Gimp.drawable_get_buffer(drawable_id)
            shadow_buffer = Gimp.drawable_get_shadow_buffer(drawable_id)

            graph = Gegl.Node()
            input = graph.create_child("gegl:buffer-source")
            input.set_property("buffer", buffer)
            invert = graph.create_child("gegl:invert")
            output = graph.create_child("gegl:write-buffer")
            output.set_property("buffer", shadow_buffer)
            input.link(invert)
            invert.link(output)
            output.process()

            # This is extremely important in bindings, since we don't
            # unref buffers. If we don't explicitly flush a buffer, we
            # may left hanging forever. This step is usually done
            # during an unref().
            shadow_buffer.flush()

            Gimp.drawable_merge_shadow(drawable_id, True)
            Gimp.drawable_update(drawable_id, x, y, width, height)
            Gimp.displays_flush()
        else:
            retval = procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR,
                                                 GLib.Error("No pixels to process in the selected area."))

        return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
예제 #13
0
    def run(self, procedure, run_mode, image, drawable, args, run_data):
        if run_mode == Gimp.RunMode.INTERACTIVE:
            gi.require_version('Gtk', '3.0')
            from gi.repository import Gtk
            gi.require_version('Gdk', '3.0')
            from gi.repository import Gdk

            GimpUi.ui_init("palette-offset.py")

            dialog = GimpUi.Dialog(use_header_bar=True,
                                   title=_("Exercise a goat (Python 3)"),
                                   role="goat-exercise-Python3")

            dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
            dialog.add_button("_Source", Gtk.ResponseType.APPLY)
            dialog.add_button("_OK", Gtk.ResponseType.OK)

            geometry = Gdk.Geometry()
            geometry.min_aspect = 0.5
            geometry.max_aspect = 1.0
            dialog.set_geometry_hints(None, geometry, Gdk.WindowHints.ASPECT)

            box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
            dialog.get_content_area().add(box)
            box.show()

            # XXX We use printf-style string for sharing the localized
            # string. You may just use recommended Python format() or
            # any style you like in your plug-ins.
            head_text = ("This plug-in is an exercise in '%s' to "
                         "demo plug-in creation.\nCheck out the last "
                         "version of the source code online by clicking "
                         "the \"Source\" button." % ("Python 3"))
            label = Gtk.Label(label=head_text)
            box.pack_start(label, False, False, 1)
            label.show()

            contents = None
            # Get the file contents Python-style instead of using
            # GLib.file_get_contents() which returns bytes result, and
            # when converting to string, get newlines as text contents.
            # Rather than wasting time to figure this out, use Python
            # core API!
            with open(os.path.realpath(__file__), 'r') as f:
                contents = f.read()

            if contents is not None:
                scrolled = Gtk.ScrolledWindow()
                scrolled.set_vexpand(True)
                box.pack_start(scrolled, True, True, 1)
                scrolled.show()

                view = Gtk.TextView()
                view.set_wrap_mode(Gtk.WrapMode.WORD)
                view.set_editable(False)
                buffer = view.get_buffer()
                buffer.set_text(contents, -1)
                scrolled.add(view)
                view.show()

            while (True):
                response = dialog.run()
                if response == Gtk.ResponseType.OK:
                    dialog.destroy()
                    break
                elif response == Gtk.ResponseType.APPLY:
                    url = "https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/goat-exercises/goat-exercise-py3.py"
                    Gio.app_info_launch_default_for_uri(url, None)
                    continue
                else:
                    dialog.destroy()
                    return procedure.new_return_values(
                        Gimp.PDBStatusType.CANCEL, GLib.Error())

        intersect, x, y, width, height = drawable.mask_intersect()
        if intersect:
            Gegl.init(None)

            buffer = drawable.get_buffer()
            shadow_buffer = drawable.get_shadow_buffer()

            graph = Gegl.Node()
            input = graph.create_child("gegl:buffer-source")
            input.set_property("buffer", buffer)
            invert = graph.create_child("gegl:invert")
            output = graph.create_child("gegl:write-buffer")
            output.set_property("buffer", shadow_buffer)
            input.link(invert)
            invert.link(output)
            output.process()

            # This is extremely important in bindings, since we don't
            # unref buffers. If we don't explicitly flush a buffer, we
            # may left hanging forever. This step is usually done
            # during an unref().
            shadow_buffer.flush()

            drawable.merge_shadow(True)
            drawable.update(x, y, width, height)
            Gimp.displays_flush()

        return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS,
                                           GLib.Error())
예제 #14
0
#!/usr/bin/env python

from gi.repository import Gegl
import sys

if __name__ == '__main__':
    Gegl.init(sys.argv)

    ptn = Gegl.Node()

    # Disable caching on all child nodes
    ptn.set_property("dont-cache", True)

    # Create our background buffer. A gegl:color node would
    # make more sense, we just use a buffer here as an example.
    background_buffer = Gegl.Buffer.new("RGBA float", 246, -10, 276, 276)
    white = Gegl.Color.new("#FFF")
    background_buffer.set_color(background_buffer.get_extent(), white)

    src = ptn.create_child("gegl:load")
    src.set_property("path", "data/surfer.png")

    crop = ptn.create_child("gegl:crop")
    crop.set_property("x", 256)
    crop.set_property("y", 0)
    crop.set_property("width", 256)
    crop.set_property("height", 256)

    buffer_src = ptn.create_child("gegl:buffer-source")
    buffer_src.set_property("buffer", background_buffer)
예제 #15
0
    <params>
      <param name='width'>256</param>
      <param name='height'>128</param>
    </params>
  </node>
</gegl>
"""

if __name__ == '__main__':
    Gegl.init(sys.argv)

    if not check_operations(
        ["gegl:png-save", "gegl:text", "gegl:plasma", "gegl:translate"]):
        sys.exit(1)

    graph = Gegl.Node()

    # Load the graphs from xml, if they were in external files
    # we would use Gegl.Node.new_from_file() instead.
    lower_graph = Gegl.Node.new_from_xml(background_xml, "/")
    upper_graph = Gegl.Node.new_from_xml(text_xml, "/")

    # Add a reference from our main node to the xml graphs so they
    # can't go out of scope as long as "graph" is alive.
    graph.add_child(lower_graph)
    graph.add_child(upper_graph)

    # Center the upper graph on the lower graph
    text_bbox = upper_graph.get_bounding_box()
    background_bbox = lower_graph.get_bounding_box()