gimp/app/base/tile-manager-crop.c
Sven Neumann d4829df4d3 removed from CVS, they are generated.
2001-12-07  Sven Neumann  <sven@gimp.org>

	* app/core/gimpmarshal.[ch]: removed from CVS, they are generated.

	* app/base/Makefile.am
	* app/base/base-enums.h: new file defining enums that are to be
	registered. Used to build app/base/base-enums.c.

	* app/base/base-types.h: include base-enums.h.

	* tools/pdbgen/Makefile.am
	* tools/pdbgen/enumcode.pl
	* tools/pdbgen/enums.pl: parse the new base-enums.h file and modified
	the perl voodoo so it doesn't prefix enums with GIMP_ that are already
	properly namespaced.

	* app/core/core-types.h: don't need to chop GIMP from enum.

	* app/pdb/color_cmds.c
	* app/pdb/tools_cmds.c
	* libgimp/gimpenums.h
	* plug-ins/script-fu/script-fu-constants.c: regenerated.

	* app/config/gimpconfig-deserialize.[ch]
	* app/config/gimpconfig-serialize.[ch]
	* app/config/gimpconfig.[ch]: made GimpConfig an interface including
	a reasonable default implementation that works on object properties.

	* app/config/Makefile.am
	* app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the
	GimpConfig interface. Yet only used for testing from app/main.c.

	* app/main.c: test the new GimpBaseConfig object.

	* app/gimprc.c
	* app/base/base-config.h
	* app/base/*.c
	* app/core/gimpdatafiles.c
	* app/core/gimpdrawable-transform.c
	* app/core/gimppreviewcache.c
	* app/gui/preferences-dialog.c
	* app/paint-funcs/paint-funcs.c
	* app/xcf/xcf-seek.c: need to include glib-object.h since base-config
	contains registered enums now. Follow name change of InterpolationType
	to GimpInterpolationType.
2001-12-07 16:10:53 +00:00

163 lines
3.9 KiB
C

/* 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 "base-types.h"
#include "pixel-region.h"
#include "tile-manager.h"
#include "paint-funcs/paint-funcs.h"
/* Crop the buffer to the size of pixels with non-zero transparency */
TileManager *
tile_manager_crop (TileManager *tiles,
gint border)
{
PixelRegion PR;
TileManager *new_tiles;
gint bytes, alpha;
guchar *data;
gint empty;
gint x1, y1, x2, y2;
gint x, y;
gint ex, ey;
gint found;
void *pr;
guchar black[MAX_CHANNELS] = { 0, 0, 0, 0 };
g_return_val_if_fail (tiles != NULL, NULL);
bytes = tile_manager_bpp (tiles);
alpha = bytes - 1;
/* go through and calculate the bounds */
x1 = tile_manager_width (tiles);
y1 = tile_manager_height (tiles);
x2 = 0;
y2 = 0;
pixel_region_init (&PR, tiles, 0, 0, x1, y1, FALSE);
for (pr = pixel_regions_register (1, &PR);
pr != NULL;
pr = pixel_regions_process (pr))
{
data = PR.data + alpha;
ex = PR.x + PR.w;
ey = PR.y + PR.h;
for (y = PR.y; y < ey; y++)
{
found = FALSE;
for (x = PR.x; x < ex; x++, data+=bytes)
if (*data)
{
if (x < x1)
x1 = x;
if (x > x2)
x2 = x;
found = TRUE;
}
if (found)
{
if (y < y1)
y1 = y;
if (y > y2)
y2 = y;
}
}
}
x2 = CLAMP (x2 + 1, 0, tile_manager_width (tiles));
y2 = CLAMP (y2 + 1, 0, tile_manager_height (tiles));
empty = (x1 == tile_manager_width (tiles) &&
y1 == tile_manager_height (tiles));
if (empty)
{
/* If there are no visible pixels, return NULL */
new_tiles = NULL;
}
else if (x1 == 0 && y1 == 0 &&
x2 == tile_manager_width (tiles) &&
y2 == tile_manager_height (tiles) &&
border == 0)
{
/* If no cropping, return original buffer */
new_tiles = tiles;
}
else
{
/* Otherwise, crop the original area */
PixelRegion srcPR, destPR;
gint new_width, new_height;
new_width = (x2 - x1) + border * 2;
new_height = (y2 - y1) + border * 2;
new_tiles = tile_manager_new (new_width, new_height, bytes);
/* If there is a border, make sure to clear the new tiles first */
if (border)
{
pixel_region_init (&destPR, new_tiles,
0, 0, new_width, border,
TRUE);
color_region (&destPR, black);
pixel_region_init (&destPR, new_tiles,
0, border, border, (y2 - y1),
TRUE);
color_region (&destPR, black);
pixel_region_init (&destPR, new_tiles,
new_width - border, border, border, (y2 - y1),
TRUE);
color_region (&destPR, black);
pixel_region_init (&destPR, new_tiles,
0, new_height - border, new_width, border,
TRUE);
color_region (&destPR, black);
}
pixel_region_init (&srcPR, tiles,
x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, new_tiles,
border, border, (x2 - x1), (y2 - y1), TRUE);
copy_region (&srcPR, &destPR);
tile_manager_set_offsets (new_tiles, x1, y1);
}
return new_tiles;
}