Exemple #1
0
        public DDSData[] Execute(int level, Size size, ImageLoader.TxtrFormats format)
        {
            pb.Image = null;
            img      = null;
            dds      = null;

            this.cbsharpen.SelectedIndex = 6;
            this.tblevel.Text            = level.ToString();
            this.tbwidth.Text            = size.Width.ToString();
            this.tbheight.Text           = size.Height.ToString();

            cbformat.SelectedIndex = 2;
            for (int i = 0; i < cbformat.Items.Count; i++)
            {
                ImageLoader.TxtrFormats fr = (ImageLoader.TxtrFormats)cbformat.Items[i];
                if (fr == format)
                {
                    cbformat.SelectedIndex = i;
                    break;
                }
            }

            this.button1.Enabled = false;
            ShowDialog();

            return(dds);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new Instance
 /// </summary>
 /// <param name="data">The Image Data</param>
 /// <param name="sz">The ParentSize (biggest MipMap Size)</param>
 /// <param name="format">the Format it uses</param>
 /// <param name="level">Index of theis Map in the Block (0 beeing the smallest Map)</param>
 /// <param name="count">Number of Items in the Block</param>
 public DDSData(byte[] data, Size sz, ImageLoader.TxtrFormats format, int level, int count)
 {
     this.format = format;
     this.size   = sz;
     this.data   = data;
     img         = null;
     this.level  = level;
     this.count  = count;
 }
Exemple #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ImageData(Rcol parent) : base(parent)
 {
     texturesize     = new Size(1, 1);
     mipmapblocks    = new MipMapBlock[1];
     mipmapblocks[0] = new MipMapBlock(this);
     mipmaplevels    = 1;
     sgres           = new SGResource(null);
     BlockID         = 0x1c4a276c;
     filenamerep     = "";
     this.version    = 0x09;
     unknown_0       = (float)1.0;
     format          = SimPe.Plugin.ImageLoader.TxtrFormats.ExtRaw24Bit;
 }
Exemple #4
0
        public static DDSData[] BuildDDS(Image img, int levels, ImageLoader.TxtrFormats format, string parameters)
        {
            string imgname = System.IO.Path.GetTempFileName() + ".png";

            img.Save(imgname, System.Drawing.Imaging.ImageFormat.Png);

            try
            {
                return(BuildDDS(imgname, levels, format, parameters));
            }
            finally
            {
                if (System.IO.File.Exists(imgname))
                {
                    System.IO.File.Delete(imgname);
                }
            }
        }
Exemple #5
0
        private void SelectItem(object sender, System.EventArgs e)
        {
            if (cbitem.Tag != null)
            {
                return;
            }
            if (cbitem.SelectedIndex < 0)
            {
                return;
            }
            try
            {
                cbitem.Tag = true;
                LevelInfo selecteditem = (LevelInfo)cbitem.Items[cbitem.SelectedIndex];

                this.tbflname.Text = selecteditem.NameResource.FileName;
                this.tbwidth.Text  = selecteditem.TextureSize.Width.ToString();
                this.tbheight.Text = selecteditem.TextureSize.Height.ToString();
                this.tbz.Text      = selecteditem.ZLevel.ToString();

                this.cbformats.SelectedIndex = 0;
                for (int i = 0; i < cbformats.Items.Count; i++)
                {
                    ImageLoader.TxtrFormats f = (ImageLoader.TxtrFormats)cbformats.Items[i];
                    if (f == selecteditem.Format)
                    {
                        cbformats.SelectedIndex = i;
                        break;
                    }
                }

                pb.Image = selecteditem.Texture;
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(Localization.Manager.GetString("erropenfile"), ex);
            }
            finally
            {
                cbitem.Tag = null;
            }
        }
Exemple #6
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        public override void Unserialize(System.IO.BinaryReader reader)
        {
            version = reader.ReadUInt32();

            /*byte len = reader.ReadByte();
             * string s = Helper.ToString(reader.ReadBytes(len));*/
            string s = reader.ReadString();

            sgres.BlockID = reader.ReadUInt32();
            sgres.Unserialize(reader);

            if (Parent.Fast)
            {
                texturesize  = new Size(0, 0);
                mipmapblocks = new MipMapBlock[0];
                return;
            }

            int w = reader.ReadInt32();
            int h = reader.ReadInt32();

            texturesize = new Size(w, h);

            format       = (ImageLoader.TxtrFormats)reader.ReadUInt32();
            mipmaplevels = reader.ReadUInt32();
            unknown_0    = reader.ReadSingle();
            mipmapblocks = new MipMapBlock[reader.ReadUInt32()];
            unknown_1    = reader.ReadUInt32();

            if (version == 0x09)
            {
                filenamerep = reader.ReadString();
            }

            for (int i = 0; i < mipmapblocks.Length; i++)
            {
                mipmapblocks[i] = new MipMapBlock(this);
                mipmapblocks[i].Unserialize(reader);
            }
        }
Exemple #7
0
        public static DDSData[] BuildDDS(string imgname, int levels, ImageLoader.TxtrFormats format, string parameters)
        {
            string ddsfile = System.IO.Path.GetTempFileName() + ".dds";


            //img.Save(imgname);

            string arg = "-file \"" + imgname + "\" ";

            arg += "-output \"" + ddsfile + "\" ";

            if (format == ImageLoader.TxtrFormats.DXT1Format)
            {
                arg += " -dxt1c";
            }
            else if (format == ImageLoader.TxtrFormats.DXT5Format)
            {
                arg += "-dxt5";
            }
            else
            {
                arg += "-dxt3";
            }

            arg += " -nmips " + levels.ToString();
            arg += " " + parameters;

            string flname = PathProvider.Global.NvidiaDDSTool;

            if (!System.IO.File.Exists(flname))
            {
                return(new DDSData[0]);
            }

            try
            {
                Process p = new Process();
                p.StartInfo.FileName  = flname;
                p.StartInfo.Arguments = arg;

                p.Start();

                p.WaitForExit();
                p.Close();

                DDSData[] ret = ImageLoader.ParesDDS(ddsfile);
                if (System.IO.File.Exists(ddsfile))
                {
                    System.IO.File.Delete(ddsfile);
                }
                return(ret);
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                if (System.IO.File.Exists(ddsfile))
                {
                    System.IO.File.Delete(ddsfile);
                }
            }



            return(new DDSData[0]);
        }
Exemple #8
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        public override void Unserialize(System.IO.BinaryReader reader)
        {
            version = reader.ReadUInt32();
            string s = reader.ReadString();

            sgres.BlockID = reader.ReadUInt32();
            sgres.Unserialize(reader);



            int w = reader.ReadInt32();
            int h = reader.ReadInt32();

            texturesize = new Size(w, h);
            zlevel      = reader.ReadInt32();

            int size = reader.ReadInt32();

            if (Parent.Fast)
            {
                reader.BaseStream.Seek(size, System.IO.SeekOrigin.Current);
                texturesize = new Size(0, 0);
                img         = null;
                return;
            }

            /*if (size == w*h) format = ImageLoader.TxtrFormats.DXT3Format;
             * else*/format = ImageLoader.TxtrFormats.DXT1Format;
            //Pumckl Contribution
            //-- 8< --------------------------------------------- 8< -----
            if (size == 4 * w * h)
            {
                format = ImageLoader.TxtrFormats.Raw32Bit;
            }
            else if (size == 3 * w * h)
            {
                format = ImageLoader.TxtrFormats.Raw24Bit;
            }
            else if (size == w * h)              // could be RAW8, DXT3 or DXT5
            {
                // it seems to be difficult to determine the right format
                if (sgres.FileName.IndexOf("bump") > 0)
                {                 // its a bump-map
                    format = ImageLoader.TxtrFormats.Raw8Bit;
                }
                else
                {
                    // i expect the upper left 4x4 corner of the pichture have
                    // all the same alpha so i can determine if it's DXT5
                    // i guess, it's somewhat dirty but what can i do else?
                    long  pos   = reader.BaseStream.Position;
                    ulong alpha = reader.ReadUInt64();                     // read the first 8 byte of the image
                    reader.BaseStream.Position = pos;
                    // on DXT5 if all alpha are the same the bytes 0 or 1 are not zero
                    // and the bytes 2-7 (codebits) ara all zero
                    if (((alpha & 0xffffffffffff0000) == 0) && ((alpha & 0xffff) != 0))
                    {
                        format = ImageLoader.TxtrFormats.DXT5Format;
                    }
                    else
                    {
                        format = ImageLoader.TxtrFormats.DXT3Format;
                    }
                }
            }
            else
            {
                format = ImageLoader.TxtrFormats.DXT1Format;              // size < w*h
            }
            //-- 8< --------------------------------------------- 8< -----


            long p1 = reader.BaseStream.Position;

            size = (int)(reader.BaseStream.Length - p1);

            /*if (!Helper.DebugMode)
             * {
             *      datatype = MipMapType.Texture;
             *      img = ImageLoader.Load(texturesize, size, format, reader, -1, 1);
             *      reader.BaseStream.Seek(p1, System.IO.SeekOrigin.Begin);
             * }
             * else */
            {
                datatype = MipMapType.SimPE_PlainData;
            }

            data = reader.ReadBytes(size);
        }