public void Test_Montage()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                MontageSettings settings = new MontageSettings();
                settings.Geometry     = new MagickGeometry(string.Format("{0}x{1}", 200, 200));
                settings.TileGeometry = new MagickGeometry(string.Format("{0}x", 2));

                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Montage(settings);
                });

                for (int i = 0; i < 9; i++)
                {
                    collection.Add(Files.Builtin.Logo);
                }

                using (IMagickImage montageResult = collection.Montage(settings))
                {
                    Assert.IsNotNull(montageResult);
                    Assert.AreEqual(400, montageResult.Width);
                    Assert.AreEqual(1000, montageResult.Height);
                }
            }
        }
Example #2
0
        public ActionResult <FrontendFile> ResizeAllFilters([FromBody] FilterPreviewModel model)
        {
            MagickGeometry geometry = model.Geometry;

            _logger.LogTrace("HTTP request received at preview/resize with geometery of {0}.", geometry);

            MontageSettings montageSettings = new MontageSettings()
            {
                BackgroundColor = MagickColors.None,
                Geometry        = new MagickGeometry(2, 2, 0, 0),
                TileGeometry    = new MagickGeometry(6, 6)
            };

            using (MagickImage magickImage = new MagickImage(model.Image.Data))
            {
                using (MagickImageCollection collection = new MagickImageCollection())
                {
                    Parallel.ForEach((IEnumerable <FilterType>) typeof(FilterType).GetEnumValues(), (filter) =>
                    {
                        MagickImage magickImageClone = (MagickImage)magickImage.Clone();
                        magickImageClone.FilterType  = filter;
                        magickImageClone.Resize(geometry);
                        collection.Add(magickImageClone);
                    });

                    using (IMagickImage montage = collection.Montage(montageSettings))
                    {
                        montage.Format = magickImage.Format;
                        return(new FrontendFile(model.Image.ContentType, montage.ToByteArray()));
                    }
                }
            }
        }
Example #3
0
    internal static Wrapper.MontageSettings GetInstance(MontageSettings value)
    {
      if (value == null)
        return null;

      return value._Instance;
    }
Example #4
0
        private void CreateThumbnail()
        {
            using (var images = new MagickImageCollection())
            {
                var montageSettings = new MontageSettings()
                {
                    BackgroundColor = MagickColors.Transparent,
                    Shadow          = false,
                    TileGeometry    = new MagickGeometry(3, 0),
                    Geometry        = new MagickGeometry(0, 0, 640, 0)
                };

                foreach (var file in Output.GetFiles("*_cutted.mp4"))
                {
                    var fileName      = Path.GetFileName(file);
                    var thumbnailFile = file.Replace("_cutted.mp4", "_thumbnail.png");
                    Output.DeleteFile(thumbnailFile);
                    Run($"-i \"{fileName}\" -ss 00:00:05 -t 00:00:00.01 \"{thumbnailFile}\"");

                    var thumbnail = new MagickImage(thumbnailFile);
                    images.Add(thumbnail);
                }
                using (IMagickImage result = images.Montage(montageSettings))
                {
                    result.Write(Output.CombinePath("thumbnail.png"));
                }
            }
        }
Example #5
0
        internal static Wrapper.MontageSettings GetInstance(MontageSettings value)
        {
            if (value == null)
            {
                return(null);
            }

            return(value._Instance);
        }
Example #6
0
        public MagickImage GenerateMontage()
        {
            var qrCodes = GenerateQrCodes();
            var first   = qrCodes.First();

            var montageSettings = new MontageSettings()
            {
                BackgroundColor = MagickColors.None,             // -background none
                Geometry        = new MagickGeometry(1, 1, 0, 0) // -geometry +5+5
            };

            var mont = qrCodes.Montage(montageSettings);

            return((MagickImage)mont);
        }
