1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-undo-push.h"
#include "gimp-intl.h"
guchar *
gimp_image_get_colormap (const GimpImage *gimage)
{
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
return gimage->cmap;
}
gint
gimp_image_get_colormap_size (const GimpImage *gimage)
{
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 0);
return gimage->num_cols;
}
void
gimp_image_set_colormap (GimpImage *gimage,
const guchar *cmap,
gint n_colors,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (cmap != NULL || n_colors == 0);
g_return_if_fail (n_colors >= 0 && n_colors <= 256);
if (push_undo)
gimp_image_undo_push_image_colormap (gimage, _("Set Colormap"));
if (cmap)
{
if (! gimage->cmap)
gimage->cmap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
memcpy (gimage->cmap, cmap, n_colors * 3);
}
else
{
if (gimage->cmap)
g_free (gimage->cmap);
gimage->cmap = NULL;
}
gimage->num_cols = n_colors;
gimp_image_colormap_changed (gimage, -1);
}
void
gimp_image_get_colormap_entry (GimpImage *gimage,
gint color_index,
GimpRGB *color)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (gimage->cmap != NULL);
g_return_if_fail (color_index >= 0 && color_index < gimage->num_cols);
g_return_if_fail (color != NULL);
gimp_rgba_set_uchar (color,
gimage->cmap[color_index * 3],
gimage->cmap[color_index * 3 + 1],
gimage->cmap[color_index * 3 + 2],
OPAQUE_OPACITY);
}
void
gimp_image_set_colormap_entry (GimpImage *gimage,
gint color_index,
const GimpRGB *color,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (gimage->cmap != NULL);
g_return_if_fail (color_index >= 0 && color_index < gimage->num_cols);
g_return_if_fail (color != NULL);
if (push_undo)
gimp_image_undo_push_image_colormap (gimage,
_("Change Colormap entry"));
gimp_rgb_get_uchar (color,
&gimage->cmap[color_index * 3],
&gimage->cmap[color_index * 3 + 1],
&gimage->cmap[color_index * 3 + 2]);
gimp_image_colormap_changed (gimage, color_index);
}
void
gimp_image_add_colormap_entry (GimpImage *gimage,
const GimpRGB *color)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (gimage->cmap != NULL);
g_return_if_fail (gimage->num_cols < 256);
g_return_if_fail (color != NULL);
gimp_image_undo_push_image_colormap (gimage,
_("Add Color to Colormap"));
gimp_rgb_get_uchar (color,
&gimage->cmap[gimage->num_cols * 3],
&gimage->cmap[gimage->num_cols * 3 + 1],
&gimage->cmap[gimage->num_cols * 3 + 2]);
gimage->num_cols++;
gimp_image_colormap_changed (gimage, -1);
}
|