mirror of https://github.com/GNOME/gimp.git
plug-ins: port the core of foggify plug-in.
There are 2 TODOs to take care of here. First, there is no GUI yet for the interactive mode which will just use the default values. Second, the color argument is not working yet because I had issues passing a GimpRGB as argument (ideally I should create a GimpParamRGB with gimp_param_spec_rgb(), but since we still have the pygobject bugs about manipulating GParamSpec data directly, I can't). Anyway it works with default values, which is already a good first step. :-)
This commit is contained in:
parent
605f349137
commit
cce5bbc344
|
@ -1,77 +0,0 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
# Gimp-Python - allows the writing of Gimp plugins in Python.
|
||||
# Copyright (C) 1997 James Henstridge <james@daa.com.au>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from gimpfu import *
|
||||
import time
|
||||
|
||||
gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
|
||||
|
||||
def foggify(img, layer, name, colour, turbulence, opacity):
|
||||
|
||||
gimp.context_push()
|
||||
img.undo_group_start()
|
||||
|
||||
if img.base_type is RGB:
|
||||
type = RGBA_IMAGE
|
||||
else:
|
||||
type = GRAYA_IMAGE
|
||||
fog = gimp.Layer(img, name,
|
||||
layer.width, layer.height, type, opacity, NORMAL_MODE)
|
||||
fog.fill(FILL_TRANSPARENT)
|
||||
img.insert_layer(fog)
|
||||
|
||||
gimp.set_background(colour)
|
||||
pdb.gimp_edit_fill(fog, FILL_BACKGROUND)
|
||||
|
||||
# create a layer mask for the new layer
|
||||
mask = fog.create_mask(0)
|
||||
fog.add_mask(mask)
|
||||
|
||||
# add some clouds to the layer
|
||||
pdb.plug_in_plasma(img, mask, int(time.time()), turbulence)
|
||||
|
||||
# apply the clouds to the layer
|
||||
fog.remove_mask(MASK_APPLY)
|
||||
|
||||
img.undo_group_end()
|
||||
gimp.context_pop()
|
||||
|
||||
register(
|
||||
"python-fu-foggify",
|
||||
N_("Add a layer of fog"),
|
||||
"Adds a layer of fog to the image.",
|
||||
"James Henstridge",
|
||||
"James Henstridge",
|
||||
"1999,2007",
|
||||
N_("_Fog..."),
|
||||
"RGB*, GRAY*",
|
||||
[
|
||||
(PF_IMAGE, "image", "Input image", None),
|
||||
(PF_DRAWABLE, "drawable", "Input drawable", None),
|
||||
(PF_STRING, "name", _("_Layer name"), _("Clouds")),
|
||||
(PF_COLOUR, "colour", _("_Fog color"), (240, 180, 70)),
|
||||
(PF_SLIDER, "turbulence", _("_Turbulence"), 1.0, (0, 10, 0.1)),
|
||||
(PF_SLIDER, "opacity", _("Op_acity"), 100, (0, 100, 1)),
|
||||
],
|
||||
[],
|
||||
foggify,
|
||||
menu="<Image>/Filters/Decor",
|
||||
domain=("gimp20-python", gimp.locale_directory)
|
||||
)
|
||||
|
||||
main()
|
|
@ -3,18 +3,20 @@
|
|||
SUBDIRS = \
|
||||
python-console
|
||||
|
||||
file_openrasterdir = $(gimpplugindir)/plug-ins/file-openraster
|
||||
file_openraster_SCRIPTS = file-openraster.py
|
||||
|
||||
foggifydir = $(gimpplugindir)/plug-ins/foggify
|
||||
foggify_SCRIPTS = foggify.py
|
||||
|
||||
palette_offsetdir = $(gimpplugindir)/plug-ins/palette-offset
|
||||
palette_offset_SCRIPTS = palette-offset.py
|
||||
|
||||
palette_to_gradientdir = $(gimpplugindir)/plug-ins/palette-to-gradient
|
||||
palette_to_gradient_SCRIPTS = palette-to-gradient.py
|
||||
|
||||
file_openrasterdir= $(gimpplugindir)/plug-ins/file-openraster
|
||||
file_openraster_SCRIPTS = file-openraster.py
|
||||
|
||||
# TODO: to be ported:
|
||||
## colorxhtml.py
|
||||
## foggify.py
|
||||
## gradients-save-as-css.py
|
||||
## histogram-export.py
|
||||
## palette-sort.py
|
||||
|
@ -32,6 +34,7 @@ endif
|
|||
|
||||
EXTRA_DIST = \
|
||||
file-openraster.py \
|
||||
foggify.py \
|
||||
palette-offset.py \
|
||||
palette-to-gradient.py
|
||||
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (C) 1997 James Henstridge <james@daa.com.au>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import gi
|
||||
gi.require_version('Gimp', '3.0')
|
||||
from gi.repository import Gimp
|
||||
from gi.repository import GObject
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gio
|
||||
import time
|
||||
import sys
|
||||
|
||||
import gettext
|
||||
_ = gettext.gettext
|
||||
def N_(message): return message
|
||||
|
||||
def foggify(procedure, run_mode, image, drawable, args, data):
|
||||
name = args.index(0)
|
||||
turbulence = args.index(1)
|
||||
opacity = args.index(2)
|
||||
if run_mode == Gimp.RunMode.INTERACTIVE:
|
||||
# TODO: add a GUI. This first port works just with default
|
||||
# values.
|
||||
color = Gimp.RGB()
|
||||
color.set(240.0, 180.0, 70.0)
|
||||
|
||||
Gimp.context_push()
|
||||
image.undo_group_start()
|
||||
|
||||
if image.base_type() is Gimp.ImageBaseType.RGB:
|
||||
type = Gimp.ImageType.RGBA_IMAGE
|
||||
else:
|
||||
type = Gimp.ImageType.GRAYA_IMAGE
|
||||
fog = Gimp.Layer.new(image, name,
|
||||
drawable.width(), drawable.height(), type, opacity,
|
||||
Gimp.LayerMode.NORMAL)
|
||||
fog.fill(Gimp.FillType.TRANSPARENT)
|
||||
image.insert_layer(fog, None, 0)
|
||||
|
||||
Gimp.context_set_background(color)
|
||||
fog.edit_fill(Gimp.FillType.BACKGROUND)
|
||||
|
||||
# create a layer mask for the new layer
|
||||
mask = fog.create_mask(0)
|
||||
fog.add_mask(mask)
|
||||
|
||||
# add some clouds to the layer
|
||||
args = Gimp.ValueArray.new(5)
|
||||
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
|
||||
args.insert(1, GObject.Value(Gimp.Image, image))
|
||||
args.insert(2, GObject.Value(Gimp.Drawable, mask))
|
||||
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
|
||||
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
|
||||
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
|
||||
|
||||
# apply the clouds to the layer
|
||||
fog.remove_mask(Gimp.MaskApplyMode.APPLY)
|
||||
fog.set_visible(True)
|
||||
|
||||
image.undo_group_end()
|
||||
Gimp.context_pop()
|
||||
|
||||
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
|
||||
|
||||
class Foggify (Gimp.PlugIn):
|
||||
## Parameters ##
|
||||
__gproperties__ = {
|
||||
"name": (str,
|
||||
_("Layer name"),
|
||||
_("Layer name"),
|
||||
_("Clouds"),
|
||||
GObject.ParamFlags.READWRITE),
|
||||
"color": (Gimp.RGB,
|
||||
_("Fog color"),
|
||||
_("Fog color"),
|
||||
GObject.ParamFlags.READWRITE),
|
||||
"turbulence": (float,
|
||||
_("Turbulence"),
|
||||
_("Turbulence"),
|
||||
0.0, 10.0, 1.0,
|
||||
GObject.ParamFlags.READWRITE),
|
||||
"opacity": (float,
|
||||
_("Opacity"),
|
||||
_("Opacity"),
|
||||
0.0, 100.0, 100.0,
|
||||
GObject.ParamFlags.READWRITE),
|
||||
}
|
||||
|
||||
## GimpPlugIn virtual methods ##
|
||||
def do_query_procedures(self):
|
||||
self.set_translation_domain("gimp30-python",
|
||||
Gio.file_new_for_path(Gimp.locale_directory()))
|
||||
|
||||
return [ 'python-fu-foggify' ]
|
||||
|
||||
def do_create_procedure(self, name):
|
||||
procedure = Gimp.ImageProcedure.new(self, name,
|
||||
Gimp.PDBProcType.PLUGIN,
|
||||
foggify, None)
|
||||
procedure.set_image_types("RGB*, GRAY*");
|
||||
procedure.set_documentation (N_("Add a layer of fog"),
|
||||
"Adds a layer of fog to the image.",
|
||||
name)
|
||||
procedure.set_menu_label(N_("_Fog..."))
|
||||
procedure.set_attribution("James Henstridge",
|
||||
"James Henstridge",
|
||||
"1999,2007")
|
||||
procedure.add_menu_path ("<Image>/Filters/Decor")
|
||||
|
||||
procedure.add_argument_from_property(self, "name")
|
||||
# TODO: add support for GBoxed values.
|
||||
#procedure.add_argument_from_property(self, "color")
|
||||
procedure.add_argument_from_property(self, "turbulence")
|
||||
procedure.add_argument_from_property(self, "opacity")
|
||||
return procedure
|
||||
|
||||
Gimp.main(Foggify.__gtype__, sys.argv)
|
Loading…
Reference in New Issue