|
Packit Service |
2781ba |
/* This file is part of GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is free software; you can redistribute it and/or
|
|
Packit Service |
2781ba |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
2781ba |
* version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
2781ba |
* Lesser General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright 2003-2007 Calvin Williamson, Øyvind Kolås
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#define __GEGL_INIT_C
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <babl/babl.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <glib-object.h>
|
|
Packit Service |
2781ba |
#include <glib/gstdio.h>
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <locale.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <stdlib.h>
|
|
Packit Service |
2781ba |
#ifdef HAVE_UNISTD_H
|
|
Packit Service |
2781ba |
#include <unistd.h>
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
#ifdef G_OS_WIN32
|
|
Packit Service |
2781ba |
#include <process.h>
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef G_OS_WIN32
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <windows.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static HMODULE hLibGeglModule = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* DllMain prototype */
|
|
Packit Service |
2781ba |
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
|
|
Packit Service |
2781ba |
DWORD fdwReason,
|
|
Packit Service |
2781ba |
LPVOID lpvReserved);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
BOOL WINAPI
|
|
Packit Service |
2781ba |
DllMain (HINSTANCE hinstDLL,
|
|
Packit Service |
2781ba |
DWORD fdwReason,
|
|
Packit Service |
2781ba |
LPVOID lpvReserved)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
hLibGeglModule = hinstDLL;
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static inline gboolean
|
|
Packit Service |
2781ba |
pid_is_running (gint pid)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
HANDLE h;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
h = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
|
Packit Service |
2781ba |
return (TerminateProcess(h, 0));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <sys/types.h>
|
|
Packit Service |
2781ba |
#include <signal.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static inline gboolean
|
|
Packit Service |
2781ba |
pid_is_running (gint pid)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return (kill (pid, 0) == 0);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <gegl-debug.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
guint gegl_debug_flags = 0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-instrument.h"
|
|
Packit Service |
2781ba |
#include "gegl-init.h"
|
|
Packit Service |
2781ba |
#include "module/geglmodule.h"
|
|
Packit Service |
2781ba |
#include "module/geglmoduledb.h"
|
|
Packit Service |
2781ba |
#include "gegl-types-internal.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-buffer.h"
|
|
Packit Service |
2781ba |
#include "operation/gegl-operation.h"
|
|
Packit Service |
2781ba |
#include "operation/gegl-operations.h"
|
|
Packit Service |
2781ba |
#include "operation/gegl-extension-handler.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-buffer-private.h"
|
|
Packit Service |
2781ba |
#include "gegl-config.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-node.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* if this function is made to return NULL swapping is disabled */
|
|
Packit Service |
2781ba |
const gchar *
|
|
Packit Service |
2781ba |
gegl_swap_dir (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
static gchar *swapdir = "";
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (swapdir && swapdir[0] == '\0')
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_SWAP"))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (g_str_equal (g_getenv ("GEGL_SWAP"), "RAM"))
|
|
Packit Service |
2781ba |
swapdir = NULL;
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
swapdir = g_strdup (g_getenv ("GEGL_SWAP"));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
swapdir = g_build_filename (g_get_user_cache_dir(),
|
|
Packit Service |
2781ba |
GEGL_LIBRARY,
|
|
Packit Service |
2781ba |
"swap",
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Fall back to "swapping to RAM" if not able to create swap dir
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
if (swapdir &&
|
|
Packit Service |
2781ba |
! g_file_test (swapdir, G_FILE_TEST_IS_DIR) &&
|
|
Packit Service |
2781ba |
g_mkdir_with_parents (swapdir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
#if 0
|
|
Packit Service |
2781ba |
gchar *name = g_filename_display_name (swapdir);
|
|
Packit Service |
2781ba |
g_warning ("unable to create swapdir '%s': %s",
|
|
Packit Service |
2781ba |
name, g_strerror (errno));
|
|
Packit Service |
2781ba |
g_free (name);
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
swapdir = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return swapdir;
|
|
Packit Service |
2781ba |
};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean gegl_post_parse_hook (GOptionContext *context,
|
|
Packit Service |
2781ba |
GOptionGroup *group,
|
|
Packit Service |
2781ba |
gpointer data,
|
|
Packit Service |
2781ba |
GError **error);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglConfig *config = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglModuleDB *module_db = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static glong global_time = 0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static const gchar *makefile (void);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/**
|
|
Packit Service |
2781ba |
* gegl_init:
|
|
Packit Service |
2781ba |
* @argc: a pointer to the number of command line arguments.
|
|
Packit Service |
2781ba |
* @argv: a pointer to the array of command line arguments.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Call this function before using any other GEGL functions. It will initialize
|
|
Packit Service |
2781ba |
* everything needed to operate GEGL and parses some standard command line
|
|
Packit Service |
2781ba |
* options. @argc and @argv are adjusted accordingly so your own code will
|
|
Packit Service |
2781ba |
* never see those standard arguments.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Note that there is an alternative ways to initialize GEGL: if you are
|
|
Packit Service |
2781ba |
* calling g_option_context_parse() with the option group returned by
|
|
Packit Service |
2781ba |
* gegl_get_option_group(), you don't have to call gegl_init().
|
|
Packit Service |
2781ba |
**/
|
|
Packit Service |
2781ba |
void
|
|
Packit Service |
2781ba |
gegl_init (gint *argc,
|
|
Packit Service |
2781ba |
gchar ***argv)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GOptionContext *context;
|
|
Packit Service |
2781ba |
GError *error = NULL;
|
|
Packit Service |
2781ba |
if (config)
|
|
Packit Service |
2781ba |
return;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* If any command-line actions are ever added to GEGL, then the commented
|
|
Packit Service |
2781ba |
* out code below should be used. Until then, we simply call the parse hook
|
|
Packit Service |
2781ba |
* directly.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
#if 0
|
|
Packit Service |
2781ba |
gegl_post_parse_hook (NULL, NULL, NULL, NULL);
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
context = g_option_context_new (NULL);
|
|
Packit Service |
2781ba |
g_option_context_set_ignore_unknown_options (context, TRUE);
|
|
Packit Service |
2781ba |
g_option_context_set_help_enabled (context, FALSE);
|
|
Packit Service |
2781ba |
g_option_context_set_main_group (context, gegl_get_option_group ());
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!g_option_context_parse (context, argc, argv, &error))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_warning ("%s", error->message);
|
|
Packit Service |
2781ba |
g_error_free (error);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_option_context_free (context);
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_swap=NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_cache_size=NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_chunk_size=NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_quality=NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_tile_size=NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_babl_tolerance =NULL;
|
|
Packit Service |
2781ba |
static gchar *cmd_gegl_threads=NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static const GOptionEntry cmd_entries[]=
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"babl-tolerance", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_babl_tolerance,
|
|
Packit Service |
2781ba |
N_("babls error tolerance, a value beteen 0.2 and 0.000000001"), "<float>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-swap", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_swap,
|
|
Packit Service |
2781ba |
N_("Where GEGL stores it's swap"), "<uri>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-cache-size", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_cache_size,
|
|
Packit Service |
2781ba |
N_("How much memory to (approximately) use for caching imagery"), "<megabytes>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-tile-size", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_tile_size,
|
|
Packit Service |
2781ba |
N_("Default size of tiles in GeglBuffers"), "<widthxheight>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-chunk-size", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_chunk_size,
|
|
Packit Service |
2781ba |
N_("The count of pixels to compute simultaneously"), "pixel count"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-quality", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_quality,
|
|
Packit Service |
2781ba |
N_("The quality of rendering a value between 0.0(fast) and 1.0(reference)"), "<quality>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
"gegl-threads", 0, 0,
|
|
Packit Service |
2781ba |
G_OPTION_ARG_STRING, &cmd_gegl_threads,
|
|
Packit Service |
2781ba |
N_("The number of concurrent processing threads to use"), "<threads>"
|
|
Packit Service |
2781ba |
},
|
|
Packit Service |
2781ba |
{ NULL }
|
|
Packit Service |
2781ba |
};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/**
|
|
Packit Service |
2781ba |
* gegl_get_option_group:
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Returns a #GOptionGroup for the commandline arguments recognized
|
|
Packit Service |
2781ba |
* by GEGL. You should add this group to your #GOptionContext
|
|
Packit Service |
2781ba |
* with g_option_context_add_group(), if you are using
|
|
Packit Service |
2781ba |
* g_option_context_parse() to parse your commandline arguments.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Returns a #GOptionGroup for the commandline arguments recognized by GEGL.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
GOptionGroup *
|
|
Packit Service |
2781ba |
gegl_get_option_group (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GOptionGroup *group;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
group = g_option_group_new ("gegl", "GEGL Options", "Show GEGL Options",
|
|
Packit Service |
2781ba |
NULL, NULL);
|
|
Packit Service |
2781ba |
g_option_group_add_entries (group, cmd_entries);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_option_group_set_parse_hooks (group, NULL, gegl_post_parse_hook);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return group;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglConfig *gegl_config (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (!config)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
config = g_object_new (GEGL_TYPE_CONFIG, NULL);
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_QUALITY"))
|
|
Packit Service |
2781ba |
config->quality = atof(g_getenv("GEGL_QUALITY"));
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_CACHE_SIZE"))
|
|
Packit Service |
2781ba |
config->cache_size = atoi(g_getenv("GEGL_CACHE_SIZE"))* 1024*1024;
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_CHUNK_SIZE"))
|
|
Packit Service |
2781ba |
config->chunk_size = atoi(g_getenv("GEGL_CHUNK_SIZE"));
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_TILE_SIZE"))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *str = g_getenv ("GEGL_TILE_SIZE");
|
|
Packit Service |
2781ba |
config->tile_width = atoi(str);
|
|
Packit Service |
2781ba |
str = strchr (str, 'x');
|
|
Packit Service |
2781ba |
if (str)
|
|
Packit Service |
2781ba |
config->tile_height = atoi(str+1);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_THREADS"))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
config->threads = atoi(g_getenv("GEGL_THREADS"));
|
|
Packit Service |
2781ba |
if (config->threads > GEGL_MAX_THREADS)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_warning ("Tried to use %i threads max is %i",
|
|
Packit Service |
2781ba |
config->threads, GEGL_MAX_THREADS);
|
|
Packit Service |
2781ba |
config->threads = GEGL_MAX_THREADS;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_USE_OPENCL") != NULL && strcmp(g_getenv ("GEGL_USE_OPENCL"), "yes") == 0)
|
|
Packit Service |
2781ba |
config->use_opencl = TRUE;
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
config->use_opencl = FALSE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_swap_dir())
|
|
Packit Service |
2781ba |
config->swap = g_strdup(gegl_swap_dir ());
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
return GEGL_CONFIG (config);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void gegl_tile_backend_ram_stats (void);
|
|
Packit Service |
2781ba |
void gegl_tile_backend_tiledir_stats (void);
|
|
Packit Service |
2781ba |
void gegl_tile_backend_file_stats (void);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void swap_clean (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *swap_dir = gegl_swap_dir ();
|
|
Packit Service |
2781ba |
GDir *dir;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (! swap_dir)
|
|
Packit Service |
2781ba |
return;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
dir = g_dir_open (gegl_swap_dir (), 0, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (dir != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GPatternSpec *pattern = g_pattern_spec_new ("*");
|
|
Packit Service |
2781ba |
const gchar *name;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
while ((name = g_dir_read_name (dir)) != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (g_pattern_match_string (pattern, name))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint readpid = atoi (name);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!pid_is_running (readpid))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *fname = g_build_filename (gegl_swap_dir (),
|
|
Packit Service |
2781ba |
name,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
g_unlink (fname);
|
|
Packit Service |
2781ba |
g_free (fname);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_pattern_spec_free (pattern);
|
|
Packit Service |
2781ba |
g_dir_close (dir);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void gegl_tile_storage_cache_cleanup (void);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void
|
|
Packit Service |
2781ba |
gegl_exit (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
glong timing = gegl_ticks ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_tile_storage_cache_cleanup ();
|
|
Packit Service |
2781ba |
gegl_tile_cache_destroy ();
|
|
Packit Service |
2781ba |
gegl_operation_gtype_cleanup ();
|
|
Packit Service |
2781ba |
gegl_extension_handler_cleanup ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (module_db != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_object_unref (module_db);
|
|
Packit Service |
2781ba |
module_db = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
babl_exit ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
timing = gegl_ticks () - timing;
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl", "gegl_exit", timing);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* used when tracking buffer and tile leaks */
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_DEBUG_BUFS") != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_buffer_stats ();
|
|
Packit Service |
2781ba |
gegl_tile_backend_ram_stats ();
|
|
Packit Service |
2781ba |
gegl_tile_backend_file_stats ();
|
|
Packit Service |
2781ba |
gegl_tile_backend_tiledir_stats ();
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
global_time = gegl_ticks () - global_time;
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl", "gegl", global_time);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_DEBUG_TIME") != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_printf ("\n%s", gegl_instrument_utf8 ());
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_buffer_leaks ())
|
|
Packit Service |
2781ba |
g_printf ("EEEEeEeek! %i GeglBuffers leaked\n", gegl_buffer_leaks ());
|
|
Packit Service |
2781ba |
gegl_tile_cache_destroy ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_swap_dir ())
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
/* remove all files matching <$GEGL_SWAP>/GEGL-<pid>-*.swap */
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
guint pid = getpid ();
|
|
Packit Service |
2781ba |
GDir *dir = g_dir_open (gegl_swap_dir (), 0, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gchar *glob = g_strdup_printf ("%i-*", pid);
|
|
Packit Service |
2781ba |
GPatternSpec *pattern = g_pattern_spec_new (glob);
|
|
Packit Service |
2781ba |
g_free (glob);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (dir != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *name;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
while ((name = g_dir_read_name (dir)) != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (g_pattern_match_string (pattern, name))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *fname = g_build_filename (gegl_swap_dir (),
|
|
Packit Service |
2781ba |
name,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
g_unlink (fname);
|
|
Packit Service |
2781ba |
g_free (fname);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_dir_close (dir);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_pattern_spec_free (pattern);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
g_object_unref (config);
|
|
Packit Service |
2781ba |
config = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void swap_clean (void);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_init_i18n (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
setlocale (LC_ALL, "");
|
|
Packit Service |
2781ba |
bindtextdomain (GETTEXT_PACKAGE, GEGL_LOCALEDIR);
|
|
Packit Service |
2781ba |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void
|
|
Packit Service |
2781ba |
gegl_get_version (int *major,
|
|
Packit Service |
2781ba |
int *minor,
|
|
Packit Service |
2781ba |
int *micro)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (major != NULL)
|
|
Packit Service |
2781ba |
*major = GEGL_MAJOR_VERSION;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (minor != NULL)
|
|
Packit Service |
2781ba |
*minor = GEGL_MINOR_VERSION;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (micro != NULL)
|
|
Packit Service |
2781ba |
*micro = GEGL_MICRO_VERSION;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_post_parse_hook (GOptionContext *context,
|
|
Packit Service |
2781ba |
GOptionGroup *group,
|
|
Packit Service |
2781ba |
gpointer data,
|
|
Packit Service |
2781ba |
GError **error)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
glong time;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (config)
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_assert (global_time == 0);
|
|
Packit Service |
2781ba |
global_time = gegl_ticks ();
|
|
Packit Service |
2781ba |
g_type_init ();
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl", "gegl_init", 0);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
config = (void*)gegl_config ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (cmd_gegl_swap)
|
|
Packit Service |
2781ba |
g_object_set (config, "swap", cmd_gegl_swap, NULL);
|
|
Packit Service |
2781ba |
if (cmd_gegl_quality)
|
|
Packit Service |
2781ba |
config->quality = atof (cmd_gegl_quality);
|
|
Packit Service |
2781ba |
if (cmd_gegl_cache_size)
|
|
Packit Service |
2781ba |
config->cache_size = atoi (cmd_gegl_cache_size)*1024*1024;
|
|
Packit Service |
2781ba |
if (cmd_gegl_chunk_size)
|
|
Packit Service |
2781ba |
config->chunk_size = atoi (cmd_gegl_chunk_size);
|
|
Packit Service |
2781ba |
if (cmd_gegl_tile_size)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *str = cmd_gegl_tile_size;
|
|
Packit Service |
2781ba |
config->tile_width = atoi(str);
|
|
Packit Service |
2781ba |
str = strchr (str, 'x');
|
|
Packit Service |
2781ba |
if (str)
|
|
Packit Service |
2781ba |
config->tile_height = atoi(str+1);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
if (cmd_gegl_threads)
|
|
Packit Service |
2781ba |
config->threads = atoi (cmd_gegl_threads);
|
|
Packit Service |
2781ba |
if (cmd_babl_tolerance)
|
|
Packit Service |
2781ba |
g_object_set (config, "babl-tolerance", atof(cmd_babl_tolerance), NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_ENABLE_DEBUG
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const char *env_string;
|
|
Packit Service |
2781ba |
env_string = g_getenv ("GEGL_DEBUG");
|
|
Packit Service |
2781ba |
if (env_string != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_debug_flags =
|
|
Packit Service |
2781ba |
g_parse_debug_string (env_string,
|
|
Packit Service |
2781ba |
gegl_debug_keys,
|
|
Packit Service |
2781ba |
G_N_ELEMENTS (gegl_debug_keys));
|
|
Packit Service |
2781ba |
env_string = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif /* GEGL_ENABLE_DEBUG */
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
time = gegl_ticks ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
babl_init ();
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl_init", "babl_init", gegl_ticks () - time);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_init_i18n ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
time = gegl_ticks ();
|
|
Packit Service |
2781ba |
if (!module_db)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *gegl_path = g_getenv ("GEGL_PATH");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
module_db = gegl_module_db_new (FALSE);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_path)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_module_db_load (module_db, gegl_path);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *module_path;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef G_OS_WIN32
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *prefix;
|
|
Packit Service |
2781ba |
prefix = g_win32_get_package_installation_directory_of_module ( hLibGeglModule );
|
|
Packit Service |
2781ba |
module_path = g_build_filename (prefix, "lib", GEGL_LIBRARY, NULL);
|
|
Packit Service |
2781ba |
g_free(prefix);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
module_path = g_build_filename (LIBDIR, GEGL_LIBRARY, NULL);
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_module_db_load (module_db, module_path);
|
|
Packit Service |
2781ba |
g_free (module_path);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* also load plug-ins from ~/.local/share/gegl-0.0/plugins */
|
|
Packit Service |
2781ba |
module_path = g_build_filename (g_get_user_data_dir (),
|
|
Packit Service |
2781ba |
GEGL_LIBRARY,
|
|
Packit Service |
2781ba |
"plug-ins",
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (g_mkdir_with_parents (module_path,
|
|
Packit Service |
2781ba |
S_IRUSR | S_IWUSR | S_IXUSR) == 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *makefile_path = g_build_filename (module_path,
|
|
Packit Service |
2781ba |
"Makefile",
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (! g_file_test (makefile_path, G_FILE_TEST_EXISTS))
|
|
Packit Service |
2781ba |
g_file_set_contents (makefile_path, makefile (), -1, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_free (makefile_path);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_module_db_load (module_db, module_path);
|
|
Packit Service |
2781ba |
g_free (module_path);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl_init", "load modules", gegl_ticks () - time);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_instrument ("gegl", "gegl_init", gegl_ticks () - global_time);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_SWAP"))
|
|
Packit Service |
2781ba |
g_object_set (config, "swap", g_getenv ("GEGL_SWAP"), NULL);
|
|
Packit Service |
2781ba |
if (g_getenv ("GEGL_QUALITY"))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *quality = g_getenv ("GEGL_QUALITY");
|
|
Packit Service |
2781ba |
if (g_str_equal (quality, "fast"))
|
|
Packit Service |
2781ba |
g_object_set (config, "quality", 0.0, NULL);
|
|
Packit Service |
2781ba |
if (g_str_equal (quality, "good"))
|
|
Packit Service |
2781ba |
g_object_set (config, "quality", 0.5, NULL);
|
|
Packit Service |
2781ba |
if (g_str_equal (quality, "best"))
|
|
Packit Service |
2781ba |
g_object_set (config, "quality", 1.0, NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
swap_clean ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Initialize OpenCL if wanted and possible */
|
|
Packit Service |
2781ba |
if (gegl_config()->use_opencl)
|
|
Packit Service |
2781ba |
gegl_cl_init (NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GEGL_NOTE (GEGL_DEBUG_OPENCL, "Using OpenCL: %d\n", gegl_config()->use_opencl && gegl_cl_is_accelerated ());
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_ENABLE_DEBUG
|
|
Packit Service |
2781ba |
#if 0
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_arg_debug_cb (const char *key,
|
|
Packit Service |
2781ba |
const char *value,
|
|
Packit Service |
2781ba |
gpointer user_data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_debug_flags |=
|
|
Packit Service |
2781ba |
g_parse_debug_string (value,
|
|
Packit Service |
2781ba |
gegl_debug_keys,
|
|
Packit Service |
2781ba |
G_N_ELEMENTS (gegl_debug_keys));
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_arg_no_debug_cb (const char *key,
|
|
Packit Service |
2781ba |
const char *value,
|
|
Packit Service |
2781ba |
gpointer user_data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_debug_flags &=
|
|
Packit Service |
2781ba |
~g_parse_debug_string (value,
|
|
Packit Service |
2781ba |
gegl_debug_keys,
|
|
Packit Service |
2781ba |
G_N_ELEMENTS (gegl_debug_keys));
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/*
|
|
Packit Service |
2781ba |
* gegl_get_debug_enabled:
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Check if gegl has debugging turned on.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Return value: TRUE if debugging is turned on, FALSE otherwise.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
gboolean
|
|
Packit Service |
2781ba |
gegl_get_debug_enabled (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
#ifdef GEGL_ENABLE_DEBUG
|
|
Packit Service |
2781ba |
return gegl_debug_flags != 0;
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
return FALSE;
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static const gchar *makefile (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return
|
|
Packit Service |
2781ba |
"# This is a generic makefile for GEGL operations. Just add .c files,\n"
|
|
Packit Service |
2781ba |
"# rename mentions of the filename and opname to the new name, and it should \n"
|
|
Packit Service |
2781ba |
"# compile. Operations in this dir should be loaded by GEGL by default\n"
|
|
Packit Service |
2781ba |
"# If the operation being written depends on extra libraries, you'd better\n"
|
|
Packit Service |
2781ba |
"# add a dedicated target with the extra bits linked in.\n"
|
|
Packit Service |
2781ba |
"\n\n"
|
|
Packit Service |
2781ba |
"CFLAGS += `pkg-config gegl --cflags` -I. -fPIC\n"
|
|
Packit Service |
2781ba |
"LDFLAGS += `pkg-config gegl --libs` -shared\n"
|
|
Packit Service |
2781ba |
"SHREXT=.so\n"
|
|
Packit Service |
2781ba |
"CFILES = $(wildcard ./*.c)\n"
|
|
Packit Service |
2781ba |
"SOBJS = $(subst ./,,$(CFILES:.c=$(SHREXT)))\n"
|
|
Packit Service |
2781ba |
"all: $(SOBJS)\n"
|
|
Packit Service |
2781ba |
"%$(SHREXT): %.c $(GEGLHEADERS)\n"
|
|
Packit Service |
2781ba |
" @echo $@; $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDADD)\n"
|
|
Packit Service |
2781ba |
"clean:\n"
|
|
Packit Service |
2781ba |
" rm -f *$(SHREXT) $(OFILES)\n";
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|