python - Gimp, Script-Fu: How can I set a value in the colormap directly -
i have scriptfu script written in python gimp applies several steps on existing image , converts indexed image in process. lightest color in resulting image white; want set exactly white. conveniently, lightest color topmost color in colormap of indexed image, want set topmost color in colormap white.
i have found nothing in api description on how manipulate colormap (i. e. colors therein), step manually (windows → dockable dialogs → colormap → click on topmost color → enter "ffffff" in text widget → close dialog). of course whole idea of scriptfu stuff automate steps, not few.
can tell me how access colormap python scriptfu script?
here current code (which not attempt perform last step, due lack of ideas on how it):
#!/usr/bin/env python """ paperwhite -- gimp plugin (place me @ ~/.gimp-2.6/plug-ins/ , give me execution permissions) making fotographs of papers (documents) white in background """ import math gimpfu import * def python_paperwhite(timg, tdrawable, radius=12): layer = tdrawable.copy() timg.add_layer(layer) layer.mode = divide_mode pdb.plug_in_despeckle(timg, layer, radius, 2, 7, 248) timg.flatten() pdb.gimp_levels(timg.layers[0], 0, 10, 230, 1.0, 0, 255) pdb.gimp_image_convert_indexed(timg, no_dither, make_palette, 16, false, true, '') (bytescount, colormap) = pdb.gimp_image_get_colormap(timg) pdb.gimp_message("consider saving png now!") register( "python_fu_paperwhite", "make paper of photographed paper document white.", "make paper of photographed paper document white.", "alfe berlin", "alfe berlin", "2012-2012", "<image>/filters/artistic/paperw_hite...", "rgb*, gray*", [ (pf_int, "radius", "radius", 12), ], [], python_paperwhite) main()
just use pdb.gimp_image_get_colormap , pdb.gimp_image_set_colormap.
if entry want change indeed first, suffice write:
colormap = pdb.gimp_image_get_colormap(timg)[1] colormap = (255,255,255) + colormap[3:] pdb.gimp_image_set_colormap(timg, len(colormap), colormap)
Comments
Post a Comment