Commit a779e748 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Cleaned up the remaining libgimp API issues:

2004-03-12  Michael Natterer  <mitch@gimp.org>

	Cleaned up the remaining libgimp API issues:

	* libgimp/gimppixelfetcher.[ch] (enum GimpPixelFetcherEdgeMode):
	added new enum value GIMP_PIXEL_FETCHER_EDGE_BACKGROUND so we
	can actually use the bg_color feature of the GimpPixelFetcher.

	(gimp_pixel_fetcher_new): added "gboolean shadow" parameter
	because it must not change while the GimpPixelFetcher exists.

	(gimp_pixel_fetcher_set_shadow): removed.

	(gimp_pixel_fetcher_set_bg_color): added "GimpRGB *color"
	parameter and don't call gimp_palette_get_foreground().

	(gimp_pixel_fetcher_get_pixel): handle BACKGROUND mode. Cleaned up
	the function.

	(gimp_get_bg_guchar)
	(gimp_get_fg_guchar): removed these functions...

	* libgimp/gimpdrawable.[ch]: ...and added
	gimp_drawable_get_color_uchar() instead.

	* libgimp/gimp.def
	* plug-ins/common/blinds.c
	* plug-ins/common/checkerboard.c
	* plug-ins/common/cubism.c
	* plug-ins/common/curve_bend.c
	* plug-ins/common/displace.c
	* plug-ins/common/edge.c
	* plug-ins/common/illusion.c
	* plug-ins/common/mblur.c
	* plug-ins/common/mosaic.c
	* plug-ins/common/plasma.c
	* plug-ins/common/polar.c
	* plug-ins/common/ripple.c
	* plug-ins/common/shift.c
	* plug-ins/common/spread.c
	* plug-ins/common/tileit.c
	* plug-ins/common/whirlpinch.c
	* plug-ins/gflare/gflare.c
	* plug-ins/libgimpoldpreview/gimpoldpreview.c: changed accordingly.

	(Didn't test the changed plug-ins because I wanted to get this
	API change into CVS as soon as possible)
