From b8bfa9f4f89a6b759b9c34c974c17e70df6bae06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20H=C3=B6ser?= Date: Fri, 1 Nov 2024 04:15:40 +0100 Subject: [PATCH] Add optional serde feature for image::ImageFormat (#2374) --- Cargo.toml | 2 ++ src/image.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 7cd5fbdf60..90c01e7e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,7 @@ rgb = { version = "0.8.48", default-features = false, optional = true } tiff = { version = "0.9.0", optional = true } zune-core = { version = "0.4.12", default-features = false, optional = true } zune-jpeg = { version = "0.4.13", optional = true } +serde = { version = "1.0.214", optional = true, features = ["derive"] } [dev-dependencies] crc32fast = "1.2.0" @@ -92,6 +93,7 @@ nasm = ["ravif?/asm"] # Enables use of nasm by rav1e (requires nasm to be instal color_quant = ["dep:color_quant"] # Enables color quantization avif-native = ["dep:mp4parse", "dep:dcv-color-primitives", "dep:dav1d"] # Enable native dependency libdav1d benchmarks = [] # Build some inline benchmarks. Useful only during development (requires nightly Rust) +serde = ["dep:serde"] [[bench]] path = "benches/decode.rs" diff --git a/src/image.rs b/src/image.rs index 81aebbd083..b150e41519 100644 --- a/src/image.rs +++ b/src/image.rs @@ -5,6 +5,9 @@ use std::mem::size_of; use std::ops::{Deref, DerefMut}; use std::path::Path; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + use crate::color::{ColorType, ExtendedColorType}; use crate::error::{ ImageError, ImageFormatHint, ImageResult, LimitError, LimitErrorKind, ParameterError, @@ -20,6 +23,7 @@ use crate::animation::Frames; /// An enumeration of supported image formats. /// Not all formats support both encoding and decoding. #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[non_exhaustive] pub enum ImageFormat { /// An Image in PNG Format