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().

svn path=/trunk/; revision=27784
This commit is contained in:
Martin Nordholts 2008-12-13 11:58:24 +00:00
parent 4cb231f53b
commit 364d2cd84f
6 changed files with 308 additions and 98 deletions

View File

@ -1,3 +1,19 @@
2008-12-13 Martin Nordholts <martinn@svn.gnome.org>
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().
2008-12-13 Martin Nordholts <martinn@svn.gnome.org>
Introduce temp_buf_get_data_size() and use it.

View File

@ -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 @@ enum
};
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 void gimp_brush_tagged_iface_init (GimpTaggedInterface *iface);
static gint64 gimp_brush_get_memsize (GimpObject *object,
gint64 *gui_size);
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 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 gint64 gimp_brush_get_memsize (GimpObject *object,
gint64 *gui_size);
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 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 (GimpBrush, gimp_brush, GIMP_TYPE_DATA)
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
@ -131,6 +139,12 @@ gimp_brush_class_init (GimpBrushClass *klass)
G_PARAM_CONSTRUCT));
}
static void
gimp_brush_tagged_iface_init (GimpTaggedInterface *iface)
{
iface->get_checksum = gimp_brush_get_checksum;
}
static void
gimp_brush_init (GimpBrush *brush)
{
@ -357,6 +371,30 @@ gimp_brush_real_want_null_motion (GimpBrush *brush,
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 */

View File

@ -94,6 +94,8 @@ static gboolean gimp_data_add_tag (GimpTagged *tagged,
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 @@ gimp_data_class_init (GimpDataClass *klass)
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 @@ gimp_data_get_tags (GimpTagged *tagged)
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.

View File

@ -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 @@ static inline gdouble gimp_gradient_calc_sphere_decreasing_factor (gdouble mid
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
@ -107,6 +113,12 @@ gimp_gradient_class_init (GimpGradientClass *klass)
data_class->duplicate = gimp_gradient_duplicate;
}
static void
gimp_gradient_tagged_iface_init (GimpTaggedInterface *iface)
{
iface->get_checksum = gimp_gradient_get_checksum;
}
static void
gimp_gradient_init (GimpGradient *gradient)
{
@ -255,6 +267,39 @@ gimp_gradient_duplicate (GimpData *data)
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 */

View File

@ -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 gint64 gimp_palette_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_palette_entry_free (GimpPaletteEntry *entry);
static gint64 gimp_palette_entry_get_memsize (GimpPaletteEntry *entry,
gint64 *gui_size);
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 (GimpPalette, gimp_palette, GIMP_TYPE_DATA)
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
@ -99,6 +105,12 @@ gimp_palette_class_init (GimpPaletteClass *klass)
data_class->duplicate = gimp_palette_duplicate;
}
static void
gimp_palette_tagged_iface_init (GimpTaggedInterface *iface)
{
iface->get_checksum = gimp_palette_get_checksum;
}
static void
gimp_palette_init (GimpPalette *palette)
{
@ -317,6 +329,39 @@ gimp_palette_duplicate (GimpData *data)
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,

View File

@ -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 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 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 (GimpPattern, gimp_pattern, GIMP_TYPE_DATA)
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
@ -79,6 +85,12 @@ gimp_pattern_class_init (GimpPatternClass *klass)
data_class->duplicate = gimp_pattern_duplicate;
}
static void
gimp_pattern_tagged_iface_init (GimpTaggedInterface *iface)
{
iface->get_checksum = gimp_pattern_get_checksum;
}
static void
gimp_pattern_init (GimpPattern *pattern)
{
@ -177,6 +189,26 @@ gimp_pattern_duplicate (GimpData *data)
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)
{