gimp/plug-ins/common/guillotine.c

223 lines
5.5 KiB
C
Raw Normal View History

1998-09-02 06:22:59 +08:00
/*
* Guillotine plug-in v0.9 by Adam D. Moss, adam@foxbox.org. 1998/09/01
*/
/* 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.
*/
/*
* HISTORY:
* 0.9 : 1998/09/01
* Initial release.
*/
#include "config.h"
1998-09-02 06:22:59 +08:00
#include <stdlib.h>
#include <libgimp/gimp.h>
#include "libgimp/stdplugins-intl.h"
1998-09-02 06:22:59 +08:00
1998-09-02 06:22:59 +08:00
/* Declare local functions.
*/
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
1998-09-02 06:22:59 +08:00
static void guillotine (gint32 image_ID);
1998-09-02 06:22:59 +08:00
GimpPlugInInfo PLUG_IN_INFO =
1998-09-02 06:22:59 +08:00
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
1998-09-02 06:22:59 +08:00
};
MAIN ()
static void
query (void)
1998-09-02 06:22:59 +08:00
{
static GimpParamDef args[] =
1998-09-02 06:22:59 +08:00
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" }
1998-09-02 06:22:59 +08:00
};
1998-09-02 06:22:59 +08:00
gimp_install_procedure ("plug_in_guillotine",
"Slice up the image into subimages, cutting along "
"the image's Guides. Fooey to you and your "
"broccoli, Pokey.",
2000-01-31 10:32:30 +08:00
"This function takes an image and blah blah. Hooray!",
1998-09-02 06:22:59 +08:00
"Adam D. Moss (adam@foxbox.org)",
"Adam D. Moss (adam@foxbox.org)",
"1998",
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-04 01:59:48 +08:00
N_("<Image>/Image/Transform/Guillotine"),
1998-09-02 06:22:59 +08:00
"RGB*, INDEXED*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
1998-09-02 06:22:59 +08:00
}
static void
run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1998-09-02 06:22:59 +08:00
{
static GimpParam values[1];
gint32 image_ID;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
1998-09-02 06:22:59 +08:00
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
1998-09-02 06:22:59 +08:00
values[0].data.d_status = status;
INIT_I18N();
1998-09-02 06:22:59 +08:00
/* Get the specified drawable */
image_ID = param[1].data.d_image;
if (status == GIMP_PDB_SUCCESS)
1998-09-02 06:22:59 +08:00
{
gimp_progress_init (_("Guillotine..."));
1998-09-02 06:22:59 +08:00
guillotine (image_ID);
gimp_displays_flush ();
}
values[0].data.d_status = status;
}
static gint
guide_sort_func (gconstpointer a,
gconstpointer b)
1998-09-02 06:22:59 +08:00
{
return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
1998-09-02 06:22:59 +08:00
}
static void
guillotine (gint32 image_ID)
1998-09-02 06:22:59 +08:00
{
gint guide_num;
gboolean guides_found;
GList *hguides, *hg;
GList *vguides, *vg;
hguides = g_list_append (NULL, GINT_TO_POINTER (0));
vguides = g_list_append (NULL, GINT_TO_POINTER (0));
1998-09-02 06:22:59 +08:00
hguides = g_list_append (hguides,
GINT_TO_POINTER (gimp_image_height (image_ID)));
vguides = g_list_append (vguides,
GINT_TO_POINTER (gimp_image_width (image_ID)));
guide_num = gimp_image_find_next_guide (image_ID, 0);
guides_found = (guide_num != 0);
1998-09-02 06:22:59 +08:00
while (guide_num > 0)
1998-09-02 06:22:59 +08:00
{
gint position = gimp_image_get_guide_position (image_ID, guide_num);
switch (gimp_image_get_guide_orientation (image_ID, guide_num))
{
case GIMP_HORIZONTAL:
hguides = g_list_insert_sorted (hguides, GINT_TO_POINTER (position),
guide_sort_func);
break;
case GIMP_VERTICAL:
vguides = g_list_insert_sorted (vguides, GINT_TO_POINTER (position),
guide_sort_func);
break;
case GIMP_UNKNOWN:
g_assert_not_reached ();
break;
1998-09-02 06:22:59 +08:00
}
guide_num = gimp_image_find_next_guide (image_ID, guide_num);
1998-09-02 06:22:59 +08:00
}
if (guides_found)
1998-09-02 06:22:59 +08:00
{
gchar *filename;
gint x, y;
1998-09-02 06:22:59 +08:00
filename = gimp_image_get_filename (image_ID);
if (!filename)
filename = g_strdup (_("Untitled"));
/* Do the actual dup'ing and cropping... this isn't a too naive a
way to do this since we got copy-on-write tiles, either. */
1998-09-02 06:22:59 +08:00
for (y = 0, hg = hguides; hg && hg->next; y++, hg = hg->next)
1998-09-02 06:22:59 +08:00
{
for (x = 0, vg = vguides; vg && vg->next; x++, vg = vg->next)
1998-09-02 06:22:59 +08:00
{
gint32 new_image = gimp_image_duplicate (image_ID);
gchar *new_filename;
if (new_image == -1)
{
g_warning ("Couldn't create new image.");
return;
}
gimp_image_undo_disable (new_image);
gimp_image_crop (new_image,
GPOINTER_TO_INT (vg->next->data) -
GPOINTER_TO_INT (vg->data),
GPOINTER_TO_INT (hg->next->data) -
GPOINTER_TO_INT (hg->data),
GPOINTER_TO_INT (vg->data),
GPOINTER_TO_INT (hg->data));
/* show the rough coordinates of the image in the title */
new_filename = g_strdup_printf ("%s-(%i,%i)",
filename,
x, y);
gimp_image_set_filename (new_image, new_filename);
g_free (new_filename);
gimp_image_undo_enable (new_image);
gimp_display_new (new_image);
1998-09-02 06:22:59 +08:00
}
}
g_free (filename);
1998-09-02 06:22:59 +08:00
}
g_list_free (hguides);
g_list_free (vguides);
1998-09-02 06:22:59 +08:00
}