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 2018 Ell
17  */
18 
19 #include "config.h"
20 #include <glib/gi18n-lib.h>
21 
22 #include <gegl.h>
23 #include <gegl-plugin.h>
24 
25 #include "gegl-config.h"
26 
27 #include "scale.h"
28 #include "module.h"
29 
30 enum
31 {
32   PROP_ABYSS_POLICY = 1
33 };
34 
35 static void              gegl_scale_get_property     (GObject      *object,
36                                                       guint         prop_id,
37                                                       GValue       *value,
38                                                       GParamSpec   *pspec);
39 static void              gegl_scale_set_property     (GObject      *object,
40                                                       guint         prop_id,
41                                                       const GValue *value,
42                                                       GParamSpec   *pspec);
43 
44 static GeglAbyssPolicy   gegl_scale_get_abyss_policy (OpTransform  *transform);
45 
46 /* ************************* */
47 
48 static void              op_scale_init               (OpScale      *self);
49 static void              op_scale_class_init         (OpScaleClass *klass);
50 static gpointer          op_scale_parent_class = NULL;
51 
52 static void
op_scale_class_intern_init(gpointer klass)53 op_scale_class_intern_init (gpointer klass)
54 {
55   op_scale_parent_class = g_type_class_peek_parent (klass);
56   op_scale_class_init ((OpScaleClass *) klass);
57 }
58 
59 GType
op_scale_get_type(void)60 op_scale_get_type (void)
61 {
62   static GType g_define_type_id = 0;
63   if (G_UNLIKELY (g_define_type_id == 0))
64     {
65       static const GTypeInfo g_define_type_info =
66         {
67           sizeof (OpScaleClass),
68           (GBaseInitFunc) NULL,
69           (GBaseFinalizeFunc) NULL,
70           (GClassInitFunc) op_scale_class_intern_init,
71           (GClassFinalizeFunc) NULL,
72           NULL,   /* class_data */
73           sizeof (OpScale),
74           0,      /* n_preallocs */
75           (GInstanceInitFunc) op_scale_init,
76           NULL    /* value_table */
77         };
78 
79       g_define_type_id =
80         gegl_module_register_type (transform_module_get_module (),
81                                    TYPE_OP_TRANSFORM,
82                                    "GeglOpPlugIn-scale-core",
83                                    &g_define_type_info, 0);
84     }
85   return g_define_type_id;
86 }
87 
88 static void
op_scale_class_init(OpScaleClass * klass)89 op_scale_class_init (OpScaleClass *klass)
90 {
91   GObjectClass     *gobject_class   = G_OBJECT_CLASS (klass);
92   OpTransformClass *transform_class = OP_TRANSFORM_CLASS (klass);
93 
94   gobject_class->set_property       = gegl_scale_set_property;
95   gobject_class->get_property       = gegl_scale_get_property;
96 
97   transform_class->get_abyss_policy = gegl_scale_get_abyss_policy;
98 
99   g_object_class_install_property (gobject_class, PROP_ABYSS_POLICY,
100                                    g_param_spec_enum (
101                                      "abyss-policy",
102                                      _("Abyss policy"),
103                                      _("How image edges are handled"),
104                                      GEGL_TYPE_ABYSS_POLICY,
105                                      GEGL_ABYSS_NONE,
106                                      G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
107 }
108 
109 static void
op_scale_init(OpScale * self)110 op_scale_init (OpScale *self)
111 {
112 }
113 
114 static void
gegl_scale_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)115 gegl_scale_get_property (GObject    *object,
116                          guint       prop_id,
117                          GValue     *value,
118                          GParamSpec *pspec)
119 {
120   OpScale *self = OP_SCALE (object);
121 
122   switch (prop_id)
123     {
124     case PROP_ABYSS_POLICY:
125       g_value_set_enum (value, self->abyss_policy);
126       break;
127     default:
128       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
129       break;
130     }
131 }
132 
133 static void
gegl_scale_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)134 gegl_scale_set_property (GObject      *object,
135                          guint         prop_id,
136                          const GValue *value,
137                          GParamSpec   *pspec)
138 {
139   OpScale *self = OP_SCALE (object);
140 
141   switch (prop_id)
142     {
143     case PROP_ABYSS_POLICY:
144       self->abyss_policy = g_value_get_enum (value);
145       break;
146     default:
147       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148       break;
149     }
150 }
151 
152 static GeglAbyssPolicy
gegl_scale_get_abyss_policy(OpTransform * transform)153 gegl_scale_get_abyss_policy (OpTransform *transform)
154 {
155   return OP_SCALE (transform)->abyss_policy;
156 }
157