2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-05-16 21:11:47 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpbrushclipboard.c
|
|
|
|
* Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-05-16 21:11:47 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-05-16 21:11:47 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-05-16 21:11:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2006-05-16 21:11:47 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpbuffer.h"
|
2014-10-12 07:16:32 +08:00
|
|
|
#include "gimpbrush-private.h"
|
2006-05-16 21:11:47 +08:00
|
|
|
#include "gimpbrushclipboard.h"
|
|
|
|
#include "gimpimage.h"
|
2017-04-20 03:52:10 +08:00
|
|
|
#include "gimppickable.h"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "gimptempbuf.h"
|
2006-05-16 21:11:47 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2017-04-20 03:52:10 +08:00
|
|
|
#define BRUSH_MAX_SIZE 1024
|
|
|
|
|
2006-05-16 21:11:47 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2017-04-20 04:33:44 +08:00
|
|
|
PROP_GIMP,
|
|
|
|
PROP_MASK_ONLY
|
2006-05-16 21:11:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_brush_clipboard_constructed (GObject *object);
|
2006-05-16 21:11:47 +08:00
|
|
|
static void gimp_brush_clipboard_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_brush_clipboard_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
#if 0
|
|
|
|
static GimpData * gimp_brush_clipboard_duplicate (GimpData *data);
|
|
|
|
#endif
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
static void gimp_brush_clipboard_changed (Gimp *gimp,
|
2006-05-16 21:11:47 +08:00
|
|
|
GimpBrush *brush);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpBrushClipboard, gimp_brush_clipboard, GIMP_TYPE_BRUSH)
|
|
|
|
|
|
|
|
#define parent_class gimp_brush_clipboard_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_clipboard_class_init (GimpBrushClipboardClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
#if 0
|
|
|
|
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
object_class->constructed = gimp_brush_clipboard_constructed;
|
2006-05-16 21:11:47 +08:00
|
|
|
object_class->set_property = gimp_brush_clipboard_set_property;
|
|
|
|
object_class->get_property = gimp_brush_clipboard_get_property;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
data_class->duplicate = gimp_brush_clipboard_duplicate;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_GIMP,
|
|
|
|
g_param_spec_object ("gimp", NULL, NULL,
|
|
|
|
GIMP_TYPE_GIMP,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2017-04-20 04:33:44 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_MASK_ONLY,
|
|
|
|
g_param_spec_boolean ("mask-only", NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_clipboard_init (GimpBrushClipboard *brush)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_clipboard_constructed (GObject *object)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2011-01-13 05:53:58 +08:00
|
|
|
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (object);
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2006-05-16 21:11:47 +08:00
|
|
|
|
|
|
|
g_assert (GIMP_IS_GIMP (brush->gimp));
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
g_signal_connect_object (brush->gimp, "clipboard-changed",
|
|
|
|
G_CALLBACK (gimp_brush_clipboard_changed),
|
2006-05-16 21:11:47 +08:00
|
|
|
brush, 0);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_brush_clipboard_changed (brush->gimp, GIMP_BRUSH (brush));
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_clipboard_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GIMP:
|
2006-11-25 22:57:26 +08:00
|
|
|
brush->gimp = g_value_get_object (value);
|
2006-05-16 21:11:47 +08:00
|
|
|
break;
|
2017-04-20 04:33:44 +08:00
|
|
|
|
|
|
|
case PROP_MASK_ONLY:
|
|
|
|
brush->mask_only = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2006-05-16 21:11:47 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_clipboard_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GIMP:
|
|
|
|
g_value_set_object (value, brush->gimp);
|
|
|
|
break;
|
2017-04-20 04:33:44 +08:00
|
|
|
|
|
|
|
case PROP_MASK_ONLY:
|
|
|
|
g_value_set_boolean (value, brush->mask_only);
|
|
|
|
break;
|
|
|
|
|
2006-05-16 21:11:47 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static GimpData *
|
|
|
|
gimp_brush_clipboard_duplicate (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (data);
|
|
|
|
|
|
|
|
return gimp_brush_clipboard_new (brush->gimp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GimpData *
|
2017-04-20 04:33:44 +08:00
|
|
|
gimp_brush_clipboard_new (Gimp *gimp,
|
|
|
|
gboolean mask_only)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2017-04-20 04:33:44 +08:00
|
|
|
const gchar *name;
|
|
|
|
|
2006-05-16 21:11:47 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2017-04-20 04:33:44 +08:00
|
|
|
if (mask_only)
|
|
|
|
name = _("Clipboard Mask");
|
|
|
|
else
|
|
|
|
name = _("Clipboard Image");
|
|
|
|
|
2006-05-17 18:24:03 +08:00
|
|
|
return g_object_new (GIMP_TYPE_BRUSH_CLIPBOARD,
|
2017-04-20 04:33:44 +08:00
|
|
|
"name", name,
|
|
|
|
"gimp", gimp,
|
|
|
|
"mask-only", mask_only,
|
2006-05-17 18:24:03 +08:00
|
|
|
NULL);
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_brush_clipboard_changed (Gimp *gimp,
|
|
|
|
GimpBrush *brush)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2017-04-20 03:52:10 +08:00
|
|
|
GimpObject *paste;
|
|
|
|
GeglBuffer *buffer = NULL;
|
2016-09-17 23:39:54 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
if (brush->priv->mask)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2014-10-12 07:16:32 +08:00
|
|
|
gimp_temp_buf_unref (brush->priv->mask);
|
|
|
|
brush->priv->mask = NULL;
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
if (brush->priv->pixmap)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2014-10-12 07:16:32 +08:00
|
|
|
gimp_temp_buf_unref (brush->priv->pixmap);
|
|
|
|
brush->priv->pixmap = NULL;
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
2017-04-20 03:52:10 +08:00
|
|
|
paste = gimp_get_clipboard_object (gimp);
|
|
|
|
|
|
|
|
if (GIMP_IS_IMAGE (paste))
|
|
|
|
{
|
|
|
|
gimp_pickable_flush (GIMP_PICKABLE (paste));
|
|
|
|
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (paste));
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_BUFFER (paste))
|
|
|
|
{
|
|
|
|
buffer = gimp_buffer_get_buffer (GIMP_BUFFER (paste));
|
|
|
|
}
|
2016-09-17 23:39:54 +08:00
|
|
|
|
2017-04-20 03:52:10 +08:00
|
|
|
if (buffer)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2012-03-31 22:35:07 +08:00
|
|
|
const Babl *format = gegl_buffer_get_format (buffer);
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2017-04-20 03:52:10 +08:00
|
|
|
width = MIN (gegl_buffer_get_width (buffer), BRUSH_MAX_SIZE);
|
|
|
|
height = MIN (gegl_buffer_get_height (buffer), BRUSH_MAX_SIZE);
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2017-04-20 04:33:44 +08:00
|
|
|
brush->priv->mask = gimp_temp_buf_new (width, height,
|
|
|
|
babl_format ("Y u8"));
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2017-04-20 04:33:44 +08:00
|
|
|
if (GIMP_BRUSH_CLIPBOARD (brush)->mask_only)
|
2006-05-16 21:11:47 +08:00
|
|
|
{
|
2017-04-20 04:33:44 +08:00
|
|
|
guchar *p;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
gegl_buffer_get (buffer,
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height), 1.0,
|
|
|
|
babl_format ("Y u8"),
|
|
|
|
gimp_temp_buf_get_data (brush->priv->mask),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
|
|
|
/* invert the mask, it's more intuitive to think
|
|
|
|
* "black on white" than the other way around
|
|
|
|
*/
|
|
|
|
for (i = 0, p = gimp_temp_buf_get_data (brush->priv->mask);
|
|
|
|
i < width * height;
|
|
|
|
i++, p++)
|
|
|
|
{
|
|
|
|
*p = 255 - *p;
|
|
|
|
}
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-20 04:33:44 +08:00
|
|
|
brush->priv->pixmap = gimp_temp_buf_new (width, height,
|
|
|
|
babl_format ("R'G'B' u8"));
|
|
|
|
|
|
|
|
/* copy the alpha channel into the brush's mask */
|
|
|
|
if (babl_format_has_alpha (format))
|
|
|
|
{
|
|
|
|
gegl_buffer_get (buffer,
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height), 1.0,
|
|
|
|
babl_format ("A u8"),
|
|
|
|
gimp_temp_buf_get_data (brush->priv->mask),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (gimp_temp_buf_get_data (brush->priv->mask), 255,
|
|
|
|
width * height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the color channels into the brush's pixmap */
|
|
|
|
gegl_buffer_get (buffer,
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height), 1.0,
|
|
|
|
babl_format ("R'G'B' u8"),
|
|
|
|
gimp_temp_buf_get_data (brush->priv->pixmap),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = 17;
|
|
|
|
height = 17;
|
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
brush->priv->mask = gimp_temp_buf_new (width, height,
|
|
|
|
babl_format ("Y u8"));
|
|
|
|
gimp_temp_buf_data_clear (brush->priv->mask);
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
brush->priv->x_axis.x = width / 2;
|
|
|
|
brush->priv->x_axis.y = 0;
|
|
|
|
brush->priv->y_axis.x = 0;
|
|
|
|
brush->priv->y_axis.y = height / 2;
|
2006-05-16 21:11:47 +08:00
|
|
|
|
2006-05-23 23:39:45 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2006-05-16 21:11:47 +08:00
|
|
|
}
|