Skip to content

Commit

Permalink
chore: 🤖 utilize ABGR8888S color space for web (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf authored Mar 18, 2024
1 parent 136b505 commit 608f606
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions dotlottie-rs/src/lottie_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl LottieRenderer {
self.width,
self.width,
self.height,
TvgColorspace::ABGR8888,
get_color_space_for_target(),
)
.map_err(LottieRendererError::ThorvgError)?;

Expand Down Expand Up @@ -184,7 +184,7 @@ impl LottieRenderer {
self.width,
self.width,
self.height,
TvgColorspace::ABGR8888,
get_color_space_for_target(),
)
.map_err(LottieRendererError::ThorvgError)?;

Expand Down Expand Up @@ -269,3 +269,16 @@ fn hex_to_rgba(hex_color: u32) -> (u8, u8, u8, u8) {

(red, green, blue, alpha)
}

#[inline]
fn get_color_space_for_target() -> TvgColorspace {
#[cfg(target_arch = "wasm32")]
{
TvgColorspace::ABGR8888S
}

#[cfg(not(target_arch = "wasm32"))]
{
TvgColorspace::ABGR8888
}
}
4 changes: 4 additions & 0 deletions dotlottie-rs/src/thorvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub enum TvgEngine {

pub enum TvgColorspace {
ABGR8888,
ABGR8888S,
ARGB8888,
ARGB8888S,
}

fn convert_tvg_result(result: Tvg_Result, function_name: &str) -> Result<(), TvgError> {
Expand Down Expand Up @@ -99,7 +101,9 @@ impl Canvas {
) -> Result<(), TvgError> {
let color_space = match color_space {
TvgColorspace::ABGR8888 => Tvg_Colorspace_TVG_COLORSPACE_ABGR8888,
TvgColorspace::ABGR8888S => Tvg_Colorspace_TVG_COLORSPACE_ABGR8888S,
TvgColorspace::ARGB8888 => Tvg_Colorspace_TVG_COLORSPACE_ARGB8888,
TvgColorspace::ARGB8888S => Tvg_Colorspace_TVG_COLORSPACE_ARGB8888S,
};

let result = unsafe {
Expand Down

0 comments on commit 608f606

Please sign in to comment.