gimpimage.c 4.01 KB
Newer Older
1 2 3 4 5
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
 *
 * gimpimage.c
 *
6
 * This library is free software: you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11 12 13 14 15 16
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
18
 * <https://www.gnu.org/licenses/>.
19 20
 */

Sven Neumann's avatar
Sven Neumann committed
21 22
#include "config.h"

23
#include "gimp.h"
24
#include "gimpimage.h"
25

26 27 28
/**
 * gimp_image_get_colormap:
 * @image_ID:   The image.
29
 * @num_colors: Returns the number of colors in the colormap array.
30 31 32 33
 *
 * Returns the image's colormap
 *
 * This procedure returns an actual pointer to the image's colormap, as
34
 * well as the number of colors contained in the colormap. If the image
35 36 37 38
 * is not of base type INDEXED, this pointer will be NULL.
 *
 * Returns: The image's colormap.
 */
39
guchar *
40 41
gimp_image_get_colormap (gint32  image_ID,
                         gint   *num_colors)
42 43 44 45
{
  gint    num_bytes;
  guchar *cmap;

46
  cmap = _gimp_image_get_colormap (image_ID, &num_bytes);
47

48 49
  if (num_colors)
    *num_colors = num_bytes / 3;
50 51 52 53

  return cmap;
}

54
/**
55 56 57
 * gimp_image_set_colormap:
 * @image_ID:   The image.
 * @colormap:   The new colormap values.
58 59 60 61 62 63 64 65 66 67 68
 * @num_colors: Number of colors in the colormap array.
 *
 * Sets the entries in the image's colormap.
 *
 * This procedure sets the entries in the specified image's colormap.
 * The number of colors is specified by the \"num_colors\" parameter
 * and corresponds to the number of INT8 triples that must be contained
 * in the \"cmap\" array.
 *
 * Returns: TRUE on success.
 */
69
gboolean
70 71 72
gimp_image_set_colormap (gint32        image_ID,
                         const guchar *colormap,
                         gint          num_colors)
73
{
74
  return _gimp_image_set_colormap (image_ID, num_colors * 3, colormap);
75 76 77 78
}

guchar *
gimp_image_get_thumbnail_data (gint32  image_ID,
Sven Neumann's avatar
Sven Neumann committed
79 80 81
                               gint   *width,
                               gint   *height,
                               gint   *bpp)
82 83 84 85 86 87 88
{
  gint    ret_width;
  gint    ret_height;
  guchar *image_data;
  gint    data_size;

  _gimp_image_thumbnail (image_ID,
Sven Neumann's avatar
Sven Neumann committed
89 90 91 92 93 94 95
                         *width,
                         *height,
                         &ret_width,
                         &ret_height,
                         bpp,
                         &data_size,
                         &image_data);
96 97 98

  *width  = ret_width;
  *height = ret_height;
99 100 101

  return image_data;
}
102

103 104 105 106 107 108 109 110 111 112
/**
 * gimp_image_get_metadata:
 * @image_ID: The image.
 *
 * Returns the image's metadata.
 *
 * Returns exif/iptc/xmp metadata from the image.
 *
 * Returns: The exif/ptc/xmp metadata, or %NULL if there is none.
 *
113
 * Since: 2.10
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
 **/
GimpMetadata *
gimp_image_get_metadata (gint32 image_ID)
{
  GimpMetadata *metadata = NULL;
  gchar        *metadata_string;

  metadata_string = _gimp_image_get_metadata (image_ID);
  if (metadata_string)
    {
      metadata = gimp_metadata_deserialize (metadata_string);
      g_free (metadata_string);
    }

  return metadata;
}

/**
 * gimp_image_set_metadata:
 * @image_ID: The image.
 * @metadata: The exif/ptc/xmp metadata.
 *
 * Set the image's metadata.
 *
 * Sets exif/iptc/xmp metadata on the image, or deletes it if
 * @metadata is %NULL.
 *
 * Returns: TRUE on success.
 *
143
 * Since: 2.10
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
 **/
gboolean
gimp_image_set_metadata (gint32        image_ID,
                         GimpMetadata *metadata)
{
  gchar    *metadata_string = NULL;
  gboolean  success;

  if (metadata)
    metadata_string = gimp_metadata_serialize (metadata);

  success = _gimp_image_set_metadata (image_ID, metadata_string);

  if (metadata_string)
    g_free (metadata_string);

  return success;
}