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
|
/* This file is an image processing operation for GEGL
*
* GEGL is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* GEGL 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_string(path, _("File"), "", _("a GeglBuffer on disk to open"))
#else
#define GEGL_CHANT_TYPE_SOURCE
#define GEGL_CHANT_C_FILE "open-buffer.c"
#include "gegl-chant.h"
static void buffer_changed (GeglBuffer *buffer,
const GeglRectangle *rect,
gpointer userdata)
{
gegl_operation_invalidate (GEGL_OPERATION (userdata), rect, FALSE);
}
static GeglBuffer *ensure_buffer (GeglOperation *operation)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglBuffer *buffer = o->chant_data;
if (buffer)
return buffer;
if (!buffer)
{
buffer = gegl_buffer_open (o->path);
o->chant_data = buffer;
}
g_signal_connect (buffer, "changed",
G_CALLBACK(buffer_changed), operation);
return buffer;
}
static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
GeglRectangle result = {0,0,0,0};
GeglBuffer *buffer = ensure_buffer (operation);
result = *gegl_buffer_get_extent (GEGL_BUFFER (buffer));
return result;
}
static GeglRectangle
get_cached_region (GeglOperation *self,
const GeglRectangle *roi)
{
return get_bounding_box (self);
}
static gboolean
process (GeglOperation *operation,
GeglOperationContext *context,
const gchar *output_pad,
const GeglRectangle *result,
gint level)
{
GeglBuffer *buffer = ensure_buffer (operation);
if (buffer)
{
g_object_ref (buffer); /* Add an extra reference, since
* gegl_operation_set_data is
* stealing one.
*/
/* override core behaviour, by resetting the buffer in the operation_context */
gegl_operation_context_take_object (context, "output", G_OBJECT (buffer));
return TRUE;
}
return FALSE;
}
static void
dispose (GObject *object)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (object);
GeglBuffer *buffer = o->chant_data;
if (buffer)
{
g_object_unref (buffer);
o->chant_data = NULL;
}
G_OBJECT_CLASS (gegl_chant_parent_class)->dispose (object);
}
static void
gegl_chant_class_init (GeglChantClass *klass)
{
GeglOperationClass *operation_class;
operation_class = GEGL_OPERATION_CLASS (klass);
G_OBJECT_CLASS (klass)->dispose = dispose;
operation_class->process = process;
operation_class->get_bounding_box = get_bounding_box;
operation_class->get_cached_region = get_cached_region;
gegl_operation_class_set_keys (operation_class,
"name" , "gegl:open-buffer",
"categories" , "input",
"description", _("A source that uses an on-disk GeglBuffer."),
NULL);
operation_class->no_cache = TRUE;
}
#endif
|