Skip to content

Commit

Permalink
Merge pull request #141
Browse files Browse the repository at this point in the history
Make log optional
  • Loading branch information
etemesi254 authored Oct 4, 2023
2 parents 62969db + 3a5fe04 commit f0a87e7
Show file tree
Hide file tree
Showing 56 changed files with 144 additions and 52 deletions.
4 changes: 3 additions & 1 deletion zune-bmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"

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

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

[dependencies]
zune-core = { version = "0.2", path = "../zune-core" }
log = "0.4.17"
2 changes: 1 addition & 1 deletion zune-bmp/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
use alloc::vec::Vec;
use alloc::{format, vec};

use log::{trace, warn};
use zune_core::log::{trace, warn};
use zune_core::bit_depth::BitDepth;
use zune_core::bytestream::{ZByteReader, ZReaderTrait};
use zune_core::colorspace::ColorSpace;
Expand Down
1 change: 1 addition & 0 deletions zune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ license = "MIT OR Apache-2.0 OR Zlib"
std = []

[dependencies]
log = { version = "0.4.17", optional = true }
serde = { version = "1.0.52", optional = true }
6 changes: 6 additions & 0 deletions zune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
#![macro_use]
extern crate alloc;

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

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

pub mod bit_depth;
pub mod bytestream;
pub mod colorspace;
Expand Down
68 changes: 68 additions & 0 deletions zune-core/src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#[repr(usize)]
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
pub enum Level {
Error = 1,
Warn,
Info,
Debug,
Trace,
}

#[doc(hidden)]
#[macro_export]
macro_rules! __log_enabled {
($lvl:expr) => {{
let _ = $lvl;
false
}}
}

#[doc(hidden)]
#[macro_export]
macro_rules! __error {
($($arg:tt)+) => (
#[cfg(feature = "std")]
{
panic!($($arg)+);
}
)
}

#[doc(hidden)]
#[macro_export]
macro_rules! __warn {
($($arg:tt)+) => (
#[cfg(feature = "std")]
{
panic!($($arg)+);
}
)
}

