ReactOS  0.4.14-dev-384-g5b37caa
volume.c
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Christian Costa
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "config.h"
20 #include "wine/port.h"
21 
22 #include "d3dx9_private.h"
23 
25 
26 HRESULT WINAPI D3DXLoadVolumeFromFileA(IDirect3DVolume9 *dst_volume,
27  const PALETTEENTRY *dst_palette,
28  const D3DBOX *dst_box,
29  const char *filename,
30  const D3DBOX *src_box,
31  DWORD filter,
34 {
35  HRESULT hr;
36  int length;
38 
39  TRACE("(%p, %p, %p, %s, %p, %#x, %#x, %p)\n",
40  dst_volume, dst_palette, dst_box, debugstr_a(filename), src_box,
42 
43  if (!dst_volume || !filename) return D3DERR_INVALIDCALL;
44 
47  if (!filenameW) return E_OUTOFMEMORY;
48 
49  hr = D3DXLoadVolumeFromFileW(dst_volume, dst_palette, dst_box, filenameW,
50  src_box, filter, color_key, info);
52 
53  return hr;
54 }
55 
56 HRESULT WINAPI D3DXLoadVolumeFromFileW(IDirect3DVolume9 *dst_volume,
57  const PALETTEENTRY *dst_palette,
58  const D3DBOX *dst_box,
59  const WCHAR *filename,
60  const D3DBOX *src_box,
61  DWORD filter,
64 {
65  HRESULT hr;
66  void *data;
67  UINT data_size;
68 
69  TRACE("(%p, %p, %p, %s, %p, %#x, %#x, %p)\n",
70  dst_volume, dst_palette, dst_box, debugstr_w(filename), src_box,
72 
73  if (!dst_volume || !filename) return D3DERR_INVALIDCALL;
74 
75  if (FAILED(map_view_of_file(filename, &data, &data_size)))
76  return D3DXERR_INVALIDDATA;
77 
78  hr = D3DXLoadVolumeFromFileInMemory(dst_volume, dst_palette, dst_box,
79  data, data_size, src_box, filter, color_key, info);
81 
82  return hr;
83 }
84 
85 HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
86  const PALETTEENTRY *dst_palette,
87  const D3DBOX *dst_box,
88  const void *src_memory,
89  D3DFORMAT src_format,
90  UINT src_row_pitch,
91  UINT src_slice_pitch,
92  const PALETTEENTRY *src_palette,
93  const D3DBOX *src_box,
94  DWORD filter,
96 {
97  HRESULT hr;
99  D3DLOCKED_BOX locked_box;
100  struct volume dst_size, src_size;
101  const struct pixel_format_desc *src_format_desc, *dst_format_desc;
102 
103  TRACE("(%p, %p, %p, %p, %#x, %u, %u, %p, %p, %x, %x)\n", dst_volume, dst_palette, dst_box,
104  src_memory, src_format, src_row_pitch, src_slice_pitch, src_palette, src_box,
105  filter, color_key);
106 
107  if (!dst_volume || !src_memory || !src_box) return D3DERR_INVALIDCALL;
108 
109  if (src_format == D3DFMT_UNKNOWN
110  || src_box->Left >= src_box->Right
111  || src_box->Top >= src_box->Bottom
112  || src_box->Front >= src_box->Back)
113  return E_FAIL;
114 
115  if (filter == D3DX_DEFAULT)
117 
118  IDirect3DVolume9_GetDesc(dst_volume, &desc);
119 
120  src_size.width = src_box->Right - src_box->Left;
121  src_size.height = src_box->Bottom - src_box->Top;
122  src_size.depth = src_box->Back - src_box->Front;
123 
124  if (!dst_box)
125  {
126  dst_size.width = desc.Width;
127  dst_size.height = desc.Height;
128  dst_size.depth = desc.Depth;
129  }
130  else
131  {
132  if (dst_box->Left >= dst_box->Right || dst_box->Right > desc.Width)
133  return D3DERR_INVALIDCALL;
134  if (dst_box->Top >= dst_box->Bottom || dst_box->Bottom > desc.Height)
135  return D3DERR_INVALIDCALL;
136  if (dst_box->Front >= dst_box->Back || dst_box->Back > desc.Depth)
137  return D3DERR_INVALIDCALL;
138 
139  dst_size.width = dst_box->Right - dst_box->Left;
140  dst_size.height = dst_box->Bottom - dst_box->Top;
141  dst_size.depth = dst_box->Back - dst_box->Front;
142  }
143 
144  src_format_desc = get_format_info(src_format);
145  if (src_format_desc->type == FORMAT_UNKNOWN)
146  return E_NOTIMPL;
147 
148  dst_format_desc = get_format_info(desc.Format);
149  if (dst_format_desc->type == FORMAT_UNKNOWN)
150  return E_NOTIMPL;
151 
152  if (desc.Format == src_format
153  && dst_size.width == src_size.width
154  && dst_size.height == src_size.height
155  && dst_size.depth == src_size.depth
156  && color_key == 0)
157  {
158  const BYTE *src_addr;
159 
160  if (src_box->Left & (src_format_desc->block_width - 1)
161  || src_box->Top & (src_format_desc->block_height - 1)
162  || (src_box->Right & (src_format_desc->block_width - 1)
163  && src_size.width != desc.Width)
164  || (src_box->Bottom & (src_format_desc->block_height - 1)
165  && src_size.height != desc.Height))
166  {
167  FIXME("Source box (%u, %u, %u, %u) is misaligned\n",
168  src_box->Left, src_box->Top, src_box->Right, src_box->Bottom);
169  return E_NOTIMPL;
170  }
171 
172  src_addr = src_memory;
173  src_addr += src_box->Front * src_slice_pitch;
174  src_addr += (src_box->Top / src_format_desc->block_height) * src_row_pitch;
175  src_addr += (src_box->Left / src_format_desc->block_width) * src_format_desc->block_byte_count;
176 
177  hr = IDirect3DVolume9_LockBox(dst_volume, &locked_box, dst_box, 0);
178  if (FAILED(hr)) return hr;
179 
180  copy_pixels(src_addr, src_row_pitch, src_slice_pitch,
181  locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch,
182  &dst_size, dst_format_desc);
183 
184  IDirect3DVolume9_UnlockBox(dst_volume);
185  }
186  else
187  {
188  const BYTE *src_addr;
189 
190 
191  if (!is_conversion_from_supported(src_format_desc)
192  || !is_conversion_to_supported(dst_format_desc))
193  {
194  FIXME("Pixel format conversion is not implemented %#x -> %#x\n",
195  src_format_desc->format, dst_format_desc->format);
196  return E_NOTIMPL;
197  }
198 
199  src_addr = src_memory;
200  src_addr += src_box->Front * src_slice_pitch;
201  src_addr += src_box->Top * src_row_pitch;
202  src_addr += src_box->Left * src_format_desc->bytes_per_pixel;
203 
204  hr = IDirect3DVolume9_LockBox(dst_volume, &locked_box, dst_box, 0);
205  if (FAILED(hr)) return hr;
206 
207  if ((filter & 0xf) == D3DX_FILTER_NONE)
208  {
209  convert_argb_pixels(src_memory, src_row_pitch, src_slice_pitch, &src_size, src_format_desc,
210  locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, &dst_size, dst_format_desc, color_key,
211  src_palette);
212  }
213  else
214  {
215  if ((filter & 0xf) != D3DX_FILTER_POINT)
216  FIXME("Unhandled filter %#x.\n", filter);
217 
218  point_filter_argb_pixels(src_addr, src_row_pitch, src_slice_pitch, &src_size, src_format_desc,
219  locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, &dst_size, dst_format_desc, color_key,
220  src_palette);
221  }
222 
223  IDirect3DVolume9_UnlockBox(dst_volume);
224  }
225 
226  return D3D_OK;
227 }
228 
229 HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume,
230  const PALETTEENTRY *dst_palette,
231  const D3DBOX *dst_box,
232  const void *src_data,
233  UINT src_data_size,
234  const D3DBOX *src_box,
235  DWORD filter,
237  D3DXIMAGE_INFO *src_info)
238 {
239  HRESULT hr;
240  D3DBOX box;
241  D3DXIMAGE_INFO image_info;
242 
243  TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_data %p, src_data_size %u, src_box %p, "
244  "filter %#x, color_key 0x%08x, src_info %p.\n",
245  dst_volume, dst_palette, dst_box, src_data, src_data_size, src_box,
246  filter, color_key, src_info);
247 
248  if (!dst_volume || !src_data)
249  return D3DERR_INVALIDCALL;
250 
251  if (FAILED(hr = D3DXGetImageInfoFromFileInMemory(src_data, src_data_size, &image_info)))
252  return hr;
253 
254  if (src_box)
255  {
256  if (src_box->Right > image_info.Width
257  || src_box->Bottom > image_info.Height
258  || src_box->Back > image_info.Depth)
259  return D3DERR_INVALIDCALL;
260 
261  box = *src_box;
262  }
263  else
264  {
265  box.Left = 0;
266  box.Top = 0;
267  box.Right = image_info.Width;
268  box.Bottom = image_info.Height;
269  box.Front = 0;
270  box.Back = image_info.Depth;
271 
272  }
273 
274  if (image_info.ImageFileFormat != D3DXIFF_DDS)
275  {
276  FIXME("File format %#x is not supported yet\n", image_info.ImageFileFormat);
277  return E_NOTIMPL;
278  }
279 
280  hr = load_volume_from_dds(dst_volume, dst_palette, dst_box, src_data, &box,
281  filter, color_key, &image_info);
282  if (FAILED(hr)) return hr;
283 
284  if (src_info)
285  *src_info = image_info;
286 
287  return D3D_OK;
288 }
289 
290 HRESULT WINAPI D3DXLoadVolumeFromVolume(IDirect3DVolume9 *dst_volume,
291  const PALETTEENTRY *dst_palette,
292  const D3DBOX *dst_box,
293  IDirect3DVolume9 *src_volume,
294  const PALETTEENTRY *src_palette,
295  const D3DBOX *src_box,
296  DWORD filter,
298 {
299  HRESULT hr;
300  D3DBOX box;
302  D3DLOCKED_BOX locked_box;
303 
304  TRACE("(%p, %p, %p, %p, %p, %p, %#x, %#x)\n",
305  dst_volume, dst_palette, dst_box, src_volume, src_palette, src_box,
306  filter, color_key);
307 
308  if (!dst_volume || !src_volume) return D3DERR_INVALIDCALL;
309 
310  IDirect3DVolume9_GetDesc(src_volume, &desc);
311 
312  if (!src_box)
313  {
314  box.Left = box.Top = 0;
315  box.Right = desc.Width;
316  box.Bottom = desc.Height;
317  box.Front = 0;
318  box.Back = desc.Depth;
319  }
320  else box = *src_box;
321 
322  hr = IDirect3DVolume9_LockBox(src_volume, &locked_box, NULL, D3DLOCK_READONLY);
323  if (FAILED(hr)) return hr;
324 
325  hr = D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box,
326  locked_box.pBits, desc.Format, locked_box.RowPitch, locked_box.SlicePitch,
327  src_palette, &box, filter, color_key);
328 
329  IDirect3DVolume9_UnlockBox(src_volume);
330  return hr;
331 }
UINT width
Definition: d3dx9_private.h:42
HRESULT hr
Definition: shlfolder.c:183
#define CP_ACP
Definition: compat.h:99
HRESULT WINAPI D3DXLoadVolumeFromFileW(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const WCHAR *filename, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *info)
Definition: volume.c:56
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
#define D3DERR_INVALIDCALL
const char * filename
Definition: ioapi.h:135
#define E_FAIL
Definition: ddrawi.h:102
WINE_DEFAULT_DEBUG_CHANNEL(d3d8)
static const WCHAR filenameW[]
Definition: amstream.c:41
void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN
Definition: surface.c:1735
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
UINT Back
Definition: d3d8types.h:1016
static const WCHAR desc[]
Definition: protectdata.c:36
HRESULT WINAPI D3DXLoadVolumeFromVolume(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, IDirect3DVolume9 *src_volume, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
Definition: volume.c:290
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
#define D3DX_DEFAULT
Definition: d3dx9.h:24
#define D3DX_FILTER_TRIANGLE
Definition: d3dx9tex.h:30
static BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:78
UINT height
Definition: d3dx9_private.h:43
smooth NULL
Definition: ftsmooth.c:416
enum _D3DFORMAT D3DFORMAT
UINT Bottom
Definition: d3d8types.h:1014
HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN
Definition: surface.c:609
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
#define TRACE(s)
Definition: solgame.cpp:4
UINT depth
Definition: d3dx9_private.h:44
#define IDirect3DVolume9_GetDesc(p, a)
Definition: d3d9.h:390
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDirect3DVolume9_UnlockBox(p)
Definition: d3d9.h:392
__wchar_t WCHAR
Definition: xmlstorage.h:180
UINT Top
Definition: d3d8types.h:1012
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:77
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT Left
Definition: d3d8types.h:1011
#define WINAPI
Definition: msvc.h:8
enum format_type type
Definition: d3dx9_private.h:65
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDirect3DVolume9_LockBox(p, a, b, c)
Definition: d3d9.h:391
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:118
unsigned char BYTE
Definition: mem.h:68
void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size, const struct pixel_format_desc *format) DECLSPEC_HIDDEN
Definition: surface.c:1601
#define D3D_OK
Definition: d3d.h:106
#define D3DX_FILTER_DITHER
Definition: d3dx9tex.h:36
HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
Definition: volume.c:85
void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN
Definition: surface.c:1632
UINT Front
Definition: d3d8types.h:1015
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
static BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:86
#define MultiByteToWideChar
Definition: compat.h:100
UINT Right
Definition: d3d8types.h:1013
#define D3DX_FILTER_POINT
Definition: d3dx9tex.h:28
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:875
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
#define UnmapViewOfFile
Definition: compat.h:411
HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_data, UINT src_data_size, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
Definition: volume.c:229
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
HRESULT WINAPI D3DXLoadVolumeFromFileA(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const char *filename, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *info)
Definition: volume.c:26
#define HeapFree(x, y, z)
Definition: compat.h:402
Definition: palette.c:467