.michelin
User since Sep 10, 2023
1 Posts
Recent Posts
async fn encode_gif(frames: Vec<Frame>) -> Result<Vec<Vec<u8>>> {fn output_frame(raw: &[u8], format: u8, delay: u32, index: usize, size: (u32, u32)) -> Result<Vec<u8>> {let b64 = general_purpose::STANDARD.encode(raw).into_bytes();let mut it = b64.chunks(4096).peekable();let mut buf = Vec::with_capacity(b64.len() + it.len() * 50);let com = if index == 0 {"T"} else {"f"};if let Some(first) = it.next() {write!(buf,"{}_Gq=2,a={},z={},i=1,C=1,U=1,f={},s={},v={},m={};{}{}\\{}",START,com, // first frame must be static image datadelay,format,size.0,size.1,it.peek().is_some() as u8,unsafe { str::from_utf8_unchecked(first) },ESCAPE,CLOSE)?;}while let Some(chunk) = it.next() {write!(buf,"{}_Gm={};{}{}\\{}",START,it.peek().is_some() as u8,unsafe { str::from_utf8_unchecked(chunk) },ESCAPE,CLOSE)?;}write!(buf, "{}", CLOSE)?;Ok(buf)}let mut frame_buffer = Vec::new();// populate framebuffer for entire giffor (index, frame) in frames.into_iter().enumerate() {let size = frame.buffer().dimensions();fn delay_to_ms(delay: Delay) -> u32 {let (num, denom) = delay.numer_denom_ms();if denom == 0 { 0 } else { num / denom }}let delay_ms = delay_to_ms(frame.delay());let buf = tokio::task::spawn_blocking(move || match DynamicImage::ImageRgba8(frame.buffer().clone()) {DynamicImage::ImageRgb8(v) => output_frame(&v, 24, delay_ms, index, size),DynamicImage::ImageRgba8(v) => output_frame(&v, 32, delay_ms, index, size),v => output_frame(v.into_rgb8().as_raw(), 24, delay_ms, index, size),}).await?;if buf.is_ok() { frame_buffer.push(buf.unwrap()) }};// transmit our framebufferOk(frame_buffer)}fn animate(id: u32) -> Result<Vec<u8>> {let mut buf = Vec::new();write!(buf,"{}_Gq=2,a=a,s=2,i={}{}\\{}", // starts the animation for id=1START,id,ESCAPE,CLOSE)?;write!(buf, "{}", CLOSE)?;Ok(buf)}
Post Statistics
Posts
No Posts Found
It looks like .michelin has no public posts
Likes
Please Log In
You must be authenticated to view a user's likes
Profile Privacy
Multi-Factor Authentication
Multi-Factor Authentication (MFA) is an authentication method that requires you to provide two or more verification factors to gain access to your account. In addition to username and password, MFA requires you to verify your email on every login, which decreases the likelihood of someone stealing your account.
Change Password
Identity Color
Changes the color of your profile icon and cursor highlight in the live code editor. You and other users will be able to view this change.
Delete Account
Deleting your account is permanent. All data associated with your account will be lost.