mirror of https://github.com/GNOME/gimp.git
libgimpwidgets: add gimp_color_area_set_color_config()
And do a display profile transform on the color area if it's set.
This commit is contained in:
parent
7326f346c3
commit
1cffaa7120
|
@ -21,16 +21,20 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <lcms2.h>
|
||||
|
||||
#include <gegl.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
||||
#include "gimpwidgetstypes.h"
|
||||
|
||||
#include "gimpcairo-utils.h"
|
||||
#include "gimpcolorarea.h"
|
||||
#include "gimpwidgetsutils.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -63,6 +67,22 @@ enum
|
|||
};
|
||||
|
||||
|
||||
typedef struct _GimpColorAreaPrivate GimpColorAreaPrivate;
|
||||
|
||||
struct _GimpColorAreaPrivate
|
||||
{
|
||||
GimpColorConfig *config;
|
||||
GimpColorTransform transform;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) \
|
||||
G_TYPE_INSTANCE_GET_PRIVATE (obj, \
|
||||
GIMP_TYPE_COLOR_AREA, \
|
||||
GimpColorAreaPrivate)
|
||||
|
||||
|
||||
static void gimp_color_area_dispose (GObject *object);
|
||||
static void gimp_color_area_finalize (GObject *object);
|
||||
static void gimp_color_area_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
|
@ -71,7 +91,6 @@ static void gimp_color_area_set_property (GObject *object,
|
|||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_color_area_finalize (GObject *object);
|
||||
|
||||
static void gimp_color_area_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
|
@ -106,6 +125,12 @@ static void gimp_color_area_drag_data_get (GtkWidget *widget,
|
|||
guint info,
|
||||
guint time);
|
||||
|
||||
static void gimp_color_area_config_notify (GimpColorConfig *config,
|
||||
const GParamSpec *pspec,
|
||||
GimpColorArea *area);
|
||||
|
||||
static void gimp_color_area_create_transform (GimpColorArea *area);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpColorArea, gimp_color_area, GTK_TYPE_DRAWING_AREA)
|
||||
|
||||
|
@ -132,9 +157,10 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
|
|||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
object_class->dispose = gimp_color_area_dispose;
|
||||
object_class->finalize = gimp_color_area_finalize;
|
||||
object_class->get_property = gimp_color_area_get_property;
|
||||
object_class->set_property = gimp_color_area_set_property;
|
||||
object_class->finalize = gimp_color_area_finalize;
|
||||
|
||||
widget_class->size_allocate = gimp_color_area_size_allocate;
|
||||
widget_class->state_changed = gimp_color_area_state_changed;
|
||||
|
@ -199,6 +225,8 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
|
|||
NULL, NULL,
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (GimpColorAreaPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -218,6 +246,16 @@ gimp_color_area_init (GimpColorArea *area)
|
|||
GDK_ACTION_COPY);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_area_dispose (GObject *object)
|
||||
{
|
||||
GimpColorArea *area = GIMP_COLOR_AREA (object);
|
||||
|
||||
gimp_color_area_set_color_config (area, NULL);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_area_finalize (GObject *object)
|
||||
{
|
||||
|
@ -342,10 +380,11 @@ static gboolean
|
|||
gimp_color_area_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event)
|
||||
{
|
||||
GimpColorArea *area = GIMP_COLOR_AREA (widget);
|
||||
GtkStyle *style = gtk_widget_get_style (widget);
|
||||
cairo_t *cr;
|
||||
cairo_surface_t *buffer;
|
||||
GimpColorArea *area = GIMP_COLOR_AREA (widget);
|
||||
GimpColorAreaPrivate *priv = GET_PRIVATE (widget);
|
||||
GtkStyle *style = gtk_widget_get_style (widget);
|
||||
cairo_t *cr;
|
||||
cairo_surface_t *buffer;
|
||||
|
||||
if (! area->buf || ! gtk_widget_is_drawable (widget))
|
||||
return FALSE;
|
||||
|
@ -358,11 +397,41 @@ gimp_color_area_expose (GtkWidget *widget,
|
|||
gdk_cairo_region (cr, event->region);
|
||||
cairo_clip (cr);
|
||||
|
||||
buffer = cairo_image_surface_create_for_data (area->buf,
|
||||
CAIRO_FORMAT_RGB24,
|
||||
area->width,
|
||||
area->height,
|
||||
area->rowstride);
|
||||
if (! priv->transform)
|
||||
gimp_color_area_create_transform (area);
|
||||
|
||||
if (priv->transform)
|
||||
{
|
||||
guchar *buf = g_new (guchar, area->rowstride * area->height);
|
||||
guchar *src = area->buf;
|
||||
guchar *dest = buf;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < area->height; i++)
|
||||
{
|
||||
cmsDoTransform (priv->transform, src, dest, area->width);
|
||||
|
||||
src += area->rowstride;
|
||||
dest += area->rowstride;
|
||||
}
|
||||
|
||||
buffer = cairo_image_surface_create_for_data (buf,
|
||||
CAIRO_FORMAT_RGB24,
|
||||
area->width,
|
||||
area->height,
|
||||
area->rowstride);
|
||||
cairo_surface_set_user_data (buffer, NULL,
|
||||
buf, (cairo_destroy_func_t) g_free);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = cairo_image_surface_create_for_data (area->buf,
|
||||
CAIRO_FORMAT_RGB24,
|
||||
area->width,
|
||||
area->height,
|
||||
area->rowstride);
|
||||
}
|
||||
|
||||
cairo_set_source_surface (cr, buffer, 0.0, 0.0);
|
||||
cairo_surface_destroy (buffer);
|
||||
|
||||
|
@ -523,6 +592,55 @@ gimp_color_area_set_draw_border (GimpColorArea *area,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_color_area_set_color_config:
|
||||
* @area: a #GimpColorArea widget.
|
||||
* @config: a #GimpColorConfig object.
|
||||
*
|
||||
* Sets the color management configuration to use with this color area.
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
void
|
||||
gimp_color_area_set_color_config (GimpColorArea *area,
|
||||
GimpColorConfig *config)
|
||||
{
|
||||
GimpColorAreaPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_COLOR_AREA (area));
|
||||
g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));
|
||||
|
||||
priv = GET_PRIVATE (area);
|
||||
|
||||
if (priv->config)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->config,
|
||||
gimp_color_area_config_notify,
|
||||
area);
|
||||
g_object_unref (priv->config);
|
||||
|
||||
if (priv->transform)
|
||||
{
|
||||
cmsDeleteTransform (priv->transform);
|
||||
priv->transform = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
priv->config = config;
|
||||
|
||||
if (priv->config)
|
||||
{
|
||||
g_object_ref (priv->config);
|
||||
|
||||
g_signal_connect (priv->config, "notify",
|
||||
G_CALLBACK (gimp_color_area_config_notify),
|
||||
area);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_color_area_render_buf (GtkWidget *widget,
|
||||
gboolean insensitive,
|
||||
|
@ -791,3 +909,41 @@ gimp_color_area_drag_data_get (GtkWidget *widget,
|
|||
gdk_atom_intern ("application/x-color", FALSE),
|
||||
16, (guchar *) vals, 8);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_area_config_notify (GimpColorConfig *config,
|
||||
const GParamSpec *pspec,
|
||||
GimpColorArea *area)
|
||||
{
|
||||
GimpColorAreaPrivate *priv = GET_PRIVATE (area);
|
||||
|
||||
if (priv->transform)
|
||||
{
|
||||
cmsDeleteTransform (priv->transform);
|
||||
priv->transform = NULL;
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (area));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_area_create_transform (GimpColorArea *area)
|
||||
{
|
||||
GimpColorAreaPrivate *priv = GET_PRIVATE (area);
|
||||
|
||||
if (priv->config)
|
||||
{
|
||||
static GimpColorProfile *profile = NULL;
|
||||
|
||||
const Babl *format = babl_format ("cairo-RGB24");
|
||||
|
||||
if (G_UNLIKELY (! profile))
|
||||
profile = gimp_color_profile_new_rgb_srgb ();
|
||||
|
||||
priv->transform = gimp_widget_get_color_transform (GTK_WIDGET (area),
|
||||
priv->config,
|
||||
profile,
|
||||
&format,
|
||||
&format);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,21 +74,25 @@ struct _GimpColorAreaClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_color_area_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_color_area_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gimp_color_area_new (const GimpRGB *color,
|
||||
GimpColorAreaType type,
|
||||
GdkModifierType drag_mask);
|
||||
GtkWidget * gimp_color_area_new (const GimpRGB *color,
|
||||
GimpColorAreaType type,
|
||||
GdkModifierType drag_mask);
|
||||
|
||||
void gimp_color_area_set_color (GimpColorArea *area,
|
||||
const GimpRGB *color);
|
||||
void gimp_color_area_get_color (GimpColorArea *area,
|
||||
GimpRGB *color);
|
||||
gboolean gimp_color_area_has_alpha (GimpColorArea *area);
|
||||
void gimp_color_area_set_type (GimpColorArea *area,
|
||||
GimpColorAreaType type);
|
||||
void gimp_color_area_set_draw_border (GimpColorArea *area,
|
||||
gboolean draw_border);
|
||||
void gimp_color_area_set_color (GimpColorArea *area,
|
||||
const GimpRGB *color);
|
||||
void gimp_color_area_get_color (GimpColorArea *area,
|
||||
GimpRGB *color);
|
||||
|
||||
gboolean gimp_color_area_has_alpha (GimpColorArea *area);
|
||||
void gimp_color_area_set_type (GimpColorArea *area,
|
||||
GimpColorAreaType type);
|
||||
void gimp_color_area_set_draw_border (GimpColorArea *area,
|
||||
gboolean draw_border);
|
||||
|
||||
void gimp_color_area_set_color_config (GimpColorArea *area,
|
||||
GimpColorConfig *config);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -29,6 +29,7 @@ EXPORTS
|
|||
gimp_color_area_has_alpha
|
||||
gimp_color_area_new
|
||||
gimp_color_area_set_color
|
||||
gimp_color_area_set_color_config
|
||||
gimp_color_area_set_draw_border
|
||||
gimp_color_area_set_type
|
||||
gimp_color_area_type_get_type
|
||||
|
|
Loading…
Reference in New Issue