public PixelBox GetPixelBox( int face, int mipmap )
{
if ( mipmap > numMipMaps )
throw new IndexOutOfRangeException();
if ( face > this.NumFaces )
throw new IndexOutOfRangeException();
// Calculate mipmap offset and size
int width = this.Width;
int height = this.Height;
int depth = this.Depth;
int faceSize = 0; // Size of one face of the image
int offset = 0;
for ( int mip = 0; mip < mipmap; ++mip )
{
faceSize = PixelUtil.GetMemorySize( width, height, depth, this.Format );
// Skip all faces of this mipmap
offset += faceSize * this.NumFaces;
// Half size in each dimension
if ( width != 1 )
width /= 2;
if ( height != 1 )
height /= 2;
if ( depth != 1 )
depth /= 2;
}
// We have advanced to the desired mipmap, offset to right face
faceSize = PixelUtil.GetMemorySize( width, height, depth, this.Format );
offset += faceSize * face;
// Return subface as pixelbox
if ( bufPtr != IntPtr.Zero )
{
return new PixelBox( width, height, depth, this.Format, bufPtr );
}
else
{
throw new AxiomException( "Image wasn't loaded, can't get a PixelBox." );
}
}