[Bf-committers] edgeRender patch
Jeroen Lamain
bf-committers@blender.org
28 Mar 2003 03:20:36 +0100
--=-qlKzqcBY+K2IRYrTipAg
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi guys,
I removed floating point calculations from addEdgeOver in edgeRender.c
I think the fixed point mathematics are correct. can someone check ?
The clipping if's are not necessary anymore because
(255-alpa)*src+(alpha*dst) can never be greater than 256*255.
Please correct me if I'm wrong.
Groetjes,
Jeroen
--=-qlKzqcBY+K2IRYrTipAg
Content-Disposition: attachment; filename=edgeRender.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=edgeRender.diff; charset=UTF-8
Index: edgeRender.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/e=
dgeRender.c,v
retrieving revision 1.3
diff -u -r1.3 edgeRender.c
--- edgeRender.c 25 Nov 2002 12:02:03 -0000 1.3
+++ edgeRender.c 26 Mar 2003 21:41:41 -0000
@@ -168,7 +168,7 @@
/**
* 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);
=20
/* -----------------------------------------------------------------------=
-- */
=20
@@ -498,31 +498,36 @@
=20
/* -----------------------------------------------------------------------=
-- */
=20
-void addEdgeOver(char *doel, char *bron) /* telt bron bij doel */
-{=09
- float c;
- int mul;
-=09
- if( bron[3] =3D=3D 0) return;
- if( bron[3] =3D=3D 255) { /* is getest, scheelt */
- *((unsigned int *)doel)=3D *((unsigned int *)bron);
- return;
- }
+void addEdgeOver(unsigned char *dst, unsigned char *src) /* adds src to =
dst */
+{
+ unsigned char inverse;
+ unsigned char alpha;
+ unsigned int c;
+
+ alpha =3D src[3];
+ =20
+ if( alpha =3D=3D 0) return;
+ if( alpha =3D=3D 255) {=20
+ /* when full opacity, just copy the pixel */
+ /* this code assumes an int is 32 bit, fix */
+ *((unsigned int *)dst)=3D *((unsigned int *)src);
+ return;
+ }
+ =20
+ /* This must be a special blend-mode, because we get a 'weird' data =
*/
+ /* input format now. With edge =3D (c_e, a_e), picture =3D (c_p, a_p), w=
e */
+ /* get: result =3D ( c_e*a_e + c_p(1 - a_e), a_p ). =
*/
+ =20
+ inverse =3D 255 - alpha;
+ =20
+ c =3D ((unsigned int)inverse * (unsigned int) dst[0] + (unsigned int)src=
[0] * (unsigned int)alpha) >> 8;
+ dst[0] =3D c;
+
+ c =3D ((unsigned int)inverse * (unsigned int) dst[1] + (unsigned int)src=
[1] * (unsigned int)alpha) >> 8;
+ dst[1] =3D c;
=20
- /* This must be a special blend-mode, because we get a 'weird' data =
*/
- /* input format now. With edge =3D (c_e, a_e), picture =3D (c_p, a_p), we=
*/
- /* get: result =3D ( c_e*a_e + c_p(1 - a_e), a_p ). =
*/
-=09
- mul =3D 255 - bron[3];
-
- /* Not sure if the conversion to float is really necessary here... I will=
*/
- /* think about it another day. =
*/
- c =3D ((mul * doel[0] + bron[0] * bron[3])/255.0);
- if(c>255) {doel[0]=3D255;} else { doel[0]=3D c;}
- c =3D ((mul * doel[1] + bron[1] * bron[3])/255.0);
- if(c>255) {doel[1]=3D255;} else { doel[1]=3D c;}
- c =3D ((mul * doel[2] + bron[2] * bron[3])/255.0);
- if(c>255) {doel[2]=3D255;} else { doel[2]=3D c;}
+ c =3D ((unsigned int)inverse * (unsigned int) dst[2] + (unsigned int)src=
[2] * (unsigned int)alpha) >> 8;
+ dst[2] =3D c;
}
=20
void calcEdgeRenderColBuf(char* colTargetBuffer)
--=-qlKzqcBY+K2IRYrTipAg--