Example #1
0
 /// <summary>
 /// Creates a mask with given <paramref name="maskChannels"/> active and of given <paramref name="width"/> and <paramref name="height"/>.
 /// </summary>
 /// <param name="maskChannels">Which channels in the mask should be activated.</param>
 /// <param name="width">Width of image.</param>
 /// <param name="height">Height of image.</param>
 public void CreateMask(MaskChannel maskChannels, int width, int height)
 {
     ClearMask();
     ddsMask = new DdsFile();
     ddsMask.CreateImage(
         MaskChannelToByte(maskChannels, MaskChannel.C1),
         MaskChannelToByte(maskChannels, MaskChannel.C2),
         MaskChannelToByte(maskChannels, MaskChannel.C3),
         MaskChannelToByte(maskChannels, MaskChannel.C4),
         width, height, false);
 }
Example #2
0
        /// <summary>
        /// Get a copy of the current DDS image as a <see cref="DdsFile"/>.
        /// </summary>
        /// <returns>A new <see cref="DdsFile"/> copy of the current DDS image.</returns>
        public DdsFile GetDdsFile()
        {
            if (!this.loaded || ddsFile == null) return null;

            DdsFile res = new DdsFile();
            res.CreateImage(ddsFile, false);
            return res;
        }
Example #3
0
 /// <summary>
 /// Creates an image from a given <see cref="T:Bitmap"/>, resized as requested.
 /// If <paramref name="supportHSV"/> is true, also creates an HSVa-encoded version of the image.
 /// </summary>
 /// <param name="image"><see cref="T:Bitmap"/> from which to extract image pixels.</param>
 /// <param name="width">Width of image.</param>
 /// <param name="height">Height of image.</param>
 /// <param name="supportHSV">When true, create an HSVa-encoded version of the image.</param>
 public void CreateImage(Bitmap image, int width, int height, bool supportHSV)
 {
     using (DdsFile ddsFileBase = new DdsFile())
     {
         ddsFileBase.CreateImage(image, false);
         CreateImage(ddsFileBase.Resize(new Size(width, height)), supportHSV);
     }
 }
Example #4
0
 /// <summary>
 /// Get a new DdsFile of the given size based on the current image.
 /// </summary>
 /// <param name="size">The new size.</param>
 /// <returns>A new DdsFile of the given size based on the current image.</returns>
 public DdsFile Resize(Size size)
 {
     DdsFile ddsFile = new DdsFile();
     ddsFile.CreateImage(this, size.Width, size.Height, SupportsHSV);
     return ddsFile;
 }
Example #5
0
        /// <summary>
        /// Creates an image from a given <see cref="T:DdsFile"/>, resized as requested.
        /// If <paramref name="supportHSV"/> is true, also creates an HSVa-encoded version of the image.
        /// </summary>
        /// <param name="image"><see cref="T:DdsFile"/> to clone.</param>
        /// <param name="width">Width of image.</param>
        /// <param name="height">Height of image.</param>
        /// <param name="supportHSV">When true, create an HSVa-encoded version of the image.</param>
        public void CreateImage(DdsFile image, int width, int height, bool supportHSV)
        {
            this.width = width;
            this.height = height;
            this.useBlockCompression = image.useBlockCompression;
            this.useLuminence = image.useLuminence;
            this.alphaDepth = image.alphaDepth;

            if (this.useLuminence)
            {
                // Life would be still relatively simple were it not for Luminence maps.
                // With these, you can't just strip the alpha channel -- they exist only for that channel,
                // so we need to deal with them separately.
                this.currentImage = new uint[width * height];
                this.SetPixels((x, y, unused) => 0);
                this.baseImage = (uint[])this.currentImage.Clone();

                Bitmap alpha = new Bitmap(image.GetGreyscaleFromAlpha(), width, height);
                this.SetAlphaFromGreyscale(alpha);
            }
            else if (alphaDepth == 0)
            {
                this.baseImage = new Bitmap(image.Image, width, height).ToARGBData();
                this.currentImage = (uint[])this.baseImage.Clone();
            }
            else
            {
                // Regardless of the pixel format, using Bitmap to resize the image pre-multiplies the alpha
                // so we need this mess.

                // Clone the image, strip the alpha, then resize
                using (DdsFile ddsFileBase = new DdsFile())
                {
                    ddsFileBase.CreateImage(image, false);
                    ddsFileBase.DeleteAlphaChannel();
                    this.baseImage = new Bitmap(ddsFileBase.Image, width, height).ToARGBData();
                }

                this.currentImage = (uint[])this.baseImage.Clone();

                // Now reapply the original alpha
                Bitmap alpha = new Bitmap(image.GetGreyscaleFromAlpha(), width, height);
                this.SetAlphaFromGreyscale(alpha);
            }

            if (supportHSV) this.UpdateHSVData();
        }