Example #7
0
        private string OutputMontage(string filename, string outputPath, MagickImageCollection images, int j)
        {
            // Keep the original image's width/height in the Montage
            var settings = new MontageSettings();

            settings.Geometry = new MagickGeometry(images[0].Width, images[0].Height);
            string outputfile = string.Format("{0}{1}_{2}.jpg", outputPath, filename, j);

            // Create a montage from the images
            using (var result = images.Montage(settings))
            {
                // Save the result
                result.Write(outputfile);
            }
            images.Clear();
            return(outputfile);
        }
        // TODO This library shouldn't be required.
        private void CreateTexture(MontageSettings montageSettings, string path, IEnumerable <byte[]> textures)
        {
            lock (textureExportLock)
            {
                using (MagickImageCollection stichedTexture = new MagickImageCollection())
                {
                    foreach (byte[] texture in textures)
                    {
                        stichedTexture.Add(new MagickImage(texture));
                    }

                    using (MagickImage result = stichedTexture.Montage(montageSettings))
                    {
                        result.Write(path);
                    }
                }
            }
        }
        public void Test_Montage()
        {
            using (MagickImageCollection images = new MagickImageCollection())
            {
                for (int i = 0; i < 9; i++)
                {
                    images.Add(Files.Builtin.Logo);
                }

                MontageSettings ms = new MontageSettings();
                ms.Geometry     = new MagickGeometry(string.Format("{0}x{1}", 200, 200));
                ms.TileGeometry = new MagickGeometry(string.Format("{0}x", 2));

                using (MagickImage montageResult = images.Montage(ms))
                {
                    Assert.IsNotNull(montageResult);
                    Assert.AreEqual(400, montageResult.Width);
                    Assert.AreEqual(1000, montageResult.Height);
                }
            }
        }
        public void ExportTextures(CnkLOD chunk)
        {
            string name = Path.GetFileNameWithoutExtension(chunk.Name);

            if (name == null)
            {
                return;
            }

            string directory = ResourceDir + "/Terrain/" + name.Split('_')[0];

            if (!Directory.Exists(directory + @"/Textures"))
            {
                Directory.CreateDirectory(directory + @"/Textures");
            }

            MontageSettings montageSettings = new MontageSettings();

            montageSettings.TileGeometry    = new MagickGeometry(2, 2);
            montageSettings.Geometry        = new MagickGeometry(512, 512);
            montageSettings.BackgroundColor = MagickColor.FromRgba(0, 0, 0, 0);
            montageSettings.BorderColor     = MagickColor.FromRgba(0, 0, 0, 0);
            montageSettings.BorderWidth     = 0;

            // Color Map
            string colorMapPath = directory + @"/Textures/" + name + "_colornx" + ".dds";

            if (!File.Exists(colorMapPath))
            {
                CreateTexture(montageSettings, colorMapPath, chunk.Textures.Select(texture => texture.ColorNXMap.ToArray()));
            }

            // Specular map
            string specMapPath = directory + @"/Textures/" + name + "_specny" + ".dds";

            if (!File.Exists(specMapPath))
            {
                CreateTexture(montageSettings, specMapPath, chunk.Textures.Select(texture => texture.SpecNyMap.ToArray()));
            }
        }
Example #11
0
        private void CreateSheet(ThumbnailSheetCreateRequest request, Response response, IMagickImageCollection images)
        {
            int tempWidth = 0, tempHeight = 0;
            var files = Directory.GetFiles(_config.TempThumbnailPath, "thumbnail*.png").OrderBy(x => x).ToList();

            foreach (var file in files)
            {
                var image = new MagickImage(file);
                tempWidth  = image.Width;
                tempHeight = image.Height;
                images.Add(image);
            }

            var conversionNumber = tempWidth / request.ThumbnailWidth;

            tempHeight = tempHeight / conversionNumber;

            var montageSetting = new MontageSettings
            {
                Geometry        = new MagickGeometry(request.ThumbnailWidth, tempHeight),
                TileGeometry    = new MagickGeometry(GetTileGeometry(files.Count)),
                BackgroundColor = MagickColors.Black,
                BorderColor     = MagickColors.DarkGray,
                BorderWidth     = 1,
                Font            = "Arial",
                FontPointsize   = request.SheetTitleFontSize,
                FillColor       = MagickColors.LightGray,
                StrokeColor     = MagickColors.WhiteSmoke,
                Title           = request.SheetName
            };

            using (var montage = images.Montage(montageSetting))
            {
                var path = Path.Combine(_config.ThumbnailSheetPath, request.SheetName + "-sheet.jpg");
                montage.Format  = MagickFormat.Jpeg;
                montage.Quality = request.SheetQuality;
                montage.Write(path);
                response.SheetFilePath = path;
            }
        }
Example #12
0
        public void Execute()
        {
            MontageConfig montageConfig = Config.Montages;

            if (montageConfig == null)
            {
                throw new ConfigurationException("Montage action performed, but no montages are defined in the configuration.");
            }

            string font = montageConfig.Font ?? DefaultFontFamily();

            MontageSettings montageSettings = new MontageSettings()
            {
                BackgroundColor = MagickColors.None,
                Geometry        = new MagickGeometry(2, 2, 0, 0),
                TileGeometry    = new MagickGeometry(8, 0),
                Font            = font
            };

            MagickReadSettings magickSettings = new MagickReadSettings()
            {
                FontFamily      = font,
                FontPointsize   = 14,
                BackgroundColor = MagickColors.None,
                FillColor       = MagickColors.White
            };

            foreach (PatternConfig pattern in montageConfig.Patterns)
            {
                string              name         = pattern.Name;
                DataResolver        resolver     = new DataResolver(pattern.Source);
                List <ResolvedData> resolverData = resolver.Data;

                if (resolverData.Count == 0)
                {
                    throw new ConfigurationException($"The pattern for montage {name} doesn't match any files, exiting the application.");
                }

                resolverData.Sort();

                using (MagickImageCollection collection = new MagickImageCollection())
                {
                    foreach (ResolvedData resolvedFile in resolverData)
                    {
                        string filename      = resolvedFile.Name;
                        string fileShortName = Path.GetFileNameWithoutExtension(filename);

                        MagickImage magickImage = resolvedFile.ToMagickImage(magickSettings);
                        magickImage.Extent(128, 144, MagickColors.None);

                        MagickColor       color         = MagickColor.FromRgba(0, 0, 0, 88);
                        DrawableRectangle drawableRect  = new DrawableRectangle(0, 128, 144, 144);
                        DrawableFillColor drawableColor = new DrawableFillColor(color);
                        magickImage.Draw(drawableColor, drawableRect);

                        magickImage.Annotate(fileShortName, Gravity.South);

                        collection.Add(magickImage);
                        Logger.Debug("Appended montage {0} with: {1}", name, resolvedFile);
                    }

                    Logger.Debug("Finished collecting input, creating a montage of {0} images.", collection.Count);

                    using (IMagickImage montage = collection.Montage(montageSettings))
                    {
                        string filepath = Path.Combine("build", "montages", name + ".png");

                        FileInfo outputPath = new FileInfo(filepath);
                        outputPath.Directory?.Create();

                        Logger.Debug("Writing monatage with name {0} to {1}.", name, filepath);
                        montage.Write(outputPath);
                    }
                }
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            currentPath     = AppDomain.CurrentDomain.BaseDirectory;
            itemsFailedPath = Path.Combine(currentPath, "items_failed");
            itemsPath       = Path.Combine(currentPath, "items");
            gifitemsPath    = Path.Combine(currentPath, "gifitems");
            outPath         = Path.Combine(currentPath, "out");
            schema          = JsonConvert.DeserializeObject <OSRSItemSchema>(File.ReadAllText(Path.Combine(currentPath, "items.json")));
            client          = new WebClient();
            imageCached     = File.Exists(Path.Combine(outPath, "tpi_32.png"));

            rules = new List <Rule>();
            rules.Add(new DefaultRule());

            CheckDirectoryExists(itemsFailedPath);
            CheckDirectoryExists(itemsPath);
            CheckDirectoryExists(outPath);

            int i = 1;

            if (!imageCached)
            {
                foreach (OSRSItem item in schema.Items.Values)
                {
                    bool downloaded = false;
                    try
                    {
                        if (!File.Exists(GetItemPathPng(item.Id)) && !File.Exists(Get404ItemPath(item.Id)))
                        {
                            DownloadItem(item.Id);
                            downloaded = true;
                        }
                        if (item.HasNoted && item.NotedId > 0 && !File.Exists(GetItemPathPng(item.NotedId)) && !File.Exists(Get404ItemPath(item.NotedId)))
                        {
                            DownloadItem(item.NotedId);
                        }
                    }
                    catch (WebException e)
                    {
                        int id = File.Exists(GetItemPathPng(item.Id)) ? item.NotedId : item.Id;
                        Console.WriteLine(Get404ItemPath(id));
                        Console.WriteLine(File.Exists(Get404ItemPath(id)));
                        Console.WriteLine($"Error downloading {id} ({i}/{schema.Items.Values.Count})");
                        Console.WriteLine(e);
                        Touch(Get404ItemPath(id));
                        downloaded = false;
                    }
                    finally
                    {
                        if (downloaded)
                        {
                            Console.WriteLine($"Downloaded {item.Id}.png ({i}/{schema.Items.Values.Count})");
                        }
                        else if (File.Exists(GetItemPathPng(item.Id)))
                        {
                            Console.WriteLine($"{item.Id}.png exists ({i}/{schema.Items.Values.Count})");
                        }
                    }
                    i++;
                }
            }
            else
            {
                Console.WriteLine("Spritesheet found, skipping scraping as it can be time consuming.");
            }

            Console.WriteLine("Done scraping!");

            MagickImageCollection     magickImageCollection = new MagickImageCollection();
            List <ModItemDataXML>     modItemList           = new List <ModItemDataXML>();
            List <ModItemTypeDataXML> modItemTypeList       = new List <ModItemTypeDataXML>();
            List <ItemXML>            itemTextures32        = new List <ItemXML>();

            i = 1;
            int count = schema.Items.Count;

            foreach (OSRSItem item in schema.Items.Values)
            {
                if (File.Exists(GetItemPathPng(item.Id)))
                {
                    AddItem(item, modItemList, modItemTypeList, itemTextures32, magickImageCollection);
                    if (item.HasNoted && item.NotedId > 0 && File.Exists(GetItemPathPng(item.NotedId)))
                    {
                        AddItem(new OSRSItem
                        {
                            Name        = $"{item.Name} (noted)",
                            Id          = item.NotedId,
                            Description = "Swap this note at any bank for the equivalent item.",
                            CanStack    = true
                        }, modItemList, modItemTypeList, itemTextures32, magickImageCollection);
                    }
                    Console.WriteLine($"Added {item.Id} ({i}/{count})");
                }
                i++;
            }

            var duplicates = modItemList.GroupBy(a => a.ItemID).Where(a => a.Count() > 1);

            Console.WriteLine($"Duplicate Count: {duplicates.Count()}");
            if (duplicates.Count() > 0)
            {
                foreach (IGrouping <string, ModItemDataXML> item in duplicates)
                {
                    Console.WriteLine(item.First().ItemID);
                }
                Console.ReadLine();
            }
            if (!imageCached)
            {
                int size = (int)Math.Ceiling(Math.Sqrt((double)itemTextures32.Count));
                Console.WriteLine($"Montage size is {size}x{size}");

                var montageSettings = new MontageSettings
                {
                    TileGeometry    = new MagickGeometry(size, size),
                    Geometry        = new MagickGeometry(32, 32),
                    BackgroundColor = new MagickColor(214, 147, 255, 0),
                };

                var spriteSheet = magickImageCollection.Montage(montageSettings);
                spriteSheet.Write(Path.Combine(outPath, "tpi_32.png"));
                Console.WriteLine($"magickImageCollection: {magickImageCollection.Count}");
                SerializeObject <ItemXML[]>(itemTextures32.ToArray(), Path.Combine(outPath, "ItemTextures32.xml"));
                Console.WriteLine($"itemTextures32: {itemTextures32.Count}");
            }
            else
            {
                Console.WriteLine("Spritesheet found, skipping stitching as it can be time consuming.");
            }
            SerializeObject <ModItemDataXML[]>(modItemList.ToArray(), Path.Combine(outPath, "ItemData.xml"));
            Console.WriteLine($"modItemList: {modItemList.Count}");
            SerializeObject <ModItemTypeDataXML[]>(modItemTypeList.ToArray(), Path.Combine(outPath, "ItemTypeData.xml"));
            Console.WriteLine($"modItemTypeList: {modItemTypeList.Count}");

            Console.ReadLine();
        }
Example #14
0
        public static void ExportTextures(ForgelightGame forgelightGame, CnkLOD chunk, string directory)
        {
            string name = Path.GetFileNameWithoutExtension(chunk.Name);

            if (name == null)
            {
                return;
            }

            directory += "/" + name.Split('_')[0];

            if (!Directory.Exists(directory + @"/Textures"))
            {
                Directory.CreateDirectory(directory + @"/Textures");
            }

            MontageSettings montageSettings = new MontageSettings();

            montageSettings.TileGeometry    = new MagickGeometry(2, 2);
            montageSettings.Geometry        = new MagickGeometry(512, 512);
            montageSettings.BackgroundColor = MagickColor.FromRgba(0, 0, 0, 0);
            montageSettings.BorderColor     = MagickColor.FromRgba(0, 0, 0, 0);
            montageSettings.BorderWidth     = 0;

            //TODO Code Duplication
            //Color Map
            string colorMapPath = directory + @"/Textures/" + name + "_colornx" + ".dds";

            if (!File.Exists(colorMapPath))
            {
                using (MagickImageCollection stitchedColorMap = new MagickImageCollection())
                {
                    foreach (CnkLOD.Texture texture in chunk.Textures)
                    {
                        MagickImage textureQuad = new MagickImage(texture.ColorNXMap.ToArray());
                        stitchedColorMap.Add(textureQuad);
                    }

                    using (MagickImage result = stitchedColorMap.Montage(montageSettings))
                    {
                        result.Write(colorMapPath);
                    }
                }
            }

            //TODO code duplication
            //Specular map
            string specMapPath = directory + @"/Textures/" + name + "_specny" + ".dds";

            if (!File.Exists(specMapPath))
            {
                using (MagickImageCollection stitchedSpecMap = new MagickImageCollection())
                {
                    foreach (CnkLOD.Texture texture in chunk.Textures)
                    {
                        MagickImage textureQuad = new MagickImage(texture.SpecNyMap.ToArray());
                        stitchedSpecMap.Add(textureQuad);
                    }

                    using (MagickImage result = stitchedSpecMap.Montage(montageSettings))
                    {
                        result.Write(specMapPath);
                    }
                }
            }
        }