3 * Copyright (c) 2007-2010 SlimDX Group
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "Direct3D10Exception.h"
29 #include "ImageInformation10.h"
31 using namespace System;
37 ImageInformation::ImageInformation( const D3DX10_IMAGE_INFO& native )
39 m_Width = native.Width;
40 m_Height = native.Height;
41 m_Depth = native.Depth;
42 m_ArraySize = native.ArraySize;
43 m_MipLevels = native.MipLevels;
44 m_MiscFlags = static_cast<ResourceOptionFlags>( native.MiscFlags );
45 m_Format = static_cast<DXGI::Format>( native.Format );
46 m_Dimension = static_cast<ResourceDimension>( native.ResourceDimension );
47 m_FileFormat = static_cast<ImageFileFormat>( native.ImageFileFormat );
50 D3DX10_IMAGE_INFO ImageInformation::CreateNativeVersion()
52 D3DX10_IMAGE_INFO native;
53 native.Width = m_Width;
54 native.Height = m_Height;
55 native.Depth = m_Depth;
56 native.ArraySize = m_ArraySize;
57 native.MipLevels = m_MipLevels;
58 native.MiscFlags = static_cast<UINT>( m_MiscFlags );
59 native.Format = static_cast<DXGI_FORMAT>( m_Format );
60 native.ResourceDimension = static_cast<D3D10_RESOURCE_DIMENSION>( m_Dimension );
61 native.ImageFileFormat = static_cast<D3DX10_IMAGE_FILE_FORMAT>( m_FileFormat );
66 int ImageInformation::Width::get()
71 void ImageInformation::Width::set( int value )
76 int ImageInformation::Height::get()
81 void ImageInformation::Height::set( int value )
86 int ImageInformation::Depth::get()
91 void ImageInformation::Depth::set( int value )
96 int ImageInformation::ArraySize::get()
101 void ImageInformation::ArraySize::set( int value )
106 int ImageInformation::MipLevels::get()
111 void ImageInformation::MipLevels::set( int value )
116 DXGI::Format ImageInformation::Format::get()
121 void ImageInformation::Format::set( DXGI::Format value )
126 ResourceOptionFlags ImageInformation::OptionFlags::get()
131 void ImageInformation::OptionFlags::set( ResourceOptionFlags value )
136 ResourceDimension ImageInformation::Dimension::get()
141 void ImageInformation::Dimension::set( ResourceDimension value )
146 ImageFileFormat ImageInformation::FileFormat::get()
151 void ImageInformation::FileFormat::set( ImageFileFormat value )
153 m_FileFormat = value;
156 Nullable<ImageInformation> ImageInformation::FromFile( String^ fileName )
158 D3DX10_IMAGE_INFO info;
159 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );
160 HRESULT hr = D3DX10GetImageInfoFromFile( pinnedName, 0, &info, 0 );
161 if( RECORD_D3D10( hr ).IsFailure )
162 return Nullable<ImageInformation>();
164 return ImageInformation( info );
167 Nullable<ImageInformation> ImageInformation::FromMemory( array<Byte>^ memory )
169 D3DX10_IMAGE_INFO info;
170 pin_ptr<unsigned char> pinnedMemory = &memory[0];
171 HRESULT hr = D3DX10GetImageInfoFromMemory( pinnedMemory, memory->Length, 0, &info, 0 );
172 if( RECORD_D3D10( hr ).IsFailure )
173 return Nullable<ImageInformation>();
175 return ImageInformation( info );
178 bool ImageInformation::operator == ( ImageInformation left, ImageInformation right )
180 return ImageInformation::Equals( left, right );
183 bool ImageInformation::operator != ( ImageInformation left, ImageInformation right )
185 return !ImageInformation::Equals( left, right );
188 int ImageInformation::GetHashCode()
190 return m_Width.GetHashCode() + m_Height.GetHashCode() + m_Depth.GetHashCode()
191 + m_ArraySize.GetHashCode() + m_MipLevels.GetHashCode() + m_MiscFlags.GetHashCode()
192 + m_Format.GetHashCode() + m_Dimension.GetHashCode() + m_FileFormat.GetHashCode();
195 bool ImageInformation::Equals( Object^ value )
197 if( value == nullptr )
200 if( value->GetType() != GetType() )
203 return Equals( safe_cast<ImageInformation>( value ) );
206 bool ImageInformation::Equals( ImageInformation value )
209 m_Width == value.m_Width &&
210 m_Height == value.m_Height &&
211 m_Depth == value.m_Depth &&
212 m_ArraySize == value.m_ArraySize &&
213 m_MipLevels == value.m_MipLevels &&
214 m_MiscFlags == value.m_MiscFlags &&
215 m_Format == value.m_Format &&
216 m_Dimension == value.m_Dimension &&
217 m_FileFormat == value.m_FileFormat
221 bool ImageInformation::Equals( ImageInformation% value1, ImageInformation% value2 )
224 value1.m_Width == value2.m_Width &&
225 value1.m_Height == value2.m_Height &&
226 value1.m_Depth == value2.m_Depth &&
227 value1.m_ArraySize == value2.m_ArraySize &&
228 value1.m_MipLevels == value2.m_MipLevels &&
229 value1.m_MiscFlags == value2.m_MiscFlags &&
230 value1.m_Format == value2.m_Format &&
231 value1.m_Dimension == value2.m_Dimension &&
232 value1.m_FileFormat == value2.m_FileFormat