Example #1
0
        ///  <summary>
        ///  Saves the current image using one of the supported DDS mechanisms.
        ///  </summary>
        ///  <param name="output">A <see cref="T:System.IO.Stream"/> to receive the DDS-encoded image.</param>
        public void Save(Stream output)
        {
            Dds.DdsFormat ddsFormat;
            if (useBlockCompression)
                switch (alphaDepth)
                {
                    case 1: ddsFormat = Dds.DdsFormat.DXT1; break;
                    case 3: ddsFormat = Dds.DdsFormat.DXT3; break;
                    default: ddsFormat = Dds.DdsFormat.DXT5; break;
                }
            else if (useLuminence)
                ddsFormat = Dds.DdsFormat.A8L8;
            else
                switch (alphaDepth)
                {
                    case 0: ddsFormat = Dds.DdsFormat.R8G8B8; break;
                    case 1: ddsFormat = Dds.DdsFormat.A1R5G5B5; break;
                    case 4: ddsFormat = Dds.DdsFormat.A4R4G4B4; break;
                    default: ddsFormat = Dds.DdsFormat.A8R8G8B8; break;
                }

            Dds dds = new Dds(ddsFormat, width, height, baseImage);
            dds.Write(output);
            output.Flush();
        }
Example #2
0
        /// <summary>
        /// Loads the data from an image encoded using one of the supported DDS mechanisms.
        /// If <paramref name="supportHSV"/> is true, also creates an HSVa-encoded version of the image.
        /// </summary>
        /// <param name="input">A <see cref="System.IO.Stream"/> containing the DDS-encoded image.</param>
        /// <param name="supportHSV">When true, create an HSVa-encoded version of the image.</param>
        public void Load(System.IO.Stream input, bool supportHSV)
        {
            Dds dds = new Dds(input);

            width = dds.Width;
            height = dds.Height;
            useBlockCompression = false;
            useLuminence = false;
            alphaDepth = 0;

            Dds.DdsFormat fmt = dds.FileFormat;
            switch (fmt)
            {
                case Dds.DdsFormat.DXT1: useBlockCompression = true; alphaDepth = 1; break;
                case Dds.DdsFormat.DXT3: useBlockCompression = true; alphaDepth = 3; break;
                case Dds.DdsFormat.DXT5: useBlockCompression = true; alphaDepth = 5; break;
                case Dds.DdsFormat.A8L8: useLuminence = true; alphaDepth = 8; break;
                case Dds.DdsFormat.A1R5G5B5: alphaDepth = 1; break;
                case Dds.DdsFormat.A4R4G4B4: alphaDepth = 4; break;
                case Dds.DdsFormat.A8B8G8R8:
                case Dds.DdsFormat.A8R8G8B8: alphaDepth = 8; break;
            }

            baseImage = dds.ImageData;

            currentImage = (uint[])baseImage.Clone();
            if (supportHSV) UpdateHSVData();
        }