1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-10 19:20:13 +00:00
oot/tools/rgba5551.py
fig02 24ab14f748
Change Colors To Decimal (#260)
* fix colliderinit typo

* convert as many colors i can find to decimal

* fix GPACK_RGBA5551, merge fhgFire

* fix remaining colors

* remove unwanted file

* alpha as 1
2020-07-16 21:37:53 -04:00

32 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
def decode_rgba5551(short, max=False):
red = (short & 0xF800) >> 8
green = (short & 0x07C0) >> 3
blue = (short & 0x003E) << 2
alpha = 1 if (short % 2) else 0
if max:
red |= red >> 5
green |= green >> 5
blue |= blue >> 5
return (red, green, blue, alpha)
def u16(x):
x = int(x, 16)
if x > 0xFFFF:
raise argparse.ArgumentTypeError("expecting a short (u16) representing a single color.")
return x
def main():
parser = argparse.ArgumentParser(description="Decodes a color encoded in rgba5551.")
parser.add_argument("short", type=u16, help="u16 raw value of the color to decode")
args = parser.parse_args()
print("Min: GPACK_RGBA5551(%d, %d, %d, %d)" % decode_rgba5551(args.short, max=False))
print("Max: GPACK_RGBA5551(%d, %d, %d, %d)" % decode_rgba5551(args.short, max=True))
print("Note: All RGB values between these encode to the given value.")
print(" Use the representation that makes the most sense.\n")
if __name__ == "__main__":
main()