2000-05-31 06:15:06 +00:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpdrawable.c
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2000-05-31 06:15:06 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-17 22:28:01 +00:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-05-31 06:15:06 +00: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-17 22:28:01 +00:00
|
|
|
* License along with this library. If not, see
|
2018-07-11 23:27:07 +02:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2000-05-31 06:15:06 +00:00
|
|
|
*/
|
|
|
|
|
2002-05-13 23:30:23 +00:00
|
|
|
#include "config.h"
|
2000-05-31 06:15:06 +00:00
|
|
|
|
2012-05-03 01:50:14 +02:00
|
|
|
#define GIMP_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2000-05-31 06:15:06 +00:00
|
|
|
#include "gimp.h"
|
|
|
|
|
2012-03-22 00:10:43 +00:00
|
|
|
#include "gimptilebackendplugin.h"
|
2000-05-31 13:24:14 +00:00
|
|
|
|
2012-03-22 11:24:03 +01:00
|
|
|
|
2000-06-01 14:59:22 +00:00
|
|
|
guchar *
|
|
|
|
gimp_drawable_get_thumbnail_data (gint32 drawable_ID,
|
2006-04-12 10:53:28 +00:00
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *bpp)
|
2000-06-01 14:59:22 +00:00
|
|
|
{
|
|
|
|
gint ret_width;
|
|
|
|
gint ret_height;
|
|
|
|
guchar *image_data;
|
|
|
|
gint data_size;
|
|
|
|
|
|
|
|
_gimp_drawable_thumbnail (drawable_ID,
|
2006-04-12 10:53:28 +00:00
|
|
|
*width,
|
|
|
|
*height,
|
|
|
|
&ret_width,
|
|
|
|
&ret_height,
|
|
|
|
bpp,
|
|
|
|
&data_size,
|
|
|
|
&image_data);
|
2000-06-01 14:59:22 +00:00
|
|
|
|
|
|
|
*width = ret_width;
|
|
|
|
*height = ret_height;
|
|
|
|
|
|
|
|
return image_data;
|
|
|
|
}
|
2001-05-21 13:58:46 +00:00
|
|
|
|
2004-12-13 23:36:17 +00:00
|
|
|
guchar *
|
|
|
|
gimp_drawable_get_sub_thumbnail_data (gint32 drawable_ID,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint src_width,
|
|
|
|
gint src_height,
|
|
|
|
gint *dest_width,
|
|
|
|
gint *dest_height,
|
|
|
|
gint *bpp)
|
|
|
|
{
|
|
|
|
gint ret_width;
|
|
|
|
gint ret_height;
|
|
|
|
guchar *image_data;
|
|
|
|
gint data_size;
|
|
|
|
|
|
|
|
_gimp_drawable_sub_thumbnail (drawable_ID,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-22 11:24:03 +01:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_buffer:
|
2012-04-02 20:43:38 +02:00
|
|
|
* @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
|
2012-03-22 11:24:03 +01: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.
|
|
|
|
*
|
|
|
|
* Return value: The #GeglBuffer.
|
|
|
|
*
|
|
|
|
* See Also: gimp_drawable_get_shadow_buffer()
|
|
|
|
*
|
2015-05-31 21:18:09 +02:00
|
|
|
* Since: 2.10
|
2012-03-22 11:24:03 +01:00
|
|
|
*/
|
2012-03-22 00:10:43 +00:00
|
|
|
GeglBuffer *
|
|
|
|
gimp_drawable_get_buffer (gint32 drawable_ID)
|
|
|
|
{
|
2012-04-24 21:45:35 +02:00
|
|
|
gimp_plugin_enable_precision ();
|
|
|
|
|
2012-09-22 20:33:03 +02:00
|
|
|
if (gimp_item_is_valid (drawable_ID))
|
2012-03-22 11:24:03 +01:00
|
|
|
{
|
2019-07-20 01:02:24 +02:00
|
|
|
GeglTileBackend *backend;
|
|
|
|
GeglBuffer *buffer;
|
2012-09-22 20:33:03 +02:00
|
|
|
|
2019-07-20 01:02:24 +02:00
|
|
|
backend = _gimp_tile_backend_plugin_new (drawable_ID, FALSE);
|
|
|
|
buffer = gegl_buffer_new_for_backend (NULL, backend);
|
|
|
|
g_object_unref (backend);
|
2012-09-22 20:33:03 +02:00
|
|
|
|
2019-07-20 01:02:24 +02:00
|
|
|
return buffer;
|
2012-03-22 11:24:03 +01:00
|
|
|
}
|
2012-03-22 00:10:43 +00:00
|
|
|
|
2012-03-22 11:24:03 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_drawable_get_shadow_buffer:
|
2012-04-02 20:43:38 +02:00
|
|
|
* @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
|
2012-03-22 11:24:03 +01: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.
|
|
|
|
*
|
|
|
|
* Return value: The #GeglBuffer.
|
|
|
|
*
|
|
|
|
* See Also: gimp_drawable_get_shadow_buffer()
|
|
|
|
*
|
2015-05-31 21:18:09 +02:00
|
|
|
* Since: 2.10
|
2012-03-22 11:24:03 +01:00
|
|
|
*/
|
2012-03-22 00:10:43 +00:00
|
|
|
GeglBuffer *
|
|
|
|
gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
|
|
|
|
{
|
2012-04-24 21:45:35 +02:00
|
|
|
gimp_plugin_enable_precision ();
|
|
|
|
|
2019-07-20 01:02:24 +02:00
|
|
|
if (gimp_item_is_valid (drawable_ID))
|
2012-03-22 11:24:03 +01:00
|
|
|
{
|
|
|
|
GeglTileBackend *backend;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
|
2019-07-20 01:02:24 +02:00
|
|
|
backend = _gimp_tile_backend_plugin_new (drawable_ID, TRUE);
|
2012-03-22 11:24:03 +01:00
|
|
|
buffer = gegl_buffer_new_for_backend (NULL, backend);
|
|
|
|
g_object_unref (backend);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-03-22 00:10:43 +00:00
|
|
|
}
|
2012-04-02 20:43:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_drawable_get_format:
|
|
|
|
* @drawable_ID: the ID of the #GimpDrawable to get the format for.
|
|
|
|
*
|
|
|
|
* Returns the #Babl format of the drawable.
|
|
|
|
*
|
|
|
|
* Return value: The #Babl format.
|
|
|
|
*
|
2015-05-31 21:18:09 +02:00
|
|
|
* Since: 2.10
|
2012-04-02 20:43:38 +02:00
|
|
|
*/
|
|
|
|
const Babl *
|
|
|
|
gimp_drawable_get_format (gint32 drawable_ID)
|
|
|
|
{
|
2012-04-24 21:45:35 +02:00
|
|
|
const Babl *format = NULL;
|
|
|
|
gchar *format_str = _gimp_drawable_get_format (drawable_ID);
|
|
|
|
|
2019-01-01 18:24:35 +01: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 14:23:01 +02:00
|
|
|
*/
|
|
|
|
|
2012-04-24 21:45:35 +02:00
|
|
|
if (format_str)
|
2012-04-02 20:43:38 +02:00
|
|
|
{
|
2019-01-30 11:26:01 +01:00
|
|
|
gint32 image_ID = gimp_item_get_image (drawable_ID);
|
|
|
|
const Babl *space = NULL;
|
2019-01-01 18:24:35 +01:00
|
|
|
|
2019-01-30 11:26:01 +01:00
|
|
|
if (gimp_item_is_layer (drawable_ID))
|
2019-01-01 18:24:35 +01:00
|
|
|
{
|
2019-01-30 11:26:01 +01:00
|
|
|
GimpColorProfile *profile = gimp_image_get_color_profile (image_ID);
|
2019-01-01 18:24:35 +01:00
|
|
|
|
2019-01-30 11:26:01 +01:00
|
|
|
if (profile)
|
2019-01-01 18:24:35 +01:00
|
|
|
{
|
2019-01-30 11:26:01 +01: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-01 18:24:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 21:45:35 +02:00
|
|
|
if (gimp_drawable_is_indexed (drawable_ID))
|
|
|
|
{
|
2019-01-01 18:24:35 +01:00
|
|
|
const Babl *palette;
|
|
|
|
const Babl *palette_alpha;
|
2012-04-24 21:45:35 +02:00
|
|
|
guchar *colormap;
|
|
|
|
gint n_colors;
|
2012-04-02 20:43:38 +02:00
|
|
|
|
2019-01-01 18:24:35 +01:00
|
|
|
babl_new_palette_with_space (format_str, space,
|
|
|
|
&palette, &palette_alpha);
|
2012-04-29 01:22:20 +02:00
|
|
|
|
2019-01-01 18:24:35 +01:00
|
|
|
if (gimp_drawable_has_alpha (drawable_ID))
|
|
|
|
format = palette_alpha;
|
|
|
|
else
|
|
|
|
format = palette;
|
2012-04-29 01:22:20 +02:00
|
|
|
|
2019-01-01 18:24:35 +01:00
|
|
|
colormap = gimp_image_get_colormap (image_ID, &n_colors);
|
2012-04-29 01:22:20 +02:00
|
|
|
|
2012-04-30 02:24:14 +02:00
|
|
|
if (colormap)
|
|
|
|
{
|
|
|
|
babl_palette_set_palette (format,
|
2019-01-01 18:24:35 +01:00
|
|
|
babl_format_with_space ("R'G'B' u8",
|
|
|
|
space),
|
2012-04-30 02:24:14 +02:00
|
|
|
colormap, n_colors);
|
|
|
|
g_free (colormap);
|
|
|
|
}
|
2012-04-24 21:45:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-01 18:24:35 +01:00
|
|
|
format = babl_format_with_space (format_str, space);
|
2012-04-24 21:45:35 +02:00
|
|
|
}
|
2012-04-02 20:43:38 +02:00
|
|
|
|
2012-04-24 21:45:35 +02:00
|
|
|
g_free (format_str);
|
2012-04-02 20:43:38 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 21:45:35 +02:00
|
|
|
return format;
|
2012-04-02 20:43:38 +02:00
|
|
|
}
|
2019-07-10 15:10:03 +02:00
|
|
|
/**
|
|
|
|
* gimp_drawable_get_thumbnail_format:
|
|
|
|
* @drawable_ID: the ID of the #GimpDrawable to get the thumbnail format for.
|
|
|
|
*
|
|
|
|
* Returns the #Babl thumbnail format of the drawable.
|
|
|
|
*
|
|
|
|
* Return value: The #Babl thumbnail format.
|
|
|
|
*
|
|
|
|
* Since: 2.10.14
|
|
|
|
*/
|
|
|
|
const Babl *
|
|
|
|
gimp_drawable_get_thumbnail_format (gint32 drawable_ID)
|
|
|
|
{
|
|
|
|
const Babl *format = NULL;
|
|
|
|
gchar *format_str = _gimp_drawable_get_thumbnail_format (drawable_ID);
|
|
|
|
|
|
|
|
if (format_str)
|
|
|
|
format = babl_format (format_str);
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|