diff --git a/icu_lib/src/endecoder/lvgl/mod.rs b/icu_lib/src/endecoder/lvgl/mod.rs index a210f2e..68af7a9 100644 --- a/icu_lib/src/endecoder/lvgl/mod.rs +++ b/icu_lib/src/endecoder/lvgl/mod.rs @@ -77,9 +77,10 @@ pub enum Flags { #[derive(BitfieldSpecifier)] #[bits = 4] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, Default)] #[repr(u8)] pub enum Compress { + #[default] NONE = 0, RLE = 1, // LVGL custom RLE compression LZ4 = 2, @@ -89,10 +90,10 @@ pub enum Compress { #[derive(Debug, Copy, Clone)] #[repr(C, packed)] struct ImageCompressedHeader { - method: Compress, /*Compression method, see `lv_image_compress_t`*/ - + method: Compress, /*Compression method, see `lv_image_compress_t`*/ + #[allow(unused)] - reserved: B28, /*Reserved to be used later*/ + reserved: B28, /*Reserved to be used later*/ compressed_size: u32, /*Compressed data size in byte*/ decompressed_size: u32, /*Decompressed data size in byte*/ } diff --git a/icu_lib/src/lib.rs b/icu_lib/src/lib.rs index 0130364..64c3f8a 100644 --- a/icu_lib/src/lib.rs +++ b/icu_lib/src/lib.rs @@ -7,6 +7,7 @@ pub struct EncoderParams { pub color_format: lvgl::ColorFormat, pub stride_align: u32, pub dither: Option, + pub compress: lvgl::Compress, pub lvgl_version: lvgl::LVGLVersion, } @@ -16,6 +17,7 @@ impl Default for EncoderParams { color_format: Default::default(), stride_align: 1, dither: None, + compress: Default::default(), lvgl_version: lvgl::LVGLVersion::Unknown, } } @@ -41,6 +43,11 @@ impl EncoderParams { self } + pub fn with_compress(mut self, compress: lvgl::Compress) -> Self { + self.compress = compress; + self + } + pub fn with_lvgl_version(mut self, lvgl_version: lvgl::LVGLVersion) -> Self { self.lvgl_version = lvgl_version; self diff --git a/src/arguments.rs b/src/arguments.rs index 24fddc3..a47ed91 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -78,6 +78,14 @@ pub(crate) enum OutputColorFormats { I8, } +#[allow(non_camel_case_types)] +#[derive(Debug, Clone, Copy, PartialOrd, PartialEq, ValueEnum)] +pub(crate) enum OutputCompressedMethod { + None, + RLE, + LZ4, +} + impl ImageFormats { pub fn get_endecoder(&self) -> &dyn EnDecoder { match &self { @@ -144,6 +152,16 @@ impl From for lvgl::LVGLVersion { } } +impl From for lvgl::Compress { + fn from(compressed_method: OutputCompressedMethod) -> Self { + match compressed_method { + OutputCompressedMethod::None => lvgl::Compress::NONE, + OutputCompressedMethod::RLE => lvgl::Compress::RLE, + OutputCompressedMethod::LZ4 => lvgl::Compress::LZ4, + } + } +} + #[derive(Parser, Debug)] #[command(author, version, long_about)] #[command( @@ -221,6 +239,9 @@ pub(crate) enum SubCommands { #[arg(short = 'C', long, value_enum)] output_color_format: Option, + #[arg(long, value_enum)] + output_compressed_method: Option, + /// dither the output image so that it will look better on screens with low color depth /// 1 to 30, 1 is the best quality and 30 is the worst quality. /// 10 is recommended. diff --git a/src/main.rs b/src/main.rs index 8416d1f..747faec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,6 +60,7 @@ fn process() -> Result<(), Box> { output_format, output_stride_align, output_color_format, + output_compressed_method, dither, lvgl_version, } => { @@ -121,6 +122,11 @@ fn process() -> Result<(), Box> { .with_color_format( (*output_color_format).map(|f| f.into()).unwrap_or_default(), ) + .with_compress( + (*output_compressed_method) + .map(|t| t.into()) + .unwrap_or_default(), + ) .with_lvgl_version((*lvgl_version).into()); let data = fs::read(&file_path)?;