| 1 | /* |
| 2 | * Copyright (c) 2023. |
| 3 | * |
| 4 | * This software is free software; |
| 5 | * |
| 6 | * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license |
| 7 | */ |
| 8 | |
| 9 | #![cfg(feature = "serde")] |
| 10 | //! Serde support for serializing |
| 11 | //! crate datastructures |
| 12 | //! |
| 13 | //! Implements serialize for |
| 14 | //! - ColorSpace |
| 15 | //! - BitDepth |
| 16 | //! - ColorCharacteristics |
| 17 | use alloc::format; |
| 18 | |
| 19 | use serde::ser::*; |
| 20 | |
| 21 | use crate::bit_depth::BitDepth; |
| 22 | use crate::colorspace::{ColorCharacteristics, ColorSpace, RenderingIntent}; |
| 23 | |
| 24 | impl Serialize for ColorSpace { |
| 25 | #[allow(clippy::uninlined_format_args)] |
| 26 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 27 | where |
| 28 | S: Serializer |
| 29 | { |
| 30 | // colorspace serialization is simply it's debug value |
| 31 | serializer.serialize_str(&format!("{:?}", self)) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl Serialize for BitDepth { |
| 36 | #[allow(clippy::uninlined_format_args)] |
| 37 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 38 | where |
| 39 | S: Serializer |
| 40 | { |
| 41 | serializer.serialize_str(&format!("{:?}", self)) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl Serialize for ColorCharacteristics { |
| 46 | #[allow(clippy::uninlined_format_args)] |
| 47 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 48 | where |
| 49 | S: Serializer |
| 50 | { |
| 51 | serializer.serialize_str(&format!("{:?}", self)) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl Serialize for RenderingIntent { |
| 56 | #[allow(clippy::uninlined_format_args)] |
| 57 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 58 | where |
| 59 | S: Serializer |
| 60 | { |
| 61 | serializer.serialize_str(&format!("{:?}", self)) |
| 62 | } |
| 63 | } |