Esempio n. 1
0
        List <SharedImageInfo> ParseImageTaskItems(ITaskItem[] images)
        {
            var r = new List <SharedImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new SharedImageInfo();

                info.Filename = image.GetMetadata("FullPath");

                info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize"));

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }

                info.TintColor = Utils.ParseColorString(image.GetMetadata("TintColor"));

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }
Esempio n. 2
0
 public AndroidAdaptiveIconGenerator(SharedImageInfo info, string appIconName, string intermediateOutputPath, ILogger logger)
 {
     Info   = info;
     Logger = logger;
     IntermediateOutputPath = intermediateOutputPath;
     AppIconName            = appIconName;
 }
Esempio n. 3
0
 public AppleIconAssetsGenerator(SharedImageInfo info, string appIconName, string intermediateOutputPath, DpiPath[] dpis, ILogger logger)
 {
     Info   = info;
     Logger = logger;
     IntermediateOutputPath = intermediateOutputPath;
     AppIconName            = appIconName;
     Dpis = dpis;
 }
        void ProcessAppIcon(SharedImageInfo img, ConcurrentBag <ResizedImageInfo> resizedImages)
        {
            var appIconName = img.OutputName;

            // Generate the actual bitmap app icons themselves
            var appIconDpis = DpiPath.GetAppIconDpis(PlatformType, appIconName);

            Log.LogMessage(MessageImportance.Low, $"App Icon");

            // Apple and Android have special additional files to generate for app icons
            if (PlatformType == "android")
            {
                Log.LogMessage(MessageImportance.Low, $"Android Adaptive Icon Generator");

                appIconName = appIconName.ToLowerInvariant();

                var adaptiveIconGen = new AndroidAdaptiveIconGenerator(img, appIconName, IntermediateOutputPath, this);
                var iconsGenerated  = adaptiveIconGen.Generate();

                foreach (var iconGenerated in iconsGenerated)
                {
                    resizedImages.Add(iconGenerated);
                }
            }
            else if (PlatformType == "ios")
            {
                Log.LogMessage(MessageImportance.Low, $"iOS Icon Assets Generator");

                var appleAssetGen = new AppleIconAssetsGenerator(img, appIconName, IntermediateOutputPath, appIconDpis, this);

                var assetsGenerated = appleAssetGen.Generate();

                foreach (var assetGenerated in assetsGenerated)
                {
                    resizedImages.Add(assetGenerated);
                }
            }

            Log.LogMessage(MessageImportance.Low, $"Generating App Icon Bitmaps for DPIs");

            var appTool = new SkiaSharpAppIconTools(img, this);

            Log.LogMessage(MessageImportance.Low, $"App Icon: Intermediate Path " + IntermediateOutputPath);

            foreach (var dpi in appIconDpis)
            {
                Log.LogMessage(MessageImportance.Low, $"App Icon: " + dpi);

                var destination = Resizer.GetFileDestination(img, dpi, IntermediateOutputPath)
                                  .Replace("{name}", appIconName);

                Log.LogMessage(MessageImportance.Low, $"App Icon Destination: " + destination);

                appTool.Resize(dpi, Path.ChangeExtension(destination, ".png"));
            }
        }
Esempio n. 5
0
        public SkiaSharpBitmapTools(SharedImageInfo info, ILogger logger)
            : base(info, logger)
        {
            var sw = new Stopwatch();

            sw.Start();

            bmp = SKBitmap.Decode(info.Filename);

            sw.Stop();
            Logger?.Log($"Open RASTER took {sw.ElapsedMilliseconds}ms");
        }
        void ProcessImageCopy(SharedImageInfo img, DpiPath originalScaleDpi, ConcurrentBag <ResizedImageInfo> resizedImages)
        {
            var resizer = new Resizer(img, IntermediateOutputPath, this);

            Log.LogMessage(MessageImportance.Low, $"Copying {img.Filename}");

            var r = resizer.CopyFile(originalScaleDpi, InputsFile, PlatformType.ToLower().Equals("android"));

            resizedImages.Add(r);

            Log.LogMessage(MessageImportance.Low, $"Copied {img.Filename}");
        }
Esempio n. 7
0
        public SkiaSharpSvgTools(SharedImageInfo info, ILogger logger)
            : base(info, logger)
        {
            var sw = new Stopwatch();

            sw.Start();

            svg = new SKSvg();
            svg.Load(Info.Filename);

            sw.Stop();
            Logger?.Log($"Open SVG took {sw.ElapsedMilliseconds}ms");
        }
        void ProcessImageResize(SharedImageInfo img, DpiPath[] dpis, ConcurrentBag <ResizedImageInfo> resizedImages)
        {
            var resizer = new Resizer(img, IntermediateOutputPath, this);

            foreach (var dpi in dpis)
            {
                Log.LogMessage(MessageImportance.Low, $"Resizing {img.Filename}");

                var r = resizer.Resize(dpi, InputsFile);
                resizedImages.Add(r);

                Log.LogMessage(MessageImportance.Low, $"Resized {img.Filename}");
            }
        }
Esempio n. 9
0
        public static string GetFileDestination(SharedImageInfo info, DpiPath dpi, string intermediateOutputPath)
        {
            var fullIntermediateOutputPath = new DirectoryInfo(intermediateOutputPath);

            var destination = Path.Combine(fullIntermediateOutputPath.FullName, dpi.Path, info.OutputName + dpi.FileSuffix + info.OutputExtension);

            var fileInfo = new FileInfo(destination);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }

            return(destination);
        }
Esempio n. 10
0
        public SkiaSharpTools(SharedImageInfo info, ILogger logger)
        {
            Info   = info;
            Logger = logger;

            if (Info.TintColor is Color tint)
            {
                var color = new SKColor(unchecked ((uint)tint.ToArgb()));
                Logger?.Log($"Detected a tint color of {color}");

                Paint = new SKPaint
                {
                    ColorFilter = SKColorFilter.CreateBlendMode(color, SKBlendMode.SrcIn)
                };
            }
        }
Esempio n. 11
0
        public static ResizedImageInfo CopyFile(SharedImageInfo info, DpiPath dpi, string intermediateOutputPath, string inputsFile, ILogger logger, bool isAndroid = false)
        {
            var destination   = Resizer.GetFileDestination(info, dpi, intermediateOutputPath);
            var androidVector = false;

            if (isAndroid && info.IsVector && !info.Resize)
            {
                // Update destination to be .xml file
                destination   = Path.ChangeExtension(info.Filename, ".xml");
                androidVector = true;
            }

            if (IsUpToDate(info.Filename, destination, inputsFile, logger))
            {
                return new ResizedImageInfo {
                           Filename = destination, Dpi = dpi
                }
            }
            ;

            if (androidVector)
            {
                logger.Log("Converting SVG to Android Drawable Vector: " + info.Filename);

                // Transform into an android vector drawable
                var convertErr = Svg2VectorDrawable.Svg2Vector.Convert(info.Filename, destination);
                if (!string.IsNullOrEmpty(convertErr))
                {
                    throw new Svg2AndroidDrawableConversionException(convertErr, info.Filename);
                }
            }
            else
            {
                // Otherwise just copy it straight
                File.Copy(info.Filename, destination, true);
            }

            return(new ResizedImageInfo {
                Filename = destination, Dpi = dpi
            });
        }
Esempio n. 12
0
        public SkiaSharpAppIconTools(SharedImageInfo info, ILogger logger)
        {
            Info   = info;
            Logger = logger;

            AppIconName = info.OutputName;

            hasForeground = File.Exists(info.ForegroundFilename);

            if (hasForeground)
            {
                foregroundTools = SkiaSharpTools.Create(info.ForegroundIsVector, info.ForegroundFilename, null, info.TintColor, logger);
            }

            backgroundTools = SkiaSharpTools.Create(info.IsVector, info.Filename, null, null, logger);

            backgroundOriginalSize = backgroundTools.GetOriginalSize();

            if (hasForeground)
            {
                foregroundOriginalSize = foregroundTools.GetOriginalSize();
            }
        }
Esempio n. 13
0
        public static ResizedImageInfo CopyFile(SharedImageInfo info, DpiPath dpi, string intermediateOutputPath, string inputsFile, ILogger logger, bool isAndroid = false)
        {
            var destination   = Resizer.GetFileDestination(info, dpi, intermediateOutputPath);
            var androidVector = false;

            if (isAndroid && info.IsVector && !info.Resize)
            {
                // TODO: Turn SVG into Vector Drawable format
                // Update destination to be .xml file
                destination   = Path.ChangeExtension(info.Filename, ".xml");
                androidVector = true;
            }

            if (IsUpToDate(info.Filename, destination, inputsFile, logger))
            {
                return new ResizedImageInfo {
                           Filename = destination, Dpi = dpi
                }
            }
            ;

            if (androidVector)
            {
                // TODO: Don't just copy, let's transform to android vector
                File.Copy(info.Filename, destination, true);
            }
            else
            {
                // Otherwise just copy it straight
                File.Copy(info.Filename, destination, true);
            }

            return(new ResizedImageInfo {
                Filename = destination, Dpi = dpi
            });
        }
        List <SharedImageInfo> ParseImageTaskItems(ITaskItem[] images)
        {
            var r = new List <SharedImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new SharedImageInfo();

                info.Filename = image.GetMetadata("FullPath");

                info.BaseSize = Utils.ParseSizeString(image.GetMetadata("BaseSize"));

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }

                info.TintColor = Utils.ParseColorString(image.GetMetadata("TintColor"));

                if (bool.TryParse(image.GetMetadata("IsAppIcon"), out var iai))
                {
                    info.IsAppIcon = iai;
                }

                if (float.TryParse(image.GetMetadata("ForegroundScale"), out var fsc))
                {
                    info.ForegroundScale = fsc;
                }

                var fgFile = image.GetMetadata("ForegroundFile");
                if (!string.IsNullOrEmpty(fgFile))
                {
                    var bgFileInfo = new FileInfo(info.Filename);

                    if (!Path.IsPathRooted(fgFile))
                    {
                        fgFile = Path.Combine(bgFileInfo.Directory.FullName, fgFile);
                    }
                    else
                    {
                        fgFile = Path.GetFullPath(fgFile);
                    }

                    Logger.Log($"AppIcon Foreground: " + fgFile);

                    if (File.Exists(fgFile))
                    {
                        info.ForegroundFilename = fgFile;
                    }
                }

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }
Esempio n. 15
0
 public SkiaSharpSvgTools(SharedImageInfo info, ILogger logger)
     : this(info.Filename, info.BaseSize, info.TintColor, logger)
 {
 }
