These patches are the last big changes to the pixel_format_desc structure.
Patch 2 of this feels like it might be a bit big, but I couldn't really come up with a clean way to split it. :)
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 30 ++++++++++++++++++++++-------- dlls/d3dx9_36/math.c | 2 +- dlls/d3dx9_36/surface.c | 24 ++++++++++++------------ dlls/d3dx9_36/texture.c | 8 ++++---- dlls/d3dx9_36/volume.c | 4 ++-- 5 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index e46cd7389b2..eb2594a43fa 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -173,20 +173,34 @@ struct d3dx_include_from_file extern CRITICAL_SECTION from_file_mutex; extern const struct ID3DXIncludeVtbl d3dx_include_from_file_vtbl;
+static inline BOOL is_unknown_format(const struct pixel_format_desc *format) +{ + return (format->format == D3DFMT_UNKNOWN); +} + +static inline BOOL is_index_format(const struct pixel_format_desc *format) +{ + return (format->type == FORMAT_INDEX); +} + +static inline BOOL is_compressed_format(const struct pixel_format_desc *format) +{ + return (format->type == FORMAT_DXT); +} + +static inline BOOL format_types_match(const struct pixel_format_desc *src, const struct pixel_format_desc *dst) +{ + return (src->type == dst->type); +} + static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format) { - if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16 - || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT || format->type == FORMAT_ARGB_SNORM) - return TRUE; - return !!format->to_rgba; + return !is_unknown_format(format); }
static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format) { - if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16 - || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT || format->type == FORMAT_ARGB_SNORM) - return TRUE; - return !!format->from_rgba; + return !is_index_format(format) && !is_unknown_format(format); }
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length); diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c index 4b8f200b199..f256b7b2662 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -3017,7 +3017,7 @@ HRESULT WINAPI D3DXSHProjectCubeMap(unsigned int order, IDirect3DCubeTexture9 *t }
format = get_format_info(desc.Format); - if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF) + if (is_unknown_format(format) || is_index_format(format) || is_compressed_format(format)) { FIXME("Unsupported texture format %#x.\n", desc.Format); return D3DERR_INVALIDCALL; diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 7ffc11af663..fa9db1167f2 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -457,7 +457,7 @@ static HRESULT d3dx_calculate_pixels_size(D3DFORMAT format, uint32_t width, uint { const struct pixel_format_desc *format_desc = get_format_info(format);
- if (format_desc->type == FORMAT_UNKNOWN) + if (is_unknown_format(format_desc)) return E_NOTIMPL;
if (format_desc->block_width != 1 || format_desc->block_height != 1) @@ -539,7 +539,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur if (FAILED(hr)) return hr;
pixel_format = get_format_info(src_desc.Format); - if (pixel_format->type == FORMAT_UNKNOWN) return E_NOTIMPL; + if (is_unknown_format(pixel_format)) return E_NOTIMPL;
file_size = calculate_dds_file_size(src_desc.Format, src_desc.Width, src_desc.Height, 1, 1, 1); if (!file_size) @@ -847,7 +847,7 @@ static HRESULT d3dx_image_wic_frame_decode(struct d3dx_image *image, return hr; }
- if (fmt_desc->type == FORMAT_INDEX) + if (is_index_format(fmt_desc)) { uint32_t nb_colors, i;
@@ -1712,7 +1712,7 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit
for (x = 0; x < min_width; x++) { if (!src_format->to_rgba && !dst_format->from_rgba - && src_format->type == dst_format->type + && format_types_match(src_format, dst_format) && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) { DWORD val; @@ -1818,7 +1818,7 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
if (!src_format->to_rgba && !dst_format->from_rgba - && src_format->type == dst_format->type + && format_types_match(src_format, dst_format) && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) { DWORD val; @@ -1963,7 +1963,7 @@ HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pi RECT unaligned_rect;
memset(pixels, 0, sizeof(*pixels)); - if (fmt_desc->type == FORMAT_UNKNOWN) + if (is_unknown_format(fmt_desc)) { FIXME("Unsupported format %#x.\n", format); return E_NOTIMPL; @@ -1973,7 +1973,7 @@ HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pi ptr += (top / fmt_desc->block_height) * row_pitch; ptr += (left / fmt_desc->block_width) * fmt_desc->block_byte_count;
- if (fmt_desc->type == FORMAT_DXT) + if (is_compressed_format(fmt_desc)) { uint32_t left_aligned, top_aligned;
@@ -2013,14 +2013,14 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, debug_d3dx_pixels(dst_pixels), dst_desc, debug_d3dx_pixels(src_pixels), src_desc, filter_flags, color_key);
- if (src_desc->type == FORMAT_DXT) + if (is_compressed_format(src_desc)) set_volume_struct(&src_size, (src_pixels->unaligned_rect.right - src_pixels->unaligned_rect.left), (src_pixels->unaligned_rect.bottom - src_pixels->unaligned_rect.top), src_pixels->size.depth); else src_size = src_pixels->size;
dst_size_aligned = dst_pixels->size; - if (dst_desc->type == FORMAT_DXT) + if (is_compressed_format(dst_desc)) set_volume_struct(&dst_size, (dst_pixels->unaligned_rect.right - dst_pixels->unaligned_rect.left), (dst_pixels->unaligned_rect.bottom - dst_pixels->unaligned_rect.top), dst_pixels->size.depth); else @@ -2055,7 +2055,7 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, * If the source is a compressed image, we need to decompress it first * before doing any modifications. */ - if (src_desc->type == FORMAT_DXT) + if (is_compressed_format(src_desc)) { uint32_t uncompressed_row_pitch, uncompressed_slice_pitch; const struct pixel_format_desc *uncompressed_desc; @@ -2079,7 +2079,7 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, }
/* Same as the above, need to decompress the destination prior to modifying. */ - if (dst_desc->type == FORMAT_DXT) + if (is_compressed_format(dst_desc)) { uint32_t uncompressed_row_pitch, uncompressed_slice_pitch; const struct pixel_format_desc *uncompressed_desc; @@ -2238,7 +2238,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, }
srcformatdesc = get_format_info(src_format); - if (srcformatdesc->type == FORMAT_UNKNOWN) + if (is_unknown_format(srcformatdesc)) { FIXME("Unsupported format %#x.\n", src_format); return E_NOTIMPL; diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 38a32052f99..73d52f16a42 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -290,7 +290,7 @@ static HRESULT check_texture_requirements(struct IDirect3DDevice9 *device, UINT
/* This format can be used, let's evaluate it. Weights chosen quite arbitrarily... */ - score = 512 * (curfmt->type == fmt->type); + score = 512 * (format_types_match(curfmt, fmt)); score -= 32 * (curchannels - channels);
for (j = 0; j < 4; j++) @@ -1287,7 +1287,7 @@ HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D f return hr;
format = get_format_info(desc.Format); - if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF) + if (is_unknown_format(format) || is_index_format(format) || is_compressed_format(format)) { FIXME("Unsupported texture format %#x.\n", desc.Format); return D3DERR_INVALIDCALL; @@ -1684,7 +1684,7 @@ HRESULT WINAPI D3DXFillCubeTexture(struct IDirect3DCubeTexture9 *texture, LPD3DX return D3DERR_INVALIDCALL;
format = get_format_info(desc.Format); - if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF) + if (is_unknown_format(format) || is_index_format(format) || is_compressed_format(format)) { FIXME("Unsupported texture format %#x\n", desc.Format); return D3DERR_INVALIDCALL; @@ -1749,7 +1749,7 @@ HRESULT WINAPI D3DXFillVolumeTexture(struct IDirect3DVolumeTexture9 *texture, LP return D3DERR_INVALIDCALL;
format = get_format_info(desc.Format); - if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF) + if (is_unknown_format(format) || is_index_format(format) || is_compressed_format(format)) { FIXME("Unsupported texture format %#x\n", desc.Format); return D3DERR_INVALIDCALL; diff --git a/dlls/d3dx9_36/volume.c b/dlls/d3dx9_36/volume.c index ae14e47b8b6..0d7fe4a7870 100644 --- a/dlls/d3dx9_36/volume.c +++ b/dlls/d3dx9_36/volume.c @@ -112,12 +112,12 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, return hr;
src_format_desc = get_format_info(src_format); - if (src_format_desc->type == FORMAT_UNKNOWN) + if (is_unknown_format(src_format_desc)) return E_NOTIMPL;
IDirect3DVolume9_GetDesc(dst_volume, &desc); dst_format_desc = get_format_info(desc.Format); - if (dst_format_desc->type == FORMAT_UNKNOWN) + if (is_unknown_format(dst_format_desc)) return E_NOTIMPL;
if (!dst_box)
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 47 +++++++++----- dlls/d3dx9_36/surface.c | 113 ++++++++++++++++++++++------------ dlls/d3dx9_36/texture.c | 6 +- dlls/d3dx9_36/util.c | 74 +++++++++++----------- 4 files changed, 147 insertions(+), 93 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index eb2594a43fa..cf78e1a1444 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -64,13 +64,16 @@ enum range { struct d3dx_color { struct vec4 value; - enum range range; + enum range rgb_range; + enum range a_range; };
-static inline void set_d3dx_color(struct d3dx_color *color, const struct vec4 *value, enum range range) +static inline void set_d3dx_color(struct d3dx_color *color, const struct vec4 *value, enum range rgb_range, + enum range a_range) { color->value = *value; - color->range = range; + color->rgb_range = rgb_range; + color->a_range = a_range; }
struct volume @@ -88,14 +91,17 @@ static inline void set_volume_struct(struct volume *volume, uint32_t width, uint }
/* for internal use */ -enum format_type { - FORMAT_ARGB, /* unsigned */ - FORMAT_ARGBF16,/* float 16 */ - FORMAT_ARGBF, /* float */ - FORMAT_ARGB_SNORM, - FORMAT_DXT, - FORMAT_INDEX, - FORMAT_UNKNOWN +enum component_type { + CTYPE_EMPTY = 0x00, + CTYPE_UNORM = 0x01, + CTYPE_SNORM = 0x02, + CTYPE_FLOAT = 0x03, + CTYPE_LUMA = 0x04, + CTYPE_INDEX = 0x05, +}; + +enum format_flag { + FMT_FLAG_DXT = 0x01, };
struct pixel_format_desc { @@ -106,7 +112,9 @@ struct pixel_format_desc { UINT block_width; UINT block_height; UINT block_byte_count; - enum format_type type; + enum component_type a_type; + enum component_type rgb_type; + uint32_t flags; void (*from_rgba)(const struct vec4 *src, struct vec4 *dst); void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette); }; @@ -180,17 +188,26 @@ static inline BOOL is_unknown_format(const struct pixel_format_desc *format)
static inline BOOL is_index_format(const struct pixel_format_desc *format) { - return (format->type == FORMAT_INDEX); + return (format->a_type == CTYPE_INDEX || format->rgb_type == CTYPE_INDEX); }
static inline BOOL is_compressed_format(const struct pixel_format_desc *format) { - return (format->type == FORMAT_DXT); + return !!(format->flags & FMT_FLAG_DXT); }
static inline BOOL format_types_match(const struct pixel_format_desc *src, const struct pixel_format_desc *dst) { - return (src->type == dst->type); + if ((src->a_type && dst->a_type) && (src->a_type != dst->a_type)) + return FALSE; + + if ((src->rgb_type && dst->rgb_type) && (src->rgb_type != dst->rgb_type)) + return FALSE; + + if (src->flags != dst->flags) + return FALSE; + + return (src->rgb_type == dst->rgb_type || src->a_type == dst->a_type); }
static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format) diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index fa9db1167f2..8c5e89f1f9c 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1505,32 +1505,34 @@ static DWORD make_argb_color(const struct argb_conversion_info *info, const DWOR return val; }
+static enum range get_range_for_component_type(enum component_type type) +{ + switch (type) + { + case CTYPE_SNORM: + return RANGE_SNORM; + + case CTYPE_LUMA: + case CTYPE_INDEX: + case CTYPE_UNORM: + return RANGE_UNORM; + + default: + return RANGE_FULL; + } +} + /* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */ 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; - case FORMAT_ARGB_SNORM: - dst->range = RANGE_SNORM; - break; - default: /* Shouldn't pass FORMAT_DXT/FORMAT_UNKNOWN into here. */ - assert(0); - break; - } - + dst->rgb_range = get_range_for_component_type(format->rgb_type); + dst->a_range = get_range_for_component_type(format->a_type); for (c = 0; c < 4; ++c) { + const enum component_type dst_ctype = !c ? format->a_type : format->rgb_type; static const unsigned int component_offsets[4] = {3, 0, 1, 2}; float *dst_component = &dst->value.x + component_offsets[c];
@@ -1541,11 +1543,22 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr memcpy(&tmp, src + format->shift[c] / 8, min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
- if (format->type == FORMAT_ARGBF16) - *dst_component = float_16_to_32(tmp); - else if (format->type == FORMAT_ARGBF) - *dst_component = *(float *)&tmp; - else if (format->type == FORMAT_ARGB_SNORM) + switch (dst_ctype) + { + case CTYPE_FLOAT: + if (format->bits[c] == 16) + *dst_component = float_16_to_32(tmp); + else + *dst_component = *(float *)&tmp; + break; + + case CTYPE_LUMA: + case CTYPE_INDEX: + case CTYPE_UNORM: + *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask; + break; + + case CTYPE_SNORM: { const uint32_t sign_bit = (1u << (format->bits[c] - 1)); uint32_t tmp_extended, tmp_masked = (tmp >> format->shift[c] % 8) & mask; @@ -1564,9 +1577,12 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr }
*dst_component = (float)(((int32_t)tmp_extended)) / (sign_bit - 1); + break; + } + + default: + break; } - else - *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask; } else *dst_component = 1.0f; @@ -1583,36 +1599,57 @@ void format_from_d3dx_color(const struct pixel_format_desc *format, const struct
for (c = 0; c < 4; ++c) { + const enum component_type dst_ctype = !c ? format->a_type : format->rgb_type; static const unsigned int component_offsets[4] = {3, 0, 1, 2}; - const float src_component = *((const float *)src + component_offsets[c]); + const float src_component = *(&src->value.x + component_offsets[c]); + const enum range src_range = !c ? src->a_range : src->rgb_range;
if (!format->bits[c]) continue;
mask32 = ~0u >> (32 - format->bits[c]);
- if (format->type == FORMAT_ARGBF16) - v = float_32_to_16(src_component); - else if (format->type == FORMAT_ARGBF) - v = *(DWORD *)&src_component; - else if (format->type == FORMAT_ARGB_SNORM) + switch (dst_ctype) + { + case CTYPE_FLOAT: + if (format->bits[c] == 16) + v = float_32_to_16(src_component); + else + v = *(DWORD *)&src_component; + break; + + case CTYPE_LUMA: + case CTYPE_UNORM: + { + float val = src_component; + + if (src_range == RANGE_SNORM) + val = (val + 1.0f) / 2.0f; + + v = d3dx_clamp(val, 0.0f, 1.0f) * ((1u << format->bits[c]) - 1) + 0.5f; + break; + } + + case CTYPE_SNORM: { const uint32_t max_value = (1u << (format->bits[c] - 1)) - 1; float val = src_component;
- if (src->range == RANGE_UNORM) + if (src_range == RANGE_UNORM) val = (val * 2.0f) - 1.0f;
v = d3dx_clamp(val, -1.0f, 1.0f) * max_value + 0.5f; + break; } - else - { - float val = src_component;
- if (src->range == RANGE_SNORM) - val = (val + 1.0f) / 2.0f; + /* We shouldn't be trying to output to CTYPE_INDEX. */ + case CTYPE_INDEX: + assert(0); + break;
- v = d3dx_clamp(val, 0.0f, 1.0f) * ((1u << format->bits[c]) - 1) + 0.5f; + default: + v = 0; + break; }
for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8) diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 73d52f16a42..fda6d44fe5a 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1321,7 +1321,7 @@ HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D f
function(&value, &coord, &size, funcdata);
- set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL, RANGE_FULL); format_from_d3dx_color(format, &color, dst); } } @@ -1714,7 +1714,7 @@ HRESULT WINAPI D3DXFillCubeTexture(struct IDirect3DCubeTexture9 *texture, LPD3DX
function(&value, &coord, &size, funcdata);
- set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL, RANGE_FULL); format_from_d3dx_color(format, &color, dst); } } @@ -1783,7 +1783,7 @@ HRESULT WINAPI D3DXFillVolumeTexture(struct IDirect3DVolumeTexture9 *texture, LP
function(&value, &coord, &size, funcdata);
- set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL); + set_d3dx_color(&color, (const struct vec4 *)&value, RANGE_FULL, RANGE_FULL); format_from_d3dx_color(format, &color, dst); } } diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index a73467f5e68..a9235b9d613 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -54,44 +54,44 @@ static void index_to_rgba(const struct vec4 *index, struct vec4 *rgba, const PAL */ static const struct pixel_format_desc formats[] = { - /* format bpc shifts bpp blocks type from_rgba to_rgba */ - {D3DFMT_R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A8R8G8B8, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_X8R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A8B8G8R8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_X8B8G8R8, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_R5G6B5, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_X1R5G5B5, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A1R5G5B5, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_R3G3B2, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A8R3G3B2, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A4R4G4B4, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_X4R4G4B4, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A2R10G10B10, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A2B10G10R10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, NULL, NULL }, - {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGB, la_from_rgba, la_to_rgba}, - {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, la_from_rgba, la_to_rgba}, - {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, la_from_rgba, la_to_rgba}, - {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGB, la_from_rgba, la_to_rgba}, - {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, FORMAT_DXT, NULL, NULL }, - {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, - {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, - {D3DFMT_DXT4, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, - {D3DFMT_DXT5, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, - {D3DFMT_R16F, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGBF16, NULL, NULL }, - {D3DFMT_G16R16F, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, FORMAT_ARGBF16, NULL, NULL }, - {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, FORMAT_ARGBF16, NULL, NULL }, - {D3DFMT_R32F, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, FORMAT_ARGBF, NULL, NULL }, - {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, FORMAT_ARGBF, NULL, NULL }, - {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, FORMAT_ARGBF, NULL, NULL }, - {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_INDEX, NULL, index_to_rgba}, - {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, FORMAT_ARGB_SNORM, NULL, NULL }, - {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, FORMAT_ARGB_SNORM, NULL, NULL }, + /* format bpc shifts bpp blocks alpha type rgb type flags from_rgba to_rgba */ + {D3DFMT_R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A8R8G8B8, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_X8R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A8B8G8R8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_X8B8G8R8, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_R5G6B5, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_X1R5G5B5, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A1R5G5B5, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_R3G3B2, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A8R3G3B2, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A4R4G4B4, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_X4R4G4B4, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A2R10G10B10, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A2B10G10R10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, + {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0, NULL, NULL }, + {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, + {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, + {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, + {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, + {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, + {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, + {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, + {D3DFMT_DXT4, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, + {D3DFMT_DXT5, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, + {D3DFMT_R16F, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_G16R16F, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_FLOAT, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_R32F, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0, NULL, NULL }, + {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0, NULL, index_to_rgba}, + {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0, NULL, NULL }, + {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0, NULL, NULL }, /* marks last element */ - {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, FORMAT_UNKNOWN, NULL, NULL }, + {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0, NULL, NULL }, };
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 8c5e89f1f9c..b0fc6e42ea4 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1542,6 +1542,7 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr
memcpy(&tmp, src + format->shift[c] / 8, min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8)); + tmp = (tmp >> (format->shift[c] % 8)) & mask;
switch (dst_ctype) { @@ -1555,26 +1556,20 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr case CTYPE_LUMA: case CTYPE_INDEX: case CTYPE_UNORM: - *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask; + *dst_component = (float)tmp / mask; break;
case CTYPE_SNORM: { const uint32_t sign_bit = (1u << (format->bits[c] - 1)); - uint32_t tmp_extended, tmp_masked = (tmp >> format->shift[c] % 8) & mask; - - tmp_extended = tmp_masked; - if (tmp_masked & sign_bit) - { - tmp_extended |= ~(sign_bit - 1); - - /* - * In order to clamp to an even range, we need to ignore - * the maximum negative value. - */ - if (tmp_masked == sign_bit) - tmp_extended |= 1; - } + uint32_t tmp_extended = (tmp & sign_bit) ? (tmp | ~(sign_bit - 1)) : tmp; + + /* + * In order to clamp to an even range, we need to ignore + * the maximum negative value. + */ + if (tmp == sign_bit) + tmp_extended |= 1;
*dst_component = (float)(((int32_t)tmp_extended)) / (sign_bit - 1); break;
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 16 ++++++++++++++++ dlls/d3dx9_36/util.c | 22 ++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index b0fc6e42ea4..50404f38328 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1579,8 +1579,14 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr break; } } + else if (dst_ctype == CTYPE_LUMA) + { + *dst_component = dst->value.x; + } else + { *dst_component = 1.0f; + } } }
@@ -1614,6 +1620,16 @@ void format_from_d3dx_color(const struct pixel_format_desc *format, const struct break;
case CTYPE_LUMA: + { + float val = src->value.x * 0.2125f + src->value.y * 0.7154f + src->value.z * 0.0721f; + + if (src_range == RANGE_SNORM) + val = (val + 1.0f) / 2.0f; + + v = d3dx_clamp(val, 0.0f, 1.0f) * ((1u << format->bits[c]) - 1) + 0.5f; + break; + } + case CTYPE_UNORM: { float val = src_component; diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index a9235b9d613..44b289450a8 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -22,20 +22,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
-static void la_from_rgba(const struct vec4 *rgba, struct vec4 *la) -{ - la->x = rgba->x * 0.2125f + rgba->y * 0.7154f + rgba->z * 0.0721f; - la->w = rgba->w; -} - -static void la_to_rgba(const struct vec4 *la, struct vec4 *rgba, const PALETTEENTRY *palette) -{ - rgba->x = la->x; - rgba->y = la->x; - rgba->z = la->x; - rgba->w = la->w; -} - static void index_to_rgba(const struct vec4 *index, struct vec4 *rgba, const PALETTEENTRY *palette) { ULONG idx = (ULONG)(index->x * 255.0f + 0.5f); @@ -72,10 +58,10 @@ static const struct pixel_format_desc formats[] = {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0, NULL, NULL }, - {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, - {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, - {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, - {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0, la_from_rgba, la_to_rgba }, + {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0, NULL, NULL }, + {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0, NULL, NULL }, + {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0, NULL, NULL }, + {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0, NULL, NULL }, {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL },
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 5 +-- dlls/d3dx9_36/math.c | 2 +- dlls/d3dx9_36/surface.c | 28 +++++------- dlls/d3dx9_36/util.c | 84 +++++++++++++++-------------------- 4 files changed, 50 insertions(+), 69 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index cf78e1a1444..03dc10973d5 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -115,8 +115,6 @@ struct pixel_format_desc { enum component_type a_type; enum component_type rgb_type; uint32_t flags; - void (*from_rgba)(const struct vec4 *src, struct vec4 *dst); - void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette); };
struct d3dx_pixels @@ -228,7 +226,8 @@ 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_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, struct d3dx_color *dst); +void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, const PALETTEENTRY *palette, + 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, diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c index f256b7b2662..92eb8f68f14 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -3093,7 +3093,7 @@ HRESULT WINAPI D3DXSHProjectCubeMap(unsigned int order, IDirect3DCubeTexture9 *t D3DXVec3Normalize(&dir, &dir); D3DXSHEvalDirection(temp, order, &dir);
- format_to_d3dx_color(format, &row[x * format->block_byte_count], &colour); + format_to_d3dx_color(format, &row[x * format->block_byte_count], NULL, &colour);
for (i = 0; i < order_square; ++i) { diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 50404f38328..c29ff13faa5 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1523,7 +1523,8 @@ static enum range get_range_for_component_type(enum component_type type) }
/* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */ -void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, struct d3dx_color *dst) +void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *src, const PALETTEENTRY *palette, + struct d3dx_color *dst) { DWORD mask, tmp; unsigned int c; @@ -1553,8 +1554,11 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr *dst_component = *(float *)&tmp; break;
- case CTYPE_LUMA: case CTYPE_INDEX: + *dst_component = (&palette[tmp].peRed)[component_offsets[c]] / 255.0f; + break; + + case CTYPE_LUMA: case CTYPE_UNORM: *dst_component = (float)tmp / mask; break; @@ -1759,8 +1763,7 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
for (x = 0; x < min_width; x++) { - if (!src_format->to_rgba && !dst_format->from_rgba - && format_types_match(src_format, dst_format) + if (format_types_match(src_format, dst_format) && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) { DWORD val; @@ -1783,10 +1786,8 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit { struct d3dx_color color, tmp;
- format_to_d3dx_color(src_format, src_ptr, &color); + format_to_d3dx_color(src_format, src_ptr, palette, &color); tmp = color; - if (src_format->to_rgba) - src_format->to_rgba(&color.value, &tmp.value, palette);
if (color_key) { @@ -1798,9 +1799,6 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit }
color = tmp; - if (dst_format->from_rgba) - dst_format->from_rgba(&tmp.value, &color.value); - format_from_d3dx_color(dst_format, &color, dst_ptr); }
@@ -1865,8 +1863,7 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic { const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
- if (!src_format->to_rgba && !dst_format->from_rgba - && format_types_match(src_format, dst_format) + if (format_types_match(src_format, dst_format) && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) { DWORD val; @@ -1889,10 +1886,8 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic { struct d3dx_color color, tmp;
- format_to_d3dx_color(src_format, src_ptr, &color); + format_to_d3dx_color(src_format, src_ptr, palette, &color); tmp = color; - if (src_format->to_rgba) - src_format->to_rgba(&color.value, &tmp.value, palette);
if (color_key) { @@ -1904,9 +1899,6 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic }
color = tmp; - if (dst_format->from_rgba) - dst_format->from_rgba(&tmp.value, &color.value); - format_from_d3dx_color(dst_format, &color, dst_ptr); }
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 44b289450a8..39d33816bcb 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -22,16 +22,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
-static void index_to_rgba(const struct vec4 *index, struct vec4 *rgba, const PALETTEENTRY *palette) -{ - ULONG idx = (ULONG)(index->x * 255.0f + 0.5f); - - rgba->x = palette[idx].peRed / 255.0f; - rgba->y = palette[idx].peGreen / 255.0f; - rgba->z = palette[idx].peBlue / 255.0f; - rgba->w = palette[idx].peFlags / 255.0f; /* peFlags is the alpha component in DX8 and higher */ -} - /************************************************************ * pixel format table providing info about number of bytes per pixel, * number of bits per channel and format type. @@ -40,44 +30,44 @@ static void index_to_rgba(const struct vec4 *index, struct vec4 *rgba, const PAL */ static const struct pixel_format_desc formats[] = { - /* format bpc shifts bpp blocks alpha type rgb type flags from_rgba to_rgba */ - {D3DFMT_R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A8R8G8B8, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_X8R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A8B8G8R8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_X8B8G8R8, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_R5G6B5, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_X1R5G5B5, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A1R5G5B5, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_R3G3B2, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A8R3G3B2, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A4R4G4B4, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_X4R4G4B4, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A2R10G10B10, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A2B10G10R10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0, NULL, NULL }, - {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0, NULL, NULL }, - {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0, NULL, NULL }, - {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0, NULL, NULL }, - {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0, NULL, NULL }, - {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0, NULL, NULL }, - {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, - {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, - {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, - {D3DFMT_DXT4, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, - {D3DFMT_DXT5, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT, NULL, NULL }, - {D3DFMT_R16F, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_G16R16F, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_FLOAT, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_R32F, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0, NULL, NULL }, - {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0, NULL, index_to_rgba}, - {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0, NULL, NULL }, - {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0, NULL, NULL }, + /* format bpc shifts bpp blocks alpha type rgb type flags */ + {D3DFMT_R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A8R8G8B8, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_X8R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A8B8G8R8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_X8B8G8R8, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_R5G6B5, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_X1R5G5B5, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A1R5G5B5, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_R3G3B2, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A8R3G3B2, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_A4R4G4B4, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_X4R4G4B4, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A2R10G10B10, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_A2B10G10R10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0 }, + {D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0 }, + {D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0 }, + {D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0 }, + {D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0 }, + {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DFMT_DXT4, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DFMT_DXT5, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DFMT_R16F, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DFMT_G16R16F, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, + {D3DFMT_R32F, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, + {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, + {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, + {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, /* marks last element */ - {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0, NULL, NULL }, + {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, };
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 46 +++++++++++++++++------------------ dlls/d3dx9_36/util.c | 1 + 2 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index f3053b165c9..02c5ac010b9 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -739,7 +739,7 @@ static void test_D3DXGetImageInfo(void) check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4); check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8); todo_wine check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16); - todo_wine check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8); + check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8);
test_dds_header_handling();
@@ -2254,19 +2254,17 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* X8L8V8U8 unorm/snorm. */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_x8l8v8u8, D3DFMT_X8L8V8U8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - /* The luma value goes into the alpha channel. */ - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_float4(&lockrect, 0, 0, 0.0, 3.77952754e-001f, 1.0f, 0.0f, 0, FALSE); - check_pixel_float4(&lockrect, 1, 0, 5.03937006e-001f, 1.0f, 1.0f, 3.33333343e-001, 0, FALSE); - check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, 1.0f, 6.66666687e-001, 0, FALSE); - check_pixel_float4(&lockrect, 1, 1, -5.03937006e-001f, -7.87401572e-003f, 1.0f, 1.0f, 0, FALSE); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + /* The luma value goes into the alpha channel. */ + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_float4(&lockrect, 0, 0, 0.0, 3.77952754e-001f, 1.0f, 0.0f, 0, FALSE); + check_pixel_float4(&lockrect, 1, 0, 5.03937006e-001f, 1.0f, 1.0f, 3.33333343e-001, 0, FALSE); + check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, 1.0f, 6.66666687e-001, 0, FALSE); + check_pixel_float4(&lockrect, 1, 1, -5.03937006e-001f, -7.87401572e-003f, 1.0f, 1.0f, 0, FALSE); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
check_release((IUnknown*)surf, 0); } @@ -2349,7 +2347,7 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) SetRect(&rect, 0, 0, 2, 2); hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8_2, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
/* * The luma channel here doesn't do RGB->Luma conversion, it just @@ -2358,10 +2356,10 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) */ hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - todo_wine check_pixel_4bpp(&lockrect, 0, 0, 0x00309282); - todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0x0070d2c2); - todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0x00b01000); - todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0x00ff5040); + check_pixel_4bpp(&lockrect, 0, 0, 0x00309282); + check_pixel_4bpp(&lockrect, 1, 0, 0x0070d2c2); + check_pixel_4bpp(&lockrect, 0, 1, 0x00b01000); + check_pixel_4bpp(&lockrect, 1, 1, 0x00ff5040); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
@@ -2372,14 +2370,14 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - todo_wine check_pixel_4bpp(&lockrect, 0, 0, 0x00b01000); - todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0x00ff5040); - todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0x002f8282); - todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0x007ed1c1); + check_pixel_4bpp(&lockrect, 0, 0, 0x00b01000); + check_pixel_4bpp(&lockrect, 1, 0, 0x00ff5040); + check_pixel_4bpp(&lockrect, 0, 1, 0x002f8282); + check_pixel_4bpp(&lockrect, 1, 1, 0x007ed1c1); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 39d33816bcb..a618100870a 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -66,6 +66,7 @@ static const struct pixel_format_desc formats[] = {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, + {D3DFMT_X8L8V8U8, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, /* marks last element */ {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, };
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 10 +++++----- dlls/d3dx9_36/util.c | 1 + 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 02c5ac010b9..72fdb627e78 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -2240,14 +2240,14 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* A2W10V10U10 unorm/snorm. */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2w10v10u10, D3DFMT_A2W10V10U10, 8, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_float4(&lockrect, 0, 0, 0.0f, 1.81996077e-001f, 3.63992155e-001f, 0.0f, 0, TRUE); - check_pixel_float4(&lockrect, 1, 0, 5.45988262e-001f, 7.27984309e-001f, 1.0f, 3.33333343e-001f, 0, TRUE); - check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, -5.47945201e-001f, 6.66666687e-001f, 0, TRUE); - check_pixel_float4(&lockrect, 1, 1, -3.65949124e-001f, -1.83953032e-001f, -1.95694715e-003f, 1.0f, 0, TRUE); + check_pixel_float4(&lockrect, 0, 0, 0.0f, 1.81996077e-001f, 3.63992155e-001f, 0.0f, 1, FALSE); + check_pixel_float4(&lockrect, 1, 0, 5.45988262e-001f, 7.27984309e-001f, 1.0f, 3.33333343e-001f, 1, FALSE); + check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, -5.47945201e-001f, 6.66666687e-001f, 0, FALSE); + check_pixel_float4(&lockrect, 1, 1, -3.65949124e-001f, -1.83953032e-001f, -1.95694715e-003f, 1.0f, 0, FALSE); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index a618100870a..b2ddaaba2c1 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -67,6 +67,7 @@ static const struct pixel_format_desc formats[] = {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, {D3DFMT_X8L8V8U8, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, + {D3DFMT_A2W10V10U10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, /* marks last element */ {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, };
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 11 +---------- dlls/d3dx9_36/util.c | 1 + 2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 72fdb627e78..46ae3c89c8f 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -1001,7 +1001,6 @@ static void test_format_conversion(IDirect3DDevice9 *device)
D3DFORMAT dst_format; const void *expected_dst_data; - BOOL partial_todo; BOOL todo; } tests[] = { { D3DFMT_P8, test_palette, { 0, 0, 2, 2 }, p8_2_2, D3DFMT_A8R8G8B8, p8_2_2_expected }, @@ -1010,7 +1009,7 @@ static void test_format_conversion(IDirect3DDevice9 *device) { D3DFMT_V16U16, NULL, { 0, 0, 2, 2 }, v16u16_2_2, D3DFMT_A32B32G32R32F, v16u16_2_2_expected2, .todo = TRUE }, { D3DFMT_V8U8, NULL, { 0, 0, 2, 2 }, v8u8_2_2, D3DFMT_A32B32G32R32F, v8u8_2_2_expected }, { D3DFMT_Q16W16V16U16, NULL, { 0, 0, 2, 2 }, q16w16v16u16_2_2, D3DFMT_A32B32G32R32F, q16w16v16u16_2_2_expected, .todo = TRUE }, - { D3DFMT_A8P8, test_palette, { 0, 0, 2, 2 }, a8p8_2_2, D3DFMT_A8R8G8B8, a8p8_2_2_expected, .todo = TRUE }, + { D3DFMT_A8P8, test_palette, { 0, 0, 2, 2 }, a8p8_2_2, D3DFMT_A8R8G8B8, a8p8_2_2_expected }, }; uint32_t i;
@@ -1037,11 +1036,9 @@ static void test_format_conversion(IDirect3DDevice9 *device) if (SUCCEEDED(hr)) { const uint32_t dst_fmt_bpp = get_bpp_for_d3dformat(tests[i].dst_format); - uint32_t mismatch_count; D3DLOCKED_RECT lock_rect; uint32_t x, y;
- mismatch_count = 0; IDirect3DSurface9_LockRect(surf, &lock_rect, NULL, D3DLOCK_READONLY); for (y = 0; y < tests[i].src_rect.bottom; ++y) { @@ -1054,16 +1051,10 @@ static void test_format_conversion(IDirect3DDevice9 *device) const uint8_t *dst_pixel = dst_row + (dst_fmt_bpp * x); BOOL pixel_match = !memcmp(dst_pixel, dst_expected_pixel, dst_fmt_bpp);
- if (!pixel_match) - mismatch_count++; - - if (!pixel_match && tests[i].partial_todo) - continue; todo_wine_if(tests[i].todo) ok(pixel_match, "Pixel mismatch at (%u,%u).\n", x, y); } }
- todo_wine_if(tests[i].partial_todo || tests[i].todo) ok(!mismatch_count, "%u mismatched pixels.\n", mismatch_count); IDirect3DSurface9_UnlockRect(surf); }
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index b2ddaaba2c1..de9f2d9771e 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -64,6 +64,7 @@ static const struct pixel_format_desc formats[] = {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, {D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, + {D3DFMT_A8P8, { 8, 8, 8, 8}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_INDEX, 0 }, {D3DFMT_Q8W8V8U8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, {D3DFMT_V8U8, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, {D3DFMT_X8L8V8U8, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 },
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=148697
Your paranoid android.
=== debian11b (64 bit WoW report) ===
d3d9: d3d9ex.c:3230: Test failed: Expected message 0x18 for window 0, but didn't receive it, i=0. d3d9ex.c:3236: Test failed: Got unexpected WINDOWPOS hwnd=0000000000000000, x=0, y=0, cx=0, cy=0, flags=0
winmm: mci: Timeout
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/d3dx9_private.h:
-enum format_type {
- FORMAT_ARGB, /* unsigned */
- FORMAT_ARGBF16,/* float 16 */
- FORMAT_ARGBF, /* float */
- FORMAT_ARGB_SNORM,
- FORMAT_DXT,
- FORMAT_INDEX,
- FORMAT_UNKNOWN
+enum component_type {
- CTYPE_EMPTY = 0x00,
- CTYPE_UNORM = 0x01,
- CTYPE_SNORM = 0x02,
- CTYPE_FLOAT = 0x03,
- CTYPE_LUMA = 0x04,
- CTYPE_INDEX = 0x05,
+};
Purely style issues, but: - the opening bracket should be on its own line - no reason to use hex initializers in this non-flag/bitmask case
Also, I'm guessing you just want `CTYPE_EMPTY` to be 0, i.e. don't care for the value of the other enum constants, right? If so, I'd leave out the other initializers to show that their particular value doesn't matter.
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
}
+static enum range get_range_for_component_type(enum component_type type) +{
- switch (type)
- {
- case CTYPE_SNORM:
return RANGE_SNORM;
- case CTYPE_LUMA:
- case CTYPE_INDEX:
- case CTYPE_UNORM:
return RANGE_UNORM;
- default:
return RANGE_FULL;
As an alternative, you could keep the `default:` label for unexpected values and make sure to explicitly list all the proper enum constants, like in the current code. Mostly just to make sure we don't forget to update this when adding a new type.
BTW, I think we usually indent the switch labels in "modern d3d style".
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
break; } }
else if (dst_ctype == CTYPE_LUMA)
{
*dst_component = dst->value.x;
This only works if we guarantee that all luma formats have a "red" component. Which is certainly expected to be the case, but...
I guess I'd like to see that guarantee enforced e.g. with an `assert(format->bits[1]);` here.
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/tests/surface.c:
SetRect(&rect, 0, 0, 2, 2); hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8_2, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); /* * The luma channel here doesn't do RGB->Luma conversion, it just
I realize only now that this means the `L8` channel isn't luma at all, IIUC. Maybe we should replace `luma` with `L8` in the comment, also for consistency with `V8` and `U8`.
This merge request was approved by Matteo Bruni.
I did leave this MR pending for way too long :/ I have a few comments but none block approval IMO.
On Mon Oct 7 08:51:36 2024 +0000, Matteo Bruni wrote:
I did leave this MR pending for way too long :/ I have a few comments but none block approval IMO.
Would you prefer if I change the things you've pointed out now, or can those wait for the next MR? Don't want to add another round of review work for you if I don't have to, but I am willing to change those things if you want me to :)
On Mon Oct 7 11:33:05 2024 +0000, Connor McAdams wrote:
Would you prefer if I change the things you've pointed out now, or can those wait for the next MR? Don't want to add another round of review work for you if I don't have to, but I am willing to change those things if you want me to :) I've already fixed these locally, just let me know if I should push them. I guess they're mostly style changes aside from the assert, so it shouldn't need too much review. :)
Either way is fine; I approved the MR already but I can certainly give it another look with the changes (agreed it should be quick :sweat_smile:)