mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
4374fc3ff0
commit
74009c8b1e
|
@ -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);
|
||||
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue