2006-12-09 13:33:38 -08:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-02-04 09:34:30 -08:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
|
*
|
2009-01-17 14:28:01 -08:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-02-04 09:34:30 -08:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-02-04 09:34:30 -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
|
2018-07-11 14:47:19 -07:00
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-02-04 09:34:30 -08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
2013-10-14 16:58:39 -07:00
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2012-03-17 13:59:10 -07:00
|
|
|
|
#include <gegl.h>
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2003-10-16 05:24:58 -07:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
2001-05-09 15:34:59 -07:00
|
|
|
|
#include "core-types.h"
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2018-05-24 07:21:21 -07:00
|
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
|
|
|
|
|
|
2001-02-04 09:34:30 -08:00
|
|
|
|
#include "gimppattern.h"
|
2006-10-03 04:37:37 -07:00
|
|
|
|
#include "gimppattern-load.h"
|
2019-02-11 11:56:07 -08:00
|
|
|
|
#include "gimppattern-save.h"
|
2008-12-13 03:58:24 -08:00
|
|
|
|
#include "gimptagged.h"
|
2012-04-08 15:59:20 -07:00
|
|
|
|
#include "gimptempbuf.h"
|
2001-05-09 15:34:59 -07:00
|
|
|
|
|
2003-03-25 08:38:19 -08:00
|
|
|
|
#include "gimp-intl.h"
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static void gimp_pattern_tagged_iface_init (GimpTaggedInterface *iface);
|
|
|
|
|
|
static void gimp_pattern_finalize (GObject *object);
|
2001-08-11 07:39:19 -07:00
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static gint64 gimp_pattern_get_memsize (GimpObject *object,
|
|
|
|
|
|
gint64 *gui_size);
|
2001-08-11 07:39:19 -07:00
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static gboolean gimp_pattern_get_size (GimpViewable *viewable,
|
|
|
|
|
|
gint *width,
|
|
|
|
|
|
gint *height);
|
2012-04-08 11:25:49 -07:00
|
|
|
|
static GimpTempBuf * gimp_pattern_get_new_preview (GimpViewable *viewable,
|
2008-12-13 03:58:24 -08:00
|
|
|
|
GimpContext *context,
|
|
|
|
|
|
gint width,
|
|
|
|
|
|
gint height);
|
|
|
|
|
|
static gchar * gimp_pattern_get_description (GimpViewable *viewable,
|
|
|
|
|
|
gchar **tooltip);
|
2008-09-12 03:35:35 -07:00
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static const gchar * gimp_pattern_get_extension (GimpData *data);
|
2017-11-04 18:21:12 -07:00
|
|
|
|
static void gimp_pattern_copy (GimpData *data,
|
|
|
|
|
|
GimpData *src_data);
|
2002-01-30 08:14:26 -08:00
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static gchar * gimp_pattern_get_checksum (GimpTagged *tagged);
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpPattern, gimp_pattern, GIMP_TYPE_DATA,
|
|
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
|
|
|
|
|
|
gimp_pattern_tagged_iface_init))
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2005-12-10 11:24:36 -08:00
|
|
|
|
#define parent_class gimp_pattern_parent_class
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
gimp_pattern_class_init (GimpPatternClass *klass)
|
|
|
|
|
|
{
|
2005-07-23 15:22:45 -07:00
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
|
|
|
|
|
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
|
2001-02-05 07:22:20 -08:00
|
|
|
|
|
2014-05-06 16:01:56 -07:00
|
|
|
|
object_class->finalize = gimp_pattern_finalize;
|
2001-02-05 07:22:20 -08:00
|
|
|
|
|
2014-05-06 16:01:56 -07:00
|
|
|
|
gimp_object_class->get_memsize = gimp_pattern_get_memsize;
|
2002-01-30 08:14:26 -08:00
|
|
|
|
|
2014-05-06 16:01:56 -07:00
|
|
|
|
viewable_class->default_icon_name = "gimp-tool-bucket-fill";
|
|
|
|
|
|
viewable_class->get_size = gimp_pattern_get_size;
|
|
|
|
|
|
viewable_class->get_new_preview = gimp_pattern_get_new_preview;
|
|
|
|
|
|
viewable_class->get_description = gimp_pattern_get_description;
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2019-02-11 11:56:07 -08:00
|
|
|
|
data_class->save = gimp_pattern_save;
|
2014-05-06 16:01:56 -07:00
|
|
|
|
data_class->get_extension = gimp_pattern_get_extension;
|
2017-11-04 18:21:12 -07:00
|
|
|
|
data_class->copy = gimp_pattern_copy;
|
2001-02-04 09:34:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static void
|
|
|
|
|
|
gimp_pattern_tagged_iface_init (GimpTaggedInterface *iface)
|
|
|
|
|
|
{
|
|
|
|
|
|
iface->get_checksum = gimp_pattern_get_checksum;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2001-02-04 09:34:30 -08:00
|
|
|
|
static void
|
|
|
|
|
|
gimp_pattern_init (GimpPattern *pattern)
|
|
|
|
|
|
{
|
2001-02-10 17:39:24 -08:00
|
|
|
|
pattern->mask = NULL;
|
2001-02-04 09:34:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-08-11 07:39:19 -07:00
|
|
|
|
gimp_pattern_finalize (GObject *object)
|
2001-02-04 09:34:30 -08:00
|
|
|
|
{
|
2003-11-16 09:51:36 -08:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (object);
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
|
g_clear_pointer (&pattern->mask, gimp_temp_buf_unref);
|
2001-02-04 09:34:30 -08:00
|
|
|
|
|
2001-08-11 07:39:19 -07:00
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-04 09:34:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 09:51:36 -08:00
|
|
|
|
static gint64
|
2003-08-25 03:49:33 -07:00
|
|
|
|
gimp_pattern_get_memsize (GimpObject *object,
|
2003-11-16 09:51:36 -08:00
|
|
|
|
gint64 *gui_size)
|
2002-01-30 08:14:26 -08:00
|
|
|
|
{
|
2004-01-29 08:19:57 -08:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (object);
|
2003-11-16 09:51:36 -08:00
|
|
|
|
gint64 memsize = 0;
|
2002-01-30 08:14:26 -08:00
|
|
|
|
|
2012-04-08 14:56:52 -07:00
|
|
|
|
memsize += gimp_temp_buf_get_memsize (pattern->mask);
|
2002-01-30 08:14:26 -08:00
|
|
|
|
|
2003-08-25 03:49:33 -07:00
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
|
|
gui_size);
|
2002-01-30 08:14:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-02-27 05:59:41 -08:00
|
|
|
|
static gboolean
|
2005-05-25 03:05:17 -07:00
|
|
|
|
gimp_pattern_get_size (GimpViewable *viewable,
|
|
|
|
|
|
gint *width,
|
|
|
|
|
|
gint *height)
|
2003-02-27 05:59:41 -08:00
|
|
|
|
{
|
2003-11-16 09:51:36 -08:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (viewable);
|
2003-02-27 05:59:41 -08:00
|
|
|
|
|
2012-04-23 00:40:56 -07:00
|
|
|
|
*width = gimp_temp_buf_get_width (pattern->mask);
|
|
|
|
|
|
*height = gimp_temp_buf_get_height (pattern->mask);
|
2003-02-27 05:59:41 -08:00
|
|
|
|
|
2005-05-25 03:05:17 -07:00
|
|
|
|
return TRUE;
|
2003-02-27 05:59:41 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-08 11:25:49 -07:00
|
|
|
|
static GimpTempBuf *
|
2001-02-06 16:06:58 -08:00
|
|
|
|
gimp_pattern_get_new_preview (GimpViewable *viewable,
|
2006-08-29 14:44:51 -07:00
|
|
|
|
GimpContext *context,
|
2005-07-23 15:22:45 -07:00
|
|
|
|
gint width,
|
|
|
|
|
|
gint height)
|
2001-02-05 07:22:20 -08:00
|
|
|
|
{
|
2004-01-29 08:19:57 -08:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (viewable);
|
2012-04-08 11:25:49 -07:00
|
|
|
|
GimpTempBuf *temp_buf;
|
2012-04-07 15:46:33 -07:00
|
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
|
|
GeglBuffer *dest_buffer;
|
2001-02-05 13:52:57 -08:00
|
|
|
|
gint copy_width;
|
|
|
|
|
|
gint copy_height;
|
2001-02-05 07:22:20 -08:00
|
|
|
|
|
2012-04-23 00:40:56 -07:00
|
|
|
|
copy_width = MIN (width, gimp_temp_buf_get_width (pattern->mask));
|
|
|
|
|
|
copy_height = MIN (height, gimp_temp_buf_get_height (pattern->mask));
|
2001-02-05 13:52:57 -08:00
|
|
|
|
|
2012-04-08 14:56:52 -07:00
|
|
|
|
temp_buf = gimp_temp_buf_new (copy_width, copy_height,
|
2012-04-23 00:40:56 -07:00
|
|
|
|
gimp_temp_buf_get_format (pattern->mask));
|
2001-02-05 13:52:57 -08:00
|
|
|
|
|
2012-04-08 15:16:46 -07:00
|
|
|
|
src_buffer = gimp_temp_buf_create_buffer (pattern->mask);
|
|
|
|
|
|
dest_buffer = gimp_temp_buf_create_buffer (temp_buf);
|
2012-04-07 15:46:33 -07:00
|
|
|
|
|
2018-05-24 07:21:21 -07:00
|
|
|
|
gimp_gegl_buffer_copy (src_buffer,
|
|
|
|
|
|
GEGL_RECTANGLE (0, 0, copy_width, copy_height),
|
|
|
|
|
|
GEGL_ABYSS_NONE,
|
|
|
|
|
|
dest_buffer, GEGL_RECTANGLE (0, 0, 0, 0));
|
2012-04-07 15:46:33 -07:00
|
|
|
|
|
|
|
|
|
|
g_object_unref (src_buffer);
|
|
|
|
|
|
g_object_unref (dest_buffer);
|
2003-02-28 19:53:41 -08:00
|
|
|
|
|
2001-02-05 13:52:57 -08:00
|
|
|
|
return temp_buf;
|
2001-02-05 07:22:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-08 09:01:01 -07:00
|
|
|
|
static gchar *
|
|
|
|
|
|
gimp_pattern_get_description (GimpViewable *viewable,
|
|
|
|
|
|
gchar **tooltip)
|
|
|
|
|
|
{
|
2003-11-16 09:51:36 -08:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (viewable);
|
2003-04-08 09:01:01 -07:00
|
|
|
|
|
2006-02-28 04:15:51 -08:00
|
|
|
|
return g_strdup_printf ("%s (%d × %d)",
|
2009-08-29 03:40:40 -07:00
|
|
|
|
gimp_object_get_name (pattern),
|
2012-04-23 00:40:56 -07:00
|
|
|
|
gimp_temp_buf_get_width (pattern->mask),
|
|
|
|
|
|
gimp_temp_buf_get_height (pattern->mask));
|
2003-04-08 09:01:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-09-12 03:35:35 -07:00
|
|
|
|
static const gchar *
|
2001-02-13 11:53:07 -08:00
|
|
|
|
gimp_pattern_get_extension (GimpData *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GIMP_PATTERN_FILE_EXTENSION;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-04 18:21:12 -07:00
|
|
|
|
static void
|
|
|
|
|
|
gimp_pattern_copy (GimpData *data,
|
|
|
|
|
|
GimpData *src_data)
|
2001-03-30 03:16:05 -08:00
|
|
|
|
{
|
2017-11-04 18:21:12 -07:00
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (data);
|
|
|
|
|
|
GimpPattern *src_pattern = GIMP_PATTERN (src_data);
|
|
|
|
|
|
|
2019-02-12 12:15:35 -08:00
|
|
|
|
g_clear_pointer (&pattern->mask, gimp_temp_buf_unref);
|
2017-11-04 18:21:12 -07:00
|
|
|
|
pattern->mask = gimp_temp_buf_copy (src_pattern->mask);
|
2001-03-30 03:16:05 -08:00
|
|
|
|
|
2017-11-04 18:21:12 -07:00
|
|
|
|
gimp_data_dirty (data);
|
2001-03-30 03:16:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-12-13 03:58:24 -08:00
|
|
|
|
static gchar *
|
|
|
|
|
|
gimp_pattern_get_checksum (GimpTagged *tagged)
|
|
|
|
|
|
{
|
|
|
|
|
|
GimpPattern *pattern = GIMP_PATTERN (tagged);
|
|
|
|
|
|
gchar *checksum_string = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (pattern->mask)
|
|
|
|
|
|
{
|
|
|
|
|
|
GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
|
|
|
|
|
|
|
2012-04-08 14:56:52 -07:00
|
|
|
|
g_checksum_update (checksum, gimp_temp_buf_get_data (pattern->mask),
|
|
|
|
|
|
gimp_temp_buf_get_data_size (pattern->mask));
|
2008-12-13 03:58:24 -08:00
|
|
|
|
|
|
|
|
|
|
checksum_string = g_strdup (g_checksum_get_string (checksum));
|
|
|
|
|
|
|
|
|
|
|
|
g_checksum_free (checksum);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return checksum_string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2001-02-14 06:57:14 -08:00
|
|
|
|
GimpData *
|
2010-04-10 10:55:42 -07:00
|
|
|
|
gimp_pattern_new (GimpContext *context,
|
|
|
|
|
|
const gchar *name)
|
2001-02-13 11:53:07 -08:00
|
|
|
|
{
|
|
|
|
|
|
GimpPattern *pattern;
|
|
|
|
|
|
guchar *data;
|
|
|
|
|
|
gint row, col;
|
|
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2010-04-10 10:55:42 -07:00
|
|
|
|
g_return_val_if_fail (name[0] != '\n', NULL);
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2004-01-29 08:19:57 -08:00
|
|
|
|
pattern = g_object_new (GIMP_TYPE_PATTERN,
|
|
|
|
|
|
"name", name,
|
|
|
|
|
|
NULL);
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2012-04-08 14:56:52 -07:00
|
|
|
|
pattern->mask = gimp_temp_buf_new (32, 32, babl_format ("R'G'B' u8"));
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2012-04-08 14:56:52 -07:00
|
|
|
|
data = gimp_temp_buf_get_data (pattern->mask);
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2012-04-23 00:40:56 -07:00
|
|
|
|
for (row = 0; row < gimp_temp_buf_get_height (pattern->mask); row++)
|
|
|
|
|
|
for (col = 0; col < gimp_temp_buf_get_width (pattern->mask); col++)
|
2001-02-13 11:53:07 -08:00
|
|
|
|
{
|
2005-07-23 15:22:45 -07:00
|
|
|
|
memset (data, (col % 2) && (row % 2) ? 255 : 0, 3);
|
|
|
|
|
|
data += 3;
|
2001-02-13 11:53:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-02-14 06:57:14 -08:00
|
|
|
|
return GIMP_DATA (pattern);
|
2001-02-13 11:53:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-02-14 06:57:14 -08:00
|
|
|
|
GimpData *
|
2010-04-05 04:24:54 -07:00
|
|
|
|
gimp_pattern_get_standard (GimpContext *context)
|
2001-02-13 11:53:07 -08:00
|
|
|
|
{
|
2004-01-29 08:19:57 -08:00
|
|
|
|
static GimpData *standard_pattern = NULL;
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
|
|
|
|
|
if (! standard_pattern)
|
|
|
|
|
|
{
|
2010-04-10 10:55:42 -07:00
|
|
|
|
standard_pattern = gimp_pattern_new (context, "Standard");
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2009-10-31 10:48:38 -07:00
|
|
|
|
gimp_data_clean (standard_pattern);
|
|
|
|
|
|
gimp_data_make_internal (standard_pattern, "gimp-pattern-standard");
|
2001-02-13 11:53:07 -08:00
|
|
|
|
|
2010-06-24 03:46:45 -07:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (standard_pattern),
|
|
|
|
|
|
(gpointer *) &standard_pattern);
|
2001-02-13 11:53:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-29 08:19:57 -08:00
|
|
|
|
return standard_pattern;
|
2001-02-13 11:53:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-08 11:25:49 -07:00
|
|
|
|
GimpTempBuf *
|
2016-05-19 14:51:44 -07:00
|
|
|
|
gimp_pattern_get_mask (GimpPattern *pattern)
|
2001-02-04 09:34:30 -08:00
|
|
|
|
{
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PATTERN (pattern), NULL);
|
|
|
|
|
|
|
|
|
|
|
|
return pattern->mask;
|
|
|
|
|
|
}
|
2012-03-17 13:59:10 -07:00
|
|
|
|
|
|
|
|
|
|
GeglBuffer *
|
2016-05-19 14:51:44 -07:00
|
|
|
|
gimp_pattern_create_buffer (GimpPattern *pattern)
|
2012-03-17 13:59:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PATTERN (pattern), NULL);
|
|
|
|
|
|
|
2012-04-08 15:16:46 -07:00
|
|
|
|
return gimp_temp_buf_create_buffer (pattern->mask);
|
2012-03-17 13:59:10 -07:00
|
|
|
|
}
|