1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*
* $Id: maskops.c 23632 2021-05-03 23:01:27Z yeti-dn $
* Copyright (C) 2003-2021 David Necas (Yeti), Petr Klapetek.
* E-mail: yeti@gwyddion.net, klapetek@gwyddion.net.
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <libgwyddion/gwymacros.h>
#include <libprocess/filters.h>
#include <libprocess/grains.h>
#include <libgwydgets/gwystock.h>
#include <libgwymodule/gwymodule-process.h>
#include <app/gwymoduleutils.h>
#include <app/gwyapp.h>
#define RUN_MODES GWY_RUN_IMMEDIATE
static gboolean module_register(void);
static void mask_remove (GwyContainer *data,
GwyRunType runtype);
static void mask_invert (GwyContainer *data,
GwyRunType runtype);
static void mask_extract (GwyContainer *data,
GwyRunType runtype);
static void remove_touching(GwyContainer *data,
GwyRunType runtype);
static void mask_thin (GwyContainer *data,
GwyRunType runtype);
static GwyModuleInfo module_info = {
GWY_MODULE_ABI_VERSION,
&module_register,
N_("Basic operations with mask: inversion, removal, extraction."),
"Yeti <yeti@gwyddion.net>",
"1.6",
"David Nečas (Yeti) & Petr Klapetek",
"2004",
};
GWY_MODULE_QUERY2(module_info, maskops)
static gboolean
module_register(void)
{
gwy_process_func_register("mask_remove",
(GwyProcessFunc)&mask_remove,
N_("/_Mask/_Remove Mask"),
GWY_STOCK_MASK_REMOVE,
RUN_MODES,
GWY_MENU_FLAG_DATA_MASK | GWY_MENU_FLAG_DATA,
N_("Remove mask from data"));
gwy_process_func_register("mask_invert",
(GwyProcessFunc)&mask_invert,
N_("/_Mask/_Invert Mask"),
GWY_STOCK_MASK_INVERT,
RUN_MODES,
GWY_MENU_FLAG_DATA_MASK | GWY_MENU_FLAG_DATA,
N_("Invert mask"));
gwy_process_func_register("mask_extract",
(GwyProcessFunc)&mask_extract,
N_("/_Mask/_Extract Mask"),
GWY_STOCK_MASK_EXTRACT,
RUN_MODES,
GWY_MENU_FLAG_DATA_MASK | GWY_MENU_FLAG_DATA,
N_("Extract mask to a new image"));
gwy_process_func_register("grain_rem_touching",
(GwyProcessFunc)&remove_touching,
N_("/_Grains/_Remove Edge-Touching"),
GWY_STOCK_GRAINS_EDGE_REMOVE,
RUN_MODES,
GWY_MENU_FLAG_DATA | GWY_MENU_FLAG_DATA_MASK,
N_("Remove grains touching image edges"));
gwy_process_func_register("mask_thin",
(GwyProcessFunc)&mask_thin,
N_("/_Mask/Thi_n"),
GWY_STOCK_MASK_THIN,
RUN_MODES,
GWY_MENU_FLAG_DATA_MASK | GWY_MENU_FLAG_DATA,
N_("Thin mask"));
return TRUE;
}
static void
mask_invert(GwyContainer *data, GwyRunType runtype)
{
GwyDataField *mfield;
GQuark mquark;
gint id;
g_return_if_fail(runtype & RUN_MODES);
gwy_app_data_browser_get_current(GWY_APP_MASK_FIELD, &mfield,
GWY_APP_MASK_FIELD_KEY, &mquark,
GWY_APP_DATA_FIELD_ID, &id,
0);
g_return_if_fail(mfield && mquark);
gwy_app_undo_qcheckpointv(data, 1, &mquark);
gwy_data_field_grains_invert(mfield);
gwy_data_field_data_changed(mfield);
gwy_app_channel_log_add_proc(data, id, id);
}
static void
mask_remove(GwyContainer *data, GwyRunType runtype)
{
GQuark mquark;
gint id;
g_return_if_fail(runtype & RUN_MODES);
gwy_app_data_browser_get_current(GWY_APP_MASK_FIELD_KEY, &mquark,
GWY_APP_DATA_FIELD_ID, &id,
0);
g_return_if_fail(mquark);
gwy_app_undo_qcheckpointv(data, 1, &mquark);
gwy_container_remove(data, mquark);
gwy_app_channel_log_add_proc(data, id, id);
}
static void
mask_extract(GwyContainer *data, GwyRunType runtype)
{
GwyDataField *field;
gint id, newid;
g_return_if_fail(runtype & RUN_MODES);
gwy_app_data_browser_get_current(GWY_APP_MASK_FIELD, &field,
GWY_APP_DATA_FIELD_ID, &id,
0);
g_return_if_fail(field);
field = gwy_data_field_duplicate(field);
gwy_data_field_clamp(field, 0.0, 1.0);
gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_z(field), NULL);
newid = gwy_app_data_browser_add_data_field(field, data, TRUE);
g_object_unref(field);
gwy_app_set_data_field_title(data, newid, _("Mask"));
gwy_app_sync_data_items(data, data, id, newid, FALSE,
GWY_DATA_ITEM_GRADIENT,
GWY_DATA_ITEM_REAL_SQUARE,
0);
gwy_app_channel_log_add_proc(data, id, newid);
}
static void
remove_touching(GwyContainer *data, GwyRunType runtype)
{
GwyDataField *mfield;
GQuark mquark;
gint id;
g_return_if_fail(runtype & RUN_MODES);
gwy_app_data_browser_get_current(GWY_APP_MASK_FIELD, &mfield,
GWY_APP_MASK_FIELD_KEY, &mquark,
GWY_APP_DATA_FIELD_ID, &id,
0);
g_return_if_fail(mfield);
gwy_app_undo_qcheckpointv(data, 1, &mquark);
gwy_data_field_grains_remove_touching_border(mfield);
gwy_data_field_data_changed(mfield);
gwy_app_channel_log_add_proc(data, id, id);
}
static void
mask_thin(GwyContainer *data, GwyRunType runtype)
{
GwyDataField *mask;
GQuark quark;
gint id;
g_return_if_fail(runtype & RUN_MODES);
gwy_app_data_browser_get_current(GWY_APP_MASK_FIELD, &mask,
GWY_APP_MASK_FIELD_KEY, &quark,
GWY_APP_DATA_FIELD_ID, &id,
0);
g_return_if_fail(mask);
gwy_app_undo_qcheckpointv(data, 1, &quark);
gwy_data_field_grains_thin(mask);
gwy_data_field_data_changed(mask);
gwy_app_channel_log_add_proc(data, id, id);
}
/* vim: set cin columns=120 tw=118 et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */
|