home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / palette-offset.py < prev    next >
Encoding:
Python Source  |  2009-08-19  |  2.2 KB  |  62 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  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 3 of the License, or
  6. #   (at your option) any later version.
  7. #
  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.
  12. #
  13. #   You should have received a copy of the GNU General Public License
  14. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. from gimpfu import *
  17.  
  18. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  19.  
  20. def palette_offset(palette, amount):
  21.     #If palette is read only, work on a copy:
  22.     editable = pdb.gimp_palette_is_editable(palette)
  23.     if not editable:palette = pdb.gimp_palette_duplicate (palette)
  24.  
  25.     num_colors = pdb.gimp_palette_get_info (palette)
  26.  
  27.     tmp_entry_array = []
  28.     for i in xrange (num_colors):
  29.         tmp_entry_array.append  ((pdb.gimp_palette_entry_get_name (palette, i),
  30.                                   pdb.gimp_palette_entry_get_color (palette, i)))
  31.     for i in xrange (num_colors):
  32.         target_index = i + amount
  33.         if target_index >= num_colors:
  34.             target_index -= num_colors
  35.         elif target_index < 0:
  36.             target_index += num_colors
  37.         pdb.gimp_palette_entry_set_name (palette, target_index, tmp_entry_array[i][0])
  38.         pdb.gimp_palette_entry_set_color (palette, target_index, tmp_entry_array[i][1])
  39.     return palette
  40.  
  41.  
  42. register(
  43.     "python-fu-palette-offset",
  44.     N_("Offset the colors in a palette"),
  45.     "palette_offset (palette, amount) -> modified_palette",
  46.     "Joao S. O. Bueno Calligaris, Carol Spears",
  47.     "(c) Joao S. O. Bueno Calligaris",
  48.     "2004, 2006",
  49.     N_("_Offset Palette..."),
  50.     "",
  51.     [
  52.      (PF_PALETTE, "palette", _("Palette"), ""),
  53.      (PF_INT,     "amount",  _("Off_set"),  1),
  54.     ],
  55.     [(PF_PALETTE, "new-palette", "Result")],
  56.     palette_offset,
  57.     menu="<Palettes>",
  58.     domain=("gimp20-python", gimp.locale_directory)
  59.     )
  60.  
  61. main ()
  62.