[gimp] app, pdb: use compat formats for brushes/patterns in plug-ins



commit 82c449496e55ace64527f21ceb91f63b5bdd1fc9
Author: Ell <ell_se yahoo com>
Date:   Thu Feb 7 09:12:53 2019 -0500

    app, pdb: use compat formats for brushes/patterns in plug-ins
    
    Plug-ins are not prepared to handle high-precision brushes/
    patterns, even when they're otherwise aware of high-precision
    drawables, so make sure to always use compat formats when
    communicating brush/pattern data to plug-ins.
    
    Allowing plug-ins to handle high-precision brush/pattern data would
    require some additional API.

 app/gegl/gimp-babl-compat.c     | 10 ++++++++++
 app/gegl/gimp-babl-compat.h     |  1 +
 app/pdb/brush-cmds.c            | 44 +++++++++++++++++++++++++++++++----------
 app/pdb/pattern-cmds.c          | 22 +++++++++++++++++----
 app/widgets/gimpbrushselect.c   | 15 ++++++++++++--
 app/widgets/gimppatternselect.c | 16 +++++++++++++--
 pdb/groups/brush.pdb            | 44 +++++++++++++++++++++++++++++++----------
 pdb/groups/pattern.pdb          | 22 +++++++++++++++++----
 8 files changed, 142 insertions(+), 32 deletions(-)
---
diff --git a/app/gegl/gimp-babl-compat.c b/app/gegl/gimp-babl-compat.c
index 4f987c6a64..629ba6d4a3 100644
--- a/app/gegl/gimp-babl-compat.c
+++ b/app/gegl/gimp-babl-compat.c
@@ -88,3 +88,13 @@ gimp_babl_compat_u8_format (const Babl *format)
                            babl_format_has_alpha (format),
                            babl_format_get_space (format));
 }
+
+const Babl *
+gimp_babl_compat_u8_mask_format (const Babl *format)
+{
+  g_return_val_if_fail (format != NULL, NULL);
+
+  return gimp_babl_format (gimp_babl_format_get_base_type (format),
+                           GIMP_PRECISION_U8_LINEAR,
+                           FALSE);
+}
diff --git a/app/gegl/gimp-babl-compat.h b/app/gegl/gimp-babl-compat.h
index a342141c09..778bf3ec90 100644
--- a/app/gegl/gimp-babl-compat.h
+++ b/app/gegl/gimp-babl-compat.h
@@ -25,6 +25,7 @@
 GimpImageType   gimp_babl_format_get_image_type (const Babl *format);
 
 const Babl    * gimp_babl_compat_u8_format      (const Babl *format);
+const Babl    * gimp_babl_compat_u8_mask_format (const Babl *format);
 
 
 #endif /* __GIMP_BABL_COMPAT_H__ */
diff --git a/app/pdb/brush-cmds.c b/app/pdb/brush-cmds.c
index 45d9b22773..2415d63318 100644
--- a/app/pdb/brush-cmds.c
+++ b/app/pdb/brush-cmds.c
@@ -36,6 +36,7 @@
 #include "core/gimpdatafactory.h"
 #include "core/gimpparamspecs.h"
 #include "core/gimptempbuf.h"
+#include "gegl/gimp-babl-compat.h"
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
@@ -283,11 +284,22 @@ brush_get_info_invoker (GimpProcedure         *procedure,
         {
           GimpTempBuf *mask   = gimp_brush_get_mask (brush);
           GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
+          const Babl  *format;
 
-          width     = gimp_brush_get_width  (brush);
-          height    = gimp_brush_get_height (brush);
-          mask_bpp  = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
-          color_bpp = pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap)) : 0;
+          format = gimp_babl_compat_u8_mask_format (
+            gimp_temp_buf_get_format (mask));
+
+          width    = gimp_brush_get_width  (brush);
+          height   = gimp_brush_get_height (brush);
+          mask_bpp = babl_format_get_bytes_per_pixel (format);
+
+          if (pixmap)
+            {
+              format = gimp_babl_compat_u8_format (
+                gimp_temp_buf_get_format (pixmap));
+
+              color_bpp = babl_format_get_bytes_per_pixel (format);
+            }
         }
       else
         success = FALSE;
