Beispiel #1
0
        /// <summary>
        /// Determines whether file contains certain cube face.
        /// </summary>
        /// <param name="face">Cube face.</param>
        /// <returns>True if contains, false otherwise.</returns>
        public bool HasCubeFace( DDSCubeFace face )
        {
            switch ( face )
            {
                case DDSCubeFace.PositiveX: return _PositiveX != null;
                case DDSCubeFace.NegativeX: return _NegativeX != null;
                case DDSCubeFace.PositiveY: return _PositiveY != null;
                case DDSCubeFace.NegativeY: return _NegativeY != null;
                case DDSCubeFace.PositiveZ: return _PositiveZ != null;
                case DDSCubeFace.NegativeZ: return _NegativeZ != null;
            }

            return false;
        }
Beispiel #2
0
        /// <summary>
        /// Gets cube texture.
        /// </summary>
        /// <param name="face">Cube face to get.</param>
        /// <param name="mipMapLevel">Mip level at which to get cube face (0 if 
        /// file does not contain mip maps).</param>
        /// <returns>Bitmap.</returns>
        public Bitmap GetCubeTextureAsBitmap( DDSCubeFace face, int mipMapLevel = 0 )
        {
            byte[] pixels = GetCubeTexture( face, mipMapLevel );

            if ( pixels != null )
            {
                int divisor = (int) Math.Pow( 2, mipMapLevel );
                int width = Math.Max( 1, _Width / divisor );
                int height = Math.Max( 1, _Height / divisor );

                Bitmap bitmap = new Bitmap( width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb );
                BitmapData data = bitmap.LockBits( new Rectangle( 0, 0, width, height ), ImageLockMode.WriteOnly, bitmap.PixelFormat );
                Marshal.Copy( pixels, 0, data.Scan0, pixels.Length );

                bitmap.UnlockBits( data );
                return bitmap;
            }

            return null;
        }
Beispiel #3
0
        /// <summary>
        /// Gets cube texture.
        /// </summary>
        /// <param name="face">Cube face to get.</param>
        /// <param name="mipMapLevel">Mip level at which to get cube face (0 if 
        /// file does not contain mip maps).</param>
        /// <returns>WPF bitmap source.</returns>
        public BitmapSource GetCubeTextureAsBitmapSource( DDSCubeFace face, int mipMapLevel = 0 )
        {
            byte[] pixels = GetCubeTexture( face, mipMapLevel );

            if ( pixels != null )
            {
                int divisor = (int) Math.Pow( 2, mipMapLevel );
                int width = Math.Max( 1, _Width / divisor );
                int height = Math.Max( 1, _Height / divisor );

                return BitmapSource.Create( width, height, 96, 96, PixelFormats.Bgra32, null, pixels, width * 4 );
            }

            return null;
        }
Beispiel #4
0
        /// <summary>
        /// Gets cube texture.
        /// </summary>
        /// <param name="face">Cube face to get.</param>
        /// <param name="mipMapLevel">Mip level at which to get cube face (0 if 
        /// file does not contain mip maps).</param>
        /// <returns>Pixel data in ARGB format.</returns>
        public byte[] GetCubeTexture( DDSCubeFace face, int mipMapLevel = 0 )
        {
            MipMaps mipMaps = null;

            switch ( face )
            {
                case DDSCubeFace.PositiveX: mipMaps = _PositiveX; break;
                case DDSCubeFace.NegativeX: mipMaps = _NegativeX; break;
                case DDSCubeFace.PositiveY: mipMaps = _PositiveY; break;
                case DDSCubeFace.NegativeY: mipMaps = _NegativeY; break;
                case DDSCubeFace.PositiveZ: mipMaps = _PositiveZ; break;
                case DDSCubeFace.NegativeZ: mipMaps = _NegativeZ; break;
            }

            if ( mipMaps != null && mipMapLevel >= 0 && mipMapLevel < mipMaps.Count )
                return mipMaps[ mipMapLevel ];

            return null;
        }