Commit 6d4e9534 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

Some code cleanup while trying to fix bug #105062:

2003-02-03  Sven Neumann  <neo@wintermute>

	Some code cleanup while trying to fix bug #105062:

	* libgimp/gimpmisc.[ch]: moved the declaration of the
	GimpPixelFetcher struct to the .c file since noone should ever
	access it directly.

	* libgimp/gimpmiscui.c: cosmetics.

	* plug-ins/common/plasma.c: code cleanup, doesn't fix #105062.
parent 0b90802f
2003-02-03 Sven Neumann <neo@wintermute>
Some code cleanup while trying to fix bug #105062:
* libgimp/gimpmisc.[ch]: moved the declaration of the
GimpPixelFetcher struct to the .c file since noone should ever
access it directly.
* libgimp/gimpmiscui.c: cosmetics.
* plug-ins/common/plasma.c: code cleanup, doesn't fix #105062.
2003-02-02 Sven Neumann <sven@gimp.org>
 
* plug-ins/ifscompose/ifscompose.c: fixed some issues (mainly
......
......@@ -23,17 +23,33 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdio.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpmisc.h"
struct _GimpPixelFetcher
{
gint col, row;
gint img_width;
gint img_height;
gint sel_x1, sel_y1, sel_x2, sel_y2;
gint img_bpp;
gint img_has_alpha;
gint tile_width, tile_height;
guchar bg_color[4];
GimpDrawable *drawable;
GimpTile *tile;
gboolean tile_dirty;
gboolean shadow;
};
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
{
......@@ -47,9 +63,9 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable)
pf->col = -1;
pf->row = -1;
pf->img_width = gimp_drawable_width (drawable->drawable_id);
pf->img_height = gimp_drawable_height (drawable->drawable_id);
pf->img_bpp = gimp_drawable_bpp (drawable->drawable_id);
pf->img_width = gimp_drawable_width (drawable->drawable_id);
pf->img_height = gimp_drawable_height (drawable->drawable_id);
pf->img_bpp = gimp_drawable_bpp (drawable->drawable_id);
pf->img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
pf->tile_width = gimp_tile_width ();
pf->tile_height = gimp_tile_height ();
......@@ -57,11 +73,13 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable)
pf->bg_color[1] = 0;
pf->bg_color[2] = 0;
pf->bg_color[3] = 255;
pf->drawable = drawable;
pf->tile = NULL;
pf->tile_dirty = FALSE;
pf->shadow = FALSE;
pf->drawable = drawable;
pf->tile = NULL;
pf->tile_dirty = FALSE;
pf->shadow = FALSE;
/* this allows us to use (slightly faster) do-while loops */
g_assert (pf->img_bpp > 0);
return pf;
}
......@@ -90,18 +108,18 @@ gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf)
void
gimp_pixel_fetcher_set_shadow (GimpPixelFetcher *pf,
gboolean shadow)
gboolean shadow)
{
pf->shadow = shadow;
}
static guchar*
static guchar *
gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
gint x,
gint y)
gint x,
gint y)
{
gint col, row;
gint coloff, rowoff;
gint col, row;
gint coloff, rowoff;
col = x / pf->tile_width;
coloff = x % pf->tile_width;
......@@ -111,7 +129,7 @@ gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, pf->tile_dirty);
gimp_tile_unref (pf->tile, pf->tile_dirty);
pf->tile = gimp_drawable_get_tile (pf->drawable, pf->shadow, row, col);
pf->tile_dirty = FALSE;
......@@ -126,9 +144,9 @@ gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
void
gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel)
gint x,
gint y,
guchar *pixel)
{
guchar *p;
gint i;
......@@ -141,15 +159,17 @@ gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
p = gimp_pixel_fetcher_provide_tile (pf, x, y);
for (i = pf->img_bpp; i; i--)
i = pf->img_bpp;
do
*pixel++ = *p++;
while (--i);
}
void
gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel)
gint x,
gint y,
guchar *pixel)
{
guchar *p;
gint i;
......@@ -162,18 +182,20 @@ gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
p = gimp_pixel_fetcher_provide_tile (pf, x, y);
for (i = pf->img_bpp; i; i--)
i = pf->img_bpp;
do
*p++ = *pixel++;
while (--i);
pf->tile_dirty = TRUE;
}
void
gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel)
gint x,
gint y,
gint wrapmode,
guchar *pixel)
{
guchar *p;
gint i;
......@@ -196,33 +218,41 @@ gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
y += pf->img_height;
}
break;
case PIXEL_SMEAR:
x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height - 1);
break;
case PIXEL_BLACK:
if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
{
for (i = 0; i < pf->img_bpp; i++)
i = pf->img_bpp;
do
pixel[i] = 0;
while (--i);
return;
}
break;
default:
return;
}
p = gimp_pixel_fetcher_provide_tile (pf, x, y);
for (i = pf->img_bpp; i; i--)
i = pf->img_bpp;
do
*pixel++ = *p++;
while (--i);
}
void
gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
{
if (pf->tile != NULL)
if (pf->tile)
gimp_tile_unref (pf->tile, pf->tile_dirty);
g_free (pf);
......@@ -230,8 +260,8 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
gboolean transparent,
guchar *bg)
{
GimpRGB background;
......@@ -265,12 +295,12 @@ gimp_get_bg_guchar (GimpDrawable *drawable,
}
static void
gimp_rgn_render_row (guchar *src,
guchar *dest,
gint col, /* row width in pixels */
gint bpp,
GimpRgnFunc2 func,
gpointer data)
gimp_rgn_render_row (guchar *src,
guchar *dest,
gint col, /* row width in pixels */
gint bpp,
GimpRgnFunc2 func,
gpointer data)
{
while (col--)
{
......@@ -283,9 +313,10 @@ gimp_rgn_render_row (guchar *src,
static void
gimp_rgn_render_region (const GimpPixelRgn *srcPR,
const GimpPixelRgn *destPR,
GimpRgnFunc2 func, gpointer data)
GimpRgnFunc2 func,
gpointer data)
{
gint row;
gint row;
guchar* src = srcPR->data;
guchar* dest = destPR->data;
......@@ -299,8 +330,10 @@ gimp_rgn_render_region (const GimpPixelRgn *srcPR,
}
void
gimp_rgn_iterate1 (GimpDrawable *drawable, GimpRunMode run_mode,
GimpRgnFunc1 func, gpointer data)
gimp_rgn_iterate1 (GimpDrawable *drawable,
GimpRunMode run_mode,
GimpRgnFunc1 func,
gpointer data)
{
GimpPixelRgn srcPR;
gint x1, y1, x2, y2;
......@@ -323,7 +356,7 @@ gimp_rgn_iterate1 (GimpDrawable *drawable, GimpRunMode run_mode,
pr = gimp_pixel_rgns_process (pr))
{
guchar *src = srcPR.data;
gint y;
gint y;
for (y = 0; y < srcPR.h; y++)
{
......@@ -343,14 +376,17 @@ gimp_rgn_iterate1 (GimpDrawable *drawable, GimpRunMode run_mode,
{
area_so_far += srcPR.w * srcPR.h;
if (((progress_skip++) % 10) == 0)
gimp_progress_update ((double) area_so_far / (double) total_area);
gimp_progress_update ((gdouble) area_so_far /
(gdouble) total_area);
}
}
}
void
gimp_rgn_iterate2 (GimpDrawable *drawable, GimpRunMode run_mode,
GimpRgnFunc2 func, gpointer data)
gimp_rgn_iterate2 (GimpDrawable *drawable,
GimpRunMode run_mode,
GimpRgnFunc2 func,
gpointer data)
{
GimpPixelRgn srcPR, destPR;
gint x1, y1, x2, y2;
......@@ -381,7 +417,8 @@ gimp_rgn_iterate2 (GimpDrawable *drawable, GimpRunMode run_mode,
{
area_so_far += srcPR.w * srcPR.h;
if (((progress_skip++) % 10) == 0)
gimp_progress_update ((double) area_so_far / (double) total_area);
gimp_progress_update ((gdouble) area_so_far /
(gdouble) total_area);
}
}
......
......@@ -30,6 +30,7 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
enum
{
PIXEL_WRAP,
......@@ -37,59 +38,46 @@ enum
PIXEL_BLACK,
};
typedef struct
{
gint col, row;
gint img_width;
gint img_height;
gint sel_x1, sel_y1, sel_x2, sel_y2;
gint img_bpp;
gint img_has_alpha;
gint tile_width, tile_height;
guchar bg_color[4];
GimpDrawable *drawable;
GimpTile *tile;
gboolean tile_dirty;
gboolean shadow;
} GimpPixelFetcher;
GimpPixelFetcher *gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_set_shadow (GimpPixelFetcher *pf,
gboolean shadow);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel);
void gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel);
void gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel);
void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
typedef void (*GimpRgnFunc1)(guchar *src, gint bpp, gpointer);
typedef void (*GimpRgnFunc2)(guchar *src, guchar *dest, gint bpp, gpointer);
typedef struct _GimpPixelFetcher GimpPixelFetcher;
GimpPixelFetcher * gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_set_shadow (GimpPixelFetcher *pf,
gboolean shadow);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel);
void gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel);
void gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel);
void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
typedef void (* GimpRgnFunc1) (guchar *src, gint bpp, gpointer);
typedef void (* GimpRgnFunc2) (guchar *src, guchar *dest, gint bpp, gpointer);
void gimp_rgn_iterate1 (GimpDrawable *drawable,
GimpRunMode run_mode,
GimpRgnFunc1 func,
gpointer data);
GimpRunMode run_mode,
GimpRgnFunc1 func,
gpointer data);
void gimp_rgn_iterate2 (GimpDrawable *drawable,
GimpRunMode run_mode,
GimpRgnFunc2 func,
gpointer data);
GimpRunMode run_mode,
GimpRgnFunc2 func,
gpointer data);
G_END_DECLS
......
......@@ -23,25 +23,28 @@
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <string.h>
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpintl.h"
#include "gimpmiscui.h"
#include "gimpintl.h"
#define PREVIEW_SIZE 128
GimpFixMePreview*
gimp_fixme_preview_new (GimpDrawable *drawable, gboolean has_frame)
gimp_fixme_preview_new (GimpDrawable *drawable,
gboolean has_frame)
{
GimpFixMePreview *preview = g_new0 (GimpFixMePreview, 1);
......@@ -85,9 +88,9 @@ gimp_fixme_preview_free (GimpFixMePreview *preview)
void
gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint row,
gint width,
guchar *src)
gint row,
gint width,
guchar *src)
{
gint x;
guchar *p0 = preview->even;
......@@ -167,20 +170,20 @@ gimp_fixme_preview_do_row (GimpFixMePreview *preview,
}
void
gimp_fixme_preview_update (GimpFixMePreview *preview,
GimpFixeMePreviewFunc func,
gpointer data)
gimp_fixme_preview_update (GimpFixMePreview *preview,
GimpFixeMePreviewFunc func,
gpointer data)
{
gint x, y;
guchar *buffer;
gint bpp;
gint bpp;
bpp = preview->bpp;
buffer = (guchar*) g_malloc (preview->rowstride);
bpp = preview->bpp;
buffer = g_new (guchar, preview->rowstride);
for (y = 0; y < preview->height; y++)
{
guchar *src = preview->cache + y * preview->rowstride;
guchar *src = preview->cache + y * preview->rowstride;
guchar *dest = buffer;
for (x = 0; x < preview->width; x++)
......@@ -190,16 +193,18 @@ gimp_fixme_preview_update (GimpFixMePreview *preview,
src += bpp;
dest += bpp;
}
gimp_fixme_preview_do_row(preview, y, preview->width, buffer);
gimp_fixme_preview_do_row (preview, y, preview->width, buffer);
}
gtk_widget_queue_draw(preview->widget);
gtk_widget_queue_draw (preview->widget);
g_free (buffer);
}
void
gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
gint32 drawable_ID)
gint32 drawable_ID)
{
gint bpp;
gint y;
......@@ -244,21 +249,21 @@ gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
}
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
}
void
gimp_fixme_preview_fill (GimpFixMePreview *preview,
GimpDrawable *drawable)
GimpDrawable *drawable)
{
GimpPixelRgn srcPR;
gint width;
gint height;
gint x1, x2, y1, y2;
gint bpp;
gint y;
guchar *src;
gint width;
gint height;
gint x1, x2, y1, y2;
gint bpp;
gint y;
guchar *src;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
......@@ -306,7 +311,7 @@ gimp_fixme_preview_fill (GimpFixMePreview *preview,
}
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
g_free (src);
......@@ -314,19 +319,19 @@ gimp_fixme_preview_fill (GimpFixMePreview *preview,
void
gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
GimpDrawable *drawable)
GimpDrawable *drawable)
{
gint bpp;
gint x1, y1, x2, y2;
gint sel_width, sel_height;
gint width, height;
gdouble px, py;
gdouble dx, dy;
gint x, y;
guchar *dest;
gint bpp;
gint x1, y1, x2, y2;
gint sel_width, sel_height;
gint width, height;
gdouble px, py;
gdouble dx, dy;
gint x, y;
guchar *dest;
GimpPixelFetcher *pft;
gimp_drawable_mask_bounds(drawable->drawable_id, &x1, &y1, &x2, &y2);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
sel_width = x2 - x1;
sel_height = y2 - y1;
......@@ -334,7 +339,7 @@ gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
/* Calculate preview size */
if (sel_width > sel_height)
{
width = MIN(sel_width, PREVIEW_SIZE);
width = MIN (sel_width, PREVIEW_SIZE);
height = sel_height * width / sel_width;
}
else
......@@ -360,11 +365,11 @@ gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
gtk_preview_size (GTK_PREVIEW (preview->widget), width, height);
preview->even = g_malloc (width * 3);
preview->odd = g_malloc (width * 3);
preview->cache = g_malloc(width * bpp * height);
preview->even = g_malloc (width * 3);
preview->odd = g_malloc (width * 3);
preview->cache = g_malloc (width * bpp * height);
preview->rowstride = width * bpp;
preview->bpp = bpp;
preview->bpp = bpp;
dx = (gdouble) (x2 - x1 - 1) / (width - 1);
dy = (gdouble) (y2 - y1 - 1) / (height - 1);
......@@ -389,15 +394,15 @@ gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
gimp_pixel_fetcher_destroy (pft);
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
}
GList*
gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name)
gimp_plug_in_parse_path (gchar *path_name,
const gchar *dir_name)
{
GList *path_list = NULL;
GList *fail_list = NULL;
gchar *path;
path = gimp_gimprc_query (path_name);
......@@ -424,19 +429,14 @@ gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name)
g_free (gimprc);
g_free (full_path);
g_free (esc_path);
return NULL;
}
path_list = gimp_path_parse (path, 16, TRUE, &fail_list);
path_list = gimp_path_parse (path, 16, TRUE, NULL);