palettes.pdb 4.4 KB
Newer Older
1
# GIMP - The GNU Image Manipulation Program
2 3
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19

# "Perlized" from C source by Manish Singh <yosh@gimp.org>

sub palettes_refresh {
20
    $blurb = 'Refreshes current palettes. This function always succeeds.';
21 22

    $help = <<'HELP';
23 24
This procedure retrieves all palettes currently in the user's palette path
and updates the palette dialogs accordingly.
25 26
HELP

27
    &adrian_pdb_misc('1998');
28 29

    %invoke = (
30 31
        code => <<'CODE'
{
32
  gimp_data_factory_data_refresh (gimp->palette_factory, context);
33 34 35
}
CODE
    );
36 37
}

38 39 40 41 42
sub palettes_get_list {
    $blurb = 'Retrieves a list of all of the available palettes';

    $help = <<'HELP';
This procedure returns a complete listing of available palettes. Each name
43
returned can be used as input to the command gimp_context_set_palette().
44 45
HELP

46
    &rock_pdb_misc('2001');
47

48
    @inargs = (
49
	{ name => 'filter', type => 'string', null_ok => 1,
50 51 52
          desc => 'An optional regular expression used to filter the list' }
    );

53 54
    @outargs = (
        { name => 'palette_list', type => 'stringarray',
55
          desc => 'The list of palette names',
56
          array => { name => 'num_palettes',
57
                     desc => 'The number of palettes in the list' } }
58 59 60
    );

    %invoke = (
61
        headers => [ qw("core/gimpcontainer-filter.h") ],
62 63
        code    => <<'CODE'
{
64
  palette_list = gimp_container_get_filtered_name_array (gimp_data_factory_get_container (gimp->palette_factory),
65 66 67
                                                         filter, &num_palettes);
}
CODE
68 69 70
    );
}

71
sub palettes_get_palette {
72
    &std_pdb_deprecated ('gimp-context-get-palette');
73

74
    @outargs = (
75 76
	{ name => 'name', type => 'string', null_ok => 1,
	  desc => 'The palette name' },
77
	{ name => 'num_colors', type => 'int32',
78
	  desc => 'The palette num_colors' }
79 80 81
    );

    %invoke = (
82 83 84 85 86 87
        code => <<'CODE'
{
  GimpPalette *palette = gimp_context_get_palette (context);

  if (palette)
    {
88
      name       = g_strdup (gimp_object_get_name (palette));
89
      num_colors = gimp_palette_get_n_colors (palette);
90 91 92 93 94
    }
  else
    success = FALSE;
}
CODE
95 96 97 98
    );
}

sub palettes_get_palette_entry {
99
    &std_pdb_deprecated ('gimp-palette-entry-get-color');
100 101

    @inargs = (
102 103
	{ name => 'name', type => 'string', null_ok => 1,
	  desc => 'The palette name ("" means currently active palette)' },
104 105 106 107 108
        { name => 'entry_num', type => 'int32',
          desc => 'The entry to retrieve' }
    );

    @outargs = (
109
	{ name => 'actual_name', type => 'string',
110
	  desc => 'The palette name' },
111
	{ name => 'num_colors', type => 'int32',
112
	  desc => 'The palette num_colors' },
113 114
	{ name => 'color', type => 'color', void_ret => 1,
	  desc => 'The color requested' }
115 116 117
    );

    %invoke = (
118
	code => <<'CODE'
119
{
120 121
  GimpPalette *palette;

122
  if (name && strlen (name))
123
    palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
124
  else
125
    palette = gimp_context_get_palette (context);
126

127
  if (palette)
128
    {
129
      GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
130

131 132
      if (entry)
        {
133
          actual_name = g_strdup (gimp_object_get_name (palette));
134
          num_colors  = gimp_palette_get_n_colors (palette);
135
          color       = entry->color;
136
        }
137 138
      else
        success = FALSE;
139
    }
140 141
  else
    success = FALSE;
142 143 144 145 146
}
CODE
    );
}

147

148 149 150 151
@headers = qw(<string.h>
              "core/gimp.h"
              "core/gimpcontext.h"
              "core/gimpdatafactory.h"
152 153
              "core/gimppalette.h"
              "gimppdb-utils.h");
154

155 156 157 158
@procs = qw(palettes_refresh
            palettes_get_list
            palettes_get_palette
            palettes_get_palette_entry);
159

160 161 162
%exports = (app => [@procs], lib => [@procs]);

$desc = 'Palettes';
163 164 165
$doc_title = 'gimppalettes';
$doc_short_desc = 'Operations related to palettes.';
$doc_long_desc = 'Operations related to palettes.';
166 167

1;