File size: 1,600 Bytes
c336648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import glob
import os


def format_time(seconds):
    hours, remainder = divmod(seconds, 3600)
    minutes, seconds = divmod(remainder, 60)
    return f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}"


def file_count(target, suffix="*.png"):
    pattern = os.path.join(target, suffix)
    files = glob.glob(pattern)
    return len(files)


def str_exist(s):
    s = s.strip()
    return s is not None and len(s) > 0


def color_string_to_tuple(c_str):
    r = 0
    g = 0
    b = 0
    a = 0
    if c_str is None or len(c_str) == 0:
        return a, g, b, a

    c_str = c_str.lower()

    if c_str[0] == '#':
        if len(c_str) >= 7:
            r = int(c_str[1:3], 16)  # Extract and convert the red component
            g = int(c_str[3:5], 16)  # Extract and convert the green component
            b = int(c_str[5:7], 16)  # Extract and convert the blue component

        if len(c_str) >= 9:
            a = int(c_str[7:9], 16)  # Extract and convert the alpha component
        else:
            a = 255
        return r, g, b, a

    if c_str[0] == 'r':
        c_str = (c_str
                 .replace('rgba', '').replace('rgb', '')
                 .replace('(', '').replace(')', ''))

    color_values = c_str.strip().split(",")
    color_values = [int(value) for value in color_values]

    if len(color_values) < 3:
        raise ValueError(f"Invalid color string: {c_str}")

    if len(color_values) >= 3:
        r, b, g = color_values[0], color_values[1], color_values[2]
        a = 255

    if len(color_values) >= 4:
        a = color_values[3]

    return r, g, b, a