rotate.c 2.31 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 28
property_double (degrees, _("Degrees"), 0.0)
    description(_("Angle to rotate (counter-clockwise)"))
    value_range (-720.0, 720.0)
    ui_range (-180.0, 180.0)
29
    ui_meta ("unit", "degree")
30 31 32

#else

33 34 35 36 37 38 39 40 41 42
#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    rotate
#define GEGL_OP_BUNDLE
#define GEGL_OP_C_FILE  "rotate.c"

#include "gegl-op.h"
43 44 45 46

#include <math.h>

static void
47
create_matrix (OpTransform *op,
48
               GeglMatrix3 *matrix)
49
{
50 51
  GeglProperties *o = GEGL_PROPERTIES (op);
  double radians = o->degrees * (2 * G_PI / 360.0);
52

53 54 55
  matrix->coeff [0][0] = matrix->coeff [1][1] = cos (radians);
  matrix->coeff [0][1] = sin (radians);
  matrix->coeff [1][0] = - matrix->coeff [0][1];
56 57
}

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#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;

  gegl_operation_class_set_keys (operation_class,
    "name", "gegl:rotate",
    "title", _("Rotate"),
    "categories", "transform",
74
    "reference-hash", "4ac5d42bb82187a705a2ecd640353490",
75
    "reference-chain", "load path=images/standard-input.png rotate degrees=30.0 clip-to-input=true origin-x=100 origin-y=100",
76 77 78 79
    "description", _("Rotate the buffer around the specified origin."),
    NULL);
}

80
#endif