Skip to content

Commit 4565425

Browse files
committed
refactor!: update Pixel subtraits
- decouple from num_traits - remove arithmetics over Pixel - add all std formatting - add minimal conversions
1 parent b8f193c commit 4565425

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ edition = "2024"
99
repository = "https://github.com/rust-av/v_frame"
1010
include = ["Cargo.toml", "README.md", "LICENSE", "src"]
1111

12-
[dependencies]
13-
num-traits = "0.2.19"
14-
1512
[features]
1613
padding_api = []
1714

src/pixel.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
//! - 8-bit frames must use `u8`
2323
//! - 9-16 bit frames must use `u16`
2424
25-
use num_traits::PrimInt;
26-
use std::fmt::Debug;
25+
use core::fmt::{Binary, Debug, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex};
26+
use core::hash::Hash;
2727

2828
mod private {
2929
pub trait Sealed {}
@@ -56,7 +56,36 @@ mod private {
5656
/// i.e. using [`std::mem::zeroed`] must __not__ cause undefined behavior for
5757
/// implementing types.
5858
pub unsafe trait Pixel:
59-
Debug + Copy + Clone + Default + Send + Sync + PrimInt + 'static + private::Sealed
59+
Sized
60+
+ Copy
61+
+ Clone
62+
// formatting
63+
+ Display
64+
+ Debug
65+
+ Octal
66+
+ LowerHex
67+
+ UpperHex
68+
+ LowerExp
69+
+ UpperExp
70+
+ Binary
71+
+ Default
72+
// comparisons
73+
+ PartialEq
74+
+ Eq
75+
+ PartialOrd
76+
+ Ord
77+
// conversions
78+
+ TryInto<u8, Error: core::error::Error>
79+
+ Into<u16>
80+
+ From<u8>
81+
+ TryFrom<u16, Error: core::error::Error>
82+
// markers
83+
+ Send
84+
+ Sync
85+
// misc.
86+
+ Hash
87+
+ 'static
88+
+ private::Sealed
6089
{
6190
}
6291

src/plane.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,9 @@ impl<T: Pixel> Plane<T> {
331331

332332
let total = self.width() * self.height() * byte_width;
333333
ExactSizeWrapper {
334-
iter: self.pixels().flat_map(move |pix| {
335-
let bytes: [u8; 2] = if byte_width == 1 {
336-
[
337-
pix.to_u8()
338-
.expect("Pixel::byte_data only supports u8 and u16 pixels"),
339-
0,
340-
]
341-
} else {
342-
pix.to_u16()
343-
.expect("Pixel::byte_data only supports u8 and u16 pixels")
344-
.to_le_bytes()
345-
};
346-
bytes.into_iter().take(byte_width)
347-
}),
334+
iter: self
335+
.pixels()
336+
.flat_map(move |pix| pix.into().to_le_bytes().into_iter().take(byte_width)),
348337
len: total,
349338
}
350339
}

0 commit comments

Comments
 (0)