[gimp] app: add gimp_image_get_preview_format()
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_image_get_preview_format()
- Date: Mon, 4 Nov 2019 11:33:20 +0000 (UTC)
commit 74009c8b1e11506cdb487b39f6230a9bccf11d53
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.
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 34fbb768fb..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;
- GimpTRCType trc;
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));
- trc = gimp_babl_format_get_trc (format);
-
- format = gimp_babl_format (gimp_babl_format_get_base_type (format),
- gimp_babl_precision (GIMP_COMPONENT_TYPE_U8, trc),
- babl_format_has_alpha (format),
- babl_format_get_space (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 8dfeca9cd6..b13b32de80 100644
--- a/app/core/gimpimageviewable.c
+++ b/app/core/gimpimageviewable.c
@@ -34,6 +34,7 @@
#include "gimpimage.h"
#include "gimpimage-color-profile.h"
+#include "gimpimage-preview.h"
#include "gimpimageviewable.h"
#include "gimppickable.h"
#include "gimpprojectable.h"
@@ -317,7 +318,6 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
GimpPickable *pickable;
const Babl *format;
GeglRectangle bounding_box;
- GimpTRCType trc;
GimpTempBuf *buf;
gdouble scale_x;
gdouble scale_y;
@@ -335,13 +335,7 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
scale = MIN (scale_x, scale_y);
- format = gimp_projectable_get_format (GIMP_PROJECTABLE (image));
- trc = gimp_babl_format_get_trc (format);
-
- format = gimp_babl_format (gimp_babl_format_get_base_type (format),
- gimp_babl_precision (GIMP_COMPONENT_TYPE_U8, trc),
- babl_format_has_alpha (format),
- babl_format_get_space (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]