Image.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. // WARNING - AUTOGENERATED - DO NOT EDIT
  2. //
  3. // Generated using `sharpie urho`
  4. //
  5. // Image.cs
  6. //
  7. // Copyright 2015 Xamarin Inc. All rights reserved.
  8. using System;
  9. using System.Runtime.InteropServices;
  10. using System.Collections.Generic;
  11. using Urho.Urho2D;
  12. using Urho.Gui;
  13. using Urho.Resources;
  14. using Urho.IO;
  15. using Urho.Navigation;
  16. using Urho.Network;
  17. namespace Urho.Resources
  18. {
  19. /// <summary>
  20. /// %Image resource.
  21. /// </summary>
  22. public unsafe partial class Image : Resource
  23. {
  24. unsafe partial void OnImageCreated ();
  25. [Preserve]
  26. public Image (IntPtr handle) : base (handle)
  27. {
  28. OnImageCreated ();
  29. }
  30. [Preserve]
  31. protected Image (UrhoObjectFlag emptyFlag) : base (emptyFlag)
  32. {
  33. OnImageCreated ();
  34. }
  35. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern int Image_GetType (IntPtr handle);
  37. private StringHash UrhoGetType ()
  38. {
  39. Runtime.ValidateRefCounted (this);
  40. return new StringHash (Image_GetType (handle));
  41. }
  42. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern IntPtr Image_GetTypeName (IntPtr handle);
  44. private string GetTypeName ()
  45. {
  46. Runtime.ValidateRefCounted (this);
  47. return Marshal.PtrToStringAnsi (Image_GetTypeName (handle));
  48. }
  49. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  50. internal static extern int Image_GetTypeStatic ();
  51. private static StringHash GetTypeStatic ()
  52. {
  53. Runtime.Validate (typeof(Image));
  54. return new StringHash (Image_GetTypeStatic ());
  55. }
  56. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern IntPtr Image_GetTypeNameStatic ();
  58. private static string GetTypeNameStatic ()
  59. {
  60. Runtime.Validate (typeof(Image));
  61. return Marshal.PtrToStringAnsi (Image_GetTypeNameStatic ());
  62. }
  63. [Preserve]
  64. public Image () : this (Application.CurrentContext)
  65. {
  66. }
  67. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  68. internal static extern IntPtr Image_Image (IntPtr context);
  69. [Preserve]
  70. public Image (Context context) : base (UrhoObjectFlag.Empty)
  71. {
  72. Runtime.Validate (typeof(Image));
  73. handle = Image_Image ((object)context == null ? IntPtr.Zero : context.Handle);
  74. Runtime.RegisterObject (this);
  75. OnImageCreated ();
  76. }
  77. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  78. internal static extern void Image_RegisterObject (IntPtr context);
  79. /// <summary>
  80. /// Register object factory.
  81. /// </summary>
  82. public static void RegisterObject (Context context)
  83. {
  84. Runtime.Validate (typeof(Image));
  85. Image_RegisterObject ((object)context == null ? IntPtr.Zero : context.Handle);
  86. }
  87. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  88. internal static extern bool Image_BeginLoad_File (IntPtr handle, IntPtr source);
  89. /// <summary>
  90. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  91. /// </summary>
  92. public override bool BeginLoad (File source)
  93. {
  94. Runtime.ValidateRefCounted (this);
  95. return Image_BeginLoad_File (handle, (object)source == null ? IntPtr.Zero : source.Handle);
  96. }
  97. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  98. internal static extern bool Image_BeginLoad_MemoryBuffer (IntPtr handle, IntPtr source);
  99. /// <summary>
  100. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  101. /// </summary>
  102. public override bool BeginLoad (MemoryBuffer source)
  103. {
  104. Runtime.ValidateRefCounted (this);
  105. return Image_BeginLoad_MemoryBuffer (handle, (object)source == null ? IntPtr.Zero : source.Handle);
  106. }
  107. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  108. internal static extern bool Image_Save_File (IntPtr handle, IntPtr dest);
  109. /// <summary>
  110. /// Save the image to a stream. Regardless of original format, the image is saved as png. Compressed image data is not supported. Return true if successful.
  111. /// </summary>
  112. public override bool Save (File dest)
  113. {
  114. Runtime.ValidateRefCounted (this);
  115. return Image_Save_File (handle, (object)dest == null ? IntPtr.Zero : dest.Handle);
  116. }
  117. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  118. internal static extern bool Image_Save_MemoryBuffer (IntPtr handle, IntPtr dest);
  119. /// <summary>
  120. /// Save the image to a stream. Regardless of original format, the image is saved as png. Compressed image data is not supported. Return true if successful.
  121. /// </summary>
  122. public override bool Save (MemoryBuffer dest)
  123. {
  124. Runtime.ValidateRefCounted (this);
  125. return Image_Save_MemoryBuffer (handle, (object)dest == null ? IntPtr.Zero : dest.Handle);
  126. }
  127. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  128. internal static extern bool Image_SaveFile (IntPtr handle, string fileName);
  129. /// <summary>
  130. /// Save the image to a file. Format of the image is determined by file extension. JPG is saved with maximum quality.
  131. /// </summary>
  132. public override bool SaveFile (string fileName)
  133. {
  134. Runtime.ValidateRefCounted (this);
  135. return Image_SaveFile (handle, fileName);
  136. }
  137. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  138. internal static extern bool Image_SetSize (IntPtr handle, int width, int height, uint components);
  139. /// <summary>
  140. /// Set 2D size and number of color components. Old image data will be destroyed and new data is undefined. Return true if successful.
  141. /// </summary>
  142. public bool SetSize (int width, int height, uint components)
  143. {
  144. Runtime.ValidateRefCounted (this);
  145. return Image_SetSize (handle, width, height, components);
  146. }
  147. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  148. internal static extern bool Image_SetSize0 (IntPtr handle, int width, int height, int depth, uint components);
  149. /// <summary>
  150. /// Set 3D size and number of color components. Old image data will be destroyed and new data is undefined. Return true if successful.
  151. /// </summary>
  152. public bool SetSize (int width, int height, int depth, uint components)
  153. {
  154. Runtime.ValidateRefCounted (this);
  155. return Image_SetSize0 (handle, width, height, depth, components);
  156. }
  157. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  158. internal static extern void Image_SetData (IntPtr handle, byte* pixelData);
  159. /// <summary>
  160. /// Set new image data.
  161. /// </summary>
  162. public void SetData (byte* pixelData)
  163. {
  164. Runtime.ValidateRefCounted (this);
  165. Image_SetData (handle, pixelData);
  166. }
  167. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  168. internal static extern void Image_SetPixel (IntPtr handle, int x, int y, ref Urho.Color color);
  169. /// <summary>
  170. /// Set a 2D pixel.
  171. /// </summary>
  172. public void SetPixel (int x, int y, Urho.Color color)
  173. {
  174. Runtime.ValidateRefCounted (this);
  175. Image_SetPixel (handle, x, y, ref color);
  176. }
  177. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  178. internal static extern void Image_SetPixel1 (IntPtr handle, int x, int y, int z, ref Urho.Color color);
  179. /// <summary>
  180. /// Set a 3D pixel.
  181. /// </summary>
  182. public void SetPixel (int x, int y, int z, Urho.Color color)
  183. {
  184. Runtime.ValidateRefCounted (this);
  185. Image_SetPixel1 (handle, x, y, z, ref color);
  186. }
  187. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  188. internal static extern void Image_SetPixelInt (IntPtr handle, int x, int y, uint uintColor);
  189. /// <summary>
  190. /// Set a 2D pixel with an integer color. R component is in the 8 lowest bits.
  191. /// </summary>
  192. public void SetPixelInt (int x, int y, uint uintColor)
  193. {
  194. Runtime.ValidateRefCounted (this);
  195. Image_SetPixelInt (handle, x, y, uintColor);
  196. }
  197. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  198. internal static extern void Image_SetPixelInt2 (IntPtr handle, int x, int y, int z, uint uintColor);
  199. /// <summary>
  200. /// Set a 3D pixel with an integer color. R component is in the 8 lowest bits.
  201. /// </summary>
  202. public void SetPixelInt (int x, int y, int z, uint uintColor)
  203. {
  204. Runtime.ValidateRefCounted (this);
  205. Image_SetPixelInt2 (handle, x, y, z, uintColor);
  206. }
  207. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  208. internal static extern bool Image_LoadColorLUT_File (IntPtr handle, IntPtr source);
  209. /// <summary>
  210. /// Load as color LUT. Return true if successful.
  211. /// </summary>
  212. public bool LoadColorLUT (File source)
  213. {
  214. Runtime.ValidateRefCounted (this);
  215. return Image_LoadColorLUT_File (handle, (object)source == null ? IntPtr.Zero : source.Handle);
  216. }
  217. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  218. internal static extern bool Image_LoadColorLUT_MemoryBuffer (IntPtr handle, IntPtr source);
  219. /// <summary>
  220. /// Load as color LUT. Return true if successful.
  221. /// </summary>
  222. public bool LoadColorLUT (MemoryBuffer source)
  223. {
  224. Runtime.ValidateRefCounted (this);
  225. return Image_LoadColorLUT_MemoryBuffer (handle, (object)source == null ? IntPtr.Zero : source.Handle);
  226. }
  227. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  228. internal static extern bool Image_FlipHorizontal (IntPtr handle);
  229. /// <summary>
  230. /// Flip image horizontally. Return true if successful.
  231. /// </summary>
  232. public bool FlipHorizontal ()
  233. {
  234. Runtime.ValidateRefCounted (this);
  235. return Image_FlipHorizontal (handle);
  236. }
  237. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  238. internal static extern bool Image_FlipVertical (IntPtr handle);
  239. /// <summary>
  240. /// Flip image vertically. Return true if successful.
  241. /// </summary>
  242. public bool FlipVertical ()
  243. {
  244. Runtime.ValidateRefCounted (this);
  245. return Image_FlipVertical (handle);
  246. }
  247. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  248. internal static extern bool Image_Resize (IntPtr handle, int width, int height);
  249. /// <summary>
  250. /// Resize image by bilinear resampling. Return true if successful.
  251. /// </summary>
  252. public bool Resize (int width, int height)
  253. {
  254. Runtime.ValidateRefCounted (this);
  255. return Image_Resize (handle, width, height);
  256. }
  257. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  258. internal static extern void Image_Clear (IntPtr handle, ref Urho.Color color);
  259. /// <summary>
  260. /// Clear the image with a color.
  261. /// </summary>
  262. public void Clear (Urho.Color color)
  263. {
  264. Runtime.ValidateRefCounted (this);
  265. Image_Clear (handle, ref color);
  266. }
  267. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  268. internal static extern void Image_ClearInt (IntPtr handle, uint uintColor);
  269. /// <summary>
  270. /// Clear the image with an integer color. R component is in the 8 lowest bits.
  271. /// </summary>
  272. public void ClearInt (uint uintColor)
  273. {
  274. Runtime.ValidateRefCounted (this);
  275. Image_ClearInt (handle, uintColor);
  276. }
  277. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  278. internal static extern bool Image_SaveBMP (IntPtr handle, string fileName);
  279. /// <summary>
  280. /// Save in BMP format. Return true if successful.
  281. /// </summary>
  282. public bool SaveBMP (string fileName)
  283. {
  284. Runtime.ValidateRefCounted (this);
  285. return Image_SaveBMP (handle, fileName);
  286. }
  287. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  288. internal static extern bool Image_SavePNG (IntPtr handle, string fileName);
  289. /// <summary>
  290. /// Save in PNG format. Return true if successful.
  291. /// </summary>
  292. public bool SavePNG (string fileName)
  293. {
  294. Runtime.ValidateRefCounted (this);
  295. return Image_SavePNG (handle, fileName);
  296. }
  297. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  298. internal static extern bool Image_SaveTGA (IntPtr handle, string fileName);
  299. /// <summary>
  300. /// Save in TGA format. Return true if successful.
  301. /// </summary>
  302. public bool SaveTGA (string fileName)
  303. {
  304. Runtime.ValidateRefCounted (this);
  305. return Image_SaveTGA (handle, fileName);
  306. }
  307. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  308. internal static extern bool Image_SaveJPG (IntPtr handle, string fileName, int quality);
  309. /// <summary>
  310. /// Save in JPG format with specified quality. Return true if successful.
  311. /// </summary>
  312. public bool SaveJPG (string fileName, int quality)
  313. {
  314. Runtime.ValidateRefCounted (this);
  315. return Image_SaveJPG (handle, fileName, quality);
  316. }
  317. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  318. internal static extern bool Image_SaveDDS (IntPtr handle, string fileName);
  319. /// <summary>
  320. /// Save in DDS format. Only uncompressed RGBA images are supported. Return true if successful.
  321. /// </summary>
  322. public bool SaveDDS (string fileName)
  323. {
  324. Runtime.ValidateRefCounted (this);
  325. return Image_SaveDDS (handle, fileName);
  326. }
  327. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  328. internal static extern bool Image_SaveWEBP (IntPtr handle, string fileName, float compression);
  329. /// <summary>
  330. /// Save in WebP format with minimum (fastest) or specified compression. Return true if successful. Fails always if WebP support is not compiled in.
  331. /// </summary>
  332. public bool SaveWEBP (string fileName, float compression = 0f)
  333. {
  334. Runtime.ValidateRefCounted (this);
  335. return Image_SaveWEBP (handle, fileName, compression);
  336. }
  337. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  338. internal static extern bool Image_IsCubemap (IntPtr handle);
  339. /// <summary>
  340. /// Whether this texture is detected as a cubemap, only relevant for DDS.
  341. /// </summary>
  342. private bool IsCubemap ()
  343. {
  344. Runtime.ValidateRefCounted (this);
  345. return Image_IsCubemap (handle);
  346. }
  347. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  348. internal static extern bool Image_IsArray (IntPtr handle);
  349. /// <summary>
  350. /// Whether this texture has been detected as a volume, only relevant for DDS.
  351. /// </summary>
  352. private bool IsArray ()
  353. {
  354. Runtime.ValidateRefCounted (this);
  355. return Image_IsArray (handle);
  356. }
  357. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  358. internal static extern bool Image_IsSRGB (IntPtr handle);
  359. /// <summary>
  360. /// Whether this texture is in sRGB, only relevant for DDS.
  361. /// </summary>
  362. private bool IsSRGB ()
  363. {
  364. Runtime.ValidateRefCounted (this);
  365. return Image_IsSRGB (handle);
  366. }
  367. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  368. internal static extern Color Image_GetPixel (IntPtr handle, int x, int y);
  369. /// <summary>
  370. /// Return a 2D pixel color.
  371. /// </summary>
  372. public Color GetPixel (int x, int y)
  373. {
  374. Runtime.ValidateRefCounted (this);
  375. return Image_GetPixel (handle, x, y);
  376. }
  377. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  378. internal static extern Color Image_GetPixel3 (IntPtr handle, int x, int y, int z);
  379. /// <summary>
  380. /// Return a 3D pixel color.
  381. /// </summary>
  382. public Color GetPixel (int x, int y, int z)
  383. {
  384. Runtime.ValidateRefCounted (this);
  385. return Image_GetPixel3 (handle, x, y, z);
  386. }
  387. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  388. internal static extern uint Image_GetPixelInt (IntPtr handle, int x, int y);
  389. /// <summary>
  390. /// Return a 2D pixel integer color. R component is in the 8 lowest bits.
  391. /// </summary>
  392. public uint GetPixelInt (int x, int y)
  393. {
  394. Runtime.ValidateRefCounted (this);
  395. return Image_GetPixelInt (handle, x, y);
  396. }
  397. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  398. internal static extern uint Image_GetPixelInt4 (IntPtr handle, int x, int y, int z);
  399. /// <summary>
  400. /// Return a 3D pixel integer color. R component is in the 8 lowest bits.
  401. /// </summary>
  402. public uint GetPixelInt (int x, int y, int z)
  403. {
  404. Runtime.ValidateRefCounted (this);
  405. return Image_GetPixelInt4 (handle, x, y, z);
  406. }
  407. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  408. internal static extern Color Image_GetPixelBilinear (IntPtr handle, float x, float y);
  409. /// <summary>
  410. /// Return a bilinearly sampled 2D pixel color. X and Y have the range 0-1.
  411. /// </summary>
  412. public Color GetPixelBilinear (float x, float y)
  413. {
  414. Runtime.ValidateRefCounted (this);
  415. return Image_GetPixelBilinear (handle, x, y);
  416. }
  417. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  418. internal static extern Color Image_GetPixelTrilinear (IntPtr handle, float x, float y, float z);
  419. /// <summary>
  420. /// Return a trilinearly sampled 3D pixel color. X, Y and Z have the range 0-1.
  421. /// </summary>
  422. public Color GetPixelTrilinear (float x, float y, float z)
  423. {
  424. Runtime.ValidateRefCounted (this);
  425. return Image_GetPixelTrilinear (handle, x, y, z);
  426. }
  427. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  428. internal static extern int Image_GetWidth (IntPtr handle);
  429. /// <summary>
  430. /// Return width.
  431. /// </summary>
  432. private int GetWidth ()
  433. {
  434. Runtime.ValidateRefCounted (this);
  435. return Image_GetWidth (handle);
  436. }
  437. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  438. internal static extern int Image_GetHeight (IntPtr handle);
  439. /// <summary>
  440. /// Return height.
  441. /// </summary>
  442. private int GetHeight ()
  443. {
  444. Runtime.ValidateRefCounted (this);
  445. return Image_GetHeight (handle);
  446. }
  447. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  448. internal static extern int Image_GetDepth (IntPtr handle);
  449. /// <summary>
  450. /// Return depth.
  451. /// </summary>
  452. private int GetDepth ()
  453. {
  454. Runtime.ValidateRefCounted (this);
  455. return Image_GetDepth (handle);
  456. }
  457. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  458. internal static extern uint Image_GetComponents (IntPtr handle);
  459. /// <summary>
  460. /// Return number of color components.
  461. /// </summary>
  462. private uint GetComponents ()
  463. {
  464. Runtime.ValidateRefCounted (this);
  465. return Image_GetComponents (handle);
  466. }
  467. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  468. internal static extern byte* Image_GetData (IntPtr handle);
  469. /// <summary>
  470. /// Return pixel data.
  471. /// </summary>
  472. private byte* GetData ()
  473. {
  474. Runtime.ValidateRefCounted (this);
  475. return Image_GetData (handle);
  476. }
  477. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  478. internal static extern bool Image_IsCompressed (IntPtr handle);
  479. /// <summary>
  480. /// Return whether is compressed.
  481. /// </summary>
  482. private bool IsCompressed ()
  483. {
  484. Runtime.ValidateRefCounted (this);
  485. return Image_IsCompressed (handle);
  486. }
  487. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  488. internal static extern CompressedFormat Image_GetCompressedFormat (IntPtr handle);
  489. /// <summary>
  490. /// Return compressed format.
  491. /// </summary>
  492. private CompressedFormat GetCompressedFormat ()
  493. {
  494. Runtime.ValidateRefCounted (this);
  495. return Image_GetCompressedFormat (handle);
  496. }
  497. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  498. internal static extern uint Image_GetNumCompressedLevels (IntPtr handle);
  499. /// <summary>
  500. /// Return number of compressed mip levels. Returns 0 if the image is has not been loaded from a source file containing multiple mip levels.
  501. /// </summary>
  502. private uint GetNumCompressedLevels ()
  503. {
  504. Runtime.ValidateRefCounted (this);
  505. return Image_GetNumCompressedLevels (handle);
  506. }
  507. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  508. internal static extern IntPtr Image_GetNextLevel (IntPtr handle);
  509. /// <summary>
  510. /// Return next mip level by bilinear filtering. Note that if the image is already 1x1x1, will keep returning an image of that size.
  511. /// </summary>
  512. private Image GetNextLevel ()
  513. {
  514. Runtime.ValidateRefCounted (this);
  515. return Runtime.LookupRefCounted<Image> (Image_GetNextLevel (handle));
  516. }
  517. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  518. internal static extern IntPtr Image_GetNextSibling (IntPtr handle);
  519. /// <summary>
  520. /// Return the next sibling image of an array or cubemap.
  521. /// </summary>
  522. private Image GetNextSibling ()
  523. {
  524. Runtime.ValidateRefCounted (this);
  525. return Runtime.LookupRefCounted<Image> (Image_GetNextSibling (handle));
  526. }
  527. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  528. internal static extern IntPtr Image_ConvertToRGBA (IntPtr handle);
  529. /// <summary>
  530. /// Return image converted to 4-component (RGBA) to circumvent modern rendering API's not supporting e.g. the luminance-alpha format.
  531. /// </summary>
  532. public Image ConvertToRGBA ()
  533. {
  534. Runtime.ValidateRefCounted (this);
  535. return Runtime.LookupRefCounted<Image> (Image_ConvertToRGBA (handle));
  536. }
  537. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  538. internal static extern CompressedLevel Image_GetCompressedLevel (IntPtr handle, uint index);
  539. /// <summary>
  540. /// Return a compressed mip level.
  541. /// </summary>
  542. public CompressedLevel GetCompressedLevel (uint index)
  543. {
  544. Runtime.ValidateRefCounted (this);
  545. return Image_GetCompressedLevel (handle, index);
  546. }
  547. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  548. internal static extern IntPtr Image_GetSubimage (IntPtr handle, ref Urho.IntRect rect);
  549. /// <summary>
  550. /// Return subimage from the image by the defined rect or null if failed. 3D images are not supported. You must free the subimage yourself.
  551. /// </summary>
  552. public Image GetSubimage (Urho.IntRect rect)
  553. {
  554. Runtime.ValidateRefCounted (this);
  555. return Runtime.LookupObject<Image> (Image_GetSubimage (handle, ref rect));
  556. }
  557. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  558. internal static extern void Image_PrecalculateLevels (IntPtr handle);
  559. /// <summary>
  560. /// Precalculate the mip levels. Used by asynchronous texture loading.
  561. /// </summary>
  562. public void PrecalculateLevels ()
  563. {
  564. Runtime.ValidateRefCounted (this);
  565. Image_PrecalculateLevels (handle);
  566. }
  567. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  568. internal static extern bool Image_HasAlphaChannel (IntPtr handle);
  569. /// <summary>
  570. /// Whether this texture has an alpha channel
  571. /// </summary>
  572. public bool HasAlphaChannel ()
  573. {
  574. Runtime.ValidateRefCounted (this);
  575. return Image_HasAlphaChannel (handle);
  576. }
  577. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  578. internal static extern bool Image_SetSubimage (IntPtr handle, IntPtr image, ref Urho.IntRect rect);
  579. /// <summary>
  580. /// Copy contents of the image into the defined rect, scaling if necessary. This image should already be large enough to include the rect. Compressed and 3D images are not supported.
  581. /// </summary>
  582. public bool SetSubimage (Image image, Urho.IntRect rect)
  583. {
  584. Runtime.ValidateRefCounted (this);
  585. return Image_SetSubimage (handle, (object)image == null ? IntPtr.Zero : image.Handle, ref rect);
  586. }
  587. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  588. internal static extern void Image_CleanupLevels (IntPtr handle);
  589. /// <summary>
  590. /// Clean up the mip levels.
  591. /// </summary>
  592. public void CleanupLevels ()
  593. {
  594. Runtime.ValidateRefCounted (this);
  595. Image_CleanupLevels (handle);
  596. }
  597. public override StringHash Type {
  598. get {
  599. return UrhoGetType ();
  600. }
  601. }
  602. public override string TypeName {
  603. get {
  604. return GetTypeName ();
  605. }
  606. }
  607. [Preserve]
  608. public new static StringHash TypeStatic {
  609. get {
  610. return GetTypeStatic ();
  611. }
  612. }
  613. public new static string TypeNameStatic {
  614. get {
  615. return GetTypeNameStatic ();
  616. }
  617. }
  618. /// <summary>
  619. /// Return pixel data.
  620. /// </summary>
  621. public byte* Data {
  622. get {
  623. return GetData ();
  624. }
  625. }
  626. /// <summary>
  627. /// Whether this texture is detected as a cubemap, only relevant for DDS.
  628. /// </summary>
  629. public bool Cubemap {
  630. get {
  631. return IsCubemap ();
  632. }
  633. }
  634. /// <summary>
  635. /// Whether this texture has been detected as a volume, only relevant for DDS.
  636. /// </summary>
  637. public bool Array {
  638. get {
  639. return IsArray ();
  640. }
  641. }
  642. /// <summary>
  643. /// Whether this texture is in sRGB, only relevant for DDS.
  644. /// </summary>
  645. public bool SRGB {
  646. get {
  647. return IsSRGB ();
  648. }
  649. }
  650. /// <summary>
  651. /// Return width.
  652. /// </summary>
  653. public int Width {
  654. get {
  655. return GetWidth ();
  656. }
  657. }
  658. /// <summary>
  659. /// Return height.
  660. /// </summary>
  661. public int Height {
  662. get {
  663. return GetHeight ();
  664. }
  665. }
  666. /// <summary>
  667. /// Return depth.
  668. /// </summary>
  669. public int Depth {
  670. get {
  671. return GetDepth ();
  672. }
  673. }
  674. /// <summary>
  675. /// Return number of color components.
  676. /// </summary>
  677. public uint Components {
  678. get {
  679. return GetComponents ();
  680. }
  681. }
  682. /// <summary>
  683. /// Return whether is compressed.
  684. /// </summary>
  685. public bool Compressed {
  686. get {
  687. return IsCompressed ();
  688. }
  689. }
  690. /// <summary>
  691. /// Return compressed format.
  692. /// </summary>
  693. public CompressedFormat CompressedFormat {
  694. get {
  695. return GetCompressedFormat ();
  696. }
  697. }
  698. /// <summary>
  699. /// Return number of compressed mip levels. Returns 0 if the image is has not been loaded from a source file containing multiple mip levels.
  700. /// </summary>
  701. public uint NumCompressedLevels {
  702. get {
  703. return GetNumCompressedLevels ();
  704. }
  705. }
  706. /// <summary>
  707. /// Return next mip level by bilinear filtering. Note that if the image is already 1x1x1, will keep returning an image of that size.
  708. /// </summary>
  709. public Image NextLevel {
  710. get {
  711. return GetNextLevel ();
  712. }
  713. }
  714. /// <summary>
  715. /// Return the next sibling image of an array or cubemap.
  716. /// </summary>
  717. public Image NextSibling {
  718. get {
  719. return GetNextSibling ();
  720. }
  721. }
  722. }
  723. }