libgimp/gimpdrawable.c libgimp/gimppixelfetcher.c libgimp/gimpprogress.c

2007-05-22  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpdrawable.c
	* libgimp/gimppixelfetcher.c
	* libgimp/gimpprogress.c
	* libgimp/gimppixelrgn.c
	* libgimp/gimpregioniterator.c: allocate structs using GSlice.

svn path=/trunk/; revision=22567
This commit is contained in:
Sven Neumann 2007-05-22 14:04:35 +00:00 committed by Sven Neumann
parent a8c9def029
commit ba25863e49
6 changed files with 66 additions and 47 deletions

View File

@ -1,3 +1,11 @@
2007-05-22 Sven Neumann <sven@gimp.org>
* libgimp/gimpdrawable.c
* libgimp/gimppixelfetcher.c
* libgimp/gimpprogress.c
* libgimp/gimppixelrgn.c
* libgimp/gimpregioniterator.c: allocate structs using GSlice.
2007-05-22 Sven Neumann <sven@gimp.org> 2007-05-22 Sven Neumann <sven@gimp.org>
* libgimp/gimpbrushmenu.c * libgimp/gimpbrushmenu.c

View File

@ -62,7 +62,7 @@ gimp_drawable_get (gint32 drawable_ID)
g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL); g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL);
drawable = g_new0 (GimpDrawable, 1); drawable = g_slice_new0 (GimpDrawable);
drawable->drawable_id = drawable_ID; drawable->drawable_id = drawable_ID;
drawable->width = width; drawable->width = width;
@ -93,10 +93,11 @@ gimp_drawable_detach (GimpDrawable *drawable)
if (drawable->tiles) if (drawable->tiles)
g_free (drawable->tiles); g_free (drawable->tiles);
if (drawable->shadow_tiles) if (drawable->shadow_tiles)
g_free (drawable->shadow_tiles); g_free (drawable->shadow_tiles);
g_free (drawable); g_slice_free (GimpDrawable, drawable);
} }
/** /**

View File

@ -3,12 +3,6 @@
* *
* gimppixelfetcher.c * gimppixelfetcher.c
* *
* FIXME: fix the following comment:
* Contains all kinds of miscellaneous routines factored out from different
* plug-ins. They stay here until their API has crystalized a bit and we can
* put them into the file where they belong (Maurits Rijk
* <lpeek.mrijk@consunet.nl> if you want to blame someone for this mess)
*
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -83,7 +77,7 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable,
g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL); g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL);
pf = g_new0 (GimpPixelFetcher, 1); pf = g_slice_new0 (GimpPixelFetcher);
gimp_drawable_mask_bounds (drawable->drawable_id, gimp_drawable_mask_bounds (drawable->drawable_id,
&pf->sel_x1, &pf->sel_y1, &pf->sel_x1, &pf->sel_y1,
@ -123,7 +117,7 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
if (pf->tile) if (pf->tile)
gimp_tile_unref (pf->tile, pf->tile_dirty); gimp_tile_unref (pf->tile, pf->tile_dirty);
g_free (pf); g_slice_free (GimpPixelFetcher, pf);
} }
/** /**

View File

@ -671,17 +671,14 @@ gimp_pixel_rgns_register2 (gint nrgns,
g_return_val_if_fail (nrgns > 0, NULL); g_return_val_if_fail (nrgns > 0, NULL);
g_return_val_if_fail (prs != NULL, NULL); g_return_val_if_fail (prs != NULL, NULL);
pri = g_new0 (GimpPixelRgnIterator, 1); pri = g_slice_new0 (GimpPixelRgnIterator);
found = FALSE; found = FALSE;
while (nrgns --) while (nrgns --)
{ {
GimpPixelRgnHolder *prh; GimpPixelRgn *pr = prs[nrgns];
GimpPixelRgn *pr; GimpPixelRgnHolder *prh = g_slice_new0 (GimpPixelRgnHolder);
pr = prs[nrgns];
prh = g_new0 (GimpPixelRgnHolder, 1);
prh->pr = pr; prh->pr = pr;
if (pr != NULL) if (pr != NULL)
@ -724,13 +721,12 @@ gimp_pixel_rgns_register (gint nrgns,
...) ...)
{ {
GimpPixelRgn **prs; GimpPixelRgn **prs;
gpointer pri;
gint n; gint n;
va_list ap; va_list ap;
g_return_val_if_fail (nrgns > 0, NULL); g_return_val_if_fail (nrgns > 0, NULL);
prs = g_new (GimpPixelRgn *, nrgns); prs = g_newa (GimpPixelRgn *, nrgns);
va_start (ap, nrgns); va_start (ap, nrgns);
@ -739,11 +735,7 @@ gimp_pixel_rgns_register (gint nrgns,
va_end (ap); va_end (ap);
pri = gimp_pixel_rgns_register2 (nrgns, prs); return gimp_pixel_rgns_register2 (nrgns, prs);
g_free (prs);
return pri;
} }
/** /**
@ -905,10 +897,10 @@ gimp_pixel_rgns_configure (GimpPixelRgnIterator *pri)
{ {
/* free the pixel regions list */ /* free the pixel regions list */
for (list = pri->pixel_regions; list; list = list->next) for (list = pri->pixel_regions; list; list = list->next)
g_free (list->data); g_slice_free (GimpPixelRgnHolder, list->data);
g_slist_free (pri->pixel_regions); g_slist_free (pri->pixel_regions);
g_free (pri); g_slice_free (GimpPixelRgnIterator, pri);
return NULL; return NULL;
} }

View File

@ -30,23 +30,23 @@
#include "gimp.h" #include "gimp.h"
typedef struct _GimpProgressData GimpProgressData; typedef struct
struct _GimpProgressData
{ {
gchar *progress_callback; gchar *progress_callback;
GimpProgressVtable vtable; GimpProgressVtable vtable;
gpointer data; gpointer data;
}; } GimpProgressData;
/* local function prototypes */ /* local function prototypes */
static void gimp_temp_progress_run (const gchar *name, static void gimp_progress_data_free (GimpProgressData *data);
gint nparams,
const GimpParam *param, static void gimp_temp_progress_run (const gchar *name,
gint *nreturn_vals, gint nparams,
GimpParam **return_vals); const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
/* private variables */ /* private variables */
@ -153,10 +153,14 @@ gimp_progress_install_vtable (const GimpProgressVtable *vtable,
/* Now add to hash table so we can find it again */ /* Now add to hash table so we can find it again */
if (! gimp_progress_ht) if (! gimp_progress_ht)
gimp_progress_ht = g_hash_table_new_full (g_str_hash, g_str_equal, {
g_free, g_free); gimp_progress_ht =
g_hash_table_new_full (g_str_hash, g_str_equal,
g_free,
(GDestroyNotify) gimp_progress_data_free);
}
progress_data = g_new0 (GimpProgressData, 1); progress_data = g_slice_new0 (GimpProgressData);
progress_data->progress_callback = progress_callback; progress_data->progress_callback = progress_callback;
progress_data->vtable.start = vtable->start; progress_data->vtable.start = vtable->start;
@ -365,6 +369,12 @@ gimp_progress_update (gdouble percentage)
/* private functions */ /* private functions */
static void
gimp_progress_data_free (GimpProgressData *data)
{
g_slice_free (GimpProgressData, data);
}
static void static void
gimp_temp_progress_run (const gchar *name, gimp_temp_progress_run (const gchar *name,
gint nparams, gint nparams,

View File

@ -3,12 +3,6 @@
* *
* gimpregioniterator.c * gimpregioniterator.c
* *
* FIXME: fix the following comment:
* Contains all kinds of miscellaneous routines factored out from different
* plug-ins. They stay here until their API has crystalized a bit and we can
* put them into the file where they belong (Maurits Rijk
* <lpeek.mrijk@consunet.nl> if you want to blame someone for this mess)
*
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -38,7 +32,10 @@
struct _GimpRgnIterator struct _GimpRgnIterator
{ {
GimpDrawable *drawable; GimpDrawable *drawable;
gint x1, y1, x2, y2; gint x1;
gint y1;
gint x2;
gint y2;
}; };
@ -64,7 +61,8 @@ static void gimp_rgn_render_region (const GimpPixelRgn *srcPR,
* @unused: ignored * @unused: ignored
* *
* Creates a new #GimpRgnIterator for @drawable. The #GimpRunMode * Creates a new #GimpRgnIterator for @drawable. The #GimpRunMode
* parameter is ignored. * parameter is ignored. Use gimp_rgn_iterator_free() to free thsi
* iterator.
* *
* Return value: a newly allocated #GimpRgnIterator. * Return value: a newly allocated #GimpRgnIterator.
**/ **/
@ -72,7 +70,11 @@ GimpRgnIterator *
gimp_rgn_iterator_new (GimpDrawable *drawable, gimp_rgn_iterator_new (GimpDrawable *drawable,
GimpRunMode unused) GimpRunMode unused)
{ {
GimpRgnIterator *iter = g_new (GimpRgnIterator, 1); GimpRgnIterator *iter;
g_return_val_if_fail (drawable != NULL, NULL);
iter = g_slice_new (GimpRgnIterator);
iter->drawable = drawable; iter->drawable = drawable;
@ -92,7 +94,9 @@ gimp_rgn_iterator_new (GimpDrawable *drawable,
void void
gimp_rgn_iterator_free (GimpRgnIterator *iter) gimp_rgn_iterator_free (GimpRgnIterator *iter)
{ {
g_free (iter); g_return_if_fail (iter != NULL);
g_slice_free (GimpRgnIterator, iter);
} }
void void
@ -102,6 +106,8 @@ gimp_rgn_iterator_src (GimpRgnIterator *iter,
{ {
GimpPixelRgn srcPR; GimpPixelRgn srcPR;
g_return_if_fail (iter != NULL);
gimp_pixel_rgn_init (&srcPR, iter->drawable, gimp_pixel_rgn_init (&srcPR, iter->drawable,
iter->x1, iter->y1, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, iter->x2 - iter->x1, iter->y2 - iter->y1,
@ -121,6 +127,8 @@ gimp_rgn_iterator_src_dest (GimpRgnIterator *iter,
gint total_area; gint total_area;
gint area_so_far; gint area_so_far;
g_return_if_fail (iter != NULL);
x1 = iter->x1; x1 = iter->x1;
y1 = iter->y1; y1 = iter->y1;
x2 = iter->x2; x2 = iter->x2;
@ -178,6 +186,8 @@ gimp_rgn_iterator_dest (GimpRgnIterator *iter,
{ {
GimpPixelRgn destPR; GimpPixelRgn destPR;
g_return_if_fail (iter != NULL);
gimp_pixel_rgn_init (&destPR, iter->drawable, gimp_pixel_rgn_init (&destPR, iter->drawable,
iter->x1, iter->y1, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, iter->x2 - iter->x1, iter->y2 - iter->y1,
@ -206,6 +216,8 @@ gimp_rgn_iterate1 (GimpDrawable *drawable,
gint area_so_far; gint area_so_far;
gint progress_skip; gint progress_skip;
g_return_if_fail (drawable != NULL);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1); total_area = (x2 - x1) * (y2 - y1);
@ -260,6 +272,8 @@ gimp_rgn_iterate2 (GimpDrawable *drawable,
gint area_so_far; gint area_so_far;
gint progress_skip; gint progress_skip;
g_return_if_fail (drawable != NULL);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1); total_area = (x2 - x1) * (y2 - y1);