Commit ab269fc6 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

removed conversion to TempBuf. Instead implement

2004-09-27  Sven Neumann  <sven@gimp.org>

	* app/core/gimpimagefile.c: removed conversion to TempBuf.
	Instead implement GimpViewable::get_new_pixbuf by compositing the
	thumbnail on a checkerboard.

	* app/widgets/gimpviewrenderer.[ch]: renamed the no_view_pixbuf
	struct member to pixbuf.
	(gimp_view_renderer_real_render): try gimp_viewable_get_pixbuf()
	and render the pixbuf before falling back to the TempBuf preview.
	(gimp_view_renderer_render_pixbuf): new function that sets a
	pixbuf for the renderer and flushes the render_buffer.

	* app/widgets/gimpviewrendererimagefile.c
	(gimp_view_renderer_imagefile_render): render the pixbuf.

	* app/dialogs/dialogs-constructors.c: create the document history
	dockable with a zero borderwidth.
parent 75a59c68
2004-09-27 Sven Neumann <sven@gimp.org>
* app/core/gimpimagefile.c: removed conversion to TempBuf.
Instead implement GimpViewable::get_new_pixbuf by compositing the
thumbnail on a checkerboard.
* app/widgets/gimpviewrenderer.[ch]: renamed the no_view_pixbuf
struct member to pixbuf.
(gimp_view_renderer_real_render): try gimp_viewable_get_pixbuf()
and render the pixbuf before falling back to the TempBuf preview.
(gimp_view_renderer_render_pixbuf): new function that sets a
pixbuf for the renderer and flushes the render_buffer.
* app/widgets/gimpviewrendererimagefile.c
(gimp_view_renderer_imagefile_render): render the pixbuf.
* app/dialogs/dialogs-constructors.c: create the document history
dockable with a zero borderwidth.
2004-09-27 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/fileops.pdb (file_load_thumbnail_invoker): use
......
......@@ -32,8 +32,6 @@
#include "core-types.h"
#include "base/temp-buf.h"
#include "config/gimpcoreconfig.h"
#include "gimp.h"
......@@ -57,27 +55,27 @@ enum
};
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
static void gimp_imagefile_init (GimpImagefile *imagefile);
static void gimp_imagefile_finalize (GObject *object);
static void gimp_imagefile_name_changed (GimpObject *object);
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
GParamSpec *pspec);
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
static void gimp_imagefile_init (GimpImagefile *imagefile);
static void gimp_imagefile_finalize (GObject *object);
static void gimp_imagefile_name_changed (GimpObject *object);
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
GParamSpec *pspec);
static TempBuf * gimp_imagefile_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
static TempBuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
gint width,
gint height);
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
GimpImage *gimage,
gint size,
GError **error);
static GdkPixbuf * gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height);
static GdkPixbuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
gint width,
gint height);
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
GimpImage *gimage,
gint size,
GError **error);
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
gchar **tooltip);
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
gchar **tooltip);
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
......@@ -137,7 +135,7 @@ gimp_imagefile_class_init (GimpImagefileClass *klass)
gimp_object_class->name_changed = gimp_imagefile_name_changed;
viewable_class->name_changed_signal = "info_changed";
viewable_class->get_new_preview = gimp_imagefile_get_new_preview;
viewable_class->get_new_pixbuf = gimp_imagefile_get_new_pixbuf;
viewable_class->get_description = gimp_imagefile_get_description;
g_type_class_ref (GIMP_TYPE_IMAGE_TYPE);
......@@ -357,20 +355,20 @@ gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
}
}
static TempBuf *
gimp_imagefile_get_new_preview (GimpViewable *viewable,
gint width,
gint height)
static GdkPixbuf *
gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
gint width,
gint height)
{
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
TempBuf *temp_buf;
GdkPixbuf *pixbuf;
if (! GIMP_OBJECT (imagefile)->name)
return NULL;
temp_buf = gimp_imagefile_load_thumb (imagefile, width, height);
pixbuf = gimp_imagefile_load_thumb (imagefile, width, height);
if (temp_buf)
if (pixbuf)
{
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
}
......@@ -391,7 +389,7 @@ gimp_imagefile_get_new_preview (GimpViewable *viewable,
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
}
return temp_buf;
return pixbuf;
}
static gchar *
......@@ -551,13 +549,12 @@ gimp_imagefile_get_desc_string (GimpImagefile *imagefile)
return (const gchar *) imagefile->description;
}
static TempBuf *
static GdkPixbuf *
gimp_imagefile_load_thumb (GimpImagefile *imagefile,
gint width,
gint height)
{
GimpThumbnail *thumbnail = imagefile->thumbnail;
TempBuf *temp_buf = NULL;
GdkPixbuf *pixbuf = NULL;
GError *error = NULL;
gint size = MAX (width, height);
......@@ -574,9 +571,13 @@ gimp_imagefile_load_thumb (GimpImagefile *imagefile,
if (! pixbuf)
{
if (error)
g_message (_("Could not open thumbnail '%s': %s"),
thumbnail->thumb_filename, error->message);
goto cleanup;
{
g_message (_("Could not open thumbnail '%s': %s"),
thumbnail->thumb_filename, error->message);
g_error_free (error);
}
return NULL;
}
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
......@@ -593,48 +594,34 @@ gimp_imagefile_load_thumb (GimpImagefile *imagefile,
if (preview_width < pixbuf_width || preview_height < pixbuf_height)
{
GdkPixbuf *scaled;
scaled = gdk_pixbuf_scale_simple (pixbuf,
preview_width, preview_height,
GDK_INTERP_BILINEAR);
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf,
preview_width,
preview_height,
GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = scaled;
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
pixbuf_width = preview_width;
pixbuf_height = preview_height;
}
{
gint bytes;
guchar *src;
guchar *dest;
gint y;
bytes = gdk_pixbuf_get_n_channels (pixbuf);
temp_buf = temp_buf_new (pixbuf_width, pixbuf_height, bytes, 0, 0, NULL);
if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
{
GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
pixbuf_width, pixbuf_height);
dest = temp_buf_data (temp_buf);
src = gdk_pixbuf_get_pixels (pixbuf);
gdk_pixbuf_composite_color (pixbuf, tmp,
0, 0, pixbuf_width, pixbuf_height,
0.0, 0.0, 1.0, 1.0,
GDK_INTERP_NEAREST, 255,
0, 0, GIMP_CHECK_SIZE_SM,
0x66666666, 0x99999999);
for (y = 0; y < pixbuf_height; y++)
{
memcpy (dest, src, pixbuf_width * bytes);
dest += pixbuf_width * bytes;
src += gdk_pixbuf_get_rowstride (pixbuf);
}
}
cleanup:
if (pixbuf)
g_object_unref (pixbuf);
if (error)
g_error_free (error);
g_object_unref (pixbuf);
pixbuf = tmp;
}
return temp_buf;
return pixbuf;
}
static gboolean
......
......@@ -380,7 +380,7 @@ dialogs_document_list_new (GimpDialogFactory *factory,
return gimp_document_view_new (GIMP_VIEW_TYPE_LIST,
context->gimp->documents,
context,
preview_size, 1,
preview_size, 0,
factory->menu_factory);
}
......
......@@ -163,7 +163,7 @@ gimp_view_renderer_init (GimpViewRenderer *renderer)
renderer->rowstride = 0;
renderer->bytes = 3;
renderer->no_view_pixbuf = NULL;
renderer->pixbuf = NULL;
renderer->bg_stock_id = NULL;
renderer->size = -1;
......@@ -195,10 +195,10 @@ gimp_view_renderer_finalize (GObject *object)
renderer->buffer = NULL;
}
if (renderer->no_view_pixbuf)
if (renderer->pixbuf)
{
g_object_unref (renderer->no_view_pixbuf);
renderer->no_view_pixbuf = NULL;
g_object_unref (renderer->pixbuf);
renderer->pixbuf = NULL;
}
if (renderer->bg_stock_id)
......@@ -301,10 +301,10 @@ gimp_view_renderer_set_viewable (GimpViewRenderer *renderer,
renderer->buffer = NULL;
}
if (renderer->no_view_pixbuf)
if (renderer->pixbuf)
{
g_object_unref (renderer->no_view_pixbuf);
renderer->no_view_pixbuf = NULL;
g_object_unref (renderer->pixbuf);
renderer->pixbuf = NULL;
}
if (renderer->viewable)
......@@ -663,7 +663,7 @@ gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
if (renderer->needs_render)
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->render (renderer, widget);
if (renderer->no_view_pixbuf)
if (renderer->pixbuf)
{
if (renderer->bg_stock_id)
{
......@@ -682,8 +682,8 @@ gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
}
}
rect.width = gdk_pixbuf_get_width (renderer->no_view_pixbuf);
rect.height = gdk_pixbuf_get_height (renderer->no_view_pixbuf);
rect.width = gdk_pixbuf_get_width (renderer->pixbuf);
rect.height = gdk_pixbuf_get_height (renderer->pixbuf);
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
......@@ -692,7 +692,7 @@ gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
{
gdk_draw_pixbuf (GDK_DRAWABLE (window),
widget->style->bg_gc[widget->state],
renderer->no_view_pixbuf,
renderer->pixbuf,
render_rect.x - rect.x,
render_rect.y - rect.y,
render_rect.x,
......@@ -738,24 +738,30 @@ static void
gimp_view_renderer_real_render (GimpViewRenderer *renderer,
GtkWidget *widget)
{
TempBuf *temp_buf;
GdkPixbuf *pixbuf;
TempBuf *temp_buf;
const gchar *stock_id;
pixbuf = gimp_viewable_get_pixbuf (renderer->viewable,
renderer->width,
renderer->height);
if (pixbuf)
{
gimp_view_renderer_render_pixbuf (renderer, pixbuf);
return;
}
temp_buf = gimp_viewable_get_preview (renderer->viewable,
renderer->width,
renderer->height);
if (temp_buf)
{
gimp_view_renderer_default_render_buffer (renderer, widget, temp_buf);
return;
}
else /* no preview available */
{
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
}
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
}
static void
......@@ -804,10 +810,10 @@ gimp_view_renderer_default_render_stock (GimpViewRenderer *renderer,
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (stock_id != NULL);
if (renderer->no_view_pixbuf)
if (renderer->pixbuf)
{
g_object_unref (renderer->no_view_pixbuf);
renderer->no_view_pixbuf = NULL;
g_object_unref (renderer->pixbuf);
renderer->pixbuf = NULL;
}
if (renderer->buffer)
......@@ -845,7 +851,7 @@ gimp_view_renderer_default_render_stock (GimpViewRenderer *renderer,
pixbuf = scaled_pixbuf;
}
renderer->no_view_pixbuf = pixbuf;
renderer->pixbuf = pixbuf;
}
renderer->needs_render = FALSE;
......@@ -858,15 +864,15 @@ gimp_view_renderer_render_buffer (GimpViewRenderer *renderer,
GimpViewBG inside_bg,
GimpViewBG outside_bg)
{
if (! renderer->buffer)
renderer->buffer = g_new0 (guchar, renderer->height * renderer->rowstride);
if (renderer->no_view_pixbuf)
if (renderer->pixbuf)
{
g_object_unref (renderer->no_view_pixbuf);
renderer->no_view_pixbuf = NULL;
g_object_unref (renderer->pixbuf);
renderer->pixbuf = NULL;
}
if (! renderer->buffer)
renderer->buffer = g_new0 (guchar, renderer->height * renderer->rowstride);
gimp_view_render_to_buffer (temp_buf,
channel,
inside_bg,
......@@ -1059,6 +1065,26 @@ gimp_view_render_to_buffer (TempBuf *temp_buf,
}
}
void
gimp_view_renderer_render_pixbuf (GimpViewRenderer *renderer,
GdkPixbuf *pixbuf)
{
if (renderer->buffer)
{
g_free (renderer->buffer);
renderer->buffer = NULL;
}
g_object_ref (pixbuf);
if (renderer->pixbuf)
g_object_unref (renderer->pixbuf);
renderer->pixbuf = pixbuf;
renderer->needs_render = FALSE;
}
static GdkGC *
gimp_view_renderer_create_gc (GimpViewRenderer *renderer,
GdkWindow *window,
......
......@@ -57,8 +57,7 @@ struct _GimpViewRenderer
guchar *buffer;
gint rowstride;
gint bytes;
GdkPixbuf *no_view_pixbuf;
GdkPixbuf *pixbuf;
gchar *bg_stock_id;
gint size;
......@@ -141,6 +140,8 @@ void gimp_view_renderer_render_buffer (GimpViewRenderer *renderer,
gint channel,
GimpViewBG inside_bg,
GimpViewBG outside_bg);
void gimp_view_renderer_render_pixbuf (GimpViewRenderer *renderer,
GdkPixbuf *pixbuf);
/* general purpose temp_buf to buffer projection function */
......
......@@ -30,8 +30,6 @@
#include "widgets-types.h"
#include "base/temp-buf.h"
#include "core/gimpimagefile.h"
#include "gimpviewrendererimagefile.h"
......@@ -102,19 +100,13 @@ static void
gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
GtkWidget *widget)
{
TempBuf *temp_buf = gimp_viewable_get_preview (renderer->viewable,
renderer->width,
renderer->height);
if (temp_buf)
{
gimp_view_renderer_default_render_buffer (renderer, widget, temp_buf);
}
else
{
GdkPixbuf *pixbuf = NULL;
GdkPixbuf *pixbuf = gimp_viewable_get_pixbuf (renderer->viewable,
renderer->width,
renderer->height);
#ifdef ENABLE_FILE_SYSTEM_ICONS
if (! pixbuf)
{
if (GIMP_VIEW_RENDERER_IMAGEFILE (renderer)->file_system)
{
GtkFileSystem *file_system;
......@@ -136,54 +128,17 @@ gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
gtk_file_path_free (path);
}
}
}
#endif /* ENABLE_FILE_SYSTEM_ICONS */
if (pixbuf)
{
gint width;
gint height;
gint bytes;
guchar *src;
guchar *dest;
gint y;
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
bytes = gdk_pixbuf_get_n_channels (pixbuf);
temp_buf = temp_buf_new (width, height, bytes, 0, 0, NULL);
dest = temp_buf_data (temp_buf);
src = gdk_pixbuf_get_pixels (pixbuf);
for (y = 0; y < height; y++)
{
memcpy (dest, src, width * bytes);
dest += width * bytes;
src += gdk_pixbuf_get_rowstride (pixbuf);
}
if (temp_buf->width < renderer->width)
temp_buf->x = (renderer->width - temp_buf->width) / 2;
if (temp_buf->height < renderer->height)
temp_buf->y = (renderer->height - temp_buf->height) / 2;
gimp_view_renderer_render_buffer (renderer, temp_buf, -1,
GIMP_VIEW_BG_WHITE,
GIMP_VIEW_BG_WHITE);
temp_buf_free (temp_buf);
g_object_unref (pixbuf);
}
else
{
const gchar *stock_id;
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
if (pixbuf)
{
gimp_view_renderer_render_pixbuf (renderer, pixbuf);
}
else
{
const gchar *stock_id = gimp_viewable_get_stock_id (renderer->viewable);
gimp_view_renderer_default_render_stock (renderer, widget,
stock_id);
}
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
}
}
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