[dia] [gtk-deprecated] Make DiaImage independent of GDK/GTK



commit 505dd628f5e49d11c0e8a637d8c8e3651f021db3
Author: Hans Breuer <hans breuer org>
Date:   Sat Dec 10 12:54:41 2011 +0100

    [gtk-deprecated] Make DiaImage independent of GDK/GTK
    
     - move interactive initialization out of dia_image.c
     - inline dia_image_draw to only user: DiaGdkRenderer
    
    Just one step to move the Gdk renderer out of the core.

 lib/dia_image.c      |   31 +++++--------------------------
 lib/dia_image.h      |    5 ++---
 lib/diagdkrenderer.c |   10 ++++++++--
 lib/dialib.c         |    3 +--
 lib/libdia.def       |    1 -
 5 files changed, 16 insertions(+), 34 deletions(-)
---
diff --git a/lib/dia_image.c b/lib/dia_image.c
index 8c87c93..8f99ac7 100644
--- a/lib/dia_image.c
+++ b/lib/dia_image.c
@@ -23,7 +23,6 @@
 #include "geometry.h"
 #include "dia_image.h"
 #include "message.h"
-#include <gtk/gtkwidget.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "dia-lib-icons.h"
@@ -109,18 +108,6 @@ dia_image_finalize(GObject* object)
 
 gboolean _dia_image_initialized = FALSE;
 
-/** Perform required initialization to handle images with GDK.
- *  Should not be called in non-interactive use.
- */
-void 
-dia_image_init(void)
-{
-  if (!_dia_image_initialized) {
-    gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
-    _dia_image_initialized = TRUE;
-  }
-}
-
 /** Get the image to put in place of a image that cannot be read.
  * @returns A statically allocated image.
  */
@@ -220,14 +207,13 @@ dia_image_unref(DiaImage *image)
  * @param width Width in pixels of rendering in window.
  * @param height Height in pixels of rendering in window.
  */
-void 
-dia_image_draw(DiaImage *image, GdkWindow *window, GdkGC *gc,
-	       int x, int y, int width, int height)
+GdkPixbuf * 
+dia_image_get_scaled_pixbuf(DiaImage *image, int width, int height)
 {
   GdkPixbuf *scaled;
 
   if (width < 1 || height < 1)
-    return;
+    return NULL;
   if (gdk_pixbuf_get_width(image->image) > width ||
       gdk_pixbuf_get_height(image->image) > height) {
     /* Using TILES to make it look more like PostScript */
@@ -249,15 +235,8 @@ dia_image_draw(DiaImage *image, GdkWindow *window, GdkGC *gc,
   } else {
     scaled = image->image;
   }
-
-  /* Once we can render Alpha, we'll do it! */
-  gdk_draw_pixbuf(window, gc, scaled,
-		  0, 0, x, y, width, height, 
-		  GDK_RGB_DITHER_NORMAL, 0, 0);
-
-#ifndef SCALING_CACHE
-  g_object_unref(scaled);
-#endif
+  /* always adding a reference */
+  return g_object_ref (scaled);
 }
 
 static gchar *
diff --git a/lib/dia_image.h b/lib/dia_image.h
index cecccb3..ebc33ec 100644
--- a/lib/dia_image.h
+++ b/lib/dia_image.h
@@ -26,8 +26,6 @@
 
 G_BEGIN_DECLS
 
-void dia_image_init(void);
-
 DiaImage *dia_image_get_broken(void);
 
 DiaImage *dia_image_load(const gchar *filename);
@@ -56,7 +54,8 @@ guint8 *dia_image_mask_data(const DiaImage *image);
  */
 const guint8 *dia_image_rgba_data(const DiaImage *image);
 const char *dia_image_filename(const DiaImage *image);
-const GdkPixbuf* dia_image_pixbuf (const DiaImage *image);
+const GdkPixbuf *dia_image_pixbuf (const DiaImage *image);
+GdkPixbuf *dia_image_get_scaled_pixbuf (DiaImage *image, int width, int height);
 
 G_END_DECLS
 
diff --git a/lib/diagdkrenderer.c b/lib/diagdkrenderer.c
index b7450ed..015fb9a 100644
--- a/lib/diagdkrenderer.c
+++ b/lib/diagdkrenderer.c
@@ -866,8 +866,14 @@ draw_image (DiaRenderer *object,
       }
     } else {
       /* otherwise still using the caching variant */
-      dia_image_draw(image,  renderer->pixmap, renderer->gc, real_x, real_y,
-		     real_width, real_height);
+      GdkPixbuf *scaled = dia_image_get_scaled_pixbuf (image, real_width, real_height);
+      if (scaled) {
+	gdk_draw_pixbuf(renderer->pixmap, renderer->gc, scaled,
+		        0, 0, real_x, real_y, real_width, real_height, 
+		        GDK_RGB_DITHER_NORMAL, 0, 0);
+
+        g_object_unref (scaled);
+      }
     }
   }
 }
diff --git a/lib/dialib.c b/lib/dialib.c
index 22a0734..de44344 100644
--- a/lib/dialib.c
+++ b/lib/dialib.c
@@ -29,7 +29,6 @@
 #include "dialib.h"
 #include "message.h"
 #include "utils.h"
-#include "dia_image.h"
 #include "color.h"
 #include "object.h"
 #include "dia_dirs.h"
@@ -108,7 +107,7 @@ libdia_init (guint flags)
   if (flags & DIA_INTERACTIVE) {
     char *diagtkrc;
 
-    dia_image_init();
+    gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
 
     diagtkrc = dia_config_filename("diagtkrc");
     dia_log_message ("Config from %s", diagtkrc);
diff --git a/lib/libdia.def b/lib/libdia.def
index 530cafd..9db86cb 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -269,7 +269,6 @@ EXPORTS
  dia_get_canonical_path
 
  dia_image_add_ref
- dia_image_draw
  dia_image_filename
  dia_image_get_broken
  dia_image_height



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]