/// <summary>
/// Return a subvolume of this PixelBox.
/// </summary>
/// <param name="def"> Defines the bounds of the subregion to return </param>
/// <returns> A pixel box describing the region and the data in it </returns>
/// <remarks>
/// This function does not copy any data, it just returns a PixelBox object with a data pointer pointing somewhere inside the data of object. Throws an Exception if def is not fully contained.
/// </remarks>
public PixelBox GetSubVolume(BasicBox def)
{
if (Compressed(this.format))
{
if (def.Left == left && def.Top == top && def.Front == front && def.Right == right && def.Bottom == bottom &&
def.Back == back)
{
// Entire buffer is being queried
return(this);
}
throw new Exception("Cannot return subvolume of compressed PixelBuffer, in PixelBox.GetSubVolume");
}
if (!Contains(def))
{
throw new Exception("Bounds out of range, in PixelBox.GetSubVolume");
}
var elemSize = PixelUtil.GetNumElemBytes(this.format);
// Calculate new data origin
var rval = new PixelBox(def, this.format, this.data);
rval.offset = (((def.Left - left) * elemSize) + ((def.Top - top) * this.rowPitch * elemSize) +
((def.Front - front) * this.slicePitch * elemSize));
rval.rowPitch = this.rowPitch;
rval.slicePitch = this.slicePitch;
rval.format = this.format;
return(rval);
}