Skip to content

Commit

Permalink
💪(icu_lib and main): add support for output compression methods
Browse files Browse the repository at this point in the history
Added a new `output_compressed_method` field to the configuration, allowing users to specify the compression method for output. Updated the `ImageCompressedHeader` and related structures to include and handle the new compression options.

Signed-off-by: Benign X <1341398182@qq.com>
  • Loading branch information
W-Mai committed Nov 26, 2024
1 parent d710a94 commit 5dd7270
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
9 changes: 5 additions & 4 deletions icu_lib/src/endecoder/lvgl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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*/
}
Expand Down
7 changes: 7 additions & 0 deletions icu_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct EncoderParams {
pub color_format: lvgl::ColorFormat,
pub stride_align: u32,
pub dither: Option<u32>,
pub compress: lvgl::Compress,
pub lvgl_version: lvgl::LVGLVersion,
}

Expand All @@ -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,
}
}
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -144,6 +152,16 @@ impl From<LVGL_Version> for lvgl::LVGLVersion {
}
}

impl From<OutputCompressedMethod> 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(
Expand Down Expand Up @@ -221,6 +239,9 @@ pub(crate) enum SubCommands {
#[arg(short = 'C', long, value_enum)]
output_color_format: Option<OutputColorFormats>,

#[arg(long, value_enum)]
output_compressed_method: Option<OutputCompressedMethod>,

/// 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.
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn process() -> Result<(), Box<dyn std::error::Error>> {
output_format,
output_stride_align,
output_color_format,
output_compressed_method,
dither,
lvgl_version,
} => {
Expand Down Expand Up @@ -121,6 +122,11 @@ fn process() -> Result<(), Box<dyn std::error::Error>> {
.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)?;
Expand Down

0 comments on commit 5dd7270

Please sign in to comment.