PixelUtility.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. namespace BansheeEngine
  8. {
  9. public static class PixelUtility
  10. {
  11. public static int GetMemorySize(int width, int height, int depth, PixelFormat format)
  12. {
  13. int value;
  14. Internal_GetMemorySize(width, height, depth, format, out value);
  15. return value;
  16. }
  17. public static bool HasAlpha(PixelFormat format)
  18. {
  19. bool value;
  20. Internal_HasAlpha(format, out value);
  21. return value;
  22. }
  23. public static bool IsFloatingPoint(PixelFormat format)
  24. {
  25. bool value;
  26. Internal_IsFloatingPoint(format, out value);
  27. return value;
  28. }
  29. public static bool IsCompressed(PixelFormat format)
  30. {
  31. bool value;
  32. Internal_IsCompressed(format, out value);
  33. return value;
  34. }
  35. public static bool IsDepth(PixelFormat format)
  36. {
  37. bool value;
  38. Internal_IsDepth(format, out value);
  39. return value;
  40. }
  41. public static int GetMaxMipmaps(int width, int height, int depth, PixelFormat format)
  42. {
  43. int value;
  44. Internal_GetMaxMipmaps(width, height, depth, format, out value);
  45. return value;
  46. }
  47. public static PixelData ConvertFormat(PixelData source, PixelFormat newFormat)
  48. {
  49. return Internal_ConvertFormat(source, newFormat);
  50. }
  51. public static PixelData Compress(PixelData source, CompressionOptions options)
  52. {
  53. return Internal_Compress(source, options);
  54. }
  55. public static PixelData[] GenerateMipmaps(PixelData source, MipMapGenOptions options)
  56. {
  57. return Internal_GenerateMipmaps(source, options);
  58. }
  59. public static PixelData Scale(PixelData source, PixelVolume newSize, ScaleFilter filter = ScaleFilter.Linear)
  60. {
  61. return Internal_Scale(source, newSize, filter);
  62. }
  63. public static void ApplyGamma(PixelData source, float gamma)
  64. {
  65. Internal_ApplyGamma(source, gamma);
  66. }
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern void Internal_GetMemorySize(int width, int height, int depth, PixelFormat format, out int value);
  69. [MethodImpl(MethodImplOptions.InternalCall)]
  70. private static extern void Internal_HasAlpha(PixelFormat format, out bool value);
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern void Internal_IsFloatingPoint(PixelFormat format, out bool value);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern void Internal_IsCompressed(PixelFormat format, out bool value);
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern void Internal_IsDepth(PixelFormat format, out bool value);
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern void Internal_GetMaxMipmaps(int width, int height, int depth, PixelFormat format, out int value);
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern PixelData Internal_ConvertFormat(PixelData source, PixelFormat newFormat);
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. private static extern PixelData Internal_Compress(PixelData source, CompressionOptions options);
  83. [MethodImpl(MethodImplOptions.InternalCall)]
  84. private static extern PixelData[] Internal_GenerateMipmaps(PixelData source, MipMapGenOptions options);
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern PixelData Internal_Scale(PixelData source, PixelVolume newSize, ScaleFilter filter);
  87. [MethodImpl(MethodImplOptions.InternalCall)]
  88. private static extern void Internal_ApplyGamma(PixelData source, float gamma);
  89. }
  90. // Note: IDs must match C++ enum PixelUtil::Filter
  91. public enum ScaleFilter
  92. {
  93. Nearest,
  94. Linear
  95. };
  96. // Note: IDs must match C++ enum CompressionQuality
  97. public enum CompressionQuality
  98. {
  99. Fastest,
  100. Normal,
  101. Production,
  102. Highest
  103. };
  104. // Note: IDs must match C++ enum AlphaMode
  105. public enum AlphaMode
  106. {
  107. None,
  108. Transparency,
  109. Premultiplied
  110. };
  111. // Note: IDs must match C++ enum MipMapWrapMode
  112. public enum MipMapWrapMode
  113. {
  114. Mirror,
  115. Repeat,
  116. Clamp
  117. };
  118. // Note: IDs must match C++ enum MipMapFilter
  119. public enum MipMapFilter
  120. {
  121. Box,
  122. Triangle,
  123. Kaiser
  124. };
  125. // Note: Layout must match C++ struct CompressionOptions
  126. [StructLayout(LayoutKind.Sequential)]
  127. public struct CompressionOptions
  128. {
  129. public PixelFormat format;
  130. public AlphaMode alphaMode;
  131. public bool isNormalMap;
  132. public bool isSRGB;
  133. public CompressionQuality quality;
  134. };
  135. // Note: Layout must match C++ struct MipMapGenOptions
  136. [StructLayout(LayoutKind.Sequential)]
  137. public struct MipMapGenOptions
  138. {
  139. public MipMapFilter filter;
  140. public MipMapWrapMode wrapMode;
  141. public bool isNormalMap;
  142. public bool normalizeMipmaps;
  143. };
  144. }