using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace BansheeEngine
{
///
/// A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession of
/// "depth" slices, each containing "height" rows of "width" pixels.
///
[ShowInInspector]
public partial class PixelData : ScriptObject
{
private PixelData(bool __dummy0) { }
protected PixelData() { }
public PixelData(PixelVolume volume, PixelFormat format = PixelFormat.BGRA8)
{
Internal_create(this, ref volume, format);
}
public PixelData(uint width, uint height, uint depth = 1, PixelFormat pixelFormat = PixelFormat.BGRA8)
{
Internal_create0(this, width, height, depth, pixelFormat);
}
///
/// Returns the number of pixels that offsets one row from another. This can be "width", but doesn't have to be as some
/// buffers require padding.
///
[ShowInInspector]
[NativeWrapper]
public uint RawRowPitch
{
get { return Internal_getRowPitch(mCachedPtr); }
}
///
/// Returns the number of pixels that offsets one depth slice from another. This can be "width * height", but doesn't
/// have to be as some buffers require padding.
///
[ShowInInspector]
[NativeWrapper]
public uint RawSlicePitch
{
get { return Internal_getSlicePitch(mCachedPtr); }
}
/// Returns the pixel format used by the internal buffer for storing the pixels.
[ShowInInspector]
[NativeWrapper]
public PixelFormat Format
{
get { return Internal_getFormat(mCachedPtr); }
}
/// Returns extents of the pixel volume this object is capable of holding.
[ShowInInspector]
[NativeWrapper]
public PixelVolume Extents
{
get
{
PixelVolume temp;
Internal_getExtents(mCachedPtr, out temp);
return temp;
}
}
///
/// Return whether this buffer is laid out consecutive in memory (meaning the pitches are equal to the dimensions).
///
[ShowInInspector]
[NativeWrapper]
public bool RawIsConsecutive
{
get { return Internal_isConsecutive(mCachedPtr); }
}
/// Return the size (in bytes) of the buffer this image requires.
[ShowInInspector]
[NativeWrapper]
public uint RawSize
{
get { return Internal_getSize(mCachedPtr); }
}
/// Returns a pixel at the specified location in the buffer.
/// X coordinate of the pixel.
/// Y coordinate of the pixel.
/// Z coordinate of the pixel.
/// Value of the pixel, or undefined value if coordinates are out of range.
public Color GetPixel(int x, int y, int z = 0)
{
Color temp;
Internal_getPixel(mCachedPtr, x, y, z, out temp);
return temp;
}
/// Sets a pixel at the specified location in the buffer.
/// Color of the pixel to set.
/// X coordinate of the pixel.
/// Y coordinate of the pixel.
/// Z coordinate of the pixel.
public void SetPixel(Color value, int x, int y, int z = 0)
{
Internal_setPixel(mCachedPtr, ref value, x, y, z);
}
/// Returns values of all pixels.
///
/// All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, each containing
/// "height" rows of "width" pixels.
///
public Color[] GetPixels()
{
return Internal_getPixels(mCachedPtr);
}
///
/// Sets all pixels in the buffer.Caller must ensure that number of pixels match the extends of the buffer.
///
///
/// All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, each containing
/// "height" rows of "width" pixels.
///
public void SetPixels(Color[] value)
{
Internal_setPixels(mCachedPtr, value);
}
/// Returns all pixels in the buffer as raw bytes.
///
/// Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential row and slice pitch
/// values.
///
public char[] GetRawPixels()
{
return Internal_getRawPixels(mCachedPtr);
}
/// Sets all pixels in the buffer as raw bytes.
///
/// Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential row and slice pitch
/// values.
///
public void SetRawPixels(char[] value)
{
Internal_setRawPixels(mCachedPtr, value);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern uint Internal_getRowPitch(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern uint Internal_getSlicePitch(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern PixelFormat Internal_getFormat(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_getExtents(IntPtr thisPtr, out PixelVolume __output);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_isConsecutive(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern uint Internal_getSize(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_create(PixelData managedInstance, ref PixelVolume volume, PixelFormat format);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_create0(PixelData managedInstance, uint width, uint height, uint depth, PixelFormat pixelFormat);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_getPixel(IntPtr thisPtr, int x, int y, int z, out Color __output);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_setPixel(IntPtr thisPtr, ref Color value, int x, int y, int z);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Color[] Internal_getPixels(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_setPixels(IntPtr thisPtr, Color[] value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern char[] Internal_getRawPixels(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_setRawPixels(IntPtr thisPtr, char[] value);
}
}