From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 13 +++++++- dlls/d3dx9_36/math.c | 10 +++--- dlls/d3dx9_36/surface.c | 62 +++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 31 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index bf16b3a7590..5ee956f041d 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -55,6 +55,17 @@ struct vec4 float x, y, z, w; };
+enum range { + RANGE_FULL = 0, + RANGE_UNORM = 1, +}; + +struct d3dx_color +{ + struct vec4 value; + enum range range; +}; + struct volume { UINT width; @@ -178,7 +189,7 @@ HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer); const struct pixel_format_desc *get_format_info(D3DFORMAT format); const struct pixel_format_desc *get_format_info_idx(int idx);
-void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst); +void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, struct d3dx_color *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/math.c b/dlls/d3dx9_36/math.c index f018f499c43..4b8f200b199 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -3052,7 +3052,7 @@ HRESULT WINAPI D3DXSHProjectCubeMap(unsigned int order, IDirect3DCubeTexture9 *t float diff_solid, x_3d, y_3d; const float u = x * S + B; const float v = y * S + B; - struct vec4 colour; + struct d3dx_color colour; D3DXVECTOR3 dir;
x_3d = (x * 2.0f + 1.0f) / desc.Width - 1.0f; @@ -3093,15 +3093,15 @@ HRESULT WINAPI D3DXSHProjectCubeMap(unsigned int order, IDirect3DCubeTexture9 *t D3DXVec3Normalize(&dir, &dir); D3DXSHEvalDirection(temp, order, &dir);
- format_to_vec4(format, &row[x * format->block_byte_count], &colour); + format_to_d3dx_color(format, &row[x * format->block_byte_count], &colour);
for (i = 0; i < order_square; ++i) { - red[i] += temp[i] * colour.x * diff_solid; + red[i] += temp[i] * colour.value.x * diff_solid; if (green) - green[i] += temp[i] * colour.y * diff_solid; + green[i] += temp[i] * colour.value.y * diff_solid; if (blue) - blue[i] += temp[i] * colour.z * diff_solid; + blue[i] += temp[i] * colour.value.z * diff_solid; } } } diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 84cf3262c7f..6b92ca997ba 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -26,6 +26,7 @@ #include "wincodec.h"
#include "txc_dxtn.h" +#include <assert.h>
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -1507,15 +1508,30 @@ static DWORD make_argb_color(const struct argb_conversion_info *info, const DWOR }
/* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */ -void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst) +void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, struct d3dx_color *dst) { DWORD mask, tmp; unsigned int c;
+ switch (format->type) + { + case FORMAT_ARGBF16: + case FORMAT_ARGBF: + dst->range = RANGE_FULL; + break; + case FORMAT_ARGB: + case FORMAT_INDEX: + dst->range = RANGE_UNORM; + break; + default: /* Shouldn't pass FORMAT_DXT/FORMAT_UNKNOWN into here. */ + assert(0); + break; + } + for (c = 0; c < 4; ++c) { static const unsigned int component_offsets[4] = {3, 0, 1, 2}; - float *dst_component = (float *)dst + component_offsets[c]; + float *dst_component = ((float *)&dst->value) + component_offsets[c];
if (format->bits[c]) { @@ -1537,7 +1553,7 @@ void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, str }
/* It doesn't work for components bigger than 32 bits. */ -static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst) +static 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; @@ -1683,29 +1699,27 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit } else { - struct vec4 color, tmp; + struct d3dx_color color, tmp;
- format_to_vec4(src_format, src_ptr, &color); + format_to_d3dx_color(src_format, src_ptr, &color); + tmp = color; if (src_format->to_rgba) - src_format->to_rgba(&color, &tmp, palette); - else - tmp = color; + src_format->to_rgba(&color.value, &tmp.value, palette);
if (ck_format) { DWORD ck_pixel;
- format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel); + format_from_d3dx_color(ck_format, &tmp, (BYTE *)&ck_pixel); if (ck_pixel == color_key) - tmp.w = 0.0f; + tmp.value.w = 0.0f; }
+ color = tmp; if (dst_format->from_rgba) - dst_format->from_rgba(&tmp, &color); - else - color = tmp; + dst_format->from_rgba(&tmp.value, &color.value);
- format_from_vec4(dst_format, &color, dst_ptr); + format_from_d3dx_color(dst_format, &color, dst_ptr); }
src_ptr += src_format->bytes_per_pixel; @@ -1791,29 +1805,27 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic } else { - struct vec4 color, tmp; + struct d3dx_color color, tmp;
- format_to_vec4(src_format, src_ptr, &color); + format_to_d3dx_color(src_format, src_ptr, &color); + tmp = color; if (src_format->to_rgba) - src_format->to_rgba(&color, &tmp, palette); - else - tmp = color; + src_format->to_rgba(&color.value, &tmp.value, palette);
if (ck_format) { DWORD ck_pixel;
- format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel); + format_from_d3dx_color(ck_format, &tmp, (BYTE *)&ck_pixel); if (ck_pixel == color_key) - tmp.w = 0.0f; + tmp.value.w = 0.0f; }
+ color = tmp; if (dst_format->from_rgba) - dst_format->from_rgba(&tmp, &color); - else - color = tmp; + dst_format->from_rgba(&tmp.value, &color.value);
- format_from_vec4(dst_format, &color, dst_ptr); + format_from_d3dx_color(dst_format, &color, dst_ptr); }
dst_ptr += dst_format->bytes_per_pixel;