51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use std::{mem::transmute, net::{self, SocketAddr}, slice, sync::{Mutex, OnceLock}};
|
|
|
|
use openh264::{decoder::Decoder, formats::YUVSource};
|
|
use zune_jpeg::{zune_core::{colorspace::ColorSpace, options::DecoderOptions}, JpegDecoder};
|
|
|
|
#[no_mangle]
|
|
pub extern fn add(a: u64, b: u64) -> u64 {
|
|
a + b
|
|
}
|
|
|
|
#[no_mangle]
|
|
/// decode jpeg image of given length
|
|
///
|
|
/// image format is 0RGB
|
|
pub extern fn decode(image: &mut u32, packet: &u8, length: u32) -> u64 {
|
|
let packet = unsafe {slice::from_raw_parts(packet, length as usize)};
|
|
let image: &mut [u8; 4*320*240] = unsafe{transmute(image)};
|
|
|
|
let options = DecoderOptions::new_fast().jpeg_set_out_colorspace(ColorSpace::RGB);
|
|
let mut frame = JpegDecoder::new_with_options(packet, options).decode().unwrap();
|
|
|
|
// 0RGB conversion, easier than shifting and zeroing A
|
|
for (buffer, image) in frame.chunks_exact_mut(3).zip(image.chunks_exact_mut(4)) {
|
|
image[0] = buffer[2];
|
|
image[1] = buffer[1];
|
|
image[2] = buffer[0];
|
|
image[3] = 0;
|
|
}
|
|
|
|
0
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern fn blit_pattern(arr: &mut u32) -> u64 {
|
|
let arr: &mut [u32; 320*240] = unsafe{transmute(arr)};
|
|
let arr: &mut [[u32; 320];240] = unsafe{transmute(arr)};
|
|
for x in 0..320 {
|
|
for y in 0..240 {
|
|
let color = y%256
|
|
+ (x%256) * 256;
|
|
//*i = 0x00FF0000;
|
|
arr[y][x] = color as u32;
|
|
}
|
|
}
|
|
|
|
0
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
}
|