예제 #1
0
파일: DdsCompressor.cs 프로젝트: zparr/ATF
        /// <summary>
        /// Compresses the specified image</summary>
        /// <param name="image">The image</param>
        /// <param name="type">The type</param>
        /// <returns>Compressed image</returns>
        static public Image Compress(Image image, CompressionType type)
        {
            Image ddsImage = null;

            MemoryStream memStream = new MemoryStream();

            // Switch on the format
            DDSUtils.TextureFormat format = 0;
            switch (type)
            {
            case CompressionType.DXT1:
                format = DDSUtils.TextureFormat.kDXT1;
                break;

            case CompressionType.DXT3:
                format = DDSUtils.TextureFormat.kDXT3;
                break;

            case CompressionType.DXT5:
                format = DDSUtils.TextureFormat.kDXT5;
                break;
            }


            if (image.OpenGlPixelFormat == Gl.GL_BGRA)
            {
                DDSUtils.ImageConverter.CompressARGB(image.Width,
                                                     image.Height,
                                                     image.Pixels,
                                                     format,
                                                     memStream);
            }
            else
            {
                DDSUtils.ImageConverter.CompressRGB(image.Width,
                                                    image.Height,
                                                    image.Pixels,
                                                    format,
                                                    memStream);
            }

            // Rewind
            memStream.Seek(0, SeekOrigin.Begin);

            var loader = new DdsImageLoader();

            ddsImage = loader.LoadImage(memStream);

            return(ddsImage);
        }
예제 #2
0
파일: DdsCompressor.cs 프로젝트: Joxx0r/ATF
        /// <summary>
        /// Compresses the specified image</summary>
        /// <param name="image">The image</param>
        /// <param name="type">The type</param>
        /// <returns>Compressed image</returns>
        static public Image Compress(Image image, CompressionType type)
        {
            Image ddsImage = null;

            MemoryStream memStream = new MemoryStream();

            // Switch on the format
            DDSUtils.TextureFormat format = 0;
            switch (type)
            {
                case CompressionType.DXT1:
                    format = DDSUtils.TextureFormat.kDXT1;
                    break;

                case CompressionType.DXT3:
                    format = DDSUtils.TextureFormat.kDXT3;
                    break;

                case CompressionType.DXT5:
                    format = DDSUtils.TextureFormat.kDXT5;
                    break;
            }


            if (image.OpenGlPixelFormat == Gl.GL_BGRA)
            {
                DDSUtils.ImageConverter.CompressARGB(image.Width,
                    image.Height,
                    image.Pixels,
                    format,
                    memStream);
            }
            else
            {
                DDSUtils.ImageConverter.CompressRGB(image.Width,
                     image.Height,
                     image.Pixels,
                     format,
                     memStream);
            }

            // Rewind
            memStream.Seek(0, SeekOrigin.Begin);

            var loader = new DdsImageLoader();
            ddsImage = loader.LoadImage(memStream);

            return ddsImage;
        }