From e87f6dcc141b9dc5217753d4a85a45a1337e01e9 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 21 Mar 2005 21:51:29 +0000 Subject: [PATCH] changed time-smoother code to use guint32 time values externally, guint64 2005-03-21 Sven Neumann * app/paint/gimpink.c: changed time-smoother code to use guint32 time values externally, guint64 internally. Proper fix for bug #164272. --- ChangeLog | 6 +++ app/paint/gimpink.c | 103 ++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f5cc51017..302ff7a788 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-03-21 Sven Neumann + + * app/paint/gimpink.c: changed time-smoother code to use guint32 + time values externally, guint64 internally. Proper fix for bug + #164272. + 2005-03-21 Sven Neumann * app/actions/dialogs-actions.h: bail out if diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c index 02b384933a..fde98b5064 100644 --- a/app/paint/gimpink.c +++ b/app/paint/gimpink.c @@ -76,9 +76,10 @@ static Blob * ink_pen_ellipse (GimpInkOptions *options, static void time_smoother_add (GimpInk *ink, guint32 value); -static gdouble time_smoother_result (GimpInk *ink); +static guint32 time_smoother_result (GimpInk *ink); static void time_smoother_init (GimpInk *ink, guint32 initval); + static void dist_smoother_add (GimpInk *ink, gdouble value); static gdouble dist_smoother_result (GimpInk *ink); @@ -518,43 +519,6 @@ ink_pen_ellipse (GimpInkOptions *options, radmin * tcos); } -static void -dist_smoother_init (GimpInk *ink, - gdouble initval) -{ - gint i; - - ink->dt_index = 0; - - for (i = 0; i < DIST_SMOOTHER_BUFFER; i++) - { - ink->dt_buffer[i] = initval; - } -} - -static gdouble -dist_smoother_result (GimpInk *ink) -{ - gint i; - gdouble result = 0.0; - - for (i = 0; i < DIST_SMOOTHER_BUFFER; i++) - { - result += ink->dt_buffer[i]; - } - - return (result / (gdouble) DIST_SMOOTHER_BUFFER); -} - -static void -dist_smoother_add (GimpInk *ink, - gdouble value) -{ - ink->dt_buffer[ink->dt_index] = value; - - if ((++ink->dt_index) == DIST_SMOOTHER_BUFFER) - ink->dt_index = 0; -} static void time_smoother_init (GimpInk *ink, @@ -565,40 +529,75 @@ time_smoother_init (GimpInk *ink, ink->ts_index = 0; for (i = 0; i < TIME_SMOOTHER_BUFFER; i++) - { - ink->ts_buffer[i] = initval; - } + ink->ts_buffer[i] = initval; } -static gdouble +static guint32 time_smoother_result (GimpInk *ink) { gint i; guint64 result = 0; for (i = 0; i < TIME_SMOOTHER_BUFFER; i++) - { - result += ink->ts_buffer[i]; - } + result += ink->ts_buffer[i]; -#ifdef _MSC_VER - return (gdouble) (gint64) (result / TIME_SMOOTHER_BUFFER); -#else - return (result / TIME_SMOOTHER_BUFFER); -#endif + return (result / (guint64) TIME_SMOOTHER_BUFFER); } static void time_smoother_add (GimpInk *ink, guint32 value) { - ink->ts_buffer[ink->ts_index] = value; + guint64 long_value = (guint64) value; - if ((++ink->ts_index) == TIME_SMOOTHER_BUFFER) + /* handle wrap-around of time values */ + if (long_value < ink->ts_buffer[ink->ts_index]) + long_value += (guint64) + G_MAXUINT32; + + ink->ts_buffer[ink->ts_index++] = long_value; + + ink->ts_buffer[ink->ts_index++] = value; + + if (ink->ts_index == TIME_SMOOTHER_BUFFER) ink->ts_index = 0; } +static void +dist_smoother_init (GimpInk *ink, + gdouble initval) +{ + gint i; + + ink->dt_index = 0; + + for (i = 0; i < DIST_SMOOTHER_BUFFER; i++) + ink->dt_buffer[i] = initval; +} + +static gdouble +dist_smoother_result (GimpInk *ink) +{ + gint i; + gdouble result = 0.0; + + for (i = 0; i < DIST_SMOOTHER_BUFFER; i++) + result += ink->dt_buffer[i]; + + return (result / (gdouble) DIST_SMOOTHER_BUFFER); +} + +static void +dist_smoother_add (GimpInk *ink, + gdouble value) +{ + ink->dt_buffer[ink->dt_index++] = value; + + if (ink->dt_index == DIST_SMOOTHER_BUFFER) + ink->dt_index = 0; +} + + /*********************************/ /* Rendering functions */ /*********************************/