gimpdrawable-operation.c 3.46 KB
Newer Older
1 2 3 4 5 6 7 8
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpdrawable-operation.c
 * Copyright (C) 2007 Øyvind Kolås <pippin@gimp.org>
 *                    Sven Neumann <sven@gimp.org>
 *                    Michael Natterer <mitch@gimp.org>
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12 13 14 15 16 17 18 19
 * (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
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 22 23 24
 */

#include "config.h"

25
#include <gdk-pixbuf/gdk-pixbuf.h>
26 27 28 29
#include <gegl.h>

#include "core-types.h"

30 31
#include "gegl/gimp-gegl-apply-operation.h"

32 33
#include "gimpdrawable.h"
#include "gimpdrawable-operation.h"
34
#include "gimpdrawable-shadow.h"
35
#include "gimpprogress.h"
36
#include "gimpsettings.h"
37

38

39 40
/*  public functions  */

41 42 43
void
gimp_drawable_apply_operation (GimpDrawable *drawable,
                               GimpProgress *progress,
44
                               const gchar  *undo_desc,
45
                               GeglNode     *operation)
46
{
47 48
  GeglBuffer    *dest_buffer;
  GeglRectangle  rect;
49 50 51 52 53

  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
  g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
  g_return_if_fail (undo_desc != NULL);
54
  g_return_if_fail (GEGL_IS_NODE (operation));
55

56 57 58
  if (! gimp_item_mask_intersect (GIMP_ITEM (drawable),
                                  &rect.x,     &rect.y,
                                  &rect.width, &rect.height))
59 60
    return;

61
  dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
62

63 64 65
  gimp_gegl_apply_operation (gimp_drawable_get_buffer (drawable),
                             progress, undo_desc,
                             operation,
66
                             dest_buffer, &rect, FALSE);
67

68 69
  gimp_drawable_merge_shadow_buffer (drawable, TRUE, undo_desc);
  gimp_drawable_free_shadow_buffer (drawable);
70 71 72 73 74 75 76

  gimp_drawable_update (drawable, rect.x, rect.y, rect.width, rect.height);

  if (progress)
    gimp_progress_end (progress);
}

77
void
78 79 80 81
gimp_drawable_apply_operation_by_name (GimpDrawable *drawable,
                                       GimpProgress *progress,
                                       const gchar  *undo_desc,
                                       const gchar  *operation_type,
82
                                       GObject      *config)
83 84 85 86 87 88 89 90
{
  GeglNode *node;

  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
  g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
  g_return_if_fail (undo_desc != NULL);
  g_return_if_fail (operation_type != NULL);
91
  g_return_if_fail (config == NULL || GIMP_IS_SETTINGS (config));
92 93 94 95 96

  node = g_object_new (GEGL_TYPE_NODE,
                       "operation", operation_type,
                       NULL);

97 98 99 100
  if (config)
    gegl_node_set (node,
                   "config", config,
                   NULL);
101

102
  gimp_drawable_apply_operation (drawable, progress, undo_desc, node);
103 104 105

  g_object_unref (node);
}