2000-05-31 14:15:06 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpdrawable.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2000-05-31 14:15:06 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-05-31 14:15:06 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2000-05-31 14:15:06 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
2000-05-31 14:15:06 +08:00
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2019-08-08 04:26:05 +08:00
|
|
|
#include "gimppixbuf.h"
|
2012-03-22 08:10:43 +08:00
|
|
|
#include "gimptilebackendplugin.h"
|
2000-05-31 21:24:14 +08:00
|
|
|
|
2012-03-22 18:24:03 +08:00
|
|
|
|
2019-08-27 22:47:17 +08:00
|
|
|
struct _GimpDrawablePrivate
|
|
|
|
{
|
|
|
|
gpointer unused;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GimpDrawable, gimp_drawable, GIMP_TYPE_ITEM)
|
2019-08-13 19:59:33 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_drawable_parent_class
|
|
|
|
|
2019-08-27 22:47:17 +08:00
|
|
|
|
2019-08-13 19:59:33 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_class_init (GimpDrawableClass *klass)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_init (GimpDrawable *drawable)
|
|
|
|
{
|
2019-08-27 22:47:17 +08:00
|
|
|
drawable->priv = gimp_drawable_get_instance_private (drawable);
|
2019-08-13 19:59:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Public API. */
|
|
|
|
|
2019-09-03 16:24:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_by_id:
|
|
|
|
* @drawable_id: The drawable id.
|
|
|
|
*
|
|
|
|
* Returns a #GimpDrawable representing @drawable_id. This function
|
|
|
|
* calls gimp_item_get_by_id() and returns the item if it is drawable
|
|
|
|
* or %NULL otherwise.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): a #GimpDrawable for
|
|
|
|
* @drawable_id or %NULL if @drawable_id does not represent a
|
|
|
|
* valid drawable. The object belongs to libgimp and you must
|
|
|
|
* not modify or unref it.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GimpDrawable *
|
|
|
|
gimp_drawable_get_by_id (gint32 drawable_id)
|
|
|
|
{
|
|
|
|
GimpItem *item = gimp_item_get_by_id (drawable_id);
|
|
|
|
|
|
|
|
if (GIMP_IS_DRAWABLE (item))
|
|
|
|
return (GimpDrawable *) item;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-08-13 19:59:33 +08:00
|
|
|
|
2019-08-27 22:32:25 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_thumbnail_data:
|
|
|
|
* @drawable: the drawable
|
|
|
|
* @width: (inout): the requested thumbnail width (<= 1024 pixels)
|
|
|
|
* @height: (inout): the requested thumbnail height (<= 1024 pixels)
|
|
|
|
* @bpp: (out): the bytes per pixel of the returned thubmnail data
|
|
|
|
*
|
|
|
|
* Retrieves thumbnail data for the drawable identified by @drawable.
|
|
|
|
* The thumbnail will be not larger than the requested size.
|
|
|
|
*
|
2020-05-08 22:57:45 +08:00
|
|
|
* Returns: (transfer full) (array) (nullable): thumbnail data or %NULL if
|
2019-08-27 22:32:25 +08:00
|
|
|
* @drawable is invalid.
|
|
|
|
**/
|
2000-06-01 22:59:22 +08:00
|
|
|
guchar *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_thumbnail_data (GimpDrawable *drawable,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *bpp)
|
2000-06-01 22:59:22 +08:00
|
|
|
{
|
|
|
|
gint ret_width;
|
|
|
|
gint ret_height;
|
|
|
|
guchar *image_data;
|
|
|
|
gint data_size;
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
_gimp_drawable_thumbnail (drawable,
|
2006-04-12 18:53:28 +08:00
|
|
|
*width,
|
|
|
|
*height,
|
|
|
|
&ret_width,
|
|
|
|
&ret_height,
|
|
|
|
bpp,
|
|
|
|
&data_size,
|
|
|
|
&image_data);
|
2000-06-01 22:59:22 +08:00
|
|
|
|
|
|
|
*width = ret_width;
|
|
|
|
*height = ret_height;
|
|
|
|
|
|
|
|
return image_data;
|
|
|
|
}
|
2001-05-21 21:58:46 +08:00
|
|
|
|
2019-08-08 04:26:05 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_thumbnail:
|
2019-08-27 22:32:25 +08:00
|
|
|
* @drawable: the drawable
|
2019-08-13 22:16:08 +08:00
|
|
|
* @width: the requested thumbnail width (<= 1024 pixels)
|
|
|
|
* @height: the requested thumbnail height (<= 1024 pixels)
|
|
|
|
* @alpha: how to handle an alpha channel
|
2019-08-08 04:26:05 +08:00
|
|
|
*
|
|
|
|
* Retrieves a thumbnail pixbuf for the drawable identified by
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable. The thumbnail will be not larger than the requested
|
2019-08-08 04:26:05 +08:00
|
|
|
* size.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GdkPixbuf
|
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.2
|
2019-08-08 04:26:05 +08:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_thumbnail (GimpDrawable *drawable,
|
2019-08-08 04:26:05 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpPixbufTransparency alpha)
|
|
|
|
{
|
|
|
|
gint thumb_width = width;
|
|
|
|
gint thumb_height = height;
|
|
|
|
gint thumb_bpp;
|
|
|
|
guchar *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (width > 0 && width <= 1024, NULL);
|
|
|
|
g_return_val_if_fail (height > 0 && height <= 1024, NULL);
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
data = gimp_drawable_get_thumbnail_data (drawable,
|
2019-08-08 04:26:05 +08:00
|
|
|
&thumb_width,
|
|
|
|
&thumb_height,
|
|
|
|
&thumb_bpp);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
return _gimp_pixbuf_from_data (data,
|
|
|
|
thumb_width, thumb_height, thumb_bpp,
|
|
|
|
alpha);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-02 17:47:01 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_sub_thumbnail_data:
|
|
|
|
* @drawable: the drawable ID
|
|
|
|
* @src_x: the x coordinate of the area
|
|
|
|
* @src_y: the y coordinate of the area
|
|
|
|
* @src_width: the width of the area
|
|
|
|
* @src_height: the height of the area
|
|
|
|
* @dest_width: (inout): the requested thumbnail width (<= 1024 pixels)
|
|
|
|
* @dest_height: (inout): the requested thumbnail height (<= 1024 pixels)
|
|
|
|
* @bpp: (out): the bytes per pixel of the returned thumbnail data
|
|
|
|
*
|
|
|
|
* Retrieves thumbnail data for the drawable identified by @drawable.
|
|
|
|
* The thumbnail will be not larger than the requested size.
|
|
|
|
*
|
2020-05-08 22:57:45 +08:00
|
|
|
* Returns: (transfer full) (array) (nullable): thumbnail data or %NULL if
|
2019-09-02 17:47:01 +08:00
|
|
|
* @drawable is invalid.
|
|
|
|
**/
|
2004-12-14 07:36:17 +08:00
|
|
|
guchar *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_sub_thumbnail_data (GimpDrawable *drawable,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint src_width,
|
|
|
|
gint src_height,
|
|
|
|
gint *dest_width,
|
|
|
|
gint *dest_height,
|
|
|
|
gint *bpp)
|
2004-12-14 07:36:17 +08:00
|
|
|
{
|
|
|
|
gint ret_width;
|
|
|
|
gint ret_height;
|
|
|
|
guchar *image_data;
|
|
|
|
gint data_size;
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
_gimp_drawable_sub_thumbnail (drawable,
|
2004-12-14 07:36:17 +08:00
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
*dest_width,
|
|
|
|
*dest_height,
|
|
|
|
&ret_width,
|
|
|
|
&ret_height,
|
|
|
|
bpp,
|
|
|
|
&data_size,
|
|
|
|
&image_data);
|
|
|
|
|
|
|
|
*dest_width = ret_width;
|
|
|
|
*dest_height = ret_height;
|
|
|
|
|
|
|
|
return image_data;
|
|
|
|
}
|
|
|
|
|
2019-08-08 04:26:05 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_sub_thumbnail:
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable: the drawable ID
|
2019-08-08 04:26:05 +08:00
|
|
|
* @src_x: the x coordinate of the area
|
|
|
|
* @src_y: the y coordinate of the area
|
|
|
|
* @src_width: the width of the area
|
|
|
|
* @src_height: the height of the area
|
|
|
|
* @dest_width: the requested thumbnail width (<= 1024 pixels)
|
|
|
|
* @dest_height: the requested thumbnail height (<= 1024 pixels)
|
|
|
|
* @alpha: how to handle an alpha channel
|
|
|
|
*
|
|
|
|
* Retrieves a thumbnail pixbuf for the drawable identified by
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable. The thumbnail will be not larger than the requested
|
2019-08-08 04:26:05 +08:00
|
|
|
* size.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GdkPixbuf
|
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.2
|
2019-08-08 04:26:05 +08:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_sub_thumbnail (GimpDrawable *drawable,
|
2019-08-08 04:26:05 +08:00
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint src_width,
|
|
|
|
gint src_height,
|
|
|
|
gint dest_width,
|
|
|
|
gint dest_height,
|
|
|
|
GimpPixbufTransparency alpha)
|
|
|
|
{
|
|
|
|
gint thumb_width = dest_width;
|
|
|
|
gint thumb_height = dest_height;
|
|
|
|
gint thumb_bpp;
|
|
|
|
guchar *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (src_x >= 0, NULL);
|
|
|
|
g_return_val_if_fail (src_y >= 0, NULL);
|
|
|
|
g_return_val_if_fail (src_width > 0, NULL);
|
|
|
|
g_return_val_if_fail (src_height > 0, NULL);
|
|
|
|
g_return_val_if_fail (dest_width > 0 && dest_width <= 1024, NULL);
|
|
|
|
g_return_val_if_fail (dest_height > 0 && dest_height <= 1024, NULL);
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
data = gimp_drawable_get_sub_thumbnail_data (drawable,
|
2019-08-08 04:26:05 +08:00
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
&thumb_width,
|
|
|
|
&thumb_height,
|
|
|
|
&thumb_bpp);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
return _gimp_pixbuf_from_data (data,
|
|
|
|
thumb_width, thumb_height, thumb_bpp,
|
|
|
|
alpha);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-22 18:24:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_buffer:
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable: the ID of the #GimpDrawable to get the buffer for.
|
2012-03-22 18:24:03 +08:00
|
|
|
*
|
|
|
|
* Returns a #GeglBuffer of a specified drawable. The buffer can be used
|
|
|
|
* like any other GEGL buffer. Its data will we synced back with the core
|
|
|
|
* drawable when the buffer gets destroyed, or when gegl_buffer_flush()
|
|
|
|
* is called.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The #GeglBuffer.
|
2012-03-22 18:24:03 +08:00
|
|
|
*
|
|
|
|
* See Also: gimp_drawable_get_shadow_buffer()
|
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.10
|
2012-03-22 18:24:03 +08:00
|
|
|
*/
|
2012-03-22 08:10:43 +08:00
|
|
|
GeglBuffer *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_buffer (GimpDrawable *drawable)
|
2012-03-22 08:10:43 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_item_is_valid (GIMP_ITEM (drawable)))
|
2012-03-22 18:24:03 +08:00
|
|
|
{
|
2019-07-20 07:02:24 +08:00
|
|
|
GeglTileBackend *backend;
|
|
|
|
GeglBuffer *buffer;
|
2012-09-23 02:33:03 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
backend = _gimp_tile_backend_plugin_new (drawable, FALSE);
|
2019-07-20 07:02:24 +08:00
|
|
|
buffer = gegl_buffer_new_for_backend (NULL, backend);
|
|
|
|
g_object_unref (backend);
|
2012-09-23 02:33:03 +08:00
|
|
|
|
2019-07-20 07:02:24 +08:00
|
|
|
return buffer;
|
2012-03-22 18:24:03 +08:00
|
|
|
}
|
2012-03-22 08:10:43 +08:00
|
|
|
|
2012-03-22 18:24:03 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_drawable_get_shadow_buffer:
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable: the ID of the #GimpDrawable to get the buffer for.
|
2012-03-22 18:24:03 +08:00
|
|
|
*
|
|
|
|
* Returns a #GeglBuffer of a specified drawable's shadow tiles. The
|
|
|
|
* buffer can be used like any other GEGL buffer. Its data will we
|
|
|
|
* synced back with the core drawable's shadow tiles when the buffer
|
|
|
|
* gets destroyed, or when gegl_buffer_flush() is called.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The #GeglBuffer.
|
2012-03-22 18:24:03 +08:00
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.10
|
2012-03-22 18:24:03 +08:00
|
|
|
*/
|
2012-03-22 08:10:43 +08:00
|
|
|
GeglBuffer *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_shadow_buffer (GimpDrawable *drawable)
|
2012-03-22 08:10:43 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_item_is_valid (GIMP_ITEM (drawable)))
|
2012-03-22 18:24:03 +08:00
|
|
|
{
|
|
|
|
GeglTileBackend *backend;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
backend = _gimp_tile_backend_plugin_new (drawable, TRUE);
|
2012-03-22 18:24:03 +08:00
|
|
|
buffer = gegl_buffer_new_for_backend (NULL, backend);
|
|
|
|
g_object_unref (backend);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-03-22 08:10:43 +08:00
|
|
|
}
|
2012-04-03 02:43:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_drawable_get_format:
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable: the ID of the #GimpDrawable to get the format for.
|
2012-04-03 02:43:38 +08:00
|
|
|
*
|
|
|
|
* Returns the #Babl format of the drawable.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: The #Babl format.
|
2012-04-03 02:43:38 +08:00
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.10
|
2012-04-03 02:43:38 +08:00
|
|
|
*/
|
|
|
|
const Babl *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_format (GimpDrawable *drawable)
|
2012-04-03 02:43:38 +08:00
|
|
|
{
|
2012-04-25 03:45:35 +08:00
|
|
|
const Babl *format = NULL;
|
2019-08-13 22:16:08 +08:00
|
|
|
gchar *format_str = _gimp_drawable_get_format (drawable);
|
2012-04-25 03:45:35 +08:00
|
|
|
|
2019-01-02 01:24:35 +08:00
|
|
|
/* _gimp_drawable_get_format() only returns the encoding, so we
|
|
|
|
* create the actual space from the image's profile
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
*/
|
|
|
|
|
2012-04-25 03:45:35 +08:00
|
|
|
if (format_str)
|
2012-04-03 02:43:38 +08:00
|
|
|
{
|
2019-08-11 23:12:20 +08:00
|
|
|
const Babl *space = NULL;
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2019-01-02 01:24:35 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_item_is_layer (GIMP_ITEM (drawable)))
|
2019-01-02 01:24:35 +08:00
|
|
|
{
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpColorProfile *profile = gimp_image_get_color_profile (image);
|
2019-01-02 01:24:35 +08:00
|
|
|
|
2019-01-30 18:26:01 +08:00
|
|
|
if (profile)
|
2019-01-02 01:24:35 +08:00
|
|
|
{
|
2019-01-30 18:26:01 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
space = gimp_color_profile_get_space
|
|
|
|
(profile,
|
|
|
|
GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (! space)
|
|
|
|
{
|
|
|
|
g_printerr ("%s: failed to create Babl space from "
|
|
|
|
"profile: %s\n",
|
|
|
|
G_STRFUNC, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (profile);
|
2019-01-02 01:24:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
2012-04-25 03:45:35 +08:00
|
|
|
{
|
2019-01-02 01:24:35 +08:00
|
|
|
const Babl *palette;
|
|
|
|
const Babl *palette_alpha;
|
2012-04-25 03:45:35 +08:00
|
|
|
guchar *colormap;
|
|
|
|
gint n_colors;
|
2012-04-03 02:43:38 +08:00
|
|
|
|
2019-01-02 01:24:35 +08:00
|
|
|
babl_new_palette_with_space (format_str, space,
|
|
|
|
&palette, &palette_alpha);
|
2012-04-29 07:22:20 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2019-01-02 01:24:35 +08:00
|
|
|
format = palette_alpha;
|
|
|
|
else
|
|
|
|
format = palette;
|
2012-04-29 07:22:20 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
colormap = gimp_image_get_colormap (image, &n_colors);
|
2012-04-29 07:22:20 +08:00
|
|
|
|
2012-04-30 08:24:14 +08:00
|
|
|
if (colormap)
|
|
|
|
{
|
|
|
|
babl_palette_set_palette (format,
|
2019-01-02 01:24:35 +08:00
|
|
|
babl_format_with_space ("R'G'B' u8",
|
|
|
|
space),
|
2012-04-30 08:24:14 +08:00
|
|
|
colormap, n_colors);
|
|
|
|
g_free (colormap);
|
|
|
|
}
|
2012-04-25 03:45:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-02 01:24:35 +08:00
|
|
|
format = babl_format_with_space (format_str, space);
|
2012-04-25 03:45:35 +08:00
|
|
|
}
|
2012-04-03 02:43:38 +08:00
|
|
|
|
2012-04-25 03:45:35 +08:00
|
|
|
g_free (format_str);
|
2012-04-03 02:43:38 +08:00
|
|
|
}
|
|
|
|
|
2012-04-25 03:45:35 +08:00
|
|
|
return format;
|
2012-04-03 02:43:38 +08:00
|
|
|
}
|
2019-07-10 21:10:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_thumbnail_format:
|
2019-08-13 22:16:08 +08:00
|
|
|
* @drawable: the ID of the #GimpDrawable to get the thumbnail format for.
|
2019-07-10 21:10:03 +08:00
|
|
|
*
|
|
|
|
* Returns the #Babl thumbnail format of the drawable.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: The #Babl thumbnail format.
|
2019-07-10 21:10:03 +08:00
|
|
|
*
|
2019-08-31 00:44:56 +08:00
|
|
|
* Since: 2.10.14
|
2019-07-10 21:10:03 +08:00
|
|
|
*/
|
|
|
|
const Babl *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_get_thumbnail_format (GimpDrawable *drawable)
|
2019-07-10 21:10:03 +08:00
|
|
|
{
|
|
|
|
const Babl *format = NULL;
|
2019-08-13 22:16:08 +08:00
|
|
|
gchar *format_str = _gimp_drawable_get_thumbnail_format (drawable);
|
2019-07-10 21:10:03 +08:00
|
|
|
|
|
|
|
if (format_str)
|
2019-08-15 18:12:25 +08:00
|
|
|
{
|
|
|
|
format = babl_format (format_str);
|
|
|
|
g_free (format_str);
|
|
|
|
}
|
2019-07-10 21:10:03 +08:00
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|