|
3 | 3 | //! Converts RGBA images to 8-bit with alpha channel. |
4 | 4 | //! |
5 | 5 | //! See `examples/` directory for example code. |
| 6 | +#![cfg_attr(all(not(feature = "std"), feature = "no_std"), no_std)] |
| 7 | + |
6 | 8 | #![doc(html_logo_url = "https://pngquant.org/pngquant-logo.png")] |
7 | 9 | #![deny(missing_docs)] |
8 | 10 | #![allow(clippy::bool_to_int_with_if)] |
|
19 | 21 | #![allow(clippy::wildcard_imports)] |
20 | 22 | #![deny(clippy::semicolon_if_nothing_returned)] |
21 | 23 |
|
| 24 | +#[cfg(all(not(feature = "std"), feature = "no_std"))] |
| 25 | +extern crate alloc as std; |
| 26 | + |
| 27 | +#[cfg(all(not(feature = "std"), feature = "no_std"))] |
| 28 | +use std::vec::Vec; |
| 29 | + |
22 | 30 | mod attr; |
23 | 31 | mod blur; |
24 | 32 | mod error; |
@@ -138,8 +146,8 @@ fn poke_it() { |
138 | 146 | assert_eq!(1, liq.min_posterization()); |
139 | 147 | liq.set_min_posterization(0).unwrap(); |
140 | 148 |
|
141 | | - use std::sync::atomic::AtomicBool; |
142 | | - use std::sync::atomic::Ordering::SeqCst; |
| 149 | + use core::sync::atomic::AtomicBool; |
| 150 | + use core::sync::atomic::Ordering::SeqCst; |
143 | 151 | use std::sync::Arc; |
144 | 152 |
|
145 | 153 | let log_called = Arc::new(AtomicBool::new(false)); |
@@ -204,8 +212,8 @@ fn thread() { |
204 | 212 | #[test] |
205 | 213 | fn r_callback_test() { |
206 | 214 | use core::mem::MaybeUninit; |
207 | | - use std::sync::atomic::AtomicU16; |
208 | | - use std::sync::atomic::Ordering::SeqCst; |
| 215 | + use core::sync::atomic::AtomicU16; |
| 216 | + use core::sync::atomic::Ordering::SeqCst; |
209 | 217 | use std::sync::Arc; |
210 | 218 |
|
211 | 219 | let called = Arc::new(AtomicU16::new(0)); |
@@ -349,3 +357,56 @@ fn test_fixed_colors() { |
349 | 357 | assert!(pal[55..].iter().any(|&p| p == RGBA::new(c, c, c, 255))); |
350 | 358 | } |
351 | 359 | } |
| 360 | + |
| 361 | +#[cfg(all(not(feature = "std"), feature = "no_std"))] |
| 362 | +pub(crate) mod no_std_compat { |
| 363 | + pub use std::boxed::Box; |
| 364 | + pub use std::vec::Vec; |
| 365 | + pub use std::format; |
| 366 | + |
| 367 | + extern "C" { |
| 368 | + fn pow(_: f64, _: f64) -> f64; |
| 369 | + fn powf(_: f32, _: f32) -> f32; |
| 370 | + fn sqrt(_: f64) -> f64; |
| 371 | + fn sqrtf(_: f32) -> f32; |
| 372 | + } |
| 373 | + |
| 374 | + pub(crate) trait NoMath: Sized { |
| 375 | + fn mul_add(self, mul: Self, add: Self) -> Self; |
| 376 | + fn powi(self, n: u32) -> Self; |
| 377 | + fn powf(self, e: Self) -> Self; |
| 378 | + fn sqrt(self) -> Self; |
| 379 | + } |
| 380 | + |
| 381 | + impl NoMath for f32 { |
| 382 | + fn mul_add(self, mul: Self, add: Self) -> Self { |
| 383 | + self * mul + add |
| 384 | + } |
| 385 | + fn powi(self, n: u32) -> Self { |
| 386 | + assert_eq!(n, 2); |
| 387 | + self * self |
| 388 | + } |
| 389 | + fn powf(self, e: Self) -> Self { |
| 390 | + unsafe { powf(self, e) } |
| 391 | + } |
| 392 | + fn sqrt(self) -> Self { |
| 393 | + unsafe { sqrtf(self) } |
| 394 | + } |
| 395 | + } |
| 396 | + |
| 397 | + impl NoMath for f64 { |
| 398 | + fn mul_add(self, mul: Self, add: Self) -> Self { |
| 399 | + self * mul + add |
| 400 | + } |
| 401 | + fn powi(self, n: u32) -> Self { |
| 402 | + assert_eq!(n, 2); |
| 403 | + self * self |
| 404 | + } |
| 405 | + fn powf(self, e: Self) -> Self { |
| 406 | + unsafe { pow(self, e) } |
| 407 | + } |
| 408 | + fn sqrt(self) -> Self { |
| 409 | + unsafe { sqrt(self) } |
| 410 | + } |
| 411 | + } |
| 412 | +} |
0 commit comments