public void MVPImageSplitIntoThreeTest()
        {
            string file = "storm_ui_mvp_icons_rewards_loyaldefender.dds";

            string blueAward = Path.ChangeExtension(file.Replace("loyaldefender", "loyaldefender_blue", StringComparison.OrdinalIgnoreCase), ".png");
            string redAward  = Path.ChangeExtension(file.Replace("loyaldefender", "loyaldefender_red", StringComparison.OrdinalIgnoreCase), ".png");
            string goldAward = Path.ChangeExtension(file.Replace("loyaldefender", "loyaldefender_gold", StringComparison.OrdinalIgnoreCase), ".png");

            using DDSImage image = new DDSImage(file);

            Assert.AreEqual(148, image.Height);
            Assert.AreEqual(444, image.Width);

            int newWidth = 444 / 3;

            image.Save(blueAward, new Point(0, 0), new Size(newWidth, image.Height));
            image.Save(redAward, new Point(newWidth, 0), new Size(newWidth, image.Height));
            image.Save(goldAward, new Point(newWidth * 2, 0), new Size(newWidth, image.Height));

            Assert.IsTrue(File.Exists(blueAward));
            Assert.IsTrue(File.Exists(redAward));
            Assert.IsTrue(File.Exists(goldAward));

            var newImage = Image.Load(blueAward);

            Assert.AreEqual(148, newImage.Height);
            Assert.AreEqual(148, newImage.Width);
        }
        /// <summary>
        /// Extracts a static image file. Returns true if successful.
        /// </summary>
        /// <param name="filePath">The file path the file will be saved to.</param>
        /// <returns></returns>
        protected bool ExtractStaticImageFile(string filePath)
        {
            string?fileName = Path.GetFileName(filePath);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new InvalidOperationException($"Invalid {nameof(filePath)} of {filePath}");
            }

            return(ExtractImageFile(filePath, () =>
            {
                string textureFilepath = Path.Combine(TexturesPath, fileName);
                if (FileExists(textureFilepath))
                {
                    using Stream stream = OpenFile(textureFilepath);
                    using DDSImage image = new DDSImage(stream);

                    PathHelper.FileNameToLower(filePath.AsMemory());

                    image.Save(Path.ChangeExtension(filePath, "png"));

                    return true;
                }
                else
                {
                    FailedFileMessages.Add($"File not found: {fileName}");
                    return false;
                }
            }));
        }
Beispiel #3
0
        /// <summary>
        /// Extracts a static image file. Returns true if successful.
        /// </summary>
        /// <param name="filePath">The file path the file will be saved to.</param>
        protected bool ExtractStaticImageFile(string filePath)
        {
            string fileName = Path.GetFileName(filePath);

            return(ExtractImageFile(filePath, () =>
            {
                string textureFilepath = Path.Combine(TexturesPath, fileName);
                if (FileExists(textureFilepath))
                {
                    using (Stream stream = OpenFile(textureFilepath))
                    {
                        DDSImage image = new DDSImage(stream);
                        PathHelper.FileNameToLower(filePath.AsMemory());

                        image.Save(Path.ChangeExtension(filePath, "png"));

                        return true;
                    }
                }
                else
                {
                    FailedFileMessages.Add($"File not found: {fileName}");
                    return false;
                }
            }));
        }
        public void DDSToPNGImageTest()
        {
            string file = "storm_ui_icon_nova_orbitalstrike.dds";

            using DDSImage image = new DDSImage(file);
            image.Save(Path.ChangeExtension(file, ".png"));

            Assert.IsTrue(File.Exists(Path.ChangeExtension(file, ".png")));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var files = Directory.GetFiles(".", "*.dds");

            foreach (var file in files)
            {
                var pngFile = Path.ChangeExtension(file, "png");
                System.Console.WriteLine($"Saving {file} -> {pngFile}");
                try {
                    var dds = new DDSImage(file);
                    dds.Save(pngFile);
                }
                catch (Exception e) {
                    System.Console.WriteLine($"   failed {e.Message}");
                }
            }

            return;

            if (args.Length != 2)
            {
                System.Console.WriteLine("ERROR: input and output file required\n");
                Environment.Exit(1);
            }

            var input  = args[0];
            var output = args[1];

            if (!File.Exists(input))
            {
                System.Console.WriteLine("ERROR: input file does not exist\n");
                Environment.Exit(1);
            }

            try
            {
                var dds = new DDSImage(input);
                dds.Save(output);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: failed to convert DDS file\n");
                System.Console.WriteLine(e);
                Environment.Exit(1);
            }

            if (File.Exists(output))
            {
                System.Console.WriteLine("Successfully created " + output);
            }
            else
            {
                System.Console.WriteLine("ERROR: something went wrong!\n");
                Environment.Exit(1);
            }
        }
        /// <summary>
        /// Extracts a static image file.
        /// </summary>
        /// <param name="filePath">The file path the file will be saved to.</param>
        /// <param name="image">The image in <see cref="DDSImage"/> format.</param>
        /// <returns></returns>
        protected bool ExtractStaticImageFile(string filePath, DDSImage image)
        {
            return(ExtractImageFile(filePath, () =>
            {
                PathHelper.FileNameToLower(filePath.AsMemory());

                image.Save(Path.ChangeExtension(filePath, "png"));

                return true;
            }));
        }
