public static SwiftBitmap Generate(int Width, int Height, int NumberFaults, int Seed)
        {
            float[,] Heights = new float[Width, Height];
            float IncreaseVal = 0.1f;
            var   Generator   = new System.Random(Seed);

            for (int x = 0; x < NumberFaults; ++x)
            {
                IncreaseVal = GenerateFault(Width, Height, NumberFaults, Heights, IncreaseVal, Generator);
            }
            var ReturnValue = new SwiftBitmap(Width, Height);

            ReturnValue.Lock();
            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    float Value = Heights[x, y];
                    Value  = (Value * 0.5f) + 0.5f;
                    Value *= 255;
                    int RGBValue = ((int)Value).Clamp(255, 0);
                    ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
                }
            }
            return(ReturnValue.Unlock());
        }
        public static SwiftBitmap Generate(int Width, int Height, int NumberOfPoints, int Seed)
        {
            float[,] DistanceBuffer = new float[Width, Height];
            float MinimumDistance = float.MaxValue;
            float MaxDistance     = float.MinValue;
            var   Map             = new CellularMap(Seed, Width, Height, NumberOfPoints);

            MaxDistance     = Map.MaxDistance;
            MinimumDistance = Map.MinDistance;
            DistanceBuffer  = Map.Distances;
            var ReturnValue = new SwiftBitmap(Width, Height);

            ReturnValue.Lock();
            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    float Value = GetHeight(x, y, DistanceBuffer, MinimumDistance, MaxDistance);
                    Value *= 255;
                    int RGBValue = ((int)Value).Clamp(255, 0);
                    ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
                }
            }
            return(ReturnValue.Unlock());
        }
예제 #3
0
 /// <summary>
 /// Convert SwiftBitmap to Stream
 /// /// </summary>
 /// <param name="bitmapToStream"></param>
 /// <returns></returns>
 public async Task <Stream> GetStreamFromBitmap(SwiftBitmap bitmapToStream)
 {
     return(await Task.Run(() => {
         var ts = new MemoryStream();
         using (var tb = bitmapToStream) {
             tb.InternalBitmap.Save(ts, ImageFormat.Jpeg);
             ts.Position = 0;
         }
         return ts;
     }));
 }
 public static SwiftBitmap Generate(int Width, int Height, int MaxRGBValue, int MinRGBValue,
     float Frequency, float Amplitude, float Persistance, int Octaves, int Seed)
 {
     var ReturnValue = new SwiftBitmap(Width, Height);
     ReturnValue.Lock();
     var Noise = GenerateNoise(Seed, Width, Height);
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             var Value = GetValue(x, y, Width, Height, Frequency, Amplitude, Persistance, Octaves, Noise);
             Value = (Value * 0.5f) + 0.5f;
             Value *= 255;
             var RGBValue = ((int)Value).Clamp(MaxRGBValue, MinRGBValue);
             ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
         }
     }
     return ReturnValue.Unlock();
 }
 public static SwiftBitmap Generate(int Width, int Height, int NumberOfCracks, int Iterations,
     int MaxChange, int MaxLength, int Seed)
 {
     Contract.Requires<ArgumentException>(NumberOfCracks >= 0, "Number of cracks should be greater than 0");
     Contract.Requires<ArgumentException>(Width >= 0, "Width must be greater than or equal to 0");
     Contract.Requires<ArgumentException>(Height >= 0, "Height must be greater than or equal to 0");
     var ReturnValue = new SwiftBitmap(Width, Height);
     var Lines = GenerateLines(Width, Height, NumberOfCracks, Iterations, MaxChange, MaxLength, Seed);
     using (Graphics ReturnGraphic = Graphics.FromImage(ReturnValue.InternalBitmap))
     {
         foreach (Line Line in Lines)
         {
             foreach (Line SubLine in Line.SubLines)
             {
                 ReturnGraphic.DrawLine(Pens.White, SubLine.X1, SubLine.Y1, SubLine.X2, SubLine.Y2);
             }
         }
     }
     return ReturnValue;
 }
