-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added poethepoet package to manage repetitive development tasks #304
Changes from all commits
dccfe92
a148d1d
a4ca983
01c3209
5e53d09
28a6cf0
895e62f
8a02cfa
4a2f3f0
f986ab1
ce4c028
5618d85
94291f2
a65142e
9419440
179c345
16cf12c
6336561
82ad974
7f6cc74
11d173a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,22 @@ | |
Color conversions between 24-bit-rgb888 and 16-bit-rgb565 | ||
""" | ||
|
||
from binascii import hexlify, unhexlify | ||
from binascii import unhexlify | ||
|
||
|
||
def rgb24_to_rgb16(rgb, big=False): | ||
""" | ||
convert 3 bytes of rgb888 into 2 bytes of rgb565 | ||
default to little-endian, so rgb565 becomes gbrg3553 | ||
convert 3 bytes of rgb888 into 2 bytes of rgb565 | ||
default to little-endian, so rgb565 becomes gbrg3553. | ||
|
||
:param rgb: bytes | ||
:param big: boolean flag to assert big or little-endian format | ||
:returns int | ||
""" | ||
|
||
# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @qlrd These are just helpers (scripts) to serve as a tool to do something not direct related to the Krux code (like creating values to put those on code, or to help with the build process). These scripts will not ship into the Krux device... I think if you really want to change this, you could use isinstance() without any problems. We already use it a lot on the code, see for example the file wallet.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this because pylint was warning |
||
# check if micropython support isinstance or typings | ||
# pylint: disable=unidiomatic-typecheck | ||
assert type(rgb) == bytes and len(rgb) == 3 | ||
|
||
# 5 significant bits of red shifted to far left | ||
|
@@ -25,12 +34,25 @@ def rgb24_to_rgb16(rgb, big=False): | |
|
||
def rgb16_to_rgb24(rgb, big=False): | ||
""" | ||
convert 2 bytes of rgb565 into 3 bytes of rgb888 | ||
default from little-endian, so rgb565 becomes gbrg3553 | ||
Convert 2 bytes of rgb565 into 3 bytes of rgb888 | ||
default from little-endian, so rgb565 becomes gbrg3553. | ||
|
||
:param rgb: bytes | ||
:param big: boolean flag to assert big or little-endian format | ||
:returns bytes in string format | ||
""" | ||
def maxv(number_of_bits): | ||
return (2 ** number_of_bits) -1 | ||
|
||
def maxv(number_of_bits): | ||
""" | ||
Return 2^number_of_bits - 1 | ||
|
||
:returns int | ||
""" | ||
return (2**number_of_bits) - 1 | ||
|
||
# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz see the comment above |
||
# check if micropython support isinstance or typings | ||
# pylint: disable=unidiomatic-typecheck | ||
assert type(rgb) == bytes and len(rgb) == 2 | ||
|
||
rgb_int = int.from_bytes(rgb, "big" if big else "little") | ||
|
@@ -44,20 +66,26 @@ def maxv(number_of_bits): | |
# right 5 bits of blue multiplied to fill 8 bit space | ||
blue = round((rgb_int & maxv(5)) * maxv(8) / maxv(5)) | ||
|
||
return b''.join([x.to_bytes(1, "big") for x in [red, green, blue]]) | ||
return b"".join([x.to_bytes(1, "big") for x in [red, green, blue]]) | ||
|
||
|
||
def main(*args): | ||
""" | ||
Main function to convert integer in bytes format | ||
|
||
:param *args: bytes in a 0x or integer format | ||
:returns bytes: the byte representation of color | ||
""" | ||
rgb = None | ||
|
||
if len(args) == 1: | ||
arg = args[0] | ||
if arg[:2] == "0x": | ||
rgb = unhexlify(arg[2:]) | ||
else: | ||
rgb = (abs(int(args[0])) % 65536).to_bytes(2, 'big') | ||
rgb = (abs(int(args[0])) % 65536).to_bytes(2, "big") | ||
else: | ||
rgb = b''.join([(abs(int(x)) % 256).to_bytes(1, 'big') for x in args]) | ||
rgb = b"".join([(abs(int(x)) % 256).to_bytes(1, "big") for x in args]) | ||
|
||
if rgb: | ||
if len(rgb) == 2: | ||
|
@@ -67,21 +95,35 @@ def main(*args): | |
else: | ||
answer = None | ||
|
||
return(answer) | ||
return answer | ||
|
||
|
||
if __name__ == '__main__': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For those type of changes (from single quotes to double quotes), it is nice to read about it here. Basically I think we already uses single quotes for fixed small strings or constants, and double quotes to the other uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was |
||
if __name__ == "__main__": | ||
import sys | ||
|
||
def help(): | ||
# Do not name the function below `help` | ||
# it can throw a pylint warning | ||
# W0622: Redefining built-in 'help' (redefined-builtin) | ||
def rgb_convert_help(): | ||
""" | ||
Simple print help | ||
""" | ||
print("syntax: {} integer-bytes-or-0xhex-color".format(sys.argv[0])) | ||
|
||
if len(sys.argv) > 1: | ||
try: | ||
print('0x' + main(*sys.argv[1:]).hex()) | ||
print("0x" + main(*sys.argv[1:]).hex()) | ||
except: | ||
help() | ||
rgb_convert_help() | ||
|
||
# TODO: this throw a pylint warn R1722: Consider using 'sys.exit'instead | ||
# check if if in micropython is better to call sys.exit | ||
# pylint: disable=consider-using-sys-exit | ||
exit(1) | ||
else: | ||
help() | ||
|
||
# TODO: this throw a pylint warn R1722: Consider using 'sys.exit'instead | ||
# check if if in micropython is better to call sys.exit | ||
# pylint: disable=consider-using-sys-exit | ||
exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is self explanatory I think, it minifies the files passed as arguments. The output is the file minified (without extra new lines or code comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i wanted more details how this is done (and projected it), sorry