3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 #include "../ComObject.h"
\r
28 #include "../DataStream.h"
\r
30 #include "Direct3D9Exception.h"
\r
34 #include "Texture.h"
\r
36 using namespace System;
\r
37 using namespace System::IO;
\r
43 VolumeDescription Volume::Description::get()
\r
45 VolumeDescription description;
\r
47 HRESULT hr = InternalPointer->GetDesc( reinterpret_cast<D3DVOLUME_DESC*>( &description ) );
\r
53 DataBox^ Volume::LockBox( LockFlags flags )
\r
55 D3DLOCKED_BOX lockedBox;
\r
57 HRESULT hr = InternalPointer->LockBox( &lockedBox, NULL, static_cast<DWORD>( flags ) );
\r
59 if( RECORD_D3D9(hr).IsFailure )
\r
62 int lockedSize = lockedBox.SlicePitch * Description.Depth;
\r
64 bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;
\r
65 DataBox^ outBox = gcnew DataBox( lockedBox.RowPitch, lockedBox.SlicePitch, gcnew DataStream( lockedBox.pBits, lockedSize, true, !readOnly, false ) );
\r
69 DataBox^ Volume::LockBox( Box box, LockFlags flags )
\r
71 D3DLOCKED_BOX lockedBox;
\r
73 HRESULT hr = InternalPointer->LockBox( &lockedBox, reinterpret_cast<D3DBOX*>( &box ), static_cast<DWORD>( flags ) );
\r
75 if( RECORD_D3D9(hr).IsFailure )
\r
78 int lockedSize = lockedBox.SlicePitch * Description.Depth;
\r
80 bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;
\r
81 DataBox^ outBox = gcnew DataBox( lockedBox.RowPitch, lockedBox.SlicePitch, gcnew DataStream( lockedBox.pBits, lockedSize, true, !readOnly, false ) );
\r
85 Result Volume::UnlockBox()
\r
87 HRESULT hr = InternalPointer->UnlockBox();
\r
88 return RECORD_D3D9( hr );
\r
91 Result Volume::FromFileInMemory_Internal( Volume^ volume, const void* memory, UINT size, Filter filter, int colorKey,
\r
92 Box* sourceBox, Box* destinationBox, PaletteEntry* palette, ImageInformation* imageInformation )
\r
94 HRESULT hr = D3DXLoadVolumeFromFileInMemory( volume->InternalPointer,
\r
95 reinterpret_cast<const PALETTEENTRY*>( palette ),
\r
96 reinterpret_cast<const D3DBOX*>( destinationBox ), memory, size,
\r
97 reinterpret_cast<const D3DBOX*>( sourceBox ), static_cast<DWORD>( filter ),
\r
98 static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( imageInformation ) );
\r
100 return RECORD_D3D9( hr );
\r
103 Result Volume::FromFileInMemory( Volume^ volume, array<Byte>^ memory, Filter filter, int colorKey, Box sourceBox,
\r
104 Box destinationBox, array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )
\r
106 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
\r
107 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
108 pin_ptr<unsigned char> pinnedMemory = &memory[0];
\r
110 return FromFileInMemory_Internal( volume, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,
\r
111 &sourceBox, &destinationBox, pinnedPalette, pinnedImageInfo );
\r
114 Result Volume::FromFileInMemory( Volume^ volume, array<Byte>^ memory, Filter filter, int colorKey, Box sourceBox,
\r
115 Box destinationBox, [Out] ImageInformation% imageInformation )
\r
117 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
118 pin_ptr<unsigned char> pinnedMemory = &memory[0];
\r
120 return FromFileInMemory_Internal( volume, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,
\r
121 &sourceBox, &destinationBox, NULL, pinnedImageInfo );
\r
124 Result Volume::FromFileInMemory( Volume^ volume, array<Byte>^ memory, Filter filter, int colorKey, Box sourceBox,
\r
125 Box destinationBox )
\r
127 pin_ptr<unsigned char> pinnedMemory = &memory[0];
\r
129 return FromFileInMemory_Internal( volume, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,
\r
130 &sourceBox, &destinationBox, NULL, NULL );
\r
133 Result Volume::FromFileInMemory( Volume^ volume, array<Byte>^ memory, Filter filter, int colorKey )
\r
135 pin_ptr<unsigned char> pinnedMemory = &memory[0];
\r
137 return FromFileInMemory_Internal( volume, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,
\r
138 NULL, NULL, NULL, NULL );
\r
141 Result Volume::FromFileInStream( Volume^ volume, Stream^ stream, Filter filter, int colorKey, Box sourceBox,
\r
142 Box destinationBox, array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )
\r
144 DataStream^ ds = nullptr;
\r
145 array<Byte>^ data = Utilities::ReadStream( stream, &ds );
\r
147 if( data == nullptr )
\r
149 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
150 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
\r
151 UINT size = static_cast<UINT>( ds->RemainingLength );
\r
153 return FromFileInMemory_Internal( volume, ds->SeekToEnd(), size, filter, colorKey,
\r
154 &sourceBox, &destinationBox, pinnedPalette, pinnedImageInfo );
\r
157 return FromFileInMemory( volume, data, filter, colorKey, sourceBox, destinationBox,
\r
158 palette, imageInformation );
\r
161 Result Volume::FromFileInStream( Volume^ volume, Stream^ stream, Filter filter, int colorKey, Box sourceBox,
\r
162 Box destinationBox, [Out] ImageInformation% imageInformation )
\r
164 DataStream^ ds = nullptr;
\r
165 array<Byte>^ data = Utilities::ReadStream( stream, &ds );
\r
167 if( data == nullptr )
\r
169 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
170 UINT size = static_cast<UINT>( ds->RemainingLength );
\r
172 return FromFileInMemory_Internal( volume, ds->SeekToEnd(), size, filter, colorKey,
\r
173 &sourceBox, &destinationBox, NULL, pinnedImageInfo );
\r
176 return FromFileInMemory( volume, data, filter, colorKey, sourceBox, destinationBox,
\r
177 imageInformation );
\r
180 Result Volume::FromFileInStream( Volume^ volume, Stream^ stream, Filter filter, int colorKey, Box sourceBox,
\r
181 Box destinationBox )
\r
183 DataStream^ ds = nullptr;
\r
184 array<Byte>^ data = Utilities::ReadStream( stream, &ds );
\r
186 if( data == nullptr )
\r
188 UINT size = static_cast<UINT>( ds->RemainingLength );
\r
190 return FromFileInMemory_Internal( volume, ds->SeekToEnd(), size, filter, colorKey,
\r
191 &sourceBox, &destinationBox, NULL, NULL );
\r
194 return FromFileInMemory( volume, data, filter, colorKey, sourceBox, destinationBox );
\r
197 Result Volume::FromFileInStream( Volume^ volume, Stream^ stream, Filter filter, int colorKey )
\r
199 DataStream^ ds = nullptr;
\r
200 array<Byte>^ data = Utilities::ReadStream( stream, &ds );
\r
202 if( data == nullptr )
\r
204 UINT size = static_cast<UINT>( ds->RemainingLength );
\r
206 return FromFileInMemory_Internal( volume, ds->SeekToEnd(), size, filter, colorKey,
\r
207 NULL, NULL, NULL, NULL );
\r
210 return FromFileInMemory( volume, data, filter, colorKey );
\r
213 Result Volume::FromFile( Volume^ volume, String^ fileName, Filter filter, int colorKey,
\r
214 Box sourceBox, Box destinationBox,
\r
215 array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )
\r
217 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
\r
218 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
219 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );
\r
221 HRESULT hr = D3DXLoadVolumeFromFile( volume->InternalPointer,
\r
222 reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ),
\r
223 reinterpret_cast<const D3DBOX*>( &destinationBox ), pinnedName,
\r
224 reinterpret_cast<const D3DBOX*>( &sourceBox ), static_cast<DWORD>( filter ),
\r
225 static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ) );
\r
226 return RECORD_D3D9( hr );
\r
229 Result Volume::FromFile( Volume^ volume, String^ fileName, Filter filter, int colorKey,
\r
230 Box sourceBox, Box destinationBox,
\r
231 [Out] ImageInformation% imageInformation )
\r
233 pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;
\r
234 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );
\r
236 HRESULT hr = D3DXLoadVolumeFromFile( volume->InternalPointer, NULL,
\r
237 reinterpret_cast<const D3DBOX*>( &destinationBox ), pinnedName,
\r
238 reinterpret_cast<const D3DBOX*>( &sourceBox ), static_cast<DWORD>( filter ),
\r
239 static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ) );
\r
240 return RECORD_D3D9( hr );
\r
243 Result Volume::FromFile( Volume^ volume, String^ fileName, Filter filter, int colorKey,
\r
244 Box sourceBox, Box destinationBox )
\r
246 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );
\r
248 HRESULT hr = D3DXLoadVolumeFromFile( volume->InternalPointer, NULL,
\r
249 reinterpret_cast<const D3DBOX*>( &destinationBox ), pinnedName,
\r
250 reinterpret_cast<const D3DBOX*>( &sourceBox ), static_cast<DWORD>( filter ),
\r
251 static_cast<D3DCOLOR>( colorKey ), NULL );
\r
252 return RECORD_D3D9( hr );
\r
255 Result Volume::FromFile( Volume^ volume, String^ fileName, Filter filter, int colorKey )
\r
257 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );
\r
259 HRESULT hr = D3DXLoadVolumeFromFile( volume->InternalPointer, NULL, NULL, pinnedName,
\r
260 NULL, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), NULL );
\r
261 return RECORD_D3D9( hr );
\r
264 Result Volume::FromVolume( Volume^ destinationVolume, Volume^ sourceVolume, Filter filter, int colorKey,
\r
265 Box sourceBox, Box destinationBox,
\r
266 array<PaletteEntry>^ destinationPalette, array<PaletteEntry>^ sourcePalette )
\r
268 pin_ptr<PaletteEntry> pinnedSource = sourcePalette == nullptr ? nullptr : &sourcePalette[0];
\r
269 pin_ptr<PaletteEntry> pinnedDest = destinationPalette == nullptr ? nullptr : &destinationPalette[0];
\r
271 HRESULT hr = D3DXLoadVolumeFromVolume( destinationVolume->InternalPointer,
\r
272 reinterpret_cast<const PALETTEENTRY*>( pinnedDest ), reinterpret_cast<const D3DBOX*>( &destinationBox ),
\r
273 sourceVolume->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedSource ),
\r
274 reinterpret_cast<const D3DBOX*>( &sourceBox ), static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );
\r
275 return RECORD_D3D9( hr );
\r
278 Result Volume::FromVolume( Volume^ destinationVolume, Volume^ sourceVolume, Filter filter, int colorKey,
\r
279 Box sourceBox, Box destinationBox )
\r
281 HRESULT hr = D3DXLoadVolumeFromVolume( destinationVolume->InternalPointer,
\r
282 NULL, reinterpret_cast<const D3DBOX*>( &destinationBox ), sourceVolume->InternalPointer, NULL,
\r
283 reinterpret_cast<const D3DBOX*>( &sourceBox ), static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );
\r
284 return RECORD_D3D9( hr );
\r
287 Result Volume::FromVolume( Volume^ destinationVolume, Volume^ sourceVolume, Filter filter, int colorKey )
\r
289 HRESULT hr = D3DXLoadVolumeFromVolume( destinationVolume->InternalPointer, NULL, NULL,
\r
290 sourceVolume->InternalPointer, NULL, NULL, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );
\r
291 return RECORD_D3D9( hr );
\r
294 DataStream^ Volume::ToStream( Volume^ volume, ImageFileFormat format, Box box, array<PaletteEntry>^ palette )
\r
296 ID3DXBuffer *result = NULL;
\r
297 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
\r
299 HRESULT hr = D3DXSaveVolumeToFileInMemory( &result, static_cast<D3DXIMAGE_FILEFORMAT>( format ),
\r
300 volume->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ), reinterpret_cast<const D3DBOX*>( &box ) );
\r
302 if( RECORD_D3D9(hr).IsFailure )
\r
305 return gcnew DataStream( result );
\r
308 DataStream^ Volume::ToStream( Volume^ volume, ImageFileFormat format, Box box )
\r
310 return ToStream( volume, format, box, nullptr );
\r
313 DataStream^ Volume::ToStream( Volume^ volume, ImageFileFormat format )
\r
315 ID3DXBuffer *result = NULL;
\r
317 HRESULT hr = D3DXSaveVolumeToFileInMemory( &result, static_cast<D3DXIMAGE_FILEFORMAT>( format ),
\r
318 volume->InternalPointer, NULL, NULL );
\r
320 if( RECORD_D3D9(hr).IsFailure )
\r
323 return gcnew DataStream( result );
\r
326 Result Volume::ToFile( Volume^ volume, String^ fileName, ImageFileFormat format, Box box, array<PaletteEntry>^ palette )
\r
328 pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);
\r
329 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
\r
331 HRESULT hr = D3DXSaveVolumeToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ),
\r
332 volume->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ),
\r
333 reinterpret_cast<const D3DBOX*>( &box ) );
\r
334 return RECORD_D3D9( hr );
\r
337 Result Volume::ToFile( Volume^ volume, String^ fileName, ImageFileFormat format, Box box )
\r
339 return ToFile( volume, fileName, format, box, nullptr );
\r
342 Result Volume::ToFile( Volume^ volume, String^ fileName, ImageFileFormat format )
\r
344 pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);
\r
346 HRESULT hr = D3DXSaveVolumeToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ),
\r
347 volume->InternalPointer, NULL, NULL );
\r
348 return RECORD_D3D9( hr );
\r