2003-11-22 05:27:10 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpcolordisplaystack.c
|
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2003-11-23 21:28:15 +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.
|
2003-11-22 05:27:10 +08:00
|
|
|
*
|
2003-11-23 21:28:15 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2003-11-22 05:27:10 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-11-23 21:28:15 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-11-22 05:27:10 +08:00
|
|
|
*
|
2003-11-23 21:28:15 +08:00
|
|
|
* 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
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2003-11-22 05:27:10 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
2011-01-23 15:28:33 +08:00
|
|
|
#undef GIMP_DISABLE_DEPRECATED
|
2003-11-22 05:27:10 +08:00
|
|
|
#include "gimpcolordisplay.h"
|
|
|
|
#include "gimpcolordisplaystack.h"
|
2003-11-22 23:54:12 +08:00
|
|
|
#include "gimpwidgetsmarshal.h"
|
2003-11-22 05:27:10 +08:00
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpcolordisplaystack
|
|
|
|
* @title: GimpColorDisplayStack
|
|
|
|
* @short_description: A stack of color correction modules.
|
|
|
|
* @see_also: #GimpColorDisplay
|
|
|
|
*
|
|
|
|
* A stack of color correction modules.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHANGED,
|
2003-11-22 23:54:12 +08:00
|
|
|
ADDED,
|
|
|
|
REMOVED,
|
|
|
|
REORDERED,
|
2003-11-22 05:27:10 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
static void gimp_color_display_stack_dispose (GObject *object);
|
2003-11-23 20:08:21 +08:00
|
|
|
|
|
|
|
static void gimp_color_display_stack_display_changed (GimpColorDisplay *display,
|
|
|
|
GimpColorDisplayStack *stack);
|
|
|
|
static void gimp_color_display_stack_display_enabled (GimpColorDisplay *display,
|
2003-11-23 21:08:56 +08:00
|
|
|
GParamSpec *pspec,
|
2003-11-23 20:08:21 +08:00
|
|
|
GimpColorDisplayStack *stack);
|
2007-08-08 20:27:11 +08:00
|
|
|
static void gimp_color_display_stack_disconnect (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display);
|
2003-11-23 20:08:21 +08:00
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpColorDisplayStack, gimp_color_display_stack, G_TYPE_OBJECT)
|
2003-11-22 05:27:10 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_color_display_stack_parent_class
|
2003-11-22 05:27:10 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint stack_signals[LAST_SIGNAL] = { 0 };
|
2003-11-22 05:27:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_display_stack_class_init (GimpColorDisplayStackClass *klass)
|
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2003-11-22 05:27:10 +08:00
|
|
|
|
|
|
|
stack_signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorDisplayStackClass, changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2003-11-22 23:54:12 +08:00
|
|
|
stack_signals[ADDED] =
|
|
|
|
g_signal_new ("added",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorDisplayStackClass, added),
|
|
|
|
NULL, NULL,
|
|
|
|
_gimp_widgets_marshal_VOID__OBJECT_INT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
GIMP_TYPE_COLOR_DISPLAY,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
|
|
stack_signals[REMOVED] =
|
|
|
|
g_signal_new ("removed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorDisplayStackClass, removed),
|
|
|
|
NULL, NULL,
|
|
|
|
_gimp_widgets_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GIMP_TYPE_COLOR_DISPLAY);
|
|
|
|
|
|
|
|
stack_signals[REORDERED] =
|
|
|
|
g_signal_new ("reordered",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorDisplayStackClass, reordered),
|
|
|
|
NULL, NULL,
|
|
|
|
_gimp_widgets_marshal_VOID__OBJECT_INT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
GIMP_TYPE_COLOR_DISPLAY,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
object_class->dispose = gimp_color_display_stack_dispose;
|
2003-11-22 05:27:10 +08:00
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
klass->changed = NULL;
|
|
|
|
klass->added = NULL;
|
|
|
|
klass->removed = NULL;
|
|
|
|
klass->reordered = NULL;
|
2003-11-22 05:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_display_stack_init (GimpColorDisplayStack *stack)
|
|
|
|
{
|
|
|
|
stack->filters = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-08 20:27:11 +08:00
|
|
|
gimp_color_display_stack_dispose (GObject *object)
|
2003-11-22 05:27:10 +08:00
|
|
|
{
|
|
|
|
GimpColorDisplayStack *stack = GIMP_COLOR_DISPLAY_STACK (object);
|
|
|
|
|
|
|
|
if (stack->filters)
|
|
|
|
{
|
2007-08-08 20:27:11 +08:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = stack->filters; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpColorDisplay *display = list->data;
|
|
|
|
|
|
|
|
gimp_color_display_stack_disconnect (stack, display);
|
|
|
|
g_object_unref (display);
|
|
|
|
}
|
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
g_list_free (stack->filters);
|
|
|
|
stack->filters = NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2003-11-22 05:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpColorDisplayStack *
|
|
|
|
gimp_color_display_stack_new (void)
|
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
return g_object_new (GIMP_TYPE_COLOR_DISPLAY_STACK, NULL);
|
2003-11-22 05:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpColorDisplayStack *
|
|
|
|
gimp_color_display_stack_clone (GimpColorDisplayStack *stack)
|
|
|
|
{
|
|
|
|
GimpColorDisplayStack *clone;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack), NULL);
|
|
|
|
|
|
|
|
clone = g_object_new (GIMP_TYPE_COLOR_DISPLAY_STACK, NULL);
|
|
|
|
|
|
|
|
for (list = stack->filters; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpColorDisplay *display;
|
|
|
|
|
|
|
|
display = gimp_color_display_clone (list->data);
|
|
|
|
|
|
|
|
gimp_color_display_stack_add (clone, display);
|
|
|
|
g_object_unref (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_changed (GimpColorDisplayStack *stack)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
|
|
|
|
g_signal_emit (stack, stack_signals[CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_add (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
|
|
|
|
g_return_if_fail (g_list_find (stack->filters, display) == NULL);
|
|
|
|
|
|
|
|
stack->filters = g_list_append (stack->filters, g_object_ref (display));
|
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
g_signal_connect (display, "changed",
|
|
|
|
G_CALLBACK (gimp_color_display_stack_display_changed),
|
|
|
|
G_OBJECT (stack));
|
|
|
|
g_signal_connect (display, "notify::enabled",
|
|
|
|
G_CALLBACK (gimp_color_display_stack_display_enabled),
|
|
|
|
G_OBJECT (stack));
|
2003-11-22 05:27:10 +08:00
|
|
|
|
2003-11-22 23:54:12 +08:00
|
|
|
g_signal_emit (stack, stack_signals[ADDED], 0,
|
|
|
|
display, g_list_length (stack->filters) - 1);
|
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
gimp_color_display_stack_changed (stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_remove (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
|
|
|
|
g_return_if_fail (g_list_find (stack->filters, display) != NULL);
|
|
|
|
|
2007-08-08 20:27:11 +08:00
|
|
|
gimp_color_display_stack_disconnect (stack, display);
|
2003-11-22 05:27:10 +08:00
|
|
|
|
|
|
|
stack->filters = g_list_remove (stack->filters, display);
|
2003-11-22 23:54:12 +08:00
|
|
|
|
|
|
|
g_signal_emit (stack, stack_signals[REMOVED], 0, display);
|
2003-11-22 05:27:10 +08:00
|
|
|
|
|
|
|
gimp_color_display_stack_changed (stack);
|
2003-11-22 23:54:12 +08:00
|
|
|
|
|
|
|
g_object_unref (display);
|
2003-11-22 05:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_reorder_up (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
|
|
|
|
|
|
|
|
list = g_list_find (stack->filters, display);
|
|
|
|
|
|
|
|
g_return_if_fail (list != NULL);
|
|
|
|
|
|
|
|
if (list->prev)
|
|
|
|
{
|
|
|
|
list->data = list->prev->data;
|
|
|
|
list->prev->data = display;
|
|
|
|
|
2003-11-22 23:54:12 +08:00
|
|
|
g_signal_emit (stack, stack_signals[REORDERED], 0,
|
|
|
|
display, g_list_position (stack->filters, list->prev));
|
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
gimp_color_display_stack_changed (stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_reorder_down (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
|
|
|
|
|
|
|
|
list = g_list_find (stack->filters, display);
|
|
|
|
|
|
|
|
g_return_if_fail (list != NULL);
|
|
|
|
|
|
|
|
if (list->next)
|
|
|
|
{
|
|
|
|
list->data = list->next->data;
|
|
|
|
list->next->data = display;
|
|
|
|
|
2003-11-22 23:54:12 +08:00
|
|
|
g_signal_emit (stack, stack_signals[REORDERED], 0,
|
|
|
|
display, g_list_position (stack->filters, list->next));
|
|
|
|
|
2003-11-22 05:27:10 +08:00
|
|
|
gimp_color_display_stack_changed (stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 15:28:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_color_display_stack_convert_surface:
|
2011-04-27 08:40:14 +08:00
|
|
|
* @stack: a #GimpColorDisplayStack
|
2011-01-23 15:28:33 +08:00
|
|
|
* @surface: a #cairo_image_surface_t of type ARGB32
|
|
|
|
*
|
|
|
|
* Runs all the stack's filters on all pixels in @surface.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_color_display_stack_convert_surface (GimpColorDisplayStack *stack,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
g_return_if_fail (surface != NULL);
|
|
|
|
g_return_if_fail (cairo_surface_get_type (surface) ==
|
|
|
|
CAIRO_SURFACE_TYPE_IMAGE);
|
|
|
|
|
|
|
|
for (list = stack->filters; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpColorDisplay *display = list->data;
|
|
|
|
|
|
|
|
gimp_color_display_convert_surface (display, surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_color_display_stack_convert:
|
2011-01-26 13:26:36 +08:00
|
|
|
* @stack: a #GimpColorDisplayStack
|
2011-01-23 15:28:33 +08:00
|
|
|
* @buf: the pixel buffer to convert
|
|
|
|
* @width: the width of the buffer
|
|
|
|
* @height: the height of the buffer
|
|
|
|
* @bpp: the number of bytes per pixel
|
|
|
|
* @bpl: the buffer's rowstride
|
|
|
|
*
|
|
|
|
* Converts all pixels in @buf.
|
|
|
|
*
|
|
|
|
* Deprecated: GIMP 2.8: Use gimp_color_display_stack_convert_surface() instead.
|
|
|
|
**/
|
2003-11-22 05:27:10 +08:00
|
|
|
void
|
|
|
|
gimp_color_display_stack_convert (GimpColorDisplayStack *stack,
|
|
|
|
guchar *buf,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bpp,
|
|
|
|
gint bpl)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_DISPLAY_STACK (stack));
|
|
|
|
|
|
|
|
for (list = stack->filters; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpColorDisplay *display = list->data;
|
|
|
|
|
|
|
|
gimp_color_display_convert (display, buf, width, height, bpp, bpl);
|
|
|
|
}
|
|
|
|
}
|
2003-11-23 20:08:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_display_stack_display_changed (GimpColorDisplay *display,
|
|
|
|
GimpColorDisplayStack *stack)
|
|
|
|
{
|
|
|
|
if (display->enabled)
|
|
|
|
gimp_color_display_stack_changed (stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_display_stack_display_enabled (GimpColorDisplay *display,
|
2003-11-23 21:08:56 +08:00
|
|
|
GParamSpec *pspec,
|
2003-11-23 20:08:21 +08:00
|
|
|
GimpColorDisplayStack *stack)
|
|
|
|
{
|
|
|
|
gimp_color_display_stack_changed (stack);
|
|
|
|
}
|
2007-08-08 20:27:11 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_display_stack_disconnect (GimpColorDisplayStack *stack,
|
|
|
|
GimpColorDisplay *display)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (display,
|
|
|
|
gimp_color_display_stack_display_changed,
|
|
|
|
stack);
|
|
|
|
g_signal_handlers_disconnect_by_func (display,
|
|
|
|
gimp_color_display_stack_display_enabled,
|
|
|
|
stack);
|
|
|
|
}
|