[gimp] app: factor file_gbr_brush_to_layer() out of the brush-to-image logic
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: factor file_gbr_brush_to_layer() out of the brush-to-image logic
- Date: Tue, 19 Feb 2019 22:45:02 +0000 (UTC)
commit 3b89ae40d0817e4cc71ba400fcde6d01583d8909
Author: Michael Natterer <mitch gimp org>
Date: Tue Feb 19 23:13:59 2019 +0100
app: factor file_gbr_brush_to_layer() out of the brush-to-image logic
of file-gbr-load, and add some layer handling magic that doesn't
change a thing for simple brushes, but is needed for loading brush
pipes.
app/file-data/file-data-gbr.c | 119 +++++++++++++++++++++++++++++-------------
app/file-data/file-data-gbr.h | 27 +++++-----
2 files changed, 99 insertions(+), 47 deletions(-)
---
diff --git a/app/file-data/file-data-gbr.c b/app/file-data/file-data-gbr.c
index 24ece2c5d0..03aaea5787 100644
--- a/app/file-data/file-data-gbr.c
+++ b/app/file-data/file-data-gbr.c
@@ -33,6 +33,7 @@
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimplayer-new.h"
+#include "core/gimpimage-resize.h"
#include "core/gimpparamspecs.h"
#include "core/gimptempbuf.h"
@@ -154,55 +155,62 @@ file_gbr_save_invoker (GimpProcedure *procedure,
return return_vals;
}
-
-/* private functions */
-
-static GimpImage *
-file_gbr_brush_to_image (Gimp *gimp,
+GimpLayer *
+file_gbr_brush_to_layer (GimpImage *image,
GimpBrush *brush)
{
- GimpImage *image;
- GimpLayer *layer;
- const Babl *format;
- const gchar *name;
- GimpImageBaseType base_type;
- gboolean alpha;
- gint width;
- gint height;
- GimpTempBuf *mask = gimp_brush_get_mask (brush);
- GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
- GeglBuffer *buffer;
- GimpParasite *parasite;
+ 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);
if (pixmap)
- {
- base_type = GIMP_RGB;
- alpha = TRUE;
- }
+ alpha = TRUE;
else
- {
- base_type = GIMP_GRAY;
- alpha = FALSE;
- }
+ alpha = FALSE;
- name = gimp_object_get_name (brush);
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_PERCEPTUAL);
+ image_width = gimp_image_get_width (image);
+ image_height = gimp_image_get_height (image);
- parasite = gimp_parasite_new ("gimp-brush-name",
- GIMP_PARASITE_PERSISTENT,
- strlen (name) + 1, name);
- gimp_image_parasite_attach (image, parasite);
- gimp_parasite_free (parasite);
+ 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;
+ }
format = gimp_image_get_layer_format (image, alpha);
- layer = gimp_layer_new (image, width, height, format, name,
+ layer = gimp_layer_new (image, width, height, format,
+ gimp_object_get_name (brush),
1.0, GIMP_LAYER_MODE_NORMAL);
- gimp_image_add_layer (image, layer, NULL, 0, FALSE);
+
+ gimp_item_set_offset (GIMP_ITEM (layer),
+ (image_width - width) / 2,
+ (image_height - height) / 2);
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
@@ -243,6 +251,47 @@ file_gbr_brush_to_image (Gimp *gimp,
mask_data, GEGL_AUTO_ROWSTRIDE);
}
+ return layer;
+}
+
+
+/* private functions */
+
+static GimpImage *
+file_gbr_brush_to_image (Gimp *gimp,
+ GimpBrush *brush)
+{
+ GimpImage *image;
+ GimpLayer *layer;
+ const gchar *name;
+ GimpImageBaseType base_type;
+ gint width;
+ gint height;
+ GimpTempBuf *mask = gimp_brush_get_mask (brush);
+ GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
+ GimpParasite *parasite;
+
+ if (pixmap)
+ base_type = GIMP_RGB;
+ else
+ base_type = GIMP_GRAY;
+
+ name = gimp_object_get_name (brush);
+ 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_PERCEPTUAL);
+
+ parasite = gimp_parasite_new ("gimp-brush-name",
+ GIMP_PARASITE_PERSISTENT,
+ strlen (name) + 1, name);
+ gimp_image_parasite_attach (image, parasite);
+ gimp_parasite_free (parasite);
+
+ layer = file_gbr_brush_to_layer (image, brush);
+ gimp_image_add_layer (image, layer, NULL, 0, FALSE);
+
return image;
}
diff --git a/app/file-data/file-data-gbr.h b/app/file-data/file-data-gbr.h
index 3cc355ef50..02fc57490c 100644
--- a/app/file-data/file-data-gbr.h
+++ b/app/file-data/file-data-gbr.h
@@ -19,19 +19,22 @@
#define __FILE_DATA_GBR_H__
-GimpValueArray * file_gbr_load_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GimpValueArray *args,
- GError **error);
+GimpValueArray * file_gbr_load_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error);
-GimpValueArray * file_gbr_save_invoker (GimpProcedure *procedure,
- Gimp *gimp,
- GimpContext *context,
- GimpProgress *progress,
- const GimpValueArray *args,
- GError **error);
+GimpValueArray * file_gbr_save_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error);
+
+GimpLayer * file_gbr_brush_to_layer (GimpImage *image,
+ GimpBrush *brush);
#endif /* __FILE_DATA_GBR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]