mirror of https://github.com/GNOME/gimp.git
changed all values to be [0.0..1.0] doubles instead of [0..255] integers.
2008-02-09 Michael Natterer <mitch@gimp.org> * app/core/gimpcurve.[ch]: changed all values to be [0.0..1.0] doubles instead of [0..255] integers. Also changed the API to use doubles instead of ints. Still have the fixed-size arrays though. (gimp_curve_map): new function to map values. * app/gegl/gimpoperationcurves.c: remove private map() function and use the one from GimpCurve. * app/gegl/gimpcurvesconfig.c * app/core/gimpdrawable-curves.c: port to the new gdouble API. * app/tools/gimpcurvestool.c: use gimp_curve_get_uchar() to get the arrays for the color bars. * app/widgets/gimpcurveview.[ch]: port to gdouble and some cleanup. svn path=/trunk/; revision=24837
This commit is contained in:
parent
67854fce82
commit
044359f93d
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2008-02-09 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimpcurve.[ch]: changed all values to be [0.0..1.0]
|
||||
doubles instead of [0..255] integers. Also changed the API to use
|
||||
doubles instead of ints. Still have the fixed-size arrays though.
|
||||
|
||||
(gimp_curve_map): new function to map values.
|
||||
|
||||
* app/gegl/gimpoperationcurves.c: remove private map() function
|
||||
and use the one from GimpCurve.
|
||||
|
||||
* app/gegl/gimpcurvesconfig.c
|
||||
* app/core/gimpdrawable-curves.c: port to the new gdouble API.
|
||||
|
||||
* app/tools/gimpcurvestool.c: use gimp_curve_get_uchar() to get
|
||||
the arrays for the color bars.
|
||||
|
||||
* app/widgets/gimpcurveview.[ch]: port to gdouble and some cleanup.
|
||||
|
||||
2008-02-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/widgets/gimptexteditor.c: use an entry with completion for
|
||||
|
|
|
@ -331,18 +331,18 @@ gimp_curve_reset (GimpCurve *curve,
|
|||
curve->curve_type = GIMP_CURVE_SMOOTH;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
curve->curve[i] = i;
|
||||
curve->curve[i] = (gdouble) i / 255.0;
|
||||
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
{
|
||||
curve->points[i][0] = -1;
|
||||
curve->points[i][1] = -1;
|
||||
curve->points[i][0] = -1.0;
|
||||
curve->points[i][1] = -1.0;
|
||||
}
|
||||
|
||||
curve->points[0][0] = 0;
|
||||
curve->points[0][1] = 0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][0] = 255;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][1] = 255;
|
||||
curve->points[0][0] = 0.0;
|
||||
curve->points[0][1] = 0.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][0] = 1.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][1] = 1.0;
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (curve));
|
||||
|
||||
|
@ -371,17 +371,16 @@ gimp_curve_set_curve_type (GimpCurve *curve,
|
|||
|
||||
if (curve_type == GIMP_CURVE_SMOOTH)
|
||||
{
|
||||
gint i;
|
||||
gint32 index;
|
||||
gint i;
|
||||
|
||||
/* pick representative points from the curve and make them
|
||||
* control points
|
||||
*/
|
||||
for (i = 0; i <= 8; i++)
|
||||
{
|
||||
index = CLAMP0255 (i * 32);
|
||||
gint32 index = CLAMP0255 (i * 32);
|
||||
|
||||
curve->points[i * 2][0] = index;
|
||||
curve->points[i * 2][0] = (gdouble) index / 255.0;
|
||||
curve->points[i * 2][1] = curve->curve[index];
|
||||
}
|
||||
|
||||
|
@ -404,30 +403,30 @@ gimp_curve_get_curve_type (GimpCurve *curve)
|
|||
return curve->curve_type;
|
||||
}
|
||||
|
||||
#define MIN_DISTANCE 8
|
||||
#define MIN_DISTANCE (8.0 / 255.0)
|
||||
|
||||
gint
|
||||
gimp_curve_get_closest_point (GimpCurve *curve,
|
||||
gint x)
|
||||
gdouble x)
|
||||
{
|
||||
gint closest_point = 0;
|
||||
gint distance = G_MAXINT;
|
||||
gint i;
|
||||
gint closest_point = 0;
|
||||
gdouble distance = G_MAXDOUBLE;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CURVE (curve), 0);
|
||||
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
{
|
||||
if (curve->points[i][0] != -1)
|
||||
if (abs (x - curve->points[i][0]) < distance)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (fabs (x - curve->points[i][0]) < distance)
|
||||
{
|
||||
distance = abs (x - curve->points[i][0]);
|
||||
distance = fabs (x - curve->points[i][0]);
|
||||
closest_point = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (distance > MIN_DISTANCE)
|
||||
closest_point = (x + 8) / 16;
|
||||
closest_point = ((gint) (x * 255.999) + 8) / 16;
|
||||
|
||||
return closest_point;
|
||||
}
|
||||
|
@ -435,8 +434,8 @@ gimp_curve_get_closest_point (GimpCurve *curve,
|
|||
void
|
||||
gimp_curve_set_point (GimpCurve *curve,
|
||||
gint point,
|
||||
gint x,
|
||||
gint y)
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve));
|
||||
|
||||
|
@ -458,7 +457,7 @@ gimp_curve_set_point (GimpCurve *curve,
|
|||
void
|
||||
gimp_curve_move_point (GimpCurve *curve,
|
||||
gint point,
|
||||
gint y)
|
||||
gdouble y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve));
|
||||
|
||||
|
@ -478,8 +477,8 @@ gimp_curve_move_point (GimpCurve *curve,
|
|||
|
||||
void
|
||||
gimp_curve_set_curve (GimpCurve *curve,
|
||||
gint x,
|
||||
gint y)
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve));
|
||||
|
||||
|
@ -488,7 +487,7 @@ gimp_curve_set_curve (GimpCurve *curve,
|
|||
|
||||
g_object_freeze_notify (G_OBJECT (curve));
|
||||
|
||||
curve->curve[x] = y;
|
||||
curve->curve[(gint) (x * 255.999)] = y;
|
||||
|
||||
g_object_notify (G_OBJECT (curve), "curve");
|
||||
|
||||
|
@ -497,14 +496,45 @@ gimp_curve_set_curve (GimpCurve *curve,
|
|||
gimp_data_dirty (GIMP_DATA (curve));
|
||||
}
|
||||
|
||||
gdouble
|
||||
gimp_curve_map (GimpCurve *curve,
|
||||
gdouble x)
|
||||
{
|
||||
gdouble value;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CURVE (curve), 0.0);
|
||||
|
||||
if (x < 0.0)
|
||||
{
|
||||
value = curve->curve[0];
|
||||
}
|
||||
else if (x >= 1.0)
|
||||
{
|
||||
value = curve->curve[255];
|
||||
}
|
||||
else /* interpolate the curve */
|
||||
{
|
||||
gint index = floor (x * 255.0);
|
||||
gdouble f = x * 255.0 - index;
|
||||
|
||||
value = ((1.0 - f) * curve->curve[index ] +
|
||||
f * curve->curve[index + 1]);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_curve_get_uchar (GimpCurve *curve,
|
||||
guchar *dest_array)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CURVE (curve));
|
||||
g_return_if_fail (dest_array != NULL);
|
||||
|
||||
memcpy (dest_array, curve->curve, 256);
|
||||
for (i = 0; i < 256; i++)
|
||||
dest_array[i] = curve->curve[i] * 255.999;
|
||||
}
|
||||
|
||||
|
||||
|
@ -527,16 +557,16 @@ gimp_curve_calculate (GimpCurve *curve)
|
|||
/* cycle through the curves */
|
||||
num_pts = 0;
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
if (curve->points[i][0] != -1)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
points[num_pts++] = i;
|
||||
|
||||
/* Initialize boundary curve points */
|
||||
if (num_pts != 0)
|
||||
{
|
||||
for (i = 0; i < curve->points[points[0]][0]; i++)
|
||||
for (i = 0; i < (gint) (curve->points[points[0]][0] * 255.999); i++)
|
||||
curve->curve[i] = curve->points[points[0]][1];
|
||||
|
||||
for (i = curve->points[points[num_pts - 1]][0]; i < 256; i++)
|
||||
for (i = (gint) (curve->points[points[num_pts - 1]][0] * 255.999); i < 256; i++)
|
||||
curve->curve[i] = curve->points[points[num_pts - 1]][1];
|
||||
}
|
||||
|
||||
|
@ -553,10 +583,10 @@ gimp_curve_calculate (GimpCurve *curve)
|
|||
/* ensure that the control points are used exactly */
|
||||
for (i = 0; i < num_pts; i++)
|
||||
{
|
||||
gint x = curve->points[points[i]][0];
|
||||
gint y = curve->points[points[i]][1];
|
||||
gdouble x = curve->points[points[i]][0];
|
||||
gdouble y = curve->points[points[i]][1];
|
||||
|
||||
curve->curve[x] = y;
|
||||
curve->curve[(gint) (x * 255.999)] = y;
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (curve), "curve");
|
||||
|
@ -661,14 +691,14 @@ gimp_curve_plot (GimpCurve *curve,
|
|||
* finally calculate the y(t) values for the given bezier values. We can
|
||||
* use homogenously distributed values for t, since x(t) increases linearily.
|
||||
*/
|
||||
for (i = 0; i <= dx; i++)
|
||||
for (i = 0; i <= (gint) (dx * 255.999); i++)
|
||||
{
|
||||
t = i / dx;
|
||||
t = i / dx / 255.0;
|
||||
y = y0 * (1-t) * (1-t) * (1-t) +
|
||||
3 * y1 * (1-t) * (1-t) * t +
|
||||
3 * y2 * (1-t) * t * t +
|
||||
y3 * t * t * t;
|
||||
|
||||
curve->curve[ROUND(x0) + i] = CLAMP0255 (ROUND (y));
|
||||
curve->curve[(gint) (x0 * 255.999) + i] = CLAMP (y, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ struct _GimpCurve
|
|||
|
||||
GimpCurveType curve_type;
|
||||
|
||||
gint points[GIMP_CURVE_NUM_POINTS][2];
|
||||
guchar curve[256];
|
||||
gdouble points[GIMP_CURVE_NUM_POINTS][2];
|
||||
gdouble curve[256];
|
||||
};
|
||||
|
||||
struct _GimpCurveClass
|
||||
|
@ -65,18 +65,21 @@ void gimp_curve_set_curve_type (GimpCurve *curve,
|
|||
GimpCurveType gimp_curve_get_curve_type (GimpCurve *curve);
|
||||
|
||||
gint gimp_curve_get_closest_point (GimpCurve *curve,
|
||||
gint x);
|
||||
gdouble x);
|
||||
void gimp_curve_set_point (GimpCurve *curve,
|
||||
gint point,
|
||||
gint x,
|
||||
gint y);
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
void gimp_curve_move_point (GimpCurve *curve,
|
||||
gint point,
|
||||
gint y);
|
||||
gdouble y);
|
||||
|
||||
void gimp_curve_set_curve (GimpCurve *curve,
|
||||
gint x,
|
||||
gint y);
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
|
||||
gdouble gimp_curve_map (GimpCurve *curve,
|
||||
gdouble x);
|
||||
|
||||
void gimp_curve_get_uchar (GimpCurve *curve,
|
||||
guchar *dest_array);
|
||||
|
|
|
@ -128,7 +128,9 @@ gimp_drawable_curves_explicit (GimpDrawable *drawable,
|
|||
gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
gimp_curve_set_curve (curve, i, points[i]);
|
||||
gimp_curve_set_curve (curve,
|
||||
(gdouble) i / 255.0,
|
||||
(gdouble) points[i] / 255.0);
|
||||
|
||||
gimp_data_thaw (GIMP_DATA (curve));
|
||||
|
||||
|
|
|
@ -373,7 +373,9 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config,
|
|||
gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH);
|
||||
|
||||
for (j = 0; j < GIMP_CURVE_NUM_POINTS; j++)
|
||||
gimp_curve_set_point (curve, j, index[i][j], value[i][j]);
|
||||
gimp_curve_set_point (curve, j,
|
||||
(gdouble) index[i][j] / 255.0,
|
||||
(gdouble) value[i][j] / 255.0);
|
||||
|
||||
gimp_data_thaw (GIMP_DATA (curve));
|
||||
}
|
||||
|
@ -387,9 +389,8 @@ gboolean
|
|||
gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
||||
gpointer fp)
|
||||
{
|
||||
FILE *file = fp;
|
||||
gint i, j;
|
||||
gint32 index;
|
||||
FILE *file = fp;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE);
|
||||
g_return_val_if_fail (file != NULL, FALSE);
|
||||
|
@ -399,6 +400,7 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
GimpCurve *curve = config->curve[i];
|
||||
gint j;
|
||||
|
||||
if (curve->curve_type == GIMP_CURVE_FREE)
|
||||
{
|
||||
|
@ -407,17 +409,17 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||
*/
|
||||
for (j = 0; j <= 8; j++)
|
||||
{
|
||||
index = CLAMP0255 (j * 32);
|
||||
gint32 index = CLAMP0255 (j * 32);
|
||||
|
||||
curve->points[j * 2][0] = index;
|
||||
curve->points[j * 2][0] = (gdouble) index / 255.0;
|
||||
curve->points[j * 2][1] = curve->curve[index];
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < GIMP_CURVE_NUM_POINTS; j++)
|
||||
fprintf (file, "%d %d ",
|
||||
curve->points[j][0],
|
||||
curve->points[j][1]);
|
||||
(gint) (curve->points[j][0] * 255.999),
|
||||
(gint) (curve->points[j][1] * 255.999));
|
||||
|
||||
fprintf (file, "\n");
|
||||
}
|
||||
|
@ -442,11 +444,13 @@ gimp_curves_config_to_cruft (GimpCurvesConfig *config,
|
|||
channel <= GIMP_HISTOGRAM_ALPHA;
|
||||
channel++)
|
||||
{
|
||||
gimp_curve_get_uchar (config->curve[channel], cruft->curve[channel]);
|
||||
gimp_curve_get_uchar (config->curve[channel],
|
||||
cruft->curve[channel]);
|
||||
}
|
||||
|
||||
if (! is_color)
|
||||
{
|
||||
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_ALPHA], cruft->curve[1]);
|
||||
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_ALPHA],
|
||||
cruft->curve[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,30 +75,6 @@ gimp_operation_curves_init (GimpOperationCurves *self)
|
|||
{
|
||||
}
|
||||
|
||||
static inline gdouble
|
||||
gimp_operation_curves_map (gdouble value,
|
||||
GimpCurve *curve)
|
||||
{
|
||||
if (value < 0.0)
|
||||
{
|
||||
value = curve->curve[0] / 255.0;
|
||||
}
|
||||
else if (value >= 1.0)
|
||||
{
|
||||
value = curve->curve[255] / 255.0;
|
||||
}
|
||||
else /* interpolate the curve */
|
||||
{
|
||||
gint index = floor (value * 255.0);
|
||||
gdouble f = value * 255.0 - index;
|
||||
|
||||
value = ((1.0 - f) * curve->curve[index ] +
|
||||
f * curve->curve[index + 1] ) / 255.0;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_operation_curves_process (GeglOperation *operation,
|
||||
void *in_buf,
|
||||
|
@ -121,13 +97,11 @@ gimp_operation_curves_process (GeglOperation *operation,
|
|||
{
|
||||
gdouble value;
|
||||
|
||||
value = gimp_operation_curves_map (src[channel],
|
||||
config->curve[channel + 1]);
|
||||
value = gimp_curve_map (config->curve[channel + 1], src[channel]);
|
||||
|
||||
/* don't apply the overall curve to the alpha channel */
|
||||
if (channel != ALPHA_PIX)
|
||||
value = gimp_operation_curves_map (value,
|
||||
config->curve[0]);
|
||||
value = gimp_curve_map (config->curve[0], value);
|
||||
|
||||
dest[channel] = value;
|
||||
}
|
||||
|
|
|
@ -641,22 +641,28 @@ gimp_curves_tool_config_notify (GObject *object,
|
|||
|
||||
switch (config->channel)
|
||||
{
|
||||
guchar r[256];
|
||||
guchar g[256];
|
||||
guchar b[256];
|
||||
|
||||
case GIMP_HISTOGRAM_VALUE:
|
||||
case GIMP_HISTOGRAM_ALPHA:
|
||||
case GIMP_HISTOGRAM_RGB:
|
||||
gimp_curve_get_uchar (curve, r);
|
||||
|
||||
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
|
||||
curve->curve,
|
||||
curve->curve,
|
||||
curve->curve);
|
||||
r, r, r);
|
||||
break;
|
||||
|
||||
case GIMP_HISTOGRAM_RED:
|
||||
case GIMP_HISTOGRAM_GREEN:
|
||||
case GIMP_HISTOGRAM_BLUE:
|
||||
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_RED], r);
|
||||
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_GREEN], g);
|
||||
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_BLUE], b);
|
||||
|
||||
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
|
||||
config->curve[GIMP_HISTOGRAM_RED]->curve,
|
||||
config->curve[GIMP_HISTOGRAM_GREEN]->curve,
|
||||
config->curve[GIMP_HISTOGRAM_BLUE]->curve);
|
||||
r, g, b);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@ static gboolean gimp_curve_view_leave_notify (GtkWidget *widget,
|
|||
static gboolean gimp_curve_view_key_press (GtkWidget *widget,
|
||||
GdkEventKey *kevent);
|
||||
|
||||
static void gimp_curve_view_set_cursor (GimpCurveView *view,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
static void gimp_curve_view_unset_cursor (GimpCurveView *view);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpCurveView, gimp_curve_view,
|
||||
GIMP_TYPE_HISTOGRAM_VIEW)
|
||||
|
@ -117,7 +122,8 @@ gimp_curve_view_init (GimpCurveView *view)
|
|||
{
|
||||
view->curve = NULL;
|
||||
view->selected = 0;
|
||||
view->last = 0;
|
||||
view->last_x = 0.0;
|
||||
view->last_y = 0.0;
|
||||
view->cursor_type = -1;
|
||||
view->xpos = -1;
|
||||
view->cursor_x = -1;
|
||||
|
@ -307,20 +313,20 @@ gimp_curve_view_draw_point (GimpCurveView *view,
|
|||
gint height,
|
||||
gint border)
|
||||
{
|
||||
gint x, y;
|
||||
gdouble x, y;
|
||||
|
||||
x = view->curve->points[i][0];
|
||||
if (x < 0)
|
||||
if (x < 0.0)
|
||||
return;
|
||||
|
||||
y = 255 - view->curve->points[i][1];
|
||||
y = 1.0 - view->curve->points[i][1];
|
||||
|
||||
cairo_move_to (cr,
|
||||
border + (gdouble) width * x / 256.0,
|
||||
border + (gdouble) height * y / 256.0);
|
||||
border + (gdouble) width * x,
|
||||
border + (gdouble) height * y);
|
||||
cairo_arc (cr,
|
||||
border + (gdouble) width * x / 256.0,
|
||||
border + (gdouble) height * y / 256.0,
|
||||
border + (gdouble) width * x,
|
||||
border + (gdouble) height * y,
|
||||
3,
|
||||
0, 2 * G_PI);
|
||||
}
|
||||
|
@ -335,7 +341,7 @@ gimp_curve_view_expose (GtkWidget *widget,
|
|||
gint border;
|
||||
gint width;
|
||||
gint height;
|
||||
gint x, y;
|
||||
gdouble x, y;
|
||||
gint i;
|
||||
|
||||
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
|
||||
|
@ -361,26 +367,26 @@ gimp_curve_view_expose (GtkWidget *widget,
|
|||
/* Draw the curve */
|
||||
gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
|
||||
|
||||
x = 0;
|
||||
y = 255 - view->curve->curve[x];
|
||||
x = 0.0;
|
||||
y = 1.0 - gimp_curve_map (view->curve, 0.0);
|
||||
|
||||
cairo_move_to (cr,
|
||||
border + (gdouble) width * x / 256.0,
|
||||
border + (gdouble) height * y / 256.0);
|
||||
border + (gdouble) width * x,
|
||||
border + (gdouble) height * y);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 1; i < 256; i++)
|
||||
{
|
||||
x = i;
|
||||
y = 255 - view->curve->curve[x];
|
||||
x = (gdouble) i / 255.0;
|
||||
y = 1.0 - gimp_curve_map (view->curve, x);
|
||||
|
||||
cairo_line_to (cr,
|
||||
border + (gdouble) width * x / 256.0,
|
||||
border + (gdouble) height * y / 256.0);
|
||||
border + (gdouble) width * x,
|
||||
border + (gdouble) height * y);
|
||||
}
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
if (view->curve->curve_type == GIMP_CURVE_SMOOTH)
|
||||
if (gimp_curve_get_curve_type (view->curve) == GIMP_CURVE_SMOOTH)
|
||||
{
|
||||
gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
|
||||
|
||||
|
@ -406,6 +412,8 @@ gimp_curve_view_expose (GtkWidget *widget,
|
|||
|
||||
if (view->xpos >= 0)
|
||||
{
|
||||
gint layout_x;
|
||||
gint layout_y;
|
||||
gchar buf[32];
|
||||
|
||||
gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
|
||||
|
@ -426,16 +434,16 @@ gimp_curve_view_expose (GtkWidget *widget,
|
|||
view->xpos_layout = gtk_widget_create_pango_layout (widget, NULL);
|
||||
|
||||
pango_layout_set_text (view->xpos_layout, buf, -1);
|
||||
pango_layout_get_pixel_size (view->xpos_layout, &x, &y);
|
||||
pango_layout_get_pixel_size (view->xpos_layout, &layout_x, &layout_y);
|
||||
|
||||
if (view->xpos < 127)
|
||||
x = border;
|
||||
layout_x = border;
|
||||
else
|
||||
x = -(x + border);
|
||||
layout_x = -(layout_x + border);
|
||||
|
||||
cairo_move_to (cr,
|
||||
border + (gdouble) width * view->xpos / 256.0 + x,
|
||||
border + height - border - y);
|
||||
border + (gdouble) width * view->xpos / 256.0 + layout_x,
|
||||
border + height - border - layout_y);
|
||||
pango_cairo_show_layout (cr, view->xpos_layout);
|
||||
cairo_fill (cr);
|
||||
}
|
||||
|
@ -512,7 +520,8 @@ gimp_curve_view_button_press (GtkWidget *widget,
|
|||
GimpCurve *curve = view->curve;
|
||||
gint border;
|
||||
gint width, height;
|
||||
gint x, y;
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gint closest_point;
|
||||
gint i;
|
||||
|
||||
|
@ -523,11 +532,11 @@ gimp_curve_view_button_press (GtkWidget *widget,
|
|||
width = widget->allocation.width - 2 * border;
|
||||
height = widget->allocation.height - 2 * border;
|
||||
|
||||
x = ROUND (((gdouble) (bevent->x - border) / (gdouble) width) * 255.0);
|
||||
y = ROUND (((gdouble) (bevent->y - border) / (gdouble) height) * 255.0);
|
||||
x = (gdouble) (bevent->x - border) / (gdouble) width;
|
||||
y = (gdouble) (bevent->y - border) / (gdouble) height;
|
||||
|
||||
x = CLAMP0255 (x);
|
||||
y = CLAMP0255 (y);
|
||||
x = CLAMP (x, 0.0, 1.0);
|
||||
y = CLAMP (y, 0.0, 1.0);
|
||||
|
||||
closest_point = gimp_curve_get_closest_point (curve, x);
|
||||
|
||||
|
@ -535,21 +544,21 @@ gimp_curve_view_button_press (GtkWidget *widget,
|
|||
|
||||
set_cursor (view, GDK_TCROSS);
|
||||
|
||||
switch (curve->curve_type)
|
||||
switch (gimp_curve_get_curve_type (curve))
|
||||
{
|
||||
case GIMP_CURVE_SMOOTH:
|
||||
/* determine the leftmost and rightmost points */
|
||||
view->leftmost = -1;
|
||||
view->leftmost = -1.0;
|
||||
for (i = closest_point - 1; i >= 0; i--)
|
||||
if (curve->points[i][0] != -1)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
{
|
||||
view->leftmost = curve->points[i][0];
|
||||
break;
|
||||
}
|
||||
|
||||
view->rightmost = 256;
|
||||
view->rightmost = 2.0;
|
||||
for (i = closest_point + 1; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
if (curve->points[i][0] != -1)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
{
|
||||
view->rightmost = curve->points[i][0];
|
||||
break;
|
||||
|
@ -557,14 +566,14 @@ gimp_curve_view_button_press (GtkWidget *widget,
|
|||
|
||||
gimp_curve_view_set_selected (view, closest_point);
|
||||
|
||||
gimp_curve_set_point (curve, view->selected, x, 255 - y);
|
||||
gimp_curve_set_point (curve, view->selected, x, 1.0 - y);
|
||||
break;
|
||||
|
||||
case GIMP_CURVE_FREE:
|
||||
gimp_curve_view_set_selected (view, x);
|
||||
view->last = y;
|
||||
view->last_x = x;
|
||||
view->last_y = y;
|
||||
|
||||
gimp_curve_set_curve (curve, x, 255 - y);
|
||||
gimp_curve_set_curve (curve, x, 1.0 - y);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -599,9 +608,9 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
|||
GimpCursorType new_cursor = GDK_X_CURSOR;
|
||||
gint border;
|
||||
gint width, height;
|
||||
gint x, y;
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gint closest_point;
|
||||
gint i;
|
||||
|
||||
if (! curve)
|
||||
return TRUE;
|
||||
|
@ -610,20 +619,20 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
|||
width = widget->allocation.width - 2 * border;
|
||||
height = widget->allocation.height - 2 * border;
|
||||
|
||||
x = ROUND (((gdouble) (mevent->x - border) / (gdouble) width) * 255.0);
|
||||
y = ROUND (((gdouble) (mevent->y - border) / (gdouble) height) * 255.0);
|
||||
x = (gdouble) (mevent->x - border) / (gdouble) width;
|
||||
y = (gdouble) (mevent->y - border) / (gdouble) height;
|
||||
|
||||
x = CLAMP0255 (x);
|
||||
y = CLAMP0255 (y);
|
||||
x = CLAMP (x, 0.0, 1.0);
|
||||
y = CLAMP (y, 0.0, 1.0);
|
||||
|
||||
closest_point = gimp_curve_get_closest_point (curve, x);
|
||||
|
||||
switch (curve->curve_type)
|
||||
switch (gimp_curve_get_curve_type (curve))
|
||||
{
|
||||
case GIMP_CURVE_SMOOTH:
|
||||
if (! view->grabbed) /* If no point is grabbed... */
|
||||
{
|
||||
if (curve->points[closest_point][0] != -1)
|
||||
if (curve->points[closest_point][0] >= 0.0)
|
||||
new_cursor = GDK_FLEUR;
|
||||
else
|
||||
new_cursor = GDK_TCROSS;
|
||||
|
@ -634,15 +643,15 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
|||
|
||||
gimp_data_freeze (GIMP_DATA (curve));
|
||||
|
||||
gimp_curve_set_point (curve, view->selected, -1, -1);
|
||||
gimp_curve_set_point (curve, view->selected, -1.0, -1.0);
|
||||
|
||||
if (x > view->leftmost && x < view->rightmost)
|
||||
{
|
||||
closest_point = (x + 8) / 16;
|
||||
if (curve->points[closest_point][0] == -1)
|
||||
closest_point = ((gint) (x * 255.999) + 8) / 16;
|
||||
if (curve->points[closest_point][0] < 0.0)
|
||||
gimp_curve_view_set_selected (view, closest_point);
|
||||
|
||||
gimp_curve_set_point (curve, view->selected, x, 255 - y);
|
||||
gimp_curve_set_point (curve, view->selected, x, 1.0 - y);
|
||||
}
|
||||
|
||||
gimp_data_thaw (GIMP_DATA (curve));
|
||||
|
@ -652,40 +661,44 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
|||
case GIMP_CURVE_FREE:
|
||||
if (view->grabbed)
|
||||
{
|
||||
gint x1, x2, y1, y2;
|
||||
gdouble x1, x2;
|
||||
gdouble y1, y2;
|
||||
|
||||
if (view->selected > x)
|
||||
if (view->last_x > x)
|
||||
{
|
||||
x1 = x;
|
||||
x2 = view->selected;
|
||||
x2 = view->last_x;
|
||||
y1 = y;
|
||||
y2 = view->last;
|
||||
y2 = view->last_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = view->selected;
|
||||
x1 = view->last_x;
|
||||
x2 = x;
|
||||
y1 = view->last;
|
||||
y1 = view->last_y;
|
||||
y2 = y;
|
||||
}
|
||||
|
||||
if (x2 != x1)
|
||||
{
|
||||
gint i;
|
||||
|
||||
gimp_data_freeze (GIMP_DATA (curve));
|
||||
|
||||
for (i = x1; i <= x2; i++)
|
||||
gimp_curve_set_curve (curve, i,
|
||||
255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1)));
|
||||
for (i = (gint) (x1 * 255.999); i <= (gint) (x2 * 255.999); i++)
|
||||
gimp_curve_set_curve (curve,
|
||||
(gdouble) i / 255.0,
|
||||
1.0 - (y1 + ((y2 - y1) * ((gdouble) i / 255.0 - x1)) / (x2 - x1)));
|
||||
|
||||
gimp_data_thaw (GIMP_DATA (curve));
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_curve_set_curve (curve, x, 255 - y);
|
||||
gimp_curve_set_curve (curve, x, 1.0 - y);
|
||||
}
|
||||
|
||||
gimp_curve_view_set_selected (view, x);
|
||||
view->last = y;
|
||||
view->last_x = x;
|
||||
view->last_y = y;
|
||||
}
|
||||
|
||||
if (mevent->state & GDK_BUTTON1_MASK)
|
||||
|
@ -709,7 +722,7 @@ gimp_curve_view_leave_notify (GtkWidget *widget,
|
|||
{
|
||||
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
|
||||
|
||||
gimp_curve_view_set_cursor (view, -1, -1);
|
||||
gimp_curve_view_unset_cursor (view);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -721,10 +734,11 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
|||
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
|
||||
GimpCurve *curve = view->curve;
|
||||
gint i = view->selected;
|
||||
gint y = curve->points[i][1];
|
||||
gdouble y = curve->points[i][1];
|
||||
gboolean retval = FALSE;
|
||||
|
||||
if (view->grabbed || ! curve || curve->curve_type == GIMP_CURVE_FREE)
|
||||
if (view->grabbed || ! curve ||
|
||||
gimp_curve_get_curve_type (curve) == GIMP_CURVE_FREE)
|
||||
return FALSE;
|
||||
|
||||
switch (kevent->keyval)
|
||||
|
@ -732,7 +746,7 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
|||
case GDK_Left:
|
||||
for (i = i - 1; i >= 0 && ! retval; i--)
|
||||
{
|
||||
if (curve->points[i][0] != -1)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
{
|
||||
gimp_curve_view_set_selected (view, i);
|
||||
|
||||
|
@ -744,7 +758,7 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
|||
case GDK_Right:
|
||||
for (i = i + 1; i < GIMP_CURVE_NUM_POINTS && ! retval; i++)
|
||||
{
|
||||
if (curve->points[i][0] != -1)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
{
|
||||
gimp_curve_view_set_selected (view, i);
|
||||
|
||||
|
@ -754,11 +768,12 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
|||
break;
|
||||
|
||||
case GDK_Up:
|
||||
if (y < 255)
|
||||
if (y < 1.0)
|
||||
{
|
||||
y = y + (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
|
||||
y = y + (kevent->state & GDK_SHIFT_MASK ?
|
||||
(16.0 / 255.0) : (1.0 / 255.0));
|
||||
|
||||
gimp_curve_move_point (curve, i, CLAMP0255 (y));
|
||||
gimp_curve_move_point (curve, i, CLAMP (y, 0.0, 1.0));
|
||||
|
||||
retval = TRUE;
|
||||
}
|
||||
|
@ -767,9 +782,10 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
|||
case GDK_Down:
|
||||
if (y > 0)
|
||||
{
|
||||
y = y - (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
|
||||
y = y - (kevent->state & GDK_SHIFT_MASK ?
|
||||
(16.0 / 255.0) : (1.0 / 255.0));
|
||||
|
||||
gimp_curve_move_point (curve, i, CLAMP0255 (y));
|
||||
gimp_curve_move_point (curve, i, CLAMP (y, 0.0, 1.0));
|
||||
|
||||
retval = TRUE;
|
||||
}
|
||||
|
@ -857,15 +873,25 @@ gimp_curve_view_set_xpos (GimpCurveView *view,
|
|||
gtk_widget_queue_draw (GTK_WIDGET (view));
|
||||
}
|
||||
|
||||
void
|
||||
gimp_curve_view_set_cursor (GimpCurveView *view,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
|
||||
|
||||
view->cursor_x = x;
|
||||
view->cursor_y = y;
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_curve_view_set_cursor (GimpCurveView *view,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
view->cursor_x = x * 255.999;
|
||||
view->cursor_y = y * 255.999;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (view));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_curve_view_unset_cursor (GimpCurveView *view)
|
||||
{
|
||||
view->cursor_x = -1;
|
||||
view->cursor_y = -1;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (view));
|
||||
}
|
||||
|
|
|
@ -44,9 +44,10 @@ struct _GimpCurveView
|
|||
gint grid_columns;
|
||||
|
||||
gint selected;
|
||||
gint last;
|
||||
gint leftmost;
|
||||
gint rightmost;
|
||||
gdouble last_x;
|
||||
gdouble last_y;
|
||||
gdouble leftmost;
|
||||
gdouble rightmost;
|
||||
gboolean grabbed;
|
||||
|
||||
GdkCursorType cursor_type;
|
||||
|
@ -78,9 +79,6 @@ void gimp_curve_view_set_selected (GimpCurveView *view,
|
|||
gint selected);
|
||||
void gimp_curve_view_set_xpos (GimpCurveView *view,
|
||||
gint x);
|
||||
void gimp_curve_view_set_cursor (GimpCurveView *view,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
|
||||
#endif /* __GIMP_CURVE_VIEW_H__ */
|
||||
|
|
Loading…
Reference in New Issue