Axiom.Media.PixelUtil.GetMemorySize C# (CSharp) Метод

GetMemorySize() публичный статический Метод

Returns the size in memory of a region with the given extents and pixel format with consecutive memory layout.
In case that the format is non-compressed, this simply returns width * height * depth * PixelConverter.GetNumElemBytes(format). In the compressed case, this does serious magic.
public static GetMemorySize ( int width, int height, int depth, PixelFormat format ) : int
width int Width of the area
height int Height of the area
depth int Depth of the area
format PixelFormat Format of the area
Результат int
		public static int GetMemorySize( int width, int height, int depth, PixelFormat format )
		{
			if ( IsCompressed( format ) )
			{
				switch ( format )
				{
					case PixelFormat.DXT1:
						return ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 ) * 8 * depth;
					case PixelFormat.DXT2:
					case PixelFormat.DXT3:
					case PixelFormat.DXT4:
					case PixelFormat.DXT5:
						return ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 ) * 16 * depth;
					default:
						throw new Exception( "Invalid compressed pixel format" );
				}
			}
			else
			{
				return width * height * depth * GetNumElemBytes( format );
			}
		}

Usage Example

Пример #1
0
        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
            IntPtr newBufPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);

            return(new PixelBox(width, height, depth, this.Format, newBufPtr));
        }
All Usage Examples Of Axiom.Media.PixelUtil::GetMemorySize