asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace RichCreator.Utility.Structs
{
    /// <summary>
    /// HSV Float型颜色数组项
    /// </summary>
    public class ZTHsvFloatColorArrayItem : ColorArrayItem
    {
        public ZTHsvFloatColorArrayItem(float hOffset,float sOffset,float vOffset,ZTPoint offset, ZTColor color):base(offset,color)
        {
            
            float h = 0, s = 0, v = 0;
            ColorUtils.RGBtoHSV(color.Red, color.Green, color.Blue, out h, out s, out v);
            MinHsv = new ZTHsvFloatColor(Math.Max(0,h - hOffset), Math.Max(0,s - sOffset), Math.Max(0,v - vOffset));
            MaxHsv= new ZTHsvFloatColor(Math.Min(1, h + hOffset), Math.Min(1, s + sOffset), Math.Min(1, v + vOffset));
        }
        
 
        public ZTHsvFloatColor MinHsv { get; private set; }
 
        public ZTHsvFloatColor MaxHsv { get; private set; }
 
        public override bool Compare(byte r, byte g, byte b)
        {
            float h = 0, s = 0, v = 0;
            ColorUtils.RGBtoHSV(r, g, b, out h, out s, out v);
            if (h >= MinHsv.H && h <= MaxHsv.H &&
                s >= MinHsv.S && s <= MaxHsv.S &&
                v >= MinHsv.V && v <= MaxHsv.V)
            {
                return true;
            }
            return false;
        }
 
    }
}