Commit a64029ba authored by Maurits Rijk's avatar Maurits Rijk
Browse files

Changed plug-ins so they now use gimpmisc functions.

parent 2a37c9e6
2002-11-21 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/blinds.c: use gimp_get_bg_guchar
* libgimp/gimpmisc.[ch]: added gimp_pixel_fetcher routine with
wrapmode and generic get background color routine (gimp_get_bg_guchar)
* plug-ins/common/edge.c: : use gimp_pixel_fetcher routines
2002-11-21 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/AlienMap.c
* plug-ins/common/AlienMap2.c: use gimp_pixel_fetcher routines
2002-11-21 Sven Neumann <sven@gimp.org>
 
* app/config/gimpdisplayconfig.[ch]
......
......@@ -81,9 +81,9 @@ gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf)
void
gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel)
gint x,
gint y,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
......@@ -104,9 +104,83 @@ gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) ||
(row != pf->row) ||
(pf->tile == NULL))
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
pf->tile = gimp_drawable_get_tile (pf->drawable, FALSE, row, col);
gimp_tile_ref (pf->tile);
pf->col = col;
pf->row = row;
}
p = pf->tile->data + pf->img_bpp * (pf->tile->ewidth * rowoff + coloff);
for (i = pf->img_bpp; i; i--)
*pixel++ = *p++;
}
void
gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
guchar *p;
gint i;
if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
switch (wrapmode)
{
case PIXEL_WRAP:
if (x < 0 || x >= pf->img_width)
{
x %= pf->img_width;
if (x < 0)
x += pf->img_width;
}
if (y < 0 || y >= pf->img_height)
{
y %= pf->img_height;
if (y < 0)
y += pf->img_height;
}
break;
case PIXEL_SMEAR:
if (x < 0)
x = 0;
if (x >= pf->img_width)
x = pf->img_width - 1;
if (y < 0)
y = 0;
if (y >= pf->img_height)
y = 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++)
pixel[i] = 0;
return;
}
break;
default:
return;
}
col = x / pf->tile_width;
coloff = x % pf->tile_width;
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
......@@ -132,3 +206,39 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = transparent ? 0 : 255;
break;
default:
break;
}
}
......@@ -30,6 +30,13 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
enum
{
PIXEL_WRAP,
PIXEL_SMEAR,
PIXEL_BLACK
};
typedef struct
{
gint col, row;
......@@ -47,11 +54,21 @@ typedef struct
GimpPixelFetcher *gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
int x,
int y,
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_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
G_END_DECLS
#endif /* __GIMP_MISC_H__ */
......@@ -81,9 +81,9 @@ gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf)
void
gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel)
gint x,
gint y,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
......@@ -104,9 +104,83 @@ gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) ||
(row != pf->row) ||
(pf->tile == NULL))
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
pf->tile = gimp_drawable_get_tile (pf->drawable, FALSE, row, col);
gimp_tile_ref (pf->tile);
pf->col = col;
pf->row = row;
}
p = pf->tile->data + pf->img_bpp * (pf->tile->ewidth * rowoff + coloff);
for (i = pf->img_bpp; i; i--)
*pixel++ = *p++;
}
void
gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
guchar *p;
gint i;
if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
switch (wrapmode)
{
case PIXEL_WRAP:
if (x < 0 || x >= pf->img_width)
{
x %= pf->img_width;
if (x < 0)
x += pf->img_width;
}
if (y < 0 || y >= pf->img_height)
{
y %= pf->img_height;
if (y < 0)
y += pf->img_height;
}
break;
case PIXEL_SMEAR:
if (x < 0)
x = 0;
if (x >= pf->img_width)
x = pf->img_width - 1;
if (y < 0)
y = 0;
if (y >= pf->img_height)
y = 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++)
pixel[i] = 0;
return;
}
break;
default:
return;
}
col = x / pf->tile_width;
coloff = x % pf->tile_width;
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
......@@ -132,3 +206,39 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = transparent ? 0 : 255;
break;
default:
break;
}
}
......@@ -30,6 +30,13 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
enum
{
PIXEL_WRAP,
PIXEL_SMEAR,
PIXEL_BLACK
};
typedef struct
{
gint col, row;
......@@ -47,11 +54,21 @@ typedef struct
GimpPixelFetcher *gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
int x,
int y,
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_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
G_END_DECLS
#endif /* __GIMP_MISC_H__ */
......@@ -81,9 +81,9 @@ gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf)
void
gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel)
gint x,
gint y,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
......@@ -104,9 +104,83 @@ gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) ||
(row != pf->row) ||
(pf->tile == NULL))
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
pf->tile = gimp_drawable_get_tile (pf->drawable, FALSE, row, col);
gimp_tile_ref (pf->tile);
pf->col = col;
pf->row = row;
}
p = pf->tile->data + pf->img_bpp * (pf->tile->ewidth * rowoff + coloff);
for (i = pf->img_bpp; i; i--)
*pixel++ = *p++;
}
void
gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
gint x,
gint y,
gint wrapmode,
guchar *pixel)
{
gint col, row;
gint coloff, rowoff;
guchar *p;
gint i;
if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
switch (wrapmode)
{
case PIXEL_WRAP:
if (x < 0 || x >= pf->img_width)
{
x %= pf->img_width;
if (x < 0)
x += pf->img_width;
}
if (y < 0 || y >= pf->img_height)
{
y %= pf->img_height;
if (y < 0)
y += pf->img_height;
}
break;
case PIXEL_SMEAR:
if (x < 0)
x = 0;
if (x >= pf->img_width)
x = pf->img_width - 1;
if (y < 0)
y = 0;
if (y >= pf->img_height)
y = 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++)
pixel[i] = 0;
return;
}
break;
default:
return;
}
col = x / pf->tile_width;
coloff = x % pf->tile_width;
row = y / pf->tile_height;
rowoff = y % pf->tile_height;
if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
{
if (pf->tile != NULL)
gimp_tile_unref(pf->tile, FALSE);
......@@ -132,3 +206,39 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[1] = transparent ? 0 : 255;
break;
default:
break;
}
}
......@@ -30,6 +30,13 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
enum
{
PIXEL_WRAP,
PIXEL_SMEAR,
PIXEL_BLACK
};
typedef struct
{
gint col, row;
......@@ -47,11 +54,21 @@ typedef struct
GimpPixelFetcher *gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
int x,
int y,
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_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
G_END_DECLS
#endif /* __GIMP_MISC_H__ */
......@@ -862,7 +862,6 @@ typedef struct
} alienmap_interface_t;
/* Declare local functions. */
static void query (void);
......@@ -878,7 +877,6 @@ static void alienmap_render_row (const guchar *src_row,
gint row,
gint row_width,
gint bytes, double, double, double);
static void alienmap_get_pixel (int x, int y, guchar *pixel);
static void transform (guchar *, guchar *, guchar *,
double, double, double);
......@@ -895,9 +893,6 @@ static void alienmap_logo_dialog (void);
/***** Variables *****/
GtkWidget *maindlg;
GtkWidget *logodlg;
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -925,13 +920,8 @@ static alienmap_vals_t wvals =
};
static GimpDrawable *drawable;
static gint tile_width, tile_height;
static gint img_width, img_height, img_bpp;
static gint sel_x1, sel_y1, sel_x2, sel_y2;
static gint sel_width, sel_height;
static gint preview_width, preview_height;
static GimpTile *the_tile = NULL;
static gdouble cen_x, cen_y;
static gdouble scale_x, scale_y;
/***** Functions *****/
......@@ -1048,11 +1038,10 @@ run (char *name,
GimpParam **return_vals)
{
static GimpParam values[1];
/* GDrawable *drawable; */
/* gint32 image_ID; */
GimpRunMode run_mode;
double xhsiz, yhsiz;
int pwidth, pheight;
double xhsiz, yhsiz;
gint sel_width, sel_height;
int pwidth, pheight;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N_UI ();
......@@ -1067,13 +1056,6 @@ run (char *name,
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
/* image_ID = param[1].data.d_image; */
tile_width = gimp_tile_width();
tile_height = gimp_tile_height();
img_width = gimp_drawable_width(drawable->drawable_id);
img_height = gimp_drawable_height(drawable->drawable_id);
img_bpp = gimp_drawable_bpp(drawable->drawable_id);
gimp_drawable_mask_bounds(drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
......@@ -1081,9 +1063,6 @@ run (char *name,
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
cen_x = (double) (sel_x2 - 1 + sel_x1) / 2.0;
cen_y = (double) (sel_y2 - 1 + sel_y1) / 2.0;