[3/4] d3dx9: Use structure to pass volume size to pixel format conversion functions.
Józef Kucia
joseph.kucia at gmail.com
Fri Jul 13 10:21:54 CDT 2012
---
dlls/d3dx9_36/d3dx9_36_private.h | 15 +++++--
dlls/d3dx9_36/surface.c | 87 +++++++++++++++++++------------------
dlls/d3dx9_36/volume.c | 47 +++++++++------------
3 files changed, 76 insertions(+), 73 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_36_private.h b/dlls/d3dx9_36/d3dx9_36_private.h
index 20d013f..76a9694 100644
--- a/dlls/d3dx9_36/d3dx9_36_private.h
+++ b/dlls/d3dx9_36/d3dx9_36_private.h
@@ -37,6 +37,13 @@ struct vec4
float x, y, z, w;
};
+struct volume
+{
+ UINT width;
+ UINT height;
+ UINT depth;
+};
+
/* for internal use */
typedef enum _FormatType {
FORMAT_ARGB, /* unsigned */
@@ -64,11 +71,11 @@ HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPE
const PixelFormatDesc *get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN;
const PixelFormatDesc *get_format_info_idx(int idx) DECLSPEC_HIDDEN;
-void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, SIZE src_size, UINT src_depth, const PixelFormatDesc *src_format,
- BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, SIZE dst_size, UINT dst_depth, const PixelFormatDesc *dst_format,
+void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, struct volume *src_size, const PixelFormatDesc *src_format,
+ BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, struct volume *dst_size, const PixelFormatDesc *dst_format,
D3DCOLOR color_key) DECLSPEC_HIDDEN;
-void point_filter_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, SIZE src_size, UINT src_depth, const PixelFormatDesc *src_format,
- BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, SIZE dst_size, UINT dst_depth, const PixelFormatDesc *dst_format,
+void point_filter_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, struct volume *src_size, const PixelFormatDesc *src_format,
+ BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, struct volume *dst_size, const PixelFormatDesc *dst_format,
D3DCOLOR color_key) DECLSPEC_HIDDEN;
HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c
index e640160..1cf77b0 100644
--- a/dlls/d3dx9_36/surface.c
+++ b/dlls/d3dx9_36/surface.c
@@ -1255,8 +1255,8 @@ static void format_from_vec4(const PixelFormatDesc *format, const struct vec4 *s
* Pixels outsize the source rect are blacked out.
* Works only for ARGB formats with 1 - 4 bytes per pixel.
*/
-void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, SIZE src_size, UINT src_depth, const PixelFormatDesc *src_format,
- BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, SIZE dst_size, UINT dst_depth, const PixelFormatDesc *dst_format, D3DCOLOR color_key)
+void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, struct volume *src_size, const PixelFormatDesc *src_format,
+ BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, struct volume *dst_size, const PixelFormatDesc *dst_format, D3DCOLOR color_key)
{
struct argb_conversion_info conv_info, ck_conv_info;
const PixelFormatDesc *ck_format = NULL;
@@ -1267,9 +1267,9 @@ void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
ZeroMemory(channels, sizeof(channels));
init_argb_conversion_info(src_format, dst_format, &conv_info);
- min_width = min(src_size.cx, dst_size.cx);
- min_height = min(src_size.cy, dst_size.cy);
- min_depth = min(src_depth, dst_depth);
+ min_width = min(src_size->width, dst_size->width);
+ min_height = min(src_size->height, dst_size->height);
+ min_depth = min(src_size->depth, dst_size->depth);
if (color_key)
{
@@ -1334,15 +1334,15 @@ void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
dst_ptr += dst_format->bytes_per_pixel;
}
- if (src_size.cx < dst_size.cx) /* black out remaining pixels */
- memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size.cx - src_size.cx));
+ if (src_size->width < dst_size->width) /* black out remaining pixels */
+ memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width));
}
- if (src_size.cy < dst_size.cy) /* black out remaining pixels */
- memset(dst + src_size.cy * dst_row_pitch, 0, dst_row_pitch * (dst_size.cy - src_size.cy));
+ if (src_size->height < dst_size->height) /* black out remaining pixels */
+ memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height));
}
- if (src_depth < dst_depth) /* black out remaining pixels */
- memset(dst + src_depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_depth - src_depth));
+ if (src_size->depth < dst_size->depth) /* black out remaining pixels */
+ memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth));
}
/************************************************************
@@ -1353,8 +1353,8 @@ void copy_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
* using a point filter.
* Works only for ARGB formats with 1 - 4 bytes per pixel.
*/
-void point_filter_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, SIZE src_size, UINT src_depth, const PixelFormatDesc *src_format,
- BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, SIZE dst_size, UINT dst_depth, const PixelFormatDesc *dst_format, D3DCOLOR color_key)
+void point_filter_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, struct volume *src_size, const PixelFormatDesc *src_format,
+ BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, struct volume *dst_size, const PixelFormatDesc *dst_format, D3DCOLOR color_key)
{
struct argb_conversion_info conv_info, ck_conv_info;
const PixelFormatDesc *ck_format = NULL;
@@ -1371,19 +1371,19 @@ void point_filter_simple_data(const BYTE *src, UINT src_row_pitch, UINT src_slic
init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
}
- for (z = 0; z < dst_depth; z++)
+ for (z = 0; z < dst_size->depth; z++)
{
BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
- const BYTE *src_slice_ptr = src + src_slice_pitch * (z * src_depth / dst_depth);
+ const BYTE *src_slice_ptr = src + src_slice_pitch * (z * src_size->depth / dst_size->depth);
- for (y = 0; y < dst_size.cy; y++)
+ for (y = 0; y < dst_size->height; y++)
{
BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
- const BYTE *src_row_ptr = src_slice_ptr + src_row_pitch * (y * src_size.cy / dst_size.cy);
+ const BYTE *src_row_ptr = src_slice_ptr + src_row_pitch * (y * src_size->height / dst_size->height);
- for (x = 0; x < dst_size.cx; x++)
+ for (x = 0; x < dst_size->width; x++)
{
- const BYTE *src_ptr = src_row_ptr + (x * src_size.cx / dst_size.cx) * src_format->bytes_per_pixel;
+ const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
DWORD val;
/* extract source color components */
@@ -1474,7 +1474,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
CONST PixelFormatDesc *srcformatdesc, *destformatdesc;
D3DSURFACE_DESC surfdesc;
D3DLOCKED_RECT lockrect;
- SIZE src_size, dst_size;
+ struct volume src_size, dst_size;
HRESULT hr;
TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s %#x, 0x%08x)\n",
@@ -1493,12 +1493,13 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
IDirect3DSurface9_GetDesc(dst_surface, &surfdesc);
- src_size.cx = src_rect->right - src_rect->left;
- src_size.cy = src_rect->bottom - src_rect->top;
+ src_size.width = src_rect->right - src_rect->left;
+ src_size.height = src_rect->bottom - src_rect->top;
+ src_size.depth = 1;
if (!dst_rect)
{
- dst_size.cx = surfdesc.Width;
- dst_size.cy = surfdesc.Height;
+ dst_size.width = surfdesc.Width;
+ dst_size.height = surfdesc.Height;
}
else
{
@@ -1508,11 +1509,12 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
return D3DERR_INVALIDCALL;
if (dst_rect->left < 0 || dst_rect->top < 0)
return D3DERR_INVALIDCALL;
- dst_size.cx = dst_rect->right - dst_rect->left;
- dst_size.cy = dst_rect->bottom - dst_rect->top;
- if (!dst_size.cx || !dst_size.cy)
+ dst_size.width = dst_rect->right - dst_rect->left;
+ dst_size.height = dst_rect->bottom - dst_rect->top;
+ if (!dst_size.width || !dst_size.height)
return D3D_OK;
}
+ dst_size.depth = 1;
srcformatdesc = get_format_info(src_format);
if (srcformatdesc->type == FORMAT_UNKNOWN)
@@ -1523,11 +1525,11 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
return E_NOTIMPL;
if (src_format == surfdesc.Format
- && dst_size.cx == src_size.cx
- && dst_size.cy == src_size.cy) /* Simple copy. */
+ && dst_size.width == src_size.width
+ && dst_size.height == src_size.height) /* Simple copy. */
{
- UINT row_block_count = ((src_size.cx + srcformatdesc->block_width - 1) / srcformatdesc->block_width);
- UINT row_count = (src_size.cy + srcformatdesc->block_height - 1) / srcformatdesc->block_height;
+ UINT row_block_count = ((src_size.width + srcformatdesc->block_width - 1) / srcformatdesc->block_width);
+ UINT row_count = (src_size.height + srcformatdesc->block_height - 1) / srcformatdesc->block_height;
const BYTE *src_addr;
BYTE *dst_addr;
UINT row;
@@ -1535,9 +1537,9 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
if (src_rect->left & (srcformatdesc->block_width - 1)
|| src_rect->top & (srcformatdesc->block_height - 1)
|| (src_rect->right & (srcformatdesc->block_width - 1)
- && src_size.cx != surfdesc.Width)
+ && src_size.width != surfdesc.Width)
|| (src_rect->bottom & (srcformatdesc->block_height - 1)
- && src_size.cy != surfdesc.Height))
+ && src_size.height != surfdesc.Height))
{
WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
return D3DXERR_INVALIDDATA;
@@ -1576,8 +1578,8 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
if ((filter & 0xf) == D3DX_FILTER_NONE)
{
- copy_simple_data(src_memory, src_pitch, 0, src_size, 1, srcformatdesc,
- lockrect.pBits, lockrect.Pitch, 0, dst_size, 1, destformatdesc, color_key);
+ copy_simple_data(src_memory, src_pitch, 0, &src_size, srcformatdesc,
+ lockrect.pBits, lockrect.Pitch, 0, &dst_size, destformatdesc, color_key);
}
else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */
{
@@ -1586,8 +1588,8 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
/* Always apply a point filter until D3DX_FILTER_LINEAR,
* D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */
- point_filter_simple_data(src_memory, src_pitch, 0, src_size, 1, srcformatdesc,
- lockrect.pBits, lockrect.Pitch, 0, dst_size, 1, destformatdesc, color_key);
+ point_filter_simple_data(src_memory, src_pitch, 0, &src_size, srcformatdesc,
+ lockrect.pBits, lockrect.Pitch, 0, &dst_size, destformatdesc, color_key);
}
IDirect3DSurface9_UnlockRect(dst_surface);
@@ -1832,7 +1834,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
else /* Pixel format conversion */
{
const PixelFormatDesc *src_format_desc, *dst_format_desc;
- SIZE size;
+ struct volume size;
DWORD dst_pitch;
void *dst_data;
@@ -1855,8 +1857,9 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
goto cleanup;
}
- size.cx = width;
- size.cy = height;
+ size.width = width;
+ size.height = height;
+ size.depth = 1;
dst_pitch = width * dst_format_desc->bytes_per_pixel;
dst_data = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height);
if (!dst_data)
@@ -1868,8 +1871,8 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
if (SUCCEEDED(hr))
{
- copy_simple_data(locked_rect.pBits, locked_rect.Pitch, 0, size, 1, src_format_desc,
- dst_data, dst_pitch, 0, size, 1, dst_format_desc, 0);
+ copy_simple_data(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
+ dst_data, dst_pitch, 0, &size, dst_format_desc, 0);
IDirect3DSurface9_UnlockRect(src_surface);
}
diff --git a/dlls/d3dx9_36/volume.c b/dlls/d3dx9_36/volume.c
index ca7df62..749d3fa 100644
--- a/dlls/d3dx9_36/volume.c
+++ b/dlls/d3dx9_36/volume.c
@@ -95,8 +95,7 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
HRESULT hr;
D3DVOLUME_DESC desc;
D3DLOCKED_BOX locked_box;
- UINT dst_width, dst_height, dst_depth;
- UINT src_width, src_height, src_depth;
+ struct volume dst_size, src_size;
const PixelFormatDesc *src_format_desc, *dst_format_desc;
TRACE("(%p, %p, %p, %p, %#x, %u, %u, %p, %p, %x, %x)\n", dst_volume, dst_palette, dst_box,
@@ -116,15 +115,15 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
IDirect3DVolume9_GetDesc(dst_volume, &desc);
- src_width = src_box->Right - src_box->Left;
- src_height = src_box->Bottom - src_box->Top;
- src_depth = src_box->Back - src_box->Front;
+ src_size.width = src_box->Right - src_box->Left;
+ src_size.height = src_box->Bottom - src_box->Top;
+ src_size.depth = src_box->Back - src_box->Front;
if (!dst_box)
{
- dst_width = desc.Width;
- dst_height = desc.Height;
- dst_depth = desc.Depth;
+ dst_size.width = desc.Width;
+ dst_size.height = desc.Height;
+ dst_size.depth = desc.Depth;
}
else
{
@@ -135,9 +134,9 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
if (dst_box->Front >= dst_box->Back || dst_box->Back > desc.Depth)
return D3DERR_INVALIDCALL;
- dst_width = dst_box->Right - dst_box->Left;
- dst_height = dst_box->Bottom - dst_box->Top;
- dst_depth = dst_box->Back - dst_box->Front;
+ dst_size.width = dst_box->Right - dst_box->Left;
+ dst_size.height = dst_box->Bottom - dst_box->Top;
+ dst_size.depth = dst_box->Back - dst_box->Front;
}
src_format_desc = get_format_info(src_format);
@@ -149,20 +148,20 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
return E_NOTIMPL;
if (desc.Format == src_format
- && dst_width == src_width && dst_height == src_height && dst_depth == src_depth)
+ && dst_size.width == src_size.width && dst_size.height == src_size.height && dst_size.depth == src_size.depth)
{
UINT row, slice;
BYTE *dst_addr;
const BYTE *src_addr;
- UINT row_block_count = (src_width + src_format_desc->block_width - 1) / src_format_desc->block_width;
- UINT row_count = (src_height + src_format_desc->block_height - 1) / src_format_desc->block_height;
+ UINT row_block_count = (src_size.width + src_format_desc->block_width - 1) / src_format_desc->block_width;
+ UINT row_count = (src_size.height + src_format_desc->block_height - 1) / src_format_desc->block_height;
if (src_box->Left & (src_format_desc->block_width - 1)
|| src_box->Top & (src_format_desc->block_height - 1)
|| (src_box->Right & (src_format_desc->block_width - 1)
- && src_width != desc.Width)
+ && src_size.width != desc.Width)
|| (src_box->Bottom & (src_format_desc->block_height - 1)
- && src_height != desc.Height))
+ && src_size.height != desc.Height))
{
FIXME("Source box (%u, %u, %u, %u) is misaligned\n",
src_box->Left, src_box->Top, src_box->Right, src_box->Bottom);
@@ -172,7 +171,7 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
hr = IDirect3DVolume9_LockBox(dst_volume, &locked_box, dst_box, 0);
if (FAILED(hr)) return hr;
- for (slice = 0; slice < src_depth; slice++)
+ for (slice = 0; slice < src_size.depth; slice++)
{
src_addr = src_memory;
src_addr += (src_box->Front + slice) * src_slice_pitch;
@@ -195,7 +194,6 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
else
{
const BYTE *src_addr;
- SIZE src_size, dst_size;
if (src_format_desc->bytes_per_pixel > 4 || dst_format_desc->bytes_per_pixel > 4
|| src_format_desc->block_height != 1 || src_format_desc->block_width != 1
@@ -206,11 +204,6 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
return E_NOTIMPL;
}
- src_size.cx = src_width;
- src_size.cy = src_height;
- dst_size.cx = dst_width;
- dst_size.cy = dst_height;
-
src_addr = src_memory;
src_addr += src_box->Front * src_slice_pitch;
src_addr += src_box->Top * src_row_pitch;
@@ -221,16 +214,16 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
if ((filter & 0xf) == D3DX_FILTER_NONE)
{
- copy_simple_data(src_memory, src_row_pitch, src_slice_pitch, src_size, src_depth, src_format_desc,
- locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, dst_size, dst_depth, dst_format_desc, color_key);
+ copy_simple_data(src_memory, src_row_pitch, src_slice_pitch, &src_size, src_format_desc,
+ locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, &dst_size, dst_format_desc, color_key);
}
else
{
if ((filter & 0xf) != D3DX_FILTER_POINT)
FIXME("Unhandled filter %#x.\n", filter);
- point_filter_simple_data(src_addr, src_row_pitch, src_slice_pitch, src_size, src_depth, src_format_desc,
- locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, dst_size, dst_depth, dst_format_desc, color_key);
+ point_filter_simple_data(src_addr, src_row_pitch, src_slice_pitch, &src_size, src_format_desc,
+ locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, &dst_size, dst_format_desc, color_key);
}
IDirect3DVolume9_UnlockBox(dst_volume);
--
1.7.8.6
More information about the wine-patches
mailing list