@@ -337,23 +349,35 @@ brush_get_pixels_invoker (GimpProcedure         *procedure,
         {
           GimpTempBuf *mask   = gimp_brush_get_mask (brush);
           GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
+          const Babl  *format;
+          gpointer     data;
+
+          format = gimp_babl_compat_u8_mask_format (
+            gimp_temp_buf_get_format (mask));
+          data   = gimp_temp_buf_lock (mask, format, GEGL_ACCESS_READ);
 
           width          = gimp_temp_buf_get_width  (mask);
           height         = gimp_temp_buf_get_height (mask);
-          mask_bpp       = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
+          mask_bpp       = babl_format_get_bytes_per_pixel (format);
           num_mask_bytes = gimp_temp_buf_get_height (mask) *
                            gimp_temp_buf_get_width  (mask) * mask_bpp;
-          mask_bytes     = g_memdup (gimp_temp_buf_get_data (mask),
-                                     num_mask_bytes);
+          mask_bytes     = g_memdup (data, num_mask_bytes);
+
+          gimp_temp_buf_unlock (mask, data);
 
           if (pixmap)
             {
-              color_bpp       = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap));
+              format = gimp_babl_compat_u8_format (
+                gimp_temp_buf_get_format (pixmap));
+              data   = gimp_temp_buf_lock (pixmap, format, GEGL_ACCESS_READ);
+
+              color_bpp       = babl_format_get_bytes_per_pixel (format);
               num_color_bytes = gimp_temp_buf_get_height (pixmap) *
                                 gimp_temp_buf_get_width  (pixmap) *
                                 color_bpp;
-              color_bytes     = g_memdup (gimp_temp_buf_get_data (pixmap),
-                                          num_color_bytes);
+              color_bytes     = g_memdup (data, num_color_bytes);
+
+              gimp_temp_buf_unlock (pixmap, data);
             }
         }
       else
diff --git a/app/pdb/pattern-cmds.c b/app/pdb/pattern-cmds.c
index d5564d4d28..e9a67d9b3c 100644
--- a/app/pdb/pattern-cmds.c
+++ b/app/pdb/pattern-cmds.c
@@ -34,6 +34,7 @@
 #include "core/gimpparamspecs.h"
 #include "core/gimppattern.h"
 #include "core/gimptempbuf.h"
+#include "gegl/gimp-babl-compat.h"
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
@@ -64,9 +65,14 @@ pattern_get_info_invoker (GimpProcedure         *procedure,
 
       if (pattern)
         {
+          const Babl *format;
+
+          format = gimp_babl_compat_u8_format (
+            gimp_temp_buf_get_format (pattern->mask));
+
           width  = gimp_temp_buf_get_width  (pattern->mask);
           height = gimp_temp_buf_get_height (pattern->mask);
-          bpp    = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask));
+          bpp    = babl_format_get_bytes_per_pixel (format);
         }
       else
         success = FALSE;
@@ -110,12 +116,20 @@ pattern_get_pixels_invoker (GimpProcedure         *procedure,
 
       if (pattern)
         {
+          const Babl *format;
+          gpointer    data;
+
+          format = gimp_babl_compat_u8_format (
+            gimp_temp_buf_get_format (pattern->mask));
+          data   = gimp_temp_buf_lock (pattern->mask, format, GEGL_ACCESS_READ);
+
           width           = gimp_temp_buf_get_width  (pattern->mask);
           height          = gimp_temp_buf_get_height (pattern->mask);
-          bpp             = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask));
+          bpp             = babl_format_get_bytes_per_pixel (format);
           num_color_bytes = gimp_temp_buf_get_data_size (pattern->mask);
-          color_bytes     = g_memdup (gimp_temp_buf_get_data (pattern->mask),
-                                      num_color_bytes);
+          color_bytes     = g_memdup (data, num_color_bytes);
+
+          gimp_temp_buf_unlock (pattern->mask, data);
         }
       else
         success = FALSE;
diff --git a/app/widgets/gimpbrushselect.c b/app/widgets/gimpbrushselect.c
index 67d2101915..c27116b92a 100644
--- a/app/widgets/gimpbrushselect.c
+++ b/app/widgets/gimpbrushselect.c
@@ -28,6 +28,8 @@
 
 #include "widgets-types.h"
 
