summaryrefslogtreecommitdiffstats
path: root/libvncserver
diff options
context:
space:
mode:
authordscho <dscho>2005-01-21 22:01:48 +0000
committerdscho <dscho>2005-01-21 22:01:48 +0000
commit6273f2065a72261ba6cb3f6a070421033c96077d (patch)
tree9f24cf8ad8aff01e6186a7ea702c100a3e90a870 /libvncserver
parentdbc826d4abc171bed44d1f42a22c2c5bdfef38ef (diff)
downloadlibtdevnc-6273f2065a72261ba6cb3f6a070421033c96077d.tar.gz
libtdevnc-6273f2065a72261ba6cb3f6a070421033c96077d.zip
implemented Floyd-Steinberg dither in order to rfbMakeMaskFromAlphaSource
Diffstat (limited to 'libvncserver')
-rw-r--r--libvncserver/cursor.c38
1 files changed, 38 insertions, 0 deletions
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<height;j++)
+ for(i=0;i<width;i++) {
+ int right,middle,left;
+ currentError+=alphaSource[i+width*j]+error[i];
+
+ if(currentError<0x80) {
+ /* set to transparent */
+ /* alpha was treated as 0 */
+ } else {
+ /* set to solid */
+ result[i/8+j*maskStride]|=(0x100>>(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) {