Add JPEG support and enable stripping in release-lto

This commit is contained in:
Michael Pfaff 2024-06-09 15:05:28 -04:00
parent 8f5bc9b574
commit da37d7a182
2 changed files with 7 additions and 2 deletions

View File

@ -7,8 +7,9 @@ edition = "2021"
crate-type = ["cdylib"]
[dependencies]
image = { version = "0.25.1", default-features = false, features = ["png", "webp", "rayon"] }
image = { version = "0.25.1", default-features = false, features = ["jpeg", "png", "webp", "rayon"] }
[profile.release-lto]
inherits = "release"
lto = "fat"
strip = true

View File

@ -1,6 +1,6 @@
use std::{convert::Infallible, io::Cursor, ptr::NonNull};
use image::{codecs::{png::PngDecoder, webp::WebPDecoder}, error::{ImageFormatHint, UnsupportedError}, ImageDecoder, ImageError};
use image::{codecs::{jpeg::JpegDecoder, png::PngDecoder, webp::WebPDecoder}, error::{ImageFormatHint, UnsupportedError}, ImageDecoder, ImageError};
#[derive(Clone, Copy)]
#[repr(C)]
@ -148,6 +148,10 @@ pub extern "system" fn load_image(input: *const u8, input_len: usize, alloc: All
};
let format = ImageFormat::from(iformat).ok_or(iformat);
match format {
Ok(ImageFormat::Jpeg) => {
JpegDecoder::new(Cursor::new(input))
.map(|dec| load_image_common(alloc, dec))
}
Ok(ImageFormat::Png) => {
PngDecoder::new(Cursor::new(input))
.map(|dec| load_image_common(alloc, dec))