|
Packit Service |
2781ba |
/* This file is an image processing operation for 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 2007 Øyvind Kolås <pippin@gimp.org>
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_int (x0, _("X0"), 0, 1000, 0, _("Start x coordinate"))
|
|
Packit Service |
2781ba |
gegl_chant_int (x1, _("X1"), 0, 1000, 200, _("End x coordinate"))
|
|
Packit Service |
2781ba |
gegl_chant_int (y0, _("Y0"), 0, 1000, 0, _("Start y coordinate"))
|
|
Packit Service |
2781ba |
gegl_chant_int (y1, _("Y1"), 0, 1000, 200, _("End y coordinate"))
|
|
Packit Service |
2781ba |
gegl_chant_int (width, _("Width"), 10, 10000, 1024, _("Width of plot"))
|
|
Packit Service |
2781ba |
gegl_chant_int (height, _("Height"), 10, 10000, 256, _("Height of plot"))
|
|
Packit Service |
2781ba |
gegl_chant_double (min, _("Min"), -500.0, 500, 0.0, _("Value at bottom"))
|
|
Packit Service |
2781ba |
gegl_chant_double (max, _("Max"), -500.0, 500, 8.0, _("Value at top"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_FILTER
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "line-profile.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include <cairo.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gfloat
|
|
Packit Service |
2781ba |
buffer_sample (GeglBuffer *buffer,
|
|
Packit Service |
2781ba |
gint x,
|
|
Packit Service |
2781ba |
gint y,
|
|
Packit Service |
2781ba |
gint component)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat rgba[4];
|
|
Packit Service |
2781ba |
GeglRectangle roi = {x,y,1,1};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_get (buffer, &roi, 1.0, babl_format ("RGBA float"), &rgba[0], GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
return rgba[component];
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglBuffer *input,
|
|
Packit Service |
2781ba |
GeglBuffer *output,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
gint width = MAX(MAX (o->width, o->x0), o->x1);
|
|
Packit Service |
2781ba |
gint height = MAX(MAX (o->height, o->y0), o->y1);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglRectangle extent = {0,0,width,height};
|
|
Packit Service |
2781ba |
output = gegl_buffer_new (&extent, babl_format ("B'aG'aR'aA u8"));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
guchar *buf = g_new0 (guchar, width * height * 4);
|
|
Packit Service |
2781ba |
cairo_t *cr;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cairo_surface_t *surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_ARGB32, width, height, width * 4);
|
|
Packit Service |
2781ba |
cr = cairo_create (surface);
|
|
Packit Service |
2781ba |
/* cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
|
|
Packit Service |
2781ba |
cairo_rectangle (cr, 0,0, o->width, o->height);
|
|
Packit Service |
2781ba |
cairo_fill (cr);*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define val2y(val) (o->height - (val - o->min) * o->height / (o->max-o->min))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, .0, .0, .8, 0.5);
|
|
Packit Service |
2781ba |
cairo_move_to (cr, 0, val2y(0.0));
|
|
Packit Service |
2781ba |
cairo_line_to (cr, o->width, val2y(0.0));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, .8, .8, .0, 0.5);
|
|
Packit Service |
2781ba |
cairo_move_to (cr, 0, val2y(1.0));
|
|
Packit Service |
2781ba |
cairo_line_to (cr, o->width, val2y(1.0));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cairo_stroke (cr);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint x;
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 1.0);
|
|
Packit Service |
2781ba |
for (x=0;x<o->width;x++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat t = (1.0*x)/o->width;
|
|
Packit Service |
2781ba |
gint sx = ((1.0-t) * o->x0) + (t * o->x1);
|
|
Packit Service |
2781ba |
gint sy = ((1.0-t) * o->y0) + (t * o->y1);
|
|
Packit Service |
2781ba |
cairo_line_to (cr, x, val2y(buffer_sample(input,sx,sy,0)));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
cairo_stroke (cr);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint x;
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
|
|
Packit Service |
2781ba |
for (x=0;x<o->width;x++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat t = (1.0*x)/o->width;
|
|
Packit Service |
2781ba |
gint sx = ((1.0-t) * o->x0) + (t * o->x1);
|
|
Packit Service |
2781ba |
gint sy = ((1.0-t) * o->y0) + (t * o->y1);
|
|
Packit Service |
2781ba |
cairo_line_to (cr, x, val2y(buffer_sample(input,sx,sy,1)));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
cairo_stroke (cr);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint x;
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 1.0);
|
|
Packit Service |
2781ba |
for (x=0;x<o->width;x++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat t = (1.0*x)/o->width;
|
|
Packit Service |
2781ba |
gint sx = ((1.0-t) * o->x0) + (t * o->x1);
|
|
Packit Service |
2781ba |
gint sy = ((1.0-t) * o->y0) + (t * o->y1);
|
|
Packit Service |
2781ba |
cairo_line_to (cr, x, val2y(buffer_sample(input,sx,sy,2)));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
cairo_stroke (cr);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.4);
|
|
Packit Service |
2781ba |
cairo_move_to (cr, o->x0, o->y0);
|
|
Packit Service |
2781ba |
cairo_line_to (cr, o->x1, o->y1);
|
|
Packit Service |
2781ba |
cairo_stroke (cr);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (output, NULL, 0, babl_format ("B'aG'aR'aA u8"), buf, GEGL_AUTO_ROWSTRIDE);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_required_for_output (GeglOperation *self,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return *gegl_operation_source_get_bounding_box (self, "input");
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_bounding_box (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglRectangle defined = {0,0,o->width,o->height};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
defined.width = MAX (MAX (o->width, o->x0), o->x1);
|
|
Packit Service |
2781ba |
defined.height = MAX (MAX (o->height, o->y0), o->y1);
|
|
Packit Service |
2781ba |
return defined;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_chant_class_init (GeglChantClass *klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class;
|
|
Packit Service |
2781ba |
GeglOperationFilterClass *filter_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
filter_class->process = process;
|
|
Packit Service |
2781ba |
operation_class->get_required_for_output = get_required_for_output;
|
|
Packit Service |
2781ba |
operation_class->get_bounding_box = get_bounding_box;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:line-profile",
|
|
Packit Service |
2781ba |
"categories" , "debug",
|
|
Packit Service |
2781ba |
"description" ,
|
|
Packit Service |
2781ba |
_("Renders luminance profiles for red green and blue components along"
|
|
Packit Service |
2781ba |
" the specified line in the input buffer, plotted in a buffer of the"
|
|
Packit Service |
2781ba |
" specified size."),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|