This MR contains a set of patches that move away from using `D3DFORMAT` inside of `struct d3dx_image`. This will allow us to support formats that do not have a direct mapping to `D3DFORMAT`, and eventually once we share code with d3dx10/d3dx11 formats that do not have a direct mapping to `DXGI_FORMAT`.
I've pushed a branch [here](https://gitlab.winehq.org/cmcadams/wine/-/tree/UPSTREAM/d3dx9-new-fmt-id-v1?...) containing patches that actually use this new internal format system in practice. I would've included those in this MR, but that seemed like it'd make for a rather large MR. Hopefully splitting it this way makes it easier to review. :)
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 60 +++++++++- dlls/d3dx9_36/surface.c | 32 ++--- dlls/d3dx9_36/texture.c | 7 +- dlls/d3dx9_36/util.c | 219 +++++++++++++++++++++++++--------- dlls/d3dx9_36/volume.c | 2 +- 5 files changed, 242 insertions(+), 78 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index d01682cc51e..2946731e74a 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -90,6 +90,56 @@ static inline void set_volume_struct(struct volume *volume, uint32_t width, uint volume->depth = depth; }
+/* These values act as indexes into the pixel_format_desc table. */ +enum d3dx_pixel_format_id +{ + D3DX_PIXEL_FORMAT_B8G8R8_UNORM, + D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM, + D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM, + D3DX_PIXEL_FORMAT_R8G8B8A8_UNORM, + D3DX_PIXEL_FORMAT_R8G8B8X8_UNORM, + D3DX_PIXEL_FORMAT_B5G6R5_UNORM, + D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM, + D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM, + D3DX_PIXEL_FORMAT_B2G3R3_UNORM, + D3DX_PIXEL_FORMAT_B2G3R3A8_UNORM, + D3DX_PIXEL_FORMAT_B4G4R4A4_UNORM, + D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM, + D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM, + D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM, + D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM, + D3DX_PIXEL_FORMAT_R16G16_UNORM, + D3DX_PIXEL_FORMAT_A8_UNORM, + D3DX_PIXEL_FORMAT_L8A8_UNORM, + D3DX_PIXEL_FORMAT_L4A4_UNORM, + D3DX_PIXEL_FORMAT_L8_UNORM, + D3DX_PIXEL_FORMAT_L16_UNORM, + D3DX_PIXEL_FORMAT_DXT1_UNORM, + D3DX_PIXEL_FORMAT_DXT2_UNORM, + D3DX_PIXEL_FORMAT_DXT3_UNORM, + D3DX_PIXEL_FORMAT_DXT4_UNORM, + D3DX_PIXEL_FORMAT_DXT5_UNORM, + D3DX_PIXEL_FORMAT_R16_FLOAT, + D3DX_PIXEL_FORMAT_R16G16_FLOAT, + D3DX_PIXEL_FORMAT_R16G16B16A16_FLOAT, + D3DX_PIXEL_FORMAT_R32_FLOAT, + D3DX_PIXEL_FORMAT_R32G32_FLOAT, + D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, + D3DX_PIXEL_FORMAT_P8_UINT, + D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, + D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, + D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM, + D3DX_PIXEL_FORMAT_U8V8_SNORM, + D3DX_PIXEL_FORMAT_U16V16_SNORM, + D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM, + D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM, + D3DX_PIXEL_FORMAT_R8G8_B8G8_UNORM, + D3DX_PIXEL_FORMAT_G8R8_G8B8_UNORM, + D3DX_PIXEL_FORMAT_UYVY, + D3DX_PIXEL_FORMAT_YUY2, + D3DX_PIXEL_FORMAT_COUNT, +}; + /* for internal use */ enum component_type { @@ -108,7 +158,7 @@ enum format_flag };
struct pixel_format_desc { - D3DFORMAT format; + enum d3dx_pixel_format_id format; BYTE bits[4]; BYTE shift[4]; UINT bytes_per_pixel; @@ -185,7 +235,7 @@ 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); + return (format->format == D3DX_PIXEL_FORMAT_COUNT); }
static inline BOOL is_index_format(const struct pixel_format_desc *format) @@ -232,6 +282,8 @@ HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer,
HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer);
+D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format); +const struct pixel_format_desc *get_d3dx_pixel_format_info(enum d3dx_pixel_format_id format); const struct pixel_format_desc *get_format_info(D3DFORMAT format); const struct pixel_format_desc *get_format_info_idx(int idx);
@@ -256,8 +308,8 @@ HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLO HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, IDirect3DSurface9 *temp_surface, BOOL update); HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pitch, - const PALETTEENTRY *palette, D3DFORMAT format, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, - uint32_t front, uint32_t back, struct d3dx_pixels *pixels); + const PALETTEENTRY *palette, enum d3dx_pixel_format_id format, uint32_t left, uint32_t top, uint32_t right, + uint32_t bottom, uint32_t front, uint32_t back, struct d3dx_pixels *pixels); HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, const struct pixel_format_desc *dst_desc, struct d3dx_pixels *src_pixels, const struct pixel_format_desc *src_desc, uint32_t filter_flags, uint32_t color_key); diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index dcffab5e5ce..a0601119873 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1100,12 +1100,14 @@ static HRESULT d3dx_image_tga_decode(const void *src_data, uint32_t src_data_siz * PALETTEENTRY is RGBA. */ src_desc = get_format_info(d3dx_get_tga_format_for_bpp(header->color_map_entrysize)); - hr = d3dx_calculate_pixels_size(src_desc->format, header->color_map_length, 1, &src_row_pitch, &src_slice_pitch); + hr = d3dx_calculate_pixels_size(d3dformat_from_d3dx_pixel_format_id(src_desc->format), header->color_map_length, + 1, &src_row_pitch, &src_slice_pitch); if (FAILED(hr)) goto exit;
dst_desc = get_format_info(D3DFMT_A8B8G8R8); - d3dx_calculate_pixels_size(dst_desc->format, 256, 1, &dst_row_pitch, &dst_slice_pitch); + d3dx_calculate_pixels_size(d3dformat_from_d3dx_pixel_format_id(dst_desc->format), 256, 1, &dst_row_pitch, + &dst_slice_pitch); convert_argb_pixels(src_palette, src_row_pitch, src_slice_pitch, &image_map_size, src_desc, (BYTE *)palette, dst_row_pitch, dst_slice_pitch, &image_map_size, dst_desc, 0, NULL);
@@ -2203,17 +2205,17 @@ static HRESULT d3dx_pixels_decompress(struct d3dx_pixels *pixels, const struct p
switch (desc->format) { - case D3DFMT_DXT1: + case D3DX_PIXEL_FORMAT_DXT1_UNORM: uncompressed_desc = get_format_info(D3DFMT_A8B8G8R8); fetch_dxt_texel = fetch_2d_texel_rgba_dxt1; break; - case D3DFMT_DXT2: - case D3DFMT_DXT3: + case D3DX_PIXEL_FORMAT_DXT2_UNORM: + case D3DX_PIXEL_FORMAT_DXT3_UNORM: uncompressed_desc = get_format_info(D3DFMT_A8B8G8R8); fetch_dxt_texel = fetch_2d_texel_rgba_dxt3; break; - case D3DFMT_DXT4: - case D3DFMT_DXT5: + case D3DX_PIXEL_FORMAT_DXT4_UNORM: + case D3DX_PIXEL_FORMAT_DXT5_UNORM: uncompressed_desc = get_format_info(D3DFMT_A8B8G8R8); fetch_dxt_texel = fetch_2d_texel_rgba_dxt5; break; @@ -2278,10 +2280,10 @@ exit: }
HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pitch, - const PALETTEENTRY *palette, D3DFORMAT format, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, - uint32_t front, uint32_t back, struct d3dx_pixels *pixels) + const PALETTEENTRY *palette, enum d3dx_pixel_format_id format, uint32_t left, uint32_t top, uint32_t right, + uint32_t bottom, uint32_t front, uint32_t back, struct d3dx_pixels *pixels) { - const struct pixel_format_desc *fmt_desc = get_format_info(format); + const struct pixel_format_desc *fmt_desc = get_d3dx_pixel_format_info(format); const BYTE *ptr = data; RECT unaligned_rect;
@@ -2429,15 +2431,15 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, TRACE("Compressing DXTn surface.\n"); switch (dst_desc->format) { - case D3DFMT_DXT1: + case D3DX_PIXEL_FORMAT_DXT1_UNORM: gl_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; - case D3DFMT_DXT2: - case D3DFMT_DXT3: + case D3DX_PIXEL_FORMAT_DXT2_UNORM: + case D3DX_PIXEL_FORMAT_DXT3_UNORM: gl_format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; - case D3DFMT_DXT4: - case D3DFMT_DXT5: + case D3DX_PIXEL_FORMAT_DXT4_UNORM: + case D3DX_PIXEL_FORMAT_DXT5_UNORM: gl_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; default: diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index fda6d44fe5a..6e220e39203 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -274,17 +274,20 @@ static HRESULT check_texture_requirements(struct IDirect3DDevice9 *device, UINT { unsigned int curchannels = !!curfmt->bits[0] + !!curfmt->bits[1] + !!curfmt->bits[2] + !!curfmt->bits[3]; + D3DFORMAT cur_d3dfmt; int score;
i++;
+ if ((cur_d3dfmt = d3dformat_from_d3dx_pixel_format_id(curfmt->format)) == D3DFMT_UNKNOWN) + continue; if (curchannels < channels) continue; if (curfmt->bytes_per_pixel == 3 && !allow_24bits) continue;
hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, - mode.Format, usage, resource_type, curfmt->format); + mode.Format, usage, resource_type, cur_d3dfmt); if (FAILED(hr)) continue;
@@ -302,7 +305,7 @@ static HRESULT check_texture_requirements(struct IDirect3DDevice9 *device, UINT if (score > bestscore) { bestscore = score; - usedformat = curfmt->format; + usedformat = cur_d3dfmt; bestfmt = curfmt; } } diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 31b6bdaeb8a..7126b4779dc 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -30,55 +30,162 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3dx); */ static const struct pixel_format_desc formats[] = { - /* 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_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_Q16W16V16U16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, 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_V16U16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, 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 }, - {D3DFMT_R8G8_B8G8, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, - {D3DFMT_G8R8_G8B8, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, - {D3DFMT_UYVY, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, - {D3DFMT_YUY2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + /* format bpc shifts bpp blocks alpha type rgb type flags */ + {D3DX_PIXEL_FORMAT_B8G8R8_UNORM, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R8G8B8A8_UNORM, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R8G8B8X8_UNORM, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B5G6R5_UNORM, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B2G3R3_UNORM, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B2G3R3A8_UNORM, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B4G4R4A4_UNORM, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R16G16_UNORM, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_A8_UNORM, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0 }, + {D3DX_PIXEL_FORMAT_L8A8_UNORM, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_LUMA, 0 }, + {D3DX_PIXEL_FORMAT_L4A4_UNORM, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_LUMA, 0 }, + {D3DX_PIXEL_FORMAT_L8_UNORM, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_EMPTY, CTYPE_LUMA, 0 }, + {D3DX_PIXEL_FORMAT_L16_UNORM, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_LUMA, 0 }, + {D3DX_PIXEL_FORMAT_DXT1_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DX_PIXEL_FORMAT_DXT2_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DX_PIXEL_FORMAT_DXT3_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DX_PIXEL_FORMAT_DXT4_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DX_PIXEL_FORMAT_DXT5_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, CTYPE_UNORM, CTYPE_UNORM, FMT_FLAG_DXT}, + {D3DX_PIXEL_FORMAT_R16_FLOAT, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_R16G16_FLOAT, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_R16G16B16A16_FLOAT, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_R32_FLOAT, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_R32G32_FLOAT, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_P8_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, + {D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, { 8, 8, 8, 8}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_INDEX, 0 }, + {D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_SNORM, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U8V8_SNORM, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U16V16_SNORM, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_R8G8_B8G8_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DX_PIXEL_FORMAT_G8R8_G8B8_UNORM, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DX_PIXEL_FORMAT_UYVY, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DX_PIXEL_FORMAT_YUY2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, /* marks last element */ - {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, + {D3DX_PIXEL_FORMAT_COUNT, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, };
+D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format) +{ + switch (format) + { + case D3DX_PIXEL_FORMAT_B8G8R8_UNORM: return D3DFMT_R8G8B8; + case D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8; + case D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8; + case D3DX_PIXEL_FORMAT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8; + case D3DX_PIXEL_FORMAT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8; + case D3DX_PIXEL_FORMAT_B5G6R5_UNORM: return D3DFMT_R5G6B5; + case D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5; + case D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5; + case D3DX_PIXEL_FORMAT_B2G3R3_UNORM: return D3DFMT_R3G3B2; + case D3DX_PIXEL_FORMAT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2; + case D3DX_PIXEL_FORMAT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4; + case D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4; + case D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10; + case D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10; + case D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16; + case D3DX_PIXEL_FORMAT_R16G16_UNORM: return D3DFMT_G16R16; + case D3DX_PIXEL_FORMAT_A8_UNORM: return D3DFMT_A8; + case D3DX_PIXEL_FORMAT_L8A8_UNORM: return D3DFMT_A8L8; + case D3DX_PIXEL_FORMAT_L4A4_UNORM: return D3DFMT_A4L4; + case D3DX_PIXEL_FORMAT_L8_UNORM: return D3DFMT_L8; + case D3DX_PIXEL_FORMAT_L16_UNORM: return D3DFMT_L16; + case D3DX_PIXEL_FORMAT_DXT1_UNORM: return D3DFMT_DXT1; + case D3DX_PIXEL_FORMAT_DXT2_UNORM: return D3DFMT_DXT2; + case D3DX_PIXEL_FORMAT_DXT3_UNORM: return D3DFMT_DXT3; + case D3DX_PIXEL_FORMAT_DXT4_UNORM: return D3DFMT_DXT4; + case D3DX_PIXEL_FORMAT_DXT5_UNORM: return D3DFMT_DXT5; + case D3DX_PIXEL_FORMAT_R16_FLOAT: return D3DFMT_R16F; + case D3DX_PIXEL_FORMAT_R16G16_FLOAT: return D3DFMT_G16R16F; + case D3DX_PIXEL_FORMAT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F; + case D3DX_PIXEL_FORMAT_R32_FLOAT: return D3DFMT_R32F; + case D3DX_PIXEL_FORMAT_R32G32_FLOAT: return D3DFMT_G32R32F; + case D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F; + case D3DX_PIXEL_FORMAT_P8_UINT: return D3DFMT_P8; + case D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM: return D3DFMT_A8P8; + case D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM: return D3DFMT_Q8W8V8U8; + case D3DX_PIXEL_FORMAT_U8V8_SNORM: return D3DFMT_V8U8; + case D3DX_PIXEL_FORMAT_U16V16_SNORM: return D3DFMT_V16U16; + case D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8; + case D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10; + case D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM: return D3DFMT_Q16W16V16U16; + case D3DX_PIXEL_FORMAT_G8R8_G8B8_UNORM: return D3DFMT_G8R8_G8B8; + case D3DX_PIXEL_FORMAT_R8G8_B8G8_UNORM: return D3DFMT_R8G8_B8G8; + case D3DX_PIXEL_FORMAT_UYVY: return D3DFMT_UYVY; + case D3DX_PIXEL_FORMAT_YUY2: return D3DFMT_YUY2; + default: + FIXME("Unknown d3dx_pixel_format_id %u.\n", format); + return D3DFMT_UNKNOWN; + } +} + +static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_d3dformat(D3DFORMAT format) +{ + switch (format) + { + case D3DFMT_R8G8B8: return D3DX_PIXEL_FORMAT_B8G8R8_UNORM; + case D3DFMT_A8R8G8B8: return D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM; + case D3DFMT_X8R8G8B8: return D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM; + case D3DFMT_A8B8G8R8: return D3DX_PIXEL_FORMAT_R8G8B8A8_UNORM; + case D3DFMT_X8B8G8R8: return D3DX_PIXEL_FORMAT_R8G8B8X8_UNORM; + case D3DFMT_R5G6B5: return D3DX_PIXEL_FORMAT_B5G6R5_UNORM; + case D3DFMT_X1R5G5B5: return D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM; + case D3DFMT_A1R5G5B5: return D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM; + case D3DFMT_R3G3B2: return D3DX_PIXEL_FORMAT_B2G3R3_UNORM; + case D3DFMT_A8R3G3B2: return D3DX_PIXEL_FORMAT_B2G3R3A8_UNORM; + case D3DFMT_A4R4G4B4: return D3DX_PIXEL_FORMAT_B4G4R4A4_UNORM; + case D3DFMT_X4R4G4B4: return D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM; + case D3DFMT_A2R10G10B10: return D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM; + case D3DFMT_A2B10G10R10: return D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM; + case D3DFMT_A16B16G16R16: return D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM; + case D3DFMT_G16R16: return D3DX_PIXEL_FORMAT_R16G16_UNORM; + case D3DFMT_A8: return D3DX_PIXEL_FORMAT_A8_UNORM; + case D3DFMT_A8L8: return D3DX_PIXEL_FORMAT_L8A8_UNORM; + case D3DFMT_A4L4: return D3DX_PIXEL_FORMAT_L4A4_UNORM; + case D3DFMT_L8: return D3DX_PIXEL_FORMAT_L8_UNORM; + case D3DFMT_L16: return D3DX_PIXEL_FORMAT_L16_UNORM; + case D3DFMT_DXT1: return D3DX_PIXEL_FORMAT_DXT1_UNORM; + case D3DFMT_DXT2: return D3DX_PIXEL_FORMAT_DXT2_UNORM; + case D3DFMT_DXT3: return D3DX_PIXEL_FORMAT_DXT3_UNORM; + case D3DFMT_DXT4: return D3DX_PIXEL_FORMAT_DXT4_UNORM; + case D3DFMT_DXT5: return D3DX_PIXEL_FORMAT_DXT5_UNORM; + case D3DFMT_R16F: return D3DX_PIXEL_FORMAT_R16_FLOAT; + case D3DFMT_G16R16F: return D3DX_PIXEL_FORMAT_R16G16_FLOAT; + case D3DFMT_A16B16G16R16F: return D3DX_PIXEL_FORMAT_R16G16B16A16_FLOAT; + case D3DFMT_R32F: return D3DX_PIXEL_FORMAT_R32_FLOAT; + case D3DFMT_G32R32F: return D3DX_PIXEL_FORMAT_R32G32_FLOAT; + case D3DFMT_A32B32G32R32F: return D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT; + case D3DFMT_P8: return D3DX_PIXEL_FORMAT_P8_UINT; + case D3DFMT_A8P8: return D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM; + case D3DFMT_Q8W8V8U8: return D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM; + case D3DFMT_V8U8: return D3DX_PIXEL_FORMAT_U8V8_SNORM; + case D3DFMT_V16U16: return D3DX_PIXEL_FORMAT_U16V16_SNORM; + case D3DFMT_X8L8V8U8: return D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM; + case D3DFMT_A2W10V10U10: return D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM; + case D3DFMT_Q16W16V16U16: return D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM; + case D3DFMT_R8G8_B8G8: return D3DX_PIXEL_FORMAT_R8G8_B8G8_UNORM; + case D3DFMT_G8R8_G8B8: return D3DX_PIXEL_FORMAT_G8R8_G8B8_UNORM; + case D3DFMT_UYVY: return D3DX_PIXEL_FORMAT_UYVY; + case D3DFMT_YUY2: return D3DX_PIXEL_FORMAT_YUY2; + default: + FIXME("No d3dx_pixel_format_id for D3DFORMAT %s.\n", debugstr_fourcc(format)); + return D3DX_PIXEL_FORMAT_COUNT; + } +}
/************************************************************ * map_view_of_file @@ -185,12 +292,16 @@ HRESULT write_buffer_to_file(const WCHAR *dst_filename, ID3DXBuffer *buffer) return hr; }
+const struct pixel_format_desc *get_d3dx_pixel_format_info(enum d3dx_pixel_format_id format) +{ + return &formats[min(format, D3DX_PIXEL_FORMAT_COUNT)]; +}
/************************************************************ * get_format_info * * Returns information about the specified format. - * If the format is unsupported, it's filled with the D3DFMT_UNKNOWN desc. + * If the format is unsupported, it's filled with the D3DX_PIXEL_FORMAT_COUNT desc. * * PARAMS * format [I] format whose description is queried @@ -198,20 +309,16 @@ HRESULT write_buffer_to_file(const WCHAR *dst_filename, ID3DXBuffer *buffer) */ const struct pixel_format_desc *get_format_info(D3DFORMAT format) { - unsigned int i = 0; - while(formats[i].format != format && formats[i].format != D3DFMT_UNKNOWN) i++; - if (formats[i].format == D3DFMT_UNKNOWN) + const struct pixel_format_desc *fmt_desc = &formats[d3dx_pixel_format_id_from_d3dformat(format)]; + + if (is_unknown_format(fmt_desc)) FIXME("Unknown format %s.\n", debugstr_fourcc(format)); - return &formats[i]; + return fmt_desc; }
const struct pixel_format_desc *get_format_info_idx(int idx) { - if(idx >= ARRAY_SIZE(formats)) - return NULL; - if(formats[idx].format == D3DFMT_UNKNOWN) - return NULL; - return &formats[idx]; + return idx < D3DX_PIXEL_FORMAT_COUNT ? &formats[idx] : NULL; }
#define WINE_D3DX_TO_STR(x) case x: return #x diff --git a/dlls/d3dx9_36/volume.c b/dlls/d3dx9_36/volume.c index 0d7fe4a7870..46a30bfeba1 100644 --- a/dlls/d3dx9_36/volume.c +++ b/dlls/d3dx9_36/volume.c @@ -136,7 +136,7 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, }
hr = d3dx_pixels_init(src_memory, src_row_pitch, src_slice_pitch, - src_palette, src_format, src_box->Left, src_box->Top, src_box->Right, src_box->Bottom, + src_palette, src_format_desc->format, src_box->Left, src_box->Top, src_box->Right, src_box->Bottom, src_box->Front, src_box->Back, &src_pixels); if (FAILED(hr)) return hr;
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 3 +- dlls/d3dx9_36/surface.c | 63 ++++++++++++++++++----------------- dlls/d3dx9_36/texture.c | 6 ++-- dlls/d3dx9_36/util.c | 2 +- dlls/d3dx9_36/volume.c | 5 +-- 5 files changed, 41 insertions(+), 38 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index 2946731e74a..6c1db3f2e31 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -197,7 +197,7 @@ static inline void set_d3dx_pixels(struct d3dx_pixels *pixels, const void *data, struct d3dx_image { D3DRESOURCETYPE resource_type; - D3DFORMAT format; + enum d3dx_pixel_format_id format;
struct volume size; uint32_t mip_levels; @@ -283,6 +283,7 @@ HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer);
D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format); +enum d3dx_pixel_format_id d3dx_pixel_format_id_from_d3dformat(D3DFORMAT format); const struct pixel_format_desc *get_d3dx_pixel_format_info(enum d3dx_pixel_format_id format); const struct pixel_format_desc *get_format_info(D3DFORMAT format); const struct pixel_format_desc *get_format_info_idx(int idx); diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index a0601119873..9a6037b3787 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -405,10 +405,10 @@ static const char *debug_volume(const struct volume *volume) return wine_dbg_sprintf("(%ux%ux%u)", volume->width, volume->height, volume->depth); }
-static HRESULT d3dx_calculate_pixels_size(D3DFORMAT format, uint32_t width, uint32_t height, +static HRESULT d3dx_calculate_pixels_size(enum d3dx_pixel_format_id format, uint32_t width, uint32_t height, uint32_t *pitch, uint32_t *size) { - const struct pixel_format_desc *format_desc = get_format_info(format); + const struct pixel_format_desc *format_desc = get_d3dx_pixel_format_info(format);
if (is_unknown_format(format_desc)) return E_NOTIMPL; @@ -429,7 +429,7 @@ static HRESULT d3dx_calculate_pixels_size(D3DFORMAT format, uint32_t width, uint return D3D_OK; }
-static uint32_t d3dx_calculate_layer_pixels_size(D3DFORMAT format, uint32_t width, uint32_t height, uint32_t depth, +static uint32_t d3dx_calculate_layer_pixels_size(enum d3dx_pixel_format_id format, uint32_t width, uint32_t height, uint32_t depth, uint32_t mip_levels) { uint32_t layer_size, row_pitch, slice_pitch, i; @@ -450,12 +450,13 @@ static uint32_t d3dx_calculate_layer_pixels_size(D3DFORMAT format, uint32_t widt static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces) { + const struct pixel_format_desc *fmt_desc = get_format_info(format); UINT i, file_size = 0;
for (i = 0; i < miplevels; i++) { UINT pitch, size = 0; - if (FAILED(d3dx_calculate_pixels_size(format, width, height, &pitch, &size))) + if (FAILED(d3dx_calculate_pixels_size(fmt_desc->format, width, height, &pitch, &size))) return 0; size *= depth; file_size += size; @@ -498,7 +499,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur if (!file_size) return D3DERR_INVALIDCALL;
- hr = d3dx_calculate_pixels_size(src_desc.Format, src_desc.Width, src_desc.Height, &dst_pitch, &surface_size); + hr = d3dx_calculate_pixels_size(pixel_format->format, src_desc.Width, src_desc.Height, &dst_pitch, &surface_size); if (FAILED(hr)) return hr;
hr = D3DXCreateBuffer(file_size, &buffer); @@ -613,10 +614,10 @@ static HRESULT d3dx_initialize_image_from_dds(const void *src_data, uint32_t src
set_volume_struct(&image->size, header->width, header->height, 1); image->mip_levels = header->miplevels ? header->miplevels : 1; - image->format = dds_pixel_format_to_d3dformat(&header->pixel_format); + image->format = d3dx_pixel_format_id_from_d3dformat(dds_pixel_format_to_d3dformat(&header->pixel_format)); image->layer_count = 1;
- if (image->format == D3DFMT_UNKNOWN) + if (image->format == D3DX_PIXEL_FORMAT_COUNT) return D3DXERR_INVALIDDATA;
TRACE("Pixel format is %#x.\n", image->format); @@ -752,7 +753,7 @@ static BOOL image_is_argb(IWICBitmapFrameDecode *frame, struct d3dx_image *image BYTE *buffer; HRESULT hr;
- if (image->format != D3DFMT_X8R8G8B8 || image->image_file_format != D3DXIFF_BMP) + if (image->format != D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM || image->image_file_format != D3DXIFF_BMP) return FALSE;
size = image->size.width * image->size.height * 4; @@ -829,7 +830,7 @@ static HRESULT d3dx_image_wic_frame_decode(struct d3dx_image *image, BYTE *buffer = NULL; HRESULT hr;
- fmt_desc = get_format_info(image->format); + fmt_desc = get_d3dx_pixel_format_info(image->format); hr = d3dx_calculate_pixels_size(image->format, image->size.width, image->size.height, &row_pitch, &slice_pitch); if (FAILED(hr)) return hr; @@ -950,7 +951,8 @@ static HRESULT d3dx_initialize_image_from_wic(const void *src_data, uint32_t src if (FAILED(hr)) goto exit;
- if ((image->format = wic_guid_to_d3dformat(&pixel_format)) == D3DFMT_UNKNOWN) + image->format = d3dx_pixel_format_id_from_d3dformat(wic_guid_to_d3dformat(&pixel_format)); + if (image->format == D3DX_PIXEL_FORMAT_COUNT) { WARN("Unsupported pixel format %s.\n", debugstr_guid(&pixel_format)); hr = D3DXERR_INVALIDDATA; @@ -958,7 +960,7 @@ static HRESULT d3dx_initialize_image_from_wic(const void *src_data, uint32_t src }
if (image_is_argb(bitmap_frame, image)) - image->format = D3DFMT_A8R8G8B8; + image->format = D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM;
if (!(flags & D3DX_IMAGE_INFO_ONLY)) { @@ -984,17 +986,17 @@ exit: return hr; }
-static D3DFORMAT d3dx_get_tga_format_for_bpp(uint8_t bpp) +static enum d3dx_pixel_format_id d3dx_get_tga_format_for_bpp(uint8_t bpp) { switch (bpp) { - case 15: return D3DFMT_X1R5G5B5; - case 16: return D3DFMT_A1R5G5B5; - case 24: return D3DFMT_R8G8B8; - case 32: return D3DFMT_A8R8G8B8; + case 15: return D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM; + case 16: return D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM; + case 24: return D3DX_PIXEL_FORMAT_B8G8R8_UNORM; + case 32: return D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM; default: WARN("Unhandled bpp %u for targa.\n", bpp); - return D3DFMT_UNKNOWN; + return D3DX_PIXEL_FORMAT_COUNT; } }
@@ -1066,10 +1068,10 @@ static HRESULT d3dx_image_tga_rle_decode_row(const uint8_t **src, uint32_t src_b static HRESULT d3dx_image_tga_decode(const void *src_data, uint32_t src_data_size, uint32_t src_header_size, struct d3dx_image *image) { + const struct pixel_format_desc *fmt_desc = get_d3dx_pixel_format_info(image->format); const struct tga_header *header = (const struct tga_header *)src_data; const BOOL right_to_left = !!(header->image_descriptor & IMAGE_RIGHTTOLEFT); const BOOL bottom_to_top = !(header->image_descriptor & IMAGE_TOPTOBOTTOM); - const struct pixel_format_desc *fmt_desc = get_format_info(image->format); const BOOL is_rle = !!(header->image_type & IMAGETYPE_RLE); uint8_t *img_buf = NULL, *src_row = NULL; uint32_t row_pitch, slice_pitch, i; @@ -1085,7 +1087,7 @@ static HRESULT d3dx_image_tga_decode(const void *src_data, uint32_t src_data_siz if (!is_rle && (src_header_size + slice_pitch) > src_data_size) return D3DXERR_INVALIDDATA;
- if (image->format == D3DFMT_P8) + if (image->format == D3DX_PIXEL_FORMAT_P8_UINT) { const uint8_t *src_palette = ((const uint8_t *)src_data) + sizeof(*header) + header->id_length; const struct volume image_map_size = { header->color_map_length, 1, 1 }; @@ -1099,15 +1101,13 @@ static HRESULT d3dx_image_tga_decode(const void *src_data, uint32_t src_data_siz * Convert from a TGA colormap to PALETTEENTRY. TGA is BGRA, * PALETTEENTRY is RGBA. */ - src_desc = get_format_info(d3dx_get_tga_format_for_bpp(header->color_map_entrysize)); - hr = d3dx_calculate_pixels_size(d3dformat_from_d3dx_pixel_format_id(src_desc->format), header->color_map_length, - 1, &src_row_pitch, &src_slice_pitch); + src_desc = get_d3dx_pixel_format_info(d3dx_get_tga_format_for_bpp(header->color_map_entrysize)); + hr = d3dx_calculate_pixels_size(src_desc->format, header->color_map_length, 1, &src_row_pitch, &src_slice_pitch); if (FAILED(hr)) goto exit;
dst_desc = get_format_info(D3DFMT_A8B8G8R8); - d3dx_calculate_pixels_size(d3dformat_from_d3dx_pixel_format_id(dst_desc->format), 256, 1, &dst_row_pitch, - &dst_slice_pitch); + d3dx_calculate_pixels_size(dst_desc->format, 256, 1, &dst_row_pitch, &dst_slice_pitch); convert_argb_pixels(src_palette, src_row_pitch, src_slice_pitch, &image_map_size, src_desc, (BYTE *)palette, dst_row_pitch, dst_slice_pitch, &image_map_size, dst_desc, 0, NULL);
@@ -1206,7 +1206,7 @@ static HRESULT d3dx_initialize_image_from_tga(const void *src_data, uint32_t src return D3DXERR_INVALIDDATA;
if (header->color_map_type && ((header->color_map_type > 1) || (!header->color_map_length) - || (d3dx_get_tga_format_for_bpp(header->color_map_entrysize) == D3DFMT_UNKNOWN))) + || (d3dx_get_tga_format_for_bpp(header->color_map_entrysize) == D3DX_PIXEL_FORMAT_COUNT))) return D3DXERR_INVALIDDATA;
switch (header->image_type & IMAGETYPE_MASK) @@ -1214,18 +1214,18 @@ static HRESULT d3dx_initialize_image_from_tga(const void *src_data, uint32_t src case IMAGETYPE_COLORMAPPED: if (header->depth != 8 || !header->color_map_type) return D3DXERR_INVALIDDATA; - image->format = D3DFMT_P8; + image->format = D3DX_PIXEL_FORMAT_P8_UINT; break;
case IMAGETYPE_TRUECOLOR: - if ((image->format = d3dx_get_tga_format_for_bpp(header->depth)) == D3DFMT_UNKNOWN) + if ((image->format = d3dx_get_tga_format_for_bpp(header->depth)) == D3DX_PIXEL_FORMAT_COUNT) return D3DXERR_INVALIDDATA; break;
case IMAGETYPE_GRAYSCALE: if (header->depth != 8) return D3DXERR_INVALIDDATA; - image->format = D3DFMT_L8; + image->format = D3DX_PIXEL_FORMAT_L8_UNORM; break;
default: @@ -1360,7 +1360,7 @@ void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *ima info->Height = image->size.height; info->Depth = image->size.depth; info->MipLevels = image->mip_levels; - info->Format = image->format; + info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); info->ResourceType = image->resource_type; }
@@ -1564,8 +1564,9 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface, if (FAILED(hr)) goto exit;
- hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect, pixels.data, img_info.Format, - pixels.row_pitch, pixels.palette, &src_rect, dwFilter, Colorkey); + hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect, pixels.data, + d3dformat_from_d3dx_pixel_format_id(image.format), pixels.row_pitch, pixels.palette, &src_rect, dwFilter, + Colorkey); if (SUCCEEDED(hr) && pSrcInfo) *pSrcInfo = img_info;
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 6e220e39203..719a2787445 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -663,7 +663,7 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi
TRACE("Texture created correctly. Now loading the texture data into it.\n"); dst_fmt_desc = get_format_info(format); - src_fmt_desc = get_format_info(imginfo.Format); + src_fmt_desc = get_d3dx_pixel_format_info(image.format); loaded_miplevels = min(imginfo.MipLevels, IDirect3DTexture9_GetLevelCount(tex)); for (i = 0; i < loaded_miplevels; i++) { @@ -1194,7 +1194,7 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic
TRACE("Texture created correctly. Now loading the texture data into it.\n"); dst_fmt_desc = get_format_info(format); - src_fmt_desc = get_format_info(image_info.Format); + src_fmt_desc = get_d3dx_pixel_format_info(image.format); loaded_miplevels = min(image_info.MipLevels, IDirect3DVolumeTexture9_GetLevelCount(tex)); for (i = 0; i < loaded_miplevels; i++) { @@ -1429,7 +1429,7 @@ HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device,
TRACE("Texture created correctly. Now loading the texture data into it.\n"); dst_fmt_desc = get_format_info(format); - src_fmt_desc = get_format_info(img_info.Format); + src_fmt_desc = get_d3dx_pixel_format_info(image.format); loaded_miplevels = min(img_info.MipLevels, IDirect3DCubeTexture9_GetLevelCount(tex)); for (i = 0; i < loaded_miplevels; ++i) { diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 7126b4779dc..f2ea089ce82 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -133,7 +133,7 @@ D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format) } }
-static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_d3dformat(D3DFORMAT format) +enum d3dx_pixel_format_id d3dx_pixel_format_id_from_d3dformat(D3DFORMAT format) { switch (format) { diff --git a/dlls/d3dx9_36/volume.c b/dlls/d3dx9_36/volume.c index 46a30bfeba1..87c39e470f6 100644 --- a/dlls/d3dx9_36/volume.c +++ b/dlls/d3dx9_36/volume.c @@ -209,8 +209,9 @@ HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, cons if (FAILED(hr)) goto exit;
- hr = D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels.data, image_info.Format, - pixels.row_pitch, pixels.slice_pitch, pixels.palette, &box, filter, color_key); + hr = D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels.data, + d3dformat_from_d3dx_pixel_format_id(image.format), pixels.row_pitch, pixels.slice_pitch, pixels.palette, + &box, filter, color_key); if (SUCCEEDED(hr) && src_info) *src_info = image_info;
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 118 ++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 58 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 9a6037b3787..bafdec6a8b5 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -241,62 +241,63 @@ HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, static const struct { struct dds_pixel_format dds_pixel_format; - D3DFORMAT d3d_format; -} dds_pixel_formats[] = { + enum d3dx_pixel_format_id d3dx_pixel_format; +} dds_pixel_formats[] = +{ /* DDS_PF_FOURCC. */ - { { 32, DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y') }, D3DFMT_UYVY }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2') }, D3DFMT_YUY2 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G') }, D3DFMT_R8G8_B8G8 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B') }, D3DFMT_G8R8_G8B8 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1') }, D3DFMT_DXT1 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2') }, D3DFMT_DXT2 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3') }, D3DFMT_DXT3 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4') }, D3DFMT_DXT4 }, - { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5') }, D3DFMT_DXT5 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y') }, D3DX_PIXEL_FORMAT_UYVY }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2') }, D3DX_PIXEL_FORMAT_YUY2 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G') }, D3DX_PIXEL_FORMAT_R8G8_B8G8_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B') }, D3DX_PIXEL_FORMAT_G8R8_G8B8_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1') }, D3DX_PIXEL_FORMAT_DXT1_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2') }, D3DX_PIXEL_FORMAT_DXT2_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3') }, D3DX_PIXEL_FORMAT_DXT3_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4') }, D3DX_PIXEL_FORMAT_DXT4_UNORM }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5') }, D3DX_PIXEL_FORMAT_DXT5_UNORM }, /* These aren't actually fourcc values, they're just D3DFMT values. */ - { { 32, DDS_PF_FOURCC, 0x24 }, D3DFMT_A16B16G16R16 }, - { { 32, DDS_PF_FOURCC, 0x6e }, D3DFMT_Q16W16V16U16 }, - { { 32, DDS_PF_FOURCC, 0x6f }, D3DFMT_R16F, }, - { { 32, DDS_PF_FOURCC, 0x70 }, D3DFMT_G16R16F }, - { { 32, DDS_PF_FOURCC, 0x71 }, D3DFMT_A16B16G16R16F }, - { { 32, DDS_PF_FOURCC, 0x72 }, D3DFMT_R32F }, - { { 32, DDS_PF_FOURCC, 0x73 }, D3DFMT_G32R32F }, - { { 32, DDS_PF_FOURCC, 0x74 }, D3DFMT_A32B32G32R32F }, + { { 32, DDS_PF_FOURCC, 0x24 }, D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM }, + { { 32, DDS_PF_FOURCC, 0x6e }, D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM }, + { { 32, DDS_PF_FOURCC, 0x6f }, D3DX_PIXEL_FORMAT_R16_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x70 }, D3DX_PIXEL_FORMAT_R16G16_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x71 }, D3DX_PIXEL_FORMAT_R16G16B16A16_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x72 }, D3DX_PIXEL_FORMAT_R32_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x73 }, D3DX_PIXEL_FORMAT_R32G32_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x74 }, D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT }, /* DDS_PF_RGB. */ - { { 32, DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0x00 }, D3DFMT_R3G3B2 }, - { { 32, DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0x0000 }, D3DFMT_R5G6B5 }, - { { 32, DDS_PF_RGB, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x0000 }, D3DFMT_X1R5G5B5 }, - { { 32, DDS_PF_RGB, 0, 16, 0x0f00, 0x00f0, 0x000f, 0x0000 }, D3DFMT_X4R4G4B4 }, - { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, D3DFMT_R8G8B8 }, - { { 32, DDS_PF_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, D3DFMT_X8R8G8B8 }, - { { 32, DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DFMT_G16R16 }, - { { 32, DDS_PF_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DFMT_X8B8G8R8 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 }, D3DFMT_A8R3G3B2 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 }, D3DFMT_A1R5G5B5 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 }, D3DFMT_A4R4G4B4 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, D3DFMT_A8R8G8B8 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DFMT_A8B8G8R8 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DFMT_A2B10G10R10 }, - { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }, D3DFMT_A2R10G10B10 }, + { { 32, DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0x00 }, D3DX_PIXEL_FORMAT_B2G3R3_UNORM }, + { { 32, DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0x0000 }, D3DX_PIXEL_FORMAT_B5G6R5_UNORM }, + { { 32, DDS_PF_RGB, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x0000 }, D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM }, + { { 32, DDS_PF_RGB, 0, 16, 0x0f00, 0x00f0, 0x000f, 0x0000 }, D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM }, + { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, D3DX_PIXEL_FORMAT_B8G8R8_UNORM }, + { { 32, DDS_PF_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM }, + { { 32, DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DX_PIXEL_FORMAT_R16G16_UNORM }, + { { 32, DDS_PF_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DX_PIXEL_FORMAT_R8G8B8X8_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 }, D3DX_PIXEL_FORMAT_B2G3R3A8_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 }, D3DX_PIXEL_FORMAT_B5G5R5A1_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 }, D3DX_PIXEL_FORMAT_B4G4R4A4_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DX_PIXEL_FORMAT_R8G8B8A8_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }, D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM }, /* DDS_PF_INDEXED. */ - { { 32, DDS_PF_INDEXED, 0, 8 }, D3DFMT_P8 }, - { { 32, DDS_PF_INDEXED | DDS_PF_ALPHA, 0, 16, 0, 0, 0, 0xff00, }, D3DFMT_A8P8 }, + { { 32, DDS_PF_INDEXED, 0, 8 }, D3DX_PIXEL_FORMAT_P8_UINT }, + { { 32, DDS_PF_INDEXED | DDS_PF_ALPHA, 0, 16, 0, 0, 0, 0xff00, }, D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM }, /* DDS_PF_LUMINANCE. */ - { { 32, DDS_PF_LUMINANCE, 0, 8, 0x00ff }, D3DFMT_L8 }, - { { 32, DDS_PF_LUMINANCE, 0, 16, 0xffff }, D3DFMT_L16 }, - { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x000f, 0, 0, 0x00f0 }, D3DFMT_A4L4 }, - { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00 }, D3DFMT_A8L8 }, + { { 32, DDS_PF_LUMINANCE, 0, 8, 0x00ff }, D3DX_PIXEL_FORMAT_L8_UNORM }, + { { 32, DDS_PF_LUMINANCE, 0, 16, 0xffff }, D3DX_PIXEL_FORMAT_L16_UNORM }, + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x000f, 0, 0, 0x00f0 }, D3DX_PIXEL_FORMAT_L4A4_UNORM }, + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00 }, D3DX_PIXEL_FORMAT_L8A8_UNORM }, /* Exceptional case, A8L8 can also have 8bpp. */ - { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x00ff, 0, 0, 0xff00 }, D3DFMT_A8L8 }, + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x00ff, 0, 0, 0xff00 }, D3DX_PIXEL_FORMAT_L8A8_UNORM }, /* DDS_PF_ALPHA_ONLY. */ - { { 32, DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff }, D3DFMT_A8 }, + { { 32, DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff }, D3DX_PIXEL_FORMAT_A8_UNORM }, /* DDS_PF_BUMPDUDV. */ - { { 32, DDS_PF_BUMPDUDV, 0, 16, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 }, D3DFMT_V8U8 }, - { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DFMT_V16U16 }, - { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DFMT_Q8W8V8U8 }, - { { 32, DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DFMT_A2W10V10U10 }, + { { 32, DDS_PF_BUMPDUDV, 0, 16, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 }, D3DX_PIXEL_FORMAT_U8V8_SNORM }, + { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DX_PIXEL_FORMAT_U16V16_SNORM }, + { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM }, + { { 32, DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM }, /* DDS_PF_BUMPLUMINANCE. */ - { { 32, DDS_PF_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DFMT_X8L8V8U8 }, + { { 32, DDS_PF_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM }, };
static BOOL dds_pixel_format_compare(const struct dds_pixel_format *pf_a, const struct dds_pixel_format *pf_b, @@ -307,7 +308,7 @@ static BOOL dds_pixel_format_compare(const struct dds_pixel_format *pf_a, const || (check_amask && pf_a->amask != pf_b->amask)); }
-static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format) +static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_dds_pixel_format(const struct dds_pixel_format *pixel_format) { uint32_t i;
@@ -327,37 +328,37 @@ static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pi { case DDS_PF_ALPHA_ONLY: if (dds_pixel_format_compare(pixel_format, dds_pf, FALSE, FALSE, FALSE, TRUE)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_FOURCC: if (pixel_format->fourcc == dds_pf->fourcc) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_INDEXED: if (dds_pixel_format_compare(pixel_format, dds_pf, FALSE, FALSE, FALSE, pixel_format->flags & DDS_PF_ALPHA)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_RGB: if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, pixel_format->flags & DDS_PF_ALPHA)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_LUMINANCE: if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, FALSE, FALSE, pixel_format->flags & DDS_PF_ALPHA)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_BUMPLUMINANCE: if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, FALSE)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
case DDS_PF_BUMPDUDV: if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, TRUE)) - return dds_pixel_formats[i].d3d_format; + return dds_pixel_formats[i].d3dx_pixel_format; break;
default: @@ -369,18 +370,19 @@ static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pi WARN("Unknown pixel format (flags %#lx, fourcc %#lx, bpp %lu, r %#lx, g %#lx, b %#lx, a %#lx).\n", pixel_format->flags, pixel_format->fourcc, pixel_format->bpp, pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask); - return D3DFMT_UNKNOWN; + return D3DX_PIXEL_FORMAT_COUNT; }
static HRESULT d3dformat_to_dds_pixel_format(struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat) { + enum d3dx_pixel_format_id d3dx_pixel_format = d3dx_pixel_format_id_from_d3dformat(d3dformat); uint32_t i;
memset(pixel_format, 0, sizeof(*pixel_format)); pixel_format->size = sizeof(*pixel_format); for (i = 0; i < ARRAY_SIZE(dds_pixel_formats); ++i) { - if (dds_pixel_formats[i].d3d_format == d3dformat) + if (dds_pixel_formats[i].d3dx_pixel_format == d3dx_pixel_format) { *pixel_format = dds_pixel_formats[i].dds_pixel_format; return D3D_OK; @@ -614,7 +616,7 @@ static HRESULT d3dx_initialize_image_from_dds(const void *src_data, uint32_t src
set_volume_struct(&image->size, header->width, header->height, 1); image->mip_levels = header->miplevels ? header->miplevels : 1; - image->format = d3dx_pixel_format_id_from_d3dformat(dds_pixel_format_to_d3dformat(&header->pixel_format)); + image->format = d3dx_pixel_format_id_from_dds_pixel_format(&header->pixel_format); image->layer_count = 1;
if (image->format == D3DX_PIXEL_FORMAT_COUNT)
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index bafdec6a8b5..d8bd3cd8e2d 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -35,39 +35,42 @@ HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory**); static const struct { const GUID *wic_guid; - D3DFORMAT d3dformat; -} wic_pixel_formats[] = { - { &GUID_WICPixelFormat8bppIndexed, D3DFMT_P8 }, - { &GUID_WICPixelFormat1bppIndexed, D3DFMT_P8 }, - { &GUID_WICPixelFormat4bppIndexed, D3DFMT_P8 }, - { &GUID_WICPixelFormat8bppGray, D3DFMT_L8 }, - { &GUID_WICPixelFormat16bppBGR555, D3DFMT_X1R5G5B5 }, - { &GUID_WICPixelFormat16bppBGR565, D3DFMT_R5G6B5 }, - { &GUID_WICPixelFormat24bppBGR, D3DFMT_R8G8B8 }, - { &GUID_WICPixelFormat32bppBGR, D3DFMT_X8R8G8B8 }, - { &GUID_WICPixelFormat32bppBGRA, D3DFMT_A8R8G8B8 } + enum d3dx_pixel_format_id d3dx_pixel_format; +} wic_pixel_formats[] = +{ + { &GUID_WICPixelFormat8bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, + { &GUID_WICPixelFormat1bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, + { &GUID_WICPixelFormat4bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, + { &GUID_WICPixelFormat8bppGray, D3DX_PIXEL_FORMAT_L8_UNORM }, + { &GUID_WICPixelFormat16bppBGR555, D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM }, + { &GUID_WICPixelFormat16bppBGR565, D3DX_PIXEL_FORMAT_B5G6R5_UNORM }, + { &GUID_WICPixelFormat24bppBGR, D3DX_PIXEL_FORMAT_B8G8R8_UNORM }, + { &GUID_WICPixelFormat32bppBGR, D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM }, + { &GUID_WICPixelFormat32bppBGRA, D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM } };
-static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid) +static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_wic_pixel_format(const GUID *guid) { unsigned int i;
for (i = 0; i < ARRAY_SIZE(wic_pixel_formats); i++) { if (IsEqualGUID(wic_pixel_formats[i].wic_guid, guid)) - return wic_pixel_formats[i].d3dformat; + return wic_pixel_formats[i].d3dx_pixel_format; }
- return D3DFMT_UNKNOWN; + return D3DX_PIXEL_FORMAT_COUNT; + }
static const GUID *d3dformat_to_wic_guid(D3DFORMAT format) { + enum d3dx_pixel_format_id d3dx_pixel_format = d3dx_pixel_format_id_from_d3dformat(format); unsigned int i;
for (i = 0; i < ARRAY_SIZE(wic_pixel_formats); i++) { - if (wic_pixel_formats[i].d3dformat == format) + if (wic_pixel_formats[i].d3dx_pixel_format == d3dx_pixel_format) return wic_pixel_formats[i].wic_guid; }
@@ -953,7 +956,7 @@ static HRESULT d3dx_initialize_image_from_wic(const void *src_data, uint32_t src if (FAILED(hr)) goto exit;
- image->format = d3dx_pixel_format_id_from_d3dformat(wic_guid_to_d3dformat(&pixel_format)); + image->format = d3dx_pixel_format_id_from_wic_pixel_format(&pixel_format); if (image->format == D3DX_PIXEL_FORMAT_COUNT) { WARN("Unsupported pixel format %s.\n", debugstr_guid(&pixel_format)); @@ -2950,7 +2953,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
memcpy(&wic_pixel_format, pixel_format_guid, sizeof(GUID)); hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &wic_pixel_format); - d3d_pixel_format = wic_guid_to_d3dformat(&wic_pixel_format); + d3d_pixel_format = d3dformat_from_d3dx_pixel_format_id(d3dx_pixel_format_id_from_wic_pixel_format(&wic_pixel_format)); if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN) { TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
if (FAILED(hr)) goto exit;
- hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect, pixels.data, img_info.Format,
pixels.row_pitch, pixels.palette, &src_rect, dwFilter, Colorkey);
- hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect, pixels.data,
d3dformat_from_d3dx_pixel_format_id(image.format), pixels.row_pitch, pixels.palette, &src_rect, dwFilter,
Colorkey);
I guess we don't need this hunk since it looks like we're going to keep `img_info` around.
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
WARN("Unknown pixel format (flags %#lx, fourcc %#lx, bpp %lu, r %#lx, g %#lx, b %#lx, a %#lx).\n", pixel_format->flags, pixel_format->fourcc, pixel_format->bpp, pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
- return D3DFMT_UNKNOWN;
- return D3DX_PIXEL_FORMAT_COUNT;
}
static HRESULT d3dformat_to_dds_pixel_format(struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat)
No big deal by any means, but this could have been a good time to rename the function into a `dds_pixel_format_from...()` form.
Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
{ unsigned int i;
for (i = 0; i < ARRAY_SIZE(wic_pixel_formats); i++) { if (IsEqualGUID(wic_pixel_formats[i].wic_guid, guid))
return wic_pixel_formats[i].d3dformat;
}return wic_pixel_formats[i].d3dx_pixel_format;
- return D3DFMT_UNKNOWN;
- return D3DX_PIXEL_FORMAT_COUNT;
}
static const GUID *d3dformat_to_wic_guid(D3DFORMAT format)
Same here.
This merge request was approved by Matteo Bruni.
I left a couple of comments but MR is okay either way.