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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpForegroundSelectTool
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "gegl/gimp-gegl-loops.h"
#include "gegl/gimp-gegl-mask.h"
#include "core/gimp.h"
#include "core/gimpchannel-select.h"
#include "core/gimpdrawable-foreground-extract.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
#include "core/gimpprogress.h"
#include "core/gimpscanconvert.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimptoolgui.h"
#include "gimpforegroundselecttool.h"
#include "gimpforegroundselectoptions.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
#define FAR_OUTSIDE -10000
typedef struct _StrokeUndo StrokeUndo;
struct _StrokeUndo
{
GeglBuffer *saved_trimap;
gint trimap_x;
gint trimap_y;
GimpMattingDrawMode draw_mode;
gint stroke_width;
};
static void gimp_foreground_select_tool_finalize (GObject *object);
static gboolean gimp_foreground_select_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_foreground_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_foreground_select_tool_button_press (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpButtonPressType press_type,
GimpDisplay *display);
static void gimp_foreground_select_tool_button_release (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpButtonReleaseType release_type,
GimpDisplay *display);
static void gimp_foreground_select_tool_motion (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_foreground_select_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display);
static void gimp_foreground_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_foreground_select_tool_active_modifier_key
(GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_foreground_select_tool_oper_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_foreground_select_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static const gchar * gimp_foreground_select_tool_can_undo
(GimpTool *tool,
GimpDisplay *display);
static const gchar * gimp_foreground_select_tool_can_redo
(GimpTool *tool,
GimpDisplay *display);
static gboolean gimp_foreground_select_tool_undo (GimpTool *tool,
GimpDisplay *display);
static gboolean gimp_foreground_select_tool_redo (GimpTool *tool,
GimpDisplay *display);
static void gimp_foreground_select_tool_options_notify (GimpTool *tool,
GimpToolOptions *options,
const GParamSpec *pspec);
static void gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool);
static void gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
GimpDisplay *display,
const GimpVector2 *points,
gint n_points);
static void gimp_foreground_select_tool_halt (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_commit (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_set_trimap (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_set_preview (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_preview (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_stroke_paint (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_cancel_paint (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_response (GimpToolGui *gui,
gint response_id,
GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_preview_toggled(GtkToggleButton *button,
GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_update_gui (GimpForegroundSelectTool *fg_select);
static StrokeUndo * gimp_foreground_select_undo_new (GeglBuffer *trimap,
GArray *stroke,
GimpMattingDrawMode draw_mode,
gint stroke_width);
static void gimp_foreground_select_undo_pop (StrokeUndo *undo,
GeglBuffer *trimap);
static void gimp_foreground_select_undo_free (StrokeUndo *undo);
G_DEFINE_TYPE (GimpForegroundSelectTool, gimp_foreground_select_tool,
GIMP_TYPE_FREE_SELECT_TOOL)
#define parent_class gimp_foreground_select_tool_parent_class
void
gimp_foreground_select_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_FOREGROUND_SELECT_TOOL,
GIMP_TYPE_FOREGROUND_SELECT_OPTIONS,
gimp_foreground_select_options_gui,
GIMP_CONTEXT_PROP_MASK_FOREGROUND |
GIMP_CONTEXT_PROP_MASK_BACKGROUND,
"gimp-foreground-select-tool",
_("Foreground Select"),
_("Foreground Select Tool: Select a region containing foreground objects"),
N_("F_oreground Select"), NULL,
NULL, GIMP_HELP_TOOL_FOREGROUND_SELECT,
GIMP_ICON_TOOL_FOREGROUND_SELECT,
data);
}
static void
gimp_foreground_select_tool_class_init (GimpForegroundSelectToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GimpFreeSelectToolClass *free_select_tool_class;
free_select_tool_class = GIMP_FREE_SELECT_TOOL_CLASS (klass);
object_class->finalize = gimp_foreground_select_tool_finalize;
tool_class->initialize = gimp_foreground_select_tool_initialize;
tool_class->control = gimp_foreground_select_tool_control;
tool_class->button_press = gimp_foreground_select_tool_button_press;
tool_class->button_release = gimp_foreground_select_tool_button_release;
tool_class->motion = gimp_foreground_select_tool_motion;
tool_class->key_press = gimp_foreground_select_tool_key_press;
tool_class->modifier_key = gimp_foreground_select_tool_modifier_key;
tool_class->active_modifier_key = gimp_foreground_select_tool_active_modifier_key;
tool_class->oper_update = gimp_foreground_select_tool_oper_update;
tool_class->cursor_update = gimp_foreground_select_tool_cursor_update;
tool_class->can_undo = gimp_foreground_select_tool_can_undo;
tool_class->can_redo = gimp_foreground_select_tool_can_redo;
tool_class->undo = gimp_foreground_select_tool_undo;
tool_class->redo = gimp_foreground_select_tool_redo;
tool_class->options_notify = gimp_foreground_select_tool_options_notify;
draw_tool_class->draw = gimp_foreground_select_tool_draw;
free_select_tool_class->select = gimp_foreground_select_tool_select;
}
static void
gimp_foreground_select_tool_init (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_scroll_lock (tool->control, FALSE);
gimp_tool_control_set_preserve (tool->control, FALSE);
gimp_tool_control_set_dirty_mask (tool->control,
GIMP_DIRTY_IMAGE_SIZE |
GIMP_DIRTY_ACTIVE_DRAWABLE);
gimp_tool_control_set_precision (tool->control,
GIMP_CURSOR_PRECISION_PIXEL_CENTER);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_action_size (tool->control,
"tools/tools-foreground-select-brush-size-set");
fg_select->state = MATTING_STATE_FREE_SELECT;
}
static void
gimp_foreground_select_tool_finalize (GObject *object)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (object);
g_clear_object (&fg_select->gui);
fg_select->preview_toggle = NULL;
if (fg_select->stroke)
g_warning ("%s: stroke should be NULL at this point", G_STRLOC);
if (fg_select->mask)
g_warning ("%s: mask should be NULL at this point", G_STRLOC);
if (fg_select->trimap)
g_warning ("%s: mask should be NULL at this point", G_STRLOC);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gimp_foreground_select_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpDisplayShell *shell = gimp_display_get_shell (display);
if (! drawable)
return FALSE;
if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer is not visible."));
return FALSE;
}
tool->display = display;
/* enable double click for the FreeSelectTool, because it may have been
* disabled if the tool has switched to MATTING_STATE_PAINT_TRIMAP,
* in gimp_foreground_select_tool_set_trimap().
*/
gimp_tool_control_set_wants_double_click (tool->control, TRUE);
fg_select->state = MATTING_STATE_FREE_SELECT;
if (! fg_select->gui)
{
fg_select->gui =
gimp_tool_gui_new (tool->tool_info,
NULL,
_("Dialog for foreground select"),
NULL, NULL,
gtk_widget_get_screen (GTK_WIDGET (shell)),
gimp_widget_get_monitor (GTK_WIDGET (shell)),
TRUE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Select"), GTK_RESPONSE_APPLY,
NULL);
gimp_tool_gui_set_auto_overlay (fg_select->gui, TRUE);
g_signal_connect (fg_select->gui, "response",
G_CALLBACK (gimp_foreground_select_tool_response),
fg_select);
fg_select->preview_toggle =
gtk_check_button_new_with_mnemonic (_("_Preview mask"));
gtk_box_pack_start (GTK_BOX (gimp_tool_gui_get_vbox (fg_select->gui)),
fg_select->preview_toggle, FALSE, FALSE, 0);
gtk_widget_show (fg_select->preview_toggle);
g_signal_connect (fg_select->preview_toggle, "toggled",
G_CALLBACK (gimp_foreground_select_tool_preview_toggled),
fg_select);
}
gimp_tool_gui_set_description (fg_select->gui,
_("Select foreground pixels"));
gimp_tool_gui_set_response_sensitive (fg_select->gui, GTK_RESPONSE_APPLY,
FALSE);
gtk_widget_set_sensitive (fg_select->preview_toggle, FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fg_select->preview_toggle),
FALSE);
gimp_tool_gui_set_shell (fg_select->gui, shell);
gimp_tool_gui_set_viewable (fg_select->gui, GIMP_VIEWABLE (drawable));
gimp_tool_gui_show (fg_select->gui);
return TRUE;
}
static void
gimp_foreground_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
switch (action)
{
case GIMP_TOOL_ACTION_PAUSE:
case GIMP_TOOL_ACTION_RESUME:
break;
case GIMP_TOOL_ACTION_HALT:
gimp_foreground_select_tool_halt (fg_select);
break;
case GIMP_TOOL_ACTION_COMMIT:
gimp_foreground_select_tool_commit (fg_select);
break;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
static void
gimp_foreground_select_tool_button_press (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpButtonPressType press_type,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
press_type, display);
}
else
{
GimpVector2 point = gimp_vector2_new (coords->x, coords->y);
gimp_draw_tool_pause (draw_tool);
if (gimp_draw_tool_is_active (draw_tool) && draw_tool->display != display)
gimp_draw_tool_stop (draw_tool);
gimp_tool_control_activate (tool->control);
fg_select->last_coords = *coords;
g_return_if_fail (fg_select->stroke == NULL);
fg_select->stroke = g_array_new (FALSE, FALSE, sizeof (GimpVector2));
g_array_append_val (fg_select->stroke, point);
if (! gimp_draw_tool_is_active (draw_tool))
gimp_draw_tool_start (draw_tool, display);
gimp_draw_tool_resume (draw_tool);
}
}
static void
gimp_foreground_select_tool_button_release (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpButtonReleaseType release_type,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
release_type, display);
/* see comment in gimp_foreground_select_tool_select() */
if (fg_select->in_double_click)
{
gimp_foreground_select_tool_set_trimap (fg_select);
fg_select->in_double_click = FALSE;
}
}
else
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
gimp_tool_control_halt (tool->control);
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
{
gimp_foreground_select_tool_cancel_paint (fg_select);
}
else
{
gimp_foreground_select_tool_stroke_paint (fg_select);
if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
gimp_foreground_select_tool_preview (fg_select);
else
gimp_foreground_select_tool_set_trimap (fg_select);
}
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
}
static void
gimp_foreground_select_tool_motion (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state,
display);
}
else
{
GimpVector2 *last = &g_array_index (fg_select->stroke,
GimpVector2,
fg_select->stroke->len - 1);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
fg_select->last_coords = *coords;
if (last->x != (gint) coords->x || last->y != (gint) coords->y)
{
GimpVector2 point = gimp_vector2_new (coords->x, coords->y);
g_array_append_val (fg_select->stroke, point);
}
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
}
static gboolean
gimp_foreground_select_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
return GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
}
else
{
if (display != tool->display)
return FALSE;
switch (kevent->keyval)
{
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
case GDK_KEY_ISO_Enter:
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fg_select->preview_toggle),
TRUE);
else
gimp_foreground_select_tool_response (fg_select->gui,
GTK_RESPONSE_APPLY, fg_select);
return TRUE;
case GDK_KEY_Escape:
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
gimp_foreground_select_tool_response (fg_select->gui,
GTK_RESPONSE_CANCEL, fg_select);
else
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fg_select->preview_toggle),
FALSE);
return TRUE;
default:
return FALSE;
}
}
}
static void
gimp_foreground_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
display);
}
else
{
#if 0
if (key == gimp_get_toggle_behavior_mask ())
{
GimpForegroundSelectOptions *options;
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
g_object_set (options,
"background", ! options->background,
NULL);
}
#endif
}
}
static void
gimp_foreground_select_tool_active_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_TOOL_CLASS (parent_class)->active_modifier_key (tool, key, press,
state, display);
}
}
static void
gimp_foreground_select_tool_oper_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
GimpForegroundSelectOptions *options;
const gchar *status_stage = NULL;
const gchar *status_mode = NULL;
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (fg_select);
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
display);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
if (GIMP_SELECTION_TOOL (tool)->function == SELECTION_SELECT)
{
if (gimp_free_select_tool_get_n_points (GIMP_FREE_SELECT_TOOL (tool)) > 2)
{
status_mode = _("Roughly outline the object to extract");
status_stage = _("press Enter to refine.");
}
else
{
status_stage = _("Roughly outline the object to extract");
}
}
}
else
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
gimp_draw_tool_pause (draw_tool);
if (proximity)
{
fg_select->last_coords = *coords;
}
else
{
fg_select->last_coords.x = FAR_OUTSIDE;
fg_select->last_coords.y = FAR_OUTSIDE;
}
gimp_draw_tool_resume (draw_tool);
if (options->draw_mode == GIMP_MATTING_DRAW_MODE_FOREGROUND)
status_mode = _("Selecting foreground");
else if (options->draw_mode == GIMP_MATTING_DRAW_MODE_BACKGROUND)
status_mode = _("Selecting background");
else
status_mode = _("Selecting unknown");
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
status_stage = _("press Enter to preview.");
else
status_stage = _("press Escape to exit preview or Enter to apply.");
}
if (proximity && status_stage)
{
if (status_mode)
gimp_tool_replace_status (tool, display, "%s, %s", status_mode, status_stage);
else
gimp_tool_replace_status (tool, display, "%s", status_stage);
}
}
static void
gimp_foreground_select_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
{
switch (GIMP_SELECTION_TOOL (tool)->function)
{
case SELECTION_MOVE_MASK:
case SELECTION_MOVE:
case SELECTION_MOVE_COPY:
case SELECTION_ANCHOR:
return;
default:
break;
}
}
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
static const gchar *
gimp_foreground_select_tool_can_undo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->undo_stack)
{
StrokeUndo *undo = fg_select->undo_stack->data;
const gchar *desc;
if (gimp_enum_get_value (GIMP_TYPE_MATTING_DRAW_MODE, undo->draw_mode,
NULL, NULL, &desc, NULL))
{
return desc;
}
}
return NULL;
}
static const gchar *
gimp_foreground_select_tool_can_redo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
if (fg_select->redo_stack)
{
StrokeUndo *undo = fg_select->redo_stack->data;
const gchar *desc;
if (gimp_enum_get_value (GIMP_TYPE_MATTING_DRAW_MODE, undo->draw_mode,
NULL, NULL, &desc, NULL))
{
return desc;
}
}
return NULL;
}
static gboolean
gimp_foreground_select_tool_undo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
StrokeUndo *undo = fg_select->undo_stack->data;
gimp_foreground_select_undo_pop (undo, fg_select->trimap);
fg_select->undo_stack = g_list_remove (fg_select->undo_stack, undo);
fg_select->redo_stack = g_list_prepend (fg_select->redo_stack, undo);
if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
gimp_foreground_select_tool_preview (fg_select);
else
gimp_foreground_select_tool_set_trimap (fg_select);
return TRUE;
}
static gboolean
gimp_foreground_select_tool_redo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
StrokeUndo *undo = fg_select->redo_stack->data;
gimp_foreground_select_undo_pop (undo, fg_select->trimap);
fg_select->redo_stack = g_list_remove (fg_select->redo_stack, undo);
fg_select->undo_stack = g_list_prepend (fg_select->undo_stack, undo);
if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
gimp_foreground_select_tool_preview (fg_select);
else
gimp_foreground_select_tool_set_trimap (fg_select);
return TRUE;
}
static void
gimp_foreground_select_tool_options_notify (GimpTool *tool,
GimpToolOptions *options,
const GParamSpec *pspec)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
GimpForegroundSelectOptions *fg_options;
fg_options = GIMP_FOREGROUND_SELECT_OPTIONS (options);
if (! tool->display)
return;
if (! strcmp (pspec->name, "mask-color"))
{
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
{
gimp_foreground_select_tool_set_trimap (fg_select);
}
else if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
{
gimp_foreground_select_tool_set_preview (fg_select);
}
}
else if (! strcmp (pspec->name, "engine"))
{
if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
{
gimp_foreground_select_tool_preview (fg_select);
}
}
else if (! strcmp (pspec->name, "iterations"))
{
if (fg_options->engine == GIMP_MATTING_ENGINE_GLOBAL &&
fg_select->state == MATTING_STATE_PREVIEW_MASK)
{
gimp_foreground_select_tool_preview (fg_select);
}
}
else if (! strcmp (pspec->name, "levels") ||
! strcmp (pspec->name, "active-levels"))
{
if (fg_options->engine == GIMP_MATTING_ENGINE_LEVIN &&
fg_select->state == MATTING_STATE_PREVIEW_MASK)
{
gimp_foreground_select_tool_preview (fg_select);
}
}
}
static void
gimp_foreground_select_tool_get_area (GeglBuffer *mask,
gint *x1,
gint *y1,
gint *x2,
gint *y2)
{
gint width;
gint height;
gimp_gegl_mask_bounds (mask, x1, y1, x2, y2);
width = *x2 - *x1;
height = *y2 - *y1;
*x1 = MAX (*x1 - width / 2, 0);
*y1 = MAX (*y1 - height / 2, 0);
*x2 = MIN (*x2 + width / 2, gimp_item_get_width (GIMP_ITEM (mask)));
*y2 = MIN (*y2 + height / 2, gimp_item_get_height (GIMP_ITEM (mask)));
}
static void
gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
{
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
GimpForegroundSelectOptions *options;
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
if (fg_select->state == MATTING_STATE_FREE_SELECT)
{
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
return;
}
else
{
gint x = fg_select->last_coords.x;
gint y = fg_select->last_coords.y;
gdouble radius = options->stroke_width / 2.0f;
if (fg_select->stroke)
{
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
gimp_draw_tool_add_pen (draw_tool,
(const GimpVector2 *) fg_select->stroke->data,
fg_select->stroke->len,
GIMP_CONTEXT (options),
GIMP_ACTIVE_COLOR_FOREGROUND,
options->stroke_width * shell->scale_y);
}
/* warn if the user is drawing outside of the working area */
if (FALSE)
{
gint x1, y1;
gint x2, y2;
gimp_foreground_select_tool_get_area (fg_select->mask,
&x1, &y1, &x2, &y2);
if (x < x1 + radius || x > x2 - radius ||
y < y1 + radius || y > y2 - radius)
{
gimp_draw_tool_add_rectangle (draw_tool, FALSE,
x1, y1,
x2 - x1, y2 - y1);
}
}
if (x > FAR_OUTSIDE && y > FAR_OUTSIDE)
gimp_draw_tool_add_arc (draw_tool, FALSE,
x - radius, y - radius,
2 * radius, 2 * radius,
0.0, 2.0 * G_PI);
}
}
static void
gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
GimpDisplay *display,
const GimpVector2 *points,
gint n_points)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (free_sel);
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (drawable && fg_select->state == MATTING_STATE_FREE_SELECT)
{
GimpScanConvert *scan_convert = gimp_scan_convert_new ();
gimp_scan_convert_add_polyline (scan_convert, n_points, points, TRUE);
fg_select->trimap =
gegl_buffer_new (GEGL_RECTANGLE (0, 0,
gimp_image_get_width (image),
gimp_image_get_height (image)),
gimp_image_get_mask_format (image));
gimp_scan_convert_render_value (scan_convert, fg_select->trimap,
0, 0, 0.5);
gimp_scan_convert_free (scan_convert);
if (! gimp_tool_control_is_active (GIMP_TOOL (fg_select)->control))
{
gimp_foreground_select_tool_set_trimap (fg_select);
}
else
{
/* if the tool is active we got here by double click
* detected in the parent class. We can't switch to trimap
* mode in the middle of a click. Set a flag and let
* button_release() forward the release to the parent class
* so it can conclude its operation
*/
fg_select->in_double_click = TRUE;
}
}
}
static void
gimp_foreground_select_tool_halt (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
g_clear_object (&fg_select->trimap);
g_clear_object (&fg_select->mask);
if (fg_select->undo_stack)
{
g_list_free_full (fg_select->undo_stack,
(GDestroyNotify) gimp_foreground_select_undo_free);
fg_select->undo_stack = NULL;
}
if (fg_select->redo_stack)
{
g_list_free_full (fg_select->redo_stack,
(GDestroyNotify) gimp_foreground_select_undo_free);
fg_select->redo_stack = NULL;
}
if (tool->display)
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
NULL, 0, 0, NULL, FALSE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
gimp_tool_control_set_toggled (tool->control, FALSE);
fg_select->state = MATTING_STATE_FREE_SELECT;
/* update the undo actions / menu items */
if (tool->display)
gimp_image_flush (gimp_display_get_image (tool->display));
tool->display = NULL;
tool->drawable = NULL;
if (fg_select->gui)
gimp_tool_gui_hide (fg_select->gui);
}
static void
gimp_foreground_select_tool_commit (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (fg_select);
if (tool->display && fg_select->state != MATTING_STATE_FREE_SELECT)
{
GimpImage *image = gimp_display_get_image (tool->display);
if (fg_select->state != MATTING_STATE_PREVIEW_MASK)
gimp_foreground_select_tool_preview (fg_select);
gimp_channel_select_buffer (gimp_image_get_mask (image),
C_("command", "Foreground Select"),
fg_select->mask,
0, /* x offset */
0, /* y offset */
options->operation,
options->feather,
options->feather_radius,
options->feather_radius);
gimp_image_flush (image);
}
}
static void
gimp_foreground_select_tool_set_trimap (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
GimpForegroundSelectOptions *options;
GimpRGB color;
g_return_if_fail (fg_select->trimap != NULL);
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
gimp_free_select_tool_halt (GIMP_FREE_SELECT_TOOL (fg_select));
gimp_foreground_select_options_get_mask_color (options, &color);
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
fg_select->trimap, 0, 0, &color, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
gimp_tool_control_set_toggled (tool->control, FALSE);
/* disable double click in paint trimap state */
gimp_tool_control_set_wants_double_click (tool->control, FALSE);
fg_select->state = MATTING_STATE_PAINT_TRIMAP;
gimp_foreground_select_tool_update_gui (fg_select);
}
static void
gimp_foreground_select_tool_set_preview (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
GimpForegroundSelectOptions *options;
GimpRGB color;
g_return_if_fail (fg_select->mask != NULL);
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
gimp_foreground_select_options_get_mask_color (options, &color);
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
fg_select->mask, 0, 0, &color, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
gimp_tool_control_set_toggle_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
gimp_tool_control_set_toggled (tool->control, FALSE);
fg_select->state = MATTING_STATE_PREVIEW_MASK;
gimp_foreground_select_tool_update_gui (fg_select);
}
static void
gimp_foreground_select_tool_preview (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
GimpForegroundSelectOptions *options;
GimpImage *image = gimp_display_get_image (tool->display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
g_clear_object (&fg_select->mask);
fg_select->mask = gimp_drawable_foreground_extract (drawable,
options->engine,
options->iterations,
options->levels,
options->active_levels,
fg_select->trimap,
GIMP_PROGRESS (fg_select));
gimp_foreground_select_tool_set_preview (fg_select);
}
static void
gimp_foreground_select_tool_stroke_paint (GimpForegroundSelectTool *fg_select)
{
GimpForegroundSelectOptions *options;
GimpScanConvert *scan_convert;
StrokeUndo *undo;
gint width;
gdouble opacity;
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (fg_select);
g_return_if_fail (fg_select->stroke != NULL);
width = ROUND ((gdouble) options->stroke_width);
if (fg_select->redo_stack)
{
g_list_free_full (fg_select->redo_stack,
(GDestroyNotify) gimp_foreground_select_undo_free);
fg_select->redo_stack = NULL;
}
undo = gimp_foreground_select_undo_new (fg_select->trimap,
fg_select->stroke,
options->draw_mode, width);
if (! undo)
{
g_array_free (fg_select->stroke, TRUE);
fg_select->stroke = NULL;
return;
}
fg_select->undo_stack = g_list_prepend (fg_select->undo_stack, undo);
scan_convert = gimp_scan_convert_new ();
if (fg_select->stroke->len == 1)
{
GimpVector2 points[2];
points[0] = points[1] = ((GimpVector2 *) fg_select->stroke->data)[0];
points[1].x += 0.01;
points[1].y += 0.01;
gimp_scan_convert_add_polyline (scan_convert, 2, points, FALSE);
}
else
{
gimp_scan_convert_add_polyline (scan_convert,
fg_select->stroke->len,
(GimpVector2 *) fg_select->stroke->data,
FALSE);
}
gimp_scan_convert_stroke (scan_convert,
width,
GIMP_JOIN_ROUND, GIMP_CAP_ROUND, 10.0,
0.0, NULL);
if (options->draw_mode == GIMP_MATTING_DRAW_MODE_FOREGROUND)
opacity = 1.0;
else if (options->draw_mode == GIMP_MATTING_DRAW_MODE_BACKGROUND)
opacity = 0.0;
else
opacity = 0.5;
gimp_scan_convert_compose_value (scan_convert, fg_select->trimap,
0, 0,
opacity);
gimp_scan_convert_free (scan_convert);
g_array_free (fg_select->stroke, TRUE);
fg_select->stroke = NULL;
/* update the undo actions / menu items */
gimp_image_flush (gimp_display_get_image (GIMP_TOOL (fg_select)->display));
}
static void
gimp_foreground_select_tool_cancel_paint (GimpForegroundSelectTool *fg_select)
{
g_return_if_fail (fg_select->stroke != NULL);
g_array_free (fg_select->stroke, TRUE);
fg_select->stroke = NULL;
}
static void
gimp_foreground_select_tool_response (GimpToolGui *gui,
gint response_id,
GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
switch (response_id)
{
case GTK_RESPONSE_APPLY:
gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, tool->display);
break;
default:
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
break;
}
}
static void
gimp_foreground_select_tool_preview_toggled (GtkToggleButton *button,
GimpForegroundSelectTool *fg_select)
{
if (fg_select->state != MATTING_STATE_FREE_SELECT)
{
if (gtk_toggle_button_get_active (button))
{
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
gimp_foreground_select_tool_preview (fg_select);
}
else
{
if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
gimp_foreground_select_tool_set_trimap (fg_select);
}
}
}
static void
gimp_foreground_select_tool_update_gui (GimpForegroundSelectTool *fg_select)
{
if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
{
gimp_tool_gui_set_description (fg_select->gui, _("Paint mask"));
}
else if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
{
gimp_tool_gui_set_description (fg_select->gui, _("Preview"));
}
gimp_tool_gui_set_response_sensitive (fg_select->gui, GTK_RESPONSE_APPLY,
TRUE);
gtk_widget_set_sensitive (fg_select->preview_toggle, TRUE);
}
static StrokeUndo *
gimp_foreground_select_undo_new (GeglBuffer *trimap,
GArray *stroke,
GimpMattingDrawMode draw_mode,
gint stroke_width)
{
StrokeUndo *undo;
gint x1, y1, x2, y2;
gint width, height;
gint i;
x1 = G_MAXINT;
y1 = G_MAXINT;
x2 = G_MININT;
y2 = G_MININT;
for (i = 0; i < stroke->len; i++)
{
GimpVector2 *point = &g_array_index (stroke, GimpVector2, i);
x1 = MIN (x1, floor (point->x));
y1 = MIN (y1, floor (point->y));
x2 = MAX (x2, ceil (point->x));
y2 = MAX (y2, ceil (point->y));
}
x1 -= (stroke_width + 1) / 2;
y1 -= (stroke_width + 1) / 2;
x2 += (stroke_width + 1) / 2;
y2 += (stroke_width + 1) / 2;
x1 = MAX (x1, 0);
y1 = MAX (y1, 0);
x2 = MIN (x2, gegl_buffer_get_width (trimap));
y2 = MIN (y2, gegl_buffer_get_height (trimap));
width = x2 - x1;
height = y2 - y1;
if (width <= 0 || height <= 0)
return NULL;
undo = g_slice_new0 (StrokeUndo);
undo->saved_trimap = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
gegl_buffer_get_format (trimap));
gimp_gegl_buffer_copy (
trimap, GEGL_RECTANGLE (x1, y1, width, height),
GEGL_ABYSS_NONE,
undo->saved_trimap, GEGL_RECTANGLE (0, 0, width, height));
undo->trimap_x = x1;
undo->trimap_y = y1;
undo->draw_mode = draw_mode;
undo->stroke_width = stroke_width;
return undo;
}
static void
gimp_foreground_select_undo_pop (StrokeUndo *undo,
GeglBuffer *trimap)
{
GeglBuffer *buffer;
gint width, height;
buffer = gegl_buffer_dup (undo->saved_trimap);
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
gimp_gegl_buffer_copy (trimap,
GEGL_RECTANGLE (undo->trimap_x, undo->trimap_y,
width, height),
GEGL_ABYSS_NONE,
undo->saved_trimap,
GEGL_RECTANGLE (0, 0, width, height));
gimp_gegl_buffer_copy (buffer,
GEGL_RECTANGLE (0, 0, width, height),
GEGL_ABYSS_NONE,
trimap,
GEGL_RECTANGLE (undo->trimap_x, undo->trimap_y,
width, height));
g_object_unref (buffer);
}
static void
gimp_foreground_select_undo_free (StrokeUndo *undo)
{
g_clear_object (&undo->saved_trimap);
g_slice_free (StrokeUndo, undo);
}
|