|
Packit Service |
2781ba |
/*
|
|
Packit Service |
2781ba |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
2781ba |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
2781ba |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
2781ba |
* (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* This program 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
|
|
Packit Service |
2781ba |
* GNU General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
2781ba |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright (C) 2009 Martin Nordholts
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <string.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define RED 0
|
|
Packit Service |
2781ba |
#define GREEN 1
|
|
Packit Service |
2781ba |
#define BLUE 2
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define SUCCESS 0
|
|
Packit Service |
2781ba |
#define FAILURE -1
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
int main(int argc, char *argv[])
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
int result = SUCCESS;
|
|
Packit Service |
2781ba |
GeglNode *graph = NULL;
|
|
Packit Service |
2781ba |
GeglNode *color_in_graph = NULL;
|
|
Packit Service |
2781ba |
GeglNode *crop_in_graph = NULL;
|
|
Packit Service |
2781ba |
GeglNode *graph_output_proxy = NULL;
|
|
Packit Service |
2781ba |
GeglNode *crop_outside_graph = NULL;
|
|
Packit Service |
2781ba |
GeglRectangle roi = { 0, 0, 1, 1 };
|
|
Packit Service |
2781ba |
guchar result_buffer[3] = { 0, 0, 0 };
|
|
Packit Service |
2781ba |
GeglColor *color1 = NULL;
|
|
Packit Service |
2781ba |
GeglColor *color2 = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Init */
|
|
Packit Service |
2781ba |
g_thread_init (NULL);
|
|
Packit Service |
2781ba |
gegl_init (&argc, &argv);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
color1 = gegl_color_new ("rgb(1.0, 0.0, 1.0)");
|
|
Packit Service |
2781ba |
color2 = gegl_color_new ("rgb(0.0, 0.0, 1.0)");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Construct graph */
|
|
Packit Service |
2781ba |
graph = gegl_node_new ();
|
|
Packit Service |
2781ba |
color_in_graph = gegl_node_new_child (graph,
|
|
Packit Service |
2781ba |
"operation", "gegl:color",
|
|
Packit Service |
2781ba |
"value", color1,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
crop_in_graph = gegl_node_new_child (graph,
|
|
Packit Service |
2781ba |
"operation", "gegl:crop",
|
|
Packit Service |
2781ba |
"x", 0.0,
|
|
Packit Service |
2781ba |
"y", 0.0,
|
|
Packit Service |
2781ba |
"width", 1.0,
|
|
Packit Service |
2781ba |
"height", 1.0,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
graph_output_proxy = gegl_node_get_output_proxy (graph,
|
|
Packit Service |
2781ba |
"output");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_node_link_many (color_in_graph,
|
|
Packit Service |
2781ba |
crop_in_graph,
|
|
Packit Service |
2781ba |
graph_output_proxy,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Make sure the implicit connection to the graph output proxy works
|
|
Packit Service |
2781ba |
* by connecting an additional crop directly to the graph node
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
crop_outside_graph = gegl_node_new_child (graph,
|
|
Packit Service |
2781ba |
"operation", "gegl:crop",
|
|
Packit Service |
2781ba |
"x", 0.0,
|
|
Packit Service |
2781ba |
"y", 0.0,
|
|
Packit Service |
2781ba |
"width", 1.0,
|
|
Packit Service |
2781ba |
"height", 1.0,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
gegl_node_connect_to (graph, "output",
|
|
Packit Service |
2781ba |
crop_outside_graph, "input");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Process the graph and make sure we get the expected result */
|
|
Packit Service |
2781ba |
memset (result_buffer, 0, sizeof (result_buffer));
|
|
Packit Service |
2781ba |
gegl_node_blit (crop_outside_graph,
|
|
Packit Service |
2781ba |
1.0,
|
|
Packit Service |
2781ba |
&roi,
|
|
Packit Service |
2781ba |
babl_format ("RGB u8"),
|
|
Packit Service |
2781ba |
result_buffer,
|
|
Packit Service |
2781ba |
GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_BLIT_DEFAULT);
|
|
Packit Service |
2781ba |
if (!(result_buffer[RED] == 255 &&
|
|
Packit Service |
2781ba |
result_buffer[GREEN] == 0 &&
|
|
Packit Service |
2781ba |
result_buffer[BLUE] == 255))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
result = FAILURE;
|
|
Packit Service |
2781ba |
g_printerr ("Initial processing failed, you messed up GEGL pretty badly :(");
|
|
Packit Service |
2781ba |
goto abort;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Process the graph again with a different color and make sure we
|
|
Packit Service |
2781ba |
* get the expected result
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
gegl_node_set (color_in_graph,
|
|
Packit Service |
2781ba |
"value", color2,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
memset (result_buffer, 0, sizeof (result_buffer));
|
|
Packit Service |
2781ba |
gegl_node_blit (crop_outside_graph,
|
|
Packit Service |
2781ba |
1.0,
|
|
Packit Service |
2781ba |
&roi,
|
|
Packit Service |
2781ba |
babl_format ("RGB u8"),
|
|
Packit Service |
2781ba |
result_buffer,
|
|
Packit Service |
2781ba |
GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_BLIT_DEFAULT);
|
|
Packit Service |
2781ba |
if (!(result_buffer[RED] == 0 &&
|
|
Packit Service |
2781ba |
result_buffer[GREEN] == 0 &&
|
|
Packit Service |
2781ba |
result_buffer[BLUE] == 255))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
result = FAILURE;
|
|
Packit Service |
2781ba |
g_printerr ("Second processing failed, i.e. changing color didn't work properly");
|
|
Packit Service |
2781ba |
goto abort;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Process the graph again but without changing anything since this
|
|
Packit Service |
2781ba |
* puts some stress on the caching mechanisms
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
memset (result_buffer, 0, sizeof (result_buffer));
|
|
Packit Service |
2781ba |
gegl_node_blit (crop_outside_graph,
|
|
Packit Service |
2781ba |
1.0,
|
|
Packit Service |
2781ba |
&roi,
|
|
Packit Service |
2781ba |
babl_format ("RGB u8"),
|
|
Packit Service |
2781ba |
result_buffer,
|
|
Packit Service |
2781ba |
GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_BLIT_DEFAULT);
|
|
Packit Service |
2781ba |
if (!(result_buffer[RED] == 0 &&
|
|
Packit Service |
2781ba |
result_buffer[GREEN] == 0 &&
|
|
Packit Service |
2781ba |
result_buffer[BLUE] == 255))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
result = FAILURE;
|
|
Packit Service |
2781ba |
g_printerr ("Third processing failed, looks like you messed up caching");
|
|
Packit Service |
2781ba |
goto abort;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
abort:
|
|
Packit Service |
2781ba |
/* Cleanup */
|
|
Packit Service |
2781ba |
g_object_unref (graph);
|
|
Packit Service |
2781ba |
g_object_unref (color1);
|
|
Packit Service |
2781ba |
g_object_unref (color2);
|
|
Packit Service |
2781ba |
gegl_exit ();
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|