static void gimp_colorize_tool_config_notify (GObject *object, GParamSpec *pspec, GimpColorizeTool *col_tool) { GimpColorizeConfig *config = GIMP_COLORIZE_CONFIG (object); GimpRGB color; if (! col_tool->hue_data) return; if (! strcmp (pspec->name, "hue")) { gtk_adjustment_set_value (col_tool->hue_data, config->hue * 360.0); } else if (! strcmp (pspec->name, "saturation")) { gtk_adjustment_set_value (col_tool->saturation_data, config->saturation * 100.0); } else if (! strcmp (pspec->name, "lightness")) { gtk_adjustment_set_value (col_tool->lightness_data, config->lightness * 100.0); } gimp_colorize_config_get_color (col_tool->config, &color); gimp_color_button_set_color (GIMP_COLOR_BUTTON (col_tool->color_button), &color); }
static gboolean gimp_colorize_config_equal (GimpConfig *a, GimpConfig *b) { GimpColorizeConfig *config_a = GIMP_COLORIZE_CONFIG (a); GimpColorizeConfig *config_b = GIMP_COLORIZE_CONFIG (b); if (config_a->hue != config_b->hue || config_a->saturation != config_b->saturation || config_a->lightness != config_b->lightness) { return FALSE; } return TRUE; }
static void gimp_colorize_tool_config_notify (GObject *object, GParamSpec *pspec, GimpColorizeTool *col_tool) { GimpColorizeConfig *config = GIMP_COLORIZE_CONFIG (object); if (! col_tool->hue_data) return; if (! strcmp (pspec->name, "hue")) { gtk_adjustment_set_value (col_tool->hue_data, config->hue * 360.0); } else if (! strcmp (pspec->name, "saturation")) { gtk_adjustment_set_value (col_tool->saturation_data, config->saturation * 100.0); } else if (! strcmp (pspec->name, "lightness")) { gtk_adjustment_set_value (col_tool->lightness_data, config->lightness * 100.0); } gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool)); }
static gboolean gimp_operation_colorize_process (GeglOperation *operation, void *in_buf, void *out_buf, glong samples, const GeglRectangle *roi, gint level) { GimpOperationPointFilter *point = GIMP_OPERATION_POINT_FILTER (operation); GimpColorizeConfig *config = GIMP_COLORIZE_CONFIG (point->config); gfloat *src = in_buf; gfloat *dest = out_buf; GimpHSL hsl; if (! config) return FALSE; hsl.h = config->hue; hsl.s = config->saturation; hsl.a = src[ALPHA]; while (samples--) { GimpRGB rgb; gfloat lum = GIMP_RGB_LUMINANCE (src[RED], src[GREEN], src[BLUE]); if (config->lightness > 0) { lum = lum * (1.0 - config->lightness); lum += 1.0 - (1.0 - config->lightness); } else if (config->lightness < 0) { lum = lum * (config->lightness + 1.0); } hsl.l = lum; gimp_hsl_to_rgb (&hsl, &rgb); /* the code in base/colorize.c would multiply r,b,g with lum, * but this is a bug since it should multiply with 255. We * don't repeat this bug here (this is the reason why the gegl * colorize is brighter than the legacy one). */ dest[RED] = rgb.r; /* * lum; */ dest[GREEN] = rgb.g; /* * lum; */ dest[BLUE] = rgb.b; /* * lum */; dest[ALPHA] = rgb.a; src += 4; dest += 4; } return TRUE; }
static void gimp_colorize_config_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GimpColorizeConfig *self = GIMP_COLORIZE_CONFIG (object); switch (property_id) { case PROP_HUE: self->hue = g_value_get_double (value); g_object_notify (object, "color"); break; case PROP_SATURATION: self->saturation = g_value_get_double (value); g_object_notify (object, "color"); break; case PROP_LIGHTNESS: self->lightness = g_value_get_double (value); g_object_notify (object, "color"); break; case PROP_COLOR: { GimpRGB rgb; GimpHSL hsl; gimp_value_get_rgb (value, &rgb); gimp_rgb_to_hsl (&rgb, &hsl); if (hsl.h == -1) hsl.h = self->hue; if (hsl.l == 0.0 || hsl.l == 1.0) hsl.s = self->saturation; g_object_set (self, "hue", hsl.h, "saturation", hsl.s, "lightness", hsl.l * 2.0 - 1.0, NULL); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void gimp_colorize_config_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GimpColorizeConfig *self = GIMP_COLORIZE_CONFIG (object); switch (property_id) { case PROP_HUE: g_value_set_double (value, self->hue); break; case PROP_SATURATION: g_value_set_double (value, self->saturation); break; case PROP_LIGHTNESS: g_value_set_double (value, self->lightness); break; case PROP_COLOR: { GimpHSL hsl; GimpRGB rgb; gimp_hsl_set (&hsl, self->hue, self->saturation, (self->lightness + 1.0) / 2.0); gimp_hsl_set_alpha (&hsl, 1.0); gimp_hsl_to_rgb (&hsl, &rgb); gimp_value_set_rgb (value, &rgb); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }