Commit 6f7e244d authored by Michael Natterer's avatar Michael Natterer 😴

app: add GInputStream* parameter to GimpDataLoadFunc

and port all loaders to loading from an already open stream.
parent d7812173
......@@ -110,31 +110,18 @@ static gboolean abr_rle_decode (GDataInputStream *input,
/* public functions */
GList *
gimp_brush_load (GimpContext *context,
GFile *file,
GError **error)
gimp_brush_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrush *brush;
GInputStream *input;
GError *my_error = NULL;
GimpBrush *brush;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
brush = gimp_brush_load_brush (context, file, input, error);
g_object_unref (input);
if (! brush)
return NULL;
......@@ -427,31 +414,21 @@ gimp_brush_load_brush (GimpContext *context,
}
GList *
gimp_brush_load_abr (GimpContext *context,
GFile *file,
GError **error)
gimp_brush_load_abr (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GInputStream *input;
GDataInputStream *data_input;
AbrHeader abr_hdr;
GList *brush_list = NULL;
GError *my_error = NULL;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
data_input = g_data_input_stream_new (input);
g_object_unref (input);
g_data_input_stream_set_byte_order (data_input,
G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
......
......@@ -27,6 +27,7 @@
GList * gimp_brush_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
GimpBrush * gimp_brush_load_brush (GimpContext *context,
GFile *file,
......@@ -35,6 +36,7 @@ GimpBrush * gimp_brush_load_brush (GimpContext *context,
GList * gimp_brush_load_abr (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
......
......@@ -35,12 +35,12 @@
GList *
gimp_brush_generated_load (GimpContext *context,
GFile *file,
GError **error)
gimp_brush_generated_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrush *brush;
GInputStream *input;
GDataInputStream *data_input;
gchar *string;
gsize string_len;
......@@ -57,22 +57,10 @@ gimp_brush_generated_load (GimpContext *context,
GError *my_error = NULL;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
else
{
data_input = g_data_input_stream_new (input);
g_object_unref (input);
}
data_input = g_data_input_stream_new (input);
/* make sure the file we are reading is the right type */
linenum = 1;
......
......@@ -24,9 +24,10 @@
#define GIMP_BRUSH_GENERATED_FILE_EXTENSION ".vbr"
GList * gimp_brush_generated_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_brush_generated_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_BRUSH_GENERATED_LOAD_H__ */
......@@ -36,12 +36,12 @@
GList *
gimp_brush_pipe_load (GimpContext *context,
GFile *file,
GError **error)
gimp_brush_pipe_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpBrushPipe *pipe = NULL;
GInputStream *input;
GimpPixPipeParams params;
gint i;
gint num_of_brushes = 0;
......@@ -50,21 +50,11 @@ gimp_brush_pipe_load (GimpContext *context,
GString *buffer;
gchar c;
gsize bytes_read;
GError *my_error = NULL;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
/* The file format starts with a painfully simple text header */
/* get the name */
......@@ -100,7 +90,6 @@ gimp_brush_pipe_load (GimpContext *context,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_file_get_utf8_name (file));
g_object_unref (input);
return NULL;
}
......@@ -125,7 +114,6 @@ gimp_brush_pipe_load (GimpContext *context,
_("Fatal parse error in brush file '%s': "
"File is corrupt."),
gimp_file_get_utf8_name (file));
g_object_unref (input);
g_object_unref (pipe);
g_string_free (buffer, TRUE);
return NULL;
......@@ -216,7 +204,6 @@ gimp_brush_pipe_load (GimpContext *context,
else
{
g_propagate_error (error, my_error);
g_object_unref (input);
g_object_unref (pipe);
return NULL;
}
......@@ -224,8 +211,6 @@ gimp_brush_pipe_load (GimpContext *context,
pipe->n_brushes++;
}
g_object_unref (input);
/* Current brush is the first one. */
pipe->current = pipe->brushes[0];
......
......@@ -23,9 +23,10 @@
#define GIMP_BRUSH_PIPE_FILE_EXTENSION ".gih"
GList * gimp_brush_pipe_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_brush_pipe_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_BRUSH_PIPE_LOAD_H__ */
......@@ -29,19 +29,21 @@
GList *
gimp_curve_load (GFile *file,
GError **error)
gimp_curve_load (GFile *file,
GInputStream *input,
GError **error)
{
GimpCurve *curve;
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);
curve = g_object_new (GIMP_TYPE_CURVE, NULL);
if (gimp_config_deserialize_gfile (GIMP_CONFIG (curve),
file,
NULL, error))
if (gimp_config_deserialize_stream (GIMP_CONFIG (curve),
input,
NULL, error))
{
return g_list_prepend (NULL, curve);
}
......
......@@ -22,8 +22,9 @@
#define GIMP_CURVE_FILE_EXTENSION ".curve"
GList * gimp_curve_load (GFile *file,
GError **error);
GList * gimp_curve_load (GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_CURVE_LOAD_H__ */
......@@ -840,14 +840,15 @@ static void
gimp_data_factory_load_data (const GimpDatafileData *file_data,
gpointer data)
{
GimpDataLoadContext *context = data;
GimpDataFactory *factory = context->factory;
GHashTable *cache = context->cache;
const GimpDataFactoryLoaderEntry *loader = NULL;
GFile *file = NULL;
GError *error = NULL;
GList *data_list;
GimpDataLoadContext *context = data;
GimpDataFactory *factory = context->factory;
GHashTable *cache = context->cache;
const GimpDataFactoryLoaderEntry *loader = NULL;
GList *data_list = NULL;
GFile *file;
GInputStream *input;
gint i;
GError *error = NULL;
for (i = 0; i < factory->priv->n_loader_entries; i++)
{
......@@ -887,7 +888,20 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
}
}
data_list = loader->load_func (context->context, file, &error);
input = G_INPUT_STREAM (g_file_read (file, NULL, &error));
if (input)
{
data_list = loader->load_func (context->context, file, input, &error);
g_object_unref (input);
}
else
{
g_prefix_error (&error,
_("Could not open '%s' for reading: "),
gimp_file_get_utf8_name (file));
}
if (G_LIKELY (data_list))
{
......
......@@ -25,12 +25,13 @@
#include "gimpobject.h"
typedef GimpData * (* GimpDataNewFunc) (GimpContext *context,
const gchar *name);
typedef GList * (* GimpDataLoadFunc) (GimpContext *context,
GFile *file,
GError **error);
typedef GimpData * (* GimpDataGetStandardFunc) (GimpContext *context);
typedef GimpData * (* GimpDataNewFunc) (GimpContext *context,
const gchar *name);
typedef GList * (* GimpDataLoadFunc) (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
typedef GimpData * (* GimpDataGetStandardFunc) (GimpContext *context);
typedef struct _GimpDataFactoryLoaderEntry GimpDataFactoryLoaderEntry;
......
......@@ -29,20 +29,22 @@
GList *
gimp_dynamics_load (GimpContext *context,
GFile *file,
GError **error)
gimp_dynamics_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpDynamics *dynamics;
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);
dynamics = g_object_new (GIMP_TYPE_DYNAMICS, NULL);
if (gimp_config_deserialize_gfile (GIMP_CONFIG (dynamics),
file,
NULL, error))
if (gimp_config_deserialize_stream (GIMP_CONFIG (dynamics),
input,
NULL, error))
{
return g_list_prepend (NULL, dynamics);
}
......
......@@ -22,9 +22,10 @@
#define GIMP_DYNAMICS_FILE_EXTENSION ".gdyn"
GList * gimp_dynamics_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_dynamics_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_DYNAMICS_LOAD_H__ */
......@@ -39,15 +39,15 @@
GList *
gimp_gradient_load (GimpContext *context,
GFile *file,
GError **error)
gimp_gradient_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpGradient *gradient = NULL;
GimpGradientSegment *prev;
gint num_segments;
gint i;
GInputStream *input;
GDataInputStream *data_input;
gchar *line;
gsize line_len;
......@@ -55,20 +55,10 @@ gimp_gradient_load (GimpContext *context,
GError *my_error = NULL;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
data_input = g_data_input_stream_new (input);
g_object_unref (input);
linenum = 1;
line_len = 1024;
......@@ -311,17 +301,22 @@ static const GMarkupParser markup_parser =
GList *
gimp_gradient_load_svg (GimpContext *context,
GFile *file,
GError **error)
gimp_gradient_load_svg (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpXmlParser *xml_parser;
SvgParser parser = { NULL, };
gboolean success;
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);
/* FIXME input */
g_input_stream_close (input, NULL, NULL);
xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
success = gimp_xml_parser_parse_gfile (xml_parser, file, error);
......
......@@ -23,12 +23,14 @@
#define GIMP_GRADIENT_SVG_FILE_EXTENSION ".svg"
GList * gimp_gradient_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_gradient_load_svg (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_gradient_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
GList * gimp_gradient_load_svg (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_GRADIENT_LOAD_H__ */
......@@ -515,7 +515,7 @@ gimp_palette_import_from_file (GimpContext *context,
switch (gimp_palette_load_detect_format (file, input))
{
case GIMP_PALETTE_FILE_FORMAT_GPL:
palette_list = gimp_palette_load_gpl (context, file, input, error);
palette_list = gimp_palette_load (context, file, input, error);
break;
case GIMP_PALETTE_FILE_FORMAT_ACT:
......
......@@ -35,39 +35,10 @@
GList *
gimp_palette_load (GimpContext *context,
GFile *file,
GError **error)
{
GList *list;
GInputStream *input;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
list = gimp_palette_load_gpl (context, file, input, error);
g_object_unref (input);
return list;
}
GList *
gimp_palette_load_gpl (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
gimp_palette_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpPalette *palette = NULL;
GimpPaletteEntry *entry;
......
......@@ -35,9 +35,6 @@ typedef enum
GList * gimp_palette_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_palette_load_gpl (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
......
......@@ -35,33 +35,23 @@
GList *
gimp_pattern_load (GimpContext *context,
GFile *file,
GError **error)
gimp_pattern_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpPattern *pattern = NULL;
const Babl *format = NULL;
GInputStream *input;
PatternHeader header;
gsize size;
gsize bytes_read;
gint bn_size;
gchar *name = NULL;
GError *my_error = NULL;
gchar *name = NULL;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
/* read the size */
if (! g_input_stream_read_all (input, &header, sizeof (header),
&bytes_read, NULL, NULL) ||
......@@ -163,46 +153,31 @@ gimp_pattern_load (GimpContext *context,
goto error;
}
g_object_unref (input);
return g_list_prepend (NULL, pattern);
error:
if (pattern)
g_object_unref (pattern);
g_object_unref (input);
return NULL;
}
GList *
gimp_pattern_load_pixbuf (GimpContext *context,
GFile *file,
GError **error)
gimp_pattern_load_pixbuf (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpPattern *pattern;
GInputStream *input;
GdkPixbuf *pixbuf;
gchar *name;
GError *my_error = NULL;
GimpPattern *pattern;
GdkPixbuf *pixbuf;
gchar *name;
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);
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
if (! input)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
return NULL;
}
pixbuf = gdk_pixbuf_new_from_stream (input, NULL, error);
g_object_unref (input);
if (! pixbuf)
return NULL;
......
......@@ -22,12 +22,14 @@
#define GIMP_PATTERN_FILE_EXTENSION ".pat"
GList * gimp_pattern_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_pattern_load_pixbuf (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_pattern_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
GList * gimp_pattern_load_pixbuf (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_PATTERN_LOAD_H__ */
......@@ -33,23 +33,25 @@
GList *
gimp_tool_preset_load (GimpContext *context,
GFile *file,
GError **error)
gimp_tool_preset_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error)
{
GimpToolPreset *tool_preset;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
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);
tool_preset = g_object_new (GIMP_TYPE_TOOL_PRESET,
"gimp", context->gimp,
NULL);
if (gimp_config_deserialize_gfile (GIMP_CONFIG (tool_preset),
file,
NULL, error))
if (gimp_config_deserialize_stream (GIMP_CONFIG (tool_preset),
input,
NULL, error))
{
if (GIMP_IS_CONTEXT (tool_preset->tool_options))
{
......
......@@ -22,9 +22,10 @@
#define GIMP_TOOL_PRESET_FILE_EXTENSION ".gtp"
GList * gimp_tool_preset_load (GimpContext *context,
GFile *file,
GError **error);
GList * gimp_tool_preset_load (GimpContext *context,
GFile *file,
GInputStream *input,
GError **error);
#endif /* __GIMP_TOOL_PRESET_LOAD_H__ */
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