Esempio n. 16
0
 public Resizer(SharedImageInfo info, string intermediateOutputPath, ILogger logger)
 {
     Info   = info;
     Logger = logger;
     IntermediateOutputPath = intermediateOutputPath;
 }
Esempio n. 17
0
        public SkiaSharpSvgTools(SharedImageInfo info, ILogger logger)
        {
            Info   = info;
            Logger = logger;

            var sw = new Stopwatch();

            sw.Start();

            var svgDoc = SKSvg.Open(Info.Filename);

            void ChangeFill(SvgElement element)
            {
                if (element is SvgPath ePath && ePath.Fill is SvgColourServer eFill)
                {
                    Logger?.Log($"Found Fill: {eFill.Colour.ToString()}");

                    if (!eFill.Colour.IsEmpty)
                    {
                        ePath.Fill = new SvgColourServer(Info.TintColor.Value);

                        Logger?.Log($"Changing Fill: {Info.TintColor.ToString()}");
                    }
                }

                if (element.Children.Count > 0)
                {
                    foreach (var item in element.Children)
                    {
                        ChangeFill(item);
                    }
                }
            }

            if (Info.TintColor.HasValue)
            {
                Logger?.Log($"Changing Tint: {Info.TintColor.Value.ToString()}");

                foreach (var elem in svgDoc.Children)
                {
                    ChangeFill(elem);
                }
            }

            Svg.SvgDocument.SkipGdiPlusCapabilityCheck = true;


            //svgDoc.Write(Info.Filename + ".mod.svg");
            sw.Stop();
            Logger?.Log($"Open SVG took {sw.ElapsedMilliseconds}ms");
            sw.Reset();
            sw.Start();


            svg = new SKSvg();
            sw.Stop();
            Logger?.Log($"new SKSvg() took {sw.ElapsedMilliseconds}ms");
            sw.Reset();
            sw.Start();

            svg.FromSvgDocument(svgDoc);
            sw.Stop();
            Logger?.Log($"svg.FromSvgDocument took {sw.ElapsedMilliseconds}ms");
        }
Esempio n. 18
0
        List <SharedImageInfo> ParseImageTaskItems(ITaskItem[] images)
        {
            var r = new List <SharedImageInfo>();

            if (images == null)
            {
                return(r);
            }

            foreach (var image in images)
            {
                var info = new SharedImageInfo();

                info.Filename = image.GetMetadata("FullPath");

                var size = image.GetMetadata("BaseSize");
                if (!string.IsNullOrWhiteSpace(size))
                {
                    var parts = size.Split(new char[] { ',', ';' }, 2);

                    if (parts.Length > 0 && int.TryParse(parts[0], out var width))
                    {
                        if (parts.Length > 1 && int.TryParse(parts[1], out var height))
                        {
                            info.BaseSize = new Size(width, height);
                        }
                        else
                        {
                            info.BaseSize = new Size(width, width);
                        }
                    }
                }

                if (bool.TryParse(image.GetMetadata("Resize"), out var rz))
                {
                    info.Resize = rz;
                }

                var tint = image.GetMetadata("TintColor");

                if (!string.IsNullOrWhiteSpace(tint))
                {
                    try
                    {
                        var hx = "0x" + tint.Trim('#');
                        var c  = Color.FromArgb(int.Parse(hx));

                        info.TintColor = c;
                    }
                    catch
                    {
                        try { info.TintColor = Color.FromName(tint); }
                        catch { }
                    }
                }

                // TODO:
                // - Parse out custom DPI's

                r.Add(info);
            }

            return(r);
        }
 public SkiaSharpBitmapTools(SharedImageInfo info, ILogger logger)
 {
     Info   = info;
     Logger = logger;
     bmp    = SKBitmap.Decode(info.Filename);
 }