Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/no_std.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ jobs:
# Target below does not have a standard library
- run: rustup target add x86_64-unknown-uefi
# Below targets run in no-std environments
- run: cargo build -p zune-core --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-inflate --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-jpeg --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-png --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-ppm --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-qoi --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-farbfeld --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-psd --target x86_64-unknown-uefi --no-default-features
- run: cargo build -p zune-bmp --target x86_64-unknown-uefi --no-default-features

- run: cargo build -p zune-core --target x86_64-unknown-uefi --no-default-features --features log,serde
- run: cargo build -p zune-inflate --target x86_64-unknown-uefi --no-default-features --features zlib,gzip
- run: cargo build -p zune-jpeg --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-png --target x86_64-unknown-uefi --no-default-features --features log,libm
- run: cargo build -p zune-ppm --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-qoi --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-farbfeld --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-psd --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-bmp --target x86_64-unknown-uefi --no-default-features --features log,rgb_inverse
- run: cargo build -p zune-gif --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-hdr --target x86_64-unknown-uefi --no-default-features --features log,libm
- run: cargo build -p zune-jpegxl --target x86_64-unknown-uefi --no-default-features --features log
- run: cargo build -p zune-image --target x86_64-unknown-uefi --no-default-features --features log,libm,serde-support,ppm,jpeg,png,psd,farbfeld,qoi,bmp,hdr
- run: cargo build -p zune-imageprocs --target x86_64-unknown-uefi --no-default-features --features log,libm


4 changes: 3 additions & 1 deletion crates/zune-bmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ description = "A fast BMP decoder"

[features]
log = ["zune-core/log"]
std = ["zune-core/std"]
rgb_inverse = []

[dependencies]
zune-core = { version = "0.5.0-rc1", path = "../zune-core" }
log = "0.4.21"

[dev-dependencies]
zune-core = { version = "0.5.0-rc1", path = "../zune-core", features = ["std"] }
6 changes: 1 addition & 5 deletions crates/zune-bmp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
//! use zune_bmp::BmpDecoder;
//! // read from a file
//! let source = BufReader::new(File::open("./image.bmp").unwrap());
//! // only run when std is enabled, otherwise zune_core doesn't implement the ZByteReader trait
//! // on File since it doesn't exist in `no_std` land
//! #[cfg(feature = "std")]
//! let decoder = BmpDecoder::new(source);
//!
//! ```
Expand All @@ -71,9 +68,8 @@
//! benchmark just in case you think it's slowing you down in any way.
//!
#![no_std]
#![macro_use]
extern crate alloc;

extern crate alloc;
extern crate core;

pub use zune_core;
Expand Down
2 changes: 1 addition & 1 deletion crates/zune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ std = []

[dependencies]
log = { version = "0.4.17", optional = true }
serde = { version = "1.0.52", optional = true }
serde = { version = "1.0.52", optional = true, default-features = false }
2 changes: 1 addition & 1 deletion crates/zune-core/src/bytestream/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,6 @@ where
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
use std::io::ErrorKind;
self.read_bytes(buf)
.map_err(|e| std::io::Error::new(ErrorKind::Other, format!("{:?}", e)))
.map_err(|e| std::io::Error::new(ErrorKind::Other, alloc::format!("{:?}", e)))
}
}
1 change: 1 addition & 0 deletions crates/zune-core/src/bytestream/reader/std_readers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(feature = "std")]

use alloc::vec::Vec;
use std::io;
use std::io::SeekFrom;

Expand Down
7 changes: 5 additions & 2 deletions crates/zune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
//!
//!
//!
#![cfg_attr(not(feature = "std"), no_std)]
#![macro_use]
#![no_std]

extern crate alloc;
extern crate core;

#[cfg(feature = "std")]
extern crate std;

#[cfg(not(feature = "log"))]
pub mod log;