Beispiel #7
0
        public void loadMaps()
        {
            cBox.Items.Clear();

            // Path to the folder the radar files are stored in
            string radarDir = Properties.Settings.Default.csgoPath + @"\csgo\resource\overviews";

            DirectoryInfo radarDirInfo = new DirectoryInfo(radarDir);

            // Create the caching directory
            if (!Directory.Exists(startupPath + "\\cache"))
            {
                Directory.CreateDirectory(startupPath + "\\cache");
            }

            // Iterate over all dds files in the overviews directory
            foreach (var file in radarDirInfo.GetFiles("*.dds"))
            {
                // If file is not the spectate radar file
                if (!file.Name.Contains("_spectate.dds"))
                {
                    // Build the cache file path
                    string cacheFilename = startupPath + "\\cache\\" + file.Name.Replace("_radar.dds", ".png");

                    // If the cache file doesn't exist
                    if (!File.Exists(cacheFilename))
                    {
                        // TODO: Fix the buffersize exception instead of ignoring it
                        try
                        {
                            // Read and convert the dds image
                            // TODO: Add support for custom radars
                            Bitmap converted = new DDSImage(File.ReadAllBytes(file.FullName)).images[0];

                            // Save the cache file
                            converted.Save(cacheFilename);

                            // Add the image to the map list
                            cBox.Items.Add(new Map(file.Name.Replace("_radar.dds", ""), converted));
                        }
                        catch
                        {
                        }
                    }
                    else // If the cache file already exists
                    {
                        // Read the cached file and add it to the list
                        cBox.Items.Add(new Map(Path.GetFileName(cacheFilename.Replace(".png", "")), new Bitmap(Bitmap.FromFile(cacheFilename))));
                    }
                }
            }
        }
Beispiel #8
0
        protected void ExtractImageFiles(JsonDocument rewardData, string originalTextureSheetFilePath, string imageFileName)
        {
            if (!File.Exists(originalTextureSheetFilePath))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"The file at {originalTextureSheetFilePath} does not exist");
                Console.ResetColor();

                return;
            }

            using DDSImage image = new DDSImage(originalTextureSheetFilePath);

            int count = 0;

            Console.WriteLine();
            Console.WriteLine("Extracting files...");
            Console.WriteLine();

            foreach (JsonProperty item in rewardData.RootElement.EnumerateObject())
            {
                if (item.Value.TryGetProperty("iconSlot", out JsonElement iconSlotElement) &&
                    item.Value.TryGetProperty("textureSheet", out JsonElement textureSheetElement) && textureSheetElement.TryGetProperty("image", out JsonElement imageElement) && imageElement.GetString() == imageFileName &&
                    textureSheetElement.TryGetProperty("columns", out JsonElement columnElement) &&
                    textureSheetElement.TryGetProperty("rows", out JsonElement rowElement))
                {
                    int iconSlot = iconSlotElement.GetInt32();
                    int columns  = columnElement.GetInt32();
                    int rows     = rowElement.GetInt32();

                    string fileName = $"storm_portrait_{item.Name.ToLowerInvariant()}.png";

#pragma warning disable IDE0047 // Remove unnecessary parentheses
                    image.Save(Path.Combine(OutputDirectory, fileName), new Point((iconSlot % columns) * _portraitWidth, (iconSlot / rows) * _portraitWidth), new Size(_portraitWidth, _portraitHeight));
#pragma warning restore IDE0047 // Remove unnecessary parentheses

                    count++;

                    Console.WriteLine(fileName);
                }
            }

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine($"{count} portrait images extracted at {OutputDirectory}");
            Console.ResetColor();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                System.Console.WriteLine("ERROR: input and output file required\n");
                Environment.Exit(1);
            }

            var input  = args[0];
            var output = args[1];

            if (!File.Exists(input))
            {
                System.Console.WriteLine("ERROR: input file does not exist\n");
                Environment.Exit(1);
            }

            try
            {
                var dds = new DDSImage(input);
                dds.Save(output);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: failed to convert DDS file\n");
                System.Console.WriteLine(e);
                Environment.Exit(1);
            }

            if (File.Exists(output))
            {
                System.Console.WriteLine("Successfully created " + output);
            }
            else
            {
                System.Console.WriteLine("ERROR: something went wrong!\n");
                Environment.Exit(1);
            }
        }