예제 #6
0
        public static SwiftBitmap Generate(int Width, int Height, int MaxRGBValue, int MinRGBValue,
                                           float Frequency, float Amplitude, float Persistance, int Octaves, int Seed)
        {
            var ReturnValue = new SwiftBitmap(Width, Height);

            ReturnValue.Lock();
            float[,] Noise = GenerateNoise(Seed, Width, Height);
            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    float Value = GetValue(x, y, Width, Height, Frequency, Amplitude, Persistance, Octaves, Noise);
                    Value  = (Value * 0.5f) + 0.5f;
                    Value *= 255;
                    int RGBValue = ((int)Value).Clamp(MaxRGBValue, MinRGBValue);
                    ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
                }
            }
            return(ReturnValue.Unlock());
        }
        public static SwiftBitmap Generate(int Width, int Height, int NumberOfCracks, int Iterations,
                                           int MaxChange, int MaxLength, int Seed)
        {
            Contract.Requires <ArgumentException>(NumberOfCracks >= 0, "Number of cracks should be greater than 0");
            Contract.Requires <ArgumentException>(Width >= 0, "Width must be greater than or equal to 0");
            Contract.Requires <ArgumentException>(Height >= 0, "Height must be greater than or equal to 0");
            var         ReturnValue = new SwiftBitmap(Width, Height);
            List <Line> Lines       = GenerateLines(Width, Height, NumberOfCracks, Iterations, MaxChange, MaxLength, Seed);

            using (Graphics ReturnGraphic = Graphics.FromImage(ReturnValue.InternalBitmap))
            {
                foreach (Line Line in Lines)
                {
                    foreach (Line SubLine in Line.SubLines)
                    {
                        ReturnGraphic.DrawLine(Pens.White, SubLine.X1, SubLine.Y1, SubLine.X2, SubLine.Y2);
                    }
                }
            }
            return(ReturnValue);
        }
 public static SwiftBitmap Generate(int Width, int Height, int NumberOfPoints, int Seed)
 {
     float[,] DistanceBuffer = new float[Width, Height];
     float MinimumDistance = float.MaxValue;
     float MaxDistance = float.MinValue;
     var Map = new CellularMap(Seed, Width, Height, NumberOfPoints);
     MaxDistance = Map.MaxDistance;
     MinimumDistance = Map.MinDistance;
     DistanceBuffer = Map.Distances;
     var ReturnValue = new SwiftBitmap(Width, Height);
     ReturnValue.Lock();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             var Value = GetHeight(x, y, DistanceBuffer, MinimumDistance, MaxDistance);
             Value *= 255;
             var RGBValue = ((int)Value).Clamp(255, 0);
             ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
         }
     }
     return ReturnValue.Unlock();
 }
 public static SwiftBitmap Generate(int Width, int Height, int NumberFaults, int Seed)
 {
     float[,] Heights = new float[Width, Height];
     float IncreaseVal = 0.1f;
     var Generator = new System.Random(Seed);
     for (int x = 0; x < NumberFaults; ++x)
     {
         IncreaseVal = GenerateFault(Width, Height, NumberFaults, Heights, IncreaseVal, Generator);
     }
     var ReturnValue = new SwiftBitmap(Width, Height);
     ReturnValue.Lock();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             float Value = Heights[x, y];
             Value = (Value * 0.5f) + 0.5f;
             Value *= 255;
             int RGBValue = ((int)Value).Clamp(255, 0);
             ReturnValue.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue));
         }
     }
     return ReturnValue.Unlock();
 }
        /// <summary>
        /// Filters the assets
        /// </summary>
        /// <param name="Assets">Assets to filter</param>
        /// <returns>The filtered assets</returns>
        public IList <IAsset> Filter(IList <IAsset> Assets)
        {
            if (Assets == null || Assets.Count == 0)
            {
                return(new List <IAsset>());
            }
            if (Assets.FirstOrDefault().Type != AssetType.CSS)
            {
                return(Assets);
            }
            foreach (IAsset Asset in Assets)
            {
                foreach (Match ImageMatch in ImageRegex.Matches(Asset.Content))
                {
                    string TempFile    = ImageMatch.Groups["File"].Value;
                    string MatchString = ImageMatch.Value;
                    var    File        = new FileInfo(TempFile);
                    File = DetermineFile(File, Asset, TempFile);
                    if (File == null || !File.Exists)
                    {
                        var AssetFile = new FileInfo(Asset.Path);
                        File = new FileInfo(AssetFile.Directory.FullName + "\\" + TempFile);
                    }
                    if (File.Exists)
                    {
                        if (File.Extension.ToUpperInvariant() == ".TTF" ||
                            File.Extension.ToUpperInvariant() == ".OTF" ||
                            File.Extension.ToUpperInvariant() == ".WOFF" ||
                            File.Extension.ToUpperInvariant() == ".SVG" ||
                            File.Extension.ToUpperInvariant() == ".EOT")
                        {
                            string MIME = "";
                            switch (File.Extension.ToUpperInvariant())
                            {
                            case ".WOFF":
                                MIME = "application/x-font-woff";
                                break;

                            case ".OTF":
                                MIME = "application/x-font-opentype";
                                break;

                            case ".TTF":
                                MIME = "application/x-font-ttf";
                                break;

                            case ".SVG":
                                MIME = "image/svg+xml";
                                break;

                            case ".EOT":
                                MIME = "application/vnd.ms-fontobject";
                                break;
                            }

                            Asset.Content = Asset.Content.Replace(MatchString, "url(data:" + MIME + ";base64," + File.ReadBinary().ToString(Base64FormattingOptions.None) + ")");
                        }
                        else
                        {
                            using (SwiftBitmap TempImage = new SwiftBitmap(File.FullName))
                            {
                                string MIMEType = "image/jpeg";
                                string Content  = "";
                                if (File.FullName.ToUpperInvariant().EndsWith(".PNG", StringComparison.Ordinal))
                                {
                                    MIMEType = "image/png";
                                    Content  = TempImage.ToString(ImageFormat.Png);
                                }
                                else if (File.FullName.ToUpperInvariant().EndsWith(".JPG", StringComparison.Ordinal) || File.FullName.ToUpperInvariant().EndsWith(".JPEG", StringComparison.Ordinal))
                                {
                                    MIMEType = "image/jpeg";
                                    Content  = TempImage.ToString(ImageFormat.Jpeg);
                                }
                                else if (File.FullName.ToUpperInvariant().EndsWith(".GIF", StringComparison.Ordinal))
                                {
                                    MIMEType = "image/gif";
                                    Content  = TempImage.ToString(ImageFormat.Gif);
                                }
                                else if (File.FullName.ToUpperInvariant().EndsWith(".TIFF", StringComparison.Ordinal))
                                {
                                    MIMEType = "image/tiff";
                                    Content  = TempImage.ToString(ImageFormat.Tiff);
                                }
                                else if (File.FullName.ToUpperInvariant().EndsWith(".BMP", StringComparison.Ordinal))
                                {
                                    MIMEType = "image/bmp";
                                    Content  = TempImage.ToString(ImageFormat.Bmp);
                                }
                                Asset.Content = Asset.Content.Replace(MatchString, "url(data:" + MIMEType + ";base64," + Content + ")");
                            }
                        }
                    }
                }
            }
            return(Assets);
        }