PixelData.generated.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace BansheeEngine
  5. {
  6. /// <summary>
  7. /// A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession of
  8. /// "depth" slices, each containing "height" rows of "width" pixels.
  9. /// </summary>
  10. [ShowInInspector]
  11. public partial class PixelData : ScriptObject
  12. {
  13. private PixelData(bool __dummy0) { }
  14. protected PixelData() { }
  15. public PixelData(PixelVolume volume, PixelFormat format = PixelFormat.BGRA8)
  16. {
  17. Internal_create(this, ref volume, format);
  18. }
  19. public PixelData(uint width, uint height, uint depth = 1, PixelFormat pixelFormat = PixelFormat.BGRA8)
  20. {
  21. Internal_create0(this, width, height, depth, pixelFormat);
  22. }
  23. /// <summary>
  24. /// Returns the number of pixels that offsets one row from another. This can be "width", but doesn't have to be as some
  25. /// buffers require padding.
  26. /// </summary>
  27. [ShowInInspector]
  28. [NativeWrapper]
  29. public uint RawRowPitch
  30. {
  31. get { return Internal_getRowPitch(mCachedPtr); }
  32. }
  33. /// <summary>
  34. /// Returns the number of pixels that offsets one depth slice from another. This can be "width * height", but doesn't
  35. /// have to be as some buffers require padding.
  36. /// </summary>
  37. [ShowInInspector]
  38. [NativeWrapper]
  39. public uint RawSlicePitch
  40. {
  41. get { return Internal_getSlicePitch(mCachedPtr); }
  42. }
  43. /// <summary>Returns the pixel format used by the internal buffer for storing the pixels.</summary>
  44. [ShowInInspector]
  45. [NativeWrapper]
  46. public PixelFormat Format
  47. {
  48. get { return Internal_getFormat(mCachedPtr); }
  49. }
  50. /// <summary>Returns extents of the pixel volume this object is capable of holding.</summary>
  51. [ShowInInspector]
  52. [NativeWrapper]
  53. public PixelVolume Extents
  54. {
  55. get
  56. {
  57. PixelVolume temp;
  58. Internal_getExtents(mCachedPtr, out temp);
  59. return temp;
  60. }
  61. }
  62. /// <summary>
  63. /// Return whether this buffer is laid out consecutive in memory (meaning the pitches are equal to the dimensions).
  64. /// </summary>
  65. [ShowInInspector]
  66. [NativeWrapper]
  67. public bool RawIsConsecutive
  68. {
  69. get { return Internal_isConsecutive(mCachedPtr); }
  70. }
  71. /// <summary>Return the size (in bytes) of the buffer this image requires.</summary>
  72. [ShowInInspector]
  73. [NativeWrapper]
  74. public uint RawSize
  75. {
  76. get { return Internal_getSize(mCachedPtr); }
  77. }
  78. /// <summary>Returns a pixel at the specified location in the buffer.</summary>
  79. /// <param name="x">X coordinate of the pixel.</param>
  80. /// <param name="y">Y coordinate of the pixel.</param>
  81. /// <param name="z">Z coordinate of the pixel.</param>
  82. /// <returns>Value of the pixel, or undefined value if coordinates are out of range.</returns>
  83. public Color GetPixel(int x, int y, int z = 0)
  84. {
  85. Color temp;
  86. Internal_getPixel(mCachedPtr, x, y, z, out temp);
  87. return temp;
  88. }
  89. /// <summary>Sets a pixel at the specified location in the buffer.</summary>
  90. /// <param name="value">Color of the pixel to set.</param>
  91. /// <param name="x">X coordinate of the pixel.</param>
  92. /// <param name="y">Y coordinate of the pixel.</param>
  93. /// <param name="z">Z coordinate of the pixel.</param>
  94. public void SetPixel(Color value, int x, int y, int z = 0)
  95. {
  96. Internal_setPixel(mCachedPtr, ref value, x, y, z);
  97. }
  98. /// <summary>Returns values of all pixels.</summary>
  99. /// <returns>
  100. /// All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, each containing
  101. /// "height" rows of "width" pixels.
  102. /// </returns>
  103. public Color[] GetPixels()
  104. {
  105. return Internal_getPixels(mCachedPtr);
  106. }
  107. /// <summary>
  108. /// Sets all pixels in the buffer.Caller must ensure that number of pixels match the extends of the buffer.
  109. /// </summary>
  110. /// <param name="value">
  111. /// All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, each containing
  112. /// "height" rows of "width" pixels.
  113. /// </param>
  114. public void SetPixels(Color[] value)
  115. {
  116. Internal_setPixels(mCachedPtr, value);
  117. }
  118. /// <summary>Returns all pixels in the buffer as raw bytes.</summary>
  119. /// <returns>
  120. /// Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential row and slice pitch
  121. /// values.
  122. /// </returns>
  123. public char[] GetRawPixels()
  124. {
  125. return Internal_getRawPixels(mCachedPtr);
  126. }
  127. /// <summary>Sets all pixels in the buffer as raw bytes.</summary>
  128. /// <param name="value">
  129. /// Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential row and slice pitch
  130. /// values.
  131. /// </param>
  132. public void SetRawPixels(char[] value)
  133. {
  134. Internal_setRawPixels(mCachedPtr, value);
  135. }
  136. [MethodImpl(MethodImplOptions.InternalCall)]
  137. private static extern uint Internal_getRowPitch(IntPtr thisPtr);
  138. [MethodImpl(MethodImplOptions.InternalCall)]
  139. private static extern uint Internal_getSlicePitch(IntPtr thisPtr);
  140. [MethodImpl(MethodImplOptions.InternalCall)]
  141. private static extern PixelFormat Internal_getFormat(IntPtr thisPtr);
  142. [MethodImpl(MethodImplOptions.InternalCall)]
  143. private static extern void Internal_getExtents(IntPtr thisPtr, out PixelVolume __output);
  144. [MethodImpl(MethodImplOptions.InternalCall)]
  145. private static extern bool Internal_isConsecutive(IntPtr thisPtr);
  146. [MethodImpl(MethodImplOptions.InternalCall)]
  147. private static extern uint Internal_getSize(IntPtr thisPtr);
  148. [MethodImpl(MethodImplOptions.InternalCall)]
  149. private static extern void Internal_create(PixelData managedInstance, ref PixelVolume volume, PixelFormat format);
  150. [MethodImpl(MethodImplOptions.InternalCall)]
  151. private static extern void Internal_create0(PixelData managedInstance, uint width, uint height, uint depth, PixelFormat pixelFormat);
  152. [MethodImpl(MethodImplOptions.InternalCall)]
  153. private static extern void Internal_getPixel(IntPtr thisPtr, int x, int y, int z, out Color __output);
  154. [MethodImpl(MethodImplOptions.InternalCall)]
  155. private static extern void Internal_setPixel(IntPtr thisPtr, ref Color value, int x, int y, int z);
  156. [MethodImpl(MethodImplOptions.InternalCall)]
  157. private static extern Color[] Internal_getPixels(IntPtr thisPtr);
  158. [MethodImpl(MethodImplOptions.InternalCall)]
  159. private static extern void Internal_setPixels(IntPtr thisPtr, Color[] value);
  160. [MethodImpl(MethodImplOptions.InternalCall)]
  161. private static extern char[] Internal_getRawPixels(IntPtr thisPtr);
  162. [MethodImpl(MethodImplOptions.InternalCall)]
  163. private static extern void Internal_setRawPixels(IntPtr thisPtr, char[] value);
  164. }
  165. }