System.Collections.Generic.Dictionary.ContainsKey(sPixel)

Here are the examples of the csharp api System.Collections.Generic.Dictionary.ContainsKey(sPixel) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : DownScale.cs
with GNU General Public License v3.0
from Salmakis

public static sPixel alphaWeightedAverage(sPixel[] pixs)
		{
			Dictionary<sPixel, double> alphaScaledPixs = new Dictionary<sPixel, double>(pixs.Length);
			double total = 0.0;

			double a = 0.0;
			double r = 0.0;
			double g = 0.0;
			double b = 0.0;


			foreach(sPixel pix in pixs)
			{
				double alphaPower = pix.Alpha / (255.0 * 1.25); // we want non-transparent pixels to count more towards the overall appearance.
				//double alphaPower = (pix.Alpha / 255.0) * (pix.Alpha / 255.0); //also an option.
				if (alphaScaledPixs.ContainsKey(pix))
				{
					alphaScaledPixs[pix] += alphaPower;
				}
				else
				{
					alphaScaledPixs.Add(pix, alphaPower);
				}
				total += alphaPower;
			}


			if (total == 0.0)
			{
				total = pixs.Length;
				foreach(KeyValuePair<sPixel, double> alphaScaledPix in alphaScaledPixs)
				{
					a += alphaScaledPix.Key.Alpha * 1.0;
					r += alphaScaledPix.Key.Red * 1.0;
					g += alphaScaledPix.Key.Green * 1.0;
					b += alphaScaledPix.Key.Blue * 1.0;
				}
			}
			else
			{
				foreach (KeyValuePair<sPixel, double> alphaScaledPix in alphaScaledPixs)
				{
					a += alphaScaledPix.Key.Alpha * alphaScaledPix.Value;
					r += alphaScaledPix.Key.Red * alphaScaledPix.Value;
					g += alphaScaledPix.Key.Green * alphaScaledPix.Value;
					b += alphaScaledPix.Key.Blue * alphaScaledPix.Value;
				}
			}
			return (new sPixel(
				(byte)((r) / total),
				(byte)((g) / total),
				(byte)((b) / total),
				(byte)((a) / total)
				));

		}