2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2002-03-17 13:52:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2002-03-17 13:52:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-03-17 13:52:25 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-03-17 13:52:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2002-03-17 13:52:25 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-04-20 13:25:55 +00:00
|
|
|
#include "actions-types.h"
|
2002-03-17 13:52:25 +00:00
|
|
|
|
2015-08-26 01:06:34 +02:00
|
|
|
#include "core/gimpchannel-select.h"
|
2004-05-13 15:50:55 +00:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-colormap.h"
|
|
|
|
|
2002-03-17 13:52:25 +00:00
|
|
|
#include "widgets/gimpcolormapeditor.h"
|
2019-03-17 23:13:34 +01:00
|
|
|
#include "widgets/gimpcolormapselection.h"
|
2002-03-17 13:52:25 +00:00
|
|
|
|
2004-05-13 15:50:55 +00:00
|
|
|
#include "actions.h"
|
2006-11-17 22:07:07 +00:00
|
|
|
#include "colormap-commands.h"
|
2002-03-17 13:52:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
colormap_edit_color_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2002-03-17 13:52:25 +00:00
|
|
|
{
|
2018-06-21 13:43:25 +02:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
|
2004-10-24 18:32:24 +00:00
|
|
|
|
2018-06-21 13:43:25 +02:00
|
|
|
gimp_colormap_editor_edit_color (editor);
|
2002-03-17 13:52:25 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 01:07:01 +02:00
|
|
|
void
|
|
|
|
colormap_delete_color_cmd_callback (GimpAction *action,
|
|
|
|
GVariant *value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
|
|
|
|
|
|
|
|
gimp_colormap_editor_delete_color (editor);
|
|
|
|
}
|
|
|
|
|
2003-09-19 11:40:12 +00:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
colormap_add_color_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2002-03-17 13:52:25 +00:00
|
|
|
{
|
2004-05-13 15:50:55 +00:00
|
|
|
GimpContext *context;
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2019-07-04 01:11:48 +02:00
|
|
|
gboolean background;
|
2004-05-13 15:50:55 +00:00
|
|
|
return_if_no_context (context, data);
|
2006-03-28 17:08:36 +00:00
|
|
|
return_if_no_image (image, data);
|
2004-05-13 15:50:55 +00:00
|
|
|
|
2019-07-04 01:11:48 +02:00
|
|
|
background = (gboolean) g_variant_get_int32 (value);
|
|
|
|
|
2007-12-25 16:21:40 +00:00
|
|
|
if (gimp_image_get_colormap_size (image) < 256)
|
2004-05-13 15:50:55 +00:00
|
|
|
{
|
2023-11-14 20:04:14 +01:00
|
|
|
GimpRGB rgb;
|
|
|
|
GeglColor *color;
|
2004-05-13 15:50:55 +00:00
|
|
|
|
2019-07-04 01:11:48 +02:00
|
|
|
if (background)
|
2023-11-14 20:04:14 +01:00
|
|
|
color = gimp_context_get_background (context);
|
2004-05-13 15:50:55 +00:00
|
|
|
else
|
2023-11-14 20:04:14 +01:00
|
|
|
color = gimp_context_get_foreground (context);
|
2002-03-17 13:52:25 +00:00
|
|
|
|
2023-11-14 20:04:14 +01:00
|
|
|
gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL);
|
|
|
|
|
|
|
|
gimp_image_add_colormap_entry (image, &rgb);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_flush (image);
|
2004-05-13 15:50:55 +00:00
|
|
|
}
|
2002-03-17 13:52:25 +00:00
|
|
|
}
|
2004-10-24 18:32:24 +00:00
|
|
|
|
2015-08-26 01:06:34 +02:00
|
|
|
void
|
2019-07-02 16:12:18 +02:00
|
|
|
colormap_to_selection_cmd_callback (GimpAction *action,
|
2019-07-04 01:11:48 +02:00
|
|
|
GVariant *value,
|
2019-07-02 16:12:18 +02:00
|
|
|
gpointer data)
|
2015-08-26 01:06:34 +02:00
|
|
|
{
|
2019-03-17 23:13:34 +01:00
|
|
|
GimpColormapSelection *selection;
|
|
|
|
GimpColormapEditor *editor;
|
|
|
|
GimpImage *image;
|
2022-10-20 00:39:10 +02:00
|
|
|
GList *drawables;
|
2019-03-17 23:13:34 +01:00
|
|
|
GimpChannelOps op;
|
|
|
|
gint col_index;
|
|
|
|
|
2015-08-26 01:06:34 +02:00
|
|
|
return_if_no_image (image, data);
|
|
|
|
|
2019-03-17 23:13:34 +01:00
|
|
|
editor = GIMP_COLORMAP_EDITOR (data);
|
|
|
|
selection = GIMP_COLORMAP_SELECTION (editor->selection);
|
|
|
|
col_index = gimp_colormap_selection_get_index (selection, NULL);
|
2015-08-26 01:06:34 +02:00
|
|
|
|
2019-07-04 01:11:48 +02:00
|
|
|
op = (GimpChannelOps) g_variant_get_int32 (value);
|
2015-08-26 01:06:34 +02:00
|
|
|
|
2022-10-20 00:39:10 +02:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
if (g_list_length (drawables) != 1)
|
|
|
|
{
|
|
|
|
/* We should not reach this anyway as colormap-actions.c normally takes
|
|
|
|
* care at making the action insensitive when the item selection is wrong.
|
|
|
|
*/
|
|
|
|
g_warning ("This action requires exactly one selected drawable.");
|
|
|
|
g_list_free (drawables);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-26 01:06:34 +02:00
|
|
|
gimp_channel_select_by_index (gimp_image_get_mask (image),
|
2022-10-20 00:39:10 +02:00
|
|
|
drawables->data,
|
2019-03-17 23:13:34 +01:00
|
|
|
col_index, op,
|
2015-08-26 01:06:34 +02:00
|
|
|
FALSE, 0.0, 0.0);
|
2018-06-22 13:38:24 -04:00
|
|
|
|
2022-10-20 00:39:10 +02:00
|
|
|
g_list_free (drawables);
|
2018-06-22 13:38:24 -04:00
|
|
|
gimp_image_flush (image);
|
2015-08-26 01:06:34 +02:00
|
|
|
}
|