Skip to content

Commit

Permalink
Merge pull request #447 from LedgerHQ/abo_fix_icon2glyph
Browse files Browse the repository at this point in the history
Fix icon2glyph script
  • Loading branch information
abonnaudet-ledger authored Oct 12, 2023
2 parents 213f748 + 8d29c3b commit 5402367
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib_nbgl/tools/icon2glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ def image_to_packed_buffer(img, bpp: int):
# Compressions functions


def rle_compress(im: Image, bpp) -> bytes:
def rle_compress(im: Image, bpp) -> Optional[bytes]:
"""
Run RLE compression on input image
"""
if bpp == 1:
return Rle1bpp.rle_1bpp(im)[1]
elif bpp == 2:
# No compression supports BPP2
return None
elif bpp == 4:
return Rle4bpp.rle_4bpp(im)[1]
Expand Down Expand Up @@ -167,6 +168,9 @@ def compress(im: Image, bpp) -> Tuple[NbglFileCompression, bytes]:
min_comp = NbglFileCompression.NoCompression

for compression, buffer in compressed_bufs.items():
if buffer is None:
continue

final_length = len(buffer)
if compression != NbglFileCompression.NoCompression:
final_length += NBGL_IMAGE_FILE_HEADER_SIZE
Expand Down Expand Up @@ -341,7 +345,7 @@ def main():

except Exception as e:
sys.stderr.write(
"Exception while processing {} {}\n".format(file), e)
"Exception while processing {}: {}\n".format(file, e))
try:
traceback.print_tb()
except:
Expand Down
4 changes: 2 additions & 2 deletions lib_nbgl/tools/nbgl_rle.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def occurrences_to_rle(cls, occurrences: Tuple[int, int], bpp: int) -> bytes:
return result

@classmethod
def rle_4bpp(cls, img) -> bytes:
def rle_4bpp(cls, img) -> Tuple[int, bytes]:
bpp = 4
pixels = cls.image_to_pixels(img, bpp)
occurrences = cls.pixels_to_occurrences(pixels)
Expand Down Expand Up @@ -314,7 +314,7 @@ def decode_pass2(cls, data):

# -------------------------------------------------------------------------
@classmethod
def rle_1bpp(cls, img) -> bytes:
def rle_1bpp(cls, img) -> Tuple[int, bytes]:
"""
Input: image to compress
- convert the picture to an array of pixels
Expand Down

0 comments on commit 5402367

Please sign in to comment.