From 6273f2065a72261ba6cb3f6a070421033c96077d Mon Sep 17 00:00:00 2001 From: dscho Date: Fri, 21 Jan 2005 22:01:48 +0000 Subject: implemented Floyd-Steinberg dither in order to rfbMakeMaskFromAlphaSource --- libvncserver/cursor.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'libvncserver') diff --git a/libvncserver/cursor.c b/libvncserver/cursor.c index 49d7b99..2577064 100644 --- a/libvncserver/cursor.c +++ b/libvncserver/cursor.c @@ -306,6 +306,44 @@ char* rfbMakeMaskForXCursor(int width,int height,char* source) return(mask); } +/* this function dithers the alpha using Floyd-Steinberg */ + +char* rfbMakeMaskFromAlphaSource(int width,int height,unsigned char* alphaSource) +{ + int* error=(int*)calloc(sizeof(int),width); + int i,j,currentError=0,maskStride=(width+7)/8; + unsigned char* result=(unsigned char*)calloc(maskStride,height); + + for(j=0;j>(i&7)); + /* alpha was treated as 0xff */ + currentError-=0xff; + } + /* propagate to next row */ + right=currentError/16; + middle=currentError*5/16; + left=currentError*3/16; + currentError-=right+middle+left; + error[i]=right; + if(i>0) { + error[i-1]=middle; + if(i>1) + error[i-2]=left; + } + } + free(error); + return result; +} + void rfbFreeCursor(rfbCursorPtr cursor) { if(cursor) { -- cgit v1.2.3