#[doc(hidden)]
#[macro_export]
macro_rules! __info {
($($arg:tt)+) => {};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __debug {
($($arg:tt)+) => {};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __trace {
($($arg:tt)+) => {};
}

// #[macro_export] is required to make macros works across crates
// but it always put the macro in the crate root.
// #[doc(hidden)] + "pub use" is a workaround to namespace a macro.
pub use crate::__error as error;
pub use crate::__warn as warn;
pub use crate::__info as info;
pub use crate::__debug as debug;
pub use crate::__trace as trace;
pub use crate::__log_enabled as log_enabled;
4 changes: 3 additions & 1 deletion zune-farbfeld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ categories = ["multimedia::images", "multimedia::encoding"]
license = "MIT OR Apache-2.0 OR Zlib"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

[dependencies]
zune-core = { path = "../zune-core", version = "0.2" }
log = "0.4.17"
2 changes: 1 addition & 1 deletion zune-farbfeld/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use alloc::vec;
use alloc::vec::Vec;

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitDepth;
use zune_core::bytestream::{ZByteReader, ZReaderTrait};
use zune_core::colorspace::ColorSpace;
Expand Down
4 changes: 3 additions & 1 deletion zune-hdr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"

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

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

[dependencies]
zune-core = { version = "0.2.13", path = "../zune-core" }
log = "0.4.17"
2 changes: 1 addition & 1 deletion zune-hdr/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::iter::Iterator;
use core::option::Option::{self, *};
use core::result::Result::{self, *};

use log::trace;
use zune_core::log::trace;
use zune_core::bytestream::{ZByteReader, ZReaderTrait};
use zune_core::colorspace::ColorSpace;
use zune_core::options::DecoderOptions;
Expand Down
6 changes: 2 additions & 4 deletions zune-image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# 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"]
ppm = ["zune-ppm"]
jpeg = ["zune-jpeg", "jpeg-encoder"]
png = ["zune-png"]
Expand All @@ -15,7 +16,6 @@ qoi = ["zune-qoi"]
jpeg-xl = ["zune-jpegxl"]
hdr = ["zune-hdr"]
bmp = ["zune-bmp"]

# Serde serialization support
serde-support = ["zune-core/serde", "serde"]
# All image formats
Expand All @@ -31,7 +31,7 @@ threads = ["zune-jpegxl/threads"]
# Simd support
simd = ["zune-jpeg/x86", "zune-png/sse", "zune-imageprocs/avx2", "zune-imageprocs/sse2", "zune-imageprocs/sse3", "zune-imageprocs/sse41"]

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

[dependencies]
zune-imageprocs = { path = "../zune-imageprocs", optional = true }
Expand All @@ -47,8 +47,6 @@ zune-qoi = { path = "../zune-qoi", optional = true }
zune-jpegxl = { path = "../zune-jpegxl", optional = true }
zune-hdr = { path = "../zune-hdr", optional = true }
zune-bmp = { path = "../zune-bmp", optional = true }
# Logging information
log = "0.4.17"
# Channel conversions in a safe way
bytemuck = { version = "1.13.1", default-features = false }
# Serializing info
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

use std::path::Path;

use log::trace;
use zune_core::log::trace;
use zune_core::bytestream::{ZByteReader, ZReaderTrait};
use zune_core::options::{DecoderOptions, EncoderOptions};

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/codecs/jpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! The decoder and encoder both support metadata extraction and saving.
//!
use jpeg_encoder::{ColorType, EncodingError};
use log::warn;
use zune_core::log::warn;
use zune_core::bit_depth::BitDepth;
use zune_core::bytestream::ZReaderTrait;
use zune_core::colorspace::ColorSpace;
Expand Down
3 changes: 2 additions & 1 deletion zune-image/src/codecs/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use zune_core::bytestream::ZReaderTrait;
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
use zune_core::result::DecodingResult;
use zune_core::log::warn;
pub use zune_png::*;

use crate::codecs::{create_options_for_encoder, ImageFormat};
Expand Down Expand Up @@ -153,7 +154,7 @@ impl EncoderTrait for PngEncoder {
if result.is_ok() {
encoder.add_exif_segment(buf.get_ref());
} else {
log::warn!("Writing exif failed {:?}", result);
warn!("Writing exif failed {:?}", result);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/core_filters/colorspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! This contains simple colorspace conversion routines
//! that convert between different colorspaces in image
//!
use log::warn;
use zune_core::log::warn;
use zune_core::bit_depth::BitType;
use zune_core::colorspace::{ColorSpace, ALL_COLORSPACES};

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/core_filters/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! when moving from `BitDepth::Eight` to `BitDepth::F32`, the library will automatically
//! divide all pixels by `255.0` after converting them to f32's
//!
use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::{BitDepth, BitType};

use crate::channel::Channel;
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/box_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::box_blur::{box_blur_f32, box_blur_u16, box_blur_u8};

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#![allow(dead_code)]

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::convolve::convolve;

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::gamma::gamma;

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/gaussian_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::gaussian_blur::{gaussian_blur_f32, gaussian_blur_u16, gaussian_blur_u8};

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::median::median;

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#![cfg(feature = "metadata")]

use log::warn;
use zune_core::log::warn;
use zune_core::bit_depth::BitType;

use crate::errors::ImageErrors;
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/premul_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! Change image from pre-multiplied alpha to
//! un-premultiplied alpha and vice versa
use log::warn;
use zune_core::log::warn;
use zune_core::bit_depth::{BitDepth, BitType};
use zune_imageprocs::premul_alpha::{
create_unpremul_table_u16, create_unpremul_table_u8, premultiply_f32, premultiply_u16,
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::spatial_ops::spatial_ops;
pub use zune_imageprocs::spatial_ops::StatisticOperations;
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::warn;
use zune_core::log::warn;
use zune_core::bit_depth::BitType;
use zune_imageprocs::threshold::threshold;
pub use zune_imageprocs::threshold::ThresholdMethod;
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/filters/unsharpen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::BitType;
use zune_imageprocs::unsharpen::{unsharpen_u16, unsharpen_u8};

Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/metadata/exif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#![cfg(feature = "metadata")]

use log::{error, trace};
use zune_core::log::{error, trace};

use crate::image::Image;
use crate::metadata::ImageMetadata;
Expand Down
2 changes: 1 addition & 1 deletion zune-image/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This software is free software; You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::trace;
use zune_core::log::trace;
use zune_core::bit_depth::{BitDepth, BitType};
use zune_core::bytestream::ZReaderTrait;
use zune_core::colorspace::{ColorSpace, ALL_COLORSPACES};
Expand Down
4 changes: 2 additions & 2 deletions zune-image/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use std::time::Instant;

use log::Level::Trace;
use log::{log_enabled, trace, Level};
use zune_core::log::Level::Trace;
use zune_core::log::{log_enabled, trace, Level};

use crate::codecs::ImageFormat;
use crate::errors::ImageErrors;
Expand Down
4 changes: 2 additions & 2 deletions zune-imageprocs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log="0.4.17"
zune-core = { path = "../zune-core", version = "0.2" }


[features]
Expand All @@ -16,7 +16,7 @@ sse3 = []
sse41 = []
## Needs nightly, disabled by default
benchmarks=[]

log = ["zune-core/log"]
default = ["avx2", "sse2", "sse3", "sse41"]


Expand Down
2 changes: 1 addition & 1 deletion zune-imageprocs/src/box_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use std::f32;

use log::warn;
use zune_core::log::warn;

use crate::mathops::{compute_mod_u32, fastdiv_u32};
use crate::traits::NumOps;
Expand Down
2 changes: 1 addition & 1 deletion zune-imageprocs/src/convolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
*/

use log::error;
use zune_core::log::error;

use crate::pad::{pad, PadMethod};
use crate::traits::NumOps;
Expand Down
2 changes: 1 addition & 1 deletion zune-imageprocs/src/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use std::sync::Once;

use log::trace;
use zune_core::log::trace;

use crate::transpose::scalar::transpose_scalar;

Expand Down
Loading

0 comments on commit f0a87e7

Please sign in to comment.