593 lines
24 KiB
Rust
593 lines
24 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use crate::engine::textures::{premultiply_rgba_srgb, TextureRegistry};
|
|
use crate::engine::types::TextureId;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum Icon {
|
|
MusicLogo,
|
|
MusicLogoLeftEn,
|
|
MusicLogoLeftRu,
|
|
Home,
|
|
HomeSelected,
|
|
Search,
|
|
SearchSelected,
|
|
Collection,
|
|
CollectionSelected,
|
|
NonMusic,
|
|
NonMusicSelected,
|
|
Kids,
|
|
KidsSelected,
|
|
Concerts,
|
|
ConcertsSelected,
|
|
MyVibe,
|
|
PlayFilled,
|
|
PauseFilled,
|
|
PlayFilledXs,
|
|
PlayLarge,
|
|
PauseLarge,
|
|
PlaySmall,
|
|
PlayXxs,
|
|
PauseSmall,
|
|
PlayVibe,
|
|
PauseVibe,
|
|
Next,
|
|
NextXxs,
|
|
Previous,
|
|
PreviousXxs,
|
|
Shuffle,
|
|
Repeat,
|
|
RepeatOne,
|
|
Like,
|
|
LikeXxs,
|
|
Liked,
|
|
LikedXxs,
|
|
Dislike,
|
|
Disliked,
|
|
Volume,
|
|
VolumeOff,
|
|
Lyrics,
|
|
Queue,
|
|
Fullscreen,
|
|
Settings,
|
|
More,
|
|
MoreXxs,
|
|
Pin,
|
|
PinFilled,
|
|
PinFilledXxs,
|
|
Download,
|
|
Downloaded,
|
|
ArrowLeft,
|
|
ArrowLeftXxs,
|
|
ArrowRight,
|
|
ArrowRightXxs,
|
|
ArrowDown,
|
|
Close,
|
|
CloseXxs,
|
|
Check,
|
|
Filter,
|
|
Plus,
|
|
Explicit,
|
|
ChartUp,
|
|
ChartDown,
|
|
ChartNew,
|
|
ChartSame,
|
|
History,
|
|
Share,
|
|
Note,
|
|
Album,
|
|
Playlist,
|
|
YandexPlusRu,
|
|
LinkRounded,
|
|
AiSparkles,
|
|
// Exact 5.129.0 `_xxs` ContextMenu icons from `app/icons/sprite.svg`
|
|
VibeXxs,
|
|
MenuArrowXxs,
|
|
ShuffleXxs,
|
|
RepeatXxs,
|
|
RepeatOneXxs,
|
|
SyncLyricsXxs,
|
|
PlayQueueXxs,
|
|
SettingsXxs,
|
|
AddToPlaylistXxs,
|
|
NoteXxs,
|
|
AlbumXxs,
|
|
ArtistXxs,
|
|
PlayNextXxs,
|
|
PlayLastXxs,
|
|
// Additional exact 5.129.0 official `sprite.svg` icons
|
|
PinXxs,
|
|
UnpinXxs,
|
|
BucketXxs,
|
|
EditXxs,
|
|
PencilXxs,
|
|
CheckXxs,
|
|
DislikeXxs,
|
|
DislikedXxs,
|
|
AddXxs,
|
|
ChainXxs,
|
|
CodeXxs,
|
|
LyricsXxs,
|
|
UploadXxs,
|
|
PauseXxs,
|
|
PauseFilledXs,
|
|
LinkXxs,
|
|
YandexPlusEn,
|
|
// Dedicated Yandex ID Profile & Appearance icons (v2.79.0) + WordsCard thumbs
|
|
ProfileAccountXxs,
|
|
ProfileSettingsXxs,
|
|
ProfileSupportXxs,
|
|
ProfileGlobeXxs,
|
|
ProfileAppearanceXxs,
|
|
ProfileAddAccountXxs,
|
|
ProfileLogoutXxs,
|
|
ProfilePlusXxs,
|
|
ThemeSystemXxs,
|
|
ThemeDarkXxs,
|
|
ThemeLightXxs,
|
|
ThumbUpXxs,
|
|
ThumbDownXxs,
|
|
YandexIdLogoRuDark,
|
|
YandexIdLogoRuLight,
|
|
YandexIdLogoEnDark,
|
|
YandexIdLogoEnLight,
|
|
}
|
|
|
|
impl Icon {
|
|
fn svg_bytes(self) -> &'static [u8] {
|
|
match self {
|
|
Icon::MusicLogo => include_bytes!("../assets/icons/musicLogo.svg"),
|
|
Icon::MusicLogoLeftEn => include_bytes!("../assets/icons/musicLogoLeftEn.svg"),
|
|
Icon::MusicLogoLeftRu => include_bytes!("../assets/icons/musicLogoLeftRu.svg"),
|
|
Icon::Home => include_bytes!("../assets/icons/navigationForYouAndTrends_xs.svg"),
|
|
Icon::HomeSelected => include_bytes!("../assets/icons/navigationForYouAndTrends_selected_xs.svg"),
|
|
Icon::Search => include_bytes!("../assets/icons/navigationSearch_xs.svg"),
|
|
Icon::SearchSelected => include_bytes!("../assets/icons/navigationSearch_xs.svg"),
|
|
Icon::Collection => include_bytes!("../assets/icons/navigationCollection_xs.svg"),
|
|
Icon::CollectionSelected => include_bytes!("../assets/icons/navigationCollection_selected_xs.svg"),
|
|
Icon::NonMusic => include_bytes!("../assets/icons/navigationNonMusic_xs.svg"),
|
|
Icon::NonMusicSelected => include_bytes!("../assets/icons/navigationNonMusic_selected_xs.svg"),
|
|
Icon::Kids => include_bytes!("../assets/icons/navigationKids_xs.svg"),
|
|
Icon::KidsSelected => include_bytes!("../assets/icons/navigationKids_selected_xs.svg"),
|
|
Icon::Concerts => include_bytes!("../assets/icons/navigationConcerts_xs.svg"),
|
|
Icon::ConcertsSelected => include_bytes!("../assets/icons/navigationConcerts_selected_xs.svg"),
|
|
Icon::MyVibe => include_bytes!("../assets/icons/navigationMyVibe_xs.svg"),
|
|
Icon::PlayFilled => include_bytes!("../assets/icons/play_filled_l.svg"),
|
|
Icon::PauseFilled => include_bytes!("../assets/icons/pause_filled_l.svg"),
|
|
Icon::PlayFilledXs => include_bytes!("../assets/icons/play_filled_xs.svg"),
|
|
Icon::PlayLarge => include_bytes!("../assets/icons/play.svg"),
|
|
Icon::PauseLarge => include_bytes!("../assets/icons/pause.svg"),
|
|
Icon::PlaySmall => include_bytes!("../assets/icons/play_xs.svg"),
|
|
Icon::PlayXxs => include_bytes!("../assets/icons/play_xxs.svg"),
|
|
Icon::PauseSmall => include_bytes!("../assets/icons/pause_xs.svg"),
|
|
Icon::PlayVibe => include_bytes!("../assets/icons/playVibe_s.svg"),
|
|
Icon::PauseVibe => include_bytes!("../assets/icons/pauseVibe_s.svg"),
|
|
Icon::Next => include_bytes!("../assets/icons/next_xs.svg"),
|
|
Icon::NextXxs => include_bytes!("../assets/icons/next_xxs.svg"),
|
|
Icon::Previous => include_bytes!("../assets/icons/previous_xs.svg"),
|
|
Icon::PreviousXxs => include_bytes!("../assets/icons/previous_xxs.svg"),
|
|
Icon::Shuffle => include_bytes!("../assets/icons/shuffle_xs.svg"),
|
|
Icon::Repeat => include_bytes!("../assets/icons/repeat_xs.svg"),
|
|
Icon::RepeatOne => include_bytes!("../assets/icons/repeat_one_xs.svg"),
|
|
Icon::Like => include_bytes!("../assets/icons/like_xs.svg"),
|
|
Icon::LikeXxs => include_bytes!("../assets/icons/like_xxs.svg"),
|
|
Icon::Liked => include_bytes!("../assets/icons/liked_xs.svg"),
|
|
Icon::LikedXxs => include_bytes!("../assets/icons/liked_xxs.svg"),
|
|
Icon::Dislike => include_bytes!("../assets/icons/dislike_xs.svg"),
|
|
Icon::Disliked => include_bytes!("../assets/icons/disliked_xs.svg"),
|
|
Icon::Volume => include_bytes!("../assets/icons/volume_xs.svg"),
|
|
Icon::VolumeOff => include_bytes!("../assets/icons/volumeOff_xs.svg"),
|
|
Icon::Lyrics => include_bytes!("../assets/icons/syncLyrics_xs.svg"),
|
|
Icon::Queue => include_bytes!("../assets/icons/playQueue_xs.svg"),
|
|
Icon::Fullscreen => include_bytes!("../assets/icons/fullscreen_xs.svg"),
|
|
Icon::Settings => include_bytes!("../assets/icons/settings_xs.svg"),
|
|
Icon::More => include_bytes!("../assets/icons/more_xs.svg"),
|
|
Icon::MoreXxs => include_bytes!("../assets/icons/more_xxs.svg"),
|
|
Icon::Pin => include_bytes!("../assets/icons/pin_xs.svg"),
|
|
Icon::PinFilled => include_bytes!("../assets/icons/pin_filled_xs.svg"),
|
|
Icon::PinFilledXxs => include_bytes!("../assets/icons/pin_filled_xxs.svg"),
|
|
Icon::Download => include_bytes!("../assets/icons/download_xxs.svg"),
|
|
Icon::Downloaded => include_bytes!("../assets/icons/downloaded_xxs.svg"),
|
|
Icon::ArrowLeft => include_bytes!("../assets/icons/arrowLeft_xs.svg"),
|
|
Icon::ArrowLeftXxs => include_bytes!("../assets/icons/arrowLeft_xxs.svg"),
|
|
Icon::ArrowRight => include_bytes!("../assets/icons/arrowRight_xs.svg"),
|
|
Icon::ArrowRightXxs => include_bytes!("../assets/icons/arrowRight_xxs.svg"),
|
|
Icon::ArrowDown => include_bytes!("../assets/icons/arrowDown_xs.svg"),
|
|
Icon::Close => include_bytes!("../assets/icons/close_xs.svg"),
|
|
Icon::CloseXxs => include_bytes!("../assets/icons/close_xxs.svg"),
|
|
Icon::Check => include_bytes!("../assets/icons/check_xs.svg"),
|
|
Icon::Filter => include_bytes!("../assets/icons/filter_xs.svg"),
|
|
Icon::Plus => include_bytes!("../assets/icons/plus.svg"),
|
|
Icon::Explicit => include_bytes!("../assets/icons/exclamation_xxxs.svg"),
|
|
Icon::ChartUp => include_bytes!("../assets/icons/chartUp_xxs.svg"),
|
|
Icon::ChartDown => include_bytes!("../assets/icons/chartDown_xxs.svg"),
|
|
Icon::ChartNew => include_bytes!("../assets/icons/chartNew_xxs.svg"),
|
|
Icon::ChartSame => include_bytes!("../assets/icons/chartSame_xxs.svg"),
|
|
Icon::History => include_bytes!("../assets/icons/history_m.svg"),
|
|
Icon::Share => include_bytes!("../assets/icons/share_xxs.svg"),
|
|
Icon::Note => include_bytes!("../assets/icons/note_l.svg"),
|
|
Icon::Album => include_bytes!("../assets/icons/album_l.svg"),
|
|
Icon::Playlist => include_bytes!("../assets/icons/playlist_s.svg"),
|
|
Icon::YandexPlusRu => include_bytes!("../assets/icons/yandexPlusRu.svg"),
|
|
Icon::LinkRounded => include_bytes!("../assets/icons/link_rounded_xxs.svg"),
|
|
Icon::AiSparkles => include_bytes!("../assets/icons/ai_sparkles_28.svg"),
|
|
Icon::VibeXxs => include_bytes!("../assets/icons/vibe_xxs.svg"),
|
|
Icon::MenuArrowXxs => include_bytes!("../assets/icons/menuArrow_xxs.svg"),
|
|
Icon::ShuffleXxs => include_bytes!("../assets/icons/shuffle_xxs.svg"),
|
|
Icon::RepeatXxs => include_bytes!("../assets/icons/repeat_xxs.svg"),
|
|
Icon::RepeatOneXxs => include_bytes!("../assets/icons/repeat_one_xxs.svg"),
|
|
Icon::SyncLyricsXxs => include_bytes!("../assets/icons/syncLyrics_xxs.svg"),
|
|
Icon::PlayQueueXxs => include_bytes!("../assets/icons/playQueue_xxs.svg"),
|
|
Icon::SettingsXxs => include_bytes!("../assets/icons/settings_xxs.svg"),
|
|
Icon::AddToPlaylistXxs => include_bytes!("../assets/icons/addToPlaylist_xxs.svg"),
|
|
Icon::NoteXxs => include_bytes!("../assets/icons/note_xxs.svg"),
|
|
Icon::AlbumXxs => include_bytes!("../assets/icons/album_xxs.svg"),
|
|
Icon::ArtistXxs => include_bytes!("../assets/icons/artist_xxs.svg"),
|
|
Icon::PlayNextXxs => include_bytes!("../assets/icons/playNext_xxs.svg"),
|
|
Icon::PlayLastXxs => include_bytes!("../assets/icons/playLast_xxs.svg"),
|
|
Icon::PinXxs => include_bytes!("../assets/icons/pin_xxs.svg"),
|
|
Icon::UnpinXxs => include_bytes!("../assets/icons/unpin_xxs.svg"),
|
|
Icon::BucketXxs => include_bytes!("../assets/icons/bucket_xxs.svg"),
|
|
Icon::EditXxs => include_bytes!("../assets/icons/edit_xxs.svg"),
|
|
Icon::PencilXxs => include_bytes!("../assets/icons/pencil_xxs.svg"),
|
|
Icon::CheckXxs => include_bytes!("../assets/icons/check_xxs.svg"),
|
|
Icon::DislikeXxs => include_bytes!("../assets/icons/dislike_xxs.svg"),
|
|
Icon::DislikedXxs => include_bytes!("../assets/icons/disliked_xxs.svg"),
|
|
Icon::AddXxs => include_bytes!("../assets/icons/add_xxs.svg"),
|
|
Icon::ChainXxs => include_bytes!("../assets/icons/chain_xxs.svg"),
|
|
Icon::CodeXxs => include_bytes!("../assets/icons/code_xxs.svg"),
|
|
Icon::LyricsXxs => include_bytes!("../assets/icons/lyrics_xxs.svg"),
|
|
Icon::UploadXxs => include_bytes!("../assets/icons/upload_xxs.svg"),
|
|
Icon::PauseXxs => include_bytes!("../assets/icons/pause_xxs.svg"),
|
|
Icon::PauseFilledXs => include_bytes!("../assets/icons/pause_filled_xs.svg"),
|
|
Icon::LinkXxs => include_bytes!("../assets/icons/link_xxs.svg"),
|
|
Icon::YandexPlusEn => include_bytes!("../assets/icons/yandexPlusEn.svg"),
|
|
Icon::ProfileAccountXxs => include_bytes!("../assets/icons/profile_account_xxs.svg"),
|
|
Icon::ProfileSettingsXxs => include_bytes!("../assets/icons/profile_settings_xxs.svg"),
|
|
Icon::ProfileSupportXxs => include_bytes!("../assets/icons/profile_support_xxs.svg"),
|
|
Icon::ProfileGlobeXxs => include_bytes!("../assets/icons/profile_globe_xxs.svg"),
|
|
Icon::ProfileAppearanceXxs => include_bytes!("../assets/icons/profile_appearance_xxs.svg"),
|
|
Icon::ProfileAddAccountXxs => include_bytes!("../assets/icons/profile_add_account_xxs.svg"),
|
|
Icon::ProfileLogoutXxs => include_bytes!("../assets/icons/profile_logout_xxs.svg"),
|
|
Icon::ProfilePlusXxs => include_bytes!("../assets/icons/profile_plus_xxs.svg"),
|
|
Icon::ThemeSystemXxs => include_bytes!("../assets/icons/theme_system_xxs.svg"),
|
|
Icon::ThemeDarkXxs => include_bytes!("../assets/icons/theme_dark_xxs.svg"),
|
|
Icon::ThemeLightXxs => include_bytes!("../assets/icons/theme_light_xxs.svg"),
|
|
Icon::ThumbUpXxs => include_bytes!("../assets/icons/thumb_up_xxs.svg"),
|
|
Icon::ThumbDownXxs => include_bytes!("../assets/icons/thumb_down_xxs.svg"),
|
|
Icon::YandexIdLogoRuDark => include_bytes!("../assets/icons/yandex_id_logo_ru_dark.svg"),
|
|
Icon::YandexIdLogoRuLight => include_bytes!("../assets/icons/yandex_id_logo_ru_light.svg"),
|
|
Icon::YandexIdLogoEnDark => include_bytes!("../assets/icons/yandex_id_logo_en_dark.svg"),
|
|
Icon::YandexIdLogoEnLight => include_bytes!("../assets/icons/yandex_id_logo_en_light.svg"),
|
|
}
|
|
}
|
|
|
|
fn raster_size(self) -> (u32, u32) {
|
|
match self {
|
|
Icon::MusicLogoLeftEn => (276, 96),
|
|
Icon::MusicLogoLeftRu => (256, 72),
|
|
Icon::YandexPlusRu | Icon::YandexPlusEn => (160, 44),
|
|
Icon::YandexIdLogoRuDark
|
|
| Icon::YandexIdLogoRuLight
|
|
| Icon::YandexIdLogoEnDark
|
|
| Icon::YandexIdLogoEnLight => (124, 60),
|
|
Icon::MusicLogo | Icon::PlayFilled | Icon::PauseFilled | Icon::PlayLarge | Icon::PauseLarge => (72, 72),
|
|
_ => (48, 48),
|
|
}
|
|
}
|
|
|
|
/// Expose raw embedded SVG bytes for automated asset integrity tests.
|
|
pub fn raw_svg(self) -> &'static [u8] {
|
|
self.svg_bytes()
|
|
}
|
|
|
|
/// Complete catalog of every official Yandex Music SVG icon wired into the app.
|
|
pub const ALL: &'static [Icon] = &[
|
|
Icon::MusicLogo,
|
|
Icon::MusicLogoLeftEn,
|
|
Icon::MusicLogoLeftRu,
|
|
Icon::Home,
|
|
Icon::HomeSelected,
|
|
Icon::Search,
|
|
Icon::SearchSelected,
|
|
Icon::Collection,
|
|
Icon::CollectionSelected,
|
|
Icon::NonMusic,
|
|
Icon::NonMusicSelected,
|
|
Icon::Kids,
|
|
Icon::KidsSelected,
|
|
Icon::Concerts,
|
|
Icon::ConcertsSelected,
|
|
Icon::MyVibe,
|
|
Icon::PlayFilled,
|
|
Icon::PauseFilled,
|
|
Icon::PlayFilledXs,
|
|
Icon::PlayLarge,
|
|
Icon::PauseLarge,
|
|
Icon::PlaySmall,
|
|
Icon::PlayXxs,
|
|
Icon::PauseSmall,
|
|
Icon::PlayVibe,
|
|
Icon::PauseVibe,
|
|
Icon::Next,
|
|
Icon::NextXxs,
|
|
Icon::Previous,
|
|
Icon::PreviousXxs,
|
|
Icon::Shuffle,
|
|
Icon::Repeat,
|
|
Icon::RepeatOne,
|
|
Icon::Like,
|
|
Icon::LikeXxs,
|
|
Icon::Liked,
|
|
Icon::LikedXxs,
|
|
Icon::Dislike,
|
|
Icon::Disliked,
|
|
Icon::Volume,
|
|
Icon::VolumeOff,
|
|
Icon::Lyrics,
|
|
Icon::Queue,
|
|
Icon::Fullscreen,
|
|
Icon::Settings,
|
|
Icon::More,
|
|
Icon::MoreXxs,
|
|
Icon::Pin,
|
|
Icon::PinFilled,
|
|
Icon::PinFilledXxs,
|
|
Icon::Download,
|
|
Icon::Downloaded,
|
|
Icon::ArrowLeft,
|
|
Icon::ArrowLeftXxs,
|
|
Icon::ArrowRight,
|
|
Icon::ArrowRightXxs,
|
|
Icon::ArrowDown,
|
|
Icon::Close,
|
|
Icon::CloseXxs,
|
|
Icon::Check,
|
|
Icon::Filter,
|
|
Icon::Plus,
|
|
Icon::Explicit,
|
|
Icon::ChartUp,
|
|
Icon::ChartDown,
|
|
Icon::ChartNew,
|
|
Icon::ChartSame,
|
|
Icon::History,
|
|
Icon::Share,
|
|
Icon::Note,
|
|
Icon::Album,
|
|
Icon::Playlist,
|
|
Icon::YandexPlusRu,
|
|
Icon::LinkRounded,
|
|
Icon::AiSparkles,
|
|
Icon::VibeXxs,
|
|
Icon::MenuArrowXxs,
|
|
Icon::ShuffleXxs,
|
|
Icon::RepeatXxs,
|
|
Icon::RepeatOneXxs,
|
|
Icon::SyncLyricsXxs,
|
|
Icon::PlayQueueXxs,
|
|
Icon::SettingsXxs,
|
|
Icon::AddToPlaylistXxs,
|
|
Icon::NoteXxs,
|
|
Icon::AlbumXxs,
|
|
Icon::ArtistXxs,
|
|
Icon::PlayNextXxs,
|
|
Icon::PlayLastXxs,
|
|
Icon::PinXxs,
|
|
Icon::UnpinXxs,
|
|
Icon::BucketXxs,
|
|
Icon::EditXxs,
|
|
Icon::PencilXxs,
|
|
Icon::CheckXxs,
|
|
Icon::DislikeXxs,
|
|
Icon::DislikedXxs,
|
|
Icon::AddXxs,
|
|
Icon::ChainXxs,
|
|
Icon::CodeXxs,
|
|
Icon::LyricsXxs,
|
|
Icon::UploadXxs,
|
|
Icon::PauseXxs,
|
|
Icon::PauseFilledXs,
|
|
Icon::LinkXxs,
|
|
Icon::YandexPlusEn,
|
|
Icon::ProfileAccountXxs,
|
|
Icon::ProfileSettingsXxs,
|
|
Icon::ProfileSupportXxs,
|
|
Icon::ProfileGlobeXxs,
|
|
Icon::ProfileAppearanceXxs,
|
|
Icon::ProfileAddAccountXxs,
|
|
Icon::ProfileLogoutXxs,
|
|
Icon::ProfilePlusXxs,
|
|
Icon::ThemeSystemXxs,
|
|
Icon::ThemeDarkXxs,
|
|
Icon::ThemeLightXxs,
|
|
Icon::ThumbUpXxs,
|
|
Icon::ThumbDownXxs,
|
|
Icon::YandexIdLogoRuDark,
|
|
Icon::YandexIdLogoRuLight,
|
|
Icon::YandexIdLogoEnDark,
|
|
Icon::YandexIdLogoEnLight,
|
|
];
|
|
}
|
|
|
|
/// Lazily rasterizes official Yandex Music vector SVG icons into crisp GPU textures via `TextureRegistry`.
|
|
/// Keeps total icon memory under ~0.5 MB!
|
|
pub struct IconCache {
|
|
pub textures: HashMap<Icon, TextureId>,
|
|
heart_tex: Option<TextureId>,
|
|
search_glow_tex: Option<TextureId>,
|
|
meteor_glow_tex: Option<TextureId>,
|
|
}
|
|
|
|
impl Default for IconCache {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl IconCache {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
textures: HashMap::with_capacity(64),
|
|
heart_tex: None,
|
|
search_glow_tex: None,
|
|
meteor_glow_tex: None,
|
|
}
|
|
}
|
|
|
|
/// Official 3D crimson heart PNG extracted from Yandex Music 5.129.0 (`heart.602389ae.png`).
|
|
/// Decoded with linear sRGB premultiply to eliminate alpha-fringe haloing on UNORM Vulkan.
|
|
pub fn get_official_heart(&mut self, registry: &mut TextureRegistry) -> TextureId {
|
|
if let Some(id) = self.heart_tex {
|
|
return id;
|
|
}
|
|
let bytes = include_bytes!("../assets/media/heart.png");
|
|
let (w, h, premul) = decode_png_rgba_css_premul(bytes);
|
|
let id = registry.create_rgba_premul(w, h, premul);
|
|
self.heart_tex = Some(id);
|
|
id
|
|
}
|
|
|
|
/// Soft round blue-cyan-violet holographic AI orb matching Yandex Music 5.129.0 Search prompts strip.
|
|
pub fn get_official_search_glow(&mut self, registry: &mut TextureRegistry) -> TextureId {
|
|
if let Some(id) = self.search_glow_tex {
|
|
return id;
|
|
}
|
|
let (w, h, premul) = generate_search_ai_orb_premul(128, 112);
|
|
let id = registry.create_rgba_premul(w, h, premul);
|
|
self.search_glow_tex = Some(id);
|
|
id
|
|
}
|
|
|
|
/// Alias for the round blue-cyan-violet holographic AI Search orb.
|
|
pub fn get_official_search_orb(&mut self, registry: &mut TextureRegistry) -> TextureId {
|
|
self.get_official_search_glow(registry)
|
|
}
|
|
|
|
/// Official AI Badge falling-meteor glow PNG from Yandex Music 5.128.0 CDN.
|
|
pub fn get_official_meteor_glow(&mut self, registry: &mut TextureRegistry) -> TextureId {
|
|
if let Some(id) = self.meteor_glow_tex {
|
|
return id;
|
|
}
|
|
let bytes = include_bytes!("../assets/media/ai_meteor_glow.png");
|
|
let (w, h, premul) = decode_png_rgba_css_premul(bytes);
|
|
let id = registry.create_rgba_premul(w, h, premul);
|
|
self.meteor_glow_tex = Some(id);
|
|
id
|
|
}
|
|
|
|
pub fn get(&mut self, registry: &mut TextureRegistry, icon: Icon) -> TextureId {
|
|
if let Some(&id) = self.textures.get(&icon) {
|
|
return id;
|
|
}
|
|
let (w, h) = icon.raster_size();
|
|
let premul = rasterize_svg_premul(icon.svg_bytes(), w, h);
|
|
let id = registry.create_rgba_premul(w, h, premul);
|
|
self.textures.insert(icon, id);
|
|
id
|
|
}
|
|
}
|
|
|
|
fn rasterize_svg_premul(svg_data: &[u8], target_w: u32, target_h: u32) -> Vec<u8> {
|
|
let opt = resvg::usvg::Options::default();
|
|
let Ok(tree) = resvg::usvg::Tree::from_data(svg_data, &opt) else {
|
|
return vec![0u8; (target_w * target_h * 4) as usize];
|
|
};
|
|
|
|
let Some(mut pixmap) = resvg::tiny_skia::Pixmap::new(target_w, target_h) else {
|
|
return vec![0u8; (target_w * target_h * 4) as usize];
|
|
};
|
|
|
|
let svg_size = tree.size();
|
|
let sx = target_w as f32 / svg_size.width().max(1.0);
|
|
let sy = target_h as f32 / svg_size.height().max(1.0);
|
|
let scale = sx.min(sy);
|
|
let tx = (target_w as f32 - svg_size.width() * scale) * 0.5;
|
|
let ty = (target_h as f32 - svg_size.height() * scale) * 0.5;
|
|
let transform = resvg::tiny_skia::Transform::from_scale(scale, scale).post_translate(tx, ty);
|
|
|
|
resvg::render(&tree, transform, &mut pixmap.as_mut());
|
|
|
|
// resvg / tiny_skia produces premultiplied RGBA8 directly.
|
|
pixmap.take()
|
|
}
|
|
|
|
/// Linear sRGB premultiply matching Chromium's CSS compositing on our UNORM Vulkan swapchain.
|
|
fn decode_png_rgba_css_premul(bytes: &[u8]) -> (u32, u32, Vec<u8>) {
|
|
if let Ok(dyn_img) = image::load_from_memory(bytes) {
|
|
let rgba = dyn_img.to_rgba8();
|
|
let (w, h) = rgba.dimensions();
|
|
let premul = premultiply_rgba_srgb(rgba.as_raw());
|
|
return (w, h, premul);
|
|
}
|
|
(4, 4, vec![0u8; 4 * 4 * 4])
|
|
}
|
|
|
|
fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
|
|
let t = ((x - edge0) / (edge1 - edge0)).clamp(0.0, 1.0);
|
|
t * t * (3.0 - 2.0 * t)
|
|
}
|
|
|
|
/// Generates the dark-indigo/violet glowing holographic AI Search orb with bright icy-cyan/lavender
|
|
/// crescent rim & soft purple outer halo matching `tests/references/search.jpg` (premultiplied linear sRGB RGBA8).
|
|
fn generate_search_ai_orb_premul(width: u32, height: u32) -> (u32, u32, Vec<u8>) {
|
|
let mut raw = Vec::with_capacity((width * height * 4) as usize);
|
|
let aspect = width as f32 / height.max(1) as f32;
|
|
|
|
for py in 0..height {
|
|
let v = (py as f32 + 0.5) / height as f32;
|
|
for px in 0..width {
|
|
let u = (px as f32 + 0.5) / width as f32;
|
|
let dx = (u - 0.5) * aspect;
|
|
let dy = v - 0.5;
|
|
let dist = (dx * dx + dy * dy).sqrt();
|
|
// Slightly elliptical organic orb matching reference (~42x36px core + soft dark-violet outer glow)
|
|
let r = ((dx / 0.44).powi(2) + (dy / 0.37).powi(2)).sqrt();
|
|
|
|
// Dark translucent indigo-violet core + soft dark-purple atmospheric halo
|
|
let body = 1.0 - smoothstep(0.68, 1.04, r);
|
|
let halo = (-r * r * 2.3).exp() * 0.32 * (1.0 - smoothstep(1.0, 1.38, r));
|
|
let rim = smoothstep(0.56, 0.90, r) * (1.0 - smoothstep(0.90, 1.12, r));
|
|
let alpha = (body * 0.72 + rim * 0.48 + halo).clamp(0.0, 1.0);
|
|
|
|
if alpha <= 0.002 {
|
|
raw.extend_from_slice(&[0, 0, 0, 0]);
|
|
continue;
|
|
}
|
|
|
|
// Swirling holographic ribbon texture inside the dark-indigo sphere
|
|
let rib = ((dx * 15.0 + dy * 7.5 + dist * 6.0).sin() * 0.5 + 0.5).clamp(0.0, 1.0);
|
|
let angle = dy.atan2(dx);
|
|
|
|
// Crescent rim highlights matching reference: bright icy-cyan/lavender on left (~PI) & bottom-right (~0.55)
|
|
let left_crescent = (-(dx + 0.34).powi(2) * 18.0 - (dy + 0.02).powi(2) * 14.0).exp();
|
|
let br_crescent = (-(dx - 0.24).powi(2) * 14.0 - (dy - 0.18).powi(2) * 18.0).exp();
|
|
let top_right_crescent = (-(dx - 0.22).powi(2) * 20.0 - (dy + 0.16).powi(2) * 20.0).exp();
|
|
let crescent = (left_crescent * 0.95 + br_crescent * 0.90 + top_right_crescent * 0.45).clamp(0.0, 1.0);
|
|
|
|
// Base dark indigo-violet interior (`RGB(58..92, 60..108, 130..185)`)
|
|
let mut cr = 60.0 + 26.0 * (angle.cos() * 0.5 + 0.5) + rib * 18.0;
|
|
let mut cg = 62.0 + 38.0 * (dy + 0.4).clamp(0.0, 1.0) + rib * 24.0;
|
|
let mut cb = 136.0 + 46.0 * body + rib * 26.0;
|
|
|
|
// Add luminous icy-cyan / periwinkle-lavender crescent rim (`RGB(158, 196, 255)`)
|
|
let rim_boost = (rim * 0.65 + crescent * 0.85).clamp(0.0, 1.1);
|
|
cr = cr + rim_boost * 96.0;
|
|
cg = cg + rim_boost * 124.0;
|
|
cb = cb + rim_boost * 108.0;
|
|
|
|
// Outside the sphere body, tint atmospheric glow to soft dark purple (`RGB(48, 28, 68)`)
|
|
let outer_mix = smoothstep(0.92, 1.20, r);
|
|
cr = cr * (1.0 - outer_mix) + 64.0 * outer_mix;
|
|
cg = cg * (1.0 - outer_mix) + 36.0 * outer_mix;
|
|
cb = cb * (1.0 - outer_mix) + 88.0 * outer_mix;
|
|
|
|
raw.push(cr.clamp(0.0, 255.0).round() as u8);
|
|
raw.push(cg.clamp(0.0, 255.0).round() as u8);
|
|
raw.push(cb.clamp(0.0, 255.0).round() as u8);
|
|
raw.push((alpha * 255.0).round() as u8);
|
|
}
|
|
}
|
|
|
|
let premul = premultiply_rgba_srgb(&raw);
|
|
(width, height, premul)
|
|
}
|