Axiom.Media.Image.CalculateSize C# (CSharp) Method

CalculateSize() public static method

public static CalculateSize ( int mipmaps, int faces, int width, int height, int depth, PixelFormat format ) : int
mipmaps int
faces int
width int
height int
depth int
format PixelFormat
return int
		public static int CalculateSize( int mipmaps, int faces, int width, int height, int depth, PixelFormat format )
		{
			int size = 0;
			for ( int mip = 0; mip <= mipmaps; ++mip )
			{
				size += PixelUtil.GetMemorySize( width, height, depth, format ) * faces;
				if ( width != 1 )
					width /= 2;
				if ( height != 1 )
					height /= 2;
				if ( depth != 1 )
					depth /= 2;
			}
			return size;

		}

Usage Example

Beispiel #1
0
        public override Codec.DecodeResult Decode(Stream input)
        {
            using (var br = new BinaryReader(input))
            {
                var numFaces = 1;                 // Assume one face until we know otherwise
                var imgData  = new ImageData();

                // Read the PVRTC header
                var header = PVRTCTexHeader.Read(br);

                // Get the file type identifier
                var pvrTag = header.pvrTag;

                if (this.PVR_MAGIC != pvrTag)
                {
                    throw new AxiomException("This is not a PVR file!");
                }

                // Get format flags
                var flags = header.flags;
                using (var wrap = BufferBase.Wrap(flags, 2))
                {
                    _flipEndian(wrap, sizeof(int));
                }
                var formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK;

                var bitmaskAlpha = header.bitmaskAlpha;
                using (var wrap = BufferBase.Wrap(bitmaskAlpha, 2))
                {
                    _flipEndian(wrap, sizeof(int));
                }

                if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2)
                {
                    if (formatFlags == kPVRTextureFlagTypePVRTC_4)
                    {
                        imgData.format = bitmaskAlpha != 0 ? PixelFormat.PVRTC_RGBA4 : PixelFormat.PVRTC_RGB4;
                    }
                    else if (formatFlags == kPVRTextureFlagTypePVRTC_2)
                    {
                        imgData.format = bitmaskAlpha != 0 ? PixelFormat.PVRTC_RGBA2 : PixelFormat.PVRTC_RGB2;
                    }

                    imgData.depth      = 1;
                    imgData.width      = header.width;
                    imgData.height     = header.height;
                    imgData.numMipMaps = header.numMipmaps;

                    // PVRTC is a compressed format
                    imgData.flags |= ImageFlags.Compressed;
                }

                // Calculate total size from number of mipmaps, faces and size
                imgData.size = Image.CalculateSize(imgData.numMipMaps, numFaces, imgData.width, imgData.height, imgData.depth,
                                                   imgData.format);

                // Now deal with the data
                var dest = br.ReadBytes(imgData.size);
                return(new DecodeResult(new MemoryStream(dest), imgData));
            }
        }
All Usage Examples Of Axiom.Media.Image::CalculateSize