Esempio n. 1
0
		internal static System.Drawing.Image SetFromTxtr(SimPe.Interfaces.Files.IPackageFile pkg)
		{
			SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.TXTR);
			if (pfds.Length>0) 
			{
				SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
				foreach (SimPe.Interfaces.Files.IPackedFileDescriptor p in pfds)				
					if (p.Size>pfd.Size) pfd = p;
				
				SimPe.Plugin.Rcol rcol = new SimPe.Plugin.GenericRcol();
				rcol.ProcessData(pfd, pkg);
				if (rcol.Blocks.Length>0) 
				{
					SimPe.Plugin.ImageData id = rcol.Blocks[0] as SimPe.Plugin.ImageData;
					if (id!=null)
					{
						SimPe.Plugin.MipMap m = id.GetLargestTexture(new System.Drawing.Size(PackageInfo.IMAGESIZE, PackageInfo.IMAGESIZE));
						if (m!=null) return m.Texture;
					}
				}
			}	
		
			return null;
		}
Esempio n. 2
0
        public bool Parse(List <string> argv)
        {
            int i = ArgParser.Parse(argv, "-txtr");

            if (i < 0)
            {
                return(false);
            }

            //get Parameters
            string filename    = "";
            string output      = "";
            string texturename = "";
            string num         = "";
            int    levels      = 9;

            System.Drawing.Size sz = new System.Drawing.Size(512, 512);
            SimPe.Plugin.ImageLoader.TxtrFormats format = SimPe.Plugin.ImageLoader.TxtrFormats.DXT1Format;

            while (argv.Count > i)
            {
                if (ArgParser.Parse(argv, i, "-image", ref filename))
                {
                    continue;
                }
                if (ArgParser.Parse(argv, i, "-out", ref output))
                {
                    continue;
                }
                if (ArgParser.Parse(argv, i, "-name", ref texturename))
                {
                    continue;
                }
                if (ArgParser.Parse(argv, i, "-levels", ref num))
                {
                    levels = Convert.ToInt32(num); continue;
                }
                if (ArgParser.Parse(argv, i, "-width", ref num))
                {
                    sz.Width = Convert.ToInt32(num); continue;
                }
                if (ArgParser.Parse(argv, i, "-height", ref num))
                {
                    sz.Height = Convert.ToInt32(num); continue;
                }
                if (ArgParser.Parse(argv, i, "-format", ref num))
                {
                    switch (num)
                    {
                    case "dxt1": format = SimPe.Plugin.ImageLoader.TxtrFormats.DXT1Format; break;

                    case "dxt3": format = SimPe.Plugin.ImageLoader.TxtrFormats.DXT3Format; break;

                    case "dxt5": format = SimPe.Plugin.ImageLoader.TxtrFormats.DXT5Format; break;

                    case "raw24": format = SimPe.Plugin.ImageLoader.TxtrFormats.Raw24Bit; break;

                    case "raw32": format = SimPe.Plugin.ImageLoader.TxtrFormats.Raw32Bit; break;

                    case "raw8": format = SimPe.Plugin.ImageLoader.TxtrFormats.Raw8Bit; break;
                    }
                    continue;
                }
                SimPe.Message.Show(Help()[0]);
                return(true);
            }

            //check if the File exists
            if (!System.IO.File.Exists(filename))
            {
                SimPe.Message.Show(filename + " was not found.");
                return(true);
            }
            if (output.Trim() == "")
            {
                SimPe.Message.Show("Please specify an output file using -out");
                return(true);
            }

            //build TXTR File
            ImageData id = new SimPe.Plugin.ImageData(null);

            if ((System.IO.File.Exists(PathProvider.Global.NvidiaDDSTool)) && ((format == ImageLoader.TxtrFormats.DXT1Format) || (format == ImageLoader.TxtrFormats.DXT3Format) || (format == ImageLoader.TxtrFormats.DXT5Format)))
            {
                LoadDDS(id, DDSTool.BuildDDS(filename, levels, format, "-sharpenMethod Smoothen"));
            }
            else
            {
                LoadTXTR(id, filename, sz, levels, format);
            }

            Rcol rcol = new GenericRcol(null, false);

            rcol.FileName       = texturename;
            rcol.FileDescriptor = new SimPe.Packages.PackedFileDescriptor();
            rcol.Blocks         = new IRcolBlock[1];
            rcol.Blocks[0]      = id;

            rcol.SynchronizeUserData();
            System.IO.FileStream   fs = System.IO.File.Create(output);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
            bw.Write(rcol.FileDescriptor.UserData);
            bw.Close();
            bw = null;
            fs.Close();
            fs.Dispose();
            fs = null;

            return(true);
        }