gimp/app/core/gimpdrawable-preview.c

421 lines
13 KiB
C
Raw Normal View History

/* GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "core-types.h"
themes/Default/images/stock-delete-16.png 2003-03-06 Michael Natterer <mitch@gimp.org> * themes/Default/images/stock-delete-16.png * themes/Default/images/stock-lower-16.png * themes/Default/images/stock-new-16.png * themes/Default/images/stock-paste-16.png * themes/Default/images/stock-raise-16.png * themes/Default/images/stock-refresh-16.png: removed these files since we use the icons provided by GTK+ now. * themes/Default/gtkrc * themes/Default/images/Makefile.am: removed them here hoo. * libgimpwidgets/gimpstock.[ch]: reordered stuff to be consistent in the header and the .c file. Added GIMP_STOCK_ERROR and GIMP_STOCK_QUESTION which are available in all sizes (unlike GTK_STOCK_DIALOG_ERROR and GTK_STOCK_DIALOG_QUESTION). * app/core/gimpviewable.c * app/display/gimpdisplayshell.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/file-save-dialog.c * app/widgets/gimpwidgets-utils.c * app/widgets/gimpdatafactoryview.c: use the new stock IDs. * app/config/gimpcoreconfig.[ch]: renamed "preview_size" to "layer_preview_size" and added "gboolean layer_previews" which switches layer previews on/off independent of their size. * app/config/gimprc-blurbs.h: added/changed their blurbs. * app/core/core-enums.[ch]: removed GIMP_PREVIEW_SIZE_NONE. * app/core/gimpdrawable-preview.c * app/core/gimpdrawable.c * app/core/gimpimage.c: return NULL previews if core_config->layer_previews is FALSE. Invalidate all layer/channel previews whenever "layer_previews" changes. * app/widgets/gimppreviewrendererdrawable.c * app/widgets/gimppreviewrendererimage.c: render the stock_id if the drawable/image returns a NULL preview. Fixes bug #107242. * app/display/gimpdisplayshell-handlers.c: don't set the sensitivity of the navigation button because it can no longer be disabled. * app/display/gimpdisplayshell-layer-select.c * app/gui/dialogs-constructors.c * app/gui/dialogs.c * app/gui/paths-dialog.c: changed accordingly. * app/gui/preferences-dialog.c: added a toggle button for the new "layer_previews" boolean. * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c: chain up unconditionally in GimpContainerView::clear_items(). * app/widgets/gimpcontainertreeview.c: ditto. Made the reorder() implementation lengthy and eeky (but working) again... Stop signal emission on double clicks so GtkTreeView doesn't re-select the item we are about change. * app/widgets/gimpcontainerview.c (gimp_container_view_real_clear_items): need to use g_hash_table_new_full() here too or everything will b0rk. * app/widgets/gimppreviewrenderer.c (gimp_preview_renderer_default_render_stock): use gtk_widget_render_icon() instead of gtk_icon_set_render_icon(). * tools/pdbgen/enums.pl: this file wanted to be regenerated...
2003-03-07 00:47:34 +08:00
#include "config/gimpcoreconfig.h"
#include "gegl/gimp-babl.h"
#include "gegl/gimp-gegl-loops.h"
#include "gegl/gimptilehandlervalidate.h"
themes/Default/images/stock-delete-16.png 2003-03-06 Michael Natterer <mitch@gimp.org> * themes/Default/images/stock-delete-16.png * themes/Default/images/stock-lower-16.png * themes/Default/images/stock-new-16.png * themes/Default/images/stock-paste-16.png * themes/Default/images/stock-raise-16.png * themes/Default/images/stock-refresh-16.png: removed these files since we use the icons provided by GTK+ now. * themes/Default/gtkrc * themes/Default/images/Makefile.am: removed them here hoo. * libgimpwidgets/gimpstock.[ch]: reordered stuff to be consistent in the header and the .c file. Added GIMP_STOCK_ERROR and GIMP_STOCK_QUESTION which are available in all sizes (unlike GTK_STOCK_DIALOG_ERROR and GTK_STOCK_DIALOG_QUESTION). * app/core/gimpviewable.c * app/display/gimpdisplayshell.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/file-save-dialog.c * app/widgets/gimpwidgets-utils.c * app/widgets/gimpdatafactoryview.c: use the new stock IDs. * app/config/gimpcoreconfig.[ch]: renamed "preview_size" to "layer_preview_size" and added "gboolean layer_previews" which switches layer previews on/off independent of their size. * app/config/gimprc-blurbs.h: added/changed their blurbs. * app/core/core-enums.[ch]: removed GIMP_PREVIEW_SIZE_NONE. * app/core/gimpdrawable-preview.c * app/core/gimpdrawable.c * app/core/gimpimage.c: return NULL previews if core_config->layer_previews is FALSE. Invalidate all layer/channel previews whenever "layer_previews" changes. * app/widgets/gimppreviewrendererdrawable.c * app/widgets/gimppreviewrendererimage.c: render the stock_id if the drawable/image returns a NULL preview. Fixes bug #107242. * app/display/gimpdisplayshell-handlers.c: don't set the sensitivity of the navigation button because it can no longer be disabled. * app/display/gimpdisplayshell-layer-select.c * app/gui/dialogs-constructors.c * app/gui/dialogs.c * app/gui/paths-dialog.c: changed accordingly. * app/gui/preferences-dialog.c: added a toggle button for the new "layer_previews" boolean. * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c: chain up unconditionally in GimpContainerView::clear_items(). * app/widgets/gimpcontainertreeview.c: ditto. Made the reorder() implementation lengthy and eeky (but working) again... Stop signal emission on double clicks so GtkTreeView doesn't re-select the item we are about change. * app/widgets/gimpcontainerview.c (gimp_container_view_real_clear_items): need to use g_hash_table_new_full() here too or everything will b0rk. * app/widgets/gimppreviewrenderer.c (gimp_preview_renderer_default_render_stock): use gtk_widget_render_icon() instead of gtk_icon_set_render_icon(). * tools/pdbgen/enums.pl: this file wanted to be regenerated...
2003-03-07 00:47:34 +08:00
#include "gimp.h"
#include "gimp-parallel.h"
#include "gimpasync.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimpimage-color-profile.h"
#include "gimpdrawable-preview.h"
#include "gimpdrawable-private.h"
#include "gimplayer.h"
#include "gimptempbuf.h"
typedef struct
{
const Babl *format;
GeglBuffer *buffer;
GeglRectangle rect;
gdouble scale;
} SubPreviewData;
/* local function prototypes */
static SubPreviewData * sub_preview_data_new (const Babl *format,
GeglBuffer *buffer,
const GeglRectangle *rect,
gdouble scale);
static void sub_preview_data_free (SubPreviewData *data);
/* private functions */
static SubPreviewData *
sub_preview_data_new (const Babl *format,
GeglBuffer *buffer,
const GeglRectangle *rect,
gdouble scale)
{
SubPreviewData *data = g_slice_new (SubPreviewData);
data->format = format;
data->buffer = g_object_ref (buffer);
data->rect = *rect;
data->scale = scale;
return data;
}
static void
sub_preview_data_free (SubPreviewData *data)
{
g_object_unref (data->buffer);
g_slice_free (SubPreviewData, data);
}
/* public functions */
2012-04-09 02:25:49 +08:00
GimpTempBuf *
gimp_drawable_get_new_preview (GimpViewable *viewable,
GimpContext *context,
gint width,
gint height)
{
GimpItem *item = GIMP_ITEM (viewable);
GimpImage *image = gimp_item_get_image (item);
if (! image->gimp->config->layer_previews)
themes/Default/images/stock-delete-16.png 2003-03-06 Michael Natterer <mitch@gimp.org> * themes/Default/images/stock-delete-16.png * themes/Default/images/stock-lower-16.png * themes/Default/images/stock-new-16.png * themes/Default/images/stock-paste-16.png * themes/Default/images/stock-raise-16.png * themes/Default/images/stock-refresh-16.png: removed these files since we use the icons provided by GTK+ now. * themes/Default/gtkrc * themes/Default/images/Makefile.am: removed them here hoo. * libgimpwidgets/gimpstock.[ch]: reordered stuff to be consistent in the header and the .c file. Added GIMP_STOCK_ERROR and GIMP_STOCK_QUESTION which are available in all sizes (unlike GTK_STOCK_DIALOG_ERROR and GTK_STOCK_DIALOG_QUESTION). * app/core/gimpviewable.c * app/display/gimpdisplayshell.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/file-save-dialog.c * app/widgets/gimpwidgets-utils.c * app/widgets/gimpdatafactoryview.c: use the new stock IDs. * app/config/gimpcoreconfig.[ch]: renamed "preview_size" to "layer_preview_size" and added "gboolean layer_previews" which switches layer previews on/off independent of their size. * app/config/gimprc-blurbs.h: added/changed their blurbs. * app/core/core-enums.[ch]: removed GIMP_PREVIEW_SIZE_NONE. * app/core/gimpdrawable-preview.c * app/core/gimpdrawable.c * app/core/gimpimage.c: return NULL previews if core_config->layer_previews is FALSE. Invalidate all layer/channel previews whenever "layer_previews" changes. * app/widgets/gimppreviewrendererdrawable.c * app/widgets/gimppreviewrendererimage.c: render the stock_id if the drawable/image returns a NULL preview. Fixes bug #107242. * app/display/gimpdisplayshell-handlers.c: don't set the sensitivity of the navigation button because it can no longer be disabled. * app/display/gimpdisplayshell-layer-select.c * app/gui/dialogs-constructors.c * app/gui/dialogs.c * app/gui/paths-dialog.c: changed accordingly. * app/gui/preferences-dialog.c: added a toggle button for the new "layer_previews" boolean. * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c: chain up unconditionally in GimpContainerView::clear_items(). * app/widgets/gimpcontainertreeview.c: ditto. Made the reorder() implementation lengthy and eeky (but working) again... Stop signal emission on double clicks so GtkTreeView doesn't re-select the item we are about change. * app/widgets/gimpcontainerview.c (gimp_container_view_real_clear_items): need to use g_hash_table_new_full() here too or everything will b0rk. * app/widgets/gimppreviewrenderer.c (gimp_preview_renderer_default_render_stock): use gtk_widget_render_icon() instead of gtk_icon_set_render_icon(). * tools/pdbgen/enums.pl: this file wanted to be regenerated...
2003-03-07 00:47:34 +08:00
return NULL;
return gimp_drawable_get_sub_preview (GIMP_DRAWABLE (viewable),
0, 0,
gimp_item_get_width (item),
gimp_item_get_height (item),
width,
height);
}
GdkPixbuf *
gimp_drawable_get_new_pixbuf (GimpViewable *viewable,
GimpContext *context,
gint width,
gint height)
{
GimpItem *item = GIMP_ITEM (viewable);
GimpImage *image = gimp_item_get_image (item);
if (! image->gimp->config->layer_previews)
return NULL;
return gimp_drawable_get_sub_pixbuf (GIMP_DRAWABLE (viewable),
0, 0,
gimp_item_get_width (item),
gimp_item_get_height (item),
width,
height);
}
const Babl *
gimp_drawable_get_preview_format (GimpDrawable *drawable)
{
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
const Babl *space;
gboolean alpha;
GimpTRCType trc;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
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
space = gimp_drawable_get_space (drawable);
alpha = gimp_drawable_has_alpha (drawable);
trc = gimp_drawable_get_trc (drawable);
switch (gimp_drawable_get_base_type (drawable))
{
case GIMP_GRAY:
return gimp_babl_format (GIMP_GRAY,
gimp_babl_precision (GIMP_COMPONENT_TYPE_U8,
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
trc),
alpha, space);
case GIMP_RGB:
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
case GIMP_INDEXED:
return gimp_babl_format (GIMP_RGB,
gimp_babl_precision (GIMP_COMPONENT_TYPE_U8,
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
trc),
alpha, space);
}
g_return_val_if_reached (NULL);
}
2012-04-09 02:25:49 +08:00
GimpTempBuf *
gimp_drawable_get_sub_preview (GimpDrawable *drawable,
gint src_x,
gint src_y,
gint src_width,
gint src_height,
gint dest_width,
gint dest_height)
{
GimpItem *item;
GimpImage *image;
GeglBuffer *buffer;
GimpTempBuf *preview;
gdouble scale;
gint scaled_x;
gint scaled_y;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
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, NULL);
g_return_val_if_fail (dest_height > 0, NULL);
item = GIMP_ITEM (drawable);
g_return_val_if_fail ((src_x + src_width) <= gimp_item_get_width (item), NULL);
g_return_val_if_fail ((src_y + src_height) <= gimp_item_get_height (item), NULL);
image = gimp_item_get_image (item);
if (! image->gimp->config->layer_previews)
return NULL;
2012-05-06 10:39:23 +08:00
buffer = gimp_drawable_get_buffer (drawable);
preview = gimp_temp_buf_new (dest_width, dest_height,
gimp_drawable_get_preview_format (drawable));
scale = MIN ((gdouble) dest_width / (gdouble) src_width,
(gdouble) dest_height / (gdouble) src_height);
scaled_x = RINT ((gdouble) src_x * scale);
scaled_y = RINT ((gdouble) src_y * scale);
gegl_buffer_get (buffer,
GEGL_RECTANGLE (scaled_x, scaled_y, dest_width, dest_height),
scale,
gimp_temp_buf_get_format (preview),
gimp_temp_buf_get_data (preview),
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
return preview;
}
GdkPixbuf *
gimp_drawable_get_sub_pixbuf (GimpDrawable *drawable,
gint src_x,
gint src_y,
gint src_width,
gint src_height,
gint dest_width,
gint dest_height)
{
GimpItem *item;
GimpImage *image;
GeglBuffer *buffer;
GdkPixbuf *pixbuf;
gdouble scale;
gint scaled_x;
gint scaled_y;
GimpColorTransform *transform;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
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, NULL);
g_return_val_if_fail (dest_height > 0, NULL);
item = GIMP_ITEM (drawable);
g_return_val_if_fail ((src_x + src_width) <= gimp_item_get_width (item), NULL);
g_return_val_if_fail ((src_y + src_height) <= gimp_item_get_height (item), NULL);
image = gimp_item_get_image (item);
if (! image->gimp->config->layer_previews)
return NULL;
buffer = gimp_drawable_get_buffer (drawable);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
dest_width, dest_height);
scale = MIN ((gdouble) dest_width / (gdouble) src_width,
(gdouble) dest_height / (gdouble) src_height);
scaled_x = RINT ((gdouble) src_x * scale);
scaled_y = RINT ((gdouble) src_y * scale);
transform = gimp_image_get_color_transform_to_srgb_u8 (image);
if (transform)
{
GimpTempBuf *temp_buf;
GeglBuffer *src_buf;
GeglBuffer *dest_buf;
temp_buf = gimp_temp_buf_new (dest_width, dest_height,
gimp_drawable_get_format (drawable));
gegl_buffer_get (buffer,
GEGL_RECTANGLE (scaled_x, scaled_y,
dest_width, dest_height),
scale,
gimp_temp_buf_get_format (temp_buf),
gimp_temp_buf_get_data (temp_buf),
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
src_buf = gimp_temp_buf_create_buffer (temp_buf);
dest_buf = gimp_pixbuf_create_buffer (pixbuf);
gimp_temp_buf_unref (temp_buf);
gimp_color_transform_process_buffer (transform,
src_buf,
GEGL_RECTANGLE (0, 0,
dest_width, dest_height),
dest_buf,
GEGL_RECTANGLE (0, 0, 0, 0));
g_object_unref (src_buf);
g_object_unref (dest_buf);
}
else
{
gegl_buffer_get (buffer,
GEGL_RECTANGLE (scaled_x, scaled_y,
dest_width, dest_height),
scale,
gimp_pixbuf_get_format (pixbuf),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
GEGL_ABYSS_CLAMP);
}
return pixbuf;
}
static void
gimp_drawable_get_sub_preview_async_func (GimpAsync *async,
SubPreviewData *data)
{
GimpTempBuf *preview;
preview = gimp_temp_buf_new (data->rect.width, data->rect.height,
data->format);
gegl_buffer_get (data->buffer, &data->rect, data->scale,
gimp_temp_buf_get_format (preview),
gimp_temp_buf_get_data (preview),
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
sub_preview_data_free (data);
gimp_async_finish_full (async,
preview,
(GDestroyNotify) gimp_temp_buf_unref);
}
GimpAsync *
gimp_drawable_get_sub_preview_async (GimpDrawable *drawable,
gint src_x,
gint src_y,
gint src_width,
gint src_height,
gint dest_width,
gint dest_height)
{
GimpItem *item;
GimpImage *image;
GeglBuffer *buffer;
gdouble scale;
gint scaled_x;
gint scaled_y;
static gint no_async_drawable_previews = -1;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
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, NULL);
g_return_val_if_fail (dest_height > 0, NULL);
item = GIMP_ITEM (drawable);
g_return_val_if_fail ((src_x + src_width) <= gimp_item_get_width (item), NULL);
g_return_val_if_fail ((src_y + src_height) <= gimp_item_get_height (item), NULL);
image = gimp_item_get_image (item);
if (! image->gimp->config->layer_previews)
return NULL;
buffer = gimp_drawable_get_buffer (drawable);
if (no_async_drawable_previews < 0)
{
no_async_drawable_previews =
(g_getenv ("GIMP_NO_ASYNC_DRAWABLE_PREVIEWS") != NULL);
}
if (no_async_drawable_previews ||
gimp_tile_handler_validate_get_assigned (buffer))
{
GimpAsync *async = gimp_async_new ();
gimp_async_finish_full (async,
gimp_drawable_get_sub_preview (drawable,
src_x,
src_y,
src_width,
src_height,
dest_width,
dest_height),
(GDestroyNotify) gimp_temp_buf_unref);
return async;
}
scale = MIN ((gdouble) dest_width / (gdouble) src_width,
(gdouble) dest_height / (gdouble) src_height);
scaled_x = RINT ((gdouble) src_x * scale);
scaled_y = RINT ((gdouble) src_y * scale);
return gimp_parallel_run_async_full (
+1,
(GimpParallelRunAsyncFunc) gimp_drawable_get_sub_preview_async_func,
sub_preview_data_new (
gimp_drawable_get_preview_format (drawable),
buffer,
GEGL_RECTANGLE (scaled_x, scaled_y, dest_width, dest_height),
scale),
(GDestroyNotify) sub_preview_data_free);
}