chore(LVGLImage): triple double-quoted strings should be used for docstrings (#5373)

This commit is contained in:
Benign X
2024-01-18 16:24:07 +08:00
committed by GitHub
parent dd42600e24
commit c2707d3fca
+29 -28
View File
@@ -54,22 +54,22 @@ class Error(Exception):
class FormatError(Error): class FormatError(Error):
''' """
Problem with input filename format. Problem with input filename format.
BIN filename does not conform to standard lvgl bin image format BIN filename does not conform to standard lvgl bin image format
''' """
class ParameterError(Error): class ParameterError(Error):
''' """
Parameter for LVGL image not correct Parameter for LVGL image not correct
''' """
class PngQuant: class PngQuant:
''' """
Compress PNG file to 8bit mode using `pngquant` Compress PNG file to 8bit mode using `pngquant`
''' """
def __init__(self, ncolors=256, dither=True, exec_path="") -> None: def __init__(self, ncolors=256, dither=True, exec_path="") -> None:
executable = path.join(exec_path, "pngquant") executable = path.join(exec_path, "pngquant")
@@ -123,9 +123,9 @@ class ColorFormat(Enum):
@property @property
def bpp(self) -> int: def bpp(self) -> int:
''' """
Return bit per pixel for this cf Return bit per pixel for this cf
''' """
cf_map = { cf_map = {
ColorFormat.UNKNOWN: 0x00, ColorFormat.UNKNOWN: 0x00,
ColorFormat.L8: 8, ColorFormat.L8: 8,
@@ -150,9 +150,10 @@ class ColorFormat(Enum):
@property @property
def ncolors(self) -> int: def ncolors(self) -> int:
''' """
Return number of colors in palette if cf is indexed1/2/4/8. Return number of colors in palette if cf is indexed1/2/4/8.
Return zero if cf is not indexed format ''' Return zero if cf is not indexed format
"""
cf_map = { cf_map = {
ColorFormat.I1: 2, ColorFormat.I1: 2,
@@ -164,9 +165,9 @@ class ColorFormat(Enum):
@property @property
def is_indexed(self) -> bool: def is_indexed(self) -> bool:
''' """
Return if cf is indexed color format Return if cf is indexed color format
''' """
return self.ncolors != 0 return self.ncolors != 0
@property @property
@@ -195,10 +196,10 @@ class ColorFormat(Enum):
def unpack_colors(data: bytes, cf: ColorFormat, w) -> List: def unpack_colors(data: bytes, cf: ColorFormat, w) -> List:
''' """
Unpack lvgl 1/2/4/8/16/32 bpp color to png color: alpha map, grey scale, Unpack lvgl 1/2/4/8/16/32 bpp color to png color: alpha map, grey scale,
or R,G,B,(A) map or R,G,B,(A) map
''' """
ret = [] ret = []
bpp = cf.bpp bpp = cf.bpp
if bpp == 8: if bpp == 8:
@@ -401,9 +402,9 @@ class LVGLImage:
f" (12+{self.data_len})Byte'") f" (12+{self.data_len})Byte'")
def adjust_stride(self, stride: int = 0, align: int = 1): def adjust_stride(self, stride: int = 0, align: int = 1):
''' """
Stride can be set directly, or by stride alignment in bytes Stride can be set directly, or by stride alignment in bytes
''' """
if self.stride == 0: if self.stride == 0:
# stride can only be 0, when LVGLImage is created with empty data # stride can only be 0, when LVGLImage is created with empty data
logging.warning("Cannot adjust stride for empty image") logging.warning("Cannot adjust stride for empty image")
@@ -469,9 +470,9 @@ class LVGLImage:
@property @property
def data_len(self) -> int: def data_len(self) -> int:
''' """
Return data_len in byte of this image, excluding image header Return data_len in byte of this image, excluding image header
''' """
# palette is always in ARGB format, 4Byte per color # palette is always in ARGB format, 4Byte per color
p = self.cf.ncolors * 4 if self.is_indexed and self.w * self.h else 0 p = self.cf.ncolors * 4 if self.is_indexed and self.w * self.h else 0
@@ -494,9 +495,9 @@ class LVGLImage:
h: int, h: int,
data: bytes, data: bytes,
stride: int = 0): stride: int = 0):
''' """
Directly set LVGL image parameters Directly set LVGL image parameters
''' """
if w > 0xffff or h > 0xffff: if w > 0xffff or h > 0xffff:
raise ParameterError(f"w, h overflow: {w}x{h}") raise ParameterError(f"w, h overflow: {w}x{h}")
@@ -523,9 +524,9 @@ class LVGLImage:
data[len(header.binary):], header.stride) data[len(header.binary):], header.stride)
def from_bin(self, filename: str): def from_bin(self, filename: str):
''' """
Read from existing bin file and update image parameters Read from existing bin file and update image parameters
''' """
if not filename.endswith(".bin"): if not filename.endswith(".bin"):
raise FormatError("filename not ended with '.bin'") raise FormatError("filename not ended with '.bin'")
@@ -547,9 +548,9 @@ class LVGLImage:
def to_bin(self, def to_bin(self,
filename: str, filename: str,
compress: CompressMethod = CompressMethod.NONE): compress: CompressMethod = CompressMethod.NONE):
''' """
Write this image to file, filename should be ended with '.bin' Write this image to file, filename should be ended with '.bin'
''' """
self._check_ext(filename, ".bin") self._check_ext(filename, ".bin")
self._check_dir(filename) self._check_dir(filename)
@@ -704,10 +705,10 @@ const lv_img_dsc_t {varname} = {{
filename: str, filename: str,
cf: ColorFormat = None, cf: ColorFormat = None,
background: int = 0x00_00_00): background: int = 0x00_00_00):
''' """
Create lvgl image from png file. Create lvgl image from png file.
If cf is none, used I1/2/4/8 based on palette size If cf is none, used I1/2/4/8 based on palette size
''' """
self.background = background self.background = background
@@ -897,9 +898,9 @@ class RLEImage(LVGLImage):
super().__init__(cf, w, h, data) super().__init__(cf, w, h, data)
def to_rle(self, filename: str): def to_rle(self, filename: str):
''' """
Compress this image to file, filename should be ended with '.rle' Compress this image to file, filename should be ended with '.rle'
''' """
self._check_ext(filename, ".rle") self._check_ext(filename, ".rle")
self._check_dir(filename) self._check_dir(filename)