[gimp/gimp-2-10] app: add gimp_image_get_preview_format()



commit e2fe79d859ff437fcd8ee6aa8794a34162980dbe
Author: Ell <ell_se yahoo com>
Date:   Mon Nov 4 12:42:34 2019 +0200

    app: add gimp_image_get_preview_format()
    
    Add an internal gimp_image_get_preview_format(), which returns the
    format to use for preview buffers, and use it in both
    gimpimage-preview and GimpImageViewable, to reduce duplication.
    
    (cherry picked from commit 74009c8b1e11506cdb487b39f6230a9bccf11d53)

 app/core/gimpimage-preview.c | 29 +++++++++++++++++++++--------
 app/core/gimpimage-preview.h | 43 +++++++++++++++++++++++--------------------
 app/core/gimpimageviewable.c | 10 ++--------
 3 files changed, 46 insertions(+), 36 deletions(-)
---
diff --git a/app/core/gimpimage-preview.c b/app/core/gimpimage-preview.c
index 2840635595..e28865e2dc 100644
--- a/app/core/gimpimage-preview.c
+++ b/app/core/gimpimage-preview.c
@@ -37,6 +37,26 @@
 #include "gimptempbuf.h"
 
 
+const Babl *
+gimp_image_get_preview_format (GimpImage *image)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  switch (gimp_image_get_base_type (image))
+    {
+    case GIMP_RGB:
+    case GIMP_GRAY:
+      return gimp_babl_format_change_component_type (
+        gimp_projectable_get_format (GIMP_PROJECTABLE (image)),
+        GIMP_COMPONENT_TYPE_U8);
+
+    case GIMP_INDEXED:
+      return babl_format ("R'G'B'A u8");
+    }
+
+  g_return_val_if_reached (NULL);
+}
+
 void
 gimp_image_get_preview_size (GimpViewable *viewable,
                              gint          size,
@@ -107,7 +127,6 @@ gimp_image_get_new_preview (GimpViewable *viewable,
 {
   GimpImage   *image = GIMP_IMAGE (viewable);
   const Babl  *format;
-  gboolean     linear;
   GimpTempBuf *buf;
   gdouble      scale_x;
   gdouble      scale_y;
@@ -115,13 +134,7 @@ gimp_image_get_new_preview (GimpViewable *viewable,
   scale_x = (gdouble) width  / (gdouble) gimp_image_get_width  (image);
   scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image);
 
-  format = gimp_projectable_get_format (GIMP_PROJECTABLE (image));
-  linear = gimp_babl_format_get_linear (format);
-
-  format = gimp_babl_format (gimp_babl_format_get_base_type (format),
-                             gimp_babl_precision (GIMP_COMPONENT_TYPE_U8,
-                                                  linear),
-                             babl_format_has_alpha (format));
+  format = gimp_image_get_preview_format (image);
 
   buf = gimp_temp_buf_new (width, height, format);
 
diff --git a/app/core/gimpimage-preview.h b/app/core/gimpimage-preview.h
index 4cf47f12f1..f8b22c0a43 100644
--- a/app/core/gimpimage-preview.h
+++ b/app/core/gimpimage-preview.h
@@ -19,30 +19,33 @@
 #define __GIMP_IMAGE_PREVIEW_H__
 
 
+const Babl  * gimp_image_get_preview_format (GimpImage    *image);
+
+
 /*
  *  virtual functions of GimpImage -- don't call directly
  */
 
-void          gimp_image_get_preview_size (GimpViewable *viewable,
-                                           gint          size,
-                                           gboolean      is_popup,
-                                           gboolean      dot_for_dot,
-                                           gint         *width,
-                                           gint         *height);
-gboolean      gimp_image_get_popup_size   (GimpViewable *viewable,
-                                           gint          width,
-                                           gint          height,
-                                           gboolean      dot_for_dot,
-                                           gint         *popup_width,
-                                           gint         *popup_height);
-GimpTempBuf * gimp_image_get_new_preview  (GimpViewable *viewable,
-                                           GimpContext  *context,
-                                           gint          width,
-                                           gint          height);
-GdkPixbuf   * gimp_image_get_new_pixbuf   (GimpViewable *viewable,
-                                           GimpContext  *context,
-                                           gint          width,
-                                           gint          height);
+void          gimp_image_get_preview_size   (GimpViewable *viewable,
+                                             gint          size,
+                                             gboolean      is_popup,
+                                             gboolean      dot_for_dot,
+                                             gint         *width,
+                                             gint         *height);
+gboolean      gimp_image_get_popup_size     (GimpViewable *viewable,
+                                             gint          width,
+                                             gint          height,
+                                             gboolean      dot_for_dot,
+                                             gint         *popup_width,
+                                             gint         *popup_height);
+GimpTempBuf * gimp_image_get_new_preview    (GimpViewable *viewable,
+                                             GimpContext  *context,
+                                             gint          width,
+                                             gint          height);
+GdkPixbuf   * gimp_image_get_new_pixbuf     (GimpViewable *viewable,
+                                             GimpContext  *context,
+                                             gint          width,
+                                             gint          height);
 
 
 #endif /* __GIMP_IMAGE_PREVIEW_H__ */
diff --git a/app/core/gimpimageviewable.c b/app/core/gimpimageviewable.c
index 8bfdccbef0..e8ea30f3a4 100644
--- a/app/core/gimpimageviewable.c
+++ b/app/core/gimpimageviewable.c
@@ -33,6 +33,7 @@
 
 #include "gimpimage.h"
 #include "gimpimage-color-profile.h"
+#include "gimpimage-preview.h"
 #include "gimpimageviewable.h"
 #include "gimppickable.h"
 #include "gimpprojectable.h"
@@ -316,7 +317,6 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
   GimpPickable      *pickable;
   const Babl        *format;
   GeglRectangle      bounding_box;
-  gboolean           linear;
   GimpTempBuf       *buf;
   gdouble            scale_x;
   gdouble            scale_y;
@@ -334,13 +334,7 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
 
   scale   = MIN (scale_x, scale_y);
 
-  format = gimp_projectable_get_format (GIMP_PROJECTABLE (image));
-  linear = gimp_babl_format_get_linear (format);
-
-  format = gimp_babl_format (gimp_babl_format_get_base_type (format),
-                             gimp_babl_precision (GIMP_COMPONENT_TYPE_U8,
-                                                  linear),
-                             babl_format_has_alpha (format));
+  format = gimp_image_get_preview_format (image);
 
   buf = gimp_temp_buf_new (width, height, format);
 


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