Beispiel #10
0
        public void SetImage(Image NewImage, string Format)
        {
            this._Image          = NewImage;
            this._IsImageChecked = true;
            this._Thumbnail      = null;

            Format           = Format.ToLower();
            this.ImageFormat = Format;

            if (NewImage == null)
            {
                this.SetContents(null);
            }
            else
            {
                MemoryStream _newStream = new MemoryStream();                 // MemoryStream should remain open for the lifetime of the Bitmap

                switch (Format)
                {
                case "16-bit":
                case "rgb16":
                case "argb16":
                case "dxt1":
                    if (GetAlphaBits() == 0)
                    {
                        DDSImage.Save((Bitmap)this.GetImage(), _newStream, DDSImage.CompressionMode.R5G6B5);
                        this.ImageFormat    = ".dds";
                        this.ImageSubformat = "RGB16";
                    }
                    else
                    {
                        DDSImage.Save((Bitmap)this.GetImage(), _newStream, DDSImage.CompressionMode.A1R5G5B5);
                        this.ImageFormat    = ".dds";
                        this.ImageSubformat = "ARGB16";
                    }
                    break;

                case "24-bit":
                case "rgb24":
                    DDSImage.Save((Bitmap)this.GetImage(), _newStream, DDSImage.CompressionMode.RGB24);
                    this.ImageFormat    = ".dds";
                    this.ImageSubformat = "RGB24";
                    break;

                case "32-bit":
                case "rgb32":
                case "dxt2":
                case "dxt3":
                case "dxt4":
                case "dxt5":
                    DDSImage.Save((Bitmap)this.GetImage(), _newStream, DDSImage.CompressionMode.RGB32);
                    this.ImageFormat    = ".dds";
                    this.ImageSubformat = "RGB32";
                    break;

                case ".bmp":
                    this.GetImage().Save(_newStream, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;

                case ".png":
                    this.GetImage().Save(_newStream, System.Drawing.Imaging.ImageFormat.Png);
                    break;

                case ".gif":
                    this.GetImage().Save(_newStream, System.Drawing.Imaging.ImageFormat.Gif);
                    break;

                case ".tif":
                case ".tiff":
                    this.GetImage().Save(_newStream, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;

                case ".jpg":
                case ".jpeg":
                    this.GetImage().Save(_newStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                default:
                    throw new Exception("Unsupported conversion format");
                }

                this.SetContents(_newStream.ToArray());
            }
        }
Beispiel #11
0
        static public void Convert(string[] inArgs, long unitNumerator, long unitDenominator, bool idUseRenderAutoTip = false)
        {
            // configuration
            Configuration config          = Configuration.LoadIIDXConfig(Common.configFileName);
            Configuration db              = Common.LoadDB();
            int           quantizeMeasure = config["BMS"].GetValue("QuantizeMeasure");
            int           quantizeNotes   = config["BMS"].GetValue("QuantizeNotes");

            // splash
            Splash.Show("Chuni to Sus Script");
            Console.WriteLine("Timing: " + unitNumerator.ToString() + "/" + unitDenominator.ToString());
            Console.WriteLine("Measure Quantize: " + quantizeMeasure.ToString());

            // args
            string[] args;
            if (inArgs.Length > 0)
            {
                args = Subfolder.Parse(inArgs);
            }
            else
            {
                args = inArgs;
            }

            // debug args (if applicable)
            if (System.Diagnostics.Debugger.IsAttached && args.Length == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Debugger attached. Input file name:");
                args = new string[] { Console.ReadLine() };
            }

            // show usage if no args provided
            if (args.Length == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Usage: ChuniToSus <input file>");
                Console.WriteLine();
                Console.WriteLine("Drag and drop with files and folders is fully supported for this application.");
                Console.WriteLine();
                Console.WriteLine("Supported formats:");
                Console.WriteLine("C2S");
            }

            string output = config["BMS"]["Output"];

            // process files
            for (int i = 0; i < args.Length; i++)
            {
                if (File.Exists(args[i]))
                {
                    Console.WriteLine();
                    Console.WriteLine("Processing File: " + args[i]);
                    string filename = args[i];

                    byte[] data = File.ReadAllBytes(args[i]);
                    switch (Path.GetExtension(args[i]).ToUpper())
                    {
                    case @".C2S":
                        // Find ID
                        string fileName = Path.GetFileName(filename);
                        // Read Music file
                        string   C2sDir        = Path.GetDirectoryName(filename) + "\\";
                        XElement musicXml      = XElement.Load(Path.Combine(C2sDir, "Music.xml"));
                        string   id            = musicXml.Element("name").Element("id").Value;
                        string   title         = musicXml.Element("name").Element("str").Value;
                        string   artist        = musicXml.Element("artistName").Element("str").Value;
                        string   genre         = musicXml.Element("genreNames").Element("list").Element("StringID").Element("str").Value;
                        var      boxedLunchRow = musicXml.Element("fumens").Elements("MusicFumenData");

                        Dictionary <string, MusicData> musicData = new Dictionary <string, MusicData>();
                        foreach (XElement boxedLunchElement in boxedLunchRow)
                        {
                            if (boxedLunchElement.Element("file").Element("path").Value != "")
                            {
                                if (boxedLunchElement.Element("type").Element("id").Value == "4")
                                {
                                    musicData.Add(
                                        boxedLunchElement.Element("file").Element("path").Value,
                                        new MusicData()
                                    {
                                        type     = boxedLunchElement.Element("type").Element("id").Value + ":" + musicXml.Element("worldsEndTagName").Element("str").Value,
                                        typeName = boxedLunchElement.Element("type").Element("data").Value,
                                        level    = musicXml.Element("starDifType").Value
                                    }
                                        );
                                }
                                else
                                {
                                    musicData.Add(
                                        boxedLunchElement.Element("file").Element("path").Value,
                                        new MusicData()
                                    {
                                        type     = boxedLunchElement.Element("type").Element("id").Value,
                                        typeName = boxedLunchElement.Element("type").Element("data").Value,
                                        level    = boxedLunchElement.Element("level").Value
                                    }
                                        );
                                }
                            }
                        }

                        System.IO.StreamReader file = new System.IO.StreamReader(args[i]);
                        ChuniC2S   archive          = ChuniC2S.Read(file, unitNumerator, unitDenominator);
                        ChartChuni chart            = archive.chart;
                        chart.Tags["ID"]        = id;
                        chart.Tags["TITLE"]     = title;
                        chart.Tags["ARTIST"]    = artist;
                        chart.Tags["GENRE"]     = genre;
                        chart.Tags["PLAYLEVEL"] = musicData[fileName].level;
                        chart.Tags["TYPE"]      = musicData[fileName].type;
                        chart.Tags["TYPENAME"]  = musicData[fileName].typeName;

                        ConvertChart(chart, config, filename, 1, null, "1");
                        break;

                    case @".DDS":
                        // Find ID
                        fileName = Path.GetFileName(filename);
                        // Read Music file
                        C2sDir   = Path.GetDirectoryName(filename) + "\\";
                        musicXml = XElement.Load(Path.Combine(C2sDir, "Music.xml"));
                        title    = musicXml.Element("name").Element("str").Value;
                        genre    = musicXml.Element("genreNames").Element("list").Element("StringID").Element("str").Value;

                        DDSImage img = new DDSImage(filename);

                        string dirPath = Path.Combine(config["BMS"]["Output"], Common.nameReplace(genre), Common.nameReplace(title), "jacket.jpg");
                        img.Save(dirPath);

                        break;
                    }
                }
            }

            // wrap up
            Console.WriteLine("BemaniToBMS finished.");
        }