From 060ea15ae2c1604d51d3df1460e99c7d6e6211cf Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 10 Nov 2016 16:17:37 +0100 Subject: [PATCH] d3drm: Introduce d3drm_set_color(). Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3drm/d3drm_private.h | 16 ++++++++++++++++ dlls/d3drm/frame.c | 5 ++--- dlls/d3drm/light.c | 2 +- dlls/d3drm/math.c | 29 +++++++++-------------------- dlls/d3drm/meshbuilder.c | 7 +++---- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/dlls/d3drm/d3drm_private.h b/dlls/d3drm/d3drm_private.h index e75fe45f06a..49e4af14eaa 100644 --- a/dlls/d3drm/d3drm_private.h +++ b/dlls/d3drm/d3drm_private.h @@ -21,6 +21,7 @@ #ifndef __D3DRM_PRIVATE_INCLUDED__ #define __D3DRM_PRIVATE_INCLUDED__ +#include #include "d3drm.h" #include "dxfile.h" #include "d3drmwin.h" @@ -140,4 +141,19 @@ struct d3drm_file_header extern char templates[] DECLSPEC_HIDDEN; +static inline BYTE d3drm_color_component(float c) +{ + if (c <= 0.0f) + return 0u; + if (c >= 1.0f) + return 0xffu; + return floor(c * 255.0f); +} + +static inline void d3drm_set_color(D3DCOLOR *color, float r, float g, float b, float a) +{ + *color = RGBA_MAKE(d3drm_color_component(r), d3drm_color_component(g), + d3drm_color_component(b), d3drm_color_component(a)); +} + #endif /* __D3DRM_PRIVATE_INCLUDED__ */ diff --git a/dlls/d3drm/frame.c b/dlls/d3drm/frame.c index 978b1d88ff7..39b2f87d71d 100644 --- a/dlls/d3drm/frame.c +++ b/dlls/d3drm/frame.c @@ -2004,8 +2004,7 @@ static HRESULT WINAPI d3drm_frame3_SetSceneBackgroundRGB(IDirect3DRMFrame3 *ifac TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue); - frame->scenebackground = RGBA_MAKE((BYTE)(red * 255.0f), - (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff); + d3drm_set_color(&frame->scenebackground, red, green, blue, 1.0f); return D3DRM_OK; } @@ -2949,7 +2948,7 @@ HRESULT d3drm_frame_create(struct d3drm_frame **frame, IUnknown *parent_frame, I object->IDirect3DRMFrame3_iface.lpVtbl = &d3drm_frame3_vtbl; object->d3drm = d3drm; object->ref = 1; - object->scenebackground = RGBA_MAKE(0, 0, 0, 0xff); + d3drm_set_color(&object->scenebackground, 0.0f, 0.0f, 0.0f, 1.0f); memcpy(object->transform, identity, sizeof(D3DRMMATRIX4D)); diff --git a/dlls/d3drm/light.c b/dlls/d3drm/light.c index 53accbfaeb3..7a7ccd46a03 100644 --- a/dlls/d3drm/light.c +++ b/dlls/d3drm/light.c @@ -183,7 +183,7 @@ static HRESULT WINAPI d3drm_light_SetColorRGB(IDirect3DRMLight *iface, TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue); - light->color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff); + d3drm_set_color(&light->color, red, green, blue, 1.0f); return D3DRM_OK; } diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c index a1ad727e94d..4ccde60d23e 100644 --- a/dlls/d3drm/math.c +++ b/dlls/d3drm/math.c @@ -19,12 +19,10 @@ #define NONAMELESSUNION -#include -#include -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "d3drmdef.h" +#include "config.h" +#include "wine/port.h" + +#include "d3drm_private.h" /* Create a RGB color from its components */ D3DCOLOR WINAPI D3DRMCreateColorRGB(D3DVALUE red, D3DVALUE green, D3DVALUE blue) @@ -34,20 +32,11 @@ D3DCOLOR WINAPI D3DRMCreateColorRGB(D3DVALUE red, D3DVALUE green, D3DVALUE blue) /* 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)); + D3DCOLOR color; + + d3drm_set_color(&color, red, green, blue, alpha); + + return color; } /* Determine the alpha part of a color */ diff --git a/dlls/d3drm/meshbuilder.c b/dlls/d3drm/meshbuilder.c index 958e7594089..0028f123108 100644 --- a/dlls/d3drm/meshbuilder.c +++ b/dlls/d3drm/meshbuilder.c @@ -1235,8 +1235,7 @@ HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *pData, values = (float*)ptr; - This->materials[i].color = RGBA_MAKE((BYTE)(values[0] * 255.0f), (BYTE)(values[1] * 255.0f), - (BYTE)(values[2] * 255.0f), (BYTE)(values[3] * 255.0f)); + d3drm_set_color(&This->materials[i].color, values[0], values[1], values[2], values[3]); IDirect3DRMMaterial2_SetAmbient(This->materials[i].material, values[0], values [1], values[2]); /* Alpha ignored */ IDirect3DRMMaterial2_SetPower(This->materials[i].material, values[4]); @@ -1694,7 +1693,7 @@ static HRESULT WINAPI d3drm_mesh_builder3_SetColorRGB(IDirect3DRMMeshBuilder3 *i TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue); - mesh_builder->color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff); + d3drm_set_color(&mesh_builder->color, red, green, blue, 1.0f); return D3DRM_OK; } @@ -2595,7 +2594,7 @@ static HRESULT WINAPI d3drm_mesh_SetGroupColorRGB(IDirect3DRMMesh *iface, if (id >= mesh->nb_groups) return D3DRMERR_BADVALUE; - mesh->groups[id].color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff); + d3drm_set_color(&mesh->groups[id].color, red, green, blue, 1.0f); return D3DRM_OK; }