Commit e93fd73f authored by Michael Natterer's avatar Michael Natterer

app: implement pattern saving in the core

Add GimpData::save() implementation to GimpPattern, and change some
glue code to make patterns editable.

Also implement GimpData::duplicate() in GimpPatternClipboard, which
makes it possible to simply copy an area and duplicate the clipboard
pattern to create a new persistent pattern.
parent fc609d12
......@@ -385,6 +385,8 @@ libappcore_a_sources = \
gimppattern-header.h \
gimppattern-load.c \
gimppattern-load.h \
gimppattern-save.c \
gimppattern-save.h \
gimppatternclipboard.c \
gimppatternclipboard.h \
gimppalette.c \
......
......@@ -151,7 +151,7 @@ gimp_data_factories_init (Gimp *gimp)
"GIMP Pattern",
gimp_pattern_load,
GIMP_PATTERN_FILE_EXTENSION,
FALSE);
TRUE);
gimp_data_loader_factory_add_fallback (gimp->pattern_factory,
"Pattern from GdkPixbuf",
gimp_pattern_load_pixbuf);
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <cairo.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimppattern.h"
#include "gimppattern-header.h"
#include "gimppattern-save.h"
#include "gimptempbuf.h"
gboolean
gimp_pattern_save (GimpData *data,
GOutputStream *output,
GError **error)
{
GimpPattern *pattern = GIMP_PATTERN (data);
GimpTempBuf *mask = gimp_pattern_get_mask (pattern);
const Babl *format = gimp_temp_buf_get_format (mask);
GimpPatternHeader header;
const gchar *name;
gint width;
gint height;
name = gimp_object_get_name (pattern);
width = gimp_temp_buf_get_width (mask);
height = gimp_temp_buf_get_height (mask);
header.header_size = g_htonl (sizeof (GimpPatternHeader) +
strlen (name) + 1);
header.version = g_htonl (1);
header.width = g_htonl (width);
header.height = g_htonl (height);
header.bytes = g_htonl (babl_format_get_bytes_per_pixel (format));
header.magic_number = g_htonl (GIMP_PATTERN_MAGIC);
if (! g_output_stream_write_all (output, &header, sizeof (header),
NULL, NULL, error))
{
return FALSE;
}
if (! g_output_stream_write_all (output, name, strlen (name) + 1,
NULL, NULL, error))
{
return FALSE;
}
if (! g_output_stream_write_all (output,
gimp_temp_buf_get_data (mask),
gimp_temp_buf_get_data_size (mask),
NULL, NULL, error))
{
return FALSE;
}
return TRUE;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_PATTERN_SAVE_H__
#define __GIMP_PATTERN_SAVE_H__
/* don't call this function directly, use gimp_data_save() instead */
gboolean gimp_pattern_save (GimpData *data,
GOutputStream *output,
GError **error);
#endif /* __GIMP_PATTERN_SAVE_H__ */
......@@ -30,6 +30,7 @@
#include "gimppattern.h"
#include "gimppattern-load.h"
#include "gimppattern-save.h"
#include "gimptagged.h"
#include "gimptempbuf.h"
......@@ -83,6 +84,7 @@ gimp_pattern_class_init (GimpPatternClass *klass)
viewable_class->get_new_preview = gimp_pattern_get_new_preview;
viewable_class->get_description = gimp_pattern_get_description;
data_class->save = gimp_pattern_save;
data_class->get_extension = gimp_pattern_get_extension;
data_class->copy = gimp_pattern_copy;
}
......
......@@ -55,9 +55,7 @@ static void gimp_pattern_clipboard_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
#if 0
static GimpData * gimp_pattern_clipboard_duplicate (GimpData *data);
#endif
static void gimp_pattern_clipboard_changed (Gimp *gimp,
GimpPattern *pattern);
......@@ -72,17 +70,13 @@ static void
gimp_pattern_clipboard_class_init (GimpPatternClipboardClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
#if 0
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
#endif
object_class->constructed = gimp_pattern_clipboard_constructed;
object_class->set_property = gimp_pattern_clipboard_set_property;
object_class->get_property = gimp_pattern_clipboard_get_property;
#if 0
data_class->duplicate = gimp_pattern_clipboard_duplicate;
#endif
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp", NULL, NULL,
......@@ -150,15 +144,15 @@ gimp_pattern_clipboard_get_property (GObject *object,
}
}
#if 0
static GimpData *
gimp_pattern_clipboard_duplicate (GimpData *data)
{
GimpPatternClipboard *pattern = GIMP_PATTERN_CLIPBOARD (data);
GimpData *new = g_object_new (GIMP_TYPE_PATTERN, NULL);
return gimp_pattern_clipboard_new (pattern->gimp);
gimp_data_copy (new, data);
return new;
}
#endif
GimpData *
gimp_pattern_clipboard_new (Gimp *gimp)
......
......@@ -91,7 +91,6 @@ gimp_pattern_factory_view_new (GimpViewType view_type,
NULL);
gtk_widget_hide (gimp_data_factory_view_get_edit_button (GIMP_DATA_FACTORY_VIEW (factory_view)));
gtk_widget_hide (gimp_data_factory_view_get_duplicate_button (GIMP_DATA_FACTORY_VIEW (factory_view)));
return GTK_WIDGET (factory_view);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment