gimp r27784 - in trunk: . app/core



Author: martinn
Date: Sat Dec 13 11:58:24 2008
New Revision: 27784
URL: http://svn.gnome.org/viewvc/gimp?rev=27784&view=rev

Log:
Bug 555954 â Merge Tagging of Gimp Resources GSoC Project

Partial merge of code from Aurimas JuÅka.

* app/core/gimpdata.c: Implement GimpTagged::get_identifier() and
GimpTagged::get_checksum().

* app/core/gimpbrush.c: 
* app/core/gimpgradient.c
* app/core/gimppalette.c
* app/core/gimppattern.c: Implement GimpTagged::get_checksum().
They all use the GimpData implementation of
GimpTagged::get_identifier().


Modified:
   trunk/ChangeLog
   trunk/app/core/gimpbrush.c
   trunk/app/core/gimpdata.c
   trunk/app/core/gimpgradient.c
   trunk/app/core/gimppalette.c
   trunk/app/core/gimppattern.c

Modified: trunk/app/core/gimpbrush.c
==============================================================================
--- trunk/app/core/gimpbrush.c	(original)
+++ trunk/app/core/gimpbrush.c	Sat Dec 13 11:58:24 2008
@@ -21,6 +21,7 @@
 #include <glib-object.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmath.h"
 
 #include "core-types.h"
 
@@ -31,6 +32,7 @@
 #include "gimpbrush-scale.h"
 #include "gimpbrushgenerated.h"
 #include "gimpmarshal.h"
+#include "gimptagged.h"
 
 #include "gimp-intl.h"
 
@@ -48,39 +50,45 @@
 };
 
 
-static void          gimp_brush_set_property          (GObject       *object,
-                                                       guint          property_id,
-                                                       const GValue  *value,
-                                                       GParamSpec    *pspec);
-static void          gimp_brush_get_property          (GObject       *object,
-                                                       guint          property_id,
-                                                       GValue        *value,
-                                                       GParamSpec    *pspec);
-static void          gimp_brush_finalize              (GObject       *object);
-
-static gint64        gimp_brush_get_memsize           (GimpObject    *object,
-                                                       gint64        *gui_size);
-
-static gboolean      gimp_brush_get_size              (GimpViewable  *viewable,
-                                                       gint          *width,
-                                                       gint          *height);
-static TempBuf     * gimp_brush_get_new_preview       (GimpViewable  *viewable,
-                                                       GimpContext   *context,
-                                                       gint           width,
-                                                       gint           height);
-static gchar       * gimp_brush_get_description       (GimpViewable  *viewable,
-                                                       gchar        **tooltip);
-static const gchar * gimp_brush_get_extension         (GimpData      *data);
-
-static GimpBrush   * gimp_brush_real_select_brush     (GimpBrush     *brush,
-                                                       GimpCoords    *last_coords,
-                                                       GimpCoords    *cur_coords);
-static gboolean      gimp_brush_real_want_null_motion (GimpBrush     *brush,
-                                                       GimpCoords    *last_coords,
-                                                       GimpCoords    *cur_coords);
+static void          gimp_brush_tagged_iface_init     (GimpTaggedInterface  *iface);
 
-
-G_DEFINE_TYPE (GimpBrush, gimp_brush, GIMP_TYPE_DATA)
+static void          gimp_brush_set_property          (GObject              *object,
+                                                       guint                 property_id,
+                                                       const GValue         *value,
+                                                       GParamSpec           *pspec);
+static void          gimp_brush_get_property          (GObject              *object,
+                                                       guint                 property_id,
+                                                       GValue               *value,
+                                                       GParamSpec           *pspec);
+static void          gimp_brush_finalize              (GObject              *object);
+
+static gint64        gimp_brush_get_memsize           (GimpObject           *object,
+                                                       gint64               *gui_size);
+
+static gboolean      gimp_brush_get_size              (GimpViewable         *viewable,
+                                                       gint                 *width,
+                                                       gint                 *height);
+static TempBuf     * gimp_brush_get_new_preview       (GimpViewable         *viewable,
+                                                       GimpContext          *context,
+                                                       gint                  width,
+                                                       gint                  height);
+static gchar       * gimp_brush_get_description       (GimpViewable         *viewable,
+                                                       gchar               **tooltip);
+static const gchar * gimp_brush_get_extension         (GimpData             *data);
+
+static GimpBrush   * gimp_brush_real_select_brush     (GimpBrush            *brush,
+                                                       GimpCoords           *last_coords,
+                                                       GimpCoords           *cur_coords);
+static gboolean      gimp_brush_real_want_null_motion (GimpBrush            *brush,
+                                                       GimpCoords           *last_coords,
+                                                       GimpCoords           *cur_coords);
+
+static gchar       * gimp_brush_get_checksum          (GimpTagged           *tagged);
+
+
+G_DEFINE_TYPE_WITH_CODE (GimpBrush, gimp_brush, GIMP_TYPE_DATA,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+                                                gimp_brush_tagged_iface_init))
 
 #define parent_class gimp_brush_parent_class
 
@@ -132,6 +140,12 @@
 }
 
 static void
+gimp_brush_tagged_iface_init (GimpTaggedInterface *iface)
+{
+  iface->get_checksum = gimp_brush_get_checksum;
+}
+
+static void
 gimp_brush_init (GimpBrush *brush)
 {
   brush->mask     = NULL;
@@ -357,6 +371,30 @@
   return TRUE;
 }
 
+static gchar *
+gimp_brush_get_checksum (GimpTagged *tagged)
+{
+  GimpBrush *brush           = GIMP_BRUSH (tagged);
+  gchar     *checksum_string = NULL;
+
+  if (brush->mask)
+    {
+      GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
+
+      g_checksum_update (checksum, temp_buf_get_data (brush->mask), temp_buf_get_data_size (brush->mask));
+      if (brush->pixmap)
+        g_checksum_update (checksum, temp_buf_get_data (brush->pixmap), temp_buf_get_data_size (brush->pixmap));
+      g_checksum_update (checksum, (const guchar *) &brush->spacing, sizeof (brush->spacing));
+      g_checksum_update (checksum, (const guchar *) &brush->x_axis, sizeof (brush->x_axis));
+      g_checksum_update (checksum, (const guchar *) &brush->y_axis, sizeof (brush->y_axis));
+
+      checksum_string = g_strdup (g_checksum_get_string (checksum));
+
+      g_checksum_free (checksum);
+    }
+
+  return checksum_string;
+}
 
 /*  public functions  */
 

Modified: trunk/app/core/gimpdata.c
==============================================================================
--- trunk/app/core/gimpdata.c	(original)
+++ trunk/app/core/gimpdata.c	Sat Dec 13 11:58:24 2008
@@ -94,6 +94,8 @@
 static gboolean  gimp_data_remove_tag        (GimpTagged            *tagged,
                                               GimpTag               *tag);
 static GList *   gimp_data_get_tags          (GimpTagged            *tagged);
+static gchar *   gimp_data_get_identifier    (GimpTagged            *tagged);
+static gchar *   gimp_data_get_checksum      (GimpTagged            *tagged);
 
 
 static guint data_signals[LAST_SIGNAL] = { 0 };
@@ -192,9 +194,11 @@
 static void
 gimp_data_tagged_iface_init (GimpTaggedInterface *iface)
 {
-  iface->add_tag    = gimp_data_add_tag;
-  iface->remove_tag = gimp_data_remove_tag;
-  iface->get_tags   = gimp_data_get_tags;
+  iface->add_tag        = gimp_data_add_tag;
+  iface->remove_tag     = gimp_data_remove_tag;
+  iface->get_tags       = gimp_data_get_tags;
+  iface->get_identifier = gimp_data_get_identifier;
+  iface->get_checksum   = gimp_data_get_checksum;
 }
 
 static void
@@ -404,6 +408,36 @@
   return GIMP_DATA (tagged)->tags;
 }
 
+static gchar*
+gimp_data_get_identifier (GimpTagged *tagged)
+{
+  GimpData *data       = GIMP_DATA (tagged);
+  gchar    *identifier = NULL;
+
+  if (data->filename)
+    {
+      identifier = g_filename_to_utf8 (data->filename, -1, NULL, NULL, NULL);
+
+      if (! identifier)
+        {
+          g_warning ("Failed to convert '%s' to utf8.\n", data->filename);
+          identifier = g_strdup (data->filename);
+        }
+    }
+  else if (data->internal)
+    {
+      identifier = g_strdup (data->identifier);
+    }
+
+  return identifier;
+}
+
+static gchar *
+gimp_data_get_checksum (GimpTagged *tagged)
+{
+  return NULL;
+}
+
 /**
  * gimp_data_save:
  * @data:  object whose contents are to be saved.

Modified: trunk/app/core/gimpgradient.c
==============================================================================
--- trunk/app/core/gimpgradient.c	(original)
+++ trunk/app/core/gimpgradient.c	Sat Dec 13 11:58:24 2008
@@ -33,39 +33,43 @@
 #include "gimpgradient.h"
 #include "gimpgradient-load.h"
 #include "gimpgradient-save.h"
+#include "gimptagged.h"
 
 
 #define EPSILON 1e-10
 
 
-static void          gimp_gradient_finalize         (GObject           *object);
+static void          gimp_gradient_tagged_iface_init (GimpTaggedInterface *iface);
+static void          gimp_gradient_finalize          (GObject             *object);
 
-static gint64        gimp_gradient_get_memsize      (GimpObject        *object,
-                                                     gint64            *gui_size);
+static gint64        gimp_gradient_get_memsize       (GimpObject          *object,
+                                                      gint64              *gui_size);
 
-static void          gimp_gradient_get_preview_size (GimpViewable      *viewable,
-                                                     gint               size,
-                                                     gboolean           popup,
-                                                     gboolean           dot_for_dot,
-                                                     gint              *width,
-                                                     gint              *height);
-static gboolean      gimp_gradient_get_popup_size   (GimpViewable      *viewable,
-                                                     gint               width,
-                                                     gint               height,
-                                                     gboolean           dot_for_dot,
-                                                     gint              *popup_width,
-                                                     gint              *popup_height);
-static TempBuf     * gimp_gradient_get_new_preview  (GimpViewable      *viewable,
-                                                     GimpContext       *context,
-                                                     gint               width,
-                                                     gint               height);
-static const gchar * gimp_gradient_get_extension    (GimpData          *data);
-static GimpData    * gimp_gradient_duplicate        (GimpData          *data);
+static void          gimp_gradient_get_preview_size  (GimpViewable        *viewable,
+                                                      gint                 size,
+                                                      gboolean             popup,
+                                                      gboolean             dot_for_dot,
+                                                      gint                *width,
+                                                      gint                *height);
+static gboolean      gimp_gradient_get_popup_size    (GimpViewable        *viewable,
+                                                      gint                 width,
+                                                      gint                 height,
+                                                      gboolean             dot_for_dot,
+                                                      gint                *popup_width,
+                                                      gint                *popup_height);
+static TempBuf     * gimp_gradient_get_new_preview   (GimpViewable        *viewable,
+                                                      GimpContext         *context,
+                                                      gint                 width,
+                                                      gint                 height);
+static const gchar * gimp_gradient_get_extension     (GimpData            *data);
+static GimpData    * gimp_gradient_duplicate         (GimpData            *data);
+
+static gchar       * gimp_gradient_get_checksum      (GimpTagged          *tagged);
 
 static GimpGradientSegment *
-              gimp_gradient_get_segment_at_internal (GimpGradient        *gradient,
-                                                     GimpGradientSegment *seg,
-                                                     gdouble              pos);
+              gimp_gradient_get_segment_at_internal  (GimpGradient        *gradient,
+                                                      GimpGradientSegment *seg,
+                                                      gdouble              pos);
 
 
 static inline gdouble  gimp_gradient_calc_linear_factor            (gdouble  middle,
@@ -80,7 +84,9 @@
                                                                     gdouble  pos);
 
 
-G_DEFINE_TYPE (GimpGradient, gimp_gradient, GIMP_TYPE_DATA)
+G_DEFINE_TYPE_WITH_CODE (GimpGradient, gimp_gradient, GIMP_TYPE_DATA,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+                                                gimp_gradient_tagged_iface_init))
 
 #define parent_class gimp_gradient_parent_class
 
@@ -108,6 +114,12 @@
 }
 
 static void
+gimp_gradient_tagged_iface_init (GimpTaggedInterface *iface)
+{
+  iface->get_checksum = gimp_gradient_get_checksum;
+}
+
+static void
 gimp_gradient_init (GimpGradient *gradient)
 {
   gradient->segments = NULL;
@@ -255,6 +267,39 @@
   return GIMP_DATA (gradient);
 }
 
+static gchar *
+gimp_gradient_get_checksum (GimpTagged *tagged)
+{
+  GimpGradient *gradient        = GIMP_GRADIENT (tagged);
+  gchar        *checksum_string = NULL;
+
+  if (gradient->segments)
+    {
+      GChecksum           *checksum = g_checksum_new (G_CHECKSUM_MD5);
+      GimpGradientSegment *segment  = gradient->segments;
+
+      while (segment)
+        {
+          g_checksum_update (checksum, (const guchar *) &segment->left, sizeof (segment->left));
+          g_checksum_update (checksum, (const guchar *) &segment->middle, sizeof (segment->middle));
+          g_checksum_update (checksum, (const guchar *) &segment->right,sizeof (segment->right));
+          g_checksum_update (checksum, (const guchar *) &segment->left_color_type, sizeof (segment->left_color_type));
+          g_checksum_update (checksum, (const guchar *) &segment->left_color, sizeof (segment->left_color));
+          g_checksum_update (checksum, (const guchar *) &segment->right_color_type, sizeof (segment->right_color_type));
+          g_checksum_update (checksum, (const guchar *) &segment->right_color, sizeof (segment->right_color));
+          g_checksum_update (checksum, (const guchar *) &segment->type, sizeof (segment->type));
+          g_checksum_update (checksum, (const guchar *) &segment->color, sizeof (segment->color));
+
+          segment = segment->next;
+        }
+
+      checksum_string = g_strdup (g_checksum_get_string (checksum));
+
+      g_checksum_free (checksum);
+    }
+
+  return checksum_string;
+}
 
 /*  public functions  */
 

Modified: trunk/app/core/gimppalette.c
==============================================================================
--- trunk/app/core/gimppalette.c	(original)
+++ trunk/app/core/gimppalette.c	Sat Dec 13 11:58:24 2008
@@ -33,6 +33,7 @@
 #include "gimppalette.h"
 #include "gimppalette-load.h"
 #include "gimppalette-save.h"
+#include "gimptagged.h"
 
 #include "gimp-intl.h"
 
@@ -40,38 +41,43 @@
 
 /*  local function prototypes  */
 
-static void          gimp_palette_finalize          (GObject           *object);
+static void          gimp_palette_tagged_iface_init (GimpTaggedInterface  *iface);
 
-static gint64        gimp_palette_get_memsize       (GimpObject        *object,
-                                                     gint64            *gui_size);
+static void          gimp_palette_finalize          (GObject              *object);
 
-static void          gimp_palette_get_preview_size  (GimpViewable      *viewable,
-                                                     gint               size,
-                                                     gboolean           popup,
-                                                     gboolean           dot_for_dot,
-                                                     gint              *width,
-                                                     gint              *height);
-static gboolean      gimp_palette_get_popup_size    (GimpViewable      *viewable,
-                                                     gint               width,
-                                                     gint               height,
-                                                     gboolean           dot_for_dot,
-                                                     gint              *popup_width,
-                                                     gint              *popup_height);
-static TempBuf     * gimp_palette_get_new_preview   (GimpViewable      *viewable,
-                                                     GimpContext       *context,
-                                                     gint               width,
-                                                     gint               height);
-static gchar       * gimp_palette_get_description   (GimpViewable      *viewable,
-                                                     gchar            **tooltip);
-static const gchar * gimp_palette_get_extension     (GimpData          *data);
-static GimpData    * gimp_palette_duplicate         (GimpData          *data);
-
-static void          gimp_palette_entry_free        (GimpPaletteEntry  *entry);
-static gint64        gimp_palette_entry_get_memsize (GimpPaletteEntry  *entry,
-                                                     gint64            *gui_size);
+static gint64        gimp_palette_get_memsize       (GimpObject           *object,
+                                                     gint64               *gui_size);
 
-
-G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_DATA)
+static void          gimp_palette_get_preview_size  (GimpViewable         *viewable,
+                                                     gint                  size,
+                                                     gboolean              popup,
+                                                     gboolean              dot_for_dot,
+                                                     gint                 *width,
+                                                     gint                 *height);
+static gboolean      gimp_palette_get_popup_size    (GimpViewable         *viewable,
+                                                     gint                  width,
+                                                     gint                  height,
+                                                     gboolean              dot_for_dot,
+                                                     gint                 *popup_width,
+                                                     gint                 *popup_height);
+static TempBuf     * gimp_palette_get_new_preview   (GimpViewable         *viewable,
+                                                     GimpContext          *context,
+                                                     gint                  width,
+                                                     gint                  height);
+static gchar       * gimp_palette_get_description   (GimpViewable         *viewable,
+                                                     gchar               **tooltip);
+static const gchar * gimp_palette_get_extension     (GimpData             *data);
+static GimpData    * gimp_palette_duplicate         (GimpData             *data);
+
+static void          gimp_palette_entry_free        (GimpPaletteEntry     *entry);
+static gint64        gimp_palette_entry_get_memsize (GimpPaletteEntry     *entry,
+                                                     gint64               *gui_size);
+static gchar       * gimp_palette_get_checksum      (GimpTagged           *tagged);
+
+
+G_DEFINE_TYPE_WITH_CODE (GimpPalette, gimp_palette, GIMP_TYPE_DATA,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+                                                gimp_palette_tagged_iface_init))
 
 #define parent_class gimp_palette_parent_class
 
@@ -100,6 +106,12 @@
 }
 
 static void
+gimp_palette_tagged_iface_init (GimpTaggedInterface *iface)
+{
+  iface->get_checksum = gimp_palette_get_checksum;
+}
+
+static void
 gimp_palette_init (GimpPalette *palette)
 {
   palette->colors    = NULL;
@@ -317,6 +329,39 @@
   return GIMP_DATA (new);
 }
 
