1 /* This file is part of GEGL
2  *
3  * GEGL is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 3 of the License, or (at your option) any later version.
7  *
8  * GEGL is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
15  *
16  * Copyright 2020 Øyvind Kolås
17  */
18 
19 #include "config.h"
20 #include <glib/gi18n-lib.h>
21 
22 #ifdef GEGL_PROPERTIES
23 
24 #else
25 
26 #include "gegl-operation-filter.h"
27 #include "transform-core.h"
28 #define GEGL_OP_NO_SOURCE
29 #define GEGL_OP_Parent  OpTransform
30 #define GEGL_OP_PARENT  TYPE_OP_TRANSFORM
31 #define GEGL_OP_NAME    reset_origin
32 #define GEGL_OP_BUNDLE
33 #define GEGL_OP_C_FILE  "reset-origin.c"
34 
35 #include "gegl-op.h"
36 
37 #include <stdio.h>
38 
39 static void
create_matrix(OpTransform * op,GeglMatrix3 * matrix)40 create_matrix (OpTransform *op,
41                GeglMatrix3 *matrix)
42 {
43   GeglOperation *operation = GEGL_OPERATION (op);
44 
45   gdouble x = 0.0;
46   gdouble y = 0.0;
47 
48   GeglNode *box_node    = gegl_operation_get_source_node (operation, "input");
49 
50   GeglRectangle box_rect = {0,};
51 
52   if (box_node)
53     box_rect = gegl_node_get_bounding_box (box_node);
54 
55   x = -box_rect.x;
56   y = -box_rect.y;
57 
58   matrix->coeff [0][2] = x;
59   matrix->coeff [1][2] = y;
60 }
61 
62 static void
gegl_op_class_init(GeglOpClass * klass)63 gegl_op_class_init (GeglOpClass *klass)
64 {
65   GeglOperationClass *operation_class;
66   OpTransformClass   *transform_class;
67   gchar              *composition =
68     "<?xml version='1.0' encoding='UTF-8'?>"
69     "<gegl>"
70     "  <node operation='gegl:crop' width='200' height='200'/>"
71     "  <node operation='gegl:over'>"
72     "    <node operation='gegl:reset-origin'>"
73     "      <params>"
74     "        <param name='origin-x'>100</param>"
75     "        <param name='origin-y'>100</param>"
76     "      </params>"
77     "    </node>"
78     "    <node operation='gegl:load' path='standard-input.png'/>"
79     "  </node>"
80     "  <node operation='gegl:checkerboard'>"
81     "    <params>"
82     "      <param name='color1'>rgb(0.25,0.25,0.25)</param>"
83     "      <param name='color2'>rgb(0.75,0.75,0.75)</param>"
84     "    </params>"
85     "  </node>"
86     "</gegl>";
87 
88   operation_class = GEGL_OPERATION_CLASS (klass);
89   transform_class = OP_TRANSFORM_CLASS (klass);
90 
91   transform_class->create_matrix = create_matrix;
92 
93   gegl_operation_class_set_keys (operation_class,
94     "name", "gegl:reset-origin",
95     "title", _("Reset origin"),
96     "categories", "transform",
97     "reference-composition", composition,
98     "description", _("Translate top-left to 0,0."),
99     NULL);
100 }
101 
102 #endif
103