From d2e598739c3a4cca3b832ee30a0edfa64c350be7 Mon Sep 17 00:00:00 2001 From: GMT 1999 Andy Thomas Date: Mon, 4 Jan 1999 23:56:37 +0000 Subject: [PATCH] app/blend.c plug-ins/script-fu/script-fu.c Mon Jan 4 23:21:56 GMT 1999 Andy Thomas * app/blend.c * plug-ins/script-fu/script-fu.c A patch from Federico to add a spiral gradient type. The patch has been slightly modified to allow both clockwise and anticlockwise spirals and the numbers used to represent these types of gradients have been made to follow on from currently allocated numbers (I hope this will not break any scripts). --- ChangeLog | 11 ++++ app/blend.c | 110 +++++++++++++++++++++++---------- app/core/gimpdrawable-blend.c | 110 +++++++++++++++++++++++---------- app/tools/blend.c | 110 +++++++++++++++++++++++---------- app/tools/gimpblendtool.c | 110 +++++++++++++++++++++++---------- plug-ins/script-fu/script-fu.c | 2 + 6 files changed, 325 insertions(+), 128 deletions(-) diff --git a/ChangeLog b/ChangeLog index b11b3aea76..451df70a6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Jan 4 23:21:56 GMT 1999 Andy Thomas + + * app/blend.c + * plug-ins/script-fu/script-fu.c + + A patch from Federico to add a spiral gradient type. The patch + has been slightly modified to allow both clockwise and anticlockwise + spirals and the numbers used to represent these types of gradients + have been made to follow on from currently allocated numbers (I hope + this will not break any scripts). + Sun Jan 3 14:40:27 PST 1999 Manish Singh * plug-ins/ps/ps.c: new version diff --git a/app/blend.c b/app/blend.c index 7ad62e053f..14c4ff0470 100644 --- a/app/blend.c +++ b/app/blend.c @@ -65,7 +65,10 @@ typedef enum ConicalAsymmetric, ShapeburstAngular, ShapeburstSpherical, - ShapeburstDimpled + ShapeburstDimpled, + SpiralClockwise, + SpiralAntiClockwise, + GradientTypeLast } GradientType; typedef enum @@ -73,14 +76,16 @@ typedef enum FG_BG_RGB_MODE, FG_BG_HSV_MODE, FG_TRANS_MODE, - CUSTOM_MODE + CUSTOM_MODE, + BLEND_MODE_LAST } BlendMode; typedef enum { REPEAT_NONE, REPEAT_SAWTOOTH, - REPEAT_TRIANGULAR + REPEAT_TRIANGULAR, + REPEAT_LAST } RepeatMode; typedef double (*RepeatFunc)(double); @@ -169,6 +174,8 @@ static double gradient_calc_linear_factor (double dist, double *vec, double x, double y); static double gradient_calc_bilinear_factor (double dist, double *vec, double offset, double x, double y); +static double gradient_calc_spiral_factor (double dist, double *axis, double offset, + double x, double y,gint cwise); static double gradient_calc_shapeburst_angular_factor (double x, double y); static double gradient_calc_shapeburst_spherical_factor (double x, double y); static double gradient_calc_shapeburst_dimpled_factor (double x, double y); @@ -229,6 +236,8 @@ static MenuItem gradient_option_items[] = { N_("Shapeburst (angular)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstAngular, NULL, NULL }, { N_("Shapeburst (spherical)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstSpherical, NULL, NULL }, { N_("Shapeburst (dimpled)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstDimpled, NULL, NULL }, + { N_("Spiral (clockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralClockwise, NULL, NULL }, + { N_("Spiral (anticlockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralAntiClockwise, NULL, NULL }, { NULL, 0, 0, NULL, NULL, NULL, NULL } }; @@ -1023,6 +1032,44 @@ gradient_calc_bilinear_factor (double dist, return rat; } /* gradient_calc_bilinear_factor */ +static double +gradient_calc_spiral_factor (double dist, + double *axis, + double offset, + double x, + double y, + gint cwise) +{ + double ang0, ang1; + double ang, r; + double rat; + + if (dist == 0.0) + rat = 0.0; + else + { + if (x != 0.0 || y != 0.0) + { + ang0 = atan2 (axis[0], axis[1]) + M_PI; + ang1 = atan2 (x, y) + M_PI; + if(!cwise) + ang = ang0 - ang1; + else + ang = ang1 - ang0; + + if (ang < 0.0) + ang += (2.0 * M_PI); + + r = sqrt (x * x + y * y) / dist; + rat = ang / (2.0 * M_PI) + r + offset; + rat = fmod (rat, 1.0); + } + else + rat = 0.5 ; /* We are on the middle point */ + } + + return rat; +} static double gradient_calc_shapeburst_angular_factor (double x, @@ -1248,6 +1295,16 @@ gradient_render_pixel(double x, double y, color_t *color, void *render_data) factor = gradient_calc_shapeburst_dimpled_factor(x, y); break; + case SpiralClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,TRUE); + break; + + case SpiralAntiClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,FALSE); + break; + default: fatal_error(_("gradient_render_pixel(): unknown gradient type %d"), (int) rbd->gradient_type); @@ -1400,6 +1457,8 @@ gradient_fill_region (GImage *gimage, case ConicalSymmetric: case ConicalAsymmetric: + case SpiralClockwise: + case SpiralAntiClockwise: case Linear: case BiLinear: rbd.dist = sqrt(SQR(ex - sx) + SQR(ey - sy)); @@ -1724,7 +1783,7 @@ ProcArg blend_args[] = }, { PDB_INT32, "gradient_type", - "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8) }" + "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8), SPIRAL-CLOCKWISE(9), SPRIAL-ANTICLOCKWISE(10) }" }, { PDB_FLOAT, "opacity", @@ -1835,14 +1894,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[1].value.pdb_int; - switch (int_value) - { - case 0: blend_mode = FG_BG_RGB_MODE; break; - case 1: blend_mode = FG_BG_HSV_MODE; break; - case 2: blend_mode = FG_TRANS_MODE; break; - case 3: blend_mode = CUSTOM_MODE; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < BLEND_MODE_LAST) + blend_mode = (BlendMode) int_value; + else + success = FALSE; } /* paint mode */ if (success) @@ -1857,19 +1913,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[3].value.pdb_int; - switch (int_value) - { - case 0: gradient_type = Linear; break; - case 1: gradient_type = BiLinear; break; - case 2: gradient_type = Radial; break; - case 3: gradient_type = Square; break; - case 4: gradient_type = ConicalSymmetric; break; - case 5: gradient_type = ConicalAsymmetric; break; - case 6: gradient_type = ShapeburstAngular; break; - case 7: gradient_type = ShapeburstSpherical; break; - case 8: gradient_type = ShapeburstDimpled; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < GradientTypeLast) + gradient_type = (GradientType) int_value; + else + success = FALSE; } /* opacity */ if (success) @@ -1893,13 +1941,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[6].value.pdb_int; - switch (int_value) - { - case 0: repeat = REPEAT_NONE; break; - case 1: repeat = REPEAT_SAWTOOTH; break; - case 2: repeat = REPEAT_TRIANGULAR; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < REPEAT_LAST) + repeat = (RepeatMode) int_value; + else + success = FALSE; } /* supersampling */ if (success) diff --git a/app/core/gimpdrawable-blend.c b/app/core/gimpdrawable-blend.c index 7ad62e053f..14c4ff0470 100644 --- a/app/core/gimpdrawable-blend.c +++ b/app/core/gimpdrawable-blend.c @@ -65,7 +65,10 @@ typedef enum ConicalAsymmetric, ShapeburstAngular, ShapeburstSpherical, - ShapeburstDimpled + ShapeburstDimpled, + SpiralClockwise, + SpiralAntiClockwise, + GradientTypeLast } GradientType; typedef enum @@ -73,14 +76,16 @@ typedef enum FG_BG_RGB_MODE, FG_BG_HSV_MODE, FG_TRANS_MODE, - CUSTOM_MODE + CUSTOM_MODE, + BLEND_MODE_LAST } BlendMode; typedef enum { REPEAT_NONE, REPEAT_SAWTOOTH, - REPEAT_TRIANGULAR + REPEAT_TRIANGULAR, + REPEAT_LAST } RepeatMode; typedef double (*RepeatFunc)(double); @@ -169,6 +174,8 @@ static double gradient_calc_linear_factor (double dist, double *vec, double x, double y); static double gradient_calc_bilinear_factor (double dist, double *vec, double offset, double x, double y); +static double gradient_calc_spiral_factor (double dist, double *axis, double offset, + double x, double y,gint cwise); static double gradient_calc_shapeburst_angular_factor (double x, double y); static double gradient_calc_shapeburst_spherical_factor (double x, double y); static double gradient_calc_shapeburst_dimpled_factor (double x, double y); @@ -229,6 +236,8 @@ static MenuItem gradient_option_items[] = { N_("Shapeburst (angular)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstAngular, NULL, NULL }, { N_("Shapeburst (spherical)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstSpherical, NULL, NULL }, { N_("Shapeburst (dimpled)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstDimpled, NULL, NULL }, + { N_("Spiral (clockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralClockwise, NULL, NULL }, + { N_("Spiral (anticlockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralAntiClockwise, NULL, NULL }, { NULL, 0, 0, NULL, NULL, NULL, NULL } }; @@ -1023,6 +1032,44 @@ gradient_calc_bilinear_factor (double dist, return rat; } /* gradient_calc_bilinear_factor */ +static double +gradient_calc_spiral_factor (double dist, + double *axis, + double offset, + double x, + double y, + gint cwise) +{ + double ang0, ang1; + double ang, r; + double rat; + + if (dist == 0.0) + rat = 0.0; + else + { + if (x != 0.0 || y != 0.0) + { + ang0 = atan2 (axis[0], axis[1]) + M_PI; + ang1 = atan2 (x, y) + M_PI; + if(!cwise) + ang = ang0 - ang1; + else + ang = ang1 - ang0; + + if (ang < 0.0) + ang += (2.0 * M_PI); + + r = sqrt (x * x + y * y) / dist; + rat = ang / (2.0 * M_PI) + r + offset; + rat = fmod (rat, 1.0); + } + else + rat = 0.5 ; /* We are on the middle point */ + } + + return rat; +} static double gradient_calc_shapeburst_angular_factor (double x, @@ -1248,6 +1295,16 @@ gradient_render_pixel(double x, double y, color_t *color, void *render_data) factor = gradient_calc_shapeburst_dimpled_factor(x, y); break; + case SpiralClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,TRUE); + break; + + case SpiralAntiClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,FALSE); + break; + default: fatal_error(_("gradient_render_pixel(): unknown gradient type %d"), (int) rbd->gradient_type); @@ -1400,6 +1457,8 @@ gradient_fill_region (GImage *gimage, case ConicalSymmetric: case ConicalAsymmetric: + case SpiralClockwise: + case SpiralAntiClockwise: case Linear: case BiLinear: rbd.dist = sqrt(SQR(ex - sx) + SQR(ey - sy)); @@ -1724,7 +1783,7 @@ ProcArg blend_args[] = }, { PDB_INT32, "gradient_type", - "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8) }" + "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8), SPIRAL-CLOCKWISE(9), SPRIAL-ANTICLOCKWISE(10) }" }, { PDB_FLOAT, "opacity", @@ -1835,14 +1894,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[1].value.pdb_int; - switch (int_value) - { - case 0: blend_mode = FG_BG_RGB_MODE; break; - case 1: blend_mode = FG_BG_HSV_MODE; break; - case 2: blend_mode = FG_TRANS_MODE; break; - case 3: blend_mode = CUSTOM_MODE; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < BLEND_MODE_LAST) + blend_mode = (BlendMode) int_value; + else + success = FALSE; } /* paint mode */ if (success) @@ -1857,19 +1913,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[3].value.pdb_int; - switch (int_value) - { - case 0: gradient_type = Linear; break; - case 1: gradient_type = BiLinear; break; - case 2: gradient_type = Radial; break; - case 3: gradient_type = Square; break; - case 4: gradient_type = ConicalSymmetric; break; - case 5: gradient_type = ConicalAsymmetric; break; - case 6: gradient_type = ShapeburstAngular; break; - case 7: gradient_type = ShapeburstSpherical; break; - case 8: gradient_type = ShapeburstDimpled; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < GradientTypeLast) + gradient_type = (GradientType) int_value; + else + success = FALSE; } /* opacity */ if (success) @@ -1893,13 +1941,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[6].value.pdb_int; - switch (int_value) - { - case 0: repeat = REPEAT_NONE; break; - case 1: repeat = REPEAT_SAWTOOTH; break; - case 2: repeat = REPEAT_TRIANGULAR; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < REPEAT_LAST) + repeat = (RepeatMode) int_value; + else + success = FALSE; } /* supersampling */ if (success) diff --git a/app/tools/blend.c b/app/tools/blend.c index 7ad62e053f..14c4ff0470 100644 --- a/app/tools/blend.c +++ b/app/tools/blend.c @@ -65,7 +65,10 @@ typedef enum ConicalAsymmetric, ShapeburstAngular, ShapeburstSpherical, - ShapeburstDimpled + ShapeburstDimpled, + SpiralClockwise, + SpiralAntiClockwise, + GradientTypeLast } GradientType; typedef enum @@ -73,14 +76,16 @@ typedef enum FG_BG_RGB_MODE, FG_BG_HSV_MODE, FG_TRANS_MODE, - CUSTOM_MODE + CUSTOM_MODE, + BLEND_MODE_LAST } BlendMode; typedef enum { REPEAT_NONE, REPEAT_SAWTOOTH, - REPEAT_TRIANGULAR + REPEAT_TRIANGULAR, + REPEAT_LAST } RepeatMode; typedef double (*RepeatFunc)(double); @@ -169,6 +174,8 @@ static double gradient_calc_linear_factor (double dist, double *vec, double x, double y); static double gradient_calc_bilinear_factor (double dist, double *vec, double offset, double x, double y); +static double gradient_calc_spiral_factor (double dist, double *axis, double offset, + double x, double y,gint cwise); static double gradient_calc_shapeburst_angular_factor (double x, double y); static double gradient_calc_shapeburst_spherical_factor (double x, double y); static double gradient_calc_shapeburst_dimpled_factor (double x, double y); @@ -229,6 +236,8 @@ static MenuItem gradient_option_items[] = { N_("Shapeburst (angular)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstAngular, NULL, NULL }, { N_("Shapeburst (spherical)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstSpherical, NULL, NULL }, { N_("Shapeburst (dimpled)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstDimpled, NULL, NULL }, + { N_("Spiral (clockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralClockwise, NULL, NULL }, + { N_("Spiral (anticlockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralAntiClockwise, NULL, NULL }, { NULL, 0, 0, NULL, NULL, NULL, NULL } }; @@ -1023,6 +1032,44 @@ gradient_calc_bilinear_factor (double dist, return rat; } /* gradient_calc_bilinear_factor */ +static double +gradient_calc_spiral_factor (double dist, + double *axis, + double offset, + double x, + double y, + gint cwise) +{ + double ang0, ang1; + double ang, r; + double rat; + + if (dist == 0.0) + rat = 0.0; + else + { + if (x != 0.0 || y != 0.0) + { + ang0 = atan2 (axis[0], axis[1]) + M_PI; + ang1 = atan2 (x, y) + M_PI; + if(!cwise) + ang = ang0 - ang1; + else + ang = ang1 - ang0; + + if (ang < 0.0) + ang += (2.0 * M_PI); + + r = sqrt (x * x + y * y) / dist; + rat = ang / (2.0 * M_PI) + r + offset; + rat = fmod (rat, 1.0); + } + else + rat = 0.5 ; /* We are on the middle point */ + } + + return rat; +} static double gradient_calc_shapeburst_angular_factor (double x, @@ -1248,6 +1295,16 @@ gradient_render_pixel(double x, double y, color_t *color, void *render_data) factor = gradient_calc_shapeburst_dimpled_factor(x, y); break; + case SpiralClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,TRUE); + break; + + case SpiralAntiClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,FALSE); + break; + default: fatal_error(_("gradient_render_pixel(): unknown gradient type %d"), (int) rbd->gradient_type); @@ -1400,6 +1457,8 @@ gradient_fill_region (GImage *gimage, case ConicalSymmetric: case ConicalAsymmetric: + case SpiralClockwise: + case SpiralAntiClockwise: case Linear: case BiLinear: rbd.dist = sqrt(SQR(ex - sx) + SQR(ey - sy)); @@ -1724,7 +1783,7 @@ ProcArg blend_args[] = }, { PDB_INT32, "gradient_type", - "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8) }" + "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8), SPIRAL-CLOCKWISE(9), SPRIAL-ANTICLOCKWISE(10) }" }, { PDB_FLOAT, "opacity", @@ -1835,14 +1894,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[1].value.pdb_int; - switch (int_value) - { - case 0: blend_mode = FG_BG_RGB_MODE; break; - case 1: blend_mode = FG_BG_HSV_MODE; break; - case 2: blend_mode = FG_TRANS_MODE; break; - case 3: blend_mode = CUSTOM_MODE; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < BLEND_MODE_LAST) + blend_mode = (BlendMode) int_value; + else + success = FALSE; } /* paint mode */ if (success) @@ -1857,19 +1913,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[3].value.pdb_int; - switch (int_value) - { - case 0: gradient_type = Linear; break; - case 1: gradient_type = BiLinear; break; - case 2: gradient_type = Radial; break; - case 3: gradient_type = Square; break; - case 4: gradient_type = ConicalSymmetric; break; - case 5: gradient_type = ConicalAsymmetric; break; - case 6: gradient_type = ShapeburstAngular; break; - case 7: gradient_type = ShapeburstSpherical; break; - case 8: gradient_type = ShapeburstDimpled; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < GradientTypeLast) + gradient_type = (GradientType) int_value; + else + success = FALSE; } /* opacity */ if (success) @@ -1893,13 +1941,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[6].value.pdb_int; - switch (int_value) - { - case 0: repeat = REPEAT_NONE; break; - case 1: repeat = REPEAT_SAWTOOTH; break; - case 2: repeat = REPEAT_TRIANGULAR; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < REPEAT_LAST) + repeat = (RepeatMode) int_value; + else + success = FALSE; } /* supersampling */ if (success) diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c index 7ad62e053f..14c4ff0470 100644 --- a/app/tools/gimpblendtool.c +++ b/app/tools/gimpblendtool.c @@ -65,7 +65,10 @@ typedef enum ConicalAsymmetric, ShapeburstAngular, ShapeburstSpherical, - ShapeburstDimpled + ShapeburstDimpled, + SpiralClockwise, + SpiralAntiClockwise, + GradientTypeLast } GradientType; typedef enum @@ -73,14 +76,16 @@ typedef enum FG_BG_RGB_MODE, FG_BG_HSV_MODE, FG_TRANS_MODE, - CUSTOM_MODE + CUSTOM_MODE, + BLEND_MODE_LAST } BlendMode; typedef enum { REPEAT_NONE, REPEAT_SAWTOOTH, - REPEAT_TRIANGULAR + REPEAT_TRIANGULAR, + REPEAT_LAST } RepeatMode; typedef double (*RepeatFunc)(double); @@ -169,6 +174,8 @@ static double gradient_calc_linear_factor (double dist, double *vec, double x, double y); static double gradient_calc_bilinear_factor (double dist, double *vec, double offset, double x, double y); +static double gradient_calc_spiral_factor (double dist, double *axis, double offset, + double x, double y,gint cwise); static double gradient_calc_shapeburst_angular_factor (double x, double y); static double gradient_calc_shapeburst_spherical_factor (double x, double y); static double gradient_calc_shapeburst_dimpled_factor (double x, double y); @@ -229,6 +236,8 @@ static MenuItem gradient_option_items[] = { N_("Shapeburst (angular)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstAngular, NULL, NULL }, { N_("Shapeburst (spherical)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstSpherical, NULL, NULL }, { N_("Shapeburst (dimpled)"), 0, 0, gradient_type_callback, (gpointer) ShapeburstDimpled, NULL, NULL }, + { N_("Spiral (clockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralClockwise, NULL, NULL }, + { N_("Spiral (anticlockwise)"), 0, 0, gradient_type_callback, (gpointer) SpiralAntiClockwise, NULL, NULL }, { NULL, 0, 0, NULL, NULL, NULL, NULL } }; @@ -1023,6 +1032,44 @@ gradient_calc_bilinear_factor (double dist, return rat; } /* gradient_calc_bilinear_factor */ +static double +gradient_calc_spiral_factor (double dist, + double *axis, + double offset, + double x, + double y, + gint cwise) +{ + double ang0, ang1; + double ang, r; + double rat; + + if (dist == 0.0) + rat = 0.0; + else + { + if (x != 0.0 || y != 0.0) + { + ang0 = atan2 (axis[0], axis[1]) + M_PI; + ang1 = atan2 (x, y) + M_PI; + if(!cwise) + ang = ang0 - ang1; + else + ang = ang1 - ang0; + + if (ang < 0.0) + ang += (2.0 * M_PI); + + r = sqrt (x * x + y * y) / dist; + rat = ang / (2.0 * M_PI) + r + offset; + rat = fmod (rat, 1.0); + } + else + rat = 0.5 ; /* We are on the middle point */ + } + + return rat; +} static double gradient_calc_shapeburst_angular_factor (double x, @@ -1248,6 +1295,16 @@ gradient_render_pixel(double x, double y, color_t *color, void *render_data) factor = gradient_calc_shapeburst_dimpled_factor(x, y); break; + case SpiralClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,TRUE); + break; + + case SpiralAntiClockwise: + factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset, + x - rbd->sx, y - rbd->sy,FALSE); + break; + default: fatal_error(_("gradient_render_pixel(): unknown gradient type %d"), (int) rbd->gradient_type); @@ -1400,6 +1457,8 @@ gradient_fill_region (GImage *gimage, case ConicalSymmetric: case ConicalAsymmetric: + case SpiralClockwise: + case SpiralAntiClockwise: case Linear: case BiLinear: rbd.dist = sqrt(SQR(ex - sx) + SQR(ey - sy)); @@ -1724,7 +1783,7 @@ ProcArg blend_args[] = }, { PDB_INT32, "gradient_type", - "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8) }" + "The type of gradient: { LINEAR (0), BILINEAR (1), RADIAL (2), SQUARE (3), CONICAL-SYMMETRIC (4), CONICAL-ASYMMETRIC (5), SHAPEBURST-ANGULAR (6), SHAPEBURST-SPHERICAL (7), SHAPEBURST-DIMPLED (8), SPIRAL-CLOCKWISE(9), SPRIAL-ANTICLOCKWISE(10) }" }, { PDB_FLOAT, "opacity", @@ -1835,14 +1894,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[1].value.pdb_int; - switch (int_value) - { - case 0: blend_mode = FG_BG_RGB_MODE; break; - case 1: blend_mode = FG_BG_HSV_MODE; break; - case 2: blend_mode = FG_TRANS_MODE; break; - case 3: blend_mode = CUSTOM_MODE; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < BLEND_MODE_LAST) + blend_mode = (BlendMode) int_value; + else + success = FALSE; } /* paint mode */ if (success) @@ -1857,19 +1913,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[3].value.pdb_int; - switch (int_value) - { - case 0: gradient_type = Linear; break; - case 1: gradient_type = BiLinear; break; - case 2: gradient_type = Radial; break; - case 3: gradient_type = Square; break; - case 4: gradient_type = ConicalSymmetric; break; - case 5: gradient_type = ConicalAsymmetric; break; - case 6: gradient_type = ShapeburstAngular; break; - case 7: gradient_type = ShapeburstSpherical; break; - case 8: gradient_type = ShapeburstDimpled; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < GradientTypeLast) + gradient_type = (GradientType) int_value; + else + success = FALSE; } /* opacity */ if (success) @@ -1893,13 +1941,11 @@ blend_invoker (Argument *args) if (success) { int_value = args[6].value.pdb_int; - switch (int_value) - { - case 0: repeat = REPEAT_NONE; break; - case 1: repeat = REPEAT_SAWTOOTH; break; - case 2: repeat = REPEAT_TRIANGULAR; break; - default: success = FALSE; - } + + if (int_value >= 0 && int_value < REPEAT_LAST) + repeat = (RepeatMode) int_value; + else + success = FALSE; } /* supersampling */ if (success) diff --git a/plug-ins/script-fu/script-fu.c b/plug-ins/script-fu/script-fu.c index ee28e04fdb..f0d29f5282 100644 --- a/plug-ins/script-fu/script-fu.c +++ b/plug-ins/script-fu/script-fu.c @@ -405,6 +405,8 @@ init_constants () setvar (cintern ("SHAPEBURST-ANGULAR"), flocons (6), NIL); setvar (cintern ("SHAPEBURST-SPHERICAL"), flocons (7), NIL); setvar (cintern ("SHAPEBURST-DIMPLED"), flocons (8), NIL); + setvar (cintern ("SPIRAL-CLOCKWISE"), flocons (9), NIL); + setvar (cintern ("SPRIAL-ANTICLOCKWISE"), flocons (10), NIL); setvar (cintern ("REPEAT-NONE"), flocons(0), NIL); setvar (cintern ("REPEAT-SAWTOOTH"), flocons(1), NIL);