-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phase out the use of dedicated image buffers. Instead, use iterators everywhere for pixel-to-pixel usecases. Signed-off-by: Christopher N. Hesse <[email protected]>
- Loading branch information
Showing
21 changed files
with
231 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use criterion::criterion_main; | ||
|
||
mod packed; | ||
mod convert; | ||
|
||
criterion_main! { | ||
packed::convert::benches, | ||
convert::benches, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use criterion::{black_box, criterion_group, Criterion}; | ||
|
||
use ffimage::color::Rgb; | ||
use ffimage_yuv::{yuv::Yuv, yuv422::Yuv422}; | ||
|
||
pub fn rgb_to_yuv(c: &mut Criterion) { | ||
let resolutions = [(640, 480), (1280, 720)]; | ||
|
||
for res in resolutions { | ||
let rgb = vec![Rgb::<u8>([10, 10, 10]); res.0 * res.1]; | ||
let mut yuv = vec![Yuv::<u8>([0, 0, 0]); res.0 * res.1]; | ||
|
||
c.bench_function(&format!("Rgb[u8] -> Yuv[u8] ({}x{})", res.0, res.1), |b| { | ||
b.iter(|| { | ||
rgb.iter() | ||
.zip(yuv.iter_mut()) | ||
.for_each(|(rgb, yuv)| black_box(*yuv = (*rgb).into())) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
pub fn rgb_to_yuyv(c: &mut Criterion) { | ||
let resolutions = [(640, 480), (1280, 720)]; | ||
|
||
for res in resolutions { | ||
let rgb = vec![Rgb::<u8>([10, 10, 10]); res.0 * res.1]; | ||
let [mut yuv1, mut yuv2] = [Yuv::<u8>([0, 0, 0]); 2]; | ||
let mut yuyv = vec![Yuv422::<u8, 0, 2, 1, 3>([0, 0, 0, 0]); (res.0 * res.1) / 2]; | ||
|
||
c.bench_function(&format!("Rgb[u8] -> Yuyv[u8] ({}x{})", res.0, res.1), |b| { | ||
b.iter(|| { | ||
(rgb.iter().zip(rgb.iter().skip(1))) | ||
.zip(yuyv.iter_mut()) | ||
.for_each(|((rgb1, rgb2), yuyv)| { | ||
black_box(yuv1 = (*rgb1).into()); | ||
black_box(yuv2 = (*rgb2).into()); | ||
black_box(*yuyv = [yuv1, yuv2].into()); | ||
}) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, rgb_to_yuv, rgb_to_yuyv); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::ops::RangeInclusive; | ||
|
||
use ffimage::color::Rgb; | ||
|
||
use ffimage_yuv::{ | ||
yuv::Yuv, | ||
yuv422::{Yuv422, Yuyv}, | ||
}; | ||
|
||
fn make_range(val: u8, delta: u8) -> RangeInclusive<u8> { | ||
let lower = if val <= delta { 0 } else { val - delta }; | ||
let upper = if val >= 255 - delta { 255 } else { val + delta }; | ||
|
||
lower..=upper | ||
} | ||
|
||
#[test] | ||
fn convert_convert_yuy_to_yuyv() { | ||
let yuv = vec![Yuv::<u8>([10, 10, 10]); 10]; | ||
let yuyv: Vec<Yuyv<u8>> = yuv | ||
.iter() | ||
.copied() | ||
.zip(yuv.iter().copied().skip(1)) | ||
.map(|(yuv1, yuv2)| Yuyv::<u8>::from([yuv1, yuv2])) | ||
.collect(); | ||
|
||
(yuv.iter().copied().zip(yuv.iter().copied().skip(1))) | ||
.zip(yuyv.into_iter()) | ||
.for_each(|((yuv1, yuv2), yuyv)| { | ||
// one macropixel is two image pixels | ||
assert_eq!(yuyv[0], yuv1[0]); | ||
assert_eq!(yuyv[1], yuv1[1]); | ||
assert_eq!(yuyv[2], yuv2[1]); | ||
assert_eq!(yuyv[3], yuv1[2]); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn convert_convert_yuyv_to_yuv() { | ||
let yuyv = vec![Yuv422::<u8, 0, 2, 1, 3>([10, 10, 10, 10]); 10]; | ||
let yuv: Vec<Yuv<u8>> = yuyv | ||
.iter() | ||
.copied() | ||
.map(|yuyv| <[Yuv<u8>; 2]>::from(yuyv)) | ||
.flatten() | ||
.collect(); | ||
|
||
yuyv.iter() | ||
.copied() | ||
.zip(yuv.iter().copied().zip(yuv.iter().copied().skip(1))) | ||
.for_each(|(yuyv, (yuv1, yuv2))| { | ||
// one macropixel is two image pixels | ||
assert_eq!(yuv1[0], yuyv[0]); | ||
assert_eq!(yuv1[1], yuyv[1]); | ||
assert_eq!(yuv2[0], yuyv[2]); | ||
assert_eq!(yuv1[2], yuyv[3]); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn convert_rgb_to_yuv_to_rgb() { | ||
let rgb_in = vec![Rgb::<u8>([10, 10, 10]); 10]; | ||
let yuv: Vec<Yuv<u8>> = rgb_in | ||
.iter() | ||
.copied() | ||
.map(|rgb| Yuv::<u8>::from(rgb)) | ||
.collect(); | ||
let rgb_out: Vec<Rgb<u8>> = yuv | ||
.iter() | ||
.copied() | ||
.map(|yuv| Rgb::<u8>::from(yuv)) | ||
.collect(); | ||
|
||
rgb_in | ||
.into_iter() | ||
.zip(rgb_out.into_iter()) | ||
.for_each(|(rgb_in, rgb_out)| { | ||
let r_range = make_range(rgb_in[0], 1); | ||
let g_range = make_range(rgb_in[1], 1); | ||
let b_range = make_range(rgb_in[2], 1); | ||
assert!(r_range.contains(&rgb_out[0])); | ||
assert!(g_range.contains(&rgb_out[1])); | ||
assert!(b_range.contains(&rgb_out[2])); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use criterion::criterion_main; | ||
|
||
mod packed; | ||
mod convert; | ||
|
||
criterion_main! { | ||
packed::convert::benches, | ||
convert::benches, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use criterion::{black_box, criterion_group, Criterion}; | ||
|
||
use ffimage::color::{Gray, Rgb}; | ||
|
||
pub fn rgb_to_bgr(c: &mut Criterion) { | ||
let resolutions = [(640, 480), (1280, 720)]; | ||
|
||
for res in resolutions { | ||
let rgb = vec![Rgb::<u8>([10, 10, 10]); res.0 * res.1]; | ||
let mut bgr = vec![Rgb::<u8, 2, 1, 0>([0, 0, 0]); res.0 * res.1]; | ||
|
||
c.bench_function(&format!("Rgb[u8] -> Bgr[u8] ({}x{})", res.0, res.1), |b| { | ||
b.iter(|| { | ||
rgb.iter() | ||
.zip(bgr.iter_mut()) | ||
.for_each(|(rgb, bgr)| black_box(*bgr = (*rgb).into())) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
pub fn rgb_to_gray(c: &mut Criterion) { | ||
let resolutions = [(640, 480), (1280, 720)]; | ||
|
||
for res in resolutions { | ||
let rgb = vec![Rgb::<u8>([10, 10, 10]); res.0 * res.1]; | ||
let mut gray = vec![Gray::<u8>([0]); res.0 * res.1]; | ||
|
||
c.bench_function(&format!("Rgb[u8] -> Gray[u8] ({}x{})", res.0, res.1), |b| { | ||
b.iter(|| { | ||
rgb.iter() | ||
.zip(gray.iter_mut()) | ||
.for_each(|(rgb, gray)| black_box(*gray = (*rgb).into())) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, rgb_to_bgr, rgb_to_gray); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.