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. :)
-- v2: d3dx9: Add support for D3DFMT_A8P8. d3dx9: Add support for D3DFMT_A2W10V10U10. d3dx9: Add support for D3DFMT_X8L8V8U8. d3dx9: Get rid of index_to_rgba callback. d3dx9: Get rid of la_{to,from}_rgba format callbacks. d3dx9: Always align and mask channel bits in format_to_d3dx_color(). d3dx9: Rework pixel_format_desc structure format type value.
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 | 49 +++++++++----- dlls/d3dx9_36/surface.c | 118 +++++++++++++++++++++++----------- dlls/d3dx9_36/texture.c | 6 +- dlls/d3dx9_36/util.c | 74 ++++++++++----------- 4 files changed, 154 insertions(+), 93 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index eb2594a43fa..acafe9d114a 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,19 @@ 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, + CTYPE_UNORM, + CTYPE_SNORM, + CTYPE_FLOAT, + CTYPE_LUMA, + CTYPE_INDEX, +}; + +enum format_flag +{ + FMT_FLAG_DXT = 0x01, };
struct pixel_format_desc { @@ -106,7 +114,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 +190,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..b30857aa384 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1505,32 +1505,39 @@ 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; + + case CTYPE_EMPTY: + case CTYPE_FLOAT: + return RANGE_FULL; + + default: + assert(0); + 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 +1548,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 +1582,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 +1604,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 b30857aa384..45a8a4abaf4 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1547,6 +1547,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) { @@ -1560,26 +1561,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 | 17 +++++++++++++++++ dlls/d3dx9_36/util.c | 22 ++++------------------ 2 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 45a8a4abaf4..8662b5b3b47 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1584,8 +1584,15 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr break; } } + else if (dst_ctype == CTYPE_LUMA) + { + assert(format->bits[1]); + *dst_component = dst->value.x; + } else + { *dst_component = 1.0f; + } } }
@@ -1619,6 +1626,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 acafe9d114a..503dbfdc924 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -117,8 +117,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 @@ -230,7 +228,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 8662b5b3b47..2439bc7f8bd 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1528,7 +1528,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; @@ -1558,8 +1559,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; @@ -1765,8 +1769,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; @@ -1789,10 +1792,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) { @@ -1804,9 +1805,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); }
@@ -1871,8 +1869,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; @@ -1895,10 +1892,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) { @@ -1910,9 +1905,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 | 48 +++++++++++++++++------------------ dlls/d3dx9_36/util.c | 1 + 2 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index f3053b165c9..21eec71a2e3 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,19 +2347,19 @@ 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 + * The L8 channel here doesn't do RGB->Luma conversion, it just * copies the alpha channel directly as UNORM. V8 and U8 are snorm, * pulled from r/g respectively. The X8 (b) channel is set to 0. */ 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 21eec71a2e3..b6f8092ba97 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 b6f8092ba97..b6eabe16983 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 },
On Mon Oct 7 13:28:30 2024 +0000, Matteo Bruni wrote:
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.
Did you see this comment? Just making sure, it's not critical or anything.
On Mon Oct 7 13:33:16 2024 +0000, Matteo Bruni wrote:
Did you see this comment? Just making sure, it's not critical or anything.
https://gitlab.winehq.org/wine/wine/-/merge_requests/6568/diffs?commit_id=f9... it should be changed in the current revision, unless I'm looking at the wrong thing.
On Mon Oct 7 13:33:16 2024 +0000, Connor McAdams wrote:
https://gitlab.winehq.org/wine/wine/-/merge_requests/6568/diffs?commit_id=f9... it should be changed in the current revision, unless I'm looking at the wrong thing.
That's what happens when I look at the diff with the older version but also forget that I added the assert in that branch as well...