PikalaxALT icon

rgbscan.py

PikalaxALT | PRO | 10/12/15 05:26:30 PM UTC | 0 ⭐ | 653 👁️ | Never ⏰ | []
Python |

730 B

|

None

|

0 👍

/

0 👎

from sys import argv
 
def convert_bytes_to_rgb(hexword):
    """
    :param hexword: dw written as big endian
    
    :output: tuple of RGB values between 0 and 31
    """
    if 0x8000 & hexword:
        raise ValueError("This is not an RGB value")
    red = (0x7c00 & hexword) >> 10
    green = (0x03e0 & hexword) >> 5
    blue = 0x001f & hexword
    return red, green, blue
 
def rgb_scan(file):
    readLines = open(file).readlines()
    for i, line in enumerate(readLines):
        if line[0] == '\t' and "$" in line:
            lineSplit = line.split("$")
            R, G, B = convert_bytes_to_rgb(int(lineSplit[1][:4], 16))
            readLines[i] = lineSplit[0] + "{}, {}, {}\n".format(R, G, B)
    open(file, 'w+').write("".join(readLines))
 
if __name__ == '__main__':
    rgb_scan(argv[1])

Comments