Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions benches/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, Criterion};
use ispc_downsampler::{downsample, Format, Image};
use ispc_downsampler::{downsample, Format, Image, Parameters};
use resize::{px::RGB, Type::Lanczos3};
use stb_image::image::{load, LoadResult};
use std::path::Path;
Expand All @@ -17,8 +17,15 @@ pub fn ispc_downsampler(c: &mut Criterion) {
let target_width = (img.width / 4) as u32;
let target_height = (img.height / 4) as u32;

let params = Parameters {
// Input stb Image is gamma-corrected (i.e. expects to be passed through a CRT with exponent 2.2)
degamma: true,
// Output image is PNG which must be stored with a gamma of 1/2.2
gamma: true,
};
Comment on lines +20 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both of these can be merged into one parameter.


c.bench_function("Downsample `square_test.png` using ispc_downsampler", |b| {
b.iter(|| downsample(&src_img, target_width, target_height))
b.iter(|| downsample(&params, &src_img, target_width, target_height))
});
}
}
Expand Down
10 changes: 8 additions & 2 deletions examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use image::{RgbImage, RgbaImage};
use ispc_downsampler::{downsample, Format, Image};
use ispc_downsampler::{downsample, Format, Image, Parameters};
use stb_image::image::{load, LoadResult};
use std::path::Path;
use std::time::Instant;
Expand All @@ -26,7 +26,13 @@ fn main() {

let now = Instant::now();
println!("Downsampling started!");
let downsampled_pixels = downsample(&src_img, target_width, target_height);
let params = Parameters {
// Input stb Image is gamma-corrected (i.e. expects to be passed through a CRT with exponent 2.2)
degamma: false,
// Output image is PNG which must be stored with a gamma of 1/2.2
gamma: true,
};
let downsampled_pixels = downsample(&params, &src_img, target_width, target_height);
println!("Finished downsampling in {:.2?}!", now.elapsed());

std::fs::create_dir_all("example_outputs").unwrap();
Expand Down
169 changes: 162 additions & 7 deletions src/ispc/downsample_ispc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,171 @@
pub mod downsample_ispc {
/* automatically generated by rust-bindgen 0.61.0 */

#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Copy, Clone)]
pub struct uint32_t2 {
pub v: [u32; 2usize],
}
#[test]
fn bindgen_test_layout_uint32_t2() {
const UNINIT: ::std::mem::MaybeUninit<uint32_t2> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<uint32_t2>(),
16usize,
concat!("Size of: ", stringify!(uint32_t2))
);
assert_eq!(
::std::mem::align_of::<uint32_t2>(),
16usize,
concat!("Alignment of ", stringify!(uint32_t2))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(uint32_t2),
"::",
stringify!(v)
)
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Parameters {
pub degamma: bool,
pub gamma: bool,
}
#[test]
fn bindgen_test_layout_Parameters() {
const UNINIT: ::std::mem::MaybeUninit<Parameters> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<Parameters>(),
2usize,
concat!("Size of: ", stringify!(Parameters))
);
assert_eq!(
::std::mem::align_of::<Parameters>(),
1usize,
concat!("Alignment of ", stringify!(Parameters))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).degamma) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(Parameters),
"::",
stringify!(degamma)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).gamma) as usize - ptr as usize },
1usize,
concat!(
"Offset of field: ",
stringify!(Parameters),
"::",
stringify!(gamma)
)
);
}
#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Copy, Clone)]
pub struct Image {
pub data: *mut u8,
pub __bindgen_padding_0: u64,
pub size: uint32_t2,
}
#[test]
fn bindgen_test_layout_Image() {
const UNINIT: ::std::mem::MaybeUninit<Image> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<Image>(),
32usize,
concat!("Size of: ", stringify!(Image))
);
assert_eq!(
::std::mem::align_of::<Image>(),
16usize,
concat!("Alignment of ", stringify!(Image))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(Image),
"::",
stringify!(data)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(Image),
"::",
stringify!(size)
)
);
}
#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Copy, Clone)]
pub struct FloatImage {
pub data: *mut f32,
pub __bindgen_padding_0: u64,
pub size: uint32_t2,
}
#[test]
fn bindgen_test_layout_FloatImage() {
const UNINIT: ::std::mem::MaybeUninit<FloatImage> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<FloatImage>(),
32usize,
concat!("Size of: ", stringify!(FloatImage))
);
assert_eq!(
::std::mem::align_of::<FloatImage>(),
16usize,
concat!("Alignment of ", stringify!(FloatImage))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(FloatImage),
"::",
stringify!(data)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(FloatImage),
"::",
stringify!(size)
)
);
}
extern "C" {
pub fn resample(
width: u32,
height: u32,
stride: u32,
params: *const Parameters,
src: *const Image,
degamma: *mut FloatImage,
dst: *mut Image,
num_channels: u8,
target_width: u32,
target_height: u32,
src_data: *const u8,
out_data: *mut u8,
);
}
extern "C" {
Expand Down
7 changes: 6 additions & 1 deletion src/ispc/kernels/image.ispc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
struct Image {
uniform uint8* data;
uniform int<2> size;
uniform uint<2> size;
};

struct FloatImage {
uniform float* data;
uniform uint<2> size;
};
Loading