3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19
gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
21
def make_gradient(palette, num_segments, num_colors):
22
gradient = pdb.gimp_gradient_new(palette)
23
pdb.gimp_gradient_segment_range_split_uniform(gradient, 0, -1, num_segments)
25
for color_number in range(0,num_segments):
26
if (color_number == num_colors-1):color_number_next = 0
27
else: color_number_next = color_number + 1
28
color_left = pdb.gimp_palette_entry_get_color(palette,
30
color_right = pdb.gimp_palette_entry_get_color(palette,
32
pdb.gimp_gradient_segment_set_left_color(gradient,
33
color_number, color_left,
35
pdb.gimp_gradient_segment_set_right_color(gradient,
36
color_number, color_right,
38
pdb.gimp_context_set_gradient(gradient)
42
def palette_to_gradient_repeating(palette):
43
num_colors = pdb.gimp_palette_get_info(palette)
44
num_segments = num_colors
45
return make_gradient(palette, num_segments, num_colors)
49
"python-fu-palette-to-gradient-repeating",
50
N_("Create a repeating gradient using colors from the palette"),
51
"Create a new repeating gradient using colors from the palette.",
52
"Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
55
N_("Palette to _Repeating Gradient"),
57
[(PF_PALETTE, "palette", _("Palette"), "")],
58
[(PF_GRADIENT, "new-gradient", "Result")],
59
palette_to_gradient_repeating,
61
domain=("gimp20-python", gimp.locale_directory)
65
def palette_to_gradient(palette):
66
num_colors = pdb.gimp_palette_get_info(palette)
67
num_segments = num_colors - 1
68
return make_gradient(palette, num_segments, num_colors)
71
"python-fu-palette-to-gradient",
72
N_("Create a gradient using colors from the palette"),
73
"Create a new gradient using colors from the palette.",
74
"Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
77
N_("Palette to _Gradient"),
79
[(PF_PALETTE, "palette", _("Palette"), "")],
80
[(PF_GRADIENT, "new-gradient", "Result")],
83
domain=("gimp20-python", gimp.locale_directory)