Exemplo n.º 1
0
        public static void RenameCounterDir(int sortMode, bool zeroPadding, int startAt)
        {
            int counter = startAt;

            FileInfo[] files       = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            var        filesSorted = files.OrderBy(n => n);

            if (sortMode == 1)
            {
                filesSorted.Reverse();
            }
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                string dir         = new DirectoryInfo(file.FullName).Parent.FullName;
                int    filesDigits = (int)Math.Floor(Math.Log10((double)files.Length) + 1);
                if (zeroPadding)
                {
                    File.Move(file.FullName, Path.Combine(dir, counter.ToString().PadLeft(filesDigits, '0') + Path.GetExtension(file.FullName)));
                }
                else
                {
                    File.Move(file.FullName, Path.Combine(dir, counter.ToString() + Path.GetExtension(file.FullName)));
                }
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 100 == 0)
                {
                    Program.Print("Renamed " + counter + " files...");
                }
            }
            Program.PostProcessing(true, false);
        }
Exemplo n.º 2
0
        public static async void ConvertDirToDds(int qMin, int qMax, bool delSrc)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Converting Image ", counter, files.Length);
                counter++;
                switch (Config.GetInt("ddsEnc"))
                {
                case 0: ConvertToDds(file.FullName, delSrc); break;

                case 1: DdsInterface.Crunch(file.FullName, qMin, qMax, delSrc); break;

                case 2: DdsInterface.NvCompress(file.FullName, Path.ChangeExtension(file.FullName, "dds"), delSrc); break;
                }
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 3
0
        public static async Task MergeAllDir(int rowLength)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();
            Logger.Log("-> Merging " + files.Length + " images...");
            Program.PreProcessing();

            if (rowLength <= 0)
            {
                rowLength = (int)Math.Sqrt(files.Length);
            }

            MagickImageCollection row  = new MagickImageCollection();
            MagickImageCollection rows = new MagickImageCollection();

            int currImg = 1;

            Logger.Log("Adding images to atlas...");
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("", counter, files.Length);
                MagickImage currentImg = new MagickImage(file);
                Logger.Log("Adding " + Path.GetFileName(currentImg.FileName) + "...", true);
                row.Add(currentImg);

                if (currImg >= rowLength)
                {
                    currImg = 0;                              // Reset counter
                    var mergedRow = row.AppendHorizontally(); // Append
                    rows.Add(mergedRow);
                    row = new MagickImageCollection();        // Reset row
                }

                currImg++;
                await Program.PutTaskDelay();

                counter++;

                if (counter > files.Length && currImg != 0 && row.Count > 0) // Merge the remaining images if we are done, even if they don't fill a row
                {
                    var mergedRow = row.AppendHorizontally();                // Append
                    rows.Add(mergedRow);
                }
            }
            Logger.Log("-> Creating output image... ");
            var result = rows.AppendVertically();

            result.BackgroundColor = new MagickColor("#" + (await Config.Get("backgroundColor")));
            result.Format          = MagickFormat.Png;
            string outpath = Program.currentDir + "-merged.png";

            result.Write(outpath);
            Logger.Log("-> Written merged image to " + outpath);
            Program.PostProcessing(files.Length);
        }
Exemplo n.º 4
0
        public static void BlurPreview()
        {
            Program.mainForm.SetBlurVars();
            FileInfo firstImg    = IOUtils.GetFiles()[0];
            string   tempImgPath = Path.Combine(IOUtils.GetAppDataDir(), "blurpreview" + firstImg.Extension);

            if (File.Exists(tempImgPath))
            {
                File.Delete(tempImgPath);
            }
            File.Copy(firstImg.FullName, tempImgPath);
            EffectsUtils.Blur(tempImgPath, blurRadiusMin, blurRadiusMax);
            Program.mainForm.PreviewImage(tempImgPath);
        }
Exemplo n.º 5
0
        public static void MedianPreview()
        {
            Program.mainForm.SetMedianVars();
            FileInfo firstImg    = IOUtils.GetFiles()[0];
            string   tempImgPath = Path.Combine(Paths.GetDataPath(), "medianpreview" + firstImg.Extension);

            if (File.Exists(tempImgPath))
            {
                File.Delete(tempImgPath);
            }
            File.Copy(firstImg.FullName, tempImgPath);
            EffectsUtils.Median(tempImgPath, medianRadiusMin, medianRadiusMax);
            Program.PreviewImage(tempImgPath);
        }
Exemplo n.º 6
0
        public static void AutoLevel(string path, string ext, bool recursive)
        {
            FileInfo[] files   = IOUtils.GetFiles();
            int        counter = 1;

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Adjusting image ", counter, files.Length);
                AutoLevel(file.FullName);
                counter++;
            }
            Program.PostProcessing(files.Length);
        }
Exemplo n.º 7
0
        public static async void ScaleDir(float sMin, float sMax, int filterMode, string filterName)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();
            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Scaling Image ", counter, files.Length);
                counter++;
                Scale(file.FullName, sMin, sMax, filterMode, filterName);
                /* if(counter % 3 == 0) */ await Program.PutTaskDelay();
            }
            Program.PostProcessing();
        }