+#include "gegl/gimp-babl-compat.h"
+
 #include "core/gimp.h"
 #include "core/gimpcontext.h"
 #include "core/gimpbrush.h"
@@ -259,11 +261,18 @@ gimp_brush_select_run_callback (GimpPdbDialog  *dialog,
 {
   GimpBrush      *brush = GIMP_BRUSH (object);
   GimpTempBuf    *mask  = gimp_brush_get_mask (brush);
+  const Babl     *format;
+  gpointer        data;
   GimpArray      *array;
   GimpValueArray *return_vals;
 
-  array = gimp_array_new (gimp_temp_buf_get_data (mask),
-                          gimp_temp_buf_get_data_size (mask),
+  format = gimp_babl_compat_u8_mask_format (gimp_temp_buf_get_format (mask));
+  data   = gimp_temp_buf_lock (mask, format, GEGL_ACCESS_READ);
+
+  array = gimp_array_new (data,
+                          gimp_temp_buf_get_width         (mask) *
+                          gimp_temp_buf_get_height        (mask) *
+                          babl_format_get_bytes_per_pixel (format),
                           TRUE);
 
   return_vals =
@@ -284,6 +293,8 @@ gimp_brush_select_run_callback (GimpPdbDialog  *dialog,
 
   gimp_array_free (array);
 
+  gimp_temp_buf_unlock (mask, data);
+
   return return_vals;
 }
 
diff --git a/app/widgets/gimppatternselect.c b/app/widgets/gimppatternselect.c
index 232be605f1..6cd3b5ae55 100644
--- a/app/widgets/gimppatternselect.c
+++ b/app/widgets/gimppatternselect.c
@@ -28,6 +28,8 @@
 
 #include "widgets-types.h"
 
+#include "gegl/gimp-babl-compat.h"
+
 #include "core/gimp.h"
 #include "core/gimpcontext.h"
 #include "core/gimpparamspecs.h"
@@ -103,11 +105,19 @@ gimp_pattern_select_run_callback (GimpPdbDialog  *dialog,
                                   GError        **error)
 {
   GimpPattern    *pattern = GIMP_PATTERN (object);
+  const Babl     *format;
+  gpointer        data;
   GimpArray      *array;
   GimpValueArray *return_vals;
 
-  array = gimp_array_new (gimp_temp_buf_get_data (pattern->mask),
-                          gimp_temp_buf_get_data_size (pattern->mask),
+  format = gimp_babl_compat_u8_format (
+    gimp_temp_buf_get_format (pattern->mask));
+  data   = gimp_temp_buf_lock (pattern->mask, format, GEGL_ACCESS_READ);
+
+  array = gimp_array_new (data,
+                          gimp_temp_buf_get_width         (pattern->mask) *
+                          gimp_temp_buf_get_height        (pattern->mask) *
+                          babl_format_get_bytes_per_pixel (format),
                           TRUE);
 
   return_vals =
@@ -126,5 +136,7 @@ gimp_pattern_select_run_callback (GimpPdbDialog  *dialog,
 
   gimp_array_free (array);
 
+  gimp_temp_buf_unlock (pattern->mask, data);
+
   return return_vals;
 }
diff --git a/pdb/groups/brush.pdb b/pdb/groups/brush.pdb
index fe6112b690..b01cebd411 100644
--- a/pdb/groups/brush.pdb
+++ b/pdb/groups/brush.pdb
@@ -243,11 +243,22 @@ HELP
     {
       GimpTempBuf *mask   = gimp_brush_get_mask (brush);
       GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
+      const Babl  *format;
 
-      width     = gimp_brush_get_width  (brush);
-      height    = gimp_brush_get_height (brush);
-      mask_bpp  = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
-      color_bpp = pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap)) : 0;
+      format = gimp_babl_compat_u8_mask_format (
+        gimp_temp_buf_get_format (mask));
+
+      width    = gimp_brush_get_width  (brush);
+      height   = gimp_brush_get_height (brush);
+      mask_bpp = babl_format_get_bytes_per_pixel (format);
+
+      if (pixmap)
+        {
+          format = gimp_babl_compat_u8_format (
+            gimp_temp_buf_get_format (pixmap));
+
+          color_bpp = babl_format_get_bytes_per_pixel (format);
+        }
     }
   else
     success = FALSE;
@@ -297,23 +308,35 @@ HELP
     {
       GimpTempBuf *mask   = gimp_brush_get_mask (brush);
       GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
+      const Babl  *format;
+      gpointer     data;
+
+      format = gimp_babl_compat_u8_mask_format (
+        gimp_temp_buf_get_format (mask));
+      data   = gimp_temp_buf_lock (mask, format, GEGL_ACCESS_READ);
 
       width          = gimp_temp_buf_get_width  (mask);
       height         = gimp_temp_buf_get_height (mask);
-      mask_bpp       = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
+      mask_bpp       = babl_format_get_bytes_per_pixel (format);
       num_mask_bytes = gimp_temp_buf_get_height (mask) *
                        gimp_temp_buf_get_width  (mask) * mask_bpp;
-      mask_bytes     = g_memdup (gimp_temp_buf_get_data (mask),
-                                 num_mask_bytes);
+      mask_bytes     = g_memdup (data, num_mask_bytes);
+
+      gimp_temp_buf_unlock (mask, data);
 
       if (pixmap)
         {
-          color_bpp       = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap));
+          format = gimp_babl_compat_u8_format (
+            gimp_temp_buf_get_format (pixmap));
+          data   = gimp_temp_buf_lock (pixmap, format, GEGL_ACCESS_READ);
+
+          color_bpp       = babl_format_get_bytes_per_pixel (format);
           num_color_bytes = gimp_temp_buf_get_height (pixmap) *
                             gimp_temp_buf_get_width  (pixmap) *
                             color_bpp;
-          color_bytes     = g_memdup (gimp_temp_buf_get_data (pixmap),
-                                      num_color_bytes);
+          color_bytes     = g_memdup (data, num_color_bytes);
+
+          gimp_temp_buf_unlock (pixmap, data);
         }
     }
   else
@@ -849,6 +872,7 @@ CODE
 
 
 @headers = qw(<string.h>
+              "gegl/gimp-babl-compat.h"
               "core/gimp.h"
               "core/gimpbrush.h"
               "core/gimpbrushgenerated.h"
diff --git a/pdb/groups/pattern.pdb b/pdb/groups/pattern.pdb
index 76b4c212a8..2c3959d325 100644
--- a/pdb/groups/pattern.pdb
+++ b/pdb/groups/pattern.pdb
@@ -47,9 +47,14 @@ HELP
 
   if (pattern)
     {
+      const Babl *format;
+
+      format = gimp_babl_compat_u8_format (
+        gimp_temp_buf_get_format (pattern->mask));
+
       width  = gimp_temp_buf_get_width  (pattern->mask);
       height = gimp_temp_buf_get_height (pattern->mask);
-      bpp    = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask));
+      bpp    = babl_format_get_bytes_per_pixel (format);
     }
   else
     success = FALSE;
@@ -95,12 +100,20 @@ HELP
 
   if (pattern)
     {
+      const Babl *format;
+      gpointer    data;
+
+      format = gimp_babl_compat_u8_format (
+        gimp_temp_buf_get_format (pattern->mask));
+      data   = gimp_temp_buf_lock (pattern->mask, format, GEGL_ACCESS_READ);
+
       width           = gimp_temp_buf_get_width  (pattern->mask);
       height          = gimp_temp_buf_get_height (pattern->mask);
-      bpp             = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask));
+      bpp             = babl_format_get_bytes_per_pixel (format);
       num_color_bytes = gimp_temp_buf_get_data_size (pattern->mask);
-      color_bytes     = g_memdup (gimp_temp_buf_get_data (pattern->mask),
-                                  num_color_bytes);
+      color_bytes     = g_memdup (data, num_color_bytes);
+
+      gimp_temp_buf_unlock (pattern->mask, data);
     }
   else
     success = FALSE;
@@ -111,6 +124,7 @@ CODE
 
 
 @headers = qw(<string.h>
+              "gegl/gimp-babl-compat.h"
               "core/gimpcontext.h"
               "core/gimpdatafactory.h"
               "core/gimppattern.h"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]