Lines Matching refs:cf

212 def unpack_colors(data: bytes, cf: ColorFormat, w) -> List:
218 bpp = cf.bpp
222 if cf == ColorFormat.A4:
234 if cf == ColorFormat.A2:
244 if cf == ColorFormat.A1:
263 if cf == ColorFormat.RGB888:
269 elif cf == ColorFormat.RGB565A8:
281 elif cf == ColorFormat.ARGB8565:
309 cf: ColorFormat,
379 ncolors = cf.ncolors
391 cf: ColorFormat = ColorFormat.UNKNOWN,
397 self.cf = cf
424 return (self.w * self.cf.bpp + 7) // 8
430 binary += uint8_t(self.cf.value)
445 self.cf = ColorFormat(data[1] & 0x1f) # color format
457 cf: ColorFormat,
460 self.blk_size = (cf.bpp + 7) // 8
494 cf: ColorFormat = ColorFormat.UNKNOWN,
501 self.set_data(cf, w, h, data)
520 header = LVGLImageHeader(self.cf, self.w, self.h, align=align)
536 current = LVGLImageHeader(self.cf, self.w, self.h, stride=self.stride)
558 palette_size = self.cf.ncolors * 4
565 if self.cf == ColorFormat.RGB565A8:
583 if not self.cf.has_alpha:
586 if self.cf.is_indexed:
593 palette_size = self.cf.ncolors * 4
601 elif self.cf is ColorFormat.ARGB8888:
617 elif self.cf is ColorFormat.RGB565A8:
642 elif self.cf is ColorFormat.ARGB8565:
674 p = self.cf.ncolors * 4 if self.is_indexed and self.w * self.h else 0
676 if self.cf is ColorFormat.RGB565A8:
683 return LVGLImageHeader(self.cf, self.w, self.h)
687 return self.cf.is_indexed
690 cf: ColorFormat,
702 self.cf = cf
708 self.stride = LVGLImageHeader(cf, w, h, stride, align=1).stride
720 return self.set_data(header.cf, header.w, header.h,
760 header = LVGLImageHeader(self.cf,
766 compressed = LVGLCompressData(self.cf, compress, self.data)
780 data = LVGLCompressData(self.cf, compress, self.data).compressed
783 write_c_array_file(self.w, self.h, self.stride, self.cf, filename,
793 if self.cf.is_indexed:
799 data[i * 4 + 3]) for i in range(self.cf.ncolors)]
801 data = data[self.cf.ncolors * 4:]
806 bitdepth=self.cf.bpp)
808 data = unpack_colors(data, self.cf, self.w)
809 elif self.cf.is_alpha_only:
811 transparency = unpack_colors(self.data, self.cf, self.w)
816 elif self.cf == ColorFormat.L8:
820 bitdepth=self.cf.bpp,
824 elif self.cf.is_colormap:
827 alpha=self.cf.has_alpha,
829 data = unpack_colors(self.data, self.cf, self.w)
841 cf: ColorFormat = None,
852 if cf is None: # guess cf from filename
858 cf = ColorFormat[c]
861 if cf is None or cf.is_indexed: # palette mode
862 self._png_to_indexed(cf, filename)
863 elif cf.is_alpha_only:
864 self._png_to_alpha_only(cf, filename)
865 elif cf.is_luma_only:
866 self._png_to_luma_only(cf, filename)
867 elif cf.is_colormap:
868 self._png_to_colormap(cf, filename)
875 def _png_to_indexed(self, cf: ColorFormat, filename: str):
877 auto_cf = cf is None
885 if not 'palette' in metadata or not auto_cf and len(metadata['palette']) != 2 ** cf.bpp:
888 bytes=PngQuant(256 if auto_cf else cf.ncolors).convert(filename))
896 cf = ColorFormat.I1
898 cf = ColorFormat.I2
900 cf = ColorFormat.I4
902 cf = ColorFormat.I8
904 if palette_len != cf.ncolors:
909 palette += [(255, 255, 255, 0)] * (cf.ncolors - palette_len)
919 if cf == ColorFormat.I8:
923 for e in png.pack_rows(rows, cf.bpp):
926 self.set_data(cf, w, h, rawdata)
928 def _png_to_alpha_only(self, cf: ColorFormat, filename: str):
935 if cf == ColorFormat.A8:
941 shift = 8 - cf.bpp
942 mask = 2**cf.bpp - 1
944 for row in png.pack_rows(rows, cf.bpp):
947 self.set_data(cf, w, h, rawdata)
959 def _png_to_luma_only(self, cf: ColorFormat, filename: str):
978 def _png_to_colormap(self, cf, filename: str): argument
980 if cf == ColorFormat.ARGB8888:
984 elif cf == ColorFormat.XRGB8888:
989 elif cf == ColorFormat.RGB888:
994 elif cf == ColorFormat.RGB565:
1003 elif cf == ColorFormat.RGB565A8:
1010 elif cf == ColorFormat.ARGB8565:
1030 if cf == ColorFormat.RGB565A8:
1035 cf in (ColorFormat.RGB565, ColorFormat.RGB565A8, ColorFormat.ARGB8565)
1045 if cf == ColorFormat.RGB565A8:
1048 self.set_data(cf, w, h, rawdata)
1107 cf: ColorFormat = ColorFormat.UNKNOWN,
1111 super().__init__(cf, w, h, data)
1121 blksize = (self.cf.bpp + 7) // 8
1223 cf: ColorFormat = ColorFormat.UNKNOWN,
1225 self.cf = cf
1232 write_c_array_file(0, 0, 0, self.cf, filename,
1237 cf: ColorFormat = None):
1238 if cf not in RAWImage.CF_SUPPORTED:
1243 self.cf = cf
1257 cf: ColorFormat,
1267 self.cf = cf
1290 if self.cf in (ColorFormat.RAW, ColorFormat.RAW_ALPHA):
1292 img = RAWImage().from_file(f, self.cf)
1295 …img = LVGLImage().from_png(f, self.cf, background=self.background, rgb565_dither=self.rgb565_dithe…
1375 if args.cf == "AUTO":
1376 cf = None
1378 cf = ColorFormat[args.cf]
1380 ofmt = OutputFormat(args.ofmt) if cf not in (
1385 cf,
1405 cf=ColorFormat.ARGB8565,
1419 cf=ColorFormat.RAW_ALPHA)