Expand Down
10 changes: 5 additions & 5 deletions crates/zune-core/src/options/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl DecoderOptions {
// where we can do runtime check if feature is present
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("sse2") {
if std::is_x86_feature_detected!("sse2") {
return true;
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ impl DecoderOptions {
// where we can do runtime check if feature is present
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("sse3") {
if std::is_x86_feature_detected!("sse3") {
return true;
}
}
Expand Down Expand Up @@ -515,7 +515,7 @@ impl DecoderOptions {
// where we can do runtime check if feature is present
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("sse4.1") {
if std::is_x86_feature_detected!("sse4.1") {
return true;
}
}
Expand Down Expand Up @@ -547,7 +547,7 @@ impl DecoderOptions {
// where we can do runtime check if feature is present
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx") {
if std::is_x86_feature_detected!("avx") {
return true;
}
}
Expand Down Expand Up @@ -579,7 +579,7 @@ impl DecoderOptions {
// where we can do runtime check if feature is present
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx2") {
if std::is_x86_feature_detected!("avx2") {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/zune-farbfeld/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//!
//!
#![no_std]
#![macro_use]

extern crate alloc;

pub use decoder::*;
Expand Down
2 changes: 2 additions & 0 deletions crates/zune-gif/src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use zune_core::bytestream::{ZByteReaderTrait, ZReader};
use zune_core::log::trace;
use zune_core::options::DecoderOptions;
Expand Down
4 changes: 2 additions & 2 deletions crates/zune-gif/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::fmt::Debug;
use std::fmt::Formatter;
use core::fmt::Formatter;

use zune_core::bytestream::ZByteIoError;

Expand All @@ -18,7 +18,7 @@ pub enum GifDecoderErrors {
TooSmallSize(usize, usize)
}
impl Debug for GifDecoderErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
GifDecoderErrors::NotAGif => {
writeln!(f, "Not a gif, magic bytes didn't match")
Expand Down
6 changes: 6 additions & 0 deletions crates/zune-gif/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![no_std]

#[macro_use]
extern crate alloc;
extern crate core;

mod decoder;
mod enums;
mod errors;
Expand Down
6 changes: 5 additions & 1 deletion crates/zune-hdr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ homepage = "https://github.com/etemesi254/zune-image/tree/dev/crates/zune-hdr"
keywords = ["image"]
categories = ["multimedia::images", "multimedia::encoding", ]
license = "MIT OR Apache-2.0 OR Zlib"
rust-version = "1.81.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
log = ["zune-core/log"]
std = []
default = ["std"]

[dependencies]
zune-core = { version = "0.5.0-rc0", path = "../zune-core", default-features = false, features = ["std"] }
zune-core = { version = "0.5.0-rc0", path = "../zune-core", default-features = false }
libm = { version = "0.2", optional = true }
39 changes: 28 additions & 11 deletions crates/zune-hdr/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

//! Radiance HDR encoder

use alloc::{format, vec};
use std::collections::HashMap;
use alloc::{format, vec, string::String, vec::Vec};

use zune_core::bytestream::{ZByteIoError, ZByteWriterTrait, ZWriter};
use zune_core::colorspace::ColorSpace;
Expand All @@ -21,7 +20,7 @@ use crate::errors::HdrEncodeErrors;
/// `width*height*3`
pub struct HdrEncoder<'a> {
data: &'a [f32],
headers: Option<&'a HashMap<String, String>>,
headers: Option<Vec<(String, String)>>,
options: EncoderOptions
}

Expand All @@ -45,9 +44,14 @@ impl<'a> HdrEncoder<'a> {
/// otherwise it will have no effect.
///
/// # Arguments:
/// - headers: A hashmap containing keys and values, the values will be encoded as key=value
/// - headers: An iterator containing keys and values, the values will be encoded as key=value
/// in the hdr header before encoding
pub fn add_headers(&mut self, headers: &'a HashMap<String, String>) {
pub fn add_headers(&mut self, headers: impl IntoIterator<Item = (String, String)>) {
let mut headers = headers.into_iter().collect::<Vec<_>>();

headers.sort_by(|(a, _), (b, _)| a.cmp(b));
headers.dedup_by(|(a, _), (b, _)| a.eq(&b));

self.headers = Some(headers)
}

Expand Down Expand Up @@ -155,7 +159,7 @@ impl<'a> HdrEncoder<'a> {
{
writer.write_all(b"#?RADIANCE\n")?;
writer.write_all(b"SOFTWARE=zune-hdr\n")?;
if let Some(headers) = self.headers {
if let Some(headers) = &self.headers {
for (k, v) in headers {
writer.write_all(format!("{}={}\n", k, v).as_bytes())?;
}
Expand Down Expand Up @@ -337,12 +341,25 @@ fn frexp(s: f32) -> (f32, i32) {
} else {
let lg = fast_log2(abs(s));
let lg_floor = floor(lg);
// Note: This is the only reason we need the standard library
// I haven't found a good exp2 function, fast_exp2 doesn't work
// and libm/musl exp2 introduces visible color distortions and is slow, so for
// now let's stick to whatever the platform provides
let x = (lg - lg_floor - 1.0).exp2();
let x = exp2(lg - lg_floor - 1.0);
let exp = lg_floor + 1.0;
(signum(s) * x, exp as i32)
}
}

fn exp2(x: f32) -> f32 {
// Note: This is the only reason we need the standard library
// I haven't found a good exp2 function, fast_exp2 doesn't work
// and libm/musl exp2 introduces visible color distortions and is slow, so for
// now let's stick to whatever the platform provides
#[cfg(all(feature = "std", not(feature = "libm")))]
{
f32::exp2(x)
}

// For `no_std`, we allow users to select `libm`, even if it produces sub-par results.
#[cfg(feature = "libm")]
{
libm::exp2f(x)
}
}
4 changes: 2 additions & 2 deletions crates/zune-hdr/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ impl Display for HdrDecodeErrors {
writeln!(f, "{:?}", self)
}
}
impl std::error::Error for HdrDecodeErrors {}
impl core::error::Error for HdrDecodeErrors {}

impl Display for HdrEncodeErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
writeln!(f, "{:?}", self)
}
}

impl std::error::Error for HdrEncodeErrors {}
impl core::error::Error for HdrEncodeErrors {}

/// HDR encoding errrors
pub enum HdrEncodeErrors {
Expand Down
12 changes: 8 additions & 4 deletions crates/zune-hdr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
//! color primaries, exposure,gamma e.t.c,
//!

// CAE: No std doesn't work because we haven't implemented
// floor and exp2 for floats, which do not exist in no std land
// #![no_std]
#![no_std]
#![forbid(unsafe_code)]
#![macro_use]

extern crate alloc;
extern crate core;

#[cfg(feature = "std")]
extern crate std;

pub extern crate zune_core;
pub use decoder::HdrDecoder;
#[cfg(any(feature = "std", feature = "libm"))]
pub use encoder::HdrEncoder;
pub use errors::{HdrDecodeErrors, HdrEncodeErrors};

mod decoder;
#[cfg(any(feature = "std", feature = "libm"))]
mod encoder;
mod errors;
21 changes: 13 additions & 8 deletions crates/zune-image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ license = "MIT OR Apache-2.0 OR Zlib"
keywords = ["image", "decoder", "encoder", "image-processing"]
categories = ["multimedia::images"]
description = "An image library, contiaining necessary capabilities to decode, manipulate and encode images"
rust-version = "1.81.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# Single based image decoders and encoders
log = ["zune-core/log"]
Expand All @@ -32,35 +35,37 @@ default = ["all"]
# Whether to use threads or not for some operations
threads = ["zune-jpegxl?/threads", "jxl-oxide?/rayon"]
# Simd support
simd = ["zune-jpeg?/x86", "zune-png?/sse", "avx2", "sse41"]
simd = ["zune-jpeg?/x86", "zune-png?/sse", "avx2", "sse41", "jpeg-encoder?/simd"]
benchmarks = []
avx2 = []
sse41 = []
std = ["zune-core/std", "zune-png?/std", "jpeg-encoder?/std", "zune-hdr?/std"]
libm = ["zune-hdr?/libm", "zune-png?/libm"]

docs = []

all = ["image_formats", "serde-support", "metadata", "threads", "simd", "log"]
all = ["image_formats", "serde-support", "metadata", "threads", "simd", "log", "std", "libm"]

[dependencies]
#zune-imageprocs = { path = "../zune-imageprocs", optional = true }
# Core primitives
zune-core = { path = "../zune-core", version = "^0.5.0-rc0", features = ["std"] }
zune-core = { path = "../zune-core", version = "^0.5.0-rc0" }
# Images
zune-png = { path = "../zune-png", version = "^0.5.0-rc0", optional = true, features = ["std"] }
zune-jpeg = { path = "../zune-jpeg", version = "^0.5.0-rc0", optional = true }
zune-png = { path = "../zune-png", version = "^0.5.0-rc0", optional = true, default-features = false }
zune-jpeg = { path = "../zune-jpeg", version = "^0.5.0-rc0", optional = true, default-features = false }
zune-ppm = { path = "../zune-ppm", version = "^0.5.0-rc0", optional = true }
zune-psd = { path = "../zune-psd", version = "^0.5.0-rc0", optional = true }
zune-farbfeld = { path = "../zune-farbfeld", version = "^0.5.0-rc0", optional = true }
zune-qoi = { path = "../zune-qoi", version = "^0.5.0-rc0", optional = true }
zune-jpegxl = { path = "../zune-jpegxl", version = "^0.5.0-rc0", optional = true }
zune-hdr = { path = "../zune-hdr", version = "^0.5.0-rc0", optional = true }
zune-hdr = { path = "../zune-hdr", version = "^0.5.0-rc0", optional = true, default-features = false }
zune-bmp = { path = "../zune-bmp", version = "^0.5.0-rc0", optional = true }
# Channel conversions in a safe way
bytemuck = { version = "1.13", default-features = false }
# Serializing info
serde = { version = "1.0.152", optional = true }
serde = { version = "1.0.152", optional = true, default-features = false }
# External image APIs
jpeg-encoder = { version = "0.6.0", optional = true, features = ["simd", "std"] }
jpeg-encoder = { version = "0.6.0", optional = true, default-features = false }
jxl-oxide = { version = "0.8.0", optional = true }
# metadata
kamadak-exif = { version = "0.5.5", optional = true }
Expand Down
Loading