using System;
using System.Drawing;
namespace shjxCamera
{
public class ColorDataPoint
{
#region protected
///
/// 单点颜色
///
protected Color PointColor { get; set; }
protected void UpdatePoint()
{
PointColor = Color.FromArgb(Convert.ToInt32(RTV / Area), Convert.ToInt32(GTV / Area), Convert.ToInt32(BTV / Area));
}
#endregion
#region properties
///
/// 序号
///
public int Id { get; set; }
///
/// 区域R总量
///
public double RTV { get; set; }
///
/// 区域G总量
///
public double GTV { get; set; }
///
/// 区域B总量
///
public double BTV { get; set; }
///
/// 区域面积
///
public double Area { get; set; }
///
/// 小数点后位数
///
public int FloatCount { get; set; }
#endregion
#region methods
public ColorDataPoint(int id = 1, double rtv = 1, double gtv = 1, double btv = 1, double area = 1, int floatcount = 2)
{
Id = id;
RTV = rtv;
GTV = gtv;
BTV = btv;
Area = area;
FloatCount = floatcount;
UpdatePoint();
}
///
/// 返回单点R平均值
///
///
public double GetRSV()
{
double ret = Math.Round(RTV / Area, FloatCount);
return ret;
}
///
/// 返回单点G平均值
///
///
public double GetGSV()
{
double ret = Math.Round(GTV / Area, FloatCount);
return ret;
}
///
/// 返回单点B平均值
///
///
public double GetBSV()
{
double ret = Math.Round(BTV / Area, FloatCount);
return ret;
}
///
/// 返回HSB色调值
///
///
public double GetHue()
{
UpdatePoint();
return Math.Round(PointColor.GetHue(), FloatCount);
}
///
/// 返回HSB饱和度值
///
///
public double GetSaturation()
{
return 1.0;
#if false
#region MyRegion
#if true
UpdatePoint();
return Math.Round(this.PointColor.GetSaturation(), FloatCount);
#endif
#region MyRegion
this.UpdatePoint();
var vmax = Math.Max(this.GTV, Math.Max(this.RTV, this.BTV)) / this.Area;
var vmin = Math.Min(this.GTV, Math.Min(this.RTV, this.BTV)) / this.Area;
var sat = Math.Max(1.0, Math.Round((vmax - vmin) / vmax * 100.0, 2));
return sat;
#endregion
#endregion
#endif
}
///
/// 返回HSB亮度值
///
///
public double GetBrightness()
{
UpdatePoint();
return Math.Round(PointColor.GetBrightness(), FloatCount);
}
#endregion
}
}