1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

core/tools: fix style in toif_convert

This commit is contained in:
Pavol Rusnak 2019-06-09 19:04:10 +02:00
parent 9cb9653c27
commit b89134bf3f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -1,14 +1,14 @@
#!/usr/bin/env python3
from PIL import Image
import io
import sys
import struct
import sys
import zlib
from os.path import basename
from PIL import Image
def png2toif(input_data):
def process_rgb(w, h, pix):
data = bytes()
for j in range(h):
@ -85,9 +85,7 @@ def png2toif(input_data):
"""
def toif2png(data):
def process_rgb(w, h, data):
pix = bytearray(w * h * 3)
for i in range(w * h):
@ -97,7 +95,6 @@ def toif2png(data):
pix[i * 3 + 2] = (c & 0x001F) << 3
return bytes(pix)
def process_grayscale(w, h, data):
pix = bytearray(w * h)
for i in range(w * h // 2):
@ -117,7 +114,9 @@ def toif2png(data):
if format == "toif":
if len(data) != w * h * 2:
raise ValueError("Uncompressed data length mismatch (%d vs %d)" % (len(data), w * h * 2))
raise ValueError(
"Uncompressed data length mismatch (%d vs %d)" % (len(data), w * h * 2)
)
pix = process_rgb(w, h, data)
img = Image.frombuffer("RGB", (w, h), pix, "raw", "RGB", 0, 1)
ret = io.BytesIO()
@ -126,7 +125,9 @@ def toif2png(data):
if format == "toig":
if len(data) != w * h // 2:
raise ValueError("Uncompressed data length mismatch (%d vs %d)" % (len(data), w * h // 2))
raise ValueError(
"Uncompressed data length mismatch (%d vs %d)" % (len(data), w * h // 2)
)
pix = process_grayscale(w, h, data)
img = Image.frombuffer("L", (w, h), pix, "raw", "L", 0, 1)
ret = io.BytesIO()