Commit a64029ba authored by Maurits Rijk's avatar Maurits Rijk

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;
xhsiz = (double) (sel_width - 1) / 2.0;
yhsiz = (double) (sel_height - 1) / 2.0;
......@@ -1188,49 +1167,6 @@ run (char *name,
gimp_drawable_detach (drawable);
}
static void
alienmap_get_pixel (int x,
int y,
guchar *pixel)
{
static gint row = -1;
static gint col = -1;
gint newcol, newrow;
gint newcoloff, newrowoff;
guchar *p;
int i;
if ((x < 0) || (x >= img_width) || (y < 0) || (y >= img_height))
{
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 0;
return;
}
newcol = x / tile_width; /* The compiler should optimize this */
newcoloff = x % tile_width;
newrow = y / tile_height;
newrowoff = y % tile_height;
if ((col != newcol) || (row != newrow) || (the_tile == NULL))
{
if (the_tile != NULL)
gimp_tile_unref(the_tile, FALSE);
the_tile = gimp_drawable_get_tile(drawable, FALSE, newrow, newcol);
gimp_tile_ref(the_tile);
col = newcol;
row = newrow;
}
p = the_tile->data + the_tile->bpp * (the_tile->ewidth * newrowoff + newcoloff);
for (i = img_bpp; i; i--)
*pixel++ = *p++;
}
static void
alienmap_render_row (const guchar *src_row,
guchar *dest_row,
......@@ -1328,6 +1264,7 @@ build_preview_source_image (void)
int x, y;
guchar *p;
guchar pixel[4];
GimpPixelFetcher *pft;
wint.image = g_new (guchar, preview_width * preview_height * 3);
wint.wimage = g_new (guchar, preview_width * preview_height * 3);
......@@ -1344,12 +1281,14 @@ build_preview_source_image (void)
p = wint.image;
pft = gimp_pixel_fetcher_new (drawable);
for (y = 0; y < preview_height; y++)
{
px = left;
for (x = 0; x < preview_width; x++)
{
alienmap_get_pixel((int) px, (int) py, pixel);
gimp_pixel_fetcher_get_pixel (pft, (gint) px, (gint) py, pixel);
*p++ = pixel[0];
*p++ = pixel[1];
......@@ -1360,6 +1299,7 @@ build_preview_source_image (void)
py += dy;
}
gimp_pixel_fetcher_destroy (pft);
}
static gint
......@@ -1378,13 +1318,13 @@ alienmap_dialog (void)
build_preview_source_image ();
dialog = maindlg =
dialog =
gimp_dialog_new (_("AlienMap"), "alienmap",
gimp_standard_help_func, "filters/alienmap.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("About"), alienmap_logo_dialog,
_("About..."), alienmap_logo_dialog,
NULL, NULL, NULL, FALSE, FALSE,
GTK_STOCK_CANCEL, gtk_widget_destroy,
......@@ -1531,12 +1471,6 @@ alienmap_dialog (void)
gimp_help_free ();
gdk_flush ();
if (the_tile != NULL)
{
gimp_tile_unref (the_tile, FALSE);
the_tile = NULL;
}
g_free (wint.image);
g_free (wint.wimage);
......@@ -1634,6 +1568,7 @@ alienmap_toggle_update (GtkWidget *widget,
static void
alienmap_logo_dialog (void)
{
static GtkWidget *logodlg = NULL;
GtkWidget *xlabel;
GtkWidget *xlogo_box;