From: Connor McAdams cmcadams@codeweavers.com
These functions do the exact same thing, so there's no need to have two separate functions.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 7 ++++ dlls/d3dx9_36/surface.c | 2 +- dlls/d3dx9_36/texture.c | 75 +++++++---------------------------- 3 files changed, 23 insertions(+), 61 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index 2338909f7cc..e46cd7389b2 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -67,6 +67,12 @@ struct d3dx_color enum range range; };
+static inline void set_d3dx_color(struct d3dx_color *color, const struct vec4 *value, enum range range) +{ + color->value = *value; + color->range = range; +} + struct volume { UINT width; @@ -192,6 +198,7 @@ const struct pixel_format_desc *get_format_info(D3DFORMAT format); const struct pixel_format_desc *get_format_info_idx(int idx);
void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, struct d3dx_color *dst); +void format_from_d3dx_color(const struct pixel_format_desc *format, const struct d3dx_color *src, BYTE *dst);
void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size, diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index bf828ddca7b..674a400d37a 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1574,7 +1574,7 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr }
/* It doesn't work for components bigger than 32 bits. */ -static void format_from_d3dx_color(const struct pixel_format_desc *format, const struct d3dx_color *src, BYTE *dst) +void format_from_d3dx_color(const struct pixel_format_desc *format, const struct d3dx_color *src, BYTE *dst) { DWORD v, mask32; unsigned int c, i; diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 2820857230d..38a32052f99 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1261,62 +1261,6 @@ err: return hr; }
-static inline void fill_texture(const struct pixel_format_desc *format, BYTE *pos, const D3DXVECTOR4 *value) -{ - DWORD c; - - for (c = 0; c < format->bytes_per_pixel; c++) - pos[c] = 0; - - for (c = 0; c < 4; c++) - { - float comp_value; - DWORD i, v = 0, mask32 = format->bits[c] == 32 ? ~0U : ((1 << format->bits[c]) - 1); - - switch (c) - { - case 0: /* Alpha */ - comp_value = value->w; - break; - case 1: /* Red */ - comp_value = value->x; - break; - case 2: /* Green */ - comp_value = value->y; - break; - case 3: /* Blue */ - comp_value = value->z; - break; - } - - if (format->type == FORMAT_ARGBF16) - v = float_32_to_16(comp_value); - else if (format->type == FORMAT_ARGBF) - v = *(DWORD *)&comp_value; - else if (format->type == FORMAT_ARGB) - v = max(comp_value * ((1 << format->bits[c]) - 1) + 0.5f, 0); - else - FIXME("Unhandled format type %#x\n", format->type); - - for (i = 0; i < format->bits[c] + format->shift[c]; i += 8) - { - BYTE byte, mask; - - if (format->shift[c] > i) - { - mask = mask32 << (format->shift[c] - i); - byte = (v << (format->shift[c] - i)) & mask; - } - else - { - mask = mask32 >> (i - format->shift[c]); - byte = (v >> (i - format->shift[c])) & mask; - } - pos[i / 8] |= byte; - } - } -} - HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D function, void *funcdata) { IDirect3DSurface9 *surface, *temp_surface; @@ -1370,11 +1314,15 @@ HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D f
for (x = 0; x < desc.Width; x++) { + BYTE *dst = data + y * lock_rect.Pitch + x * format->bytes_per_pixel; + struct d3dx_color color; + coord.x = (x + 0.5f) / desc.Width;
function(&value, &coord, &size, funcdata);
- fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + format_from_d3dx_color(format, &color, dst); } } if (FAILED(hr = unlock_surface(surface, NULL, temp_surface, TRUE))) @@ -1757,13 +1705,17 @@ HRESULT WINAPI D3DXFillCubeTexture(struct IDirect3DCubeTexture9 *texture, LPD3DX { for (x = 0; x < desc.Width; x++) { + BYTE *dst = data + y * lock_rect.Pitch + x * format->bytes_per_pixel; + struct d3dx_color color; + coord.x = get_cube_coord(coordmap[f][0], x, y, desc.Width) / desc.Width * 2.0f - 1.0f; coord.y = get_cube_coord(coordmap[f][1], x, y, desc.Width) / desc.Width * 2.0f - 1.0f; coord.z = get_cube_coord(coordmap[f][2], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
function(&value, &coord, &size, funcdata);
- fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + format_from_d3dx_color(format, &color, dst); } } IDirect3DCubeTexture9_UnlockRect(texture, f, m); @@ -1824,12 +1776,15 @@ HRESULT WINAPI D3DXFillVolumeTexture(struct IDirect3DVolumeTexture9 *texture, LP
for (x = 0; x < desc.Width; x++) { + BYTE *dst = data + z * lock_box.SlicePitch + y * lock_box.RowPitch + x * format->bytes_per_pixel; + struct d3dx_color color; + coord.x = (x + 0.5f) / desc.Width;
function(&value, &coord, &size, funcdata);
- fill_texture(format, data + z * lock_box.SlicePitch + y * lock_box.RowPitch - + x * format->bytes_per_pixel, &value); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + format_from_d3dx_color(format, &color, dst); } } }