Exemplo n.º 8
0
        public static void NoisePreview()
        {
            Program.mainForm.SetNoiseVars();
            FileInfo firstImg    = IOUtils.GetFiles()[0];
            string   tempImgPath = Path.Combine(Paths.GetDataPath(), "noisepreview" + firstImg.Extension);

            if (File.Exists(tempImgPath))
            {
                File.Delete(tempImgPath);
            }
            File.Copy(firstImg.FullName, tempImgPath);
            Random rand = new Random();

            EffectsUtils.AddNoise(tempImgPath, GetNoiseTypeList(), attenMin, attenMax, monochrome);
            Program.PreviewImage(tempImgPath);
        }
Exemplo n.º 9
0
        public static async void ConvertDirToHeif(int q, bool delSrc)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Converting Image ", counter, files.Length);
                counter++;
                HeifInterface.EncodeImage(file.FullName, q, delSrc);
                await Program.PutTaskDelay();
            }
            Program.PostProcessing();
        }
Exemplo n.º 10
0
        public static void RemoveMissingFiles(string checkDir, bool testRun)
        {
            int counter = 1;

            FileInfo[] files         = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            FileInfo[] filesCheckDir = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"), checkDir);
            Program.Print("(1/2) Checking " + files.Length + " files...");
            Program.Print("Folder B has " + filesCheckDir.Length + " files");
            foreach (FileInfo file in files)
            {
                if (!File.Exists(Path.Combine(checkDir, file.Name)))
                {
                    Program.ShowProgress("", counter, files.Length);
                    counter++;
                    Program.Print("-> " + file.Name + " doesn't exist in second dir, will delete");
                    if (!testRun)
                    {
                        File.Delete(file.FullName);
                    }
                    if (counter % 50 == 0)
                    {
                        Program.Print("Processed " + counter + " files...");
                    }
                }
            }
            Program.Print("(2/2) Checking " + filesCheckDir.Length + " files...");
            Program.Print("Folder A has " + filesCheckDir.Length + " files");
            foreach (FileInfo file in filesCheckDir)
            {
                if (!File.Exists(Path.Combine(Program.currentDir, file.Name)))
                {
                    Program.ShowProgress("", counter, files.Length);
                    counter++;
                    Program.Print("-> " + file.Name + " doesn't exist in second dir, will delete");
                    if (!testRun)
                    {
                        File.Delete(file.FullName);
                    }
                    if (counter % 50 == 0)
                    {
                        Program.Print("Processed " + counter + " files...");
                    }
                }
            }
            Program.PostProcessing(false, false);
        }
Exemplo n.º 11
0
        public static async void ResampleDirRand(float sMin, float sMax, int downFilterMode, string downFilterName, int upFilterMode, string upFilterName)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Resampling Image ", counter, files.Length);
                counter++;
                RandomResample(file.FullName, sMin, sMax, downFilterMode, downFilterName, upFilterMode, upFilterName);
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
        }
Exemplo n.º 12
0
        public static async Task ScaleDir(float sMin, float sMax, int filterMode, string filterName)
        {
            int counter = 0;

            FileInfo[] files = IOUtils.GetFiles();
            Program.PreProcessing();

            Task forEach = Task.Run(async() => Parallel.ForEach(files, await MtUtils.GetParallelOpts(), async file => {
                await Scale(file.FullName, sMin, sMax, filterMode, filterName);
                Program.ShowProgressIncrement("", ref counter, files.Length);
            }));

            while (!forEach.IsCompleted)
            {
                await Task.Delay(1);
            }
            Program.PostProcessing(files.Length, true);
        }
Exemplo n.º 13
0
        public async static void EraseDir(List <PatternType> patterns, int scale, MagickColor color)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Adding Erase Markers to Image ", counter, files.Length);
                Erase(file.FullName, patterns, scale, color);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(files.Length, true);
        }
Exemplo n.º 14
0
        public static async void CropDivisibleDir(int divisibleBy, Gravity grav, bool expand)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Cropping " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("Cropping Image ", counter, Files.Length);
                counter++;
                CropDivisible(file.FullName, divisibleBy, grav, expand);
                if (counter % 3 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 15
0
        public static async void CropRelativeDir(int minSize, int maxSize, SizeMode sizeMode, Gravity grav)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Resizing " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("Resizing Image ", counter, Files.Length);
                counter++;
                CropRelative(file.FullName, minSize, maxSize, sizeMode, grav);
                if (counter % 3 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 16
0
        public static async void BlurDir(int radiusMin, int radiusMax)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Blurring Image ", counter, files.Length);
                Blur(file.FullName, radiusMin, radiusMax);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true);
        }
Exemplo n.º 17
0
        public async static void HaloDir(int radiusMin, int radiusMax)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Running Halo Effect on Image ", counter, files.Length);
                Halo(file.FullName, radiusMin, radiusMax);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(files.Length, true);
        }
