Skip to content

Commit

Permalink
🚧(icu_lib): add support for lvgl v8 format
Browse files Browse the repository at this point in the history
  • Loading branch information
W-Mai committed Mar 5, 2024
1 parent 1848526 commit 6b4c126
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 80 deletions.
1 change: 1 addition & 0 deletions icu_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license = "MIT"
bench = false

[dependencies]
modular-bitfield = "0.11.2"
image = "0.24.8"
color_quant = "1.1.0"
log = "0.4.20"
Expand Down
35 changes: 17 additions & 18 deletions icu_lib/src/endecoder/lvgl_v9/lvgl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::endecoder::lvgl_v9::color_converter::{rgba8888_from, rgba8888_to};
use crate::endecoder::lvgl_v9::{ColorFormat, Flags, ImageDescriptor, ImageHeader, LVGL};
use crate::endecoder::lvgl_v9::{
ColorFormat, Flags, ImageDescriptor, ImageHeader, LVGLVersion, LVGL,
};
use crate::endecoder::{EnDecoder, ImageInfo};
use crate::midata::MiData;
use crate::EncoderParams;
Expand All @@ -16,11 +18,7 @@ impl EnDecoder for LVGL {
let header_data = &data[..header_size];

let header = ImageHeader::decode(Vec::from(header_data));
if header.magic != 0x19 && header.cf != ColorFormat::UNKNOWN {
return false;
}

true
header.version != LVGLVersion::Unknown
}

fn encode(&self, data: &MiData, encoder_params: EncoderParams) -> Vec<u8> {
Expand All @@ -42,6 +40,7 @@ impl EnDecoder for LVGL {
buf.write_all(
&ImageDescriptor::new(
ImageHeader::new(
encoder_params.lvgl_version,
color_format,
Flags::NONE,
img.width() as u16,
Expand All @@ -64,22 +63,22 @@ impl EnDecoder for LVGL {
log::trace!("Decoding image with data size: {}", data.len());
let img_desc = ImageDescriptor::decode(data);

let header = &img_desc.header;
let header = &img_desc.header.header;

log::trace!("Decoding image with color format: {:?}", header.cf);
log::trace!("Decoding image with color format: {:?}", header.cf());
log::trace!("Decoded image header: {:#?}", img_desc.header);
log::trace!("Converting image data to RGBA");

// Convert image data to RGBA
let img_buffer = RgbaImage::from_vec(
img_desc.header.w as u32,
img_desc.header.h as u32,
header.w() as u32,
header.h() as u32,
rgba8888_from(
img_desc.data.clone().as_mut(),
header.cf,
header.w as u32,
header.h as u32,
header.stride as u32,
header.cf(),
header.w() as u32,
header.h() as u32,
header.stride() as u32,
),
)
.unwrap();
Expand All @@ -100,13 +99,13 @@ impl EnDecoder for LVGL {

let header_data = &data[..header_size];

let header = ImageHeader::decode(Vec::from(header_data));
let header = ImageHeader::decode(Vec::from(header_data)).header;

ImageInfo {
width: header.w as u32,
height: header.h as u32,
width: header.w() as u32,
height: header.h() as u32,
data_size: data.len() as u32,
format: format!("LVGL.V9({:?})", header.cf),
format: format!("LVGL.V9({:?})", header.cf()),
other_info: Default::default(),
}
}
Expand Down
Loading

0 comments on commit 6b4c126

Please sign in to comment.