PIKApp/app/operations/pikaoperationsettings.c

300 lines
8.9 KiB
C

/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikaoperationsettings.c
* Copyright (C) 2020 Ell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libpikaconfig/pikaconfig.h"
#include "operations-types.h"
#include "gegl/pika-gegl-utils.h"
#include "core/pikadrawable.h"
#include "core/pikadrawablefilter.h"
#include "pikaoperationsettings.h"
#include "pika-intl.h"
enum
{
PROP_0,
PROP_CLIP,
PROP_REGION,
PROP_MODE,
PROP_OPACITY,
PROP_GAMMA_HACK
};
static void pika_operation_settings_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void pika_operation_settings_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (PikaOperationSettings, pika_operation_settings,
PIKA_TYPE_SETTINGS)
#define parent_class pika_operation_settings_parent_class
static void
pika_operation_settings_class_init (PikaOperationSettingsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = pika_operation_settings_set_property;
object_class->get_property = pika_operation_settings_get_property;
PIKA_CONFIG_PROP_ENUM (object_class, PROP_CLIP,
"pika-clip",
_("Clipping"),
_("How to clip"),
PIKA_TYPE_TRANSFORM_RESIZE,
PIKA_TRANSFORM_RESIZE_ADJUST,
PIKA_CONFIG_PARAM_DEFAULTS);
PIKA_CONFIG_PROP_ENUM (object_class, PROP_REGION,
"pika-region",
NULL, NULL,
PIKA_TYPE_FILTER_REGION,
PIKA_FILTER_REGION_SELECTION,
PIKA_CONFIG_PARAM_DEFAULTS);
PIKA_CONFIG_PROP_ENUM (object_class, PROP_MODE,
"pika-mode",
_("Mode"),
NULL,
PIKA_TYPE_LAYER_MODE,
PIKA_LAYER_MODE_REPLACE,
PIKA_CONFIG_PARAM_DEFAULTS);
PIKA_CONFIG_PROP_DOUBLE (object_class, PROP_OPACITY,
"pika-opacity",
_("Opacity"),
NULL,
0.0, 1.0, 1.0,
PIKA_CONFIG_PARAM_DEFAULTS);
PIKA_CONFIG_PROP_BOOLEAN (object_class, PROP_GAMMA_HACK,
"pika-gamma-hack",
"Gamma hack (temp hack, please ignore)",
NULL,
FALSE,
PIKA_CONFIG_PARAM_DEFAULTS);
}
static void
pika_operation_settings_init (PikaOperationSettings *settings)
{
}
static void
pika_operation_settings_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PikaOperationSettings *settings = PIKA_OPERATION_SETTINGS (object);
switch (property_id)
{
case PROP_CLIP:
g_value_set_enum (value, settings->clip);
break;
case PROP_REGION:
g_value_set_enum (value, settings->region);
break;
case PROP_MODE:
g_value_set_enum (value, settings->mode);
break;
case PROP_OPACITY:
g_value_set_double (value, settings->opacity);
break;
case PROP_GAMMA_HACK:
g_value_set_boolean (value, settings->gamma_hack);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_operation_settings_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PikaOperationSettings *settings = PIKA_OPERATION_SETTINGS (object);
switch (property_id)
{
case PROP_CLIP:
settings->clip = g_value_get_enum (value);
break;
case PROP_REGION:
settings->region = g_value_get_enum (value);
break;
case PROP_MODE:
settings->mode = g_value_get_enum (value);
break;
case PROP_OPACITY:
settings->opacity = g_value_get_double (value);
break;
case PROP_GAMMA_HACK:
settings->gamma_hack = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/* public functions */
void
pika_operation_settings_sync_drawable_filter (PikaOperationSettings *settings,
PikaDrawableFilter *filter)
{
gboolean clip;
g_return_if_fail (PIKA_IS_OPERATION_SETTINGS (settings));
g_return_if_fail (PIKA_IS_DRAWABLE_FILTER (filter));
clip = settings->clip == PIKA_TRANSFORM_RESIZE_CLIP ||
! babl_format_has_alpha (pika_drawable_filter_get_format (filter));
pika_drawable_filter_set_region (filter, settings->region);
pika_drawable_filter_set_clip (filter, clip);
pika_drawable_filter_set_mode (filter,
settings->mode,
PIKA_LAYER_COLOR_SPACE_AUTO,
PIKA_LAYER_COLOR_SPACE_AUTO,
PIKA_LAYER_COMPOSITE_AUTO);
pika_drawable_filter_set_opacity (filter, settings->opacity);
pika_drawable_filter_set_gamma_hack (filter, settings->gamma_hack);
}
/* protected functions */
static const gchar * const base_properties[] =
{
"time",
"pika-clip",
"pika-region",
"pika-mode",
"pika-opacity",
"pika-gamma-hack"
};
gboolean
pika_operation_settings_config_serialize_base (PikaConfig *config,
PikaConfigWriter *writer,
gpointer data)
{
gint i;
for (i = 0; i < G_N_ELEMENTS (base_properties); i++)
{
if (! pika_config_serialize_property_by_name (config,
base_properties[i],
writer))
{
return FALSE;
}
}
return TRUE;
}
gboolean
pika_operation_settings_config_equal_base (PikaConfig *a,
PikaConfig *b)
{
PikaOperationSettings *settings_a = PIKA_OPERATION_SETTINGS (a);
PikaOperationSettings *settings_b = PIKA_OPERATION_SETTINGS (b);
return settings_a->clip == settings_b->clip &&
settings_a->region == settings_b->region &&
settings_a->mode == settings_b->mode &&
settings_a->opacity == settings_b->opacity &&
settings_a->gamma_hack == settings_b->gamma_hack;
}
void
pika_operation_settings_config_reset_base (PikaConfig *config)
{
gint i;
g_object_freeze_notify (G_OBJECT (config));
for (i = 0; i < G_N_ELEMENTS (base_properties); i++)
pika_config_reset_property (G_OBJECT (config), base_properties[i]);
g_object_thaw_notify (G_OBJECT (config));
}
gboolean
pika_operation_settings_config_copy_base (PikaConfig *src,
PikaConfig *dest,
GParamFlags flags)
{
gint i;
g_object_freeze_notify (G_OBJECT (dest));
for (i = 0; i < G_N_ELEMENTS (base_properties); i++)
{
g_object_unref (g_object_bind_property (src, base_properties[i],
dest, base_properties[i],
G_BINDING_SYNC_CREATE));
}
g_object_thaw_notify (G_OBJECT (dest));
return TRUE;
}