История изменений
Исправление Demige, (текущая версия) :
Последнюю скомпилил. Работает. Вставил ещё в плагин поле с выбором количества цветов из активной палитры.
#!/usr/bin/python
from gimpfu import *
import tempfile, subprocess, os
def plugin_main(timg, tdrawable, amount,colors):
sfx = '.png'
pfx = 'gimp_convert_to_paletted_plugin'
tmpifn = tempfile.mktemp(sfx, pfx)
tmpofn = tempfile.mktemp(sfx, pfx)
tmppfn = tempfile.mktemp(sfx, pfx)
pal = pdb.gimp_context_get_palette()
num_colors, colors = pdb.gimp_palette_get_colors(pal)
tempimage = pdb.gimp_image_duplicate(timg)
tempdrawable = pdb.gimp_layer_new_from_visible(tempimage, tempimage, "visible")
pdb.gimp_file_save(tempimage, tempdrawable, tmpifn, "")
pdb.gimp_image_delete(tempimage)
tempimage = pdb.gimp_image_new(num_colors, 1, 0)
tempdrawable = pdb.gimp_layer_new(tempimage, num_colors, 1, 1, "pal", 100, 0)
for x,c in zip(xrange(num_colors), colors):
pdb.gimp_drawable_set_pixel(tempdrawable, x, 0, 4, c)
pdb.gimp_file_save(tempimage, tempdrawable, tmppfn, "")
pdb.gimp_image_delete(tempimage)
colors=16
cmd = 'convert %s -dither floyd-steinberg -define dither:diffusion-amount=%i%% -remap %s -colors %i %s' % \
(tmpifn, amount, tmppfn, colors, tmpofn)
p = subprocess.Popen(cmd.split(), shell=False)
p.communicate()
layer = pdb.gimp_file_load_layer(timg, tmpofn)
pdb.gimp_image_insert_layer(timg, layer, None, -1)
for fn in [tmpifn, tmpofn, tmppfn]:
os.remove(fn)
register(
"python_fu_convert_to_paletted",
"Convert to paletted",
"Convert to paletted",
"Anonymous",
"Anonymous",
"2019",
"<Image>/Image/Convert to paletted...",
"RGB*",
[(PF_SLIDER, "diffusion_amount", "Diffusion Amount, %:", 50, [0, 100, 1]),
(PF_INT, "colors", "Colors count", "16")],
[],
plugin_main)
Таким способом можно кстати и pixel-art в плугин засовать.
Исходная версия Demige, :
Последнюю скомпилил. Работает. Вставил ещё в плагин поле с выбором количества цветов из активной палитры.
#!/usr/bin/python
from gimpfu import *
import tempfile, subprocess, os
def plugin_main(timg, tdrawable, amount,colors):
sfx = '.png'
pfx = 'gimp_convert_to_paletted_plugin'
tmpifn = tempfile.mktemp(sfx, pfx)
tmpofn = tempfile.mktemp(sfx, pfx)
tmppfn = tempfile.mktemp(sfx, pfx)
pal = pdb.gimp_context_get_palette()
num_colors, colors = pdb.gimp_palette_get_colors(pal)
tempimage = pdb.gimp_image_duplicate(timg)
tempdrawable = pdb.gimp_layer_new_from_visible(tempimage, tempimage, "visible")
pdb.gimp_file_save(tempimage, tempdrawable, tmpifn, "")
pdb.gimp_image_delete(tempimage)
tempimage = pdb.gimp_image_new(num_colors, 1, 0)
tempdrawable = pdb.gimp_layer_new(tempimage, num_colors, 1, 1, "pal", 100, 0)
for x,c in zip(xrange(num_colors), colors):
pdb.gimp_drawable_set_pixel(tempdrawable, x, 0, 4, c)
pdb.gimp_file_save(tempimage, tempdrawable, tmppfn, "")
pdb.gimp_image_delete(tempimage)
colors=16
cmd = 'convert %s -dither floyd-steinberg -define dither:diffusion-amount=%i%% -remap %s -colors %i %s' % \
(tmpifn, amount, tmppfn, colors, tmpofn)
p = subprocess.Popen(cmd.split(), shell=False)
p.communicate()
layer = pdb.gimp_file_load_layer(timg, tmpofn)
pdb.gimp_image_insert_layer(timg, layer, None, -1)
for fn in [tmpifn, tmpofn, tmppfn]:
os.remove(fn)
register(
"python_fu_convert_to_paletted",
"Convert to paletted",
"Convert to paletted",
"Anonymous",
"Anonymous",
"2019",
"<Image>/Image/Convert to paletted...",
"RGB*",
[(PF_SLIDER, "diffusion_amount", "Diffusion Amount, %:", 50, [0, 100, 1]),
(PF_INT, "colors", "Colors count", "16")],
[],
plugin_main)