//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace NPerf.Report
{
using System;
using System.Drawing;
public enum ColorMap
{
Hot,
GrayScale,
Jet
}
public sealed class ColorGenerator
{
private ColorMap map;
private int current;
private int count;
public ColorGenerator(ColorMap map, int count)
{
this.map = map;
this.count = count;
this.current = -1;
}
public ColorMap Map
{
get
{
return this.map;
}
set
{
this.map = value;
}
}
public void Reset()
{
this.current = -1;
}
public void Reset(int count)
{
this.count = count;
this.current = -1;
}
public Color MoveNextColor()
{
++current;
if (this.current > this.count)
throw new Exception("Color out of range");
switch(map)
{
case ColorMap.Hot:
return Hot(Alpha);
case ColorMap.GrayScale:
return GrayScale(Alpha);
case ColorMap.Jet:
return Jet(Alpha);
}
throw new Exception("unknown map");
}
internal double Alpha
{
get
{
return (double)current/(double)count;
}
}
public Color Hot(double alpha)
{
int ai = AlphaToInt(alpha);
int n = 255/8*3;
if (ai < n)
return Color.FromArgb(255,Scale(ai,n), 0, 0);
else if (ai < 2*n)
return Color.FromArgb(255,255, Scale(ai-n,n), 0);
else
return Color.FromArgb(255,255,255,Scale(ai-2*n,n));
}
public Color GrayScale(double alpha)
{
int ai = AlphaToInt(alpha,150);
return Color.FromArgb(255,ai, ai, ai);
}
public Color Jet(double alpha)
{
int ai = AlphaToInt(alpha,255);
int n = (int)Math.Max(Math.Round(255.0/4),1);
if (ai < n/2)
return Color.FromArgb(255, 0,0,Scale(ai+n/2,n));
else if (ai < n/2*3)
return Color.FromArgb(255, 0,Scale(ai-n/2,n),255);
else if (ai < n/2*5)
return Color.FromArgb(255, Scale(ai-n/2*3,n),255,255-Scale(ai-n/2*3,n));
else if (ai < n/2*7)
return Color.FromArgb(255, 255,255-Scale(ai-n/2*5,n),0);
else
return Color.FromArgb(255, 255-Scale(ai+n/2-n/2*7,n),0,0);
}
internal int AlphaToInt(double alpha)
{
int ai = (int)Math.Floor(alpha*255);
return Math.Min(255, Math.Max(0,ai));
}
internal int AlphaToInt(double alpha, int maxValue)
{
int ai = (int)Math.Floor(alpha*maxValue);
return Math.Min(maxValue, Math.Max(0,ai));
}
internal int Scale(int ai, int n)
{
return (int)Math.Floor((double)ai/n*255.0);
}
}
}