달력

5

« 2024/5 »

  • 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

'Source'에 해당되는 글 1

  1. 2009.11.16 [Delphi] How to Convert RGB Color to HSB (HSV) Color
2009. 11. 16. 00:38

[Delphi] How to Convert RGB Color to HSB (HSV) Color 작업2009. 11. 16. 00:38

출처 : 초모룽마... | 초모룽마 http://blog.naver.com/chomorungma/70003686178

The HSV (Hue, Saturation, Value) model, also called HSB (Hue, Saturation, Brightness), defines a color space commonly used in graphics applications. Hue value ranges from 0 to 360, Saturation and Brightness values range from 0 to 100%. The RGB (Red, Green, Blue) is also used, primarily in web design. When written, RGB values are commonly specified using three integers between 0 and 255, each representing red, green, and blue intensities. Here's a function to convert a RGB color to a HSV color.

uses Math;
type TRGBColor = record Red, Green, Blue : Byte; end;

THSBColor = record Hue, Saturnation, Brightness : Double;
end;

function RGBToHSB(rgb : TRGBColor) : THSBColor;
var minRGB, maxRGB, delta : Double; h , s , b : Double ;
begin
H := 0.0 ;
minRGB := Min(Min(rgb.Red, rgb.Green), rgb.Blue) ;
maxRGB := Max(Max(rgb.Red, rgb.Green), rgb.Blue) ;
delta := ( maxRGB - minRGB ) ;

b := maxRGB ;

if (maxRGB <> 0.0) then
s := 255.0 * Delta / maxRGB
else s := 0.0;

if (s <> 0.0) then
begin
if rgb.Red = maxRGB then
h := (rgb.Green - rgb.Blue) / Delta
else if rgb.Green = minRGB then
h := 2.0 + (rgb.Blue - rgb.Red) / Delta
else if rgb.Blue = maxRGB then
h := 4.0 + (rgb.Red - rgb.Green) / Delta
end
else h := -1.0; h := h * 60 ;

if h < 0.0 then h := h + 360.0;

with result do
begin
Hue := h; Saturnation := s * 100 / 255;
Brightness := b * 100 / 255;
end;
end;
:
Posted by 해타리