Finished the addition of "gboolean reverse" to the gradient API:

2003-08-18  Michael Natterer  <mitch@gimp.org>

	Finished the addition of "gboolean reverse" to the gradient API:

	* tools/pdbgen/pdb/gradients.pdb: added "reverse" params to
	gimp_gradients_sample_uniform(), sample_custom() and
	get_gradient_data().

	* app/pdb/gradients_cmds.c
	* libgimp/gimpgradients_pdb.[ch]: regenerated.

	* libgimp/gimpgradientmenu.c: changed accordingly.

	Made everything compile with the new API:

	* plug-ins/FractalExplorer/Dialogs.c
	* plug-ins/FractalExplorer/FractalExplorer.[ch]: got lost in
	"reverse" adding, whitespace removal and general code cleanup.
	I better commit this now before continuing, even though "reverse"
	adding is not finished.

	* plug-ins/common/sample_colorize.c: removed own gradient
	reversing code, use "reverse" instead.

	* plug-ins/common/gradmap.c
	* plug-ins/flame/flame.c
	* plug-ins/gflare/gflare.c
	* plug-ins/pagecurl/pagecurl.c: simply pass reverse == FALSE and
	added #warnings that more work needs to be done. Some whitespace
	removal and minor cleanup.
This commit is contained in:
Michael Natterer 2003-08-18 12:17:21 +00:00 committed by Michael Natterer
parent e5be1ae62c
commit cd9f65cb87
14 changed files with 495 additions and 427 deletions

View File

@ -1,3 +1,34 @@
2003-08-18 Michael Natterer <mitch@gimp.org>
Finished the addition of "gboolean reverse" to the gradient API:
* tools/pdbgen/pdb/gradients.pdb: added "reverse" params to
gimp_gradients_sample_uniform(), sample_custom() and
get_gradient_data().
* app/pdb/gradients_cmds.c
* libgimp/gimpgradients_pdb.[ch]: regenerated.
* libgimp/gimpgradientmenu.c: changed accordingly.
Made everything compile with the new API:
* plug-ins/FractalExplorer/Dialogs.c
* plug-ins/FractalExplorer/FractalExplorer.[ch]: got lost in
"reverse" adding, whitespace removal and general code cleanup.
I better commit this now before continuing, even though "reverse"
adding is not finished.
* plug-ins/common/sample_colorize.c: removed own gradient
reversing code, use "reverse" instead.
* plug-ins/common/gradmap.c
* plug-ins/flame/flame.c
* plug-ins/gflare/gflare.c
* plug-ins/pagecurl/pagecurl.c: simply pass reverse == FALSE and
added #warnings that more work needs to be done. Some whitespace
removal and minor cleanup.
2003-08-18 Sven Neumann <sven@gimp.org>
* app/composite/Makefile.am: cleaned up whitespace.

View File