parent 5f9f60f4
2004-03-12 Michael Natterer <mitch@gimp.org>
Cleaned up the remaining libgimp API issues:
* libgimp/gimppixelfetcher.[ch] (enum GimpPixelFetcherEdgeMode):
added new enum value GIMP_PIXEL_FETCHER_EDGE_BACKGROUND so we
can actually use the bg_color feature of the GimpPixelFetcher.
(gimp_pixel_fetcher_new): added "gboolean shadow" parameter
because it must not change while the GimpPixelFetcher exists.
(gimp_pixel_fetcher_set_shadow): removed.
(gimp_pixel_fetcher_set_bg_color): added "GimpRGB *color"
parameter and don't call gimp_palette_get_foreground().
(gimp_pixel_fetcher_get_pixel): handle BACKGROUND mode. Cleaned up
the function.
(gimp_get_bg_guchar)
(gimp_get_fg_guchar): removed these functions...
* libgimp/gimpdrawable.[ch]: ...and added
gimp_drawable_get_color_uchar() instead.
* libgimp/gimp.def
* plug-ins/common/blinds.c
* plug-ins/common/checkerboard.c
* plug-ins/common/cubism.c
* plug-ins/common/curve_bend.c
* plug-ins/common/displace.c
* plug-ins/common/edge.c
* plug-ins/common/illusion.c
* plug-ins/common/mblur.c
* plug-ins/common/mosaic.c
* plug-ins/common/plasma.c
* plug-ins/common/polar.c
* plug-ins/common/ripple.c
* plug-ins/common/shift.c
* plug-ins/common/spread.c
* plug-ins/common/tileit.c
* plug-ins/common/whirlpinch.c
* plug-ins/gflare/gflare.c
* plug-ins/libgimpoldpreview/gimpoldpreview.c: changed accordingly.
(Didn't test the changed plug-ins because I wanted to get this
API change into CVS as soon as possible)
2004-03-12 Raphaël Quinet <quinet@gamers.org> 2004-03-12 Raphaël Quinet <quinet@gamers.org>
* app/core/gimpdrawable-transform.c (RECURSION_LEVEL): Set to 0 in * app/core/gimpdrawable-transform.c (RECURSION_LEVEL): Set to 0 in
...@@ -54,6 +54,7 @@ EXPORTS ...@@ -54,6 +54,7 @@ EXPORTS
gimp_drawable_fill gimp_drawable_fill
gimp_drawable_flush gimp_drawable_flush
gimp_drawable_get gimp_drawable_get
gimp_drawable_get_color_uchar
gimp_drawable_get_image gimp_drawable_get_image
gimp_drawable_get_linked gimp_drawable_get_linked
gimp_drawable_get_name gimp_drawable_get_name
...@@ -121,9 +122,7 @@ EXPORTS ...@@ -121,9 +122,7 @@ EXPORTS
gimp_free_select gimp_free_select
gimp_fuzzy_select gimp_fuzzy_select
gimp_gamma gimp_gamma
gimp_get_bg_guchar
gimp_get_default_comment gimp_get_default_comment
gimp_get_fg_guchar
gimp_get_module_load_inhibit gimp_get_module_load_inhibit
gimp_get_monitor_resolution gimp_get_monitor_resolution
gimp_get_path_by_tattoo gimp_get_path_by_tattoo
...@@ -314,7 +313,6 @@ EXPORTS ...@@ -314,7 +313,6 @@ EXPORTS
gimp_pixel_fetcher_put_pixel gimp_pixel_fetcher_put_pixel
gimp_pixel_fetcher_set_bg_color gimp_pixel_fetcher_set_bg_color
gimp_pixel_fetcher_set_edge_mode gimp_pixel_fetcher_set_edge_mode
gimp_pixel_fetcher_set_shadow
gimp_pixel_rgn_get_col gimp_pixel_rgn_get_col
gimp_pixel_rgn_get_pixel gimp_pixel_rgn_get_pixel
gimp_pixel_rgn_get_rect gimp_pixel_rgn_get_rect
......
...@@ -182,6 +182,43 @@ gimp_drawable_get_tile2 (GimpDrawable *drawable, ...@@ -182,6 +182,43 @@ gimp_drawable_get_tile2 (GimpDrawable *drawable,
return gimp_drawable_get_tile (drawable, shadow, row, col); return gimp_drawable_get_tile (drawable, shadow, row, col);
} }
void
gimp_drawable_get_color_uchar (gint32 drawable_ID,
const GimpRGB *color,
guchar *color_uchar)
{
g_return_if_fail (color != NULL);
g_return_if_fail (color_uchar != NULL);
switch (gimp_drawable_type (drawable_ID))
{
case GIMP_RGB_IMAGE:
gimp_rgb_get_uchar (color,
&color_uchar[0], &color_uchar[1], &color_uchar[2]);
color_uchar[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgba_get_uchar (color,
&color_uchar[0], &color_uchar[1], &color_uchar[2],
&color_uchar[3]);
break;
case GIMP_GRAY_IMAGE:
color_uchar[0] = gimp_rgb_intensity_uchar (color);
color_uchar[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
color_uchar[0] = gimp_rgb_intensity_uchar (color);
gimp_rgba_get_uchar (color, NULL, NULL, NULL, &color_uchar[1]);
break;
default:
break;
}
}
guchar * guchar *
gimp_drawable_get_thumbnail_data (gint32 drawable_ID, gimp_drawable_get_thumbnail_data (gint32 drawable_ID,
gint *width, gint *width,
......
...@@ -52,6 +52,10 @@ GimpTile * gimp_drawable_get_tile2 (GimpDrawable *drawable, ...@@ -52,6 +52,10 @@ GimpTile * gimp_drawable_get_tile2 (GimpDrawable *drawable,
gint x, gint x,
gint y); gint y);
void gimp_drawable_get_color_uchar (gint32 drawable_ID,
const GimpRGB *color,
guchar *color_uchar);
guchar * gimp_drawable_get_thumbnail_data (gint32 drawable_ID, guchar * gimp_drawable_get_thumbnail_data (gint32 drawable_ID,
gint *width, gint *width,
gint *height, gint *height,
......
...@@ -27,12 +27,7 @@ ...@@ -27,12 +27,7 @@
#include "config.h" #include "config.h"
#include <stdio.h>
#include <glib.h>
#include "gimp.h" #include "gimp.h"
#include "gimppixelfetcher.h"
struct _GimpPixelFetcher struct _GimpPixelFetcher
...@@ -51,12 +46,34 @@ struct _GimpPixelFetcher ...@@ -51,12 +46,34 @@ struct _GimpPixelFetcher
gboolean shadow; gboolean shadow;
}; };
/* local function prototypes */
static guchar * gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
gint x,
gint y);
/* public functions */
GimpPixelFetcher * GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable) gimp_pixel_fetcher_new (GimpDrawable *drawable,
gboolean shadow)
{ {
GimpPixelFetcher *pf; GimpPixelFetcher *pf;
gint width;
gint height;
gint bpp;
g_return_val_if_fail (drawable != NULL, NULL);
width = gimp_drawable_width (drawable->drawable_id);
height = gimp_drawable_height (drawable->drawable_id);
bpp = gimp_drawable_bpp (drawable->drawable_id);
pf = g_new (GimpPixelFetcher, 1); g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL);
pf = g_new0 (GimpPixelFetcher, 1);
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,
...@@ -64,9 +81,9 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable) ...@@ -64,9 +81,9 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable)
pf->col = -1; pf->col = -1;
pf->row = -1; pf->row = -1;
pf->img_width = gimp_drawable_width (drawable->drawable_id); pf->img_width = width;
pf->img_height = gimp_drawable_height (drawable->drawable_id); pf->img_height = height;
pf->img_bpp = gimp_drawable_bpp (drawable->drawable_id); pf->img_bpp = bpp;
pf->tile_width = gimp_tile_width (); pf->tile_width = gimp_tile_width ();
pf->tile_height = gimp_tile_height (); pf->tile_height = gimp_tile_height ();
pf->bg_color[0] = 0; pf->bg_color[0] = 0;
...@@ -77,227 +94,185 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable) ...@@ -77,227 +94,185 @@ gimp_pixel_fetcher_new (GimpDrawable *drawable)
pf->drawable = drawable; pf->drawable = drawable;
pf->tile = NULL; pf->tile = NULL;
pf->tile_dirty = FALSE; pf->tile_dirty = FALSE;
pf->shadow = FALSE; pf->shadow = shadow;
/* this allows us to use (slightly faster) do-while loops */
g_assert (pf->img_bpp > 0);
return pf; return pf;
} }
void
gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
{
g_return_if_fail (pf != NULL);
if (pf->tile)
gimp_tile_unref (pf->tile, pf->tile_dirty);
g_free (pf);
}
void void
gimp_pixel_fetcher_set_edge_mode (GimpPixelFetcher *pf, gimp_pixel_fetcher_set_edge_mode (GimpPixelFetcher *pf,
GimpPixelFetcherEdgeMode mode) GimpPixelFetcherEdgeMode mode)
{ {
g_return_if_fail (pf != NULL);
pf->mode = mode; pf->mode = mode;
} }
void void
gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf) gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf,
const GimpRGB *color)
{ {
GimpRGB background; g_return_if_fail (pf != NULL);
g_return_if_fail (color != NULL);
gimp_palette_get_background (&background);
switch (pf->img_bpp) switch (pf->img_bpp)
{ {
case 2: pf->bg_color[1] = 255; case 2: pf->bg_color[1] = 255;
case 1: case 1:
pf->bg_color[0] = gimp_rgb_intensity_uchar (&background); pf->bg_color[0] = gimp_rgb_intensity_uchar (color);
break; break;
case 4: pf->bg_color[3] = 255; case 4: pf->bg_color[3] = 255;
case 3: case 3:
gimp_rgb_get_uchar (&background, gimp_rgb_get_uchar (color,
pf->bg_color, pf->bg_color + 1, pf->bg_color + 2); pf->bg_color, pf->bg_color + 1, pf->bg_color + 2);
break; break;
} }
} }
void void
gimp_pixel_fetcher_set_shadow (GimpPixelFetcher *pf, gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gboolean shadow)
{
pf->shadow = shadow;
}
static guchar *
gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
gint x,
gint y)
{
gint col, row;
gint coloff, rowoff;
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, pf->tile_dirty);
pf->tile = gimp_drawable_get_tile (pf->drawable, pf->shadow, row, col);
pf->tile_dirty = FALSE;
gimp_tile_ref (pf->tile);
pf->col = col;
pf->row = row;
}
return pf->tile->data + pf->img_bpp * (pf->tile->ewidth * rowoff + coloff);
}
void
gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x, gint x,
gint y, gint y,
const guchar *pixel) guchar *pixel)
{ {
guchar *p; guchar *p;
gint i; gint i;
if (x < pf->sel_x1 || x >= pf->sel_x2 || g_return_if_fail (pf != NULL);
y < pf->sel_y1 || y >= pf->sel_y2) g_return_if_fail (pixel != NULL);
if (pf->mode == GIMP_PIXEL_FETCHER_EDGE_NONE &&
(x < pf->sel_x1 || x >= pf->sel_x2 ||
y < pf->sel_y1 || y >= pf->sel_y2))
{ {
return; return;
} }
if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
{
switch (pf->mode)
{
case GIMP_PIXEL_FETCHER_EDGE_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 GIMP_PIXEL_FETCHER_EDGE_SMEAR:
x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height - 1);
break;
case GIMP_PIXEL_FETCHER_EDGE_BLACK:
for (i = 0; i < pf->img_bpp; i++)
pixel[i] = 0;
return;
case GIMP_PIXEL_FETCHER_EDGE_BACKGROUND:
for (i = 0; i < pf->img_bpp; i++)
pixel[i] = pf->bg_color[i];
return;
default:
return;
}
}
p = gimp_pixel_fetcher_provide_tile (pf, x, y); p = gimp_pixel_fetcher_provide_tile (pf, x, y);
i = pf->img_bpp; i = pf->img_bpp;
do do
*p++ = *pixel++; {
*pixel++ = *p++;
}
while (--i); while (--i);
pf->tile_dirty = TRUE;
} }
void void
gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf, gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x, gint x,
gint y, gint y,
guchar *pixel) const guchar *pixel)
{ {
guchar *p; guchar *p;
gint i; gint i;
if (pf->mode == GIMP_PIXEL_FETCHER_EDGE_NONE && g_return_if_fail (pf != NULL);
(x < pf->sel_x1 || x >= pf->sel_x2 || g_return_if_fail (pixel != NULL);
y < pf->sel_y1 || y >= pf->sel_y2))
if (x < pf->sel_x1 || x >= pf->sel_x2 ||
y < pf->sel_y1 || y >= pf->sel_y2)
{ {
return; return;
} }
else if (x < 0 || x >= pf->img_width ||
y < 0 || y >= pf->img_height)
switch (pf->mode)
{
case GIMP_PIXEL_FETCHER_EDGE_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 GIMP_PIXEL_FETCHER_EDGE_SMEAR:
x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height - 1);
break;
case GIMP_PIXEL_FETCHER_EDGE_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;
}
p = gimp_pixel_fetcher_provide_tile (pf, x, y); p = gimp_pixel_fetcher_provide_tile (pf, x, y);
i = pf->img_bpp; i = pf->img_bpp;
do do
*pixel++ = *p++; {
*p++ = *pixel++;
}
while (--i); while (--i);
pf->tile_dirty = TRUE;
} }
void
gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
{
if (pf->tile)
gimp_tile_unref (pf->tile, pf->tile_dirty);
g_free (pf); /* private functions */
}
static void static guchar *
gimp_get_color_guchar (GimpDrawable *drawable, gimp_pixel_fetcher_provide_tile (GimpPixelFetcher *pf,
GimpRGB *color, gint x,
gboolean transparent, gint y)
guchar *bg)
{ {
switch (gimp_drawable_type (drawable->drawable_id)) gint col, row;
{ gint coloff, rowoff;
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE: col = x / pf->tile_width;
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]); coloff = x % pf->tile_width;
bg[3] = transparent ? 0 : 255; row = y / pf->tile_height;
break; rowoff = y % pf->tile_height;
case GIMP_GRAY_IMAGE: if ((col != pf->col) || (row != pf->row) || (pf->tile == NULL))
bg[0] = gimp_rgb_intensity_uchar (color); {
bg[1] = 255; if (pf->tile != NULL)
break; gimp_tile_unref (pf->tile, pf->tile_dirty);
case GIMP_GRAYA_IMAGE: pf->tile = gimp_drawable_get_tile (pf->drawable, pf->shadow, row, col);
bg[0] = gimp_rgb_intensity_uchar (color); pf->tile_dirty = FALSE;
bg[1] = transparent ? 0 : 255; gimp_tile_ref (pf->tile);
break;
default: pf->col = col;
break; pf->row = row;
} }
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
gimp_get_color_guchar (drawable, &background, transparent, bg);
}
void
gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg)
{
GimpRGB foreground;
gimp_palette_get_foreground (&foreground); return pf->tile->data + pf->img_bpp * (pf->tile->ewidth * rowoff + coloff);
gimp_get_color_guchar (drawable, &foreground, transparent, fg);
} }
...@@ -35,36 +35,31 @@ typedef enum ...@@ -35,36 +35,31 @@ typedef enum
GIMP_PIXEL_FETCHER_EDGE_NONE, GIMP_PIXEL_FETCHER_EDGE_NONE,
GIMP_PIXEL_FETCHER_EDGE_WRAP, GIMP_PIXEL_FETCHER_EDGE_WRAP,
GIMP_PIXEL_FETCHER_EDGE_SMEAR, GIMP_PIXEL_FETCHER_EDGE_SMEAR,
GIMP_PIXEL_FETCHER_EDGE_BLACK GIMP_PIXEL_FETCHER_EDGE_BLACK,
GIMP_PIXEL_FETCHER_EDGE_BACKGROUND
} GimpPixelFetcherEdgeMode; } GimpPixelFetcherEdgeMode;
typedef struct _GimpPixelFetcher GimpPixelFetcher; typedef struct _GimpPixelFetcher GimpPixelFetcher;
GimpPixelFetcher * gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_edge_mode (GimpPixelFetcher *pf,
GimpPixelFetcherEdgeMode mode);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf); GimpPixelFetcher * gimp_pixel_fetcher_new (GimpDrawable *drawable,
void gimp_pixel_fetcher_set_shadow (GimpPixelFetcher *pf, gboolean shadow);
gboolean shadow); void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
guchar *pixel);
void gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
gint x,
gint y,
const guchar *pixel);
void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_pixel_fetcher_set_edge_mode (GimpPixelFetcher *pf,
GimpPixelFetcherEdgeMode mode);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf,
const GimpRGB *color);
void gimp_get_bg_guchar (GimpDrawable *drawable, void gimp_pixel_fetcher_get_pixel (GimpPixelFetcher *pf,
gboolean transparent, gint x,
guchar *bg); gint y,
void gimp_get_fg_guchar (GimpDrawable *drawable, guchar *pixel);
gboolean transparent, void gimp_pixel_fetcher_put_pixel (GimpPixelFetcher *pf,
guchar *fg); gint x,
gint y,
const guchar *pixel);
G_END_DECLS G_END_DECLS
......
...@@ -528,13 +528,19 @@ blindsapply (guchar *srow, ...@@ -528,13 +528,19 @@ blindsapply (guchar *srow,
static void static void
dialog_update_preview (void) dialog_update_preview (void)
{ {
gint y; gint y;
guchar *p, *buffer; guchar *p, *buffer;
guchar bg[4]; GimpRGB background;
guchar bg[4];
p = preview->cache; p = preview->cache;
gimp_get_bg_guchar (blindsdrawable, bvals.bg_trans, bg); gimp_palette_get_background (&background);
if (bvals.bg_trans)
gimp_rgb_set_alpha (&background, 0.0);
gimp_drawable_get_color_uchar (blindsdrawable->drawable_id, &background, bg);
buffer = (guchar*) g_malloc (preview->rowstride); buffer = (guchar*) g_malloc (preview->rowstride);
...@@ -620,18 +626,24 @@ dialog_update_preview (void) ...@@ -620,18 +626,24 @@ dialog_update_preview (void)
static void static void
apply_blinds (void) apply_blinds (void)
{ {
GimpPixelRgn des_rgn; GimpPixelRgn des_rgn;
GimpPixelRgn src_rgn; GimpPixelRgn src_rgn;
guchar *src_rows, *des_rows; guchar *src_rows, *des_rows;
gint x,y; gint x, y;
guchar bg[4]; GimpRGB background;
gint sel_x1, sel_y1, sel_x2, sel_y2; guchar bg