diff options
author | Kent Mein <mein@cs.umn.edu> | 2003-05-21 19:55:00 +0400 |
---|---|---|
committer | Kent Mein <mein@cs.umn.edu> | 2003-05-21 19:55:00 +0400 |
commit | 19e892b2d99def07a0806acbdf15476c804cc556 (patch) | |
tree | de3b3d8486ad997675484e1009240b8c3b5f4033 | |
parent | ffaae2040076282c2dc78d25925fe58cdfcc95e0 (diff) |
Jeroen Lamain's edgeRender patch....
Removes floating point calculations and fixes some rounding errors
too boot.
I created a test program so you can see the differences if anyone is
interested you can grab it from
http://www.cs.umn.edu/~mein/blender/testedge.c
Kent
-rw-r--r-- | source/blender/render/intern/source/edgeRender.c | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/source/blender/render/intern/source/edgeRender.c b/source/blender/render/intern/source/edgeRender.c index ce843432239..c4f7ad34cd6 100644 --- a/source/blender/render/intern/source/edgeRender.c +++ b/source/blender/render/intern/source/edgeRender.c @@ -168,7 +168,7 @@ int zBufferEdgeRenderObjects(void); /** * Add edge pixels to the original image. It blends <bron> over <doel>. */ -void addEdgeOver(char *doel, char *bron); +void addEdgeOver(unsigned char *dst, unsigned char *src); /* ------------------------------------------------------------------------- */ @@ -498,37 +498,48 @@ void renderEdges(char *colourRect) /* ------------------------------------------------------------------------- */ -void addEdgeOver(char *doel, char *bron) /* adds bron (source) to doel (goal) */ -{ - float c; - int mul; - - if( bron[3] == 0) return; - if( bron[3] == 255) { /* has been tested, saves a lot */ - *((unsigned int *)doel)= *((unsigned int *)bron); - return; - } - - /* This must be a special blend-mode, because we get a 'weird' data */ - /* input format now. With edge = (c_e, a_e), picture = (c_p, a_p), we */ - /* get: result = ( c_e*a_e + c_p(1 - a_e), a_p ). */ - - mul = 255 - bron[3]; - - /* Not sure if the conversion to float is really necessary here... I will*/ - /* think about it another day. */ - c = ((mul * doel[0] + bron[0] * bron[3])/255.0); - if(c>255) {doel[0]=255;} else { doel[0]= c;} - c = ((mul * doel[1] + bron[1] * bron[3])/255.0); - if(c>255) {doel[1]=255;} else { doel[1]= c;} - c = ((mul * doel[2] + bron[2] * bron[3])/255.0); - if(c>255) {doel[2]=255;} else { doel[2]= c;} +/* adds src to dst */ +void addEdgeOver(unsigned char *dst, unsigned char *src) +{ + unsigned char inverse; + unsigned char alpha; + unsigned int c; + + alpha = src[3]; + + if( alpha == 0) return; + if( alpha == 255) { + /* when full opacity, just copy the pixel */ + /* this code assumes an int is 32 bit, fix + + *(( unsigned int *)dst)= *((unsigned int *)src); + replaced with memcpy + */ + memcpy(dst,src,4); + return; + } + + /* This must be a special blend-mode, because we get a 'weird' data */ + /* input format now. With edge = (c_e, a_e), picture = (c_p, a_p), we */ + /* get: result = ( c_e*a_e + c_p(1 - a_e), a_p ). */ + + inverse = 255 - alpha; + + c = ((unsigned int)inverse * (unsigned int) dst[0] + (unsigned int)src[0] * + (unsigned int)alpha) >> 8; + dst[0] = c; + + c = ((unsigned int)inverse * (unsigned int) dst[1] + (unsigned int)src[1] * + (unsigned int)alpha) >> 8; + dst[1] = c; + c = ((unsigned int)inverse * (unsigned int) dst[2] + (unsigned int)src[2] * + (unsigned int)alpha) >> 8; + dst[2] = c; } void calcEdgeRenderColBuf(char* colTargetBuffer) { -/* int part; */ int keepLooping = 1; int sample; |