Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add telegram skin recolor #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rlottie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version = "1.60"

[features]
serde = ["dep:serde", "rgb/serde"]
telegrand = []

[dependencies]
rgb = { version = "0.8.32", default-features = false }
Expand Down
40 changes: 40 additions & 0 deletions rlottie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,46 @@ impl Animation {
Self::from_ptr(ptr)
}

/// Constructs an animation object from JSON string data. External resources are
/// resolved relative to `resource_path`.
///
///
///
/// Note that the `cache_key` might be used by the rlottie library to cache the
/// json data and/or its resources.
///
/// This method will panic if json_data or cache_key contain nul bytes. or fitzpatrick_type not in range 0..=6
#[cfg(feature = "telegrand")]
pub fn from_data_recolored<D, K, P>(
json_data: D,
cache_key: K,
resource_path: P,
fitzpatrick_type: i32
) -> Option<Self>
where
D: Into<Vec<u8>>,
K: Into<Vec<u8>>,
P: AsRef<Path>
{
assert!(
(0 ..= 6).contains(&fitzpatrick_type),
"fitzpatrick_type must be in range 0..=6"
);
let json_data =
CString::new(json_data).expect("json_data must not contain nul");
let cache_key = CString::new(cache_key).expect("key must not contain nul");
let resource_path = path_to_cstr(resource_path);
let ptr = unsafe {
lottie_animation_from_data_recolored(
json_data.as_ptr(),
cache_key.as_ptr(),
resource_path.as_ptr(),
fitzpatrick_type
)
};
Self::from_ptr(ptr)
}

/// Return the default viewport size of this animation.
pub fn size(&self) -> Size {
let mut size = Size {
Expand Down