Commit 68c6e937 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Added GimpViewable infrastructure which enables migrating from TempBuf to

2004-05-13  Michael Natterer  <mitch@gimp.org>

	Added GimpViewable infrastructure which enables migrating from
	TempBuf to GdkPixbuf for both providing and getting previews:

	* app/core/gimpviewable.[ch]: added new virtual functions
	GimpViewable::get_pixbuf() and GimpViewable::get_new_pixbuf()
	which are implemented exactly as get_preview() and
	get_new_preview() except that get_new_pixbuf() has a default
	implementation which creates the pixbuf from a TempBuf.

	Renamed public functions _get_preview_pixbuf() and
	_get_new_preview_pixbuf() to _get_pixbuf() and _get_new_pixbuf().

	Added gimp_viewable_get_dummy_pixbuf() and use it from
	gimp_viewable_get_dummy_preview().

	* app/core/gimpimagefile.c (gimp_imagefile_save_thumb)
	* app/display/gimpdisplayshell.c (gimp_display_shell_update_icon)
	* app/gui/resize-dialog.c (resize_dialog_new): changed accordingly.
parent c2e13dec
2004-05-13 Michael Natterer <mitch@gimp.org>
Added GimpViewable infrastructure which enables migrating from
TempBuf to GdkPixbuf for both providing and getting previews:
* app/core/gimpviewable.[ch]: added new virtual functions
GimpViewable::get_pixbuf() and GimpViewable::get_new_pixbuf()
which are implemented exactly as get_preview() and
get_new_preview() except that get_new_pixbuf() has a default
implementation which creates the pixbuf from a TempBuf.
Renamed public functions _get_preview_pixbuf() and
_get_new_preview_pixbuf() to _get_pixbuf() and _get_new_pixbuf().
Added gimp_viewable_get_dummy_pixbuf() and use it from
gimp_viewable_get_dummy_preview().
* app/core/gimpimagefile.c (gimp_imagefile_save_thumb)
* app/display/gimpdisplayshell.c (gimp_display_shell_update_icon)
* app/gui/resize-dialog.c (resize_dialog_new): changed accordingly.
2004-05-13 Sven Neumann <sven@gimp.org>
* libgimpthumb/gimpthumbnail.[ch]: added mime-type support.
......
......@@ -670,8 +670,8 @@ gimp_imagefile_save_thumb (GimpImagefile *imagefile,
}
}
pixbuf = gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage),
width, height);
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (gimage),
width, height);
/* when layer previews are disabled, we won't get a pixbuf */
if (! pixbuf)
......
......@@ -73,6 +73,9 @@ static gint64 gimp_viewable_get_memsize (GimpObject *object,
static void gimp_viewable_real_invalidate_preview (GimpViewable *viewable);
static GdkPixbuf * gimp_viewable_real_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height);
static void gimp_viewable_real_get_preview_size (GimpViewable *viewable,
gint size,
gboolean popup,
......@@ -181,6 +184,8 @@ gimp_viewable_class_init (GimpViewableClass *klass)
klass->get_popup_size = NULL;
klass->get_preview = NULL;
klass->get_new_preview = NULL;
klass->get_pixbuf = NULL;
klass->get_new_pixbuf = gimp_viewable_real_get_new_pixbuf;
klass->get_description = gimp_viewable_real_get_description;
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_STOCK_ID, "stock-id",
......@@ -304,6 +309,62 @@ gimp_viewable_real_get_preview_size (GimpViewable *viewable,
*height = size;
}
static GdkPixbuf *
gimp_viewable_real_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height)
{
TempBuf *temp_buf;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
temp_buf = gimp_viewable_get_preview (viewable, width, height);
if (temp_buf)
{
TempBuf *color_buf = NULL;
gint width;
gint height;
gint bytes;
bytes = temp_buf->bytes;
width = temp_buf->width;
height = temp_buf->height;
if (bytes == 1 || bytes == 2)
{
gint color_bytes;
color_bytes = (bytes == 2) ? 4 : 3;
color_buf = temp_buf_new (width, height, color_bytes, 0, 0, NULL);
temp_buf_copy (temp_buf, color_buf);
temp_buf = color_buf;
bytes = color_bytes;
}
pixbuf = gdk_pixbuf_new_from_data (g_memdup (temp_buf_data (temp_buf),
width * height * bytes),
GDK_COLORSPACE_RGB,
(bytes == 4),
8,
width,
height,
width * bytes,
(GdkPixbufDestroyNotify) g_free,
NULL);
if (color_buf)
temp_buf_free (color_buf);
}
return pixbuf;
}
static gchar *
gimp_viewable_real_get_description (GimpViewable *viewable,
gchar **tooltip)
......@@ -561,42 +622,17 @@ gimp_viewable_get_dummy_preview (GimpViewable *viewable,
gint height,
gint bpp)
{
GdkPixbuf *icon;
GdkPixbuf *pixbuf;
TempBuf *buf;
guchar *src;
guchar *dest;
gdouble ratio;
gint w, h;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (bpp == 3 || bpp == 4, NULL);
icon = gdk_pixbuf_new_from_inline (-1, stock_question_64, FALSE, NULL);
g_return_val_if_fail (icon != NULL, NULL);
w = gdk_pixbuf_get_width (icon);
h = gdk_pixbuf_get_height (icon);
ratio = (gdouble) MIN (width, height) / (gdouble) MAX (w, h);
ratio = MIN (ratio, 1.0);
w = RINT (ratio * (gdouble) w);
h = RINT (ratio * (gdouble) h);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, (bpp == 4), 8, width, height);
gdk_pixbuf_fill (pixbuf, 0xffffffff);
if (w && h)
gdk_pixbuf_composite (icon, pixbuf,
(width - w) / 2, (height - h) / 2, w, h,
(width - w) / 2, (height - h) / 2, ratio, ratio,
GDK_INTERP_BILINEAR, 0xFF);
g_object_unref (icon);
pixbuf = gimp_viewable_get_dummy_pixbuf (viewable, width, height, bpp);
buf = temp_buf_new (width, height, bpp, 0, 0, NULL);
......@@ -617,26 +653,36 @@ gimp_viewable_get_dummy_preview (GimpViewable *viewable,
}
GdkPixbuf *
gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height)
gimp_viewable_get_pixbuf (GimpViewable *viewable,
gint width,
gint height)
{
GdkPixbuf *pixbuf;
GimpViewableClass *viewable_class;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
if (viewable_class->get_pixbuf)
pixbuf = viewable_class->get_pixbuf (viewable, width, height);
if (pixbuf)
return pixbuf;
pixbuf = g_object_get_qdata (G_OBJECT (viewable), quark_preview_pixbuf);
if (pixbuf &&
gdk_pixbuf_get_width (pixbuf) == width &&
gdk_pixbuf_get_width (pixbuf) == width &&
gdk_pixbuf_get_height (pixbuf) == height)
{
return pixbuf;
}
return pixbuf;
pixbuf = NULL;
pixbuf = gimp_viewable_get_new_preview_pixbuf (viewable, width, height);
if (viewable_class->get_new_pixbuf)
pixbuf = viewable_class->get_new_pixbuf (viewable, width, height);
g_object_set_qdata_full (G_OBJECT (viewable), quark_preview_pixbuf,
pixbuf,
......@@ -646,57 +692,73 @@ gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
}
GdkPixbuf *
gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height)
gimp_viewable_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height)
{
TempBuf *temp_buf;
GdkPixbuf *pixbuf = NULL;
GimpViewableClass *viewable_class;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
temp_buf = gimp_viewable_get_preview (viewable, width, height);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
if (temp_buf)
{
TempBuf *color_buf = NULL;
gint width;
gint height;
gint bytes;
if (viewable_class->get_new_pixbuf)
pixbuf = viewable_class->get_new_pixbuf (viewable, width, height);
bytes = temp_buf->bytes;
width = temp_buf->width;
height = temp_buf->height;
if (pixbuf)
return pixbuf;
if (bytes == 1 || bytes == 2)
{
gint color_bytes;
if (viewable_class->get_pixbuf)
pixbuf = viewable_class->get_pixbuf (viewable, width, height);
color_bytes = (bytes == 2) ? 4 : 3;
if (pixbuf)
return gdk_pixbuf_copy (pixbuf);
color_buf = temp_buf_new (width, height, color_bytes, 0, 0, NULL);
temp_buf_copy (temp_buf, color_buf);
return NULL;
}
temp_buf = color_buf;
bytes = color_bytes;
}
GdkPixbuf *
gimp_viewable_get_dummy_pixbuf (GimpViewable *viewable,
gint width,
gint height,
gint bpp)
{
GdkPixbuf *icon;
GdkPixbuf *pixbuf;
gdouble ratio;
gint w, h;
pixbuf = gdk_pixbuf_new_from_data (g_memdup (temp_buf_data (temp_buf),
width * height * bytes),
GDK_COLORSPACE_RGB,
(bytes == 4),
8,
width,
height,
width * bytes,
(GdkPixbufDestroyNotify) g_free,
NULL);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (bpp == 3 || bpp == 4, NULL);
if (color_buf)
temp_buf_free (color_buf);
}
icon = gdk_pixbuf_new_from_inline (-1, stock_question_64, FALSE, NULL);
g_return_val_if_fail (icon != NULL, NULL);
w = gdk_pixbuf_get_width (icon);
h = gdk_pixbuf_get_height (icon);
ratio = (gdouble) MIN (width, height) / (gdouble) MAX (w, h);
ratio = MIN (ratio, 1.0);
w = RINT (ratio * (gdouble) w);
h = RINT (ratio * (gdouble) h);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, (bpp == 4), 8, width, height);
gdk_pixbuf_fill (pixbuf, 0xffffffff);
if (w && h)
gdk_pixbuf_composite (icon, pixbuf,
(width - w) / 2, (height - h) / 2, w, h,
(width - w) / 2, (height - h) / 2, ratio, ratio,
GDK_INTERP_BILINEAR, 0xFF);
g_object_unref (icon);
return pixbuf;
}
......
......@@ -60,87 +60,98 @@ struct _GimpViewableClass
const gchar *name_changed_signal;
/* signals */
void (* invalidate_preview) (GimpViewable *viewable);
void (* size_changed) (GimpViewable *viewable);
void (* invalidate_preview) (GimpViewable *viewable);
void (* size_changed) (GimpViewable *viewable);
/* virtual functions */
void (* get_preview_size) (GimpViewable *viewable,
gint size,
gboolean is_popup,
gboolean dot_for_dot,
gint *width,
gint *height);
gboolean (* get_popup_size) (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
TempBuf * (* get_preview) (GimpViewable *viewable,
gint width,
gint height);
TempBuf * (* get_new_preview) (GimpViewable *viewable,
gint width,
gint height);
gchar * (* get_description) (GimpViewable *viewable,
gchar **tooltip);
void (* get_preview_size) (GimpViewable *viewable,
gint size,
gboolean is_popup,
gboolean dot_for_dot,
gint *width,
gint *height);
gboolean (* get_popup_size) (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
TempBuf * (* get_preview) (GimpViewable *viewable,
gint width,
gint height);
TempBuf * (* get_new_preview) (GimpViewable *viewable,
gint width,
gint height);
GdkPixbuf * (* get_pixbuf) (GimpViewable *viewable,
gint width,
gint height);
GdkPixbuf * (* get_new_pixbuf) (GimpViewable *viewable,
gint width,
gint height);
gchar * (* get_description) (GimpViewable *viewable,
gchar **tooltip);
};
GType gimp_viewable_get_type (void) G_GNUC_CONST;
void gimp_viewable_invalidate_preview (GimpViewable *viewable);
void gimp_viewable_size_changed (GimpViewable *viewable);
void gimp_viewable_calc_preview_size (gint aspect_width,
gint aspect_height,
gint width,
gint height,
gboolean dot_for_dot,
gdouble xresolution,
gdouble yresolution,
gint *return_width,
gint *return_height,
gboolean *scaling_up);
void gimp_viewable_get_preview_size (GimpViewable *viewable,
gint size,
gboolean popup,
gboolean dot_for_dot,
gint *width,
gint *height);
gboolean gimp_viewable_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
TempBuf * gimp_viewable_get_preview (GimpViewable *viewable,
gint width,
gint height);
TempBuf * gimp_viewable_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
TempBuf * gimp_viewable_get_dummy_preview (GimpViewable *vieable,
gint width,
gint height,
gint bpp);
GdkPixbuf * gimp_viewable_get_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height);
GdkPixbuf * gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
gint width,
gint height);
gchar * gimp_viewable_get_description (GimpViewable *viewable,
gchar **tooltip);
const gchar * gimp_viewable_get_stock_id (GimpViewable *viewable);
void gimp_viewable_set_stock_id (GimpViewable *viewable,
const gchar *stock_id);
GType gimp_viewable_get_type (void) G_GNUC_CONST;
void gimp_viewable_invalidate_preview (GimpViewable *viewable);
void gimp_viewable_size_changed (GimpViewable *viewable);
void gimp_viewable_calc_preview_size (gint aspect_width,
gint aspect_height,
gint width,
gint height,
gboolean dot_for_dot,
gdouble xresolution,
gdouble yresolution,
gint *return_width,
gint *return_height,
gboolean *scaling_up);
void gimp_viewable_get_preview_size (GimpViewable *viewable,
gint size,
gboolean popup,
gboolean dot_for_dot,
gint *width,
gint *height);
gboolean gimp_viewable_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
TempBuf * gimp_viewable_get_preview (GimpViewable *viewable,
gint width,
gint height);
TempBuf * gimp_viewable_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
TempBuf * gimp_viewable_get_dummy_preview (GimpViewable *vieable,
gint width,
gint height,
gint bpp);
GdkPixbuf * gimp_viewable_get_pixbuf (GimpViewable *viewable,
gint width,
gint height);
GdkPixbuf * gimp_viewable_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height);
GdkPixbuf * gimp_viewable_get_dummy_pixbuf (GimpViewable *viewable,
gint width,
gint height,
gint bpp);
gchar * gimp_viewable_get_description (GimpViewable *viewable,
gchar **tooltip);
const gchar * gimp_viewable_get_stock_id (GimpViewable *viewable);
void gimp_viewable_set_stock_id (GimpViewable *viewable,
const gchar *stock_id);
#endif /* __GIMP_VIEWABLE_H__ */
......@@ -540,7 +540,7 @@ resize_dialog_new (GimpViewable *viewable,
gimp_viewable_get_preview_size (viewable, 200, FALSE, TRUE, &w, &h);
pixbuf = gimp_viewable_get_preview_pixbuf (viewable, w, h);
pixbuf = gimp_viewable_get_pixbuf (viewable, w, h);
gimp_offset_area_set_pixbuf (GIMP_OFFSET_AREA (private->offset_area),
pixbuf);
}
......
......@@ -1252,9 +1252,8 @@ gimp_display_shell_update_icon (GimpDisplayShell *shell)
width = MAX (shell->icon_size, 1);
}
pixbuf =
gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (shell->gdisp->gimage),
width, height);
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (shell->gdisp->gimage),
width, height);
gtk_window_set_icon (GTK_WINDOW (shell), pixbuf);
......
......@@ -540,7 +540,7 @@ resize_dialog_new (GimpViewable *viewable,
gimp_viewable_get_preview_size (viewable, 200, FALSE, TRUE, &w, &h);
pixbuf = gimp_viewable_get_preview_pixbuf (viewable, w, h);
pixbuf = gimp_viewable_get_pixbuf (viewable, w, h);
gimp_offset_area_set_pixbuf (GIMP_OFFSET_AREA (private->offset_area),
pixbuf);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment