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"
|
#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
|
void
|
||||||
gimp_image_get_preview_size (GimpViewable *viewable,
|
gimp_image_get_preview_size (GimpViewable *viewable,
|
||||||
gint size,
|
gint size,
|
||||||
|
@ -107,7 +127,6 @@ gimp_image_get_new_preview (GimpViewable *viewable,
|
||||||
{
|
{
|
||||||
GimpImage *image = GIMP_IMAGE (viewable);
|
GimpImage *image = GIMP_IMAGE (viewable);
|
||||||
const Babl *format;
|
const Babl *format;
|
||||||
GimpTRCType trc;
|
|
||||||
GimpTempBuf *buf;
|
GimpTempBuf *buf;
|
||||||
gdouble scale_x;
|
gdouble scale_x;
|
||||||
gdouble scale_y;
|
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_x = (gdouble) width / (gdouble) gimp_image_get_width (image);
|
||||||
scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image);
|
scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image);
|
||||||
|
|
||||||
format = gimp_projectable_get_format (GIMP_PROJECTABLE (image));
|
format = gimp_image_get_preview_format (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));
|
|
||||||
|
|
||||||
buf = gimp_temp_buf_new (width, height, format);
|
buf = gimp_temp_buf_new (width, height, format);
|
||||||
|
|
||||||
|
|
|
@ -19,30 +19,33 @@
|
||||||
#define __GIMP_IMAGE_PREVIEW_H__
|
#define __GIMP_IMAGE_PREVIEW_H__
|
||||||
|
|
||||||
|
|
||||||
|
const Babl * gimp_image_get_preview_format (GimpImage *image);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* virtual functions of GimpImage -- don't call directly
|
* virtual functions of GimpImage -- don't call directly
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gimp_image_get_preview_size (GimpViewable *viewable,
|
void gimp_image_get_preview_size (GimpViewable *viewable,
|
||||||
gint size,
|
gint size,
|
||||||
gboolean is_popup,
|
gboolean is_popup,
|
||||||
gboolean dot_for_dot,
|
gboolean dot_for_dot,
|
||||||
gint *width,
|
gint *width,
|
||||||
gint *height);
|
gint *height);
|
||||||
gboolean gimp_image_get_popup_size (GimpViewable *viewable,
|
gboolean gimp_image_get_popup_size (GimpViewable *viewable,
|
||||||
gint width,
|
gint width,
|
||||||
gint height,
|
gint height,
|
||||||
gboolean dot_for_dot,
|
gboolean dot_for_dot,
|
||||||
gint *popup_width,
|
gint *popup_width,
|
||||||
gint *popup_height);
|
gint *popup_height);
|
||||||
GimpTempBuf * gimp_image_get_new_preview (GimpViewable *viewable,
|
GimpTempBuf * gimp_image_get_new_preview (GimpViewable *viewable,
|
||||||
GimpContext *context,
|
GimpContext *context,
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height);
|
||||||
GdkPixbuf * gimp_image_get_new_pixbuf (GimpViewable *viewable,
|
GdkPixbuf * gimp_image_get_new_pixbuf (GimpViewable *viewable,
|
||||||
GimpContext *context,
|
GimpContext *context,
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_IMAGE_PREVIEW_H__ */
|
#endif /* __GIMP_IMAGE_PREVIEW_H__ */
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "gimpimage.h"
|
#include "gimpimage.h"
|
||||||
#include "gimpimage-color-profile.h"
|
#include "gimpimage-color-profile.h"
|
||||||
|
#include "gimpimage-preview.h"
|
||||||
#include "gimpimageviewable.h"
|
#include "gimpimageviewable.h"
|
||||||
#include "gimppickable.h"
|
#include "gimppickable.h"
|
||||||
#include "gimpprojectable.h"
|
#include "gimpprojectable.h"
|
||||||
|
@ -317,7 +318,6 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
|
||||||
GimpPickable *pickable;
|
GimpPickable *pickable;
|
||||||
const Babl *format;
|
const Babl *format;
|
||||||
GeglRectangle bounding_box;
|
GeglRectangle bounding_box;
|
||||||
GimpTRCType trc;
|
|
||||||
GimpTempBuf *buf;
|
GimpTempBuf *buf;
|
||||||
gdouble scale_x;
|
gdouble scale_x;
|
||||||
gdouble scale_y;
|
gdouble scale_y;
|
||||||
|
@ -335,13 +335,7 @@ gimp_image_viewable_get_new_preview (GimpViewable *viewable,
|
||||||
|
|
||||||
scale = MIN (scale_x, scale_y);
|
scale = MIN (scale_x, scale_y);
|
||||||
|
|
||||||
format = gimp_projectable_get_format (GIMP_PROJECTABLE (image));
|
format = gimp_image_get_preview_format (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));
|
|
||||||
|
|
||||||
buf = gimp_temp_buf_new (width, height, format);
|
buf = gimp_temp_buf_new (width, height, format);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue