2000-06-02 05:18:04 +08:00
/* The GIMP -- an image manipulation program
2003-07-03 08:47:26 +08:00
* Copyright ( C ) 1995 - 2003 Spencer Kimball and Peter Mattis
2000-06-02 05:18:04 +08:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
/* NOTE: This file is autogenerated by pdbgen.pl. */
2000-12-29 23:22:01 +08:00
# include "config.h"
2001-10-29 02:45:45 +08:00
# include <string.h>
2000-12-29 23:22:01 +08:00
2001-08-17 22:27:31 +08:00
# include <glib-object.h>
2000-12-29 23:22:01 +08:00
2001-08-17 22:27:31 +08:00
# include "pdb-types.h"
2006-04-26 17:13:47 +08:00
# include "gimppdb.h"
2006-03-31 17:15:08 +08:00
# include "gimpprocedure.h"
2006-03-29 03:58:00 +08:00
# include "core/gimpparamspecs.h"
2000-06-02 05:18:04 +08:00
2001-07-05 03:31:35 +08:00
# include "core/gimp.h"
2003-09-05 01:04:36 +08:00
# include "core/gimpcontainer-filter.h"
2001-05-09 10:32:03 +08:00
# include "core/gimpcontext.h"
# include "core/gimpdatafactory.h"
# include "core/gimpgradient.h"
# include "core/gimplist.h"
2000-06-02 05:18:04 +08:00
2006-04-04 18:30:58 +08:00
static GValueArray *
gradients_refresh_invoker ( GimpProcedure * procedure ,
Gimp * gimp ,
GimpContext * context ,
GimpProgress * progress ,
const GValueArray * args )
2002-02-21 19:16:00 +08:00
{
2005-04-13 06:58:12 +08:00
gimp_data_factory_data_refresh ( gimp - > gradient_factory ) ;
2006-04-01 01:42:13 +08:00
return gimp_procedure_get_return_values ( procedure , TRUE ) ;
2002-02-21 19:16:00 +08:00
}
2006-04-04 18:30:58 +08:00
static GValueArray *
gradients_get_list_invoker ( GimpProcedure * procedure ,
Gimp * gimp ,
GimpContext * context ,
GimpProgress * progress ,
const GValueArray * args )
2000-06-02 05:18:04 +08:00
{
2003-09-05 01:04:36 +08:00
gboolean success = TRUE ;
2006-04-04 18:30:58 +08:00
GValueArray * return_vals ;
2006-04-03 00:03:32 +08:00
const gchar * filter ;
2006-03-15 23:32:39 +08:00
gint32 num_gradients = 0 ;
2003-09-05 01:28:13 +08:00
gchar * * gradient_list = NULL ;
2001-02-11 03:35:29 +08:00
2006-04-04 18:30:58 +08:00
filter = g_value_get_string ( & args - > values [ 0 ] ) ;
2003-09-05 01:04:36 +08:00
if ( success )
2006-03-22 17:58:08 +08:00
{
gradient_list = gimp_container_get_filtered_name_array ( gimp - > gradient_factory - > container ,
filter , & num_gradients ) ;
}
2000-06-02 05:18:04 +08:00
2006-04-01 01:42:13 +08:00
return_vals = gimp_procedure_get_return_values ( procedure , success ) ;
2000-06-02 05:18:04 +08:00
2003-09-05 01:04:36 +08:00
if ( success )
{
2006-04-04 18:30:58 +08:00
g_value_set_int ( & return_vals - > values [ 1 ] , num_gradients ) ;
gimp_value_take_stringarray ( & return_vals - > values [ 2 ] , gradient_list , num_gradients ) ;
2003-09-05 01:04:36 +08:00
}
2000-06-02 05:18:04 +08:00
2006-03-28 05:09:32 +08:00
return return_vals ;
2000-06-02 05:18:04 +08:00
}
2006-04-04 18:30:58 +08:00
static GValueArray *
gradients_sample_uniform_invoker ( GimpProcedure * procedure ,
Gimp * gimp ,
GimpContext * context ,
GimpProgress * progress ,
const GValueArray * args )
2000-06-02 05:18:04 +08:00
{
gboolean success = TRUE ;
2006-04-04 18:30:58 +08:00
GValueArray * return_vals ;
2006-03-15 23:00:01 +08:00
gint32 num_samples ;
2003-08-18 20:17:21 +08:00
gboolean reverse ;
2000-06-02 05:18:04 +08:00
gint32 array_length = 0 ;
gdouble * color_samples = NULL ;
2006-04-04 18:30:58 +08:00
num_samples = g_value_get_int ( & args - > values [ 0 ] ) ;
reverse = g_value_get_boolean ( & args - > values [ 1 ] ) ;
2003-08-18 20:17:21 +08:00
2000-06-02 05:18:04 +08:00
if ( success )
{
2006-03-15 05:35:50 +08:00
GimpGradient * gradient ;
2005-02-27 07:55:50 +08:00
GimpGradientSegment * seg = NULL ;
2006-03-15 05:35:50 +08:00
gdouble pos , delta ;
GimpRGB color ;
gdouble * pv ;
2005-02-27 07:55:50 +08:00
2004-09-23 23:05:48 +08:00
pos = 0.0 ;
2006-03-15 23:00:01 +08:00
delta = 1.0 / ( num_samples - 1 ) ;
2004-03-27 00:38:44 +08:00
2006-03-15 23:00:01 +08:00
array_length = num_samples * 4 ;
2004-03-27 00:38:44 +08:00
2000-06-02 05:18:04 +08:00
pv = color_samples = g_new ( gdouble , array_length ) ;
2004-03-27 00:38:44 +08:00
2004-04-15 07:37:34 +08:00
gradient = gimp_context_get_gradient ( context ) ;
2004-03-27 00:38:44 +08:00
2006-03-15 23:00:01 +08:00
while ( num_samples - - )
2004-03-27 00:49:18 +08:00
{
2005-02-27 07:55:50 +08:00
seg = gimp_gradient_get_color_at ( gradient , seg , pos , reverse , & color ) ;
2004-03-27 00:38:44 +08:00
2004-03-27 00:49:18 +08:00
* pv + + = color . r ;
* pv + + = color . g ;
* pv + + = color . b ;
* pv + + = color . a ;
2004-03-27 00:38:44 +08:00
2004-03-27 00:49:18 +08:00
pos + = delta ;
}
2000-06-02 05:18:04 +08:00
}
2006-04-01 01:42:13 +08:00
return_vals = gimp_procedure_get_return_values ( procedure , success ) ;
2000-06-02 05:18:04 +08:00
if ( success )
{
2006-04-04 18:30:58 +08:00
g_value_set_int ( & return_vals - > values [ 1 ] , array_length ) ;
gimp_value_take_floatarray ( & return_vals - > values [ 2 ] , color_samples , array_length ) ;
2000-06-02 05:18:04 +08:00
}
2006-03-28 05:09:32 +08:00
return return_vals ;
2000-06-02 05:18:04 +08:00
}
2006-04-04 18:30:58 +08:00
static GValueArray *
gradients_sample_custom_invoker ( GimpProcedure * procedure ,
Gimp * gimp ,
GimpContext * context ,
GimpProgress * progress ,
const GValueArray * args )
2000-06-02 05:18:04 +08:00
{
gboolean success = TRUE ;
2006-04-04 18:30:58 +08:00
GValueArray * return_vals ;
2006-03-15 23:00:01 +08:00
gint32 num_samples ;
2006-04-03 00:03:32 +08:00
const gdouble * positions ;
2003-08-18 20:17:21 +08:00
gboolean reverse ;
2000-06-02 05:18:04 +08:00
gint32 array_length = 0 ;
gdouble * color_samples = NULL ;
2006-04-04 18:30:58 +08:00
num_samples = g_value_get_int ( & args - > values [ 0 ] ) ;
positions = gimp_value_get_floatarray ( & args - > values [ 1 ] ) ;
reverse = g_value_get_boolean ( & args - > values [ 2 ] ) ;
2003-08-18 20:17:21 +08:00
2000-06-02 05:18:04 +08:00
if ( success )
{
2006-03-15 05:35:50 +08:00
GimpGradient * gradient ;
2005-02-27 07:55:50 +08:00
GimpGradientSegment * seg = NULL ;
2006-03-15 05:35:50 +08:00
GimpRGB color ;
gdouble * pv ;
2005-02-27 07:55:50 +08:00
2006-03-15 23:00:01 +08:00
array_length = num_samples * 4 ;
2004-03-27 00:38:44 +08:00
2000-06-02 05:18:04 +08:00
pv = color_samples = g_new ( gdouble , array_length ) ;
2004-03-27 00:38:44 +08:00
2004-04-15 07:37:34 +08:00
gradient = gimp_context_get_gradient ( context ) ;
2004-03-27 00:38:44 +08:00
2006-03-15 23:00:01 +08:00
while ( num_samples - - )
2004-03-27 00:49:18 +08:00
{
2006-03-15 23:00:01 +08:00
seg = gimp_gradient_get_color_at ( gradient , seg , * positions ,
reverse , & color ) ;
2004-03-27 00:38:44 +08:00
2004-03-27 00:49:18 +08:00
* pv + + = color . r ;
* pv + + = color . g ;
* pv + + = color . b ;
* pv + + = color . a ;
2004-03-27 00:38:44 +08:00
2006-03-15 23:00:01 +08:00
positions + + ;
2004-03-27 00:49:18 +08:00
}
2000-06-02 05:18:04 +08:00
}
2006-04-01 01:42:13 +08:00
return_vals = gimp_procedure_get_return_values ( procedure , success ) ;
2000-06-02 05:18:04 +08:00
if ( success )
{
2006-04-04 18:30:58 +08:00
g_value_set_int ( & return_vals - > values [ 1 ] , array_length ) ;
gimp_value_take_floatarray ( & return_vals - > values [ 2 ] , color_samples , array_length ) ;
2000-06-02 05:18:04 +08:00
}
2006-03-28 05:09:32 +08:00
return return_vals ;
2000-06-02 05:18:04 +08:00
}
2006-04-04 18:30:58 +08:00
static GValueArray *
gradients_get_gradient_data_invoker ( GimpProcedure * procedure ,
Gimp * gimp ,
GimpContext * context ,
GimpProgress * progress ,
const GValueArray * args )
2001-10-26 05:59:52 +08:00
{
gboolean success = TRUE ;
2006-04-04 18:30:58 +08:00
GValueArray * return_vals ;
2006-04-03 00:03:32 +08:00
const gchar * name ;
2001-10-26 05:59:52 +08:00
gint32 sample_size ;
2003-08-18 20:17:21 +08:00
gboolean reverse ;
2006-03-15 20:49:25 +08:00
gchar * actual_name = NULL ;
gint32 width = 0 ;
2006-03-15 23:00:01 +08:00
gdouble * grad_data = NULL ;
2001-10-26 05:59:52 +08:00
2006-04-04 18:30:58 +08:00
name = g_value_get_string ( & args - > values [ 0 ] ) ;
sample_size = g_value_get_int ( & args - > values [ 1 ] ) ;
reverse = g_value_get_boolean ( & args - > values [ 2 ] ) ;
2003-08-18 20:17:21 +08:00
2001-10-26 05:59:52 +08:00
if ( success )
{
2006-03-15 20:49:25 +08:00
GimpGradient * gradient ;
2006-03-18 18:28:39 +08:00
if ( sample_size < 1 | | sample_size > 10000 )
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE ;
2004-09-23 23:05:48 +08:00
if ( name & & strlen ( name ) )
2004-10-06 07:28:17 +08:00
{
gradient = ( GimpGradient * )
gimp_container_get_child_by_name ( gimp - > gradient_factory - > container ,
name ) ;
}
else
{
gradient = gimp_context_get_gradient ( context ) ;
}
2004-03-27 00:38:44 +08:00
2003-07-22 22:24:11 +08:00
if ( gradient )
2004-03-27 00:49:18 +08:00
{
2005-02-27 07:55:50 +08:00
GimpGradientSegment * seg = NULL ;
gdouble * pv ;
gdouble pos , delta ;
GimpRGB color ;
2004-03-27 00:49:18 +08:00
pos = 0.0 ;
2006-03-15 20:49:25 +08:00
delta = 1.0 / ( sample_size - 1 ) ;
2006-03-25 05:57:47 +08:00
actual_name = g_strdup ( gimp_object_get_name ( GIMP_OBJECT ( gradient ) ) ) ;
2006-03-15 23:00:01 +08:00
grad_data = g_new ( gdouble , sample_size * 4 ) ;
2006-03-15 20:49:25 +08:00
width = sample_size * 4 ;
2004-03-27 00:49:18 +08:00
2006-03-15 23:00:01 +08:00
pv = grad_data ;
2004-03-27 00:49:18 +08:00
2006-03-15 20:49:25 +08:00
while ( sample_size )
2004-03-27 00:49:18 +08:00
{
2005-02-27 07:55:50 +08:00
seg = gimp_gradient_get_color_at ( gradient , seg , pos , reverse , & color ) ;
2004-03-27 00:49:18 +08:00
* pv + + = color . r ;
* pv + + = color . g ;
* pv + + = color . b ;
* pv + + = color . a ;
pos + = delta ;
}
}
2003-12-08 19:58:45 +08:00
else
2004-03-27 00:49:18 +08:00
success = FALSE ;
2001-10-26 05:59:52 +08:00
}
2006-04-01 01:42:13 +08:00
return_vals = gimp_procedure_get_return_values ( procedure , success ) ;
2001-10-26 05:59:52 +08:00
if ( success )
{
2006-04-04 18:30:58 +08:00
g_value_take_string ( & return_vals - > values [ 1 ] , actual_name ) ;
g_value_set_int ( & return_vals - > values [ 2 ] , width ) ;
gimp_value_take_floatarray ( & return_vals - > values [ 3 ] , grad_data , width ) ;
2001-10-26 05:59:52 +08:00
}
2006-03-28 05:09:32 +08:00
return return_vals ;
2001-10-26 05:59:52 +08:00
}
2006-04-05 05:11:45 +08:00
void
2006-04-26 17:13:47 +08:00
register_gradients_procs ( GimpPDB * pdb )
2001-10-26 05:59:52 +08:00
{
2006-04-05 05:11:45 +08:00
GimpProcedure * procedure ;
/*
* gimp - gradients - refresh
*/
2006-04-06 18:01:30 +08:00
procedure = gimp_procedure_new ( gradients_refresh_invoker ) ;
2006-04-07 18:04:27 +08:00
gimp_object_set_static_name ( GIMP_OBJECT ( procedure ) , " gimp-gradients-refresh " ) ;
2006-04-05 05:11:45 +08:00
gimp_procedure_set_static_strings ( procedure ,
" gimp-gradients-refresh " ,
" Refresh current gradients. This function always succeeds. " ,
" This procedure retrieves all gradients currently in the user's gradient path and updates the gradient dialogs accordingly. " ,
" Michael Natterer <mitch@gimp.org> " ,
" Michael Natterer " ,
" 2002 " ,
NULL ) ;
2006-04-26 17:13:47 +08:00
gimp_pdb_register_procedure ( pdb , procedure ) ;
2006-04-07 16:16:26 +08:00
g_object_unref ( procedure ) ;
2006-04-05 05:11:45 +08:00
/*
* gimp - gradients - get - list
*/
2006-04-06 18:01:30 +08:00
procedure = gimp_procedure_new ( gradients_get_list_invoker ) ;
2006-04-07 18:04:27 +08:00
gimp_object_set_static_name ( GIMP_OBJECT ( procedure ) , " gimp-gradients-get-list " ) ;
2006-04-05 05:11:45 +08:00
gimp_procedure_set_static_strings ( procedure ,
" gimp-gradients-get-list " ,
" Retrieve the list of loaded gradients. " ,
" This procedure returns a list of the gradients that are currently loaded. You can later use the 'gimp-context-set-gradient' function to set the active gradient. " ,
" Federico Mena Quintero " ,
" Federico Mena Quintero " ,
" 1997 " ,
NULL ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_string ( " filter " ,
" filter " ,
" An optional regular expression used to filter the list " ,
FALSE , TRUE ,
NULL ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_int32 ( " num-gradients " ,
" num gradients " ,
" The number of loaded gradients " ,
0 , G_MAXINT32 , 0 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_string_array ( " gradient-list " ,
" gradient list " ,
" The list of gradient names " ,
GIMP_PARAM_READWRITE ) ) ;
2006-04-26 17:13:47 +08:00
gimp_pdb_register_procedure ( pdb , procedure ) ;
2006-04-07 16:16:26 +08:00
g_object_unref ( procedure ) ;
2006-04-05 05:11:45 +08:00
/*
* gimp - gradients - sample - uniform
*/
2006-04-06 18:01:30 +08:00
procedure = gimp_procedure_new ( gradients_sample_uniform_invoker ) ;
2006-04-07 18:04:27 +08:00
gimp_object_set_static_name ( GIMP_OBJECT ( procedure ) , " gimp-gradients-sample-uniform " ) ;
2006-04-05 05:11:45 +08:00
gimp_procedure_set_static_strings ( procedure ,
" gimp-gradients-sample-uniform " ,
" This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead. " ,
" This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead. " ,
" " ,
" " ,
" " ,
" gimp-gradient-get-uniform-samples " ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_int32 ( " num-samples " ,
" num samples " ,
" The number of samples to take " ,
2 , G_MAXINT32 , 2 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_argument ( procedure ,
g_param_spec_boolean ( " reverse " ,
" reverse " ,
2006-05-19 01:25:15 +08:00
" Use the reverse gradient " ,
2006-04-05 05:11:45 +08:00
FALSE ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_int32 ( " array-length " ,
" array length " ,
" Length of the color_samples array (4 * num_samples) " ,
0 , G_MAXINT32 , 0 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_float_array ( " color-samples " ,
" color samples " ,
" Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An } " ,
GIMP_PARAM_READWRITE ) ) ;
2006-04-26 17:13:47 +08:00
gimp_pdb_register_procedure ( pdb , procedure ) ;
2006-04-07 16:16:26 +08:00
g_object_unref ( procedure ) ;
2006-04-05 05:11:45 +08:00
/*
* gimp - gradients - sample - custom
*/
2006-04-06 18:01:30 +08:00
procedure = gimp_procedure_new ( gradients_sample_custom_invoker ) ;
2006-04-07 18:04:27 +08:00
gimp_object_set_static_name ( GIMP_OBJECT ( procedure ) , " gimp-gradients-sample-custom " ) ;
2006-04-05 05:11:45 +08:00
gimp_procedure_set_static_strings ( procedure ,
" gimp-gradients-sample-custom " ,
" This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead. " ,
" This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead. " ,
" " ,
" " ,
" " ,
" gimp-gradient-get-custom-samples " ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_int32 ( " num-samples " ,
" num samples " ,
" The number of samples to take " ,
0 , G_MAXINT32 , 0 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_float_array ( " positions " ,
" positions " ,
" The list of positions to sample along the gradient " ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_argument ( procedure ,
g_param_spec_boolean ( " reverse " ,
" reverse " ,
2006-05-19 01:25:15 +08:00
" Use the reverse gradient " ,
2006-04-05 05:11:45 +08:00
FALSE ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_int32 ( " array-length " ,
" array length " ,
" Length of the color_samples array (4 * num_samples) " ,
0 , G_MAXINT32 , 0 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_float_array ( " color-samples " ,
" color samples " ,
" Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An } " ,
GIMP_PARAM_READWRITE ) ) ;
2006-04-26 17:13:47 +08:00
gimp_pdb_register_procedure ( pdb , procedure ) ;
2006-04-07 16:16:26 +08:00
g_object_unref ( procedure ) ;
2006-04-05 05:11:45 +08:00
/*
* gimp - gradients - get - gradient - data
*/
2006-04-06 18:01:30 +08:00
procedure = gimp_procedure_new ( gradients_get_gradient_data_invoker ) ;
2006-04-07 18:04:27 +08:00
gimp_object_set_static_name ( GIMP_OBJECT ( procedure ) , " gimp-gradients-get-gradient-data " ) ;
2006-04-05 05:11:45 +08:00
gimp_procedure_set_static_strings ( procedure ,
" gimp-gradients-get-gradient-data " ,
" This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead. " ,
" This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead. " ,
" " ,
" " ,
" " ,
" gimp-gradient-get-uniform-samples " ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_string ( " name " ,
" name " ,
" The gradient name ( \" \" means current active gradient) " ,
FALSE , TRUE ,
NULL ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_argument ( procedure ,
gimp_param_spec_int32 ( " sample-size " ,
" sample size " ,
2006-05-19 01:25:15 +08:00
" Size of the sample to return when the gradient is changed " ,
2006-04-05 05:11:45 +08:00
1 , 10000 , 1 ,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE ) ) ;
gimp_procedure_add_argument ( procedure ,
g_param_spec_boolean ( " reverse " ,
" reverse " ,
2006-05-19 01:25:15 +08:00
" Use the reverse gradient " ,
2006-04-05 05:11:45 +08:00
FALSE ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_string ( " actual-name " ,
" actual name " ,
" The gradient name " ,
FALSE , FALSE ,
NULL ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_int32 ( " width " ,
" width " ,
" The gradient sample width (r,g,b,a) " ,
0 , G_MAXINT32 , 0 ,
GIMP_PARAM_READWRITE ) ) ;
gimp_procedure_add_return_value ( procedure ,
gimp_param_spec_float_array ( " grad-data " ,
" grad data " ,
" The gradient sample data " ,
GIMP_PARAM_READWRITE ) ) ;
2006-04-26 17:13:47 +08:00
gimp_pdb_register_procedure ( pdb , procedure ) ;
2006-04-07 16:16:26 +08:00
g_object_unref ( procedure ) ;
2006-04-05 05:11:45 +08:00
}