translate.c 2.39 KB
Newer Older
1 2 3 4 5
/* This file is part of GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
6
 * version 3 of the License, or (at your option) any later version.
7 8 9 10 11 12 13
 *
 * GEGL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
14
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
15 16
 *
 * Copyright 2006 Philip Lafleur
17
 *           2017 Øyvind Kolås
18 19
 */

20 21 22
#include "config.h"
#include <glib/gi18n-lib.h>

23
#ifdef GEGL_PROPERTIES
24

25 26 27
property_double (x, _("X"), 0.0)
    description (_("Horizontal translation"))
    ui_range (-1000.0, 1000.0)
28 29
    ui_meta ("unit", "pixel-distance")
    ui_meta ("axis", "x")
30

31 32 33
property_double (y, _("Y"), 0.0)
    description (_("Vertical translation"))
    ui_range (-1000.0, 1000.0)
34 35
    ui_meta ("unit", "pixel-distance")
    ui_meta ("axis", "y")
36 37 38

#else

39 40 41 42 43 44 45 46 47 48 49 50
#include "gegl-operation-filter.h"
#include "transform-core.h"
#define GEGL_OP_NO_SOURCE
#define GEGL_OP_Parent  OpTransform
#define GEGL_OP_PARENT  TYPE_OP_TRANSFORM
#define GEGL_OP_NAME    translate
#define GEGL_OP_BUNDLE
#define GEGL_OP_C_FILE  "translate.c"

#include "gegl-op.h"

#include <math.h>
51 52

static void
53
create_matrix (OpTransform *op,
54
               GeglMatrix3 *matrix)
55
{
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  GeglProperties *o = GEGL_PROPERTIES (op);

  matrix->coeff [0][2] = o->x;
  matrix->coeff [1][2] = o->y;
}

#include <stdio.h>

static void
gegl_op_class_init (GeglOpClass *klass)
{
  GeglOperationClass *operation_class;
  OpTransformClass   *transform_class;

  operation_class = GEGL_OPERATION_CLASS (klass);
  transform_class = OP_TRANSFORM_CLASS (klass);
  transform_class->create_matrix = create_matrix;
73

74 75 76 77
  gegl_operation_class_set_keys (operation_class,
    "name", "gegl:translate",
    "title", _("Translate"),
    "categories", "transform",
78
    "reference-hash", "fd7287903bdf467448454216712a0b2a",
79
    "description", _("Repositions the buffer (with subpixel precision), if integer coordinates are passed a fast-path without resampling is used"),
80
    "reference-chain", "load path=images/standard-input.png translate x=23.0 y=42.0 clip-to-input=true",
81
    NULL);
82 83 84
}

#endif