gegl r2222 - in trunk: . gegl gegl/buffer gegl/operation
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2222 - in trunk: . gegl gegl/buffer gegl/operation
- Date: Wed, 23 Apr 2008 22:08:18 +0100 (BST)
Author: ok
Date: Wed Apr 23 21:08:17 2008
New Revision: 2222
URL: http://svn.gnome.org/viewvc/gegl?rev=2222&view=rev
Log:
* gegl/gegl-config.c: New files for configuration object, that stores
* gegl/gegl-config.h: the settings that GEGL determines its behavior
from.
* gegl/buffer/gegl-buffer.c: use swap from gegl-config
* gegl/gegl-init.[ch]: initialize GeglConfig from
default->environment->commandline->application, the control from the
application might not be fully working for all properties.
* gegl/gegl.h.in: added gegl_config()
* gegl/operation/gegl-operation-processors.c:
(gegl_class_register_alternate_vfunc): determine quality to use from
gegl_config.
* gegl/Makefile.am: added new files.
Added:
trunk/gegl/gegl-config.c
trunk/gegl/gegl-config.h
Modified:
trunk/ChangeLog
trunk/gegl/Makefile.am
trunk/gegl/buffer/gegl-buffer.c
trunk/gegl/gegl-init.c
trunk/gegl/gegl-init.h
trunk/gegl/gegl.h.in
trunk/gegl/operation/gegl-operation-processors.c
Modified: trunk/gegl/Makefile.am
==============================================================================
--- trunk/gegl/Makefile.am (original)
+++ trunk/gegl/Makefile.am Wed Apr 23 21:08:17 2008
@@ -14,22 +14,24 @@
lib_LTLIBRARIES = libgegl- GEGL_API_VERSION@.la
GEGL_sources = \
+ gegl-config.c \
+ gegl-cpuaccel.c \
+ gegl-dot.c \
gegl-init.c \
gegl-instrument.c \
- gegl-dot.c \
gegl-utils.c \
gegl-xml.c \
- gegl-cpuaccel.c \
- gegl-cpuaccel.h \
\
- gegl-init.h \
- gegl-types.h \
- gegl-dot.h \
- gegl-xml.h \
- gegl-plugin.h \
gegl-chant.h \
+ gegl-config.h \
+ gegl-cpuaccel.h \
+ gegl-dot.h \
+ gegl-init.h \
gegl-instrument.h \
- gegl-module.h
+ gegl-module.h \
+ gegl-plugin.h \
+ gegl-types.h \
+ gegl-xml.h
libgegl_ GEGL_API_VERSION@_la_SOURCES = $(GEGL_sources) $(GEGL_public_headers)
@@ -63,6 +65,7 @@
gegl-utils.h \
gegl-chant.h \
gegl-plugin.h \
+ gegl-config.c \
buffer/gegl-buffer.h \
property-types/gegl-paramspecs.h \
property-types/gegl-color.h \
Modified: trunk/gegl/buffer/gegl-buffer.c
==============================================================================
--- trunk/gegl/buffer/gegl-buffer.c (original)
+++ trunk/gegl/buffer/gegl-buffer.c Wed Apr 23 21:08:17 2008
@@ -62,6 +62,7 @@
#include "gegl-utils.h"
#include "gegl-id-pool.h"
#include "gegl-buffer-index.h"
+#include "gegl-config.h"
G_DEFINE_TYPE (GeglBuffer, gegl_buffer, GEGL_TYPE_TILE_HANDLER)
@@ -899,10 +900,10 @@
filename = g_strdup_printf ("%i-%i", getpid(), no++);
- path = g_build_filename (gegl_swap_dir (), filename, NULL);
+ path = g_build_filename (gegl_config()->swap, filename, NULL);
g_free (filename);
- if (gegl_swap_dir ())
+ if (gegl_config()->swap)
{
tile_storage = g_object_new (GEGL_TYPE_TILE_STORAGE,
"format", babl_format,
@@ -927,50 +928,6 @@
return buffer;
}
-const gchar *
-gegl_swap_dir (void);
-
-/* if this function is made to return NULL swapping is disabled */
-const gchar *
-gegl_swap_dir (void)
-{
- static gchar *swapdir = "";
-
- if (swapdir && swapdir[0] == '\0')
- {
- if (g_getenv ("GEGL_SWAP"))
- {
- if (g_str_equal (g_getenv ("GEGL_SWAP"), "RAM"))
- swapdir = NULL;
- else
- swapdir = g_strdup (g_getenv ("GEGL_SWAP"));
- }
- else
- {
- swapdir = g_build_filename (g_get_home_dir(),
- "." GEGL_LIBRARY,
- "swap",
- NULL);
- }
-
- /* Fall back to "swapping to RAM" if not able to create swap dir
- */
- if (swapdir &&
- ! g_file_test (swapdir, G_FILE_TEST_IS_DIR) &&
- g_mkdir_with_parents (swapdir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
- {
- gchar *name = g_filename_display_name (swapdir);
-
- g_warning ("unable to create swapdir '%s': %s",
- name, g_strerror (errno));
- g_free (name);
-
- swapdir = NULL;
- }
- }
- return swapdir;
-};
-
static const void *int_gegl_buffer_get_format (GeglBuffer *buffer)
{
Added: trunk/gegl/gegl-config.c
==============================================================================
--- (empty file)
+++ trunk/gegl/gegl-config.c Wed Apr 23 21:08:17 2008
@@ -0,0 +1,156 @@
+/* This file is part of GEGL.
+ *
+ * This library 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.
+ *
+ * This library 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, 2007 Ãyvind KolÃs <pippin gimp org>
+ */
+#include <glib.h>
+#include <glib-object.h>
+#include "gegl-config.h"
+#include <string.h>
+#include <glib/gprintf.h>
+
+G_DEFINE_TYPE (GeglConfig, gegl_config, G_TYPE_OBJECT);
+
+static GObjectClass * parent_class = NULL;
+
+enum
+{
+ PROP_0,
+ PROP_QUALITY,
+ PROP_CACHE_SIZE,
+ PROP_SWAP,
+ PROP_BABL_ERROR
+};
+
+static void
+get_property (GObject *gobject,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeglConfig *config = GEGL_CONFIG (gobject);
+
+ switch (property_id)
+ {
+ case PROP_CACHE_SIZE:
+ g_value_set_int (value, config->cache_size);
+ break;
+
+ case PROP_QUALITY:
+ g_value_set_double (value, config->quality);
+ break;
+
+ case PROP_BABL_ERROR:
+ g_value_set_double (value, config->babl_error);
+ break;
+
+ case PROP_SWAP:
+ g_value_set_string (value, config->swap);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *gobject,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeglConfig *config = GEGL_CONFIG (gobject);
+
+ switch (property_id)
+ {
+ case PROP_CACHE_SIZE:
+ config->cache_size = g_value_get_int (value);
+ break;
+ case PROP_QUALITY:
+ config->quality = g_value_get_double (value);
+ return;
+ case PROP_BABL_ERROR:
+ {
+ gchar buf[256];
+ config->babl_error = g_value_get_double (value);
+ g_sprintf (buf, "%f", config->babl_error);
+ g_setenv ("BABL_ERROR", buf, 0);
+ /* babl picks up the babl error through the environment,
+ * not sure if it is cached or not
+ */
+ }
+ return;
+ case PROP_SWAP:
+ if (config->swap)
+ g_free (config->swap);
+ config->swap = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+ break;
+ }
+}
+
+static void
+finalize (GObject *gobject)
+{
+ GeglConfig *config = GEGL_CONFIG (gobject);
+
+ if (config->swap)
+ g_free (config->swap);
+
+ G_OBJECT_CLASS (gegl_config_parent_class)->finalize (gobject);
+}
+
+static void
+gegl_config_class_init (GeglConfigClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = set_property;
+ gobject_class->get_property = get_property;
+ gobject_class->finalize = finalize;
+
+ g_object_class_install_property (gobject_class, PROP_CACHE_SIZE,
+ g_param_spec_double ("cachei-size", "Cache size", "size of cache in bytes",
+ 0.0, 1.0, 1.0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_QUALITY,
+ g_param_spec_double ("quality", "Quality", "quality/speed trade off 1.0 = full quality, 0.0=full speed",
+ 0.0, 1.0, 1.0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_BABL_ERROR,
+ g_param_spec_double ("babl-error", "babl error", "the error tolerance babl operates with",
+ 0.0, 0.2, 0.0001,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_SWAP,
+ g_param_spec_string ("swap", "Swap", "where gegl stores it's swap files", NULL,
+ G_PARAM_READWRITE));
+}
+
+static void
+gegl_config_init (GeglConfig *self)
+{
+ self->swap = NULL;
+ self->quality = 1.0;
+ self->cache_size = 64*1024*1024;
+}
Added: trunk/gegl/gegl-config.h
==============================================================================
--- (empty file)
+++ trunk/gegl/gegl-config.h Wed Apr 23 21:08:17 2008
@@ -0,0 +1,59 @@
+/* This file is part of GEGL.
+ *
+ * This library 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.
+ *
+ * This library 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, 2007 Ãyvind KolÃs <pippin gimp org>
+ */
+
+#ifndef __GEGL_CONFIG_H__
+#define __GEGL_CONFIG_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEGL_TYPE_CONFIG (gegl_config_get_type ())
+#define GEGL_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_CONFIG, GeglConfig))
+#define GEGL_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEGL_TYPE_CONFIG, GeglConfigClass))
+#define GEGL_IS_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_CONFIG))
+#define GEGL_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_CONFIG))
+#define GEGL_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_CONFIG, GeglConfigClass))
+
+typedef struct _GeglConfig GeglConfig;
+typedef struct _GeglConfigClass GeglConfigClass;
+
+struct _GeglConfig
+{
+ GObject parent_instance;
+
+ gchar *swap;
+ gint cache_size;
+ gdouble quality;
+ gdouble babl_error;
+};
+
+struct _GeglConfigClass
+{
+ GObjectClass parent_class;
+};
+
+
+GType gegl_config_get_type (void) G_GNUC_CONST;
+#ifndef __GEGL_INIT_H__
+GeglConfig * gegl_config (void);
+#endif
+G_END_DECLS
+
+#endif
Modified: trunk/gegl/gegl-init.c
==============================================================================
--- trunk/gegl/gegl-init.c (original)
+++ trunk/gegl/gegl-init.c Wed Apr 23 21:08:17 2008
@@ -39,19 +39,60 @@
guint gegl_debug_flags = 0;
-
#include "gegl-instrument.h"
-/*#include "gegl-types.h"*/
#include "gegl-init.h"
-
#include "module/geglmodule.h"
#include "module/geglmoduledb.h"
-
+#include "gegl-types.h"
+#include "buffer/gegl-buffer.h"
#include "operation/gegl-operation.h"
#include "operation/gegl-operations.h"
#include "operation/gegl-extension-handler.h"
#include "buffer/gegl-buffer-private.h"
+#include "gegl-config.h"
+
+/* if this function is made to return NULL swapping is disabled */
+const gchar *
+gegl_swap_dir (void)
+{
+ static gchar *swapdir = "";
+
+ if (swapdir && swapdir[0] == '\0')
+ {
+ if (g_getenv ("GEGL_SWAP"))
+ {
+ if (g_str_equal (g_getenv ("GEGL_SWAP"), "RAM"))
+ swapdir = NULL;
+ else
+ swapdir = g_strdup (g_getenv ("GEGL_SWAP"));
+ }
+ else
+ {
+ swapdir = g_build_filename (g_get_home_dir(),
+ "." GEGL_LIBRARY,
+ "swap",
+ NULL);
+ }
+
+ /* Fall back to "swapping to RAM" if not able to create swap dir
+ */
+ if (swapdir &&
+ ! g_file_test (swapdir, G_FILE_TEST_IS_DIR) &&
+ g_mkdir_with_parents (swapdir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
+ {
+#if 0
+ gchar *name = g_filename_display_name (swapdir);
+ g_warning ("unable to create swapdir '%s': %s",
+ name, g_strerror (errno));
+ g_free (name);
+#endif
+
+ swapdir = NULL;
+ }
+ }
+ return swapdir;
+};
static gboolean gegl_post_parse_hook (GOptionContext *context,
GOptionGroup *group,
@@ -59,7 +100,8 @@
GError **error);
-static gboolean gegl_initialized = FALSE;
+static GeglConfig *config = NULL;
+
static GeglModuleDB *module_db = NULL;
@@ -85,7 +127,9 @@
gegl_init (gint *argc,
gchar ***argv)
{
- if (gegl_initialized)
+ GOptionContext *context;
+ GError *error = NULL;
+ if (config)
return;
#if ENABLE_MP
@@ -97,11 +141,9 @@
* out code below should be used. Until then, we simply call the parse hook
* directly.
*/
- gegl_post_parse_hook (NULL, NULL, NULL, NULL);
-
#if 0
- GOptionContext *context;
- GError *error = NULL;
+ gegl_post_parse_hook (NULL, NULL, NULL, NULL);
+#else
context = g_option_context_new (NULL);
g_option_context_set_ignore_unknown_options (context, TRUE);
@@ -118,6 +160,36 @@
#endif
}
+static gchar *cmd_gegl_swap=NULL;
+static gchar *cmd_gegl_cache_size=NULL;
+static gchar *cmd_gegl_quality=NULL;
+static gchar *cmd_babl_error=NULL;
+
+static const GOptionEntry cmd_entries[]=
+{
+ {
+ "babl-error", 0, 0,
+ G_OPTION_ARG_STRING, &cmd_babl_error,
+ N_("babls error tolerance, a value beteen 0.2 and 0.000000001"), "<float>"
+ },
+ {
+ "gegl-swap", 0, 0,
+ G_OPTION_ARG_STRING, &cmd_gegl_swap,
+ N_("Where GEGL stores it's swap"), "<uri>"
+ },
+ {
+ "gegl-cache-size", 0, 0,
+ G_OPTION_ARG_STRING, &cmd_gegl_cache_size,
+ N_("How much memory to (approximately) use for caching imagery"), "<megabytes>"
+ },
+ {
+ "gegl-quality", 0, 0,
+ G_OPTION_ARG_STRING, &cmd_gegl_quality,
+ N_("The quality of rendering a value between 0.0(fast) and 1.0(reference)"), "<quality>"
+ },
+ { NULL }
+};
+
/**
* gegl_get_option_group:
*
@@ -135,12 +207,19 @@
group = g_option_group_new ("gegl", "GEGL Options", "Show GEGL Options",
NULL, NULL);
+ g_option_group_add_entries (group, cmd_entries);
g_option_group_set_parse_hooks (group, NULL, gegl_post_parse_hook);
return group;
}
+GObject *gegl_config (void);
+GObject *gegl_config (void)
+{
+ return G_OBJECT (config);
+}
+
void gegl_tile_backend_ram_stats (void);
void gegl_tile_backend_tiledir_stats (void);
void gegl_tile_backend_file_stats (void);
@@ -217,24 +296,12 @@
g_pattern_spec_free (pattern);
}
+ g_object_unref (config);
+ config = NULL;
g_print ("\n");
}
-void
-gegl_get_version (int *major,
- int *minor,
- int *micro)
-{
- if (major != NULL)
- *major = GEGL_MAJOR_VERSION;
-
- if (minor != NULL)
- *minor = GEGL_MINOR_VERSION;
-
- if (micro != NULL)
- *micro = GEGL_MICRO_VERSION;
-}
static void
@@ -245,6 +312,8 @@
}
+
+
static gboolean
gegl_post_parse_hook (GOptionContext *context,
GOptionGroup *group,
@@ -253,14 +322,28 @@
{
glong time;
- if (gegl_initialized)
+ if (config)
return TRUE;
+
g_assert (global_time == 0);
global_time = gegl_ticks ();
g_type_init ();
gegl_instrument ("gegl", "gegl_init", 0);
+ config = g_object_new (GEGL_TYPE_CONFIG, NULL);
+ if (g_getenv ("GEGL_QUALITY"))
+ config->quality = atof(g_getenv("GEGL_QUALITY"));
+ if (gegl_swap_dir())
+ config->swap = g_strdup(gegl_swap_dir ());
+ if (cmd_gegl_swap)
+ g_object_set (config, "swap", cmd_gegl_swap, NULL);
+ if (cmd_gegl_quality)
+ config->quality = atof (cmd_gegl_quality);
+ if (cmd_gegl_cache_size)
+ config->cache_size = atoi (cmd_gegl_cache_size)*1024*1024;
+ if (cmd_babl_error)
+ g_object_set (config, "babl-error", atof(cmd_babl_error), NULL);
#ifdef GEGL_ENABLE_DEBUG
{
@@ -279,9 +362,6 @@
time = gegl_ticks ();
- if (g_getenv ("BABL_ERROR") == NULL)
- g_setenv ("BABL_ERROR", "0.0001", 0);
-
babl_init ();
gegl_instrument ("gegl_init", "babl_init", gegl_ticks () - time);
@@ -341,7 +421,19 @@
}
gegl_instrument ("gegl", "gegl_init", gegl_ticks () - global_time);
- gegl_initialized = TRUE;
+
+ if (g_getenv ("GEGL_SWAP"))
+ g_object_set (config, "swap-path", g_getenv ("GEGL_SWAP"), NULL);
+ if (g_getenv ("GEGL_QUALITY"))
+ {
+ const gchar *quality = g_getenv ("GEGL_QUALITY");
+ if (g_str_equal (quality, "fast"))
+ g_object_set (config, "quality", 0.0, NULL);
+ if (g_str_equal (quality, "good"))
+ g_object_set (config, "quality", 0.5, NULL);
+ if (g_str_equal (quality, "best"))
+ g_object_set (config, "quality", 1.0, NULL);
+ }
return TRUE;
}
@@ -349,6 +441,7 @@
#ifdef GEGL_ENABLE_DEBUG
+#if 0
static gboolean
gegl_arg_debug_cb (const char *key,
const char *value,
@@ -373,6 +466,7 @@
return TRUE;
}
#endif
+#endif
/*
* gegl_get_debug_enabled:
Modified: trunk/gegl/gegl-init.h
==============================================================================
--- trunk/gegl/gegl-init.h (original)
+++ trunk/gegl/gegl-init.h Wed Apr 23 21:08:17 2008
@@ -26,7 +26,12 @@
gchar ***argv);
GOptionGroup * gegl_get_option_group (void);
void gegl_exit (void);
-gboolean gegl_get_debug_enabled (void);
+
+gboolean gegl_get_debug_enabled (void); /* should be moved into config */
+
+void gegl_get_version (int *major,
+ int *minor,
+ int *micro);
G_END_DECLS
Modified: trunk/gegl/gegl.h.in
==============================================================================
--- trunk/gegl/gegl.h.in (original)
+++ trunk/gegl/gegl.h.in Wed Apr 23 21:08:17 2008
@@ -820,6 +820,7 @@
*/
void gegl_processor_destroy (GeglProcessor *processor);
+GObject * gegl_config (void);
#ifndef GEGL_INTERNAL
Modified: trunk/gegl/operation/gegl-operation-processors.c
==============================================================================
--- trunk/gegl/operation/gegl-operation-processors.c (original)
+++ trunk/gegl/operation/gegl-operation-processors.c Wed Apr 23 21:08:17 2008
@@ -25,6 +25,7 @@
#include <string.h>
#include "gegl-types.h"
+#include "gegl-config.h"
#include "gegl-operation.h"
#include "gegl-utils.h"
#include "gegl-cpuaccel.h"
@@ -47,13 +48,18 @@
#include <glib/gprintf.h>
+/* FIXME:
+ *
+ * pick the correct processor at runtime rather than at class init time
+ * to allow the gegl_config request to override the initial conditions
+ */
+
typedef struct VFuncData
{
GCallback callback[MAX_PROCESSOR];
gchar *string[MAX_PROCESSOR];
} VFuncData;
-
void
gegl_class_register_alternate_vfunc (GObjectClass *cclass,
gpointer vfunc_ptr2,
@@ -86,7 +92,7 @@
if (data->callback[0]==NULL)
{
if (*vfunc_ptr == NULL)
- g_error ("%s: No exsiting default () vfunc defined for %s",
+ g_error ("%s: No existing default () vfunc defined for %s",
G_STRFUNC, g_type_name (type));
data->callback[0]=callback;
data->string[0]=g_strdup ("reference");
@@ -109,7 +115,6 @@
}
{
- const gchar *quality = g_getenv ("GEGL_QUALITY");
gint fast = 0;
gint good = 0;
gint reference = 0;
@@ -117,11 +122,6 @@
gint choice = 0;
- /* if no quality is specified, look for good, which also includes the
- * g4float implementation */
- if (quality == NULL)
- quality = "good";
-
for (i=0;i<MAX_PROCESSOR;i++)
{
const gchar *string = data->string[i];
@@ -142,16 +142,16 @@
reference = 0;
g_assert (data->callback[reference]);
- if (g_str_equal (quality, "good")||
- g_str_equal (quality, "fast"))
+ if (gegl_config()->quality <= 0.5)
{
if (good) choice = good;
if (g4f) choice = g4f;
}
- if (g_str_equal (quality, "fast"))
+ if (gegl_config()->quality <= 0.2)
{
if (good) choice = good;
if (g4f) choice = g4f;
+ if (fast) choice = fast;
}
GEGL_NOTE(PROCESSOR, "Using %s implementation for %s", data->string[choice], g_type_name (G_TYPE_FROM_CLASS (cclass)));
@@ -159,8 +159,6 @@
}
}
-
-
void
gegl_operation_class_add_processor (GeglOperationClass *cclass,
GCallback process,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]