Author: post
Date: 2010-10-31 16:27:38 +0100 (Sun, 31 Oct 2010)
New Revision: 3600
Modified:
trunk/librawstudio/rs-curve.c
trunk/librawstudio/rs-curve.h
Log:
Enable requesting the curve data prior to modification from parent filter
chain. This also includes complete re-write of current pixel display, that will
now display input/output values and removal of unused code for this.
Modified: trunk/librawstudio/rs-curve.c
===================================================================
--- trunk/librawstudio/rs-curve.c 2010-10-31 15:15:37 UTC (rev 3599)
+++ trunk/librawstudio/rs-curve.c 2010-10-31 15:27:38 UTC (rev 3600)
@@ -31,7 +31,6 @@
gint active_knot;
gfloat *array;
guint array_length;
- gfloat marker;
gulong size_signal;
/* For drawing the histogram */
@@ -119,7 +118,6 @@
curve->array = NULL;
curve->array_length = 0;
curve->spline = rs_spline_new(NULL, 0, NATURAL);
- curve->marker = -1.0;
curve->bg_buffer = NULL;
/* Let us know about pointer movements */
@@ -150,25 +148,28 @@
return g_object_new (RS_CURVE_TYPE_WIDGET, NULL);
}
-/**
- * Sets a position to be marked in the curve widget
- * @param curve A RSCurveWidget
- * @param position The position to mark in the range 0.0-1.0 (-1.0 to hide)
- */
-extern void
-rs_curve_widget_set_marker(RSCurveWidget *curve, gfloat position)
+float
+rs_curve_widget_get_marker(RSCurveWidget *curve)
{
- g_return_if_fail (curve != NULL);
- g_return_if_fail (RS_IS_CURVE_WIDGET(curve));
+ g_return_val_if_fail (curve != NULL, -1.0f);
+ g_return_val_if_fail (RS_IS_CURVE_WIDGET(curve), -1.0f);
+ gfloat position = MAX(MAX(curve->rgb_values[0],
curve->rgb_values[1]),curve->rgb_values[2]);
+
/* Clamp values above 1.0 */
if (position > 1.0)
position = 1.0;
- curve->marker = position;
+ if (curve->display_color_space && position >= 0.0f)
+ {
+ const RS1dFunction *func =
rs_color_space_get_gamma_function(curve->display_color_space);
+ position = rs_1d_function_evaluate_inverse(func, position);
+ position = sqrtf(position);
+ }
+ else
+ position = -1.0;
- /* Redraw everything */
- rs_curve_draw(curve);
+ return position;
}
/**
@@ -201,48 +202,14 @@
#define BLUMF LUM_FIXED(0.072169f)
#define HALFF LUM_FIXED(0.5f)
-static void
-calculate_histogram(RSCurveWidget *curve)
+void
+rs_curve_set_histogram_data(RSCurveWidget *curve, const gint *input)
{
- gint x, y;
-
- guint *hist = &curve->histogram_data[0];
- /* Reset table */
- memset(hist, 0x00, sizeof(guint)*256);
+ g_return_if_fail (RS_IS_CURVE_WIDGET(curve));
- if (!curve->input)
- return;
-
- RSFilterRequest *request = rs_filter_request_new();
- rs_filter_request_set_quick(RS_FILTER_REQUEST(request), TRUE);
- rs_filter_param_set_object(RS_FILTER_PARAM(request), "colorspace",
curve->display_color_space);
-
- RSFilterResponse *response = rs_filter_get_image8(curve->input,
request);
- g_object_unref(request);
-
- GdkPixbuf *pixbuf = rs_filter_response_get_image8(response);
- if (!pixbuf)
- return;
-
- const gint pix_width = gdk_pixbuf_get_n_channels(pixbuf);
- const gint w = gdk_pixbuf_get_width(pixbuf);
- const gint h = gdk_pixbuf_get_height(pixbuf);
- for(y = 0; y < h; y++)
- {
- guchar *i = GET_PIXBUF_PIXEL(pixbuf, 0, y);
-
- for(x = 0; x < w ; x++)
- {
- guchar r = i[R];
- guchar g = i[G];
- guchar b = i[B];
- guchar luma = (guchar)((RLUMF * (int)r + GLUMF * (int)g
+ BLUMF * (int)b + HALFF) >> LUM_PRECISION);
- hist[luma]++;
- i += pix_width;
- }
- }
- g_object_unref(pixbuf);
- g_object_unref(response);
+ gint i;
+ for (i = 0; i < 256; i++)
+ curve->histogram_data[i] = input[i];
}
/**
@@ -258,6 +225,9 @@
g_return_if_fail (RS_IS_FILTER(input));
curve->input = input;
+ if (curve->input)
+ rs_filter_set_recursive(RS_FILTER(input), "read-out-curve",
curve, NULL);
+
curve->display_color_space = display_color_space;
}
@@ -272,7 +242,17 @@
{
g_assert(RS_IS_CURVE_WIDGET(curve));
- calculate_histogram(curve);
+ if (curve->input)
+ {
+ RSFilterRequest *request = rs_filter_request_new();
+ rs_filter_request_set_quick(RS_FILTER_REQUEST(request), TRUE);
+ rs_filter_param_set_object(RS_FILTER_PARAM(request),
"colorspace", curve->display_color_space);
+ rs_filter_set_recursive(RS_FILTER(curve->input),
"read-out-curve", curve, NULL);
+ RSFilterResponse *response = rs_filter_get_image8(curve->input,
request);
+ g_object_unref(request);
+ g_object_unref(response);
+ }
+
if (curve->bg_buffer)
g_free(curve->bg_buffer);
curve->bg_buffer = NULL;
@@ -316,6 +296,8 @@
g_object_unref(curve->spline);
}
g_object_unref(curve->help_layout);
+ if (curve->input)
+ rs_filter_set_recursive(RS_FILTER(curve->input),
"read-out-curve", NULL, NULL);
}
/**
@@ -570,41 +552,9 @@
/* Red */
static const GdkColor red = {0, 0xffff, 0x0000, 0x0000};
-static void
-rs_curve_draw_marker(GtkWidget *widget)
-{
- RSCurveWidget *curve;
+/* Light Red */
+static const GdkColor light_red = {0, 0xf000, 0x9000, 0x9000};
- /* Get back our curve widget */
- curve = RS_CURVE_WIDGET(widget);
-
- /* Draw marker if needed */
- if (curve->marker > 0.0)
- {
- /* Get the drawing window */
- GdkDrawable *window = GDK_DRAWABLE(widget->window);
-
- if (!window) return;
-
- /* Graphics context and color */
- GdkGC *gc = gdk_gc_new(window);
- gdk_gc_set_rgb_fg_color(gc, &red);
-
- /* Width and height */
- gint width;
- gint height;
-
- /* Where to draw the lines */
- gint line;
-
- /* Width and height */
- gdk_drawable_get_size(window, &width, &height);
-
- line = (gint) (((gfloat)width) * curve->marker);
- gdk_draw_line(window, gc, line, 0, line, height);
- }
-}
-
static void
rs_curve_draw_background(GtkWidget *widget)
{
@@ -799,14 +749,18 @@
}
/* Draw current luminance */
- gfloat lum = 0.212671f * curve->rgb_values[0] + 0.715160f *
curve->rgb_values[1] + 0.072169f * curve->rgb_values[2];
- gint current = (int)(lum*width);
+ gfloat marker = rs_curve_widget_get_marker(curve);
+ gint current = (int)(marker*(height-1));
- if (current >=0 && current < width)
+ if (current >=0 && current < height)
{
- gdk_gc_set_rgb_fg_color(gc, &red);
- gint y = (gint)(height*(1-samples[current])+0.5);
- gdk_draw_rectangle(window, gc, FALSE, current-3, y-3, 6, 6);
+ gdk_gc_set_rgb_fg_color(gc, &light_red);
+ gint x = 0;
+ while (samples[x] < marker)
+ x++;
+ current = height - current;
+ gdk_draw_line(window, gc, x, current, width, current);
+ gdk_draw_line(window, gc, x, current, x, height);
}
g_free(samples);
@@ -828,9 +782,6 @@
/* Draw the background */
rs_curve_draw_background(widget);
- /* Draw the marker line */
- rs_curve_draw_marker(widget);
-
/* Draw the control points */
rs_curve_draw_knots(widget);
@@ -904,10 +855,15 @@
g_return_val_if_fail(RS_IS_CURVE_WIDGET (widget), FALSE);
g_return_val_if_fail(event != NULL, FALSE);
+ RSCurveWidget *curve = RS_CURVE_WIDGET(widget);
+
/* Do nothing if there's more expose events */
if (event->count > 0)
return FALSE;
+ if (curve->input)
+ rs_filter_set_recursive(RS_FILTER(curve->input),
"read-out-curve", curve, NULL);
+
rs_curve_draw(RS_CURVE_WIDGET(widget));
return FALSE;
Modified: trunk/librawstudio/rs-curve.h
===================================================================
--- trunk/librawstudio/rs-curve.h 2010-10-31 15:15:37 UTC (rev 3599)
+++ trunk/librawstudio/rs-curve.h 2010-10-31 15:27:38 UTC (rev 3600)
@@ -38,14 +38,6 @@
rs_curve_widget_new(void);
/**
- * Sets a position to be marked in the curve widget
- * @param curve A RSCurveWidget
- * @param position The position to mark in the range 0.0-1.0 (-1.0 to hide)
- */
-extern void
-rs_curve_widget_set_marker(RSCurveWidget *curve, gfloat position);
-
-/**
* Sets sample array for a RSCurveWidget, this array will be updates whenever
the curve changes
* @param curve A RSCurveWidget
* @param array An array of gfloats to be updated or NULL to unset
@@ -136,7 +128,7 @@
rs_curve_widget_load(RSCurveWidget *curve, const gchar *filename);
/**
- * Set an image to base the histogram of
+ * Set the input to base the histogram drawing from
* @param curve A RSCurveWidget
* @param image An image
* @param display_color_space Colorspace to use to transform the input.
@@ -144,9 +136,22 @@
extern void
rs_curve_set_input(RSCurveWidget *curve, RSFilter* input, RSColorSpace
*display_color_space);
+/**
+ * Sets the current RGB data to be marked in histogram view based on currently
set colorspace
+ * @param curve A RSCurveWidget
+ * @param rgb_values An array of length 3, that contain the current RGB value.
Pass NULL to disable view.
+ */
extern void
rs_curve_set_highlight(RSCurveWidget *curve, const guchar* rgb_values);
+/**
+ * Sets the current histogram data
+ * @param curve A RSCurveWidget
+ * @param input An array of 256 entries containing the current histogram
+ */
+extern void
+rs_curve_set_histogram_data(RSCurveWidget *curve, const gint *input);
+
#define RS_CURVE_TYPE_WIDGET (rs_curve_widget_get_type ())
#define RS_CURVE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
RS_CURVE_TYPE_WIDGET, RSCurveWidget))
#define RS_CURVE_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj),
RS_CURVE_WIDGET, RSCurveWidgetClass))
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit