Coverage for pyguymer3/image/rgb2hlsComp.py: 9%

11 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-16 08:31 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def rgb2hlsComp(r, g, b, /): 

5 """ 

6 This function returns the HLS complementary colour of an RGB triplet. 

7 """ 

8 

9 # Import standard modules ... 

10 import colorsys 

11 

12 # Convert the RGB triplet to an HLS triplet ... 

13 h, l, s = colorsys.rgb_to_hls( 

14 float(r) / 255.0, 

15 float(g) / 255.0, 

16 float(b) / 255.0, 

17 ) 

18 

19 # Convert the HLS triplet into its HLS complementary colour ... 

20 if h > 0.5: 

21 h -= 0.5 

22 else: 

23 h += 0.5 

24 

25 # Convert the HLS triplet to an RGB triplet ... 

26 tmpR, tmpG, tmpB = colorsys.hls_to_rgb(h, l, s) 

27 tmpR = round(tmpR * 255.0) 

28 tmpG = round(tmpG * 255.0) 

29 tmpB = round(tmpB * 255.0) 

30 

31 # Return answer ... 

32 return tmpR, tmpG, tmpB