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

Add telegram skin recolor #31

wants to merge 2 commits into from

Conversation

yuraiz
Copy link
Contributor

@yuraiz yuraiz commented Oct 27, 2022

This PR implements Animation::from_data_tg function that takes FitzModifier (one of emoji skin tones) as last argument
image

@msrd0
Copy link
Owner

msrd0 commented Oct 27, 2022

Hm ... I don't like this. It makes claims about the internal structure of the C binding's struct - which has an additional field in the samsung version for example.

@msrd0 msrd0 linked an issue Oct 27, 2022 that may be closed by this pull request
@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 27, 2022

We need to use this struct only when telegram's version of library is used, so I think it's normal

also rust bindings uses only first field of this struct

// That works on my pc
struct Lottie_Animation_S {
    std::unique_ptr<Animation> mAnimation;
    // other values
};

Ofc I can make fork on teleram's rlottie and update c bindings but I don't know what repo use for pull request

@msrd0
Copy link
Owner

msrd0 commented Oct 27, 2022

also rust bindings uses only first field of this struct

Well, C++ is going to instantiate a struct with your definition and access and drop a struct with the rlottie libraries version. Given that the telegram version doesn't even do releases, and likely does not commit to keep that struct the same forever, this sounds like a bad idea.

Ofc I can make fork on teleram's rlottie and update c bindings but I don't know what repo use for pull request

It'd be best if you could get the folks at telegram to expose some C API in addition to what they currently have to change the skin tone. Not sure if that's something they're willing to do.

@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 27, 2022

If I understand correctly TelegramSwift also uses struct with only unique_ptr
https://github.com/overtake/TelegramSwift/blob/master/submodules/RLottie_Xcode/Sources/RLottieBridge.mm#L17=L21
but it doesn't use c bindings

@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 28, 2022

I suggest to use SkinTone enum like this, because not everyone knows about fitzpatrick skin type
Also I want to use custom enum instead of auto generated because it works better with code analysis and autocompletion

#[cfg(feature = "tg")]
pub enum SkinTone {
	None = 0,
	Light,
	MediumLight,
	Medium,
	MediumDark,
	Dark
}

#[cfg(feature = "tg")]
impl SkinTone {
	pub fn from_emoji_modifier(emoji_modifier: char) -> Self {
		match emoji_modifier {
			'\u{1F3FB}' => Self::Light,
			'\u{1F3FC}' => Self::MediumLight,
			'\u{1F3FD}' => Self::Medium,
			'\u{1F3FE}' => Self::MediumDark,
			'\u{1F3FF}' => Self::Dark,
			_ => Self::None
		}
	}
}

@msrd0
Copy link
Owner

msrd0 commented Oct 28, 2022

Yes, that sounds like a good API design. Maybe don't have a _ => Self::None case though as that implies that literally any char has a meaning? I wouldn't expect for an input like ✌a for a to be an skin tone modifier.

Also, I added a CI test for the telegram version of rlottie, please update this PR.

Regarding the C struct, I'm still not sure if I'm happy with that ...

@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 28, 2022

I wouldn't expect for an input like ✌a for a to be an skin tone modifier.

I want to put last char of my message text to get skin color

https://github.com/overtake/TelegramSwift/blob/13d62c1c03df7dea70bad0f395fb68115f5a0b43/Telegram-Mac/CoreExtension.swift#L426-L432

@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 28, 2022

Maybe I can use Option<SkinTone> instead

@yuraiz
Copy link
Contributor Author

yuraiz commented Oct 28, 2022

Lol, I already have fitzpatrick_type in Animated emoji

image

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 26, 2023

We with @melix99 decided keeping a fork
so I'll extend c binidgs in that fork with requred methods later

https://github.com/melix99/rlottie

it requires telegand's fork of rlottie
@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 27, 2023

That works, but I haven't published my rlottie changes yet

image

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 27, 2023

I made fitzpatrick_type of type i32 'cause that type is used in tdlib-rs

@msrd0
Copy link
Owner

msrd0 commented Mar 28, 2023

Sorry for the delay on this PR.

Is your intention to merge the changes on your fork into the telegram rlottie library? I really don't think it would be a good idea to have a 3rd version of the rlottie library around ...

I made fitzpatrick_type of type i32 'cause that type is used in tdlib-rs

Sorry but that doesn't make any sense. It is an enum in the rlottie library so why wouldn't we just use that?

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 28, 2023

Sorry but that doesn't make any sense. It is an enum in the rlottie library so why wouldn't we just use that?

https://docs.rs/tdlib/latest/tdlib/types/struct.AnimatedEmoji.html#structfield.fitzpatrick_type

It will be easier to pass that variable without any conversions

@yuraiz yuraiz closed this Mar 28, 2023
@msrd0
Copy link
Owner

msrd0 commented Mar 28, 2023

Well, someone has to do the conversion, and I think it would make more sense for the rlottie binding to expose an API the way rlottie does it.

I think without any changes to the upstream rlottie library, it would make the most sense to, if some skin-recolor feature is enabled, use a small header and c++ file to expose the rlottie::FitzModifier enum and a method that allows passing it to rlottie::Animation::loadFromData.

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 28, 2023

Is your intention to merge the changes on your fork into the telegram rlottie library

TelegramMessenger/rlottie#4 haven't merged yet, also other telegram clients don't care about c bindings, telegram for macos also keeps its own fork

@yuraiz yuraiz reopened this Mar 28, 2023
@msrd0
Copy link
Owner

msrd0 commented Mar 28, 2023

TelegramMessenger/rlottie#4 haven't merged yet

Yes I know, I even use that PR in my CI (https://github.com/msrd0/install-rlottie-action/blob/v1/action.yml#L34).

It is very sad to see that no one seems to be maintaining rlottie in a way that people can contribute, but at least it's open source. To me, since I want this library to be as widely compatible as possible, it would make the most sense to:

  • With default features, keep it the way it is. That makes it work with samsung and telegram versions, but does not allow skin recolouring.
  • Add a feature as I said before, that keeps using the existing c api but adds just one more function to allow skin recolouring.

Also, docs.rs uses the 0.0.1 release from samsung to generate the documentation, since that's the only one available in the ubuntu packages.

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 28, 2023

With default features, keep it the way it is. That makes it work with samsung and telegram versions, but does not allow skin recolouring.

I've added telegrand feature, so any things dependent on melix99/rlottie will use that feature

@yuraiz
Copy link
Contributor Author

yuraiz commented Mar 28, 2023

I don't want to add a SkinTone enum because it allows to recolor only telegram emojis, and I don't sure that it will be used anywhere except telegrand

@msrd0
Copy link
Owner

msrd0 commented Mar 29, 2023

I just searched through the rlottie code and it seems to be the case that there can only be those variants: https://github.com/TelegramMessenger/rlottie/blob/master/src/lottie/lottieparser.cpp#L643

Since the rlottie code kinda forces the enum, I think we should keep that in our binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Telegram skin recolor
2 participants