ReactOS 0.4.17-dev-966-gf06eace
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
20#include "d3dx9_private.h"
21
23
24HRESULT WINAPI D3DXLoadVolumeFromFileA(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
25 const D3DBOX *dst_box, const char *filename, const D3DBOX *src_box, DWORD filter,
27{
28 HRESULT hr;
29 int length;
31
32 TRACE("dst_volume %p, dst_palette %p, dst_box %p, filename %s, src_box %p, filter %#lx, "
33 "color_key 0x%08lx, info %p.\n",
34 dst_volume, dst_palette, dst_box, debugstr_a(filename), src_box, filter, color_key, info);
35
36 if (!dst_volume || !filename) return D3DERR_INVALIDCALL;
37
39 filenameW = malloc(length * sizeof(*filenameW));
40 if (!filenameW) return E_OUTOFMEMORY;
42
43 hr = D3DXLoadVolumeFromFileW(dst_volume, dst_palette, dst_box, filenameW,
44 src_box, filter, color_key, info);
46
47 return hr;
48}
49
50HRESULT WINAPI D3DXLoadVolumeFromFileW(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
51 const D3DBOX *dst_box, const WCHAR *filename, const D3DBOX *src_box, DWORD filter,
53{
54 DWORD data_size;
55 HRESULT hr;
56 void *data;
57
58 TRACE("dst_volume %p, dst_palette %p, dst_box %p, filename %s, src_box %p, filter %#lx, "
59 "color_key 0x%08lx, info %p.\n",
60 dst_volume, dst_palette, dst_box, debugstr_w(filename), src_box, filter, color_key, info);
61
62 if (!dst_volume || !filename) return D3DERR_INVALIDCALL;
63
64 if (FAILED(map_view_of_file(filename, &data, &data_size)))
66
67 hr = D3DXLoadVolumeFromFileInMemory(dst_volume, dst_palette, dst_box,
68 data, data_size, src_box, filter, color_key, info);
70
71 return hr;
72}
73
75 uint32_t back)
76{
77 box->Left = left;
78 box->Top = top;
79 box->Right = right;
80 box->Bottom = bottom;
81 box->Front = front;
82 box->Back = back;
83}
84
85static HRESULT d3dx_load_volume_from_memory(IDirect3DVolume9 *dst_volume,
86 const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory,
87 enum d3dx_pixel_format_id src_format, uint32_t src_row_pitch, uint32_t src_slice_pitch,
88 const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
89{
90 const struct pixel_format_desc *src_format_desc, *dst_format_desc;
91 struct d3dx_pixels src_pixels, dst_pixels;
92 RECT dst_rect_aligned, dst_rect_unaligned;
93 D3DBOX dst_box_aligned, dst_box_tmp;
94 D3DLOCKED_BOX locked_box;
96 HRESULT hr;
97
98 IDirect3DVolume9_GetDesc(dst_volume, &desc);
99 dst_format_desc = get_format_info(desc.Format);
100 if (is_unknown_format(dst_format_desc))
101 return E_NOTIMPL;
102
103 if (!dst_box)
104 {
105 set_d3dbox(&dst_box_tmp, 0, 0, desc.Width, desc.Height, 0, desc.Depth);
106 dst_box = &dst_box_tmp;
107 }
108 else
109 {
110 if (dst_box->Left >= dst_box->Right || dst_box->Right > desc.Width)
111 return D3DERR_INVALIDCALL;
112 if (dst_box->Top >= dst_box->Bottom || dst_box->Bottom > desc.Height)
113 return D3DERR_INVALIDCALL;
114 if (dst_box->Front >= dst_box->Back || dst_box->Back > desc.Depth)
115 return D3DERR_INVALIDCALL;
116 }
117
118 src_format_desc = get_d3dx_pixel_format_info(src_format);
119 hr = d3dx_pixels_init(src_memory, src_row_pitch, src_slice_pitch,
120 src_palette, src_format_desc->format, src_box->Left, src_box->Top, src_box->Right, src_box->Bottom,
121 src_box->Front, src_box->Back, &src_pixels);
122 if (FAILED(hr))
123 return hr;
124
125 get_aligned_rect(dst_box->Left, dst_box->Top, dst_box->Right, dst_box->Bottom, desc.Width, desc.Height,
126 dst_format_desc, &dst_rect_aligned);
127 set_d3dbox(&dst_box_aligned, dst_rect_aligned.left, dst_rect_aligned.top, dst_rect_aligned.right,
128 dst_rect_aligned.bottom, dst_box->Front, dst_box->Back);
129
130 hr = IDirect3DVolume9_LockBox(dst_volume, &locked_box, &dst_box_aligned, 0);
131 if (FAILED(hr))
132 return hr;
133
134 SetRect(&dst_rect_unaligned, dst_box->Left, dst_box->Top, dst_box->Right, dst_box->Bottom);
135 OffsetRect(&dst_rect_unaligned, -dst_rect_aligned.left, -dst_rect_aligned.top);
136 set_d3dx_pixels(&dst_pixels, locked_box.pBits, locked_box.RowPitch, locked_box.SlicePitch, dst_palette,
137 (dst_box_aligned.Right - dst_box_aligned.Left), (dst_box_aligned.Bottom - dst_box_aligned.Top),
138 (dst_box_aligned.Back - dst_box_aligned.Front), &dst_rect_unaligned);
139
140 hr = d3dx_load_pixels_from_pixels(&dst_pixels, dst_format_desc, &src_pixels, src_format_desc, filter,
141 color_key);
142 IDirect3DVolume9_UnlockBox(dst_volume);
143 return hr;
144}
145
146HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume,
147 const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory,
148 D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch,
149 const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
150{
151 const struct pixel_format_desc *src_format_desc;
152 HRESULT hr;
153
154 TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_memory %p, src_format %#x, "
155 "src_row_pitch %u, src_slice_pitch %u, src_palette %p, src_box %p, filter %#lx, color_key 0x%08lx.\n",
156 dst_volume, dst_palette, dst_box, src_memory, src_format, src_row_pitch, src_slice_pitch,
157 src_palette, src_box, filter, color_key);
158
159 if (!dst_volume || !src_memory || !src_box)
160 return D3DERR_INVALIDCALL;
161
162 if (src_format == D3DFMT_UNKNOWN
163 || src_box->Left >= src_box->Right
164 || src_box->Top >= src_box->Bottom
165 || src_box->Front >= src_box->Back)
166 return E_FAIL;
167
169 return hr;
170
171 src_format_desc = get_format_info(src_format);
172 if (is_unknown_format(src_format_desc))
173 return E_NOTIMPL;
174
175 return d3dx_load_volume_from_memory(dst_volume, dst_palette, dst_box, src_memory, src_format_desc->format,
176 src_row_pitch, src_slice_pitch, src_palette, src_box, filter, color_key);
177}
178
179HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
180 const D3DBOX *dst_box, const void *src_data, UINT src_data_size, const D3DBOX *src_box,
182{
183 HRESULT hr;
184 D3DBOX box;
185 struct d3dx_image image;
186 struct d3dx_pixels pixels;
187 D3DXIMAGE_INFO image_info;
188
189 TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_data %p, src_data_size %u, src_box %p, "
190 "filter %#lx, color_key 0x%08lx, src_info %p.\n",
191 dst_volume, dst_palette, dst_box, src_data, src_data_size, src_box,
192 filter, color_key, src_info);
193
194 if (!dst_volume || !src_data || !src_data_size)
195 return D3DERR_INVALIDCALL;
196
198 return hr;
199
200 hr = d3dx_image_init(src_data, src_data_size, &image, 0, 0);
201 if (FAILED(hr))
202 return D3DXERR_INVALIDDATA;
203
205 if (src_box)
206 {
207 if (src_box->Right > image_info.Width
208 || src_box->Bottom > image_info.Height
209 || src_box->Back > image_info.Depth)
210 {
212 goto exit;
213 }
214 if (src_box->Left >= src_box->Right || src_box->Top >= src_box->Bottom
215 || src_box->Front >= src_box->Back)
216 {
217 hr = E_FAIL;
218 goto exit;
219 }
220
221 box = *src_box;
222 }
223 else
224 {
225 set_d3dbox(&box, 0, 0, image_info.Width, image_info.Height, 0, image_info.Depth);
226 }
227
229 if (FAILED(hr))
230 goto exit;
231
232 hr = d3dx_load_volume_from_memory(dst_volume, dst_palette, dst_box, pixels.data, image.format,
233 pixels.row_pitch, pixels.slice_pitch, pixels.palette, &box, filter, color_key);
234 if (SUCCEEDED(hr) && src_info)
235 *src_info = image_info;
236
237exit:
239 return FAILED(hr) ? hr : D3D_OK;
240}
241
242HRESULT WINAPI D3DXLoadVolumeFromVolume(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
243 const D3DBOX *dst_box, IDirect3DVolume9 *src_volume, const PALETTEENTRY *src_palette,
244 const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
245{
246 HRESULT hr;
247 D3DBOX box;
249 D3DLOCKED_BOX locked_box;
250
251 TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_volume %p, src_palette %p, src_box %p, "
252 "filter %#lx, color_key 0x%08lx.\n",
253 dst_volume, dst_palette, dst_box, src_volume, src_palette, src_box, filter, color_key);
254
255 if (!dst_volume || !src_volume) return D3DERR_INVALIDCALL;
256
258 return hr;
259
260 IDirect3DVolume9_GetDesc(src_volume, &desc);
261
262 if (!src_box)
263 {
264 box.Left = box.Top = 0;
265 box.Right = desc.Width;
266 box.Bottom = desc.Height;
267 box.Front = 0;
268 box.Back = desc.Depth;
269 }
270 else box = *src_box;
271
272 hr = IDirect3DVolume9_LockBox(src_volume, &locked_box, NULL, D3DLOCK_READONLY);
273 if (FAILED(hr)) return hr;
274
275 hr = D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box,
276 locked_box.pBits, desc.Format, locked_box.RowPitch, locked_box.SlicePitch,
277 src_palette, &box, filter, color_key);
278
279 IDirect3DVolume9_UnlockBox(src_volume);
280 return hr;
281}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
@ D3DFMT_UNKNOWN
Definition: d3d8types.h:601
enum _D3DFORMAT D3DFORMAT
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
#define IDirect3DVolume9_UnlockBox(p)
Definition: d3d9.h:286
#define IDirect3DVolume9_LockBox(p, a, b, c)
Definition: d3d9.h:285
#define IDirect3DVolume9_GetDesc(p, a)
Definition: d3d9.h:284
#define D3D_OK
Definition: d3d.h:106
#define D3DXERR_INVALIDDATA
Definition: compiler.c:53
const struct pixel_format_desc * get_format_info(D3DFORMAT format)
Definition: util.c:312
void get_aligned_rect(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, uint32_t width, uint32_t height, const struct pixel_format_desc *fmt_desc, RECT *aligned_rect)
Definition: surface.c:2654
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length)
Definition: util.c:211
static BOOL is_unknown_format(const struct pixel_format_desc *format)
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)
Definition: surface.c:2498
void d3dx_image_cleanup(struct d3dx_image *image)
Definition: surface.c:1392
const struct pixel_format_desc * get_d3dx_pixel_format_info(enum d3dx_pixel_format_id format)
Definition: util.c:297
static HRESULT d3dx9_handle_load_filter(DWORD *filter)
Definition: d3dx9_private.h:45
static void set_d3dx_pixels(struct d3dx_pixels *pixels, const void *data, uint32_t row_pitch, uint32_t slice_pitch, const PALETTEENTRY *palette, uint32_t width, uint32_t height, uint32_t depth, const RECT *unaligned_rect)
HRESULT d3dx_image_init(const void *src_data, uint32_t src_data_size, struct d3dx_image *image, uint32_t starting_mip_level, uint32_t flags)
Definition: surface.c:1332
HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t layer, uint32_t mip_level, struct d3dx_pixels *pixels)
Definition: surface.c:1398
HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pitch, 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)
Definition: surface.c:2450
d3dx_pixel_format_id
Definition: d3dx9_private.h:95
void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *image)
Definition: surface.c:1441
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
UINT32 uint32_t
Definition: types.h:75
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:146
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:179
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:50
static HRESULT d3dx_load_volume_from_memory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, enum d3dx_pixel_format_id src_format, uint32_t src_row_pitch, uint32_t src_slice_pitch, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
Definition: volume.c:85
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:242
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:24
static void set_d3dbox(D3DBOX *box, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, uint32_t front, uint32_t back)
Definition: volume.c:74
#define UnmapViewOfFile
Definition: compat.h:746
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLdouble GLdouble right
Definition: glext.h:10859
GLint left
Definition: glext.h:7726
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLint GLint bottom
Definition: glext.h:7726
unsigned int UINT
Definition: sysinfo.c:13
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
const char * filename
Definition: ioapi.h:137
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
static const WCHAR filenameW[]
Definition: resource.c:27
short WCHAR
Definition: pedump.c:58
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
static struct address_cache * front
Definition: rpcb_clnt.c:83
#define exit(n)
Definition: config.h:202
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dcommon.idl:28
UINT Left
Definition: d3d8types.h:1011
UINT Bottom
Definition: d3d8types.h:1014
UINT Top
Definition: d3d8types.h:1012
UINT Right
Definition: d3d8types.h:1013
UINT Front
Definition: d3d8types.h:1015
UINT Back
Definition: d3d8types.h:1016
Definition: palette.c:466
Definition: filter.c:165
Definition: image.c:84
enum d3dx_pixel_format_id format
#define WINAPI
Definition: msvc.h:6