2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This filter tiles an image to arbitrary width and height
|
|
|
|
*/
|
2000-01-26 01:46:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <string.h>
|
2000-01-09 04:00:10 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-tile"
|
|
|
|
#define PLUG_IN_BINARY "tile"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-tile"
|
2005-08-16 06:42:34 +08:00
|
|
|
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
gint new_width;
|
|
|
|
gint new_height;
|
|
|
|
gint constrain;
|
|
|
|
gint new_image;
|
|
|
|
} TileVals;
|
|
|
|
|
2000-11-09 06:41:13 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
typedef struct _Tile Tile;
|
|
|
|
typedef struct _TileClass TileClass;
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
struct _Tile
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
struct _TileClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
2016-02-17 01:55:57 +08:00
|
|
|
|
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
#define TILE_TYPE (tile_get_type ())
|
|
|
|
#define TILE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TILE_TYPE, Tile))
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
GType tile_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * tile_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * tile_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * tile_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
|
|
|
|
static void tile (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpImage **new_image,
|
|
|
|
GimpLayer **new_layer);
|
|
|
|
|
|
|
|
static void tile_gegl (GeglBuffer *src,
|
|
|
|
gint src_width,
|
|
|
|
gint src_height,
|
|
|
|
GeglBuffer *dst,
|
|
|
|
gint dst_width,
|
|
|
|
gint dst_height);
|
|
|
|
|
|
|
|
static gboolean tile_dialog (GimpImage *image,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Tile, tile, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (TILE_TYPE)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
static TileVals tvals =
|
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
1, /* new_width */
|
|
|
|
1, /* new_height */
|
|
|
|
TRUE, /* constrain */
|
|
|
|
TRUE /* new_image */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2000-11-09 06:41:13 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2019-09-03 19:24:05 +08:00
|
|
|
tile_class_init (TileClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-09-03 19:24:05 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = tile_query_procedures;
|
|
|
|
plug_in_class->create_procedure = tile_create_procedure;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-03 19:24:05 +08:00
|
|
|
tile_init (Tile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-09-03 19:24:05 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
static GList *
|
|
|
|
tile_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
tile_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, PLUG_IN_PROC))
|
|
|
|
{
|
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
tile_run, NULL, NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("_Tile..."));
|
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Filters/Map");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
N_("Create an array of copies "
|
|
|
|
"of the image"),
|
|
|
|
"This function creates a new image "
|
|
|
|
"with a single layer sized to the "
|
|
|
|
"specified 'new_width' and "
|
|
|
|
"'new_height' parameters. The "
|
|
|
|
"specified drawable is tiled into "
|
|
|
|
"this layer. The new layer will have "
|
|
|
|
"the same type as the specified "
|
|
|
|
"drawable and the new image will "
|
|
|
|
"have a corresponding base type.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"1996-1997");
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_INT (procedure, "new-width",
|
|
|
|
"New width",
|
|
|
|
"New (tiled) image width",
|
|
|
|
1, GIMP_MAX_IMAGE_SIZE, 1,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_INT (procedure, "new-height",
|
|
|
|
"New height",
|
|
|
|
"New (tiled) image height",
|
|
|
|
1, GIMP_MAX_IMAGE_SIZE, 1,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_BOOLEAN (procedure, "new-image",
|
|
|
|
"New image",
|
|
|
|
"Create a new image",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_VAL_IMAGE (procedure, "new-image",
|
|
|
|
"New image",
|
|
|
|
"Output image (NULL if new-image == FALSE)",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_VAL_LAYER (procedure, "new-layer",
|
|
|
|
"New layer",
|
|
|
|
"Output layer (NULL if new-image == FALSE)",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
}
|
2003-03-26 00:38:19 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
return procedure;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
tile_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpLayer *new_layer;
|
|
|
|
GimpImage *new_image;
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
gegl_init (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &tvals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
if (! tile_dialog (image, drawable))
|
2007-07-31 15:48:26 +08:00
|
|
|
{
|
2019-09-03 19:24:05 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
2007-07-31 15:48:26 +08:00
|
|
|
}
|
2019-09-03 19:24:05 +08:00
|
|
|
break;
|
2007-07-31 15:48:26 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
tvals.new_width = GIMP_VALUES_GET_INT (args, 0);
|
|
|
|
tvals.new_height = GIMP_VALUES_GET_INT (args, 1);
|
|
|
|
tvals.new_image = GIMP_VALUES_GET_BOOLEAN (args, 2);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &tvals);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
gimp_progress_init (_("Tiling"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
tile (image,
|
|
|
|
drawable,
|
|
|
|
&new_image,
|
|
|
|
&new_layer);
|
2016-02-17 01:55:57 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_set_data (PLUG_IN_PROC, &tvals, sizeof (TileVals));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
{
|
|
|
|
if (tvals.new_image)
|
|
|
|
gimp_display_new (new_image);
|
|
|
|
else
|
|
|
|
gimp_displays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, new_image);
|
|
|
|
GIMP_VALUES_SET_LAYER (return_vals, 2, new_layer);
|
2016-02-17 01:55:57 +08:00
|
|
|
|
2019-09-03 19:24:05 +08:00
|
|
|
return return_vals;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-02-17 01:55:57 +08:00
|
|
|
static void
|
|
|
|
tile_gegl (GeglBuffer *src,
|
|
|
|
gint src_width,
|
|
|
|
gint src_height,
|
|
|
|
GeglBuffer *dst,
|
|
|
|
gint dst_width,
|
|
|
|
gint dst_height)
|
|
|
|
{
|
|
|
|
GeglNode *node;
|
|
|
|
GeglNode *buffer_src_node;
|
|
|
|
GeglNode *tile_node;
|
|
|
|
GeglNode *crop_src_node;
|
|
|
|
GeglNode *crop_dst_node;
|
|
|
|
GeglNode *buffer_dst_node;
|
|
|
|
|
|
|
|
GeglProcessor *processor;
|
|
|
|
gdouble progress;
|
|
|
|
|
|
|
|
node = gegl_node_new ();
|
|
|
|
|
|
|
|
buffer_src_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", src,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
crop_src_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:crop",
|
|
|
|
"width", (gdouble) src_width,
|
|
|
|
"height", (gdouble) src_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
tile_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:tile",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
crop_dst_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:crop",
|
|
|
|
"width", (gdouble) dst_width,
|
|
|
|
"height", (gdouble) dst_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
buffer_dst_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:write-buffer",
|
|
|
|
"buffer", dst,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gegl_node_link_many (buffer_src_node,
|
|
|
|
crop_src_node,
|
|
|
|
tile_node,
|
|
|
|
crop_dst_node,
|
|
|
|
buffer_dst_node,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
processor = gegl_node_new_processor (buffer_dst_node, NULL);
|
|
|
|
|
|
|
|
while (gegl_processor_work (processor, &progress))
|
|
|
|
if (!((gint) (progress * 100.0) % 10))
|
|
|
|
gimp_progress_update (progress);
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
|
|
|
g_object_unref (processor);
|
|
|
|
g_object_unref (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-31 01:45:34 +08:00
|
|
|
tile (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpImage **new_image,
|
|
|
|
GimpLayer **new_layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-31 01:45:34 +08:00
|
|
|
GimpDrawable *dst_drawable;
|
|
|
|
GeglBuffer *dst_buffer;
|
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
gint dst_width = tvals.new_width;
|
|
|
|
gint dst_height = tvals.new_height;
|
|
|
|
gint src_width = gimp_drawable_width (drawable);
|
|
|
|
gint src_height = gimp_drawable_height (drawable);
|
2016-02-17 01:55:57 +08:00
|
|
|
|
2007-07-31 15:48:26 +08:00
|
|
|
GimpImageBaseType image_type = GIMP_RGB;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tvals.new_image)
|
|
|
|
{
|
|
|
|
/* create a new image */
|
2019-08-31 01:45:34 +08:00
|
|
|
gint32 precision = gimp_image_get_precision (image);
|
2016-02-17 01:55:57 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
switch (gimp_drawable_type (drawable))
|
2007-07-31 15:48:26 +08:00
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
image_type = GIMP_RGB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
image_type = GIMP_GRAY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
image_type = GIMP_INDEXED;
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
*new_image = gimp_image_new_with_precision (dst_width,
|
|
|
|
dst_height,
|
|
|
|
image_type,
|
|
|
|
precision);
|
|
|
|
gimp_image_undo_disable (*new_image);
|
2007-06-27 16:15:54 +08:00
|
|
|
|
2016-02-17 01:55:57 +08:00
|
|
|
/* copy the colormap, if necessary */
|
|
|
|
if (image_type == GIMP_INDEXED)
|
|
|
|
{
|
|
|
|
guchar *cmap;
|
|
|
|
gint ncols;
|
2000-11-09 06:41:13 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
cmap = gimp_image_get_colormap (image, &ncols);
|
|
|
|
gimp_image_set_colormap (*new_image, cmap, ncols);
|
2016-02-17 01:55:57 +08:00
|
|
|
g_free (cmap);
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
*new_layer = gimp_layer_new (*new_image, _("Background"),
|
|
|
|
dst_width, dst_height,
|
|
|
|
gimp_drawable_type (drawable),
|
|
|
|
100,
|
|
|
|
gimp_image_get_default_new_layer_mode (*new_image));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
if (*new_layer == NULL)
|
2016-02-17 01:55:57 +08:00
|
|
|
return;
|
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_image_insert_layer (*new_image, *new_layer, NULL, 0);
|
|
|
|
dst_drawable = GIMP_DRAWABLE (*new_layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-31 01:45:34 +08:00
|
|
|
*new_image = NULL;
|
|
|
|
*new_layer = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_image_undo_group_start (image);
|
|
|
|
gimp_image_resize (image, dst_width, dst_height, 0, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
if (gimp_item_is_layer (GIMP_ITEM (drawable)))
|
2007-07-31 15:48:26 +08:00
|
|
|
{
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_layer_resize (GIMP_LAYER (drawable), dst_width, dst_height, 0, 0);
|
|
|
|
}
|
|
|
|
else if (gimp_item_is_layer_mask (GIMP_ITEM (drawable)))
|
|
|
|
{
|
|
|
|
GimpLayer *layer = gimp_layer_from_mask (GIMP_LAYER_MASK (drawable));
|
|
|
|
|
|
|
|
gimp_layer_resize (layer, dst_width, dst_height, 0, 0);
|
2007-07-31 15:48:26 +08:00
|
|
|
}
|
2016-02-17 01:55:57 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
dst_drawable = drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
src_buffer = gimp_drawable_get_buffer (drawable);
|
|
|
|
dst_buffer = gimp_drawable_get_buffer (dst_drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-02-17 01:55:57 +08:00
|
|
|
tile_gegl (src_buffer, src_width, src_height,
|
|
|
|
dst_buffer, dst_width, dst_height);
|
|
|
|
|
|
|
|
gegl_buffer_flush (dst_buffer);
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_drawable_update (dst_drawable, 0, 0, dst_width, dst_height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tvals.new_image)
|
|
|
|
{
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_image_undo_enable (*new_image);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2003-12-05 22:18:47 +08:00
|
|
|
{
|
2019-08-31 01:45:34 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-12-05 22:18:47 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-02-17 01:55:57 +08:00
|
|
|
g_object_unref (src_buffer);
|
|
|
|
g_object_unref (dst_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-05-20 08:50:05 +08:00
|
|
|
static gboolean
|
2019-08-31 01:45:34 +08:00
|
|
|
tile_dialog (GimpImage *image,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dlg;
|
2004-05-20 08:50:05 +08:00
|
|
|
GtkWidget *vbox;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *frame;
|
2000-02-03 01:59:44 +08:00
|
|
|
GtkWidget *sizeentry;
|
2003-11-06 23:27:05 +08:00
|
|
|
GtkWidget *chainbutton;
|
2000-01-26 01:46:56 +08:00
|
|
|
GtkWidget *toggle;
|
2000-11-09 06:41:13 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
GimpUnit unit;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-31 01:45:34 +08:00
|
|
|
width = gimp_drawable_width (drawable);
|
|
|
|
height = gimp_drawable_height (drawable);
|
|
|
|
unit = gimp_image_get_unit (image);
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2000-02-03 01:59:44 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
tvals.new_width = width;
|
1997-11-25 06:05:25 +08:00
|
|
|
tvals.new_height = height;
|
|
|
|
|
2011-04-09 02:31:34 +08:00
|
|
|
dlg = gimp_dialog_new (_("Tile"), PLUG_IN_ROLE,
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2007-07-31 15:48:26 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2000-01-09 04:00:10 +08:00
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_OK"), GTK_RESPONSE_OK,
|
2000-01-09 04:00:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
|
2005-08-16 06:42:34 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dlg));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2004-05-20 08:50:05 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2009-07-16 00:57:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
|
|
|
vbox, TRUE, TRUE, 0);
|
2004-05-20 08:50:05 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
frame = gimp_frame_new (_("Tile to New Size"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
2000-02-03 01:59:44 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-09-07 04:44:47 +08:00
|
|
|
sizeentry = gimp_coordinates_new (unit, "%a", TRUE, TRUE, 8,
|
2007-07-31 15:48:26 +08:00
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
2000-02-03 01:59:44 +08:00
|
|
|
|
2007-07-31 15:48:26 +08:00
|
|
|
tvals.constrain, TRUE,
|
2000-02-03 01:59:44 +08:00
|
|
|
|
2007-07-31 15:48:26 +08:00
|
|
|
_("_Width:"), width, xres,
|
|
|
|
1, GIMP_MAX_IMAGE_SIZE,
|
|
|
|
0, width,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-07-31 15:48:26 +08:00
|
|
|
_("_Height:"), height, yres,
|
|
|
|
1, GIMP_MAX_IMAGE_SIZE,
|
|
|
|
0, height);
|
2000-02-03 01:59:44 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), sizeentry);
|
|
|
|
gtk_widget_show (sizeentry);
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
chainbutton = GTK_WIDGET (GIMP_COORDINATES_CHAINBUTTON (sizeentry));
|
2000-02-03 01:59:44 +08:00
|
|
|
|
2005-08-23 08:18:08 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("C_reate new image"));
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), tvals.new_image);
|
2004-05-20 08:50:05 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2002-01-08 17:20:02 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&tvals.new_image);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (run)
|
|
|
|
{
|
|
|
|
tvals.new_width =
|
|
|
|
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (sizeentry), 0));
|
|
|
|
tvals.new_height =
|
|
|
|
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (sizeentry), 1));
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
tvals.constrain =
|
|
|
|
gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chainbutton));
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (dlg);
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|