1mlib_ImageColorRGB2HSL(3MLImBe)diaLib Library Functiomnlsib_ImageColorRGB2HSL(3MLIB)
2
3
4
6 mlib_ImageColorRGB2HSL - RGB to HSL color conversion
7
9 cc [ flag... ] file... -lmlib [ library... ]
10 #include <mlib.h>
11
12 mlib_status mlib_ImageColorRGB2HSL(mlib_image *dst, const mlib_image *src);
13
14
16 The mlib_ImageColorRGB2HSL() function performs a conversion from
17 red/green/blue to hue/saturation/lightness. The source and destination
18 images must be three-channel images.
19
20
21 It uses the following equations:
22
23 V = max(R, G, B)
24 Vmin = min(R, G, B)
25
26 L = (V + Vmin)/2
27
28 S = (V - Vmin)/(V + Vmin) if L ≤ 1/2
29 S = (V - Vmin)/(2 - V - Vmin) if L > 1/2
30
31 H = (5.0 + (V - B)/(V - Vmin))/6 if R = V and G = Vmin
32 H = (1.0 - (V - G)/(V - Vmin))/6 if R = V and B = Vmin
33 H = (1.0 + (V - R)/(V - Vmin))/6 if G = V and B = Vmin
34 H = (3.0 - (V - B)/(V - Vmin))/6 if G = V and R = Vmin
35 H = (3.0 + (V - G)/(V - Vmin))/6 if B = V and R = Vmin
36 H = (5.0 - (V - R)/(V - Vmin))/6 if B = V and G = Vmin
37 H = 0.0 if R = G = B
38
39
40
41 where 0 ≤ R, G, B, V, Vmin, L, S ≤ 1 and 0 ≤ H < 1.
42
43
44 Assuming a pixel in the source image is (r, g, b) and its corresponding
45 pixel in the destination image is (h, s, l), then for MLIB_BYTE images,
46 the following applies:
47
48 R = r/255
49 G = g/255
50 B = b/255
51 h = H*256
52 s = S*255
53 l = L*255
54
55
56
57 for MLIB_SHORT images, the following applies:
58
59 R = (r + 32768)/65535
60 G = (g + 32768)/65535
61 B = (b + 32768)/65535
62 h = H*65536 - 32768
63 s = S*65535 - 32768
64 l = L*65535 - 32768
65
66
67
68 for MLIB_USHORT images, the following applies:
69
70 R = r/65535
71 G = g/65535
72 B = b/65535
73 h = H*65536
74 s = S*65535
75 l = L*65535
76
77
78
79 and for MLIB_INT images, the following applies:
80
81 R = (r + 2147483648)/4294967295
82 G = (g + 2147483648)/4294967295
83 B = (b + 2147483648)/4294967295
84 h = H*4294967296 - 2147483648
85 s = S*4294967295 - 2147483648
86 l = L*4294967295 - 2147483648
87
88
90 The function takes the following arguments:
91
92 dst Pointer to destination image.
93
94
95 src Pointer to source image.
96
97
99 The function returns MLIB_SUCCESS if successful. Otherwise it returns
100 MLIB_FAILURE.
101
103 See attributes(5) for descriptions of the following attributes:
104
105
106
107
108 ┌─────────────────────────────┬─────────────────────────────┐
109 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
110 ├─────────────────────────────┼─────────────────────────────┤
111 │Interface Stability │Committed │
112 ├─────────────────────────────┼─────────────────────────────┤
113 │MT-Level │MT-Safe │
114 └─────────────────────────────┴─────────────────────────────┘
115
117 mlib_ImageColorHSL2RGB(3MLIB), mlib_ImageColorHSL2RGB_Fp(3MLIB),
118 mlib_ImageColorRGB2HSL_Fp(3MLIB), attributes(5)
119
120
121
122SunOS 5.11 2 Mar 2007 mlib_ImageColorRGB2HSL(3MLIB)