1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
* Copyright (C) 1999 Adrian Likins and Tor Lillqvist
*
* 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 <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimpbrush-load.h"
#include "gimpbrush-private.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
#include "gimp-intl.h"
GList *
gimp_brush_pipe_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrushPipe *pipe = NULL;
gint n_brushes = 0;
GString *buffer;
gchar *paramstring;
gchar c;
gsize bytes_read;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* The file format starts with a painfully simple text header */
/* get the name */
buffer = g_string_new (NULL);
while (g_input_stream_read_all (input, &c, 1, &bytes_read, NULL, NULL) &&
bytes_read == 1 &&
c != '\n' &&
buffer->len < 1024)
{
g_string_append_c (buffer, c);
}
if (buffer->len > 0 && buffer->len < 1024)
{
gchar *utf8 =
gimp_any_to_utf8 (buffer->str, buffer->len,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_file_get_utf8_name (file));
pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE,
"name", utf8,
"mime-type", "image/x-gimp-gih",
NULL);
g_free (utf8);
}
g_string_free (buffer, TRUE);
if (! pipe)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_file_get_utf8_name (file));
return NULL;
}
/* get the number of brushes */
buffer = g_string_new (NULL);
while (g_input_stream_read_all (input, &c, 1, &bytes_read, NULL, NULL) &&
bytes_read == 1 &&
c != '\n' &&
buffer->len < 1024)
{
g_string_append_c (buffer, c);
}
if (buffer->len > 0 && buffer->len < 1024)
{
n_brushes = strtol (buffer->str, ¶mstring, 10);
}
if (n_brushes < 1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_file_get_utf8_name (file));
g_object_unref (pipe);
g_string_free (buffer, TRUE);
return NULL;
}
while (*paramstring && g_ascii_isspace (*paramstring))
paramstring++;
pipe->brushes = g_new0 (GimpBrush *, n_brushes);
while (pipe->n_brushes < n_brushes)
{
pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context,
file, input,
error);
if (! pipe->brushes[pipe->n_brushes])
{
g_object_unref (pipe);
g_string_free (buffer, TRUE);
return NULL;
}
pipe->n_brushes++;
}
if (! gimp_brush_pipe_set_params (pipe, paramstring))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Inconsistent parameters."),
gimp_file_get_utf8_name (file));
g_object_unref (pipe);
g_string_free (buffer, TRUE);
return NULL;
}
g_string_free (buffer, TRUE);
/* Current brush is the first one. */
pipe->current = pipe->brushes[0];
/* just to satisfy the code that relies on this crap */
GIMP_BRUSH (pipe)->priv->spacing = pipe->current->priv->spacing;
GIMP_BRUSH (pipe)->priv->x_axis = pipe->current->priv->x_axis;
GIMP_BRUSH (pipe)->priv->y_axis = pipe->current->priv->y_axis;
GIMP_BRUSH (pipe)->priv->mask = pipe->current->priv->mask;
GIMP_BRUSH (pipe)->priv->pixmap = pipe->current->priv->pixmap;
return g_list_prepend (NULL, pipe);
}
|