From 36d5c586b170deaed4af895aff4a445c9c82e940 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 7 Sep 2012 01:02:10 +0100 Subject: [PATCH] controller: fix direct control binding double -> int conversion Round properly to nearest integer. Fixes controller unit test on PowerPC G4. --- libs/gst/controller/gstdirectcontrolbinding.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/gst/controller/gstdirectcontrolbinding.c b/libs/gst/controller/gstdirectcontrolbinding.c index bc85d93..8cfd027 100644 --- a/libs/gst/controller/gstdirectcontrolbinding.c +++ b/libs/gst/controller/gstdirectcontrolbinding.c @@ -76,7 +76,7 @@ static GParamSpec *properties[PROP_LAST]; /* mapping functions */ -#define DEFINE_CONVERT(type,Type,TYPE) \ +#define DEFINE_CONVERT(type,Type,TYPE,ROUNDING_OP) \ static void \ convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) \ { \ @@ -84,7 +84,7 @@ convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) g##type v; \ \ s = CLAMP (s, 0.0, 1.0); \ - v = pspec->minimum + (g##type) ((pspec->maximum - pspec->minimum) * s); \ + v = pspec->minimum + (g##type) ROUNDING_OP ((pspec->maximum - pspec->minimum) * s); \ g_value_set_##type (d, v); \ } \ \ @@ -95,18 +95,18 @@ convert_value_to_##type (GstDirectControlBinding *self, gdouble s, gpointer d_) g##type *d = (g##type *)d_; \ \ s = CLAMP (s, 0.0, 1.0); \ - *d = pspec->minimum + (g##type) ((pspec->maximum - pspec->minimum) * s); \ + *d = pspec->minimum + (g##type) ROUNDING_OP ((pspec->maximum - pspec->minimum) * s); \ } -DEFINE_CONVERT (int, Int, INT); -DEFINE_CONVERT (uint, UInt, UINT); -DEFINE_CONVERT (long, Long, LONG); -DEFINE_CONVERT (ulong, ULong, ULONG); -DEFINE_CONVERT (int64, Int64, INT64); -DEFINE_CONVERT (uint64, UInt64, UINT64); -DEFINE_CONVERT (float, Float, FLOAT); -DEFINE_CONVERT (double, Double, DOUBLE); +DEFINE_CONVERT (int, Int, INT, rint); +DEFINE_CONVERT (uint, UInt, UINT, rint); +DEFINE_CONVERT (long, Long, LONG, rint); +DEFINE_CONVERT (ulong, ULong, ULONG, rint); +DEFINE_CONVERT (int64, Int64, INT64, rint); +DEFINE_CONVERT (uint64, UInt64, UINT64, rint); +DEFINE_CONVERT (float, Float, FLOAT, /*NOOP*/); +DEFINE_CONVERT (double, Double, DOUBLE, /*NOOP*/); static void convert_g_value_to_boolean (GstDirectControlBinding * self, gdouble s, -- 2.7.4