title: Gimp, Script-Fu: How can I set a value in the colormap directly
body: <p>I have a Scriptfu script written in Python for Gimp which applies several steps on an existing image and converts it to an indexed image in the process.  The lightest color in the resulting image is always nearly white; I want to set it to <em>exactly</em> white.  Conveniently, that lightest color is always the topmost color in the colormap of the indexed image, so I just want to set the topmost color in the colormap to white.</p>
  
  <p>I have found nothing in the API description on how to manipulate the colormap (i. e. colors therein), so currently that step I always do manually (Windows → Dockable Dialogs → Colormap → Click on the topmost color → enter "ffffff" in the text widget → close dialog).  But of course the whole idea of the Scriptfu stuff is to automate all steps, not just a few.</p>
  
  <p>Can anybody tell me how to access the colormap from a Python Scriptfu script?</p>
  
  <p>Here is my current code (which does not even attempt to perform that last step, due to lack of ideas on how to do it):</p>
  
  <pre><code>#!/usr/bin/env python
  
  """
  paperwhite -- a gimp plugin (place me at ~/.gimp-2.6/plug-ins/ and give
                me execution permissions) for making fotographs of papers
                (documents) white in the background
  """
  
  import math
  from 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 as PNG now!")
  
  register(
          "python_fu_paperwhite",
          "Make the paper of the photographed paper document white.",
          "Make the paper of the photographed paper document white.",
          "Alfe Berlin",
          "Alfe Berlin",
          "2012-2012",
          "&lt;Image&gt;/Filters/Artistic/Paperw_hite...",
          "RGB*, GRAY*",
          [
                  (PF_INT, "radius", "Radius", 12),
          ],
          [],
          python_paperwhite)
  
  main()
  </code></pre>