Exemplo n.º 18
0
        public async static void EdgeDetectDir()
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Running Edge Detection on Image ", counter, files.Length);
                EdgeDetect(file.FullName);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true);
        }
Exemplo n.º 19
0
        public async static void AddNoiseDir(List <NoiseType> noiseTypes, double attenMin, double attenMax, bool monoChrome)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Adding Noise to Image ", counter, files.Length);
                AddNoise(file.FullName, noiseTypes, attenMin, attenMax, monoChrome);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true);
        }
Exemplo n.º 20
0
        public static async void CropAbsoluteDir(int newWidth, int newHeight, Gravity grav)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Resizing " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("Resizing Image ", counter, Files.Length);
                counter++;
                CropAbsolute(file.FullName, newWidth, newHeight, grav);
                if (counter % 3 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 21
0
        public static async void AddSuffixPrefixDir(string text, bool suffix)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                AddSuffixPrefix(file.FullName, text, suffix);
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 100 == 0)
                {
                    Program.Print("Renamed " + counter + " files...");
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true, false);
        }
Exemplo n.º 22
0
        public async static void ConvertDirToPng(int q, bool delSrc)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles();

            Program.PreProcessing();
            foreach (FileInfo file in files)
            {
                Program.ShowProgress("Converting Image ", counter, files.Length);
                ConvertToPng(file.FullName, q, delSrc);
                counter++;
                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true);
        }
Exemplo n.º 23
0
        public static async void PrintImageInfoDir()
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                MagickImage img        = IOUtils.ReadImage(file.FullName);
                string      fnameNoExt = Path.GetFileNameWithoutExtension(file.Name);
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 10 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true, false);
        }
Exemplo n.º 24
0
        public static async void CropPaddingDir(int pixMin, int pixMax, bool cut)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Resizing " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("Resizing Image ", counter, Files.Length);
                counter++;
                CropPadding(file.FullName, pixMin, pixMax, cut);
                if (counter % 3 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 25
0
        public static async void TileDir(int w, int h, bool useTileAmount, bool delSrc)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Tiling " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("Tiling Image ", counter, Files.Length);
                counter++;
                await Tile(file.FullName, w, h, useTileAmount, delSrc);

                if (counter % 2 == 0)
                {
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 26
0
        public static async void RemoveBytesDir(int bytes)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                string fnameNoExt = Path.GetFileNameWithoutExtension(file.Name);
                RemoveBytes(file.FullName, bytes);
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 100 == 0)
                {
                    Program.Print("Processed " + counter + " files...");
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true, false);
        }
Exemplo n.º 27
0
        public static async void ReplaceInFilenamesDir(string textToFind, string textToReplace)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                ReplaceInFilename(file.FullName, textToFind, textToReplace);
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 100 == 0)
                {
                    Program.Print("Processed " + counter + " files...");
                    await Program.PutTaskDelay();
                }
            }
            Program.Print("Done - Processed " + counter + " files.");
            Program.PostProcessing(true, false);
        }
Exemplo n.º 28
0
        public static async void DelSmallImgsDir(int minSize, ImageSizeFilterUtils.SizeMode scaleMode, ImageSizeFilterUtils.Operator op)
        {
            int counter = 1;

            FileInfo[] Files = IOUtils.GetFiles();
            Program.Print("Checking " + Files.Length + " images...");
            Program.PreProcessing();
            foreach (FileInfo file in Files)
            {
                Program.ShowProgress("", counter, Files.Length);
                counter++;
                ImageSizeFilterUtils.DeleteSmallImages(file.FullName, scaleMode, op, minSize);
                if (counter % 10 == 0)
                {
                    await Program.PutTaskDelay();
                }
                if (counter % 100 == 0)
                {
                    Program.Print("Processed " + counter + " files...");
                }
            }
            Program.PostProcessing();
        }
Exemplo n.º 29
0
        public static async void AddZeroPaddingDir(int targetLength)
        {
            int counter = 1;

            FileInfo[] files = IOUtils.GetFiles(Config.GetBool("fileOperationsNoFilter"));
            Program.PreProcessing(true, false);
            foreach (FileInfo file in files)
            {
                string fnameNoExt = Path.GetFileNameWithoutExtension(file.Name);
                string ext        = Path.GetExtension(file.Name);
                //string dir = new DirectoryInfo(file.FullName).Parent.FullName;
                //int filesDigits = (int)Math.Floor(Math.Log10((double)files.Length) + 1);
                //File.Move(file.FullName, Path.Combine(fnameNoExt.PadLeft(targetLength, '0') + Path.GetExtension(file.FullName)));
                File.Move(file.FullName, Path.Combine(Path.GetDirectoryName(file.FullName), fnameNoExt.PadLeft(targetLength, '0') + ext));
                Program.ShowProgress("", counter, files.Length);
                counter++;
                if (counter % 100 == 0)
                {
                    Program.Print("Renamed " + counter + " files...");
                    await Program.PutTaskDelay();
                }
            }
            Program.PostProcessing(true, false);
        }