[gimp/wip/gradient-edit: 15/42] app: add gimp_gradient_segment_get_{left, right}_flat_color()
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/gradient-edit: 15/42] app: add gimp_gradient_segment_get_{left, right}_flat_color()
- Date: Fri, 6 Oct 2017 20:04:16 +0000 (UTC)
commit 3e7c5f87f87291c5a19a4e104cf495a14ddb050c
Author: Ell <ell_se yahoo com>
Date: Fri Jul 28 13:28:29 2017 -0400
app: add gimp_gradient_segment_get_{left,right}_flat_color()
... which returns the flat (context-independent) left and right
colors of a egment. Replace code that calculates the flat color
explicitly with calls to these functions.
app/core/gimpgradient.c | 160 ++++++++++++++++++++++-------------------------
app/core/gimpgradient.h | 14 ++++
2 files changed, 88 insertions(+), 86 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 26ce0e2..ccd902d 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -74,6 +74,10 @@ static GimpGradientSegment *
gimp_gradient_get_segment_at_internal (GimpGradient *gradient,
GimpGradientSegment *seg,
gdouble pos);
+static void gimp_gradient_get_flat_color (GimpContext *context,
+ const GimpRGB *color,
+ GimpGradientColor color_type,
+ GimpRGB *flat_color);
static inline gdouble gimp_gradient_calc_linear_factor (gdouble middle,
@@ -490,51 +494,11 @@ gimp_gradient_get_color_at (GimpGradient *gradient,
/* Get left/right colors */
- switch (seg->left_color_type)
- {
- case GIMP_GRADIENT_COLOR_FIXED:
- left_color = seg->left_color;
- break;
+ gimp_gradient_segment_get_left_flat_color (gradient,
+ context, seg, &left_color);
- case GIMP_GRADIENT_COLOR_FOREGROUND:
- case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
- gimp_context_get_foreground (context, &left_color);
-
- if (seg->left_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&left_color, 0.0);
- break;
-
- case GIMP_GRADIENT_COLOR_BACKGROUND:
- case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
- gimp_context_get_background (context, &left_color);
-
- if (seg->left_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&left_color, 0.0);
- break;
- }
-
- switch (seg->right_color_type)
- {
- case GIMP_GRADIENT_COLOR_FIXED:
- right_color = seg->right_color;
- break;
-
- case GIMP_GRADIENT_COLOR_FOREGROUND:
- case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
- gimp_context_get_foreground (context, &right_color);
-
- if (seg->right_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&right_color, 0.0);
- break;
-
- case GIMP_GRADIENT_COLOR_BACKGROUND:
- case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
- gimp_context_get_background (context, &right_color);
-
- if (seg->right_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&right_color, 0.0);
- break;
- }
+ gimp_gradient_segment_get_right_flat_color (gradient,
+ context, seg, &right_color);
/* Calculate color components */
@@ -641,51 +605,15 @@ gimp_gradient_flatten (GimpGradient *gradient,
for (seg = flat->segments; seg; seg = seg->next)
{
- switch (seg->left_color_type)
- {
- case GIMP_GRADIENT_COLOR_FIXED:
- break;
-
- case GIMP_GRADIENT_COLOR_FOREGROUND:
- case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
- gimp_context_get_foreground (context, &seg->left_color);
-
- if (seg->left_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&seg->left_color, 0.0);
- break;
-
- case GIMP_GRADIENT_COLOR_BACKGROUND:
- case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
- gimp_context_get_background (context, &seg->left_color);
-
- if (seg->left_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&seg->left_color, 0.0);
- break;
- }
+ gimp_gradient_segment_get_left_flat_color (gradient,
+ context, seg,
+ &seg->left_color);
seg->left_color_type = GIMP_GRADIENT_COLOR_FIXED;
- switch (seg->right_color_type)
- {
- case GIMP_GRADIENT_COLOR_FIXED:
- break;
-
- case GIMP_GRADIENT_COLOR_FOREGROUND:
- case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
- gimp_context_get_foreground (context, &seg->right_color);
-
- if (seg->right_color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&seg->right_color, 0.0);
- break;
-
- case GIMP_GRADIENT_COLOR_BACKGROUND:
- case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
- gimp_context_get_background (context, &seg->right_color);
-
- if (seg->right_color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
- gimp_rgb_set_alpha (&seg->right_color, 0.0);
- break;
- }
+ gimp_gradient_segment_get_right_flat_color (gradient,
+ context, seg,
+ &seg->right_color);
seg->right_color_type = GIMP_GRADIENT_COLOR_FIXED;
}
@@ -1052,6 +980,36 @@ gimp_gradient_segment_set_right_color_type (GimpGradient *gradient,
gimp_data_thaw (GIMP_DATA (gradient));
}
+void
+gimp_gradient_segment_get_left_flat_color (GimpGradient *gradient,
+ GimpContext *context,
+ GimpGradientSegment *seg,
+ GimpRGB *color)
+{
+ g_return_if_fail (GIMP_IS_GRADIENT (gradient));
+ g_return_if_fail (seg != NULL);
+ g_return_if_fail (color != NULL);
+
+ gimp_gradient_get_flat_color (context,
+ &seg->left_color, seg->left_color_type,
+ color);
+}
+
+void
+gimp_gradient_segment_get_right_flat_color (GimpGradient *gradient,
+ GimpContext *context,
+ GimpGradientSegment *seg,
+ GimpRGB *color)
+{
+ g_return_if_fail (GIMP_IS_GRADIENT (gradient));
+ g_return_if_fail (seg != NULL);
+ g_return_if_fail (color != NULL);
+
+ gimp_gradient_get_flat_color (context,
+ &seg->right_color, seg->right_color_type,
+ color);
+}
+
gdouble
gimp_gradient_segment_get_left_pos (GimpGradient *gradient,
GimpGradientSegment *seg)
@@ -2044,6 +2002,36 @@ gimp_gradient_get_segment_at_internal (GimpGradient *gradient,
return NULL;
}
+static void
+gimp_gradient_get_flat_color (GimpContext *context,
+ const GimpRGB *color,
+ GimpGradientColor color_type,
+ GimpRGB *flat_color)
+{
+ switch (color_type)
+ {
+ case GIMP_GRADIENT_COLOR_FIXED:
+ *flat_color = *color;
+ break;
+
+ case GIMP_GRADIENT_COLOR_FOREGROUND:
+ case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT:
+ gimp_context_get_foreground (context, flat_color);
+
+ if (color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT)
+ gimp_rgb_set_alpha (flat_color, 0.0);
+ break;
+
+ case GIMP_GRADIENT_COLOR_BACKGROUND:
+ case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT:
+ gimp_context_get_background (context, flat_color);
+
+ if (color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT)
+ gimp_rgb_set_alpha (flat_color, 0.0);
+ break;
+ }
+}
+
static inline gdouble
gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos)
diff --git a/app/core/gimpgradient.h b/app/core/gimpgradient.h
index 55cd2bb..b78936a 100644
--- a/app/core/gimpgradient.h
+++ b/app/core/gimpgradient.h
@@ -147,6 +147,20 @@ gimp_gradient_segment_set_right_color_type (GimpGradient *gradient,
GimpGradientColor color_type);
+void
+gimp_gradient_segment_get_left_flat_color (GimpGradient *gradient,
+ GimpContext *context,
+ GimpGradientSegment *seg,
+ GimpRGB *color);
+
+
+void
+gimp_gradient_segment_get_right_flat_color (GimpGradient *gradient,
+ GimpContext *context,
+ GimpGradientSegment *seg,
+ GimpRGB *color);
+
+
/* Position Setting/Getting Routines */
/* (Setters return the position after it was set) */
gdouble gimp_gradient_segment_get_left_pos (GimpGradient *gradient,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]