2004-07-30 01:10:28 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-07-30 01:10:28 +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.
|
2004-07-30 01:10:28 +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
|
|
|
|
* Lesser 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/>.
|
2004-07-30 01:10:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
#include <gegl.h>
|
2004-07-30 01:10:28 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2016-05-25 03:43:20 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimppreviewarea.h"
|
2016-05-25 03:43:20 +08:00
|
|
|
#include "gimpwidgetsutils.h"
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2004-09-04 03:34:59 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimppreviewarea
|
|
|
|
* @title: GimpPreviewArea
|
|
|
|
* @short_description: A general purpose preview widget which caches
|
|
|
|
* its pixel data.
|
|
|
|
*
|
|
|
|
* A general purpose preview widget which caches its pixel data.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2004-09-02 23:39:07 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_CHECK_SIZE,
|
2020-05-25 04:26:50 +08:00
|
|
|
PROP_CHECK_TYPE,
|
|
|
|
PROP_CHECK_CUSTOM_COLOR1,
|
|
|
|
PROP_CHECK_CUSTOM_COLOR2
|
2004-09-02 23:39:07 +08:00
|
|
|
};
|
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2004-09-02 23:39:07 +08:00
|
|
|
#define DEFAULT_CHECK_SIZE GIMP_CHECK_SIZE_MEDIUM_CHECKS
|
|
|
|
#define DEFAULT_CHECK_TYPE GIMP_CHECK_TYPE_GRAY_CHECKS
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
#define CHECK_R(are, row, col) \
|
|
|
|
(((((area)->offset_y + (row)) & size) ^ \
|
|
|
|
(((area)->offset_x + (col)) & size)) ? rgb1[0] : rgb2[0])
|
2020-05-25 04:26:50 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
#define CHECK_G(area, row, col) \
|
|
|
|
(((((area)->offset_y + (row)) & size) ^ \
|
|
|
|
(((area)->offset_x + (col)) & size)) ? rgb1[1] : rgb2[1])
|
2020-05-25 04:26:50 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
#define CHECK_B(area, row, col) \
|
|
|
|
(((((area)->offset_y + (row)) & size) ^ \
|
|
|
|
(((area)->offset_x + (col)) & size)) ? rgb1[2] : rgb2[2])
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2004-09-10 01:11:16 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
struct _GimpPreviewArea
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkDrawingArea parent_instance;
|
|
|
|
|
2018-05-03 21:17:43 +08:00
|
|
|
GimpCheckSize check_size;
|
|
|
|
GimpCheckType check_type;
|
2023-11-21 04:38:11 +08:00
|
|
|
GeglColor *check_custom_color1;
|
|
|
|
GeglColor *check_custom_color2;
|
2018-05-03 21:17:43 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint rowstride;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint max_width;
|
|
|
|
gint max_height;
|
|
|
|
guchar *buf;
|
|
|
|
guchar *colormap;
|
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
GimpColorConfig *config;
|
2016-05-26 03:35:54 +08:00
|
|
|
GimpColorTransform *transform;
|
2016-05-25 03:43:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-02 04:38:58 +08:00
|
|
|
static void gimp_preview_area_dispose (GObject *object);
|
|
|
|
static void gimp_preview_area_finalize (GObject *object);
|
|
|
|
static void gimp_preview_area_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_preview_area_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2010-10-20 01:07:49 +08:00
|
|
|
static gboolean gimp_preview_area_widget_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2016-06-02 04:38:58 +08:00
|
|
|
|
|
|
|
static void gimp_preview_area_queue_draw (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
static gint gimp_preview_area_image_type_bytes (GimpImageType type);
|
|
|
|
|
|
|
|
static void gimp_preview_area_create_transform (GimpPreviewArea *area);
|
|
|
|
static void gimp_preview_area_destroy_transform (GimpPreviewArea *area);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
G_DEFINE_TYPE (GimpPreviewArea, gimp_preview_area, GTK_TYPE_DRAWING_AREA)
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_preview_area_parent_class
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_class_init (GimpPreviewAreaClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2023-11-21 04:38:11 +08:00
|
|
|
GeglColor *color1_default;
|
|
|
|
GeglColor *color2_default;
|
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
|
|
|
color1_default = gegl_color_new (NULL);
|
2024-03-18 00:19:25 +08:00
|
|
|
gegl_color_set_pixel (color1_default, babl_format ("R'G'B'A double"), GIMP_CHECKS_CUSTOM_COLOR1);
|
2023-11-21 04:38:11 +08:00
|
|
|
color2_default = gegl_color_new (NULL);
|
2024-03-18 00:19:25 +08:00
|
|
|
gegl_color_set_pixel (color2_default, babl_format ("R'G'B'A double"), GIMP_CHECKS_CUSTOM_COLOR2);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
object_class->dispose = gimp_preview_area_dispose;
|
2004-07-30 01:10:28 +08:00
|
|
|
object_class->finalize = gimp_preview_area_finalize;
|
2004-09-02 23:39:07 +08:00
|
|
|
object_class->set_property = gimp_preview_area_set_property;
|
|
|
|
object_class->get_property = gimp_preview_area_get_property;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
widget_class->size_allocate = gimp_preview_area_size_allocate;
|
2010-10-20 01:07:49 +08:00
|
|
|
widget_class->draw = gimp_preview_area_widget_draw;
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_CHECK_SIZE,
|
2004-09-04 03:34:59 +08:00
|
|
|
g_param_spec_enum ("check-size",
|
2017-06-07 03:19:17 +08:00
|
|
|
_("Check Size"),
|
|
|
|
"The size of the checkerboard pattern indicating transparency",
|
2004-09-02 23:39:07 +08:00
|
|
|
GIMP_TYPE_CHECK_SIZE,
|
|
|
|
DEFAULT_CHECK_SIZE,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_CHECK_TYPE,
|
2004-09-04 03:34:59 +08:00
|
|
|
g_param_spec_enum ("check-type",
|
2017-06-07 03:19:17 +08:00
|
|
|
_("Check Style"),
|
|
|
|
"The colors of the checkerboard pattern indicating transparency",
|
2004-09-02 23:39:07 +08:00
|
|
|
GIMP_TYPE_CHECK_TYPE,
|
|
|
|
DEFAULT_CHECK_TYPE,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_CHECK_CUSTOM_COLOR1,
|
2024-04-20 05:02:29 +08:00
|
|
|
gimp_param_spec_color ("check-custom-color1",
|
2023-11-21 04:38:11 +08:00
|
|
|
_("Custom Checks Color 1"),
|
|
|
|
"The first color of the checkerboard pattern indicating transparency",
|
2024-04-20 05:02:29 +08:00
|
|
|
FALSE, color1_default,
|
2023-11-21 04:38:11 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_CHECK_CUSTOM_COLOR2,
|
2024-04-20 05:02:29 +08:00
|
|
|
gimp_param_spec_color ("check-custom-color2",
|
2023-11-21 04:38:11 +08:00
|
|
|
_("Custom Checks Color 2"),
|
|
|
|
"The second color of the checkerboard pattern indicating transparency",
|
2024-04-20 05:02:29 +08:00
|
|
|
FALSE, color2_default,
|
2023-11-21 04:38:11 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_unref (color1_default);
|
|
|
|
g_object_unref (color2_default);
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_init (GimpPreviewArea *area)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
area->check_size = DEFAULT_CHECK_SIZE;
|
|
|
|
area->check_type = DEFAULT_CHECK_TYPE;
|
|
|
|
area->check_custom_color1 = gegl_color_new (NULL);
|
|
|
|
gegl_color_set_pixel (area->check_custom_color1, babl_format ("R'G'B'A double"), GIMP_CHECKS_CUSTOM_COLOR1);
|
|
|
|
area->check_custom_color2 = gegl_color_new (NULL);
|
|
|
|
gegl_color_set_pixel (area->check_custom_color2, babl_format ("R'G'B'A double"), GIMP_CHECKS_CUSTOM_COLOR2);
|
|
|
|
area->max_width = -1;
|
|
|
|
area->max_height = -1;
|
2016-06-02 04:38:58 +08:00
|
|
|
|
|
|
|
gimp_widget_track_monitor (GTK_WIDGET (area),
|
|
|
|
G_CALLBACK (gimp_preview_area_destroy_transform),
|
2019-08-08 05:44:18 +08:00
|
|
|
NULL, NULL);
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (object);
|
|
|
|
|
|
|
|
gimp_preview_area_set_color_config (area, NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_finalize (GObject *object)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (object);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_pointer (&area->buf, g_free);
|
|
|
|
g_clear_pointer (&area->colormap, g_free);
|
|
|
|
g_clear_object (&area->check_custom_color1);
|
|
|
|
g_clear_object (&area->check_custom_color2);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2004-09-02 23:39:07 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (object);
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_CHECK_SIZE:
|
2024-07-29 09:51:38 +08:00
|
|
|
area->check_size = g_value_get_enum (value);
|
2004-09-02 23:39:07 +08:00
|
|
|
break;
|
|
|
|
case PROP_CHECK_TYPE:
|
2024-07-29 09:51:38 +08:00
|
|
|
area->check_type = g_value_get_enum (value);
|
2004-09-02 23:39:07 +08:00
|
|
|
break;
|
2020-05-25 04:26:50 +08:00
|
|
|
case PROP_CHECK_CUSTOM_COLOR1:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&area->check_custom_color1);
|
|
|
|
area->check_custom_color1 = gegl_color_duplicate (g_value_get_object (value));
|
2020-05-25 04:26:50 +08:00
|
|
|
break;
|
|
|
|
case PROP_CHECK_CUSTOM_COLOR2:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&area->check_custom_color2);
|
|
|
|
area->check_custom_color2 = gegl_color_duplicate (g_value_get_object (value));
|
2020-05-25 04:26:50 +08:00
|
|
|
break;
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (object);
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_CHECK_SIZE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_value_set_enum (value, area->check_size);
|
2004-09-02 23:39:07 +08:00
|
|
|
break;
|
|
|
|
case PROP_CHECK_TYPE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_value_set_enum (value, area->check_type);
|
2004-09-02 23:39:07 +08:00
|
|
|
break;
|
2020-05-25 04:26:50 +08:00
|
|
|
case PROP_CHECK_CUSTOM_COLOR1:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_value_set_object (value, area->check_custom_color1);
|
2020-05-25 04:26:50 +08:00
|
|
|
break;
|
|
|
|
case PROP_CHECK_CUSTOM_COLOR2:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_value_set_object (value, area->check_custom_color2);
|
2020-05-25 04:26:50 +08:00
|
|
|
break;
|
2004-09-02 23:39:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (widget);
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
width = (area->max_width > 0 ?
|
|
|
|
MIN (allocation->width, area->max_width) : allocation->width);
|
|
|
|
height = (area->max_height > 0 ?
|
|
|
|
MIN (allocation->height, area->max_height) : allocation->height);
|
2004-09-09 22:47:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (width != area->width || height != area->height)
|
2004-07-30 01:10:28 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->buf)
|
2004-07-30 05:08:13 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (area->buf);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->buf = NULL;
|
|
|
|
area->rowstride = 0;
|
2004-07-30 05:08:13 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->width = width;
|
|
|
|
area->height = height;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-10-20 01:07:49 +08:00
|
|
|
gimp_preview_area_widget_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2004-07-30 01:10:28 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (widget);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GdkRectangle rect;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->buf)
|
2004-07-30 01:10:28 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2009-10-18 00:51:48 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
rect.x = (allocation.width - area->width) / 2;
|
|
|
|
rect.y = (allocation.height - area->height) / 2;
|
|
|
|
rect.width = area->width;
|
|
|
|
rect.height = area->height;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->transform)
|
2016-05-25 03:43:20 +08:00
|
|
|
gimp_preview_area_create_transform (area);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->transform)
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
2016-05-26 03:35:54 +08:00
|
|
|
const Babl *format = babl_format ("R'G'B' u8");
|
2024-07-29 09:51:38 +08:00
|
|
|
gint rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
guchar *buf = g_new (guchar, rowstride * area->height);
|
|
|
|
guchar *src = area->buf;
|
2016-05-26 03:35:54 +08:00
|
|
|
guchar *dest = buf;
|
|
|
|
gint i;
|
2016-05-25 03:43:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
for (i = 0; i < area->height; i++)
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
gimp_color_transform_process_pixels (area->transform,
|
2016-05-26 03:35:54 +08:00
|
|
|
format, src,
|
|
|
|
format, dest,
|
2024-07-29 09:51:38 +08:00
|
|
|
area->width);
|
2016-05-25 03:43:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
src += area->rowstride;
|
2016-05-25 03:43:20 +08:00
|
|
|
dest += rowstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_data (buf,
|
|
|
|
GDK_COLORSPACE_RGB,
|
|
|
|
FALSE,
|
|
|
|
8,
|
|
|
|
rect.width,
|
|
|
|
rect.height,
|
|
|
|
rowstride,
|
|
|
|
(GdkPixbufDestroyNotify) g_free, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
pixbuf = gdk_pixbuf_new_from_data (area->buf,
|
2016-05-25 03:43:20 +08:00
|
|
|
GDK_COLORSPACE_RGB,
|
|
|
|
FALSE,
|
|
|
|
8,
|
|
|
|
rect.width,
|
|
|
|
rect.height,
|
2024-07-29 09:51:38 +08:00
|
|
|
area->rowstride,
|
2016-05-25 03:43:20 +08:00
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2010-12-18 05:24:56 +08:00
|
|
|
gdk_cairo_set_source_pixbuf (cr, pixbuf, rect.x, rect.y);
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-09-10 01:13:58 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_queue_draw (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2004-09-10 01:11:16 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (area);
|
|
|
|
GtkAllocation allocation;
|
2009-10-18 00:51:48 +08:00
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2004-09-10 01:13:58 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
x += (allocation.width - area->width) / 2;
|
|
|
|
y += (allocation.height - area->height) / 2;
|
2004-09-10 01:11:16 +08:00
|
|
|
|
2004-09-10 01:13:58 +08:00
|
|
|
gtk_widget_queue_draw_area (widget, x, y, width, height);
|
2004-09-10 01:11:16 +08:00
|
|
|
}
|
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
static gint
|
|
|
|
gimp_preview_area_image_type_bytes (GimpImageType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_create_transform (GimpPreviewArea *area)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->config)
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
|
|
|
static GimpColorProfile *profile = NULL;
|
|
|
|
|
|
|
|
const Babl *format = babl_format ("R'G'B' u8");
|
|
|
|
|
|
|
|
if (G_UNLIKELY (! profile))
|
|
|
|
profile = gimp_color_profile_new_rgb_srgb ();
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->transform = gimp_widget_get_color_transform (GTK_WIDGET (area),
|
|
|
|
area->config,
|
2016-05-25 03:43:20 +08:00
|
|
|
profile,
|
2016-05-26 03:35:54 +08:00
|
|
|
format,
|
2022-06-01 04:59:31 +08:00
|
|
|
format,
|
2022-08-10 23:01:15 +08:00
|
|
|
NULL,
|
|
|
|
GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
|
|
|
|
FALSE);
|
2016-05-25 03:43:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 04:38:58 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_destroy_transform (GimpPreviewArea *area)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->transform)
|
2016-06-02 04:38:58 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_object_unref (area->transform);
|
|
|
|
area->transform = NULL;
|
2016-06-02 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (area));
|
|
|
|
}
|
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_new:
|
|
|
|
*
|
2005-01-22 07:11:43 +08:00
|
|
|
* Creates a new #GimpPreviewArea widget.
|
|
|
|
*
|
app, libgimp, libgimpbase, libgimpwidgets: better checkboard colors API.
- Some coding style fixes (alignment, etc.).
- Adding missing "Since: 3.0" annotations. We are still wondering
whether this should go in 2.10, in which case, it would become
"Since: 2.10.32" annotations. See discussion in !274.
- Changing gimp_checks_get_colors() signature: merge the 4 color
arguments into 2 (inout) arguments which seems a bit nicer in C,
whereas binding handles such arguments correctly. The other
alternative would have been to at least change the order to have out
arguments in the end.
I also hesitated to get another API in libgimp, which would have been
config-aware (just returning the 2 check colors, depending on user-set
Preferences), then having GimpPreviewArea handling 2 colors (without a
GimpCheckType input). But actually, doing this, we'd remove the nice
menu popup where one could choose a generic check type (not everyone
wants to play with specific non-gray colors) in Gimp*Preview widgets.
So in the end, I left this whole thing as-is.
Instead I document the function with code sample to initialize
properly the GimpPreviewArea (since libgimpwidgets/ are independent
with no knowledge of the core config) in order to respect user
preferences.
- Hide the color properties in gimp_preview_area_menu_new() because
anyway gimp_preview_area_menu_new() does not support GimpRGB
properties right now (so all we get are warnings). It's still possible
to select custom colors on GimpPreviewArea, simply we are stuck at the
ones set in Preferences globally for now (unless a plug-in creates
custom GUI to set these).
Fixed Conflicts from !274:
libgimp/gimp.h
libgimpwidgets/gimppreviewarea.c
2022-05-14 01:00:07 +08:00
|
|
|
* If the preview area is used to draw an image with transparency, you
|
|
|
|
* might want to default the checkboard size and colors to user-set
|
|
|
|
* Preferences. To do this, you may set the following properties on the
|
|
|
|
* newly created #GimpPreviewArea:
|
|
|
|
*
|
|
|
|
* |[<!-- language="C" -->
|
|
|
|
* g_object_set (area,
|
|
|
|
* "check-size", gimp_check_size (),
|
|
|
|
* "check-type", gimp_check_type (),
|
|
|
|
* "check-custom-color1", gimp_check_custom_color1 (),
|
|
|
|
* "check-custom-color2", gimp_check_custom_color2 (),
|
|
|
|
* NULL);
|
|
|
|
* ]|
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a new #GimpPreviewArea widget.
|
2004-07-30 01:10:28 +08:00
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_preview_area_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_PREVIEW_AREA, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_area_draw:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
|
|
|
* @width: buffer width
|
|
|
|
* @height: buffer height
|
2004-07-31 09:03:00 +08:00
|
|
|
* @type: the #GimpImageType of @buf
|
2020-05-05 03:29:42 +08:00
|
|
|
* @buf: (array): a #guchar buffer that contains the preview pixel data.
|
2004-07-31 09:03:00 +08:00
|
|
|
* @rowstride: rowstride of @buf
|
2004-07-30 01:10:28 +08:00
|
|
|
*
|
2004-12-27 18:24:16 +08:00
|
|
|
* Draws @buf on @area and queues a redraw on the given rectangle.
|
2004-07-30 01:10:28 +08:00
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_draw (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
const guchar *buf,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *src;
|
|
|
|
guchar *dest;
|
|
|
|
guint size;
|
|
|
|
GeglColor *color1;
|
|
|
|
GeglColor *color2;
|
|
|
|
guchar rgb1[3];
|
|
|
|
guchar rgb2[3];
|
|
|
|
gint row;
|
|
|
|
gint col;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
2007-04-18 03:02:55 +08:00
|
|
|
g_return_if_fail (width >= 0 && height >= 0);
|
2007-04-18 03:09:58 +08:00
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
g_return_if_fail (rowstride > 0);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width < 0 || x >= area->width)
|
2004-07-30 01:10:28 +08:00
|
|
|
return;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height < 0 || y >= area->height)
|
2004-07-30 01:10:28 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
gint bpp = gimp_preview_area_image_type_bytes (type);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2007-01-04 20:14:24 +08:00
|
|
|
buf -= x * bpp;
|
|
|
|
width += x;
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
buf -= y * rowstride;
|
|
|
|
height += y;
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->buf)
|
2004-07-31 09:03:00 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new0 (guchar, area->rowstride * area->height);
|
2004-07-31 09:03:00 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
size = 1 << (2 + area->check_size);
|
|
|
|
color1 = area->check_custom_color1;
|
|
|
|
color2 = area->check_custom_color2;
|
|
|
|
gimp_checks_get_colors (area->check_type, &color1, &color2);
|
2023-11-21 04:38:11 +08:00
|
|
|
gegl_color_get_pixel (color1, babl_format ("R'G'B' u8"), rgb1);
|
|
|
|
gegl_color_get_pixel (color2, babl_format ("R'G'B' u8"), rgb2);
|
|
|
|
g_object_unref (color1);
|
|
|
|
g_object_unref (color2);
|
2004-09-02 23:39:07 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
src = buf;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
memcpy (dest, src, 3 * width);
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s += 4, d+= 3)
|
|
|
|
{
|
|
|
|
switch (s[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = s[0];
|
|
|
|
d[1] = s[1];
|
|
|
|
d[2] = s[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s[2] - check_b) * alpha) >> 8;
|
2004-07-30 20:01:44 +08:00
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s++, d += 3)
|
|
|
|
{
|
2004-07-30 22:38:11 +08:00
|
|
|
d[0] = d[1] = d[2] = s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s += 2, d+= 3)
|
|
|
|
{
|
|
|
|
switch (s[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = s[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s[0] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s[0] - check_b) * alpha) >> 8;
|
2004-07-30 20:01:44 +08:00
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-07-30 01:10:28 +08:00
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s++, d += 3)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *colormap = area->colormap + 3 * s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2004-11-02 19:30:49 +08:00
|
|
|
d[0] = colormap[0];
|
|
|
|
d[1] = colormap[1];
|
|
|
|
d[2] = colormap[2];
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-07-30 01:10:28 +08:00
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
2004-08-07 08:04:16 +08:00
|
|
|
for (col = x; col < x + width; col++, s += 2, d += 3)
|
2004-07-30 01:10:28 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *colormap = area->colormap + 3 * s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
switch (s[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
2004-11-02 19:30:49 +08:00
|
|
|
d[0] = colormap[0];
|
|
|
|
d[1] = colormap[1];
|
|
|
|
d[2] = colormap[2];
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (colormap[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (colormap[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (colormap[2] - check_b) * alpha) >> 8;
|
2004-07-30 20:01:44 +08:00
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-09-10 01:11:16 +08:00
|
|
|
gimp_preview_area_queue_draw (area, x, y, width, height);
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_blend:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
|
|
|
* @width: buffer width
|
|
|
|
* @height: buffer height
|
|
|
|
* @type: the #GimpImageType of @buf1 and @buf2
|
2020-05-05 03:29:42 +08:00
|
|
|
* @buf1: (array): a #guchar buffer that contains the pixel data for
|
|
|
|
* the lower layer
|
2004-09-08 04:20:13 +08:00
|
|
|
* @rowstride1: rowstride of @buf1
|
2020-05-05 03:29:42 +08:00
|
|
|
* @buf2: (array): a #guchar buffer that contains the pixel data for
|
|
|
|
* the upper layer
|
2004-09-08 04:20:13 +08:00
|
|
|
* @rowstride2: rowstride of @buf2
|
|
|
|
* @opacity: The opacity of the first layer.
|
|
|
|
*
|
2004-12-27 18:24:16 +08:00
|
|
|
* Composites @buf1 on @buf2 with the given @opacity, draws the result
|
|
|
|
* to @area and queues a redraw on the given rectangle.
|
2004-09-08 04:20:13 +08:00
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_blend (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
const guchar *buf1,
|
|
|
|
gint rowstride1,
|
|
|
|
const guchar *buf2,
|
|
|
|
gint rowstride2,
|
|
|
|
guchar opacity)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *src1;
|
|
|
|
const guchar *src2;
|
|
|
|
guchar *dest;
|
|
|
|
guint size;
|
|
|
|
GeglColor *color1;
|
|
|
|
GeglColor *color2;
|
|
|
|
guchar rgb1[3];
|
|
|
|
guchar rgb2[3];
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
gint i;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
2007-04-18 03:02:55 +08:00
|
|
|
g_return_if_fail (width >= 0 && height >= 0);
|
2007-04-18 03:09:58 +08:00
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
g_return_if_fail (buf1 != NULL);
|
|
|
|
g_return_if_fail (buf2 != NULL);
|
|
|
|
g_return_if_fail (rowstride1 > 0);
|
|
|
|
g_return_if_fail (rowstride2 > 0);
|
|
|
|
|
2004-09-08 19:52:05 +08:00
|
|
|
switch (opacity)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gimp_preview_area_draw (area, x, y, width, height,
|
|
|
|
type, buf1, rowstride1);
|
|
|
|
return;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 19:52:05 +08:00
|
|
|
case 255:
|
|
|
|
gimp_preview_area_draw (area, x, y, width, height,
|
|
|
|
type, buf2, rowstride2);
|
|
|
|
return;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 19:52:05 +08:00
|
|
|
default:
|
2004-09-08 20:37:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width < 0 || x >= area->width)
|
2004-09-08 20:37:09 +08:00
|
|
|
return;
|
2004-09-08 19:52:05 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height < 0 || y >= area->height)
|
2004-09-08 20:37:09 +08:00
|
|
|
return;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
if (x < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
gint bpp = gimp_preview_area_image_type_bytes (type);
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2007-01-04 20:14:24 +08:00
|
|
|
buf1 -= x * bpp;
|
|
|
|
buf2 -= x * bpp;
|
|
|
|
width += x;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
x = 0;
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
if (y < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
buf1 -= y * rowstride1;
|
|
|
|
buf2 -= y * rowstride2;
|
|
|
|
height += y;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
y = 0;
|
|
|
|
}
|
2004-09-08 19:52:05 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->buf)
|
2004-09-08 20:37:09 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new0 (guchar, area->rowstride * area->height);
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
size = 1 << (2 + area->check_size);
|
|
|
|
color1 = area->check_custom_color1;
|
|
|
|
color2 = area->check_custom_color2;
|
|
|
|
gimp_checks_get_colors (area->check_type, &color1, &color2);
|
2023-11-21 04:38:11 +08:00
|
|
|
gegl_color_get_pixel (color1, babl_format ("R'G'B' u8"), rgb1);
|
|
|
|
gegl_color_get_pixel (color2, babl_format ("R'G'B' u8"), rgb2);
|
|
|
|
g_object_unref (color1);
|
|
|
|
g_object_unref (color2);
|
2004-09-08 20:37:09 +08:00
|
|
|
|
|
|
|
src1 = buf1;
|
|
|
|
src2 = buf2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-08 20:37:09 +08:00
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
for (col = x; col < x + width; col++, s1 += 3, s2 += 3, d+= 3)
|
|
|
|
{
|
|
|
|
d[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * opacity) >> 8;
|
|
|
|
d[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * opacity) >> 8;
|
|
|
|
d[2] = ((s1[2] << 8) + (s2[2] - s1[2]) * opacity) >> 8;
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 4, s2 += 4, d+= 3)
|
|
|
|
{
|
|
|
|
guchar inter[4];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[3] == s2[3])
|
2004-09-08 20:37:09 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * opacity) >> 8;
|
|
|
|
inter[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * opacity) >> 8;
|
|
|
|
inter[2] = ((s1[2] << 8) + (s2[2] - s1[2]) * opacity) >> 8;
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[3] = s1[3];
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[3] = ((s1[3] << 8) + (s2[3] - s1[3]) * opacity) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (inter[3])
|
|
|
|
{
|
2004-09-09 22:47:39 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
2004-09-09 21:22:27 +08:00
|
|
|
{
|
|
|
|
gushort a = s1[i] * s1[3];
|
|
|
|
gushort b = s2[i] * s2[3];
|
|
|
|
|
|
|
|
inter[i] =
|
|
|
|
(((a << 8) + (b - a) * opacity) >> 8) / inter[3];
|
|
|
|
}
|
|
|
|
}
|
2015-02-27 16:50:34 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2015-02-27 16:50:34 +08:00
|
|
|
switch (inter[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2015-02-27 16:50:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = inter[0];
|
|
|
|
d[1] = inter[1];
|
|
|
|
d[2] = inter[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (inter[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (inter[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (inter[2] - check_b) * alpha) >> 8;
|
2015-02-27 16:50:34 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
for (col = 0; col < width; col++, s1++, s2++, d += 3)
|
|
|
|
{
|
|
|
|
d[0] = d[1] = d[2] =
|
|
|
|
((s1[0] << 8) + (s2[0] - s1[0]) * opacity) >> 8;
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 2, s2 += 2, d+= 3)
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2005-07-09 02:18:00 +08:00
|
|
|
guchar inter[2] = { 0, };
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[1] == s2[1])
|
2004-09-08 19:52:05 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * opacity) >> 8;
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[1] = s1[1];
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * opacity) >> 8;
|
|
|
|
|
|
|
|
if (inter[1])
|
|
|
|
{
|
|
|
|
gushort a = s1[0] * s1[1];
|
|
|
|
gushort b = s2[0] * s2[1];
|
|
|
|
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[0] =
|
|
|
|
(((a << 8) + (b - a) * opacity) >> 8) / inter[1];
|
2004-09-09 21:22:27 +08:00
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
switch (inter[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 20:37:09 +08:00
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = inter[0];
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
default:
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (inter[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (inter[0] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (inter[0] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case GIMP_INDEXED_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-09-08 20:37:09 +08:00
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
for (col = 0; col < width; col++, s1++, s2++, d += 3)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *cmap1 = area->colormap + 3 * s1[0];
|
|
|
|
const guchar *cmap2 = area->colormap + 3 * s2[0];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
d[0] = ((cmap1[0] << 8) + (cmap2[0] - cmap1[0]) * opacity) >> 8;
|
|
|
|
d[1] = ((cmap1[1] << 8) + (cmap2[1] - cmap1[1]) * opacity) >> 8;
|
|
|
|
d[2] = ((cmap1[2] << 8) + (cmap2[2] - cmap1[2]) * opacity) >> 8;
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-09-08 20:37:09 +08:00
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
for (col = x; col < x + width; col++, s1 += 2, s2 += 2, d += 3)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *cmap1 = area->colormap + 3 * s1[0];
|
|
|
|
const guchar *cmap2 = area->colormap + 3 * s2[0];
|
2004-09-08 20:37:09 +08:00
|
|
|
guchar inter[4];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[1] == s2[1])
|
2004-09-08 20:37:09 +08:00
|
|
|
{
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[0] = (((cmap1[0] << 8) +
|
|
|
|
(cmap2[0] - cmap1[0]) * opacity) >> 8);
|
|
|
|
inter[1] = (((cmap1[1] << 8) +
|
|
|
|
(cmap2[1] - cmap1[1]) * opacity) >> 8);
|
|
|
|
inter[2] = (((cmap1[2] << 8) +
|
|
|
|
(cmap2[2] - cmap1[2]) * opacity) >> 8);
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[3] = s1[1];
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[3] = ((s1[1] << 8) + (s2[1] - s1[1]) * opacity) >> 8;
|
|
|
|
|
|
|
|
if (inter[3])
|
|
|
|
{
|
2004-09-09 22:47:39 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
2004-09-09 21:22:27 +08:00
|
|
|
{
|
|
|
|
gushort a = cmap1[i] * s1[1];
|
|
|
|
gushort b = cmap2[i] * s2[1];
|
|
|
|
|
|
|
|
inter[i] =
|
|
|
|
(((a << 8) + (b - a) * opacity) >> 8) / inter[3];
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
switch (inter[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 20:37:09 +08:00
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
case 255:
|
|
|
|
d[0] = inter[0];
|
|
|
|
d[1] = inter[1];
|
|
|
|
d[2] = inter[2];
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-08 20:37:09 +08:00
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (inter[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (inter[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (inter[2] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 19:52:05 +08:00
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-09-10 01:11:16 +08:00
|
|
|
gimp_preview_area_queue_draw (area, x, y, width, height);
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_area_mask:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
|
|
|
* @width: buffer width
|
|
|
|
* @height: buffer height
|
|
|
|
* @type: the #GimpImageType of @buf1 and @buf2
|
2020-05-05 03:29:42 +08:00
|
|
|
* @buf1: (array): a #guchar buffer that contains the pixel data for
|
2004-12-27 18:24:16 +08:00
|
|
|
* the lower layer
|
2004-09-08 04:20:13 +08:00
|
|
|
* @rowstride1: rowstride of @buf1
|
2020-05-05 03:29:42 +08:00
|
|
|
* @buf2: (array): a #guchar buffer that contains the pixel data for
|
2004-12-27 18:24:16 +08:00
|
|
|
* the upper layer
|
2004-09-08 04:20:13 +08:00
|
|
|
* @rowstride2: rowstride of @buf2
|
2020-05-05 03:29:42 +08:00
|
|
|
* @mask: (array): a #guchar buffer representing the mask of the second
|
2004-09-08 04:20:13 +08:00
|
|
|
* layer.
|
|
|
|
* @rowstride_mask: rowstride for the mask.
|
|
|
|
*
|
2004-12-27 18:24:16 +08:00
|
|
|
* Composites @buf1 on @buf2 with the given @mask, draws the result on
|
|
|
|
* @area and queues a redraw on the given rectangle.
|
2004-09-08 04:20:13 +08:00
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_mask (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
const guchar *buf1,
|
|
|
|
gint rowstride1,
|
|
|
|
const guchar *buf2,
|
|
|
|
gint rowstride2,
|
2004-12-27 18:24:16 +08:00
|
|
|
const guchar *mask,
|
2004-09-08 04:20:13 +08:00
|
|
|
gint rowstride_mask)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *src1;
|
|
|
|
const guchar *src2;
|
|
|
|
const guchar *src_mask;
|
|
|
|
guchar *dest;
|
|
|
|
guint size;
|
|
|
|
GeglColor *color1;
|
|
|
|
GeglColor *color2;
|
|
|
|
guchar rgb1[3];
|
|
|
|
guchar rgb2[3];
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
gint i;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
2007-04-18 03:02:55 +08:00
|
|
|
g_return_if_fail (width >= 0 && height >= 0);
|
2007-04-18 03:09:58 +08:00
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
g_return_if_fail (buf1 != NULL);
|
|
|
|
g_return_if_fail (buf2 != NULL);
|
|
|
|
g_return_if_fail (mask != NULL);
|
|
|
|
g_return_if_fail (rowstride1 > 0);
|
|
|
|
g_return_if_fail (rowstride2 > 0);
|
|
|
|
g_return_if_fail (rowstride_mask > 0);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width < 0 || x >= area->width)
|
2004-09-08 04:20:13 +08:00
|
|
|
return;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height < 0 || y >= area->height)
|
2004-09-08 04:20:13 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
gint bpp = gimp_preview_area_image_type_bytes (type);
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2007-01-04 20:14:24 +08:00
|
|
|
buf1 -= x * bpp;
|
|
|
|
buf2 -= x * bpp;
|
|
|
|
mask -= x;
|
|
|
|
width += x;
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
buf1 -= y * rowstride1;
|
|
|
|
buf2 -= y * rowstride2;
|
|
|
|
mask -= y * rowstride_mask;
|
|
|
|
height += y;
|
2004-09-08 20:37:09 +08:00
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->buf)
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new0 (guchar, area->rowstride * area->height);
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
size = 1 << (2 + area->check_size);
|
|
|
|
color1 = area->check_custom_color1;
|
|
|
|
color2 = area->check_custom_color2;
|
|
|
|
gimp_checks_get_colors (area->check_type, &color1, &color2);
|
2023-11-21 04:38:11 +08:00
|
|
|
gegl_color_get_pixel (color1, babl_format ("R'G'B' u8"), rgb1);
|
|
|
|
gegl_color_get_pixel (color2, babl_format ("R'G'B' u8"), rgb2);
|
|
|
|
g_object_unref (color1);
|
|
|
|
g_object_unref (color2);
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
src1 = buf1;
|
|
|
|
src2 = buf2;
|
|
|
|
src_mask = mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 3, s2 += 3, m++, d+= 3)
|
|
|
|
{
|
|
|
|
d[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * m[0]) >> 8;
|
|
|
|
d[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * m[0]) >> 8;
|
|
|
|
d[2] = ((s1[2] << 8) + (s2[2] - s1[2]) * m[0]) >> 8;
|
|
|
|
}
|
2004-12-27 18:24:16 +08:00
|
|
|
|
2004-09-08 04:20:13 +08:00
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 4, s2 += 4, m++, d+= 3)
|
|
|
|
{
|
|
|
|
switch (m[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (s1[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = s1[0];
|
|
|
|
d[1] = s1[1];
|
|
|
|
d[2] = s1[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s1[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s1[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s1[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s1[2] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
switch (s2[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = s2[0];
|
|
|
|
d[1] = s2[1];
|
|
|
|
d[2] = s2[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s2[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s2[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s2[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s2[2] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
guchar inter[4];
|
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[3] == s2[3])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * m[0]) >> 8;
|
|
|
|
inter[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * m[0]) >> 8;
|
|
|
|
inter[2] = ((s1[2] << 8) + (s2[2] - s1[2]) * m[0]) >> 8;
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[3] = s1[3];
|
|
|
|
}
|
2004-09-09 21:22:27 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
inter[3] = ((s1[3] << 8) + (s2[3] - s1[3]) * m[0]) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (inter[3])
|
|
|
|
{
|
2004-09-09 22:47:39 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
2004-09-09 21:22:27 +08:00
|
|
|
{
|
|
|
|
gushort a = s1[i] * s1[3];
|
|
|
|
gushort b = s2[i] * s2[3];
|
|
|
|
|
|
|
|
inter[i] =
|
|
|
|
(((a << 8) + (b - a) * m[0]) >> 8) / inter[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
switch (inter[3])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-09 21:22:27 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = inter[0];
|
|
|
|
d[1] = inter[1];
|
|
|
|
d[2] = inter[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = (((check_r << 8) +
|
|
|
|
(inter[0] - check_r) * alpha) >> 8);
|
|
|
|
d[1] = (((check_g << 8) +
|
|
|
|
(inter[1] - check_g) * alpha) >> 8);
|
|
|
|
d[2] = (((check_b << 8) +
|
|
|
|
(inter[2] - check_b) * alpha) >> 8);
|
2004-09-09 21:22:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s1++, s2++, m++, d += 3)
|
2004-12-27 18:24:16 +08:00
|
|
|
d[0] = d[1] = d[2] = ((s1[0] << 8) + (s2[0] - s1[0]) * m[0]) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
2004-09-08 20:37:09 +08:00
|
|
|
for (row = y; row < y + height; row++)
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 2, s2 += 2, m++, d+= 3)
|
|
|
|
{
|
|
|
|
switch (m[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (s1[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = s1[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s1[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s1[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s1[0] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s1[0] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
switch (s2[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = s2[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s2[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (s2[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (s2[0] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (s2[0] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2005-07-09 02:18:00 +08:00
|
|
|
guchar inter[2] = { 0, };
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[1] == s2[1])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[0] = ((s1[0] << 8) + (s2[0] - s1[0]) * m[0]) >> 8;
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[1] = s1[1];
|
2004-09-08 20:37:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[1] = ((s1[1] << 8) + (s2[1] - s1[1]) * m[0]) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (inter[1])
|
|
|
|
{
|
|
|
|
gushort a = s1[0] * s1[1];
|
|
|
|
gushort b = s2[0] * s2[1];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[0] =
|
|
|
|
(((a << 8) + (b - a) * m[0]) >> 8) / inter[1];
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
switch (inter[1])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-09 21:22:27 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = inter[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (inter[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (inter[0] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (inter[0] - check_b) * alpha) >> 8;
|
2004-09-09 21:22:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-09-08 04:20:13 +08:00
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s1++, s2++, m++, d += 3)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *cmap1 = area->colormap + 3 * s1[0];
|
|
|
|
const guchar *cmap2 = area->colormap + 3 * s2[0];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
d[0] = ((cmap1[0] << 8) + (cmap2[0] - cmap1[0]) * m[0]) >> 8;
|
|
|
|
d[1] = ((cmap1[1] << 8) + (cmap2[1] - cmap1[1]) * m[0]) >> 8;
|
|
|
|
d[2] = ((cmap1[2] << 8) + (cmap2[2] - cmap1[2]) * m[0]) >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
2024-07-29 09:51:38 +08:00
|
|
|
g_return_if_fail (area->colormap != NULL);
|
2004-09-08 04:20:13 +08:00
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s1 = src1;
|
|
|
|
const guchar *s2 = src2;
|
|
|
|
const guchar *m = src_mask;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s1 += 2, s2 += 2, m++, d += 3)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
const guchar *cmap1 = area->colormap + 3 * s1[0];
|
|
|
|
const guchar *cmap2 = area->colormap + 3 * s2[0];
|
2004-09-08 04:20:13 +08:00
|
|
|
|
|
|
|
switch (m[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (s1[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = cmap1[0];
|
|
|
|
d[1] = cmap1[1];
|
|
|
|
d[2] = cmap1[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s1[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (cmap1[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (cmap1[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (cmap1[2] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
switch (s2[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-08 04:20:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = cmap2[0];
|
|
|
|
d[1] = cmap2[1];
|
|
|
|
d[2] = cmap2[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = s2[1] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2020-05-25 04:26:50 +08:00
|
|
|
|
|
|
|
d[0] = ((check_r << 8) + (cmap2[0] - check_r) * alpha) >> 8;
|
|
|
|
d[1] = ((check_g << 8) + (cmap2[1] - check_g) * alpha) >> 8;
|
|
|
|
d[2] = ((check_b << 8) + (cmap2[2] - check_b) * alpha) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
guchar inter[4];
|
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (s1[1] == s2[1])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 22:47:39 +08:00
|
|
|
inter[0] = (((cmap1[0] << 8) +
|
|
|
|
(cmap2[0] - cmap1[0]) * m[0]) >> 8);
|
|
|
|
inter[1] = (((cmap1[1] << 8) +
|
|
|
|
(cmap2[1] - cmap1[1]) * m[0]) >> 8);
|
|
|
|
inter[2] = (((cmap1[2] << 8) +
|
|
|
|
(cmap2[2] - cmap1[2]) * m[0]) >> 8);
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[3] = s1[1];
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-09-08 20:37:09 +08:00
|
|
|
else
|
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
inter[3] = ((s1[1] << 8) + (s2[1] - s1[1]) * m[0]) >> 8;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
if (inter[3])
|
|
|
|
{
|
|
|
|
for (i = 0 ; i < 3 ; i++)
|
|
|
|
{
|
|
|
|
gushort a = cmap1[i] * s1[1];
|
|
|
|
gushort b = cmap2[i] * s2[1];
|
|
|
|
|
2004-12-27 18:24:16 +08:00
|
|
|
inter[i] = ((((a << 8) + (b - a) * m[0]) >> 8)
|
|
|
|
/ inter[3]);
|
2004-09-09 21:22:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-09 21:22:27 +08:00
|
|
|
switch (inter[3])
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-09 21:22:27 +08:00
|
|
|
case 0:
|
2024-07-29 09:51:38 +08:00
|
|
|
d[0] = CHECK_R (area, row, col);
|
|
|
|
d[1] = CHECK_G (area, row, col);
|
|
|
|
d[2] = CHECK_B (area, row, col);
|
2004-09-09 21:22:27 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = inter[0];
|
|
|
|
d[1] = inter[1];
|
|
|
|
d[2] = inter[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-05-25 04:26:50 +08:00
|
|
|
register guint alpha = inter[3] + 1;
|
2024-07-29 09:51:38 +08:00
|
|
|
register guint check_r = CHECK_R (area, row, col);
|
|
|
|
register guint check_g = CHECK_G (area, row, col);
|
|
|
|
register guint check_b = CHECK_B (area, row, col);
|
2004-09-09 21:22:27 +08:00
|
|
|
|
2004-12-27 18:24:16 +08:00
|
|
|
d[0] =
|
2020-05-25 04:26:50 +08:00
|
|
|
((check_r << 8) + (inter[0] - check_r) * alpha) >> 8;
|
2004-12-27 18:24:16 +08:00
|
|
|
d[1] =
|
2020-05-25 04:26:50 +08:00
|
|
|
((check_g << 8) + (inter[1] - check_g) * alpha) >> 8;
|
2004-12-27 18:24:16 +08:00
|
|
|
d[2] =
|
2020-05-25 04:26:50 +08:00
|
|
|
((check_b << 8) + (inter[2] - check_b) * alpha) >> 8;
|
2004-09-09 21:22:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src1 += rowstride1;
|
|
|
|
src2 += rowstride2;
|
|
|
|
src_mask += rowstride_mask;
|
2024-07-29 09:51:38 +08:00
|
|
|
dest += area->rowstride;
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-09-10 01:11:16 +08:00
|
|
|
gimp_preview_area_queue_draw (area, x, y, width, height);
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
|
2004-07-31 09:03:00 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_fill:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
2007-04-18 03:09:58 +08:00
|
|
|
* @width: width of the rectangle to fill
|
|
|
|
* @height: height of the rectangle to fill
|
2004-12-27 18:24:16 +08:00
|
|
|
* @red: red component of the fill color (0-255)
|
|
|
|
* @green: green component of the fill color (0-255)
|
|
|
|
* @blue: red component of the fill color (0-255)
|
2004-07-31 09:03:00 +08:00
|
|
|
*
|
2007-04-18 03:09:58 +08:00
|
|
|
* Fills the given rectangle of @area in the given color and queues a
|
|
|
|
* redraw.
|
2004-07-31 09:03:00 +08:00
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_fill (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
guchar red,
|
|
|
|
guchar green,
|
|
|
|
guchar blue)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
guchar *dest;
|
|
|
|
guchar *d;
|
|
|
|
gint row;
|
|
|
|
gint col;
|
2004-07-31 09:03:00 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
2007-04-18 03:02:55 +08:00
|
|
|
g_return_if_fail (width >= 0 && height >= 0);
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2007-04-18 03:09:58 +08:00
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width < 0 || x >= area->width)
|
2004-07-31 09:03:00 +08:00
|
|
|
return;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height < 0 || y >= area->height)
|
2004-07-31 09:03:00 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
width += x;
|
2004-07-31 09:03:00 +08:00
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
2004-07-31 09:03:00 +08:00
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
2007-01-04 20:14:24 +08:00
|
|
|
height += y;
|
2004-07-31 09:03:00 +08:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! area->buf)
|
2004-07-31 09:03:00 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new0 (guchar, area->rowstride * area->height);
|
2004-07-31 09:03:00 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2004-09-08 20:54:36 +08:00
|
|
|
/* colorize first row */
|
|
|
|
for (col = 0, d = dest; col < width; col++, d+= 3)
|
2004-07-31 09:03:00 +08:00
|
|
|
{
|
2004-09-08 20:54:36 +08:00
|
|
|
d[0] = red;
|
|
|
|
d[1] = green;
|
|
|
|
d[2] = blue;
|
|
|
|
}
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2004-09-08 20:54:36 +08:00
|
|
|
/* copy first row to remaining rows */
|
|
|
|
for (row = 1, d = dest; row < height; row++)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
d += area->rowstride;
|
2004-09-08 20:54:36 +08:00
|
|
|
memcpy (d, dest, width * 3);
|
2004-07-31 09:03:00 +08:00
|
|
|
}
|
|
|
|
|
2004-09-10 01:11:16 +08:00
|
|
|
gimp_preview_area_queue_draw (area, x, y, width, height);
|
2004-07-31 09:03:00 +08:00
|
|
|
}
|
|
|
|
|
2023-08-29 01:19:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_reset:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
*
|
2023-10-02 06:07:46 +08:00
|
|
|
* Reset any previous drawing done through [class@GimpUi.PreviewArea] functions.
|
2023-08-29 01:19:50 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_reset (GimpPreviewArea *area)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkAllocation allocation;
|
2023-08-29 01:19:50 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->buf)
|
2023-08-29 01:19:50 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (area->buf);
|
2023-08-29 01:19:50 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->buf = NULL;
|
|
|
|
area->rowstride = 0;
|
2023-08-29 01:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (area), &allocation);
|
|
|
|
gimp_preview_area_queue_draw (area, 0, 0, allocation.width, allocation.height);
|
|
|
|
}
|
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_set_offsets:
|
|
|
|
* @area: a #GimpPreviewArea
|
|
|
|
* @x: horizontal offset
|
|
|
|
* @y: vertical offset
|
|
|
|
*
|
|
|
|
* Sets the offsets of the previewed area. This information is used
|
|
|
|
* when drawing the checkerboard and to determine the dither offsets.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-01 09:18:19 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_set_offsets (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->offset_x = x;
|
|
|
|
area->offset_y = y;
|
2004-09-01 09:18:19 +08:00
|
|
|
}
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
/**
|
2004-11-02 19:30:49 +08:00
|
|
|
* gimp_preview_area_set_colormap:
|
2004-07-30 01:10:28 +08:00
|
|
|
* @area: a #GimpPreviewArea
|
2020-05-04 08:10:55 +08:00
|
|
|
* @colormap: (array): a #guchar buffer that contains the colormap
|
2004-07-30 01:10:28 +08:00
|
|
|
* @num_colors: the number of colors in the colormap
|
|
|
|
*
|
|
|
|
* Sets the colormap for the #GimpPreviewArea widget. You need to
|
|
|
|
* call this function before you use gimp_preview_area_draw() with
|
|
|
|
* an image type of %GIMP_INDEXED_IMAGE or %GIMP_INDEXEDA_IMAGE.
|
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
2004-11-02 19:30:49 +08:00
|
|
|
gimp_preview_area_set_colormap (GimpPreviewArea *area,
|
|
|
|
const guchar *colormap,
|
|
|
|
gint num_colors)
|
2004-07-30 01:10:28 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
2004-11-02 19:30:49 +08:00
|
|
|
g_return_if_fail (colormap != NULL || num_colors == 0);
|
2004-07-30 05:08:13 +08:00
|
|
|
g_return_if_fail (num_colors >= 0 && num_colors <= 256);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
if (num_colors > 0)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->colormap)
|
|
|
|
memset (area->colormap, 0, 3 * 256);
|
2007-07-07 04:47:44 +08:00
|
|
|
else
|
2024-07-29 09:51:38 +08:00
|
|
|
area->colormap = g_new0 (guchar, 3 * 256);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
memcpy (area->colormap, colormap, 3 * num_colors);
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (area->colormap);
|
|
|
|
area->colormap = NULL;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
2004-09-04 03:34:59 +08:00
|
|
|
|
2016-05-25 03:43:20 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_set_color_config:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @config: a #GimpColorConfig object.
|
|
|
|
*
|
|
|
|
* Sets the color management configuration to use with this preview area.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_preview_area_set_color_config (GimpPreviewArea *area,
|
|
|
|
GimpColorConfig *config)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (config != area->config)
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->config)
|
2016-05-25 03:43:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (area->config,
|
2016-06-02 04:38:58 +08:00
|
|
|
gimp_preview_area_destroy_transform,
|
2016-05-31 18:24:58 +08:00
|
|
|
area);
|
|
|
|
|
2016-06-02 04:38:58 +08:00
|
|
|
gimp_preview_area_destroy_transform (area);
|
2016-05-25 03:43:20 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_set_object (&area->config, config);
|
2016-05-25 03:43:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (area->config)
|
2016-05-31 18:24:58 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_signal_connect_swapped (area->config, "notify",
|
2016-06-02 04:38:58 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_destroy_transform),
|
|
|
|
area);
|
2016-05-31 18:24:58 +08:00
|
|
|
}
|
2016-05-25 03:43:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 03:29:42 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_get_size:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @width: (out): The preview areay width
|
|
|
|
* @height: (out): The preview areay height
|
|
|
|
*
|
|
|
|
* Gets the preview area size
|
|
|
|
*/
|
2018-05-03 21:17:43 +08:00
|
|
|
void
|
|
|
|
gimp_preview_area_get_size (GimpPreviewArea *area,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (width) *width = area->width;
|
|
|
|
if (height) *height = area->height;
|
2018-05-03 21:17:43 +08:00
|
|
|
}
|
|
|
|
|
2004-09-09 22:47:39 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_set_max_size:
|
2004-09-10 06:36:15 +08:00
|
|
|
* @area: a #GimpPreviewArea widget
|
|
|
|
* @width: the maximum width in pixels or -1 to unset the limit
|
|
|
|
* @height: the maximum height in pixels or -1 to unset the limit
|
|
|
|
*
|
|
|
|
* Usually a #GimpPreviewArea fills the size that it is
|
2013-01-27 23:52:38 +08:00
|
|
|
* allocated. This function allows you to limit the preview area to a
|
2004-09-10 06:36:15 +08:00
|
|
|
* maximum size. If a larger size is allocated for the widget, the
|
|
|
|
* preview will draw itself centered into the allocated area.
|
2004-09-09 22:47:39 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-09 22:47:39 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_set_max_size (GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
area->max_width = width;
|
|
|
|
area->max_height = height;
|
2004-09-09 22:47:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-04 03:34:59 +08:00
|
|
|
|
|
|
|
/* popup menu */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_menu_toggled (GtkWidget *item,
|
|
|
|
GimpPreviewArea *area)
|
|
|
|
{
|
|
|
|
gboolean active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
|
|
|
|
|
|
|
|
if (active)
|
|
|
|
{
|
2004-12-27 18:24:16 +08:00
|
|
|
const gchar *name = g_object_get_data (G_OBJECT (item),
|
|
|
|
"gimp-preview-area-prop-name");
|
2004-09-04 03:34:59 +08:00
|
|
|
if (name)
|
2004-12-27 18:24:16 +08:00
|
|
|
{
|
|
|
|
gint value =
|
|
|
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item),
|
|
|
|
"gimp-preview-area-prop-value"));
|
|
|
|
g_object_set (area,
|
|
|
|
name, value,
|
|
|
|
NULL);
|
|
|
|
}
|
2004-09-04 03:34:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
gimp_preview_area_menu_new (GimpPreviewArea *area,
|
|
|
|
const gchar *property)
|
|
|
|
{
|
|
|
|
GParamSpec *pspec;
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
|
|
|
GSList *group = NULL;
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (area), property);
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (pspec), NULL);
|
|
|
|
|
|
|
|
g_object_get (area,
|
|
|
|
property, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
enum_class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
|
|
|
|
for (enum_value = enum_class->values; enum_value->value_name; enum_value++)
|
|
|
|
{
|
2004-10-26 01:55:25 +08:00
|
|
|
const gchar *name = gimp_enum_value_get_desc (enum_class, enum_value);
|
2004-09-04 03:34:59 +08:00
|
|
|
|
|
|
|
item = gtk_radio_menu_item_new_with_label (group, name);
|
|
|
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (item),
|
|
|
|
"gimp-preview-area-prop-name",
|
|
|
|
(gpointer) property);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (item),
|
|
|
|
"gimp-preview-area-prop-value",
|
|
|
|
GINT_TO_POINTER (enum_value->value));
|
|
|
|
|
|
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
|
|
|
|
(enum_value->value == value));
|
|
|
|
|
|
|
|
g_signal_connect (item, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_area_menu_toggled),
|
|
|
|
area);
|
|
|
|
|
|
|
|
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
|
|
|
|
}
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label (g_param_spec_get_nick (pspec));
|
|
|
|
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
|
|
|
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2004-09-04 07:41:39 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_menu_popup:
|
|
|
|
* @area: a #GimpPreviewArea
|
2020-05-05 03:29:42 +08:00
|
|
|
* @event: (nullable): the button event that causes the menu to popup or %NULL
|
2004-09-04 07:41:39 +08:00
|
|
|
*
|
2012-11-11 22:50:25 +08:00
|
|
|
* Creates a popup menu that allows one to configure the size and type of
|
2004-09-04 07:41:39 +08:00
|
|
|
* the checkerboard pattern that the @area uses to visualize transparency.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-04 07:41:39 +08:00
|
|
|
**/
|
2004-09-04 03:34:59 +08:00
|
|
|
void
|
|
|
|
gimp_preview_area_menu_popup (GimpPreviewArea *area,
|
2004-09-04 07:41:39 +08:00
|
|
|
GdkEventButton *event)
|
2004-09-04 03:34:59 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
gtk_menu_set_screen (GTK_MENU (menu),
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (area)));
|
|
|
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu),
|
|
|
|
gimp_preview_area_menu_new (area, "check-type"));
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu),
|
|
|
|
gimp_preview_area_menu_new (area, "check-size"));
|
app, libgimp, libgimpbase, libgimpwidgets: better checkboard colors API.
- Some coding style fixes (alignment, etc.).
- Adding missing "Since: 3.0" annotations. We are still wondering
whether this should go in 2.10, in which case, it would become
"Since: 2.10.32" annotations. See discussion in !274.
- Changing gimp_checks_get_colors() signature: merge the 4 color
arguments into 2 (inout) arguments which seems a bit nicer in C,
whereas binding handles such arguments correctly. The other
alternative would have been to at least change the order to have out
arguments in the end.
I also hesitated to get another API in libgimp, which would have been
config-aware (just returning the 2 check colors, depending on user-set
Preferences), then having GimpPreviewArea handling 2 colors (without a
GimpCheckType input). But actually, doing this, we'd remove the nice
menu popup where one could choose a generic check type (not everyone
wants to play with specific non-gray colors) in Gimp*Preview widgets.
So in the end, I left this whole thing as-is.
Instead I document the function with code sample to initialize
properly the GimpPreviewArea (since libgimpwidgets/ are independent
with no knowledge of the core config) in order to respect user
preferences.
- Hide the color properties in gimp_preview_area_menu_new() because
anyway gimp_preview_area_menu_new() does not support GimpRGB
properties right now (so all we get are warnings). It's still possible
to select custom colors on GimpPreviewArea, simply we are stuck at the
ones set in Preferences globally for now (unless a plug-in creates
custom GUI to set these).
Fixed Conflicts from !274:
libgimp/gimp.h
libgimpwidgets/gimppreviewarea.c
2022-05-14 01:00:07 +08:00
|
|
|
#if 0
|
|
|
|
/* gimp_preview_area_menu_new() currently only handles enum types, and
|
|
|
|
* in particular not color properties.
|
|
|
|
*/
|
2020-05-25 04:26:50 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu),
|
|
|
|
gimp_preview_area_menu_new (area, "check-custom-color1"));
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu),
|
|
|
|
gimp_preview_area_menu_new (area, "check-custom-color2"));
|
app, libgimp, libgimpbase, libgimpwidgets: better checkboard colors API.
- Some coding style fixes (alignment, etc.).
- Adding missing "Since: 3.0" annotations. We are still wondering
whether this should go in 2.10, in which case, it would become
"Since: 2.10.32" annotations. See discussion in !274.
- Changing gimp_checks_get_colors() signature: merge the 4 color
arguments into 2 (inout) arguments which seems a bit nicer in C,
whereas binding handles such arguments correctly. The other
alternative would have been to at least change the order to have out
arguments in the end.
I also hesitated to get another API in libgimp, which would have been
config-aware (just returning the 2 check colors, depending on user-set
Preferences), then having GimpPreviewArea handling 2 colors (without a
GimpCheckType input). But actually, doing this, we'd remove the nice
menu popup where one could choose a generic check type (not everyone
wants to play with specific non-gray colors) in Gimp*Preview widgets.
So in the end, I left this whole thing as-is.
Instead I document the function with code sample to initialize
properly the GimpPreviewArea (since libgimpwidgets/ are independent
with no knowledge of the core config) in order to respect user
preferences.
- Hide the color properties in gimp_preview_area_menu_new() because
anyway gimp_preview_area_menu_new() does not support GimpRGB
properties right now (so all we get are warnings). It's still possible
to select custom colors on GimpPreviewArea, simply we are stuck at the
ones set in Preferences globally for now (unless a plug-in creates
custom GUI to set these).
Fixed Conflicts from !274:
libgimp/gimp.h
libgimpwidgets/gimppreviewarea.c
2022-05-14 01:00:07 +08:00
|
|
|
#endif
|
2004-09-04 03:34:59 +08:00
|
|
|
|
2018-05-02 05:21:04 +08:00
|
|
|
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) event);
|
2004-09-04 03:34:59 +08:00
|
|
|
}
|