-
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.
Make use of the new Pixels, ColorConvert and Write facilities. Signed-off-by: Christopher N. Hesse <raymanfx@gmail.com>
- Loading branch information
Showing
2 changed files
with
50 additions
and
34 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,45 +1,54 @@ | ||
use criterion::{black_box, criterion_group, Criterion}; | ||
|
||
use ffimage::color::Rgb; | ||
use ffimage::{ | ||
color::Rgb, | ||
iter::{ColorConvertExt, PixelsExt, WriteExt}, | ||
}; | ||
use ffimage_yuv::{yuv::Yuv, yuv422::Yuv422}; | ||
|
||
pub fn rgb_to_yuv(c: &mut Criterion) { | ||
pub fn yuv_to_rgb(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]; | ||
let yuv = vec![10; res.0 * res.1 * 3]; | ||
let mut rgb = vec![10; res.0 * res.1 * 3]; | ||
|
||
c.bench_function(&format!("Rgb[u8] -> Yuv[u8] ({}x{})", res.0, res.1), |b| { | ||
c.bench_function(&format!("Yuv[u8] -> Rgb[u8] ({}x{})", res.0, res.1), |b| { | ||
b.iter(|| { | ||
rgb.iter() | ||
.zip(yuv.iter_mut()) | ||
.for_each(|(rgb, yuv)| black_box(*yuv = (*rgb).into())) | ||
yuv.iter() | ||
.copied() | ||
.pixels::<Yuv<u8>>() | ||
.colorconvert::<Rgb<u8>>() | ||
.write(black_box(&mut rgb)) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
pub fn rgb_to_yuyv(c: &mut Criterion) { | ||
pub fn yuv422_to_rgb(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()); | ||
}) | ||
}) | ||
}); | ||
let yuv422 = vec![10; res.0 * res.1 * 2]; | ||
let mut rgb = vec![10; res.0 * res.1 * 3]; | ||
|
||
c.bench_function( | ||
&format!("Yuv422[u8] -> Rgb[u8] ({}x{})", res.0, res.1), | ||
|b| { | ||
b.iter(|| { | ||
yuv422 | ||
.iter() | ||
.copied() | ||
.pixels::<Yuv422<u8, 0, 2, 1, 3>>() | ||
.colorconvert::<[Yuv<u8>; 2]>() | ||
.map(|yuv422| <[Yuv<u8>; 2]>::from(yuv422)) | ||
.flatten() | ||
.map(|yuv| Rgb::<u8>::from(yuv)) | ||
.write(&mut rgb); | ||
}) | ||
}, | ||
); | ||
} | ||
} | ||
|
||
criterion_group!(benches, rgb_to_yuv, rgb_to_yuyv); | ||
criterion_group!(benches, yuv_to_rgb, yuv422_to_rgb); |
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