@ -247,6 +247,7 @@ gradients_sample_uniform_invoker (Gimp *gimp,
gboolean success = TRUE;
Argument *return_args;
gint32 i;
gboolean reverse;
gint32 array_length = 0;
gdouble *color_samples = NULL;
GimpGradient *gradient;
@ -258,6 +259,8 @@ gradients_sample_uniform_invoker (Gimp *gimp,
if (i < 2)
success = FALSE;
reverse = args[1].value.pdb_int ? TRUE : FALSE;
if (success)
{
pos = 0.0;
@ -271,7 +274,7 @@ gradients_sample_uniform_invoker (Gimp *gimp,
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
@ -299,6 +302,11 @@ static ProcArg gradients_sample_uniform_inargs[] =
GIMP_PDB_INT32,
"num_samples",
"The number of samples to take"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
@ -325,7 +333,7 @@ static ProcRecord gradients_sample_uniform_proc =
"Federico Mena Quintero",
"1997",
GIMP_INTERNAL,
1,
2,
gradients_sample_uniform_inargs,
2,
gradients_sample_uniform_outargs,
@ -340,6 +348,7 @@ gradients_sample_custom_invoker (Gimp *gimp,
Argument *return_args;
gint32 i;
gdouble *pos;
gboolean reverse;
gint32 array_length = 0;
gdouble *color_samples = NULL;
GimpGradient *gradient;
@ -352,6 +361,8 @@ gradients_sample_custom_invoker (Gimp *gimp,
pos = (gdouble *) args[1].value.pdb_pointer;
reverse = args[2].value.pdb_int ? TRUE : FALSE;
if (success)
{
array_length = i * 4;
@ -362,7 +373,7 @@ gradients_sample_custom_invoker (Gimp *gimp,
while (i--)
{
gimp_gradient_get_color_at (gradient, *pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, *pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
@ -395,6 +406,11 @@ static ProcArg gradients_sample_custom_inargs[] =
GIMP_PDB_FLOATARRAY,
"positions",
"The list of positions to sample along the gradient"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
@ -421,7 +437,7 @@ static ProcRecord gradients_sample_custom_proc =
"Federico Mena Quintero",
"1997",
GIMP_INTERNAL,
2,
3,
gradients_sample_custom_inargs,
2,
gradients_sample_custom_outargs,
@ -436,6 +452,7 @@ gradients_get_gradient_data_invoker (Gimp *gimp,
Argument *return_args;
gchar *name;
gint32 sample_size;
gboolean reverse;
gdouble *values = NULL;
GimpGradient *gradient = NULL;
@ -447,6 +464,8 @@ gradients_get_gradient_data_invoker (Gimp *gimp,
if (sample_size <= 0 || sample_size > 10000)
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
reverse = args[2].value.pdb_int ? TRUE : FALSE;
if (success)
{
if (strlen (name))
@ -480,7 +499,7 @@ gradients_get_gradient_data_invoker (Gimp *gimp,
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
@ -515,6 +534,11 @@ static ProcArg gradients_get_gradient_data_inargs[] =
GIMP_PDB_INT32,
"sample_size",
"Size of the sample to return when the gradient is changed (0 < sample_size <= 10000)"
},
{
GIMP_PDB_INT32,
"reverse",
"Use the reverse gradient (TRUE or FALSE)"
}
};
@ -546,7 +570,7 @@ static ProcRecord gradients_get_gradient_data_proc =
"Federico Mena Quintero",
"1997",
GIMP_INTERNAL,
2,
3,
gradients_get_gradient_data_inargs,
3,
gradients_get_gradient_data_outargs,

View File

@ -51,6 +51,7 @@ struct _GradientSelect
gchar *gradient_name; /* Local copy */
gint sample_size;
gboolean reverse;
const gchar *temp_gradient_callback;
};
@ -108,6 +109,7 @@ gimp_gradient_select_widget_new (const gchar *title,
gradient_sel->data = data;
gradient_sel->sample_size = CELL_WIDTH;
gradient_sel->reverse = FALSE;
gradient_sel->button = gtk_button_new ();
@ -129,6 +131,7 @@ gimp_gradient_select_widget_new (const gchar *title,
gradient_sel->gradient_name =
gimp_gradients_get_gradient_data (gradient_name,
gradient_sel->sample_size,
gradient_sel->reverse,
&width,
&grad_data);
@ -203,6 +206,7 @@ gimp_gradient_select_widget_set (GtkWidget *widget,
name = gimp_gradients_get_gradient_data (gradient_name,
gradient_sel->sample_size,
gradient_sel->reverse,
&width,
&grad_data);

View File

@ -160,6 +160,7 @@ gimp_gradients_set_gradient (const gchar *name)
/**
* gimp_gradients_sample_uniform:
* @num_samples: The number of samples to take.
* @reverse: Use the reverse gradient.
*
* Sample the active gradient in uniform parts.
*
@ -174,7 +175,8 @@ gimp_gradients_set_gradient (const gchar *name)
* Returns: Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }.
*/
gdouble *
gimp_gradients_sample_uniform (gint num_samples)
gimp_gradients_sample_uniform (gint num_samples,
gboolean reverse)
{
GimpParam *return_vals;
gint nreturn_vals;
@ -184,6 +186,7 @@ gimp_gradients_sample_uniform (gint num_samples)
return_vals = gimp_run_procedure ("gimp_gradients_sample_uniform",
&nreturn_vals,
GIMP_PDB_INT32, num_samples,
GIMP_PDB_INT32, reverse,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
@ -203,6 +206,7 @@ gimp_gradients_sample_uniform (gint num_samples)
* gimp_gradients_sample_custom:
* @num_samples: The number of samples to take.
* @positions: The list of positions to sample along the gradient.
* @reverse: Use the reverse gradient.
*
* Sample the active gradient in custom positions.
*
@ -217,7 +221,8 @@ gimp_gradients_sample_uniform (gint num_samples)
*/
gdouble *
gimp_gradients_sample_custom (gint num_samples,
const gdouble *positions)
const gdouble *positions,
gboolean reverse)
{
GimpParam *return_vals;
gint nreturn_vals;
@ -228,6 +233,7 @@ gimp_gradients_sample_custom (gint num_samples,
&nreturn_vals,
GIMP_PDB_INT32, num_samples,
GIMP_PDB_FLOATARRAY, positions,
GIMP_PDB_INT32, reverse,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
@ -247,6 +253,7 @@ gimp_gradients_sample_custom (gint num_samples,
* gimp_gradients_get_gradient_data:
* @name: The gradient name (\"\" means current active gradient).
* @sample_size: Size of the sample to return when the gradient is changed.
* @reverse: Use the reverse gradient.
* @width: The gradient sample width (r,g,b,a).
* @grad_data: The gradient sample data.
*
@ -260,6 +267,7 @@ gimp_gradients_sample_custom (gint num_samples,
gchar *
gimp_gradients_get_gradient_data (const gchar *name,
gint sample_size,
gboolean reverse,
gint *width,
gdouble **grad_data)
{
@ -271,6 +279,7 @@ gimp_gradients_get_gradient_data (const gchar *name,
&nreturn_vals,
GIMP_PDB_STRING, name,
GIMP_PDB_INT32, sample_size,
GIMP_PDB_INT32, reverse,
GIMP_PDB_END);
*width = 0;

View File

@ -33,11 +33,14 @@ gboolean gimp_gradients_refresh (void);
gchar** gimp_gradients_get_list (gint *num_gradients);
gchar* gimp_gradients_get_gradient (void);
gboolean gimp_gradients_set_gradient (const gchar *name);
gdouble* gimp_gradients_sample_uniform (gint num_samples);
gdouble* gimp_gradients_sample_uniform (gint num_samples,
gboolean reverse);
gdouble* gimp_gradients_sample_custom (gint num_samples,
const gdouble *positions);
const gdouble *positions,
gboolean reverse);
gchar* gimp_gradients_get_gradient_data (const gchar *name,
gint sample_size,
gboolean reverse,
gint *width,
gdouble **grad_data);

View File

@ -212,6 +212,7 @@ explorer_number_of_colors_callback (GtkAdjustment *adjustment,
gimp_gradients_get_gradient_data (gradient_name,
wvals.ncolors,
wvals.gradinvert,
&dummy,
&gradient_samples);
@ -235,6 +236,7 @@ explorer_gradient_select_callback (const gchar *name,
gimp_gradients_get_gradient_data (gradient_name,
wvals.ncolors,
wvals.gradinvert,
&dummy,
&gradient_samples);
@ -904,7 +906,8 @@ explorer_dialog (void)
"the gradient editor"), NULL);
gradient_name = gimp_gradients_get_gradient ();
gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors);
gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors,
wvals.gradinvert);
gradient = gimp_gradient_select_widget_new (_("FractalExplorer Gradient"),
gradient_name,
explorer_gradient_select_callback,
@ -1287,7 +1290,8 @@ make_color_map (void)
* mode for noninteractive use (bug #103470).
*/
if (gradient_samples == NULL)
gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors);
gradient_samples = gimp_gradients_sample_uniform (wvals.ncolors,
wvals.gradinvert);
redstretch = wvals.redstretch * 127.5;
greenstretch = wvals.greenstretch * 127.5;
@ -1842,6 +1846,7 @@ load_options (fractalexplorerOBJ *xxx,
xxx->opts.blueinvert = 0;
xxx->opts.alwayspreview = 1;
xxx->opts.ncolors = 256; /* not saved */
xxx->opts.gradinvert = FALSE;
get_line (load_buf, MAX_LOAD_LINE, fp, 0);

View File

@ -60,12 +60,13 @@ typedef struct
gint redmode;
gint greenmode;
gint bluemode;
gint redinvert;
gint greeninvert;
gint blueinvert;
gint alwayspreview;
gboolean redinvert;
gboolean greeninvert;
gboolean blueinvert;
gboolean alwayspreview;
gint ncolors;
gint useloglog;
gboolean gradinvert;
gboolean useloglog;
} explorer_vals_t;
typedef struct

View File

@ -229,7 +229,10 @@ get_samples (GimpDrawable *drawable)
gint bpp, color, has_alpha, alpha;
gint i, j;
f_samples = gimp_gradients_sample_uniform (NSAMPLES);
#ifdef __GNUC__
#warning FIXME: "reverse" hardcoded to FALSE.
#endif
f_samples = gimp_gradients_sample_uniform (NSAMPLES, FALSE);
bpp = gimp_drawable_bpp (drawable->drawable_id);
color = gimp_drawable_is_rgb (drawable->drawable_id);

View File

@ -524,7 +524,7 @@ p_smp_menu_callback(gint32 id, gpointer data)
{
gint32 *id_ptr;
if(g_Sdebug) printf("MENU_CB: data %p, dst: %x, samp %x\n", data, (int)&g_values.sample_id, (int)&g_values.dst_id);
if(TRUE) printf("MENU_CB: id: %d, data %p, dst: %x, samp %x\n", id, data, (int)&g_values.sample_id, (int)&g_values.dst_id);
if((id_ptr = (gint32 *)data) != NULL)
{
@ -2502,12 +2502,12 @@ p_get_gradient (gint mode)
gint l_lum;
p_free_colors();
f_samples = gimp_gradients_sample_uniform (256 /* n_samples */);
f_samples = gimp_gradients_sample_uniform (256 /* n_samples */,
mode == SMP_INV_GRADIENT);
for (l_lum = 0; l_lum < 256; l_lum++)
{
if(mode == SMP_GRADIENT) { f_samp = &f_samples[l_lum * 4]; }
else { f_samp = &f_samples[(255 - l_lum) * 4]; }
f_samp = &f_samples[l_lum * 4];
g_sample_color_tab[l_lum + l_lum + l_lum ] = f_samp[0] * 255;
g_sample_color_tab[l_lum + l_lum + l_lum +1] = f_samp[1] * 255;
@ -2525,57 +2525,21 @@ static gint32
p_is_layer_alive(gint32 drawable_id)
{
/* return -1 if layer has become invalid */
gint32 *layers;
gint32 *images;
gint nlayers;
gint nimages;
gint l_idi, l_idl;
gint l_found;
if (drawable_id < 0)
{
return -1;
}
/* gimp_layer_get_image_id: crash in gimp 1.1.2 if called with invalid drawable_id
* gimp 1.0.2 works fine !!
*/
/*
* if(gimp_layer_get_image_id(drawable_id) < 0)
* {
* printf("sample colorize: invalid image_id (maybe Image was closed)\n");
* return (-1);
* }
*/
images = gimp_image_list (&nimages);
l_idi = nimages -1;
l_found = FALSE;
while ((l_idi >= 0) && images)
if (gimp_layer_get_image_id (drawable_id) < 0)
{
layers = gimp_image_get_layers (images[l_idi], &nlayers);
l_idl = nlayers - 1;
while ((l_idl >= 0) && layers)
{
if (drawable_id == layers[l_idl])
{
l_found = TRUE;
break;
}
l_idl--;
}
g_free (layers);
l_idi--;
}
g_free(images);
if (!l_found)
{
printf("sample colorize: unknown layer_id %d (Image closed?)\n",
printf ("sample colorize: unknown layer_id %d (Image closed?)\n",
(int)drawable_id);
return -1;
}
return drawable_id;
} /* end p_is_layer_alive */
}
static void
p_end_gdrw(t_GDRW *gdrw)

View File

@ -153,7 +153,9 @@ maybe_init_cp (void)
config.randomize = 0;
config.variation = VARIATION_SAME;
config.cmap_drawable = GRADIENT_DRAWABLE;
random_control_point(&config.cp, variation_random);
random_control_point (&config.cp, variation_random);
config.cp.center[0] = 0.0;
config.cp.center[1] = 0.0;
config.cp.pixels_per_unit = 100;
@ -265,7 +267,10 @@ drawable_to_cmap (control_point *cp)
}
else if (GRADIENT_DRAWABLE == config.cmap_drawable)
{
gdouble *g = gimp_gradients_sample_uniform (256);
#ifdef __GNUC__
#warning FIXME: "reverse" hardcoded to FALSE.
#endif
gdouble *g = gimp_gradients_sample_uniform (256, FALSE);
for (i = 0; i < 256; i++)
for (j = 0; j < 3; j++)
cp->cmap[i][j] = g[i*4 + j];

View File

@ -781,8 +781,11 @@ static void gradient_get_default (gchar *name, guchar *values,
static void gradient_get_values_external (gchar *gradient_name,
guchar *values, gint nvalues);
static void gradient_get_values_real_external (gchar *gradient_name,
guchar *values, gint nvalues);
static GradientCacheItem *gradient_cache_lookup (gchar *name, gint *found);
guchar *values,
gint nvalues,
gboolean reverse);
static GradientCacheItem *gradient_cache_lookup (gchar *name,
gint *found);
static void gradient_cache_zorch (void);
/* *** INSERT-FILE-END *** */
@ -4870,7 +4873,11 @@ gradient_get_values_external (gchar *gradient_name,
ci = gradient_cache_lookup (gradient_name, &found);
if (!found)
{
gradient_get_values_real_external (gradient_name, ci->values, GRADIENT_RESOLUTION);
#ifdef __GNUC__
#warning FIXME: "reverse" hardcoded to FALSE.
#endif
gradient_get_values_real_external (gradient_name, ci->values,
GRADIENT_RESOLUTION, FALSE);
}
if (nvalues == GRADIENT_RESOLUTION)
{
@ -4908,7 +4915,8 @@ gradient_get_values_external (gchar *gradient_name,
static void
gradient_get_values_real_external (gchar *gradient_name,
guchar *values,
gint nvalues)
gint nvalues,
gboolean reverse)
{
gchar *old_name;
gdouble *tmp_values;
@ -4919,7 +4927,7 @@ gradient_get_values_real_external (gchar *gradient_name,
gimp_gradients_set_gradient (gradient_name);
tmp_values = gimp_gradients_sample_uniform (nvalues);
tmp_values = gimp_gradients_sample_uniform (nvalues, reverse);
for (i = 0; i < nvalues; i++)
for (j = 0; j < 4; j++)
values[4*i+j] = (guchar) (tmp_values[4*i+j] * 255);

View File

@ -1028,7 +1028,10 @@ get_samples (GimpDrawable *drawable)
gint bpp, color, has_alpha, alpha;
gint i, j;
f_samples = gimp_gradients_sample_uniform (NGRADSAMPLES);
#ifdef __GNUC__
#warning FIXME: "reverse" hardcoded to FALSE.
#endif
f_samples = gimp_gradients_sample_uniform (NGRADSAMPLES, FALSE);
bpp = gimp_drawable_bpp (drawable->drawable_id);
color = gimp_drawable_is_rgb (drawable->drawable_id);

View File

@ -146,6 +146,11 @@ sub sample_num_arg {
desc => 'The number of samples to take', alias => 'i' }
}
sub reverse_arg {
{ name => 'reverse', type => 'boolean',
desc => 'Use the reverse gradient (%%desc%%)' }
}
sub sample_outargs {
@outargs = (
{ name => 'color_samples', type => 'floatarray', init => 1,
@ -170,7 +175,10 @@ HELP
&pdb_misc;
@inargs = ( &sample_num_arg('2 <= ') );
@inargs = (
&sample_num_arg('2 <= '),
&reverse_arg
);
&sample_outargs;
%invoke = (
@ -188,7 +196,7 @@ HELP
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
@ -217,13 +225,12 @@ HELP
&pdb_misc;
@inargs = (
{
name => 'positions',
{ name => 'positions',
type => 'floatarray',
desc => 'The list of positions to sample along the gradient',
alias => 'pos',
array => &sample_num_arg("")
}
array => &sample_num_arg("") },
&reverse_arg
);
&sample_outargs;
@ -240,7 +247,7 @@ HELP
while (i--)
{
gimp_gradient_get_color_at (gradient, *pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, *pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
@ -254,14 +261,14 @@ CODE
);
}
sub sample_size_arg {{
name => 'sample_size',
sub sample_size_arg {
{ name => 'sample_size',
type => '0 < int32 <= 10000',
desc => 'Size of the sample to return when the gradient is changed
(%%desc%%)',
on_fail => 'sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;',
no_success => 1
}}
no_success => 1 }
}
sub gradients_get_gradient_data {
$blurb = <<'BLURB';
@ -278,7 +285,8 @@ HELP
@inargs = (
{ name => 'name', type => 'string',
desc => 'The gradient name ("" means current active gradient)' },
&sample_size_arg
&sample_size_arg,
&reverse_arg
);
@outargs = (
@ -327,7 +335,7 @@ HELP
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, FALSE, &color);
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;