2019-02-11 12:45:06 +01:00
|
|
|
/* GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-02-16 19:00:04 +01:00
|
|
|
#include <cairo.h>
|
2019-02-11 12:45:06 +01:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2019-02-16 19:00:04 +01:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2019-09-23 19:49:36 +02:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
#include "core/core-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpbrush-load.h"
|
2019-02-16 19:00:04 +01:00
|
|
|
#include "core/gimpbrush-private.h"
|
2023-10-16 15:30:12 +02:00
|
|
|
#include "core/gimpcontainer.h"
|
2019-02-11 12:45:06 +01:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
2023-10-16 15:30:12 +02:00
|
|
|
#include "core/gimpimage-merge.h"
|
|
|
|
#include "core/gimpimage-new.h"
|
2019-02-19 23:13:59 +01:00
|
|
|
#include "core/gimpimage-resize.h"
|
2023-10-16 15:30:12 +02:00
|
|
|
#include "core/gimplayer-new.h"
|
2019-02-11 12:45:06 +01:00
|
|
|
#include "core/gimpparamspecs.h"
|
2023-10-16 15:30:12 +02:00
|
|
|
#include "core/gimppickable.h"
|
2019-02-11 12:45:06 +01:00
|
|
|
#include "core/gimptempbuf.h"
|
|
|
|
|
|
|
|
#include "pdb/gimpprocedure.h"
|
|
|
|
|
|
|
|
#include "file-data-gbr.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2023-10-16 15:30:12 +02:00
|
|
|
static GimpImage * file_gbr_brush_to_image (Gimp *gimp,
|
|
|
|
GimpBrush *brush);
|
|
|
|
static GimpBrush * file_gbr_image_to_brush (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
const gchar *name,
|
|
|
|
gdouble spacing);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpValueArray *
|
|
|
|
file_gbr_load_invoker (GimpProcedure *procedure,
|
|
|
|
Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
GFile *file;
|
|
|
|
GInputStream *input;
|
|
|
|
GError *my_error = NULL;
|
|
|
|
|
|
|
|
gimp_set_busy (gimp);
|
|
|
|
|
2019-09-11 21:48:34 +02:00
|
|
|
file = g_value_get_object (gimp_value_array_index (args, 1));
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
|
|
|
|
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
GimpBrush *brush = gimp_brush_load_brush (context, file, input, error);
|
|
|
|
|
|
|
|
if (brush)
|
|
|
|
{
|
|
|
|
image = file_gbr_brush_to_image (gimp, brush);
|
|
|
|
g_object_unref (brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_propagate_prefixed_error (error, my_error,
|
|
|
|
_("Could not open '%s' for reading: "),
|
|
|
|
gimp_file_get_utf8_name (file));
|
|
|
|
}
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_get_return_values (procedure, image != NULL,
|
|
|
|
error ? *error : NULL);
|
|
|
|
|
|
|
|
if (image)
|
2019-08-29 11:25:35 +02:00
|
|
|
g_value_set_object (gimp_value_array_index (return_vals, 1), image);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
gimp_unset_busy (gimp);
|
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpValueArray *
|
|
|
|
file_gbr_save_invoker (GimpProcedure *procedure,
|
|
|
|
Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
GError **error)
|
|
|
|
{
|
2023-10-16 15:30:12 +02:00
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpImage *image;
|
|
|
|
GimpDrawable **drawables;
|
|
|
|
gint n_drawables;
|
|
|
|
GimpBrush *brush;
|
|
|
|
const gchar *name;
|
|
|
|
GFile *file;
|
|
|
|
gint spacing;
|
|
|
|
gboolean success;
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
gimp_set_busy (gimp);
|
|
|
|
|
2023-10-16 15:30:12 +02:00
|
|
|
image = g_value_get_object (gimp_value_array_index (args, 1));
|
2024-10-22 22:46:21 +02:00
|
|
|
drawables = (GimpDrawable **) g_value_get_boxed (gimp_value_array_index (args, 2));
|
|
|
|
n_drawables = gimp_core_object_array_get_length ((GObject **) drawables);
|
|
|
|
file = g_value_get_object (gimp_value_array_index (args, 3));
|
|
|
|
spacing = g_value_get_int (gimp_value_array_index (args, 4));
|
|
|
|
name = g_value_get_string (gimp_value_array_index (args, 5));
|
2019-02-16 19:00:04 +01:00
|
|
|
|
2023-10-16 15:30:12 +02:00
|
|
|
brush = file_gbr_image_to_brush (image, context, n_drawables, drawables, name, spacing);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
gimp_data_set_file (GIMP_DATA (brush), file, TRUE, TRUE);
|
|
|
|
|
|
|
|
success = gimp_data_save (GIMP_DATA (brush), error);
|
|
|
|
|
|
|
|
g_object_unref (brush);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_get_return_values (procedure, success,
|
|
|
|
error ? *error : NULL);
|
|
|
|
|
|
|
|
gimp_unset_busy (gimp);
|
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
|
2019-02-19 23:13:59 +01:00
|
|
|
GimpLayer *
|
|
|
|
file_gbr_brush_to_layer (GimpImage *image,
|
2019-02-11 12:45:06 +01:00
|
|
|
GimpBrush *brush)
|
|
|
|
{
|
2019-02-19 23:13:59 +01:00
|
|
|
GimpLayer *layer;
|
|
|
|
const Babl *format;
|
|
|
|
gboolean alpha;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
|
|
|
GimpTempBuf *mask;
|
|
|
|
GimpTempBuf *pixmap;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
|
|
|
|
|
|
|
mask = gimp_brush_get_mask (brush);
|
|
|
|
pixmap = gimp_brush_get_pixmap (brush);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
if (pixmap)
|
2019-02-19 23:13:59 +01:00
|
|
|
alpha = TRUE;
|
2019-02-11 12:45:06 +01:00
|
|
|
else
|
2019-02-19 23:13:59 +01:00
|
|
|
alpha = FALSE;
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
width = gimp_temp_buf_get_width (mask);
|
|
|
|
height = gimp_temp_buf_get_height (mask);
|
|
|
|
|
2019-02-19 23:13:59 +01:00
|
|
|
image_width = gimp_image_get_width (image);
|
|
|
|
image_height = gimp_image_get_height (image);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
2019-02-19 23:13:59 +01:00
|
|
|
if (width > image_width || height > image_height)
|
|
|
|
{
|
|
|
|
gint new_width = MAX (image_width, width);
|
|
|
|
gint new_height = MAX (image_height, height);
|
|
|
|
|
|
|
|
gimp_image_resize (image, gimp_get_user_context (image->gimp),
|
|
|
|
new_width, new_height,
|
|
|
|
(new_width - image_width) / 2,
|
|
|
|
(new_height - image_height) / 2,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
image_width = new_width;
|
|
|
|
image_height = new_height;
|
|
|
|
}
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
format = gimp_image_get_layer_format (image, alpha);
|
|
|
|
|
2019-02-19 23:13:59 +01:00
|
|
|
layer = gimp_layer_new (image, width, height, format,
|
|
|
|
gimp_object_get_name (brush),
|
2019-02-11 12:45:06 +01:00
|
|
|
1.0, GIMP_LAYER_MODE_NORMAL);
|
2019-02-19 23:13:59 +01:00
|
|
|
|
|
|
|
gimp_item_set_offset (GIMP_ITEM (layer),
|
|
|
|
(image_width - width) / 2,
|
|
|
|
(image_height - height) / 2);
|
2019-02-11 12:45:06 +01:00
|
|
|
|
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
|
|
|
|
|
|
|
if (pixmap)
|
|
|
|
{
|
|
|
|
guchar *pixmap_data;
|
|
|
|
guchar *mask_data;
|
|
|
|
guchar *p;
|
|
|
|
guchar *m;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
|
|
|
|
babl_format ("R'G'B' u8"),
|
|
|
|
gimp_temp_buf_get_data (pixmap), GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
|
|
|
pixmap_data = gegl_buffer_linear_open (buffer, NULL, NULL, NULL);
|
|
|
|
mask_data = gimp_temp_buf_get_data (mask);
|
|
|
|
|
|
|
|
for (i = 0, p = pixmap_data, m = mask_data;
|
|
|
|
i < width * height;
|
|
|
|
i++, p += 4, m += 1)
|
|
|
|
{
|
|
|
|
p[3] = *m;
|
|
|
|
}
|
|
|
|
|
|
|
|
gegl_buffer_linear_close (buffer, pixmap_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guchar *mask_data = gimp_temp_buf_get_data (mask);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < width * height; i++)
|
|
|
|
mask_data[i] = 255 - mask_data[i];
|
|
|
|
|
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
|
|
|
|
babl_format ("Y' u8"),
|
|
|
|
mask_data, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
}
|
|
|
|
|
2019-02-19 23:13:59 +01:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
GimpBrush *
|
|
|
|
file_gbr_drawable_to_brush (GimpDrawable *drawable,
|
|
|
|
const GeglRectangle *rect,
|
|
|
|
const gchar *name,
|
|
|
|
gdouble spacing)
|
2019-02-11 12:45:06 +01:00
|
|
|
{
|
2019-02-16 19:00:04 +01:00
|
|
|
GimpBrush *brush;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpTempBuf *mask;
|
|
|
|
GimpTempBuf *pixmap = NULL;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (rect != NULL, NULL);
|
|
|
|
|
2019-02-16 19:00:04 +01:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
2019-02-27 00:06:17 +01:00
|
|
|
width = rect->width;
|
|
|
|
height = rect->height;
|
2019-02-16 19:00:04 +01:00
|
|
|
|
|
|
|
brush = g_object_new (GIMP_TYPE_BRUSH,
|
|
|
|
"name", name,
|
|
|
|
"mime-type", "image/x-gimp-gbr",
|
|
|
|
"spacing", spacing,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
mask = gimp_temp_buf_new (width, height, babl_format ("Y u8"));
|
|
|
|
|
|
|
|
if (gimp_drawable_is_gray (drawable))
|
|
|
|
{
|
|
|
|
guchar *m = gimp_temp_buf_get_data (mask);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
{
|
|
|
|
GeglBufferIterator *iter;
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
iter = gegl_buffer_iterator_new (buffer, rect, 0,
|
2024-09-05 21:21:37 +00:00
|
|
|
babl_format ("Y'A float"),
|
2019-02-16 19:00:04 +01:00
|
|
|
GEGL_ACCESS_READ, GEGL_ABYSS_NONE,
|
|
|
|
1);
|
|
|
|
|
|
|
|
while (gegl_buffer_iterator_next (iter))
|
|
|
|
{
|
2024-09-05 21:21:37 +00:00
|
|
|
gfloat *data = (gfloat *) iter->items[0].data;
|
2019-02-16 19:00:04 +01:00
|
|
|
gint j;
|
|
|
|
|
|
|
|
for (j = 0; j < iter->length; j++)
|
|
|
|
{
|
2024-09-05 21:21:37 +00:00
|
|
|
gint x, y;
|
|
|
|
gint dest;
|
2019-02-16 19:00:04 +01:00
|
|
|
|
2024-09-05 21:21:37 +00:00
|
|
|
/* Composite brush color on top of white (1.0, 1.0, 1.0, 1.0) */
|
|
|
|
if (data[1] < 1.0)
|
|
|
|
data[0] = (1.0 - data[1]) + (data[0] * data[1]);
|
2019-02-16 19:00:04 +01:00
|
|
|
|
|
|
|
x = iter->items[0].roi.x + j % iter->items[0].roi.width;
|
|
|
|
y = iter->items[0].roi.y + j / iter->items[0].roi.width;
|
|
|
|
|
|
|
|
dest = y * width + x;
|
|
|
|
|
2024-09-05 21:21:37 +00:00
|
|
|
m[dest] = (guchar) (data[0] * 255);
|
2019-02-16 19:00:04 +01:00
|
|
|
|
|
|
|
data += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-27 00:06:17 +01:00
|
|
|
gegl_buffer_get (buffer, rect, 1.0,
|
2019-02-16 19:00:04 +01:00
|
|
|
babl_format ("Y' u8"), m,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invert */
|
|
|
|
for (i = 0; i < width * height; i++)
|
|
|
|
m[i] = 255 - m[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pixmap = gimp_temp_buf_new (width, height, babl_format ("R'G'B' u8"));
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
gegl_buffer_get (buffer, rect, 1.0,
|
2019-02-16 19:00:04 +01:00
|
|
|
babl_format ("R'G'B' u8"),
|
|
|
|
gimp_temp_buf_get_data (pixmap),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
gegl_buffer_get (buffer, rect, 1.0,
|
2019-02-16 19:00:04 +01:00
|
|
|
babl_format ("A u8"),
|
|
|
|
gimp_temp_buf_get_data (mask),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
brush->priv->mask = mask;
|
|
|
|
brush->priv->pixmap = pixmap;
|
|
|
|
|
|
|
|
return brush;
|
2019-02-11 12:45:06 +01:00
|
|
|
}
|
2019-02-27 00:06:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static GimpImage *
|
|
|
|
file_gbr_brush_to_image (Gimp *gimp,
|
|
|
|
GimpBrush *brush)
|
|
|
|
{
|
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageBaseType base_type;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
GimpTempBuf *mask = gimp_brush_get_mask (brush);
|
|
|
|
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
|
2019-09-23 19:49:36 +02:00
|
|
|
GString *string;
|
|
|
|
GimpConfigWriter *writer;
|
2019-02-27 00:06:17 +01:00
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
if (pixmap)
|
|
|
|
base_type = GIMP_RGB;
|
|
|
|
else
|
|
|
|
base_type = GIMP_GRAY;
|
|
|
|
|
|
|
|
width = gimp_temp_buf_get_width (mask);
|
|
|
|
height = gimp_temp_buf_get_height (mask);
|
|
|
|
|
|
|
|
image = gimp_image_new (gimp, width, height, base_type,
|
|
|
|
GIMP_PRECISION_U8_NON_LINEAR);
|
|
|
|
|
2019-09-23 19:49:36 +02:00
|
|
|
string = g_string_new (NULL);
|
|
|
|
writer = gimp_config_writer_new_from_string (string);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "spacing");
|
|
|
|
gimp_config_writer_printf (writer, "%d", gimp_brush_get_spacing (brush));
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
|
|
|
gimp_config_writer_linefeed (writer);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "description");
|
|
|
|
gimp_config_writer_string (writer, gimp_object_get_name (brush));
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
|
|
|
gimp_config_writer_finish (writer, NULL, NULL);
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new ("GimpProcedureConfig-file-gbr-save-last",
|
2019-02-27 00:06:17 +01:00
|
|
|
GIMP_PARASITE_PERSISTENT,
|
2019-09-23 19:49:36 +02:00
|
|
|
string->len + 1, string->str);
|
2019-05-30 16:44:23 +02:00
|
|
|
gimp_image_parasite_attach (image, parasite, FALSE);
|
2019-02-27 00:06:17 +01:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
|
2019-09-23 19:49:36 +02:00
|
|
|
g_string_free (string, TRUE);
|
|
|
|
|
2019-02-27 00:06:17 +01:00
|
|
|
layer = file_gbr_brush_to_layer (image, brush);
|
|
|
|
gimp_image_add_layer (image, layer, NULL, 0, FALSE);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpBrush *
|
2023-10-16 15:30:12 +02:00
|
|
|
file_gbr_image_to_brush (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
const gchar *name,
|
|
|
|
gdouble spacing)
|
2019-02-27 00:06:17 +01:00
|
|
|
{
|
2023-10-16 15:30:12 +02:00
|
|
|
GimpBrush *brush;
|
|
|
|
GimpImage *subimage = NULL;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2019-02-27 00:06:17 +01:00
|
|
|
|
2023-10-16 15:30:12 +02:00
|
|
|
g_return_val_if_fail (n_drawables > 0, NULL);
|
libgimp: PDB procedure arguments are not order-based anymore (API-wise).
As far as plug-in API is concerned, at least the calling API, order of arguments
when calling PDB procedures doesn't matter anymore.
Order still matters for creating procedures with standard arguments (for
instance, "run-mode" is first, then image, or file, drawables or whatnot,
depending on the subtype of procedure), but not for calling with libgimp.
Concretely in this commit:
- gimp_pdb_run_procedure_argv() was removed as it's intrinsically order-based.
- gimp_pdb_run_procedure() and gimp_pdb_run_procedure_valist() stay but their
semantic changes. Instead of an ordered list of (type, value) couple, it's now
an unordered list of (name, type, value) triplets. This way, you can also
ignore as many args as you want if you intend to keep them default. For
instance, say you have a procedure with 20 args and you only want to change
the last one and keep the 19 first with default values: while you used to have
to write down all 20 args annoyingly, now you can just list the only arg you
care about.
There are 2 important consequences here:
1. Calling PDB procedures becomes much more semantic, which means scripts with
PDB calls are simpler (smaller list of arguments) and easier to read (when
you had 5 int arguments in a row, you couldn't know what they refer to,
except by always checking the PDB source; now you'll have associated names,
such as "width", "height" and so on) hence maintain.
2. We will have the ability to add arguments and even order the new arguments in
middle of existing arguments without breaking compatibility. The only thing
which will matter will be that default values of new arguments will have to
behave like when the arg didn't exist. This way, existing scripts will not be
broken. This will avoid us having to always create variants of PDB procedure
(like original "file-bla-save", then variant "file-bla-save-2" and so on)
each time we add arguments.
Note: gimp_pdb_run_procedure_array() was not removed yet because it's currently
used by the PDB. To be followed.
2023-10-16 16:44:06 +02:00
|
|
|
g_return_val_if_fail (drawables != NULL, NULL);
|
2023-10-16 15:30:12 +02:00
|
|
|
|
|
|
|
if (n_drawables > 1)
|
|
|
|
{
|
|
|
|
GList *drawable_list = NULL;
|
|
|
|
|
|
|
|
for (gint i = 0; i < n_drawables; i++)
|
|
|
|
drawable_list = g_list_prepend (drawable_list, drawables[i]);
|
|
|
|
|
|
|
|
subimage = gimp_image_new_from_drawables (image->gimp, drawable_list, FALSE, FALSE);
|
|
|
|
g_list_free (drawable_list);
|
|
|
|
gimp_container_remove (image->gimp->images, GIMP_OBJECT (subimage));
|
|
|
|
gimp_image_resize_to_layers (subimage, context,
|
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
|
|
|
drawable = GIMP_DRAWABLE (gimp_image_merge_visible_layers (subimage, context, GIMP_CLIP_TO_IMAGE,
|
|
|
|
FALSE, TRUE, NULL));
|
|
|
|
gimp_pickable_flush (GIMP_PICKABLE (subimage));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawable = drawables[0];
|
|
|
|
}
|
|
|
|
width = gimp_item_get_width (GIMP_ITEM (drawable));
|
|
|
|
height = gimp_item_get_height (GIMP_ITEM (drawable));
|
|
|
|
|
|
|
|
brush = file_gbr_drawable_to_brush (drawable,
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
name, spacing);
|
|
|
|
g_clear_object (&subimage);
|
|
|
|
|
|
|
|
return brush;
|
2019-02-27 00:06:17 +01:00
|
|
|
}
|