mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 20:41:43 +00:00
d26c26686e
2001-06-26 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/color_transfer.[ch]: removed. * app/tools/Makefile.am * app/tools/gimpcolorbalancetool-transfer.[ch]: added. * app/tools/gimpcolorbalancetool.c: changed accordingly. * app/base/Makefile.am * app/base/tile-manager-crop.[ch]: formerly known as crop_buffer(). * app/tools/gimptexttool.c: changed accordingly. * app/context_manager.[ch]: added the global clipboard and the named buffer list here. * app/app_procs.c: don't call color_transfer_init() and don't free the buffer stuff (done by the context manager now). * app/errorconsole.c: don't #include "gui/commands.h" * app/global_edit.[ch]: removed lots of stuff which is now done by gui/edit-commands.* or the new GimpBuffer object. The "paste named" dialog will go away and this file will be moved to core/ soon. * app/image_new.c: no need to declare the global_buffer extern any more. * app/qmask.c: don't #include "global_edit.h" * app/core/Makefile.am * app/core/core-types.h * app/core/gimpbuffer.[ch]: new object (aka named buffer) * app/core/gimpcontext.[ch]: added a GimpBuffer attribute. * app/core/gimpimage.[ch]: one s/int/gboolean/. * app/core/gimppattern.c: hmm... * app/gui/commands.[ch]: split up in small files: * app/gui/Makefile.am * app/gui/edit-commands.[ch] * app/gui/file-commands.[ch] * app/gui/image-commands.[ch] * app/gui/select-commands.[ch] * app/gui/view-commands.[ch]: new files. * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.c: added the named buffer list & grid. * app/gui/file-new-dialog.[ch] * app/gui/menus.c * app/gui/palette-editor.c * app/gui/test-commands.c: changed accordingly. * app/pdb/edit_cmds.c * tools/pdbgen/pdb/edit.pdb: changed for the global_edit stuff. * app/widgets/Makefile.am * app/widgets/gimpbufferpreview.[ch] * app/widgets/gimpbufferview.[ch] * app/widgets/gimpcontainereditor.[ch]: new widgets. * app/widgets/gimpcontainerview-utils.c * app/widgets/gimpdatafactoryview.[ch] * app/widgets/gimpdnd.[ch] * app/widgets/gimpdrawablepreview.c * app/widgets/gimplayerlistview.c * app/widgets/gimppreview.c * app/widgets/widgets-types.h: changed accordingly for the new GimpBuffer object and it's views, misc. cleanups. * pixmaps/Makefile.am * pixmaps/paste-as-new.xpm * pixmaps/paste-into.xpm * pixmaps/paste.xpm: new pixmaps (they all look the same... Tigert? ;-) * po/POTFILES.in: added the new files.
163 lines
3.9 KiB
C
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.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;
|
|
}
|