Commit 9ad22a72 authored by Øyvind Kolås's avatar Øyvind Kolås

Harmonization, reindentation, simplification and tiny bits more

parent 01dff55d
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_double (radius, 0.0, 200.0, 4.0, "radius of square pixel region, (width and height will be radius*2+1.")
......@@ -43,8 +43,6 @@ ver_blur (GeglBuffer *src,
#include <stdio.h>
/* Actual image processing code
************************************************************************/
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
......@@ -102,8 +100,6 @@ process (GeglOperation *operation,
g_object_unref (temp_in);
}
if (filter->output)
g_object_unref (filter->output);
filter->output = output;
}
return TRUE;
......
......@@ -20,7 +20,7 @@
* in "Signal Processing 44 (1995) 139 - 151"
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_double (radius_x, -0.91675, 500.0, 4.0, "blur radius in horizontal direction.")
gegl_chant_double (radius_y, -0.91675, 500.0, 4.0, "blur radius in vertical direction.")
......@@ -55,11 +55,6 @@ find_iir_constants (gfloat radius,
gdouble *B,
gdouble *b);
/* Actual image processing code
************************************************************************/
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
......@@ -73,6 +68,7 @@ process (GeglOperation *operation,
GeglBuffer *input = filter->input;
GeglBuffer *output;
if(strcmp("output", output_prop))
return FALSE;
......@@ -125,8 +121,6 @@ process (GeglOperation *operation,
g_object_unref (temp_in);
}
if (filter->output)
g_object_unref (filter->output);
filter->output = output;
}
return TRUE;
......
......@@ -17,39 +17,100 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
gegl_chant_double (contrast, -100.0, 100.0, 1.0, "Range scale factor")
gegl_chant_double (brightness, -10.0, 10.0, 0.0, "Amount to increase brightness")
/* Followed by this #if ... */
#if GEGL_CHANT_PROPERTIES
/* ... are the properties of the filter, these are all scalar values (doubles),
* the the parameters are:
* property name, min, max, default, "description of property" */
gegl_chant_double (contrast, -100.0, 100.0, 1.0, "Range scale factor")
gegl_chant_double (brightness, -10.0, 10.0, 0.0, "Amount to increase brightness")
/* this will create the following structure for our use, and register the
* property with the given ranges, default values and a comment for the
* documentation/tooltip.
*/
#else
/* Following an else, is then the meta information for this operation */
#define GEGL_CHANT_NAME brightness_contrast
/* The name of the operation (with lower case here, _ and - are interchangeable
* when used by GEGL. */
#define GEGL_CHANT_SELF "brightness-contrast.c"
/* we need to specify the name of the source file for gegl-chant.h to
* do it's magic.
*/
#define GEGL_CHANT_POINT_FILTER
#define GEGL_CHANT_NAME brightness_contrast
/* This sets the super class we are deriving from, in this case from the class
* point filter. With a point filter we only need to implement processing for a
* linear buffer
*/
#define GEGL_CHANT_DESCRIPTION "Changes the light level and contrast."
#define GEGL_CHANT_SELF "brightness-contrast.c"
/* This string shows up in the documentation, and perhaps online help/
* operation browser/tooltips or similar.
*/
#define GEGL_CHANT_CATEGORIES "color"
/* A colon seperated list of categories/tags for this operation. */
#define GEGL_CHANT_INIT
/* here we specify that we've got our own init function for initializing
* the instance
*/
/* gegl-chant, uses the properties defined at the top, and the configuration
* in the preceding lines to generate a GObject plug-in.
*/
#include "gegl-chant.h"
static void init (GeglChantOperation *self)
{
/* set the babl format this operation prefers to work on */
GEGL_OPERATION_POINT_FILTER (self)->format = babl_format ("RGBA float");
}
/* GeglOperationPointFilter gives us a linear buffer to operate on
* in our requested pixel format
*/
static gboolean
process (GeglOperation *op,
void *in_buf,
void *out_buf,
glong n_pixels)
void *in_buf,
void *out_buf,
glong n_pixels)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (op);
gint o;
gfloat *p = in_buf; /* it is inplace anyways, and out_but==in_buf) */
GeglChantOperation *self;
gfloat *pixel;
gint i;
g_assert (in_buf == out_buf);
self = GEGL_CHANT_OPERATION (op);
pixel = in_buf;
for (o=0; o<n_pixels; o++)
for (i=0; i<n_pixels; i++)
{
gint i;
for (i=0;i<3;i++)
p[i] = (p[i] - 0.5) * self->contrast + self->brightness + 0.5;
p+=4;
gint component;
for (component=0; component<3; component++)
{
gfloat c = pixel[component];
c = (c - 0.5) * self->contrast + self->brightness + 0.5;
pixel[component] = c;
}
pixel += 4;
}
return TRUE;
}
#endif
#endif /* closing #if GEGL_CHANT_PROPERTIES ... else ... */
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
/* no properties */
#else
......@@ -37,9 +37,9 @@ static void init (GeglChantOperation *self)
static gboolean
process (GeglOperation *op,
void *in_buf,
void *out_buf,
glong samples)
void *in_buf,
void *out_buf,
glong samples)
{
gint i;
gfloat *in = in_buf;
......@@ -50,7 +50,10 @@ process (GeglOperation *op,
int j;
for (j=0; j<3; j++)
{
out[j] = 1.0 - in[j];
gfloat c;
c = in[j];
c = 1.0 - c;
out[j] = c;
}
out[3]=in[3];
in += 4;
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
#else
......@@ -38,7 +38,7 @@ inner_process (gdouble min,
gint n_pixels)
{
gint o;
float *p = (float*) (buf);
gfloat *p = (gfloat*) (buf);
for (o=0; o<n_pixels; o++)
{
......@@ -55,18 +55,19 @@ buffer_get_min_max (GeglBuffer *buffer,
gdouble *min,
gdouble *max)
{
gdouble tmin = 9000000.0;
gdouble tmax =-9000000.0;
gfloat tmin = 9000000.0;
gfloat tmax =-9000000.0;
gfloat *buf = g_malloc0 (sizeof (gfloat) * 4 * buffer->width * buffer->height);
gint i;
gegl_buffer_get_fmt (buffer, buf, babl_format ("RGBA float"));
for (i=0;i<gegl_buffer_pixels (buffer);i++)
{
gint c;
for (c=0;c<3;c++)
gint component;
for (component=0; component<3; component++)
{
gdouble val = buf[i*4+c];
gfloat val = buf[i*4+component];
if (val<tmin)
tmin=val;
if (val>tmax)
......@@ -82,7 +83,7 @@ buffer_get_min_max (GeglBuffer *buffer,
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationFilter *filter = GEGL_OPERATION_FILTER (operation);
GeglRect *result;
......@@ -93,6 +94,7 @@ process (GeglOperation *operation,
input = filter->input;
result = gegl_operation_get_requested_region (operation);
if (result->w==0 ||
result->h==0)
{
......@@ -145,8 +147,6 @@ process (GeglOperation *operation,
g_free (buf);
}
if (filter->output)
g_object_unref (filter->output);
filter->output = output;
return TRUE;
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_double (value, -100.0, 100.0, 0.5, "global threshold level (used when there is no aux input")
......@@ -39,10 +39,10 @@ static void init (GeglChantOperation *self)
static gboolean
process (GeglOperation *op,
void *in_buf,
void *aux_buf,
void *out_buf,
glong n_pixels)
void *in_buf,
void *aux_buf,
void *out_buf,
glong n_pixels)
{
gint i;
......@@ -55,7 +55,12 @@ process (GeglOperation *op,
gfloat value = GEGL_CHANT_OPERATION (op)->value;
for (i=0; i<n_pixels; i++)
{
out[0] = in[0]>=value?1.0:0.0;
gfloat c;
c = in[0];
c = c>=value?1.0:0.0;
out[0] = c;
out[1] = in[1];
in += 2;
out += 2;
......@@ -65,7 +70,13 @@ process (GeglOperation *op,
{
for (i=0; i<n_pixels; i++)
{
out[0] = in[0]>=(*aux)?1.0:0.0;
gfloat value = *aux;
gfloat c;
c = in[0];
c = c>=value?1.0:0.0;
out[0] = c;
out[1] = in[1];
in += 2;
out += 2;
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_object(buffer, "GeglBuffer to use")
#else
......@@ -31,18 +31,15 @@ gegl_chant_object(buffer, "GeglBuffer to use")
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationSource *op_source = GEGL_OPERATION_SOURCE(operation);
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
if(strcmp("output", output_prop))
return FALSE;
if (op_source->output)
g_object_unref (op_source->output);
op_source->output=NULL;
if (self->buffer)
op_source->output = GEGL_BUFFER (g_object_ref (self->buffer));
return TRUE;
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string (ref, "", "The reference ID used as input.")
......@@ -36,15 +36,12 @@ gegl_chant_string (ref, "", "The reference ID used as input.")
************************************************************************/
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationFilter *filter = GEGL_OPERATION_FILTER(operation);
GeglBuffer *input = filter->input;
if (filter->output)
g_object_unref (filter->output);
filter->output = g_object_ref (input);
if (filter->input)
filter->output = g_object_ref (filter->input);
return TRUE;
}
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_double (x, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "left most pixel coordinate")
gegl_chant_double (y, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "top pixel coordinate")
......@@ -30,8 +30,8 @@ gegl_chant_double (height, -G_MAXDOUBLE, G_MAXDOUBLE, 10.0, "height in pixels")
#define GEGL_CHANT_NAME crop
#define GEGL_CHANT_SELF "crop.c"
#define GEGL_CHANT_DESCRIPTION "crops the image, can be used to rectangulary" \
"clip buffers, as well as specifying what " \
"portion of a composition to render to file"
"clip buffers, as well as specifying what " \
"portion of a composition to render to file"
#define GEGL_CHANT_CATEGORIES "geometry"
#define GEGL_CHANT_CLASS_INIT
#include "gegl-chant.h"
......@@ -45,45 +45,50 @@ int gegl_chant_foo = 0;
************************************************************************/
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationFilter *filter = GEGL_OPERATION_FILTER(operation);
GeglBuffer *input = filter->input;
GeglChantOperation *crop = GEGL_CHANT_OPERATION (operation);
GeglOperationFilter *filter;
GeglBuffer *input;
GeglChantOperation *crop;
crop = GEGL_CHANT_OPERATION (operation);
filter = GEGL_OPERATION_FILTER(operation);
input = filter->input;
if(strcmp("output", output_prop))
return FALSE;
if (filter->output)
g_object_unref (filter->output);
g_assert (input);
g_assert (gegl_buffer_get_format (input));
filter->output = g_object_new (GEGL_TYPE_BUFFER,
"source", input,
"x", (int)crop->x,
"y", (int)crop->y,
"x", (int)crop->x,
"y", (int)crop->y,
"width", (int)crop->width,
"height", (int)crop->height,
NULL);
crop = NULL;
return TRUE;
}
static GeglRect
get_defined_region (GeglOperation *operation)
{
GeglRect result = {0,0,0,0};
GeglChantOperation *op_crop = (GeglChantOperation*)(operation);
GeglRect *in_rect = gegl_operation_source_get_defined_region (operation, "input");
GeglRect result = {0,0,0,0};
GeglChantOperation *op_crop;
GeglRect *in_rect;
op_crop = (GeglChantOperation*)(operation);
in_rect = gegl_operation_source_get_defined_region (operation, "input");
if (!in_rect)
return result;
result.x=op_crop->x;
result.y=op_crop->y;
result.w=op_crop->width;
result.h=op_crop->height;
result.x = op_crop->x;
result.y = op_crop->y;
result.w = op_crop->width;
result.h = op_crop->height;
return result;
}
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
#else
......@@ -43,19 +43,11 @@ op_process (GeglOperation *operation,
GeglOperationFilter *op_filter = GEGL_OPERATION_FILTER (operation);
gboolean success = FALSE;
if (op_filter->output != NULL)
{
g_object_unref (op_filter->output);
op_filter->output = NULL;
}
if (op_filter->input != NULL)
if (op_filter->input)
{
op_filter->output=g_object_ref (op_filter->input);
g_object_unref (op_filter->input);
op_filter->input=NULL;
return TRUE;
}
/* the NOP op does not complain about NULL inputs */
return success;
}
static void class_init (GeglOperationClass *klass)
......@@ -63,5 +55,4 @@ static void class_init (GeglOperationClass *klass)
klass->process = op_process;
}
#endif
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_double (x, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "x coordinate of new origin")
gegl_chant_double (y, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "y coordinate of new origin")
......@@ -47,12 +47,10 @@ process (GeglOperation *operation,
GeglBuffer *input = filter->input;
GeglChantOperation *translate = (GeglChantOperation*)filter;
if(strcmp("output", output_prop))
return FALSE;
if (filter->output)
g_object_unref (filter->output);
g_assert (input);
g_assert (gegl_buffer_get_format (input));
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string(window_title, "window_title", "Title to be given output window")
gegl_chant_string(icon_title, "icon_title", "Icon to be used for output window")
......@@ -79,7 +79,7 @@ init_sdl (void)
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationFilter *op_filter = GEGL_OPERATION_FILTER (operation);
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
......@@ -165,7 +165,7 @@ process (GeglOperation *operation,
self->width = need->w;
self->height = need->h;
op_filter->output = NULL;
return TRUE;
}
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string (path, "/tmp/romedalen.jpg", "Path to jpg file on disk to load")
......@@ -25,7 +25,7 @@ gegl_chant_string (path, "/tmp/romedalen.jpg", "Path to jpg file on disk to load
#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_NAME jpg_load
#define GEGL_CHANT_DESCRIPTION "loads a jpeg file using libjpeg"
#define GEGL_CHANT_DESCRIPTION "JPG image loader"
#define GEGL_CHANT_SELF "jpg-load.c"
#define GEGL_CHANT_CATEGORIES "hidden"
#define GEGL_CHANT_CLASS_INIT
......@@ -46,7 +46,7 @@ query_jpg (const gchar *path,
static gboolean
process (GeglOperation *operation,
const gchar *output_prop)
const gchar *output_prop)
{
GeglOperationSource *op_source = GEGL_OPERATION_SOURCE (operation);
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
......@@ -54,15 +54,10 @@ process (GeglOperation *operation,
gint height;
gint result;
if(strcmp("output", output_prop))
return FALSE;
if (op_source->output!=NULL)
{
g_object_unref (op_source->output);
op_source->output=NULL;
}
{
result = query_jpg (self->path, &width, &height);
if (result)
......@@ -93,7 +88,7 @@ process (GeglOperation *operation,
{
g_warning ("%s failed to open file %s for reading.",
G_OBJECT_TYPE_NAME (operation), self->path);
op_source->output = NULL;
return FALSE;
}
}
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string(path, "/tmp/lena.png", "Path of file to load.")
gegl_chant_boolean(cache, TRUE, "Whether to cache the entire buffer loaded from the file.")
......@@ -26,7 +26,9 @@ gegl_chant_boolean(cache, TRUE, "Whether to cache the entire buffer loaded from
#define GEGL_CHANT_GRAPH
#define GEGL_CHANT_NAME load
#define GEGL_CHANT_DESCRIPTION "Multipurpose file loader, that uses other native handlers, and fallback conversion using image magick's convert."
#define GEGL_CHANT_DESCRIPTION "Multipurpose file loader, that uses other "\
"native handlers, and fallback conversion using "\
"image magick's convert."
#define GEGL_CHANT_SELF "load.c"
#define GEGL_CHANT_CLASS_INIT
#include "gegl-chant.h"
......@@ -47,6 +49,37 @@ struct _Priv
static void refresh_cache (GeglChantOperation *self);
static void
dispose (GObject *object)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (object);
Priv *priv = (Priv*)self->priv;
if (priv->cached_buffer)
{
g_object_unref (priv->cached_buffer);
priv->cached_buffer = NULL;
}
if (priv->cached_path)
{
g_free (priv->cached_path);
priv->cached_path = NULL;
}
G_OBJECT_CLASS (g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))->dispose (object);
}
static void
finalize (GObject *object)
{
GeglChantOperation *self = GEGL_CHANT_OPERATION (object);
if (self->priv)
g_free (self->priv);
G_OBJECT_CLASS (g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))->finalize (object);
}
static void
prepare (GeglOperation *operation)
{
......@@ -135,6 +168,9 @@ static void class_init (GeglOperationClass *klass)
{
klass->prepare = prepare;
klass->associate = associate;
G_OBJECT_CLASS (klass)->dispose = dispose;
G_OBJECT_CLASS (klass)->finalize = finalize;
}
......
......@@ -17,14 +17,13 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string (path, "/tmp/gegl-logo.svg", "path to file to load")
#else
#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_NAME magick_load
#define GEGL_CHANT_DESCRIPTION "Image Magick wrapper, that converts to" \
"PNG before loading."
#define GEGL_CHANT_DESCRIPTION "Image Magick wrapper using the png op"
#define GEGL_CHANT_SELF "magick-load.c"
#define GEGL_CHANT_CATEGORIES "hidden"
......@@ -66,12 +65,10 @@ process (GeglOperation *operation,
GeglOperationSource *op_source = GEGL_OPERATION_SOURCE(operation);
GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
if(strcmp("output", output_prop))
return FALSE;
if (op_source->output)
g_object_unref (op_source->output);
op_source->output = NULL;
if (!self->priv)
return FALSE;
......
......@@ -17,7 +17,7 @@
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#ifdef GEGL_CHANT_PROPERTIES
#if GEGL_CHANT_PROPERTIES
gegl_chant_string (path, "/tmp/romedalen.png", "path to file to load")
......@@ -25,7 +25,7 @@ gegl_chant_string (path, "/tmp/romedalen.png", "path to file to load")
#define GEGL_CHANT_SOURCE
#define GEGL_CHANT_NAME png_load
#define GEGL_CHANT_DESCRIPTION "loads a png file using libpng, currently restricted to 8bpc"
#define GEGL_CHANT_DESCRIPTION "PNG image loader"
#define GEGL_CHANT_SELF "png-load.c"
#define GEGL_CHANT_CATEGORIES "hidden"
#define GEGL_CHANT_CLASS_INIT
......@@ -53,12 +53,10 @@ process (GeglOperation *operation,
GeglOperationSource *op_source = GEGL_OPERATION_SOURCE(operation);
gint result;
if(strcmp("output", output_prop))