Пример #1
0
        private BitmapSource CreateWhiteNoizeBmp(int width, int height)
        {
            var    dataSource = DataSource;
            Random rnd        = new Random();

            int[] pixels = new int[width * height];
            for (int i = 0; i < width * height; i++)
            {
                HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
                int      argb  = color.ToArgb();
                pixels[i] = argb;
            }
            //var whiteNoizeBmp = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, width * 4);

            var contentBounds = dataSource.Grid.GetGridBounds();

            Viewport2D.SetContentBounds(this, contentBounds);

            int[] effectivePixels = CreateConvolutionArray(width, height, pixels);

            var filter = new NormalizeFilter();

            filter.Filter(effectivePixels, width, height);

            var result = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, effectivePixels, width * 4);

            //ScreenshotHelper.SaveBitmapToFile(result, "1.png");

            return(result);
        }
		private BitmapSource CreateWhiteNoizeBmp(int width, int height)
		{
			var dataSource = DataSource;
			Random rnd = new Random();
			int[] pixels = new int[width * height];
			for (int i = 0; i < width * height; i++)
			{
				HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
				int argb = color.ToArgb();
				pixels[i] = argb;
			}
			//var whiteNoizeBmp = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, width * 4);

			var contentBounds = dataSource.Grid.GetGridBounds();
			Viewport2D.SetContentBounds(this, contentBounds);

			int[] effectivePixels = CreateConvolutionArray(width, height, pixels);

			var filter = new NormalizeFilter();
			filter.Filter(effectivePixels, width, height);

			var result = WriteableBitmap.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, effectivePixels, width * 4);
			//ScreenshotHelper.SaveBitmapToFile(result, "1.png");

			return result;
		}
        public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double maxLength = Double.NegativeInfinity;
            double minLength = Double.PositiveInfinity;

            // determine min and max length
            // this works faster than parallel enumerable version.
            for (int ix = 0; ix < width; ix++)
            {
                for (int iy = 0; iy < height; iy++)
                {
                    var length = field[ix, iy].Length;
                    if (length > maxLength)
                    {
                        maxLength = length;
                    }
                    if (length < minLength)
                    {
                        minLength = length;
                    }
                }
            }

            int[] resultPixels = new int[width * height];
            pixels.CopyTo(resultPixels, 0);

            // attempt to avoid exception on line
            // 'HsbColor color = HsbColor.FromArgb(pixels[i]);'
            if (pixels.Length == 0)
            {
                return(pixels);
            }

            Parallel.For(0, width * height, i =>
            {
                HsbColor color = HsbColor.FromArgb(pixels[i]);

                int ix     = i % width;
                int iy     = i / width;
                var length = field[ix, height - 1 - iy].Length;

                var ratio = (length - minLength) / (maxLength - minLength);
                if (ratio.IsNaN())
                {
                    ratio = 0;
                }

                var paletteColor = Palette.GetColor(ratio).ToHsbColor();

                color.Hue        = paletteColor.Hue;
                color.Saturation = paletteColor.Saturation;

                resultPixels[i] = color.ToArgb();
            });

            return(resultPixels);
        }
Пример #4
0
        private static void GenerateWhiteNoizeImage(int width, int height, int[] pixels)
        {
            Random rnd = new Random();

            for (int i = 0; i < width * height; i++)
            {
                HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
                int      argb  = color.ToArgb();
                pixels[i] = argb;
            }
        }
Пример #5
0
		public static int[] CreateWhiteNoizeImage(int width, int height)
		{
			int[] pixels = new int[width * height];

			Random rnd = new Random();
			for (int i = 0; i < width * height; i++)
			{
				HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
				int argb = color.ToArgb();
				pixels[i] = argb;
			}

			return pixels;
		}
Пример #6
0
        public static int[] CreateWhiteNoizeImage(int width, int height)
        {
            int[] pixels = new int[width * height];

            Random rnd = new Random();

            for (int i = 0; i < width * height; i++)
            {
                HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
                int      argb  = color.ToArgb();
                pixels[i] = argb;
            }

            return(pixels);
        }
Пример #7
0
        public Color GetColor(double t)
        {
            Verify.AssertIsFinite(t);
            Verify.IsTrue(0 <= t && t <= 1);

            if (t <= 0)
            {
                return(colors[0]);
            }
            else if (t >= 1)
            {
                return(colors[colors.Count - 1]);
            }
            else
            {
                int i = 0;
                while (points[i] < t)
                {
                    i++;
                }

                double alpha = (points[i] - t) / (points[i] - points[i - 1]);

                Verify.IsTrue(0 <= alpha && alpha <= 1);

                Color c0  = colors[i - 1];
                Color c1  = colors[i];
                Color res = Color.FromRgb(
                    (byte)(c0.R * alpha + c1.R * (1 - alpha)),
                    (byte)(c0.G * alpha + c1.G * (1 - alpha)),
                    (byte)(c0.B * alpha + c1.B * (1 - alpha)));

                // Increasing saturation and brightness
                if (increaseBrightness)
                {
                    HsbColor hsb = res.ToHsbColor();
                    //hsb.Saturation = 0.5 * (1 + hsb.Saturation);
                    hsb.Brightness = 0.5 * (1 + hsb.Brightness);
                    return(hsb.ToArgb());
                }
                else
                {
                    return(res);
                }
            }
        }
Пример #8
0
        private void CreateNoizeTexture(GraphicsDevice device)
        {
            const int size = 512;

            noizeTexture = new Texture2D(device, size, size);

            int[]  noizeData = new int[size * size];
            Random rnd       = new Random();

            for (int i = 0; i < size * size; i++)
            {
                HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
                int      argb  = color.ToArgb();
                noizeData[i] = argb;
            }

            noizeTexture.SetData(noizeData);
        }
Пример #9
0
        public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double maxLength = Double.NegativeInfinity;
            double minLength = Double.PositiveInfinity;

            for (int ix = 0; ix < width; ix++)
            {
                for (int iy = 0; iy < height; iy++)
                {
                    var length = field[ix, iy].Length;
                    if (length > maxLength)
                    {
                        maxLength = length;
                    }
                    if (length < minLength)
                    {
                        minLength = length;
                    }
                }
            }

            for (int i = 0; i < width * height; i++)
            {
                HsbColor color = HsbColor.FromArgb(pixels[i]);

                int ix     = i % width;
                int iy     = i / width;
                var length = field[ix, iy].Length;

                var ratio = (length - minLength) / (maxLength - minLength);
                if (ratio.IsNaN())
                {
                    ratio = 0;
                }

                var paletteColor = Palette.GetColor(ratio).ToHsbColor();

                color.Hue        = paletteColor.Hue;
                color.Saturation = paletteColor.Saturation;

                pixels[i] = color.ToArgb();
            }
        }
		private static void GenerateWhiteNoizeImage(int width, int height, int[] pixels)
		{
			Random rnd = new Random();
			for (int i = 0; i < width * height; i++)
			{
				HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
				int argb = color.ToArgb();
				pixels[i] = argb;
			}
		}
		protected void RebuildUI()
		{
			var time = watch.ElapsedMilliseconds;
			double dt = time - prevElapsedMilliseconds;
			prevElapsedMilliseconds = time;

			dt /= 1000;
			GetFluidData(dens_prev, u_prev, v_prev);
			VelocityStep(N, u, v, u_prev, v_prev, 0.01, dt);
			DensityStep(N, dens, dens_prev, u, v, 2.0, dt);

			double densityMin = Double.PositiveInfinity;
			double densityMax = Double.NegativeInfinity;
			for (int i = 0; i < N + 2; i++)
			{
				for (int j = 0; j < N + 2; j++)
				{
					var value = dens[i, j];
					if (value < densityMin)
						densityMin = value;
					if (value > densityMax)
						densityMax = value;
				}
			}

			int[] pixels = new int[(N + 2) * (N + 2)];

			for (int i = 0; i < N + 2; i++)
			{
				for (int j = 0; j < N + 2; j++)
				{
					double value = dens[i, N + 1 - j];
					HsbColor color = new HsbColor(10, 1, (value - densityMin) / (densityMax - densityMin));

					pixels[(N + 1 - j) * (N + 2) + i] = color.ToArgb();
				}
			}

			bmp.WritePixels(new Int32Rect(0, 0, N + 2, N + 2), pixels, ((N + 2) * PixelFormats.Bgra32.BitsPerPixel + 7) / 8, 0);
		}