OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d10 / ImageInformation10.cpp
1 #include "stdafx.h"
2 /*
3 * Copyright (c) 2007-2010 SlimDX Group
4
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:
11
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14
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
21 * THE SOFTWARE.
22 */
23
24 #include <d3d10.h>
25 #include <vcclr.h>
26
27 #include "Direct3D10Exception.h"
28
29 #include "ImageInformation10.h"
30
31 using namespace System;
32
33 namespace SlimDX
34 {
35         namespace Direct3D10
36         {       
37                 ImageInformation::ImageInformation( const D3DX10_IMAGE_INFO& native )
38                 {
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 );
48                 }
49
50                 D3DX10_IMAGE_INFO ImageInformation::CreateNativeVersion()
51                 {
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 );
62
63                         return native;
64                 }
65
66                 int ImageInformation::Width::get()
67                 {
68                         return m_Width;
69                 }
70
71                 void ImageInformation::Width::set( int value )
72                 {
73                         m_Width = value;
74                 }
75                 
76                 int ImageInformation::Height::get()
77                 {
78                         return m_Height;
79                 }
80
81                 void ImageInformation::Height::set( int value )
82                 {
83                         m_Height = value;
84                 }
85                 
86                 int ImageInformation::Depth::get()
87                 {
88                         return m_Depth;
89                 }
90
91                 void ImageInformation::Depth::set( int value )
92                 {
93                         m_Depth = value;
94                 }
95                 
96                 int ImageInformation::ArraySize::get()
97                 {
98                         return m_ArraySize;
99                 }
100
101                 void ImageInformation::ArraySize::set( int value )
102                 {
103                         m_ArraySize = value;
104                 }
105                 
106                 int ImageInformation::MipLevels::get()
107                 {
108                         return m_MipLevels;
109                 }
110
111                 void ImageInformation::MipLevels::set( int value )
112                 {
113                         m_MipLevels = value;
114                 }
115
116                 DXGI::Format ImageInformation::Format::get()
117                 {
118                         return m_Format;
119                 }
120
121                 void ImageInformation::Format::set( DXGI::Format value )
122                 {
123                         m_Format = value;
124                 }
125
126                 ResourceOptionFlags ImageInformation::OptionFlags::get()
127                 {
128                         return m_MiscFlags;
129                 }
130
131                 void ImageInformation::OptionFlags::set( ResourceOptionFlags value )
132                 {
133                         m_MiscFlags = value;
134                 }
135                 
136                 ResourceDimension ImageInformation::Dimension::get()
137                 {
138                         return m_Dimension;
139                 }
140
141                 void ImageInformation::Dimension::set( ResourceDimension value )
142                 {
143                         m_Dimension = value;
144                 }
145                 
146                 ImageFileFormat ImageInformation::FileFormat::get()
147                 {
148                         return m_FileFormat;
149                 }
150
151                 void ImageInformation::FileFormat::set( ImageFileFormat value )
152                 {
153                         m_FileFormat = value;
154                 }
155                 
156                 Nullable<ImageInformation> ImageInformation::FromFile( String^ fileName )
157                 {
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>();
163                         
164                         return ImageInformation( info );
165                 }
166                 
167                 Nullable<ImageInformation> ImageInformation::FromMemory( array<Byte>^ memory )
168                 {
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>();
174                         
175                         return ImageInformation( info );
176                 }
177
178                 bool ImageInformation::operator == ( ImageInformation left, ImageInformation right )
179                 {
180                         return ImageInformation::Equals( left, right );
181                 }
182
183                 bool ImageInformation::operator != ( ImageInformation left, ImageInformation right )
184                 {
185                         return !ImageInformation::Equals( left, right );
186                 }
187
188                 int ImageInformation::GetHashCode()
189                 {
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();
193                 }
194
195                 bool ImageInformation::Equals( Object^ value )
196                 {
197                         if( value == nullptr )
198                                 return false;
199
200                         if( value->GetType() != GetType() )
201                                 return false;
202
203                         return Equals( safe_cast<ImageInformation>( value ) );
204                 }
205
206                 bool ImageInformation::Equals( ImageInformation value )
207                 {
208                         return (
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
218                         );
219                 }
220
221                 bool ImageInformation::Equals( ImageInformation% value1, ImageInformation% value2 )
222                 {
223                         return (
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
233                         );
234                 }
235         }
236 }