Skip to content

Commit

Permalink
remove unsave webp-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Feb 11, 2024
1 parent b471ffd commit 575d2ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ image = "0.24"
kamadak-exif = "0.5"
lexical-sort = "0.3"
libavif-image = {version = "0.11", optional = true}
libwebp-sys = "0.9.2"
log = "0.4"
nalgebra = "0.32"
notan = {version = "0.11", default-features = false, features = ["backend", "draw", "glsl-to-spirv","drop_files", "egui"]}
Expand Down
31 changes: 7 additions & 24 deletions src/image_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::ktx2_loader::CompressedImageFormats;
use crate::utils::{fit, Frame, FrameSource};
use crate::{ktx2_loader, FONT};
use libwebp_sys::{WebPDecodeRGBA, WebPGetInfo};
use log::{debug, error, info};
use psd::Psd;

Expand All @@ -18,7 +17,6 @@ use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::SystemTime;
use tiff::decoder::Limits;
use usvg::{TreeParsing, TreeTextToPath};
use webp_animation::prelude::*;
Expand Down Expand Up @@ -437,18 +435,15 @@ pub fn open_image(img_location: &Path) -> Result<Receiver<Frame>> {
// return Ok(receiver);

let buffer = std::fs::read(img_location)?;

let decoder = Decoder::new(&buffer)?;

let mut dec_iter = decoder.into_iter();
let mut decoder = Decoder::new(&buffer)?.into_iter();

let mut last_timestamp = 0;

let mut frames = vec![];
let mut i = 0;

loop {
if let Some(frame) = dec_iter.next() {
if let Some(frame) = decoder.next() {
if frames.len() > 1 {
if let Some(last) = frames.pop() {
_ = sender.send(last);
Expand All @@ -472,12 +467,15 @@ pub fn open_image(img_location: &Path) -> Result<Receiver<Frame>> {
}

if i == 1 {
info!("This is a still");
debug!("This is a still");
if let Some(mut last) = frames.pop() {
last.source = FrameSource::Still;
_ = sender.send(last);
}
// _ = sender.send(Frame::new(buf, delay as u16, FrameSource::Animation));
} else {
for f in frames {
_ = sender.send(f);
}
}

// TODO: Use thread for animation and return receiver immediately
Expand Down Expand Up @@ -681,21 +679,6 @@ fn tonemap_rgb(px: [f32; 3]) -> [u8; 4] {
tm
}

// Unsafe webp decoding using webp-sys
fn decode_webp(buf: &[u8]) -> Option<RgbaImage> {
let mut width = 0;
let mut height = 0;
let len = buf.len();
let webp_buffer: Vec<u8>;
unsafe {
WebPGetInfo(buf.as_ptr(), len, &mut width, &mut height);
let out_buf = WebPDecodeRGBA(buf.as_ptr(), len, &mut width, &mut height);
let len = width * height * 4;
webp_buffer = Vec::from_raw_parts(out_buf, len as usize, len as usize);
}
image::ImageBuffer::from_raw(width as u32, height as u32, webp_buffer)
}

fn u16_to_u8(p: u16) -> u8 {
((p as f32 / u16::MAX as f32) * u8::MAX as f32) as u8
}
Expand Down

0 comments on commit 575d2ad

Please sign in to comment.