static gboolean gimp_color_balance_config_copy (GimpConfig *src, GimpConfig *dest, GParamFlags flags) { GimpColorBalanceConfig *src_config = GIMP_COLOR_BALANCE_CONFIG (src); GimpColorBalanceConfig *dest_config = GIMP_COLOR_BALANCE_CONFIG (dest); GimpTransferMode range; for (range = GIMP_TRANSFER_SHADOWS; range <= GIMP_TRANSFER_HIGHLIGHTS; range++) { dest_config->cyan_red[range] = src_config->cyan_red[range]; dest_config->magenta_green[range] = src_config->magenta_green[range]; dest_config->yellow_blue[range] = src_config->yellow_blue[range]; } g_object_notify (G_OBJECT (dest), "cyan-red"); g_object_notify (G_OBJECT (dest), "magenta-green"); g_object_notify (G_OBJECT (dest), "yellow-blue"); dest_config->range = src_config->range; dest_config->preserve_luminosity = src_config->preserve_luminosity; g_object_notify (G_OBJECT (dest), "range"); g_object_notify (G_OBJECT (dest), "preserve-luminosity"); return TRUE; }
static gboolean gimp_color_balance_config_equal (GimpConfig *a, GimpConfig *b) { GimpColorBalanceConfig *config_a = GIMP_COLOR_BALANCE_CONFIG (a); GimpColorBalanceConfig *config_b = GIMP_COLOR_BALANCE_CONFIG (b); GimpTransferMode range; for (range = GIMP_TRANSFER_SHADOWS; range <= GIMP_TRANSFER_HIGHLIGHTS; range++) { if (config_a->cyan_red[range] != config_b->cyan_red[range] || config_a->magenta_green[range] != config_b->magenta_green[range] || config_a->yellow_blue[range] != config_b->yellow_blue[range]) return FALSE; } /* don't compare "range" */ if (config_a->preserve_luminosity != config_b->preserve_luminosity) return FALSE; return TRUE; }
static void gimp_color_balance_config_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GimpColorBalanceConfig *self = GIMP_COLOR_BALANCE_CONFIG (object); switch (property_id) { case PROP_RANGE: g_value_set_enum (value, self->range); break; case PROP_CYAN_RED: g_value_set_double (value, self->cyan_red[self->range]); break; case PROP_MAGENTA_GREEN: g_value_set_double (value, self->magenta_green[self->range]); break; case PROP_YELLOW_BLUE: g_value_set_double (value, self->yellow_blue[self->range]); break; case PROP_PRESERVE_LUMINOSITY: g_value_set_boolean (value, self->preserve_luminosity); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static gboolean gimp_color_balance_config_serialize (GimpConfig *config, GimpConfigWriter *writer, gpointer data) { GimpColorBalanceConfig *bc_config = GIMP_COLOR_BALANCE_CONFIG (config); GimpTransferMode range; GimpTransferMode old_range; gboolean success = TRUE; if (! gimp_config_serialize_property_by_name (config, "time", writer)) return FALSE; old_range = bc_config->range; for (range = GIMP_TRANSFER_SHADOWS; range <= GIMP_TRANSFER_HIGHLIGHTS; range++) { bc_config->range = range; success = (gimp_config_serialize_property_by_name (config, "range", writer) && gimp_config_serialize_property_by_name (config, "cyan-red", writer) && gimp_config_serialize_property_by_name (config, "magenta-green", writer) && gimp_config_serialize_property_by_name (config, "yellow-blue", writer)); if (! success) break; } if (success) success = gimp_config_serialize_property_by_name (config, "preserve-luminosity", writer); bc_config->range = old_range; return success; }
static void gimp_color_balance_config_reset (GimpConfig *config) { GimpColorBalanceConfig *cb_config = GIMP_COLOR_BALANCE_CONFIG (config); GimpTransferMode range; for (range = GIMP_TRANSFER_SHADOWS; range <= GIMP_TRANSFER_HIGHLIGHTS; range++) { cb_config->range = range; gimp_color_balance_config_reset_range (cb_config); } gimp_config_reset_property (G_OBJECT (config), "range"); gimp_config_reset_property (G_OBJECT (config), "preserve-luminosity"); }
static gboolean gimp_color_balance_config_deserialize (GimpConfig *config, GScanner *scanner, gint nest_level, gpointer data) { GimpColorBalanceConfig *cb_config = GIMP_COLOR_BALANCE_CONFIG (config); GimpTransferMode old_range; gboolean success = TRUE; old_range = cb_config->range; success = gimp_config_deserialize_properties (config, scanner, nest_level); g_object_set (config, "range", old_range, NULL); return success; }
static void color_balance_config_notify (GObject *object, GParamSpec *pspec, GimpColorBalanceTool *cb_tool) { GimpColorBalanceConfig *config = GIMP_COLOR_BALANCE_CONFIG (object); if (! cb_tool->cyan_red_adj) return; if (! strcmp (pspec->name, "range")) { gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (cb_tool->range_radio), config->range); } else if (! strcmp (pspec->name, "cyan-red")) { gtk_adjustment_set_value (cb_tool->cyan_red_adj, config->cyan_red[config->range] * 100.0); } else if (! strcmp (pspec->name, "magenta-green")) { gtk_adjustment_set_value (cb_tool->magenta_green_adj, config->magenta_green[config->range] * 100.0); } else if (! strcmp (pspec->name, "yellow-blue")) { gtk_adjustment_set_value (cb_tool->yellow_blue_adj, config->yellow_blue[config->range] * 100.0); } else if (! strcmp (pspec->name, "preserve-luminosity")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_tool->preserve_toggle), config->preserve_luminosity); } gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool)); }
static gboolean gimp_operation_color_balance_process (GeglOperation *operation, void *in_buf, void *out_buf, glong samples, const GeglRectangle *roi, gint level) { GimpOperationPointFilter *point = GIMP_OPERATION_POINT_FILTER (operation); GimpColorBalanceConfig *config = GIMP_COLOR_BALANCE_CONFIG (point->config); gfloat *src = in_buf; gfloat *dest = out_buf; if (! config) return FALSE; while (samples--) { gfloat r = src[RED]; gfloat g = src[GREEN]; gfloat b = src[BLUE]; gfloat r_n; gfloat g_n; gfloat b_n; GimpRGB rgb = { r, g, b}; GimpHSL hsl; gimp_rgb_to_hsl (&rgb, &hsl); r_n = gimp_operation_color_balance_map (r, hsl.l, config->cyan_red[GIMP_SHADOWS], config->cyan_red[GIMP_MIDTONES], config->cyan_red[GIMP_HIGHLIGHTS]); g_n = gimp_operation_color_balance_map (g, hsl.l, config->magenta_green[GIMP_SHADOWS], config->magenta_green[GIMP_MIDTONES], config->magenta_green[GIMP_HIGHLIGHTS]); b_n = gimp_operation_color_balance_map (b, hsl.l, config->yellow_blue[GIMP_SHADOWS], config->yellow_blue[GIMP_MIDTONES], config->yellow_blue[GIMP_HIGHLIGHTS]); if (config->preserve_luminosity) { GimpHSL hsl2; rgb.r = r_n; rgb.g = g_n; rgb.b = b_n; gimp_rgb_to_hsl (&rgb, &hsl); rgb.r = r; rgb.g = g; rgb.b = b; gimp_rgb_to_hsl (&rgb, &hsl2); hsl.l = hsl2.l; gimp_hsl_to_rgb (&hsl, &rgb); r_n = rgb.r; g_n = rgb.g; b_n = rgb.b; } dest[RED] = r_n; dest[GREEN] = g_n; dest[BLUE] = b_n; dest[ALPHA] = src[ALPHA]; src += 4; dest += 4; } return TRUE; }
static void color_balance_range_reset_callback (GtkWidget *widget, GimpImageMapTool *im_tool) { gimp_color_balance_config_reset_range (GIMP_COLOR_BALANCE_CONFIG (im_tool->config)); }