Commit 149e81da authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/core/Makefile.am new file for utility functions. Contains

2003-05-14  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/gimp-utils.[ch]: new file for utility functions.
	Contains gimp_rectangle_intersect() for now.

	* app/core/gimpdrawable-transform.c: removed the function here.

	* app/core/gimpdrawable.c (gimp_drawable_resize): use it to
	determine the amount of pixels to copy between the old and new
	tile managers. Removed restriction that forced the areas to
	overlap by at least one pixel.

	* app/core/gimpitem.c (gimp_item_real_transform): removed the
	restriction here, too.

	* app/core/gimplayer.c (gimp_layer_create_mask): use the new
	function to decide how much to copy from the selection when
	creating a mask from it.
parent 5f42f8da
2003-05-14 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/gimp-utils.[ch]: new file for utility functions.
Contains gimp_rectangle_intersect() for now.
* app/core/gimpdrawable-transform.c: removed the function here.
* app/core/gimpdrawable.c (gimp_drawable_resize): use it to
determine the amount of pixels to copy between the old and new
tile managers. Removed restriction that forced the areas to
overlap by at least one pixel.
* app/core/gimpitem.c (gimp_item_real_transform): removed the
restriction here, too.
* app/core/gimplayer.c (gimp_layer_create_mask): use the new
function to decide how much to copy from the selection when
creating a mask from it.
2003-05-14 Michael Natterer <mitch@gimp.org>
* app/core/gimpdrawable-transform.[ch]: changed the TileManager
......@@ -30,6 +30,8 @@ libappcore_a_sources = \
gimp-parasites.h \
gimp-templates.c \
gimp-templates.h \
gimp-utils.c \
gimp-utils.h \
gimpbrush.c \
gimpbrush.h \
gimpbrush-header.h \
......
......@@ -34,6 +34,7 @@
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpdrawable.h"
......@@ -425,36 +426,6 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
return new_tiles;
}
gboolean
gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height)
{
gint d_x, d_y;
gint d_w, d_h;
d_x = MAX (x1, x2);
d_y = MAX (y1, y2);
d_w = MIN (x1 + width1, x2 + width2) - d_x;
d_h = MIN (y1 + height1, y2 + height2) - d_y;
if (dest_x) *dest_x = d_x;
if (dest_y) *dest_y = d_y;
if (dest_width) *dest_width = d_w;
if (dest_height) *dest_height = d_h;
return (d_w > 0 && d_h > 0);
}
TileManager *
gimp_drawable_transform_tiles_flip (GimpDrawable *drawable,
TileManager *orig_tiles,
......
/* The GIMP -- an 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "core-types.h"
#include "gimp-utils.h"
gboolean
gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height)
{
gint d_x, d_y;
gint d_w, d_h;
d_x = MAX (x1, x2);
d_y = MAX (y1, y2);
d_w = MIN (x1 + width1, x2 + width2) - d_x;
d_h = MIN (y1 + height1, y2 + height2) - d_y;
if (dest_x) *dest_x = d_x;
if (dest_y) *dest_y = d_y;
if (dest_width) *dest_width = d_w;
if (dest_height) *dest_height = d_h;
return (d_w > 0 && d_h > 0);
}
/* The GIMP -- an 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __APP_GIMP_UTILS_H__
#define __APP_GIMP_UTILS_H__
gboolean gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height);
#endif /* __APP_GIMP_UTILS_H__ */
......@@ -34,6 +34,7 @@
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpdrawable.h"
......@@ -425,36 +426,6 @@ gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
return new_tiles;
}
gboolean
gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height)
{
gint d_x, d_y;
gint d_w, d_h;
d_x = MAX (x1, x2);
d_y = MAX (y1, y2);
d_w = MIN (x1 + width1, x2 + width2) - d_x;
d_h = MIN (y1 + height1, y2 + height2) - d_y;
if (dest_x) *dest_x = d_x;
if (dest_y) *dest_y = d_y;
if (dest_width) *dest_width = d_w;
if (dest_height) *dest_height = d_h;
return (d_w > 0 && d_h > 0);
}
TileManager *
gimp_drawable_transform_tiles_flip (GimpDrawable *drawable,
TileManager *orig_tiles,
......
......@@ -37,6 +37,7 @@
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpdrawable.h"
......@@ -369,89 +370,58 @@ gimp_drawable_resize (GimpItem *item,
GimpDrawable *drawable;
PixelRegion srcPR, destPR;
TileManager *new_tiles;
gint w, h;
gint x1, y1, x2, y2;
gint new_offset_x;
gint new_offset_y;
gint copy_x, copy_y;
gint copy_width, copy_height;
drawable = GIMP_DRAWABLE (item);
x1 = CLAMP (offset_x, 0, new_width);
y1 = CLAMP (offset_y, 0, new_height);
x2 = CLAMP (offset_x + item->width, 0, new_width);
y2 = CLAMP (offset_y + item->height, 0, new_height);
new_offset_x = item->offset_x - offset_x;
new_offset_y = item->offset_y - offset_y;
w = x2 - x1;
h = y2 - y1;
if (offset_x > 0)
{
x1 = 0;
x2 = offset_x;
}
else
{
x1 = -offset_x;
x2 = 0;
}
if (offset_y > 0)
{
y1 = 0;
y2 = offset_y;
}
else
{
y1 = -offset_y;
y2 = 0;
}
gimp_rectangle_intersect (item->offset_x, item->offset_y,
item->width, item->height,
new_offset_x, new_offset_y,
new_width, new_height,
&copy_x, &copy_y,
&copy_width, &copy_height);
/* Update the old position */
gimp_drawable_update (drawable, 0, 0, item->width, item->height);
/* Configure the pixel regions */
pixel_region_init (&srcPR, drawable->tiles,
x1, y1,
w, h,
FALSE);
/* Allocate the new tile manager, configure dest region */
new_tiles = tile_manager_new (new_width, new_height,
drawable->bytes);
/* Determine whether the new tiles need to be initially cleared */
if ((new_width > item->width) ||
(new_height > item->height) ||
(x2 || y2))
if (copy_width != new_width ||
copy_height != new_height)
{
guchar bg[MAX_CHANNELS] = { 0, };
pixel_region_init (&destPR, new_tiles,
0, 0,
new_width, new_height,
TRUE);
/* fill with the fill color */
if (gimp_drawable_has_alpha (drawable) ||
GIMP_IS_CHANNEL (drawable) /* EEK */)
{
/* Set to transparent and black */
guchar bg[4] = { 0, 0, 0, 0 };
if (! gimp_drawable_has_alpha (drawable) && ! GIMP_IS_CHANNEL (drawable))
gimp_image_get_background (gimp_item_get_image (item), drawable, bg);
color_region (&destPR, bg);
}
else
{
guchar bg[3];
gimp_image_get_background (gimp_item_get_image (item),
drawable, bg);
color_region (&destPR, bg);
}
color_region (&destPR, bg);
}
/* copy from the old to the new */
if (w && h)
/* Determine whether anything needs to be copied */
if (copy_width && copy_height)
{
pixel_region_init (&srcPR, drawable->tiles,
copy_x - item->offset_x, copy_y - item->offset_y,
copy_width, copy_height,
FALSE);
pixel_region_init (&destPR, new_tiles,
x2, y2,
w, h,
copy_x - new_offset_x, copy_y - new_offset_y,
copy_width, copy_height,
TRUE);
copy_region (&srcPR, &destPR);
......
......@@ -334,37 +334,8 @@ gimp_item_real_resize (GimpItem *item,
gint offset_x,
gint offset_y)
{
gint x1, y1, x2, y2;
x1 = CLAMP (offset_x, 0, new_width);
y1 = CLAMP (offset_y, 0, new_height);
x2 = CLAMP (offset_x + item->width, 0, new_width);
y2 = CLAMP (offset_y + item->height, 0, new_height);
if (offset_x > 0)
{
x1 = 0;
x2 = offset_x;
}
else
{
x1 = -offset_x;
x2 = 0;
}
if (offset_y > 0)
{
y1 = 0;
y2 = offset_y;
}
else
{
y1 = -offset_y;
y2 = 0;
}
item->offset_x = x1 + item->offset_x - x2;
item->offset_y = y1 + item->offset_y - y2;
item->offset_x = item->offset_x - offset_x;
item->offset_y = item->offset_y - offset_y;
item->width = new_width;
item->height = new_height;
}
......
......@@ -34,10 +34,12 @@
#include "paint-funcs/paint-funcs.h"
#include "gimp-utils.h"
#include "gimpdrawable-invert.h"
#include "gimpcontainer.h"
#include "gimpimage.h"
#include "gimpimage-convert.h"
#include "gimpimage-mask.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimplayer.h"
......@@ -897,8 +899,7 @@ gimp_layer_create_mask (const GimpLayer *layer,
{
pixel_region_init (&srcPR, drawable->tiles,
0, 0,
item->width,
item->height,
item->width, item->height,
FALSE);
extract_alpha_region (&srcPR, NULL, &destPR);
......@@ -908,69 +909,37 @@ gimp_layer_create_mask (const GimpLayer *layer,
case GIMP_ADD_SELECTION_MASK:
{
GimpChannel *selection;
gboolean selection_empty;
gint copy_x, copy_y;
gint copy_width, copy_height;
selection = gimp_image_get_mask (gimage);
selection = gimp_image_get_mask (gimage);
selection_empty = gimp_image_mask_is_empty (gimage);
if (item->offset_x < 0 ||
item->offset_y < 0 ||
item->offset_x + item->width > gimage->width ||
item->offset_y + item->height > gimage->height)
{
gint width, height;
width = item->width;
height = item->height;
if (item->offset_x < 0)
width += item->offset_x;
if (item->offset_y < 0)
height += item->offset_y;
if (item->offset_x + item->width > gimage->width)
width -= item->offset_x + item->width - gimage->width;
if (item->offset_y + item->height > gimage->height)
height -= item->offset_y + item->height - gimage->height;
if (width < item->width || height < item->height)
gimp_channel_clear (GIMP_CHANNEL (mask), FALSE);
if (width > 0 && height > 0)
{
gint x, y;
x = MAX (0, item->offset_x);
y = MAX (0, item->offset_y);
gimp_rectangle_intersect (0, 0, gimage->width, gimage->height,
item->offset_x, item->offset_y,
item->width, item->height,
&copy_x, &copy_y, &copy_width, &copy_height);
pixel_region_init (&srcPR, GIMP_DRAWABLE (selection)->tiles,
x, y, width, height,
FALSE);
if (copy_width < item->width || copy_height < item->height ||
selection_empty)
gimp_channel_clear (GIMP_CHANNEL (mask), FALSE);
x = MAX (0, -item->offset_x);
y = MAX (0, -item->offset_y);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x, y, width, height,
TRUE);
copy_region (&srcPR, &destPR);
}
}
else
if ((copy_width || copy_height) && ! selection_empty)
{
pixel_region_init (&srcPR, GIMP_DRAWABLE (selection)->tiles,
item->offset_x,
item->offset_y,
item->width,
item->height,
pixel_region_init (&srcPR, GIMP_DRAWABLE (selection)->tiles,
copy_x, copy_y,
copy_width, copy_height,
FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
copy_x - item->offset_x, copy_y - item->offset_y,
copy_width, copy_height,
TRUE);
copy_region (&srcPR, &destPR);
GIMP_CHANNEL (mask)->bounds_known = FALSE;
}
if (! (selection->bounds_known && selection->empty))
GIMP_CHANNEL (mask)->bounds_known = FALSE;
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment