From: Chris Bagwell <ch...@cnpbagwell.com>

The more time that passes, the less meaning that previous
samples have to current sample.  Make window size shrink
as more time occurs since last sample received.

Old filter average would introduce a offset error when
deltas between older samples was large (when drawing fast).
If a user quickly drew to edge of Bamboo tablet and went
out of proximity then the offset error would not allow to
reach edge of screen.

This shrinking window seems to resolve that issue.

Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com>
---
 src/wcmFilter.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index 4cb1bb7..d9ebf50 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -310,6 +310,7 @@ static void filterIntuosStylus(WacomCommonPtr common,
 {
        int x=0, y=0, tx=0, ty=0, i;
        WacomFilterState *state;
+       int max_holdoff, sample_window;
 
        storeRawSample(common, pChannel, ds);
 
@@ -318,23 +319,27 @@ static void filterIntuosStylus(WacomCommonPtr common,
 
        state = &pChannel->rawFilter;
 
-       for ( i=0; i<common->wcmRawSample; i++ )
+       max_holdoff = common->wcmRawSample * WCM_FILTER_HOLDOFF;
+       sample_window = max_holdoff / pChannel->rawFilter.sample;
+       if (!sample_window) sample_window = 1;
+
+       for ( i=0; i< sample_window; i++ )
        {
                x += state->x[i];
                y += state->y[i];
                tx += state->tiltx[i];
                ty += state->tilty[i];
        }
-       ds->x = x / common->wcmRawSample;
-       ds->y = y / common->wcmRawSample;
+       ds->x = x / sample_window;
+       ds->y = y / sample_window;
 
-       ds->tiltx = tx / common->wcmRawSample;
+       ds->tiltx = tx / sample_window;
        if (ds->tiltx > common->wcmMaxtiltX/2-1)
                ds->tiltx = common->wcmMaxtiltX/2-1;    
        else if (ds->tiltx < -common->wcmMaxtiltX/2)
                ds->tiltx = -common->wcmMaxtiltX/2;
 
-       ds->tilty = ty / common->wcmRawSample;
+       ds->tilty = ty / sample_window;
        if (ds->tilty > common->wcmMaxtiltY/2-1)
                ds->tilty = common->wcmMaxtiltY/2-1;    
        else if (ds->tilty < -common->wcmMaxtiltY/2)
@@ -353,6 +358,7 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr 
pChannel,
 
        WacomDeviceState *pLast;
        int *x, *y, i; 
+       int max_holdoff, sample_window;
 
        DBG(10, common, "common->wcmRawSample = %d \n", common->wcmRawSample);
 
@@ -368,13 +374,17 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr 
pChannel,
        ds->x = 0;
        ds->y = 0;
 
-       for ( i=0; i<common->wcmRawSample; i++ )
+       max_holdoff = common->wcmRawSample * WCM_FILTER_HOLDOFF;
+       sample_window = max_holdoff / pChannel->rawFilter.sample;
+       if (!sample_window) sample_window = 1;
+
+       for ( i=0; i < sample_window; i++ )
        {
                ds->x += x[i];
                ds->y += y[i];
        }
-       ds->x /= common->wcmRawSample;
-       ds->y /= common->wcmRawSample;
+       ds->x /= sample_window;
+       ds->y /= sample_window;
 
        return 0; /* lookin' good */
 }
-- 
1.7.3.1


------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to