PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/Main/src/DynamicDataDisplay.Maps/Charts/VectorFields/Convolution/NormalizeFilter.cs

#
C# | 43 lines | 37 code | 6 blank | 0 comment | 4 complexity | 740afce6c3b93cedfa9f257d1f10918b MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows;
 6
 7namespace Microsoft.Research.DynamicDataDisplay.Maps.Charts.VectorFields
 8{
 9	public class NormalizeFilter : VectorFieldConvolutionFilter
10	{
11		public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
12		{
13			double minBrightness = Double.PositiveInfinity;
14			double maxBrightness = Double.NegativeInfinity;
15
16			for (int i = 0; i < pixels.Length; i++)
17			{
18				int x = i % width;
19				int y = i / width;
20
21				int argb = pixels[i];
22				var color = HsbColor.FromArgb(argb);
23				var brightness = color.Brightness;
24
25				if (brightness < minBrightness)
26					minBrightness = brightness;
27				if (brightness > maxBrightness)
28					maxBrightness = brightness;
29			}
30
31			for (int i = 0; i < pixels.Length; i++)
32			{
33				int argb = pixels[i];
34				var color = HsbColor.FromArgb(argb);
35				var brightness = color.Brightness;
36
37				double ratio = (brightness - minBrightness) / (maxBrightness - minBrightness);
38				color.Brightness = ratio;
39				pixels[i] = color.ToArgb();
40			}
41		}
42	}
43}