2 * Copyright 2010 Christian Costa
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.
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.
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
20 #include "d3dx9_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
24 HRESULT WINAPI
D3DXLoadVolumeFromFileA(IDirect3DVolume9
*dst_volume
,
25 const PALETTEENTRY
*dst_palette
,
26 const D3DBOX
*dst_box
,
28 const D3DBOX
*src_box
,
37 TRACE("(%p, %p, %p, %s, %p, %#x, %#x, %p)\n",
38 dst_volume
, dst_palette
, dst_box
, debugstr_a(filename
), src_box
,
39 filter
, color_key
, info
);
41 if (!dst_volume
|| !filename
) return D3DERR_INVALIDCALL
;
43 length
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
44 filenameW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(*filenameW
));
45 if (!filenameW
) return E_OUTOFMEMORY
;
47 hr
= D3DXLoadVolumeFromFileW(dst_volume
, dst_palette
, dst_box
, filenameW
,
48 src_box
, filter
, color_key
, info
);
49 HeapFree(GetProcessHeap(), 0, filenameW
);
54 HRESULT WINAPI
D3DXLoadVolumeFromFileW(IDirect3DVolume9
*dst_volume
,
55 const PALETTEENTRY
*dst_palette
,
56 const D3DBOX
*dst_box
,
57 const WCHAR
*filename
,
58 const D3DBOX
*src_box
,
67 TRACE("(%p, %p, %p, %s, %p, %#x, %#x, %p)\n",
68 dst_volume
, dst_palette
, dst_box
, debugstr_w(filename
), src_box
,
69 filter
, color_key
, info
);
71 if (!dst_volume
|| !filename
) return D3DERR_INVALIDCALL
;
73 if (FAILED(map_view_of_file(filename
, &data
, &data_size
)))
74 return D3DXERR_INVALIDDATA
;
76 hr
= D3DXLoadVolumeFromFileInMemory(dst_volume
, dst_palette
, dst_box
,
77 data
, data_size
, src_box
, filter
, color_key
, info
);
78 UnmapViewOfFile(data
);
83 HRESULT WINAPI
D3DXLoadVolumeFromMemory(IDirect3DVolume9
*dst_volume
,
84 const PALETTEENTRY
*dst_palette
,
85 const D3DBOX
*dst_box
,
86 const void *src_memory
,
90 const PALETTEENTRY
*src_palette
,
91 const D3DBOX
*src_box
,
97 D3DLOCKED_BOX locked_box
;
98 struct volume dst_size
, src_size
;
99 const struct pixel_format_desc
*src_format_desc
, *dst_format_desc
;
101 TRACE("(%p, %p, %p, %p, %#x, %u, %u, %p, %p, %x, %x)\n", dst_volume
, dst_palette
, dst_box
,
102 src_memory
, src_format
, src_row_pitch
, src_slice_pitch
, src_palette
, src_box
,
105 if (!dst_volume
|| !src_memory
|| !src_box
) return D3DERR_INVALIDCALL
;
107 if (src_format
== D3DFMT_UNKNOWN
108 || src_box
->Left
>= src_box
->Right
109 || src_box
->Top
>= src_box
->Bottom
110 || src_box
->Front
>= src_box
->Back
)
113 if (filter
== D3DX_DEFAULT
)
114 filter
= D3DX_FILTER_TRIANGLE
| D3DX_FILTER_DITHER
;
116 IDirect3DVolume9_GetDesc(dst_volume
, &desc
);
118 src_size
.width
= src_box
->Right
- src_box
->Left
;
119 src_size
.height
= src_box
->Bottom
- src_box
->Top
;
120 src_size
.depth
= src_box
->Back
- src_box
->Front
;
124 dst_size
.width
= desc
.Width
;
125 dst_size
.height
= desc
.Height
;
126 dst_size
.depth
= desc
.Depth
;
130 if (dst_box
->Left
>= dst_box
->Right
|| dst_box
->Right
> desc
.Width
)
131 return D3DERR_INVALIDCALL
;
132 if (dst_box
->Top
>= dst_box
->Bottom
|| dst_box
->Bottom
> desc
.Height
)
133 return D3DERR_INVALIDCALL
;
134 if (dst_box
->Front
>= dst_box
->Back
|| dst_box
->Back
> desc
.Depth
)
135 return D3DERR_INVALIDCALL
;
137 dst_size
.width
= dst_box
->Right
- dst_box
->Left
;
138 dst_size
.height
= dst_box
->Bottom
- dst_box
->Top
;
139 dst_size
.depth
= dst_box
->Back
- dst_box
->Front
;
142 src_format_desc
= get_format_info(src_format
);
143 if (src_format_desc
->type
== FORMAT_UNKNOWN
)
146 dst_format_desc
= get_format_info(desc
.Format
);
147 if (dst_format_desc
->type
== FORMAT_UNKNOWN
)
150 if (desc
.Format
== src_format
151 && dst_size
.width
== src_size
.width
152 && dst_size
.height
== src_size
.height
153 && dst_size
.depth
== src_size
.depth
156 const BYTE
*src_addr
;
158 if (src_box
->Left
& (src_format_desc
->block_width
- 1)
159 || src_box
->Top
& (src_format_desc
->block_height
- 1)
160 || (src_box
->Right
& (src_format_desc
->block_width
- 1)
161 && src_size
.width
!= desc
.Width
)
162 || (src_box
->Bottom
& (src_format_desc
->block_height
- 1)
163 && src_size
.height
!= desc
.Height
))
165 FIXME("Source box (%u, %u, %u, %u) is misaligned\n",
166 src_box
->Left
, src_box
->Top
, src_box
->Right
, src_box
->Bottom
);
170 src_addr
= src_memory
;
171 src_addr
+= src_box
->Front
* src_slice_pitch
;
172 src_addr
+= (src_box
->Top
/ src_format_desc
->block_height
) * src_row_pitch
;
173 src_addr
+= (src_box
->Left
/ src_format_desc
->block_width
) * src_format_desc
->block_byte_count
;
175 hr
= IDirect3DVolume9_LockBox(dst_volume
, &locked_box
, dst_box
, 0);
176 if (FAILED(hr
)) return hr
;
178 copy_pixels(src_addr
, src_row_pitch
, src_slice_pitch
,
179 locked_box
.pBits
, locked_box
.RowPitch
, locked_box
.SlicePitch
,
180 &dst_size
, dst_format_desc
);
182 IDirect3DVolume9_UnlockBox(dst_volume
);
186 const BYTE
*src_addr
;
188 if (!is_conversion_from_supported(src_format_desc
)
189 || !is_conversion_to_supported(dst_format_desc
))
191 FIXME("Pixel format conversion is not implemented %#x -> %#x\n",
192 src_format_desc
->format
, dst_format_desc
->format
);
196 src_addr
= src_memory
;
197 src_addr
+= src_box
->Front
* src_slice_pitch
;
198 src_addr
+= src_box
->Top
* src_row_pitch
;
199 src_addr
+= src_box
->Left
* src_format_desc
->bytes_per_pixel
;
201 hr
= IDirect3DVolume9_LockBox(dst_volume
, &locked_box
, dst_box
, 0);
202 if (FAILED(hr
)) return hr
;
204 if ((filter
& 0xf) == D3DX_FILTER_NONE
)
206 convert_argb_pixels(src_memory
, src_row_pitch
, src_slice_pitch
, &src_size
, src_format_desc
,
207 locked_box
.pBits
, locked_box
.RowPitch
, locked_box
.SlicePitch
, &dst_size
, dst_format_desc
, color_key
,
212 if ((filter
& 0xf) != D3DX_FILTER_POINT
)
213 FIXME("Unhandled filter %#x.\n", filter
);
215 point_filter_argb_pixels(src_addr
, src_row_pitch
, src_slice_pitch
, &src_size
, src_format_desc
,
216 locked_box
.pBits
, locked_box
.RowPitch
, locked_box
.SlicePitch
, &dst_size
, dst_format_desc
, color_key
,
220 IDirect3DVolume9_UnlockBox(dst_volume
);
226 HRESULT WINAPI
D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9
*dst_volume
,
227 const PALETTEENTRY
*dst_palette
,
228 const D3DBOX
*dst_box
,
229 const void *src_data
,
231 const D3DBOX
*src_box
,
234 D3DXIMAGE_INFO
*src_info
)
238 D3DXIMAGE_INFO image_info
;
240 TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_data %p, src_data_size %u, src_box %p, "
241 "filter %#x, color_key 0x%08x, src_info %p.\n",
242 dst_volume
, dst_palette
, dst_box
, src_data
, src_data_size
, src_box
,
243 filter
, color_key
, src_info
);
245 if (!dst_volume
|| !src_data
)
246 return D3DERR_INVALIDCALL
;
248 if (FAILED(hr
= D3DXGetImageInfoFromFileInMemory(src_data
, src_data_size
, &image_info
)))
253 if (src_box
->Right
> image_info
.Width
254 || src_box
->Bottom
> image_info
.Height
255 || src_box
->Back
> image_info
.Depth
)
256 return D3DERR_INVALIDCALL
;
264 box
.Right
= image_info
.Width
;
265 box
.Bottom
= image_info
.Height
;
267 box
.Back
= image_info
.Depth
;
271 if (image_info
.ImageFileFormat
!= D3DXIFF_DDS
)
273 FIXME("File format %#x is not supported yet\n", image_info
.ImageFileFormat
);
277 hr
= load_volume_from_dds(dst_volume
, dst_palette
, dst_box
, src_data
, &box
,
278 filter
, color_key
, &image_info
);
279 if (FAILED(hr
)) return hr
;
282 *src_info
= image_info
;
287 HRESULT WINAPI
D3DXLoadVolumeFromVolume(IDirect3DVolume9
*dst_volume
,
288 const PALETTEENTRY
*dst_palette
,
289 const D3DBOX
*dst_box
,
290 IDirect3DVolume9
*src_volume
,
291 const PALETTEENTRY
*src_palette
,
292 const D3DBOX
*src_box
,
299 D3DLOCKED_BOX locked_box
;
301 TRACE("(%p, %p, %p, %p, %p, %p, %#x, %#x)\n",
302 dst_volume
, dst_palette
, dst_box
, src_volume
, src_palette
, src_box
,
305 if (!dst_volume
|| !src_volume
) return D3DERR_INVALIDCALL
;
307 IDirect3DVolume9_GetDesc(src_volume
, &desc
);
311 box
.Left
= box
.Top
= 0;
312 box
.Right
= desc
.Width
;
313 box
.Bottom
= desc
.Height
;
315 box
.Back
= desc
.Depth
;
319 hr
= IDirect3DVolume9_LockBox(src_volume
, &locked_box
, NULL
, D3DLOCK_READONLY
);
320 if (FAILED(hr
)) return hr
;
322 hr
= D3DXLoadVolumeFromMemory(dst_volume
, dst_palette
, dst_box
,
323 locked_box
.pBits
, desc
.Format
, locked_box
.RowPitch
, locked_box
.SlicePitch
,
324 src_palette
, &box
, filter
, color_key
);
326 IDirect3DVolume9_UnlockBox(src_volume
);