+static gchar *
+gimp_palette_get_checksum (GimpTagged *tagged)
+{
+  GimpPalette *palette         = GIMP_PALETTE (tagged);
+  gchar       *checksum_string = NULL;
+
+  if (palette->n_colors > 0)
+    {
+      GChecksum *checksum       = g_checksum_new (G_CHECKSUM_MD5);
+      GList     *color_iterator = palette->colors;
+
+      g_checksum_update (checksum, (const guchar *) &palette->n_colors, sizeof (palette->n_colors));
+      g_checksum_update (checksum, (const guchar *) &palette->n_columns, sizeof (palette->n_columns));
+
+      while (color_iterator)
+        {
+          GimpPaletteEntry *entry = (GimpPaletteEntry *) color_iterator->data;
+
+          g_checksum_update (checksum, (const guchar *) &entry->color, sizeof (entry->color));
+          if (entry->name)
+            g_checksum_update (checksum, (const guchar *) entry->name, strlen (entry->name));
+
+          color_iterator = g_list_next (color_iterator);
+        }
+
+      checksum_string = g_strdup (g_checksum_get_string (checksum));
+
+      g_checksum_free (checksum);
+    }
+
+  return checksum_string;
+}
+
 GimpPaletteEntry *
 gimp_palette_add_entry (GimpPalette   *palette,
                         gint           position,

Modified: trunk/app/core/gimppattern.c
==============================================================================
--- trunk/app/core/gimppattern.c	(original)
+++ trunk/app/core/gimppattern.c	Sat Dec 13 11:58:24 2008
@@ -30,30 +30,36 @@
 
 #include "gimppattern.h"
 #include "gimppattern-load.h"
+#include "gimptagged.h"
 
 #include "gimp-intl.h"
 
 
-static void          gimp_pattern_finalize        (GObject       *object);
+static void          gimp_pattern_tagged_iface_init (GimpTaggedInterface  *iface);
+static void          gimp_pattern_finalize          (GObject              *object);
 
-static gint64        gimp_pattern_get_memsize     (GimpObject    *object,
-                                                   gint64        *gui_size);
+static gint64        gimp_pattern_get_memsize       (GimpObject           *object,
+                                                     gint64               *gui_size);
 
-static gboolean      gimp_pattern_get_size        (GimpViewable  *viewable,
-                                                   gint          *width,
-                                                   gint          *height);
-static TempBuf     * gimp_pattern_get_new_preview (GimpViewable  *viewable,
-                                                   GimpContext   *context,
-                                                   gint           width,
-                                                   gint           height);
-static gchar       * gimp_pattern_get_description (GimpViewable  *viewable,
-                                                   gchar        **tooltip);
-
-static const gchar * gimp_pattern_get_extension   (GimpData      *data);
-static GimpData    * gimp_pattern_duplicate       (GimpData      *data);
-
-
-G_DEFINE_TYPE (GimpPattern, gimp_pattern, GIMP_TYPE_DATA)
+static gboolean      gimp_pattern_get_size          (GimpViewable         *viewable,
+                                                     gint                 *width,
+                                                     gint                 *height);
+static TempBuf     * gimp_pattern_get_new_preview   (GimpViewable         *viewable,
+                                                     GimpContext          *context,
+                                                     gint                  width,
+                                                     gint                  height);
+static gchar       * gimp_pattern_get_description   (GimpViewable         *viewable,
+                                                     gchar               **tooltip);
+
+static const gchar * gimp_pattern_get_extension     (GimpData             *data);
+static GimpData    * gimp_pattern_duplicate         (GimpData             *data);
+
+static gchar       * gimp_pattern_get_checksum      (GimpTagged           *tagged);
+
+
+G_DEFINE_TYPE_WITH_CODE (GimpPattern, gimp_pattern, GIMP_TYPE_DATA,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+                                                gimp_pattern_tagged_iface_init))
 
 #define parent_class gimp_pattern_parent_class
 
@@ -80,6 +86,12 @@
 }
 
 static void
+gimp_pattern_tagged_iface_init (GimpTaggedInterface *iface)
+{
+  iface->get_checksum = gimp_pattern_get_checksum;
+}
+
+static void
 gimp_pattern_init (GimpPattern *pattern)
 {
   pattern->mask = NULL;
@@ -177,6 +189,26 @@
   return GIMP_DATA (pattern);
 }
 
+static gchar *
+gimp_pattern_get_checksum (GimpTagged *tagged)
+{
+  GimpPattern *pattern         = GIMP_PATTERN (tagged);
+  gchar       *checksum_string = NULL;
+
+  if (pattern->mask)
+    {
+      GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
+
+      g_checksum_update (checksum, temp_buf_get_data (pattern->mask), temp_buf_get_data_size (pattern->mask));
+
+      checksum_string = g_strdup (g_checksum_get_string (checksum));
+
+      g_checksum_free (checksum);
+    }
+
+  return checksum_string;
+}
+
 GimpData *
 gimp_pattern_new (const gchar *name)
 {



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