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
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gegl.h>
#include "core-types.h"
#include "base/pixel-region.h"
#include "base/tile-manager.h"
#include "paint-funcs/paint-funcs.h"
#include "gimpchannel.h"
#include "gimpdrawable-combine.h"
#include "gimpdrawableundo.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
void
gimp_drawable_real_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
GimpLayerModeEffects mode,
TileManager *src1_tiles,
PixelRegion *destPR,
gint x,
gint y)
{
GimpItem *item = GIMP_ITEM (drawable);
GimpImage *image = gimp_item_get_image (item);
GimpChannel *mask = gimp_image_get_mask (image);
gint x1, y1, x2, y2;
gint offset_x, offset_y;
PixelRegion src1PR, my_destPR;
CombinationMode operation;
gboolean active_components[MAX_CHANNELS];
/* don't apply the mask to itself and don't apply an empty mask */
if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
mask = NULL;
/* configure the active channel array */
gimp_drawable_get_active_components (drawable, active_components);
/* determine what sort of operation is being attempted and
* if it's actually legal...
*/
operation = gimp_image_get_combination_mode (gimp_drawable_type (drawable),
src2PR->bytes);
if (operation == -1)
{
g_warning ("%s: illegal parameters.", G_STRFUNC);
return;
}
/* get the layer offsets */
gimp_item_get_offset (item, &offset_x, &offset_y);
/* make sure the image application coordinates are within drawable bounds */
x1 = CLAMP (x, 0, gimp_item_get_width (item));
y1 = CLAMP (y, 0, gimp_item_get_height (item));
x2 = CLAMP (x + src2PR->w, 0, gimp_item_get_width (item));
y2 = CLAMP (y + src2PR->h, 0, gimp_item_get_height (item));
if (mask)
{
GimpItem *mask_item = GIMP_ITEM (mask);
/* make sure coordinates are in mask bounds ...
* we need to add the layer offset to transform coords
* into the mask coordinate system
*/
x1 = CLAMP (x1, -offset_x, gimp_item_get_width (mask_item) - offset_x);
y1 = CLAMP (y1, -offset_y, gimp_item_get_height (mask_item) - offset_y);
x2 = CLAMP (x2, -offset_x, gimp_item_get_width (mask_item) - offset_x);
y2 = CLAMP (y2, -offset_y, gimp_item_get_height (mask_item) - offset_y);
}
/* If the calling procedure specified an undo step... */
if (push_undo)
{
GimpDrawableUndo *undo;
gimp_drawable_push_undo (drawable, undo_desc,
x1, y1,
x2 - x1, y2 - y1,
NULL, FALSE);
undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
if (undo)
{
PixelRegion tmp_srcPR;
PixelRegion tmp_destPR;
undo->paint_mode = mode;
undo->opacity = opacity;
undo->src2_tiles = tile_manager_new (x2 - x1, y2 - y1,
src2PR->bytes);
tmp_srcPR = *src2PR;
pixel_region_resize (&tmp_srcPR,
src2PR->x + (x1 - x), src2PR->y + (y1 - y),
x2 - x1, y2 - y1);
pixel_region_init (&tmp_destPR, undo->src2_tiles,
0, 0,
x2 - x1, y2 - y1, TRUE);
copy_region (&tmp_srcPR, &tmp_destPR);
}
}
/* configure the pixel regions */
/* check if an alternative to using the drawable's data as src1 was
* provided...
*/
if (src1_tiles)
{
pixel_region_init (&src1PR, src1_tiles,
x1, y1, x2 - x1, y2 - y1,
FALSE);
}
else
{
pixel_region_init (&src1PR, gimp_drawable_get_tiles (drawable),
x1, y1, x2 - x1, y2 - y1,
FALSE);
}
/* check if an alternative to using the drawable's data as dest was
* provided...
*/
if (!destPR)
{
pixel_region_init (&my_destPR, gimp_drawable_get_tiles (drawable),
x1, y1, x2 - x1, y2 - y1,
TRUE);
destPR = &my_destPR;
}
pixel_region_resize (src2PR,
src2PR->x + (x1 - x), src2PR->y + (y1 - y),
x2 - x1, y2 - y1);
if (mask)
{
PixelRegion maskPR;
pixel_region_init (&maskPR,
gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
x1 + offset_x,
y1 + offset_y,
x2 - x1, y2 - y1,
FALSE);
combine_regions (&src1PR, src2PR, destPR, &maskPR, NULL,
opacity * 255.999,
mode,
active_components,
operation);
}
else
{
combine_regions (&src1PR, src2PR, destPR, NULL, NULL,
opacity * 255.999,
mode,
active_components,
operation);
}
}
/* Similar to gimp_drawable_apply_region but works in "replace" mode (i.e.
* transparent pixels in src2 make the result transparent rather than
* opaque.
*
* Takes an additional mask pixel region as well.
*/
void
gimp_drawable_real_replace_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
PixelRegion *maskPR,
gint x,
gint y)
{
GimpItem *item = GIMP_ITEM (drawable);
GimpImage *image = gimp_item_get_image (item);
GimpChannel *mask = gimp_image_get_mask (image);
gint x1, y1, x2, y2;
gint offset_x, offset_y;
PixelRegion src1PR, destPR;
CombinationMode operation;
gboolean active_components[MAX_CHANNELS];
/* don't apply the mask to itself and don't apply an empty mask */
if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
mask = NULL;
/* configure the active channel array */
gimp_drawable_get_active_components (drawable, active_components);
/* determine what sort of operation is being attempted and
* if it's actually legal...
*/
operation = gimp_image_get_combination_mode (gimp_drawable_type (drawable),
src2PR->bytes);
if (operation == -1)
{
g_warning ("%s: illegal parameters.", G_STRFUNC);
return;
}
/* get the layer offsets */
gimp_item_get_offset (item, &offset_x, &offset_y);
/* make sure the image application coordinates are within drawable bounds */
x1 = CLAMP (x, 0, gimp_item_get_width (item));
y1 = CLAMP (y, 0, gimp_item_get_height (item));
x2 = CLAMP (x + src2PR->w, 0, gimp_item_get_width (item));
y2 = CLAMP (y + src2PR->h, 0, gimp_item_get_height (item));
if (mask)
{
GimpItem *mask_item = GIMP_ITEM (mask);
/* make sure coordinates are in mask bounds ...
* we need to add the layer offset to transform coords
* into the mask coordinate system
*/
x1 = CLAMP (x1, -offset_x, gimp_item_get_width (mask_item) - offset_x);
y1 = CLAMP (y1, -offset_y, gimp_item_get_height (mask_item) - offset_y);
x2 = CLAMP (x2, -offset_x, gimp_item_get_width (mask_item) - offset_x);
y2 = CLAMP (y2, -offset_y, gimp_item_get_height (mask_item) - offset_y);
}
/* If the calling procedure specified an undo step... */
if (push_undo)
gimp_drawable_push_undo (drawable, undo_desc,
x1, y1,
x2 - x1, y2 - y1,
NULL, FALSE);
/* configure the pixel regions */
pixel_region_init (&src1PR, gimp_drawable_get_tiles (drawable),
x1, y1, x2 - x1, y2 - y1,
FALSE);
pixel_region_init (&destPR, gimp_drawable_get_tiles (drawable),
x1, y1, x2 - x1, y2 - y1,
TRUE);
pixel_region_resize (src2PR,
src2PR->x + (x1 - x), src2PR->y + (y1 - y),
x2 - x1, y2 - y1);
if (mask)
{
PixelRegion mask2PR, tempPR;
guchar *temp_data;
pixel_region_init (&mask2PR,
gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
x1 + offset_x,
y1 + offset_y,
x2 - x1, y2 - y1,
FALSE);
temp_data = g_malloc ((y2 - y1) * (x2 - x1));
pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
0, 0, x2 - x1, y2 - y1);
copy_region (&mask2PR, &tempPR);
pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
0, 0, x2 - x1, y2 - y1);
apply_mask_to_region (&tempPR, maskPR, OPAQUE_OPACITY);
pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
0, 0, x2 - x1, y2 - y1);
combine_regions_replace (&src1PR, src2PR, &destPR, &tempPR, NULL,
opacity * 255.999,
active_components,
operation);
g_free (temp_data);
}
else
{
combine_regions_replace (&src1PR, src2PR, &destPR, maskPR, NULL,
opacity * 255.999,
active_components,
operation);
}
}
|