Advertisement
PikalaxALT

rgbscan.py

Oct 12th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from sys import argv
  2.  
  3. def convert_bytes_to_rgb(hexword):
  4.     """
  5.     :param hexword: dw written as big endian
  6.    
  7.     :output: tuple of RGB values between 0 and 31
  8.     """
  9.     if 0x8000 & hexword:
  10.         raise ValueError("This is not an RGB value")
  11.     red = (0x7c00 & hexword) >> 10
  12.     green = (0x03e0 & hexword) >> 5
  13.     blue = 0x001f & hexword
  14.     return red, green, blue
  15.  
  16. def rgb_scan(file):
  17.     readLines = open(file).readlines()
  18.     for i, line in enumerate(readLines):
  19.         if line[0] == '\t' and "$" in line:
  20.             lineSplit = line.split("$")
  21.             R, G, B = convert_bytes_to_rgb(int(lineSplit[1][:4], 16))
  22.             readLines[i] = lineSplit[0] + "{}, {}, {}\n".format(R, G, B)
  23.     open(file, 'w+').write("".join(readLines))
  24.  
  25. if __name__ == '__main__':
  26.     rgb_scan(argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement