David Adam : d3drm: Implement D3DRMCreateColorRGBA.

Alexandre Julliard julliard at wine.codeweavers.com
Mon May 21 09:40:26 CDT 2007


Module: wine
Branch: master
Commit: 21b7413deecfaed247b88512426486026cc40044
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=21b7413deecfaed247b88512426486026cc40044

Author: David Adam <David.Adam at math.cnrs.fr>
Date:   Sun May 20 16:26:44 2007 +0200

d3drm: Implement D3DRMCreateColorRGBA.

---

 dlls/d3drm/d3drm.spec     |    2 +-
 dlls/d3drm/math.c         |   19 +++++++++++++++++++
 dlls/d3drm/tests/vector.c |   33 +++++++++++++++++++++++++++++++--
 include/d3drmdef.h        |    1 +
 4 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec
index 19df75c..69da8b6 100644
--- a/dlls/d3drm/d3drm.spec
+++ b/dlls/d3drm/d3drm.spec
@@ -3,7 +3,7 @@
 @ stdcall D3DRMColorGetGreen(long)
 @ stdcall D3DRMColorGetRed(long)
 @ stub D3DRMCreateColorRGB
-@ stub D3DRMCreateColorRGBA
+@ stdcall D3DRMCreateColorRGBA(long long long long)
 @ stdcall D3DRMMatrixFromQuaternion(ptr ptr)
 @ stdcall D3DRMQuaternionFromRotation(ptr ptr long)
 @ stdcall D3DRMQuaternionMultiply(ptr ptr ptr)
diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c
index f660de4..a06c024 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -34,6 +34,25 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
 
+/* Create a RGBA color from its components */
+D3DCOLOR WINAPI D3DRMCreateColorRGBA(D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVALUE alpha)
+{
+    int Red, Green, Blue, Alpha;
+    Red=floor(red*255);
+    Green=floor(green*255);
+    Blue=floor(blue*255);
+    Alpha=floor(alpha*255);
+    if (red < 0) Red=0;
+    if (red > 1) Red=255;
+    if (green < 0) Green=0;
+    if (green > 1) Green=255;
+    if (blue < 0) Blue=0;
+    if (blue > 1) Blue=255;
+    if (alpha < 0) Alpha=0;
+    if (alpha > 1) Alpha=255;
+    return (RGBA_MAKE(Red, Green, Blue, Alpha));
+}
+
 /* Determine the alpha part of a color */
 D3DVALUE WINAPI D3DRMColorGetAlpha(D3DCOLOR color)
 {
diff --git a/dlls/d3drm/tests/vector.c b/dlls/d3drm/tests/vector.c
index 82d714b..8448879 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -79,6 +79,7 @@ static LPD3DVECTOR (WINAPI * pD3DRMVectorScale)(LPD3DVECTOR, LPD3DVECTOR, D3DVAL
 static LPD3DVECTOR (WINAPI * pD3DRMVectorSubtract)(LPD3DVECTOR, LPD3DVECTOR, LPD3DVECTOR);
 static LPD3DRMQUATERNION (WINAPI * pD3DRMQuaternionFromRotation)(LPD3DRMQUATERNION, LPD3DVECTOR, D3DVALUE);
 static LPD3DRMQUATERNION (WINAPI * pD3DRMQuaternionSlerp)(LPD3DRMQUATERNION, LPD3DRMQUATERNION, LPD3DRMQUATERNION, D3DVALUE);
+static D3DCOLOR (WINAPI * pD3DRMCreateColorRGBA)(D3DVALUE, D3DVALUE, D3DVALUE, D3DVALUE);
 static D3DVALUE (WINAPI * pD3DRMColorGetAlpha)(D3DCOLOR);
 static D3DVALUE (WINAPI * pD3DRMColorGetBlue)(D3DCOLOR);
 static D3DVALUE (WINAPI * pD3DRMColorGetGreen)(D3DCOLOR);
@@ -114,6 +115,7 @@ static BOOL InitFunctionPtrs(void)
     D3DRM_GET_PROC(D3DRMVectorSubtract)
     D3DRM_GET_PROC(D3DRMQuaternionFromRotation)
     D3DRM_GET_PROC(D3DRMQuaternionSlerp)
+    D3DRM_GET_PROC(D3DRMCreateColorRGBA)
     D3DRM_GET_PROC(D3DRMColorGetAlpha)
     D3DRM_GET_PROC(D3DRMColorGetBlue)
     D3DRM_GET_PROC(D3DRMColorGetGreen)
@@ -256,8 +258,35 @@ static void QuaternionTest(void)
 
 static void ColorTest(void)
 {
-    D3DCOLOR color;
-    D3DVALUE expected, got;
+    D3DCOLOR color, expected_color, got_color;
+    D3DVALUE expected, got, red, green, blue, alpha;
+
+/*___________D3DRMCreateColorRGBA________________________*/
+    red=0.1;
+    green=0.4;
+    blue=0.7;
+    alpha=0.58;
+    expected_color=0x931966b2;
+    got_color=pD3DRMCreateColorRGBA(red,green,blue,alpha);
+    ok((expected_color==got_color),"Expected color=%x, Got color=%x\n",expected_color,got_color);
+
+/* if a component is <0 then, then one considers this compenent as 0. The following test proves this fact (test only with the red component). */
+    red=-0.88;
+    green=0.4;
+    blue=0.6;
+    alpha=0.41;
+    expected_color=0x68006699;
+    got_color=pD3DRMCreateColorRGBA(red,green,blue,alpha);
+    ok((expected_color==got_color),"Expected color=%x, Got color=%x\n",expected_color,got_color);
+
+/* if a component is >1 then, then one considers this compenent as 1. The following test proves this fact (test only with the red component). */
+    red=2.37;
+    green=0.4;
+    blue=0.6;
+    alpha=0.41;
+    expected_color=0x68ff6699;
+    got_color=pD3DRMCreateColorRGBA(red,green,blue,alpha);
+    ok((expected_color==got_color),"Expected color=%x, Got color=%x\n",expected_color,got_color);
 
 /*___________D3DRMColorGetAlpha_________________________*/
     color=0x0e4921bf;
diff --git a/include/d3drmdef.h b/include/d3drmdef.h
index abe8949..bd94924 100644
--- a/include/d3drmdef.h
+++ b/include/d3drmdef.h
@@ -54,6 +54,7 @@ LPD3DVECTOR WINAPI D3DRMVectorReflect(LPD3DVECTOR, LPD3DVECTOR, LPD3DVECTOR);
 LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR, LPD3DVECTOR, D3DVALUE);
 LPD3DVECTOR WINAPI D3DRMVectorSubtract(LPD3DVECTOR, LPD3DVECTOR, LPD3DVECTOR);
 
+D3DCOLOR WINAPI D3DRMCreateColorRGBA(D3DVALUE, D3DVALUE, D3DVALUE, D3DVALUE);
 D3DVALUE WINAPI D3DRMColorGetAlpha(D3DCOLOR);
 D3DVALUE WINAPI D3DRMColorGetBlue(D3DCOLOR);
 D3DVALUE WINAPI D3DRMColorGetGreen(D3DCOLOR);




More information about the wine-cvs mailing list