changed time-smoother code to use guint32 time values externally, guint64

2005-03-21  Sven Neumann  <sven@gimp.org>

	* app/paint/gimpink.c: changed time-smoother code to use guint32
	time values externally, guint64 internally. Proper fix for bug
	#164272.
This commit is contained in:
Sven Neumann 2005-03-21 21:51:29 +00:00 committed by Sven Neumann
parent eac2c0065b
commit e87f6dcc14
2 changed files with 57 additions and 52 deletions

View File

@ -1,3 +1,9 @@
2005-03-21 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org> 2005-03-21 Sven Neumann <sven@gimp.org>
* app/actions/dialogs-actions.h: bail out if * app/actions/dialogs-actions.h: bail out if

View File

@ -76,9 +76,10 @@ static Blob * ink_pen_ellipse (GimpInkOptions *options,
static void time_smoother_add (GimpInk *ink, static void time_smoother_add (GimpInk *ink,
guint32 value); guint32 value);
static gdouble time_smoother_result (GimpInk *ink); static guint32 time_smoother_result (GimpInk *ink);
static void time_smoother_init (GimpInk *ink, static void time_smoother_init (GimpInk *ink,
guint32 initval); guint32 initval);
static void dist_smoother_add (GimpInk *ink, static void dist_smoother_add (GimpInk *ink,
gdouble value); gdouble value);
static gdouble dist_smoother_result (GimpInk *ink); static gdouble dist_smoother_result (GimpInk *ink);
@ -518,43 +519,6 @@ ink_pen_ellipse (GimpInkOptions *options,
radmin * tcos); 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 static void
time_smoother_init (GimpInk *ink, time_smoother_init (GimpInk *ink,
@ -565,40 +529,75 @@ time_smoother_init (GimpInk *ink,
ink->ts_index = 0; ink->ts_index = 0;
for (i = 0; i < TIME_SMOOTHER_BUFFER; i++) 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) time_smoother_result (GimpInk *ink)
{ {
gint i; gint i;
guint64 result = 0; guint64 result = 0;
for (i = 0; i < TIME_SMOOTHER_BUFFER; i++) for (i = 0; i < TIME_SMOOTHER_BUFFER; i++)
{ result += ink->ts_buffer[i];
result += ink->ts_buffer[i];
}
#ifdef _MSC_VER return (result / (guint64) TIME_SMOOTHER_BUFFER);
return (gdouble) (gint64) (result / TIME_SMOOTHER_BUFFER);
#else
return (result / TIME_SMOOTHER_BUFFER);
#endif
} }
static void static void
time_smoother_add (GimpInk *ink, time_smoother_add (GimpInk *ink,
guint32 value) 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; 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 */ /* Rendering functions */
/*********************************/ /*********************************/