Перевести из RGB в HSV

type 
  TRGB = array [0..2] of byte;
  THSV = record
           H : 0..360;
           S : 0..100;
           V : 0..100;
         end;



function RGBToHSV(const RGB: TRGB):THSV;
var
  Min, Max: Integer;
  Range: Byte;
  i: Integer;

  function GetH(h: integer): integer;
  begin
    if h<0 then result := h+360
           else result := h;
  end;

begin
  Min := 256;
  Max :=  -1;
  for i := Low(RGB) to High(RGB) do
  begin
    if RGB[i] < Min then Min := RGB[i];
    if RGB[i] > Max then Max := RGB[i];
  end;

  Range := Max - Min;

  if Range = 0 then
  begin
    result.H := 0; 
    result.S := 0; 
    result.V := round(RGB[0]/255*100); 
  end
    else
  begin
    if Max = RGB[0] then result.H := GetH(round((Integer(RGB[1])-RGB[2])/Range * 60))
      else if Max = RGB[1] then result.H := GetH(round(((Integer(RGB[2])-RGB[0])/Range +2) * 60))
        else if Max = RGB[2] then result.H := GetH(round(((Integer(RGB[0])-RGB[1])/Range +4)* 60));

    result.S := round(Range / Max * 100);
    result.V := round(Max / 255 * 100);
  end;
end;