/[gr2lib]/trunk/gr2lib/core/coreapi/coreapi.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coreapi/coreapi.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 192 - (show annotations) (download)
Sat Jul 24 08:45:59 2010 UTC (11 years, 4 months ago) by william
File size: 24321 byte(s)
add more xml documentation

1 using System;
2 using System.Runtime.InteropServices;
3
4 using gr2lib.core.typedefs;
5 using gr2lib.core.coretypes;
6 using gr2lib.core.coretypes.implementation;
7 //using gr2lib.core.coretypes;
8
9 namespace gr2lib.core
10 {
11 /// <summary>
12 /// coreapi class (this is the heart of gr2lib, this is where all of the Granny2 API calls will live
13 /// </summary>
14 public class coreapi
15 {
16 #region INTEROP SUPPORT
17 /// <summary>
18 /// ExternalSupport class
19 /// </summary>
20 public class ExternalSupport
21 {
22 /// <summary>
23 /// GetProcAddress(IntPtr hModule, string procName);
24 /// </summary>
25 /// <param name="hModule">pointer to module</param>
26 /// <param name="procName">procedure name</param>
27 /// <returns></returns>
28 [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
29 public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
30 /// <summary>
31 /// LoadLibrary(string lpFileName);
32 /// </summary>
33 /// <param name="lpFileName">filename</param>
34 /// <returns></returns>
35 [DllImport("kernel32", SetLastError = true)]
36 public static extern IntPtr LoadLibrary(string lpFileName);
37 }
38 #endregion
39
40 #region Granny2 API Version Support
41 /// <summary>
42 /// VersionSupport class
43 /// </summary>
44 public class VersionSupport
45 {
46 /// <summary>
47 /// GrannyVersionsMatch(major,minor,customization,build)
48 /// </summary>
49 /// <param name="MajorVersion">an integer, representing the major</param>
50 /// <param name="MinorVersion">an integer, representing the minor</param>
51 /// <param name="Customization">an integer, representing the customization</param>
52 /// <param name="BuildNumber">an integer, representing the build</param>
53 /// <returns>boolean indicating if the supplied version matches what the granny2.dll's intenal version</returns>
54 [DllImport("granny2.dll", EntryPoint = "GrannyVersionsMatch_", CallingConvention = CallingConvention.StdCall)]
55 internal static extern bool GrannyVersionsMatch(granny_int32x MajorVersion, granny_int32x MinorVersion, granny_int32x Customization, granny_int32x BuildNumber);
56 /// <summary>
57 /// GrannyGetVersion(&amp;major,&amp;minor,&amp;customization,&amp;build)
58 /// </summary>
59 /// <param name="MajorVersion">an integer, to store the major</param>
60 /// <param name="MinorVersion">an integer, to store the minor</param>
61 /// <param name="Customization">an integer, to store the customization</param>
62 /// <param name="BuildNumber">an integer, to store the build</param>
63 [DllImport("granny2.dll", EntryPoint = "GrannyGetVersion", CallingConvention = CallingConvention.StdCall)]
64 internal static extern void GrannyGetVersion(ref granny_int32x MajorVersion, ref granny_int32x MinorVersion, ref granny_int32x Customization, ref granny_int32x BuildNumber);
65 /// <summary>
66 /// GrannyGetVersionString()
67 /// </summary>
68 /// <returns>a string representing the granny2.dll's internal library version</returns>
69 [DllImport("granny2.dll", EntryPoint = "GrannyGetVersionString", CallingConvention = CallingConvention.StdCall)]
70 internal static extern string GrannyGetVersionString();
71 }
72 #endregion
73
74 #region Granny2 API File Loading Support
75 /// <summary>
76 /// FileLoadingSupport class
77 /// </summary>
78 public class FileLoadingSupport
79 {
80 /// <summary>
81 /// GrannyReadEntireFile(string fileName)
82 /// </summary>
83 /// <param name="fileName">the filename to load</param>
84 /// <returns>a pointer to the file</returns>
85 [DllImport("granny2.dll", EntryPoint = "GrannyReadEntireFile", CallingConvention = CallingConvention.StdCall)]
86 public static extern IntPtr GrannyReadEntireFile(string fileName);
87 /// <summary>
88 /// GetFileInfo(IntPtr file)
89 /// </summary>
90 /// <param name="file">pointer to the file: <see cref="GrannyReadEntireFile"/></param>
91 /// <returns>a pointer to the file info</returns>
92 [DllImport("granny2.dll", EntryPoint = "GrannyGetFileInfo", CallingConvention = CallingConvention.StdCall)]
93 public static extern IntPtr GetFileInfo(IntPtr file);
94 /// <summary>
95 /// FreeFile(IntPtr pointer)
96 /// </summary>
97 /// <param name="file">pointer to the file: <see cref="GrannyReadEntireFile"/></param>
98 [DllImport("granny2.dll", EntryPoint = "GrannyFreeFile", CallingConvention = CallingConvention.StdCall)]
99 public static extern void FreeFile(IntPtr file);
100 }
101 #endregion
102
103 #region Granny2 API Header Support
104 /// <summary>
105 /// HeaderSupport class
106 /// </summary>
107 public class HeaderSupport
108 {
109 /// <summary>
110 /// GrannyGetFileTypeTag(IntPtr File)
111 /// </summary>
112 /// <param name="File">pointer to the file: <see cref="coreapi.FileLoadingSupport.GrannyReadEntireFile"/></param>
113 /// <returns>an integer representing the TypeTag</returns>
114 [DllImport("granny2.dll", EntryPoint = "GrannyGetFileTypeTag", CallingConvention = CallingConvention.StdCall)]
115 public static extern int GrannyGetFileTypeTag(IntPtr File);
116 }
117 #endregion
118
119 #region Granny2 API Granny Texture Format Support
120 /// <summary>
121 /// TextureSupport class
122 /// </summary>
123 public class TextureSupport
124 {
125 /// <summary>
126 /// GrannyCopyTextureImage(IntPtr Texture, int ImageIndex, int MIPIndex, IntPtr Layout, int DestWidth, int DestHeight, int DestStride, IntPtr Pixels);
127 /// </summary>
128 /// <param name="Texture">pointer to the texture to copy (use the nativepointer, of the texture class)</param>
129 /// <param name="ImageIndex">index in the images list</param>
130 /// <param name="MIPIndex">index of the miplevel in the images list at ImageIndex</param>
131 /// <param name="Layout">pointer to the pixel layout (use the nativepointer, of the layout class)</param>
132 /// <param name="DestWidth">the target width</param>
133 /// <param name="DestHeight">the target height</param>
134 /// <param name="DestStride">width*bytesperpixel</param>
135 /// <param name="Pixels">pointer to the pixels (this will hold the copied pixels)</param>
136 /// <returns>a boolean value indicating that the copy operation succeeded</returns>
137 [DllImport("granny2.dll", EntryPoint = "_GrannyCopyTextureImage@32", CallingConvention = CallingConvention.StdCall)]
138 public static extern bool GrannyCopyTextureImage(IntPtr Texture, int ImageIndex, int MIPIndex, IntPtr Layout, int DestWidth, int DestHeight, int DestStride, IntPtr Pixels);
139 /// <summary>
140 /// GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SourcePixelLayout)
141 /// </summary>
142 /// <param name="SourceLayoutFromEnum">the source layout to swap: <see cref="granny_pixel_layout"/></param>
143 /// <param name="SwappedPixelLayout">returns the swapped pixel layout</param>
144 /// <param name="SwappedLayout">returns the swapped layout as a granny_pixel_layout value</param>
145 public static void GrannySwapRGBAToBGRA(granny_pixel_layout SourceLayoutFromEnum, out Layout SwappedPixelLayout, out granny_pixel_layout SwappedLayout)
146 {
147 SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout;
148 SwappedLayout = granny_pixel_layout.GrannyRGBA8888PixelFormat;
149 switch (SourceLayoutFromEnum)
150 {
151 case granny_pixel_layout.GrannyBGR555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB555PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB555PixelFormat; break;
152 case granny_pixel_layout.GrannyBGR565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB565PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB565PixelFormat; break;
153 case granny_pixel_layout.GrannyBGR888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGB888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGB888PixelFormat; break;
154 case granny_pixel_layout.GrannyBGRA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA4444PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA4444PixelFormat; break;
155 case granny_pixel_layout.GrannyBGRA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA5551PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA5551PixelFormat; break;
156 case granny_pixel_layout.GrannyBGRA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyRGBA8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyRGBA8888PixelFormat; break;
157 case granny_pixel_layout.GrannyRGB555PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR555PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR555PixelFormat; break;
158 case granny_pixel_layout.GrannyRGB565PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR565PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR565PixelFormat; break;
159 case granny_pixel_layout.GrannyRGB888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGR888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGR888PixelFormat; break;
160 case granny_pixel_layout.GrannyRGBA4444PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA4444PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA4444PixelFormat; break;
161 case granny_pixel_layout.GrannyRGBA5551PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA5551PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA5551PixelFormat; break;
162 case granny_pixel_layout.GrannyRGBA8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyBGRA8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyBGRA8888PixelFormat; break;
163 case granny_pixel_layout.GrannyARGB8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyABGR8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyABGR8888PixelFormat; break;
164 case granny_pixel_layout.GrannyABGR8888PixelFormat: SwappedPixelLayout = granny_pixel_layouts.GrannyARGB8888PixelFormat; SwappedLayout = granny_pixel_layout.GrannyARGB8888PixelFormat; break;
165 default: SwappedPixelLayout = granny_pixel_layouts.GrannyDefaultPixelLayout; break;
166 }
167 }
168 /// <summary>
169 /// Begin's a Raw Texture
170 /// </summary>
171 /// <param name="Width">image width</param>
172 /// <param name="Height">image height</param>
173 /// <param name="ResultingLayout">pointer to pixel layout</param>
174 /// <param name="StrideAlignment">StrideAlignment</param>
175 /// <returns>pointer to texture_builder</returns>
176 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginRawTexture@16", CallingConvention = CallingConvention.StdCall)]
177 public static extern IntPtr GrannyBeginRawTexture(granny_int32x Width, granny_int32x Height, IntPtr ResultingLayout, granny_int32x StrideAlignment);
178 /// <summary>
179 /// Begin's a S3TC Texture
180 /// </summary>
181 /// <param name="Width">image width</param>
182 /// <param name="Height">image height</param>
183 /// <param name="Format">granny_s3tc_texture_format Format</param>
184 /// <returns>pointer to texture_builder</returns>
185 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginS3TCTexture@12", CallingConvention = CallingConvention.StdCall)]
186 public static extern IntPtr GrannyBeginS3TCTexture(granny_int32x Width, granny_int32x Height, granny_s3tc_texture_format Format);
187 /// <summary>
188 /// Begin's a Best S3TC Texture match
189 /// </summary>
190 /// <param name="Width">image width</param>
191 /// <param name="Height">image height</param>
192 /// <returns>pointer to texture_builder</returns>
193 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginBestMatchS3TCTexture@8", CallingConvention = CallingConvention.StdCall)]
194 public static extern IntPtr GrannyBeginBestMatchS3TCTexture(granny_int32x Width, granny_int32x Height);
195 /// <summary>
196 /// Begin's a Bink Texture
197 /// </summary>
198 /// <param name="Width">image width</param>
199 /// <param name="Height">image height</param>
200 /// <param name="Compression">granny_compression_type ??? Compression</param>
201 /// <param name="Flags">granny_bink_texture_flags ??? Flags</param>
202 /// <returns>pointer to texture_builder</returns>
203 [DllImport("granny2.dll", EntryPoint = "_GrannyBeginBinkTexture@16", CallingConvention = CallingConvention.StdCall)]
204 public static extern IntPtr GrannyBeginBinkTexture(granny_int32x Width, granny_int32x Height, granny_int32x Compression, granny_uint32x Flags);
205 /// <summary>
206 /// End's a Texture
207 /// </summary>
208 /// <param name="Builder">pointer texture_build</param>
209 /// <returns>pointer to texture</returns>
210 [DllImport("granny2.dll", EntryPoint = "_GrannyEndTexture@4", CallingConvention = CallingConvention.StdCall)]
211 public static extern IntPtr GrannyEndTexture(IntPtr Builder);
212 /// <summary>
213 /// Gets the resulting Texture size
214 /// </summary>
215 /// <param name="Builder">pointer to texture_builder</param>
216 /// <returns>granny_int32x</returns>
217 [DllImport("granny2.dll", EntryPoint = "_GrannyGetResultingTextureSize@4", CallingConvention = CallingConvention.StdCall)]
218 public static extern granny_int32x GrannyGetResultingTextureSize(IntPtr Builder);
219 /// <summary>
220 /// End's Texture in Place (basically the same as GrannyEndTexture
221 /// </summary>
222 /// <param name="Builder">pointer to texture_builder</param>
223 /// <param name="Memory">pointer memory</param>
224 /// <returns></returns>
225 [DllImport("granny2.dll", EntryPoint = "_GrannyEndTextureInPlace@8", CallingConvention = CallingConvention.StdCall)]
226 public static extern IntPtr GrannyEndTextureInPlace(IntPtr Builder, IntPtr Memory);
227 /// <summary>
228 /// Set Image Scaling Filter
229 /// </summary>
230 /// <param name="Builder">pointer to texture_builder</param>
231 /// <param name="UpsamplingFilter">granny_pixel_filter_type UpsamplingFilter</param>
232 /// <param name="DownsamplingFilter">granny_pixel_filter_type DownsamplingFilter</param>
233 [DllImport("granny2.dll", EntryPoint = "_GrannySetImageScalingFilter@12", CallingConvention = CallingConvention.StdCall)]
234 public static extern void GrannySetImageScalingFilter(IntPtr Builder, granny_pixel_filter_type UpsamplingFilter, granny_pixel_filter_type DownsamplingFilter);
235 /// <summary>
236 /// Encode Image
237 /// </summary>
238 /// <param name="Builder">pointer to texture_builder</param>
239 /// <param name="Width">image width</param>
240 /// <param name="Height">image height</param>
241 /// <param name="Stride">Stride</param>
242 /// <param name="MIPLevelCount">MIPLevelCount</param>
243 /// <param name="RGBAData">pointer to RGBAData, in a byte[]</param>
244 [DllImport("granny2.dll", EntryPoint = "_GrannyEncodeImage@24", CallingConvention = CallingConvention.StdCall)]
245 public static extern void GrannyEncodeImage(IntPtr Builder, granny_int32x Width, granny_int32x Height, granny_int32x Stride, granny_int32x MIPLevelCount, IntPtr RGBAData);
246 /// <summary>
247 /// Free texture_builder
248 /// </summary>
249 /// <param name="Result">pointer to texture</param>
250 [DllImport("granny2.dll", EntryPoint = "_GrannyFreeBuilderResult@4", CallingConvention = CallingConvention.StdCall)]
251 public static extern void GrannyFreeBuilderResult(IntPtr Result);
252
253
254 }
255
256
257
258 #endregion
259
260 #region Granny2 API Logging Support
261 /// <summary>
262 /// LoggingSupport class
263 /// </summary>
264 public class LoggingSupport
265 {
266 /// <summary>
267 /// Delegate for the LogCallBack
268 /// </summary>
269 /// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param>
270 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
271 /// <param name="Message">the message</param>
272 /// <param name="UserData">pointer to userdata [will always be IntPtr.Zero, in gr2lib]</param>
273 [DllImport("granny2.dll", EntryPoint = "granny_log_function", CallingConvention = CallingConvention.StdCall)]
274 public static extern void granny_log_function(granny_log_message_type Type, granny_log_message_origin Origin, string Message, IntPtr UserData);
275 /// <summary>
276 /// Set the Log Callback
277 /// </summary>
278 /// <param name="LogCallback">the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param>
279 [DllImport("granny2.dll", EntryPoint = "_GrannySetLogCallback@4", CallingConvention = CallingConvention.StdCall)]
280 public static extern void GrannySetLogCallback(ref gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback);
281 /// <summary>
282 /// Get the Log Callback
283 /// </summary>
284 /// <param name="LogCallback">returns the callback <see cref="gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback"/></param>
285 [DllImport("granny2.dll", EntryPoint = "_GrannyGetLogCallback@4", CallingConvention = CallingConvention.StdCall)]
286 public static extern void GrannyGetLogCallback(out gr2lib.core.coretypes.implementation.granny_log_callback_builder.granny_log_callback LogCallback);
287 /// <summary>
288 /// Explicitly allow or disallow all logging
289 /// </summary>
290 /// <param name="Enabled">True = allow, False = disallow</param>
291 [DllImport("granny2.dll", EntryPoint = "_GrannyFilterAllMessages@4", CallingConvention = CallingConvention.StdCall)]
292 public static extern void GrannyFilterAllMessages(bool Enabled);
293 /// <summary>
294 /// Explicitly allow or disallow logging from specific Origin
295 /// </summary>
296 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
297 /// <param name="Enabled">>True = allow, False = disallow</param>
298 [DllImport("granny2.dll", EntryPoint = "_GrannyFilterMessage@8", CallingConvention = CallingConvention.StdCall)]
299 public static extern void GrannyFilterMessage(granny_log_message_origin Origin, bool Enabled);
300 /// <summary>
301 /// Check to see if anything is listening to log events
302 /// </summary>
303 /// <returns>a boolean value indicating if anything is listening to log events</returns>
304 [DllImport("granny2.dll", EntryPoint = "_GrannyLogging@0", CallingConvention = CallingConvention.StdCall)]
305 public static extern bool GrannyLogging();
306 /// <summary>
307 /// Returns the last Message Log Type, that was the most serious
308 /// </summary>
309 /// <returns></returns>
310 [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessageType@0", CallingConvention = CallingConvention.StdCall)]
311 public static extern granny_log_message_type GrannyGetMostSeriousMessageType();
312 /// <summary>
313 /// Get the message from the last most serious message
314 /// </summary>
315 /// <returns></returns>
316 [DllImport("granny2.dll", EntryPoint = "_GrannyGetMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)]
317 public static extern string GrannyGetMostSeriousMessage();
318 /// <summary>
319 /// Clear the last most serious message, so that new messages can be tracked
320 /// </summary>
321 [DllImport("granny2.dll", EntryPoint = "_GrannyClearMostSeriousMessage@0", CallingConvention = CallingConvention.StdCall)]
322 public static extern void GrannyClearMostSeriousMessage();
323 /// <summary>
324 /// Enable logging of all Granny reports to a file:
325 /// </summary>
326 /// <param name="FileName">Filenanme to log to</param>
327 /// <param name="Clear">True = overwrite file, False = append to file</param>
328 /// <returns></returns>
329 [DllImport("granny2.dll", EntryPoint = "_GrannySetLogFileName@8", CallingConvention = CallingConvention.StdCall)]
330 public static extern bool GrannySetLogFileName([MarshalAs(UnmanagedType.LPStr)] string FileName, bool Clear);
331 }
332 #endregion
333
334 #region Granny2 API Enum Value to String Support
335 /// <summary>
336 /// EnumToStringSupport class
337 /// </summary>
338 public class EnumToStringSupport
339 {
340 /// <summary>
341 /// GetGrannyEnumTypeString&lt;T&gt;(T _type)
342 /// </summary>
343 /// <typeparam name="T">The Type of the enum</typeparam>
344 /// <param name="_type">The Enum value</param>
345 /// <returns>The name of the enum member associated with the _type value</returns>
346 public static string GetGrannyEnumTypeString<T>(T _type) { return Enum.GetName(typeof(T), _type); }
347 /// <summary>
348 /// GrannyGetLogMessageTypeString(granny_log_message_type Type)
349 /// </summary>
350 /// <param name="Type">The Log Type <see cref="granny_log_message_type"/></param>
351 /// <returns>The name of the enum member associated with the Type value</returns>
352 public static string GrannyGetLogMessageTypeString(granny_log_message_type Type) { try { return GetGrannyEnumTypeString<granny_log_message_type>(Type); } catch { return GetGrannyEnumTypeString<granny_log_message_type>(granny_log_message_type.GrannyUnknownLogMessage); } }
353 /// <summary>
354 /// rannyGetLogMessageOriginString(granny_log_message_origin Origin)
355 /// </summary>
356 /// <param name="Origin">The Log Origin <see cref="granny_log_message_origin"/></param>
357 /// <returns>The name of the enum member associated with the Origin value</returns>
358 public static string GrannyGetLogMessageOriginString(granny_log_message_origin Origin) { try { return GetGrannyEnumTypeString<granny_log_message_origin>(Origin); } catch { return GetGrannyEnumTypeString<granny_log_message_origin>(granny_log_message_origin.GrannyUnknownLogMessage); } }
359 #endregion
360 }
361 }
362 }

  ViewVC Help
Powered by ViewVC 1.1.22