Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for compressing bc6h #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ispc = ["ispc_compile", "cc"]
[dev-dependencies]
ddsfile = "0.5.0"
image = "0.25.1"
half = "2.4.1"

[profile.release]
lto = true
Expand Down
30 changes: 30 additions & 0 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use image::LumaA;
use image::Pixel;
use intel_tex_2::bc4;
use intel_tex_2::bc5;
use intel_tex_2::bc6h;
use intel_tex_2::bc7;
use std::fs::File;
use std::path::Path;
Expand Down Expand Up @@ -93,6 +94,35 @@ fn main() {
let mut dds_file = File::create("examples/lambertian_bc5.dds").unwrap();
dds.write(&mut dds_file).expect("Failed to write dds file");
}
// BC6
{
let mut dds = Dds::new_dxgi(NewDxgiParams {
format: DxgiFormat::BC6H_UF16,
..dds_defaults
})
.unwrap();
let rgba_f16_data: Vec<u8> = rgba_img
.iter()
.flat_map(|c| half::f16::from_f32(*c as f32 / 255.0).to_le_bytes())
.collect();
let surface = intel_tex_2::RgbaSurface {
width,
height,
stride: width * 4 * std::mem::size_of::<half::f16>() as u32,
data: &rgba_f16_data,
};

println!("Compressing to BC6...");
bc6h::compress_blocks_into(
&bc6h::very_fast_settings(),
&surface,
dds.get_mut_data(0 /* layer */).unwrap(),
);
println!(" Done!");
println!("Saving lambertian_bc6.dds file");
let mut dds_file = File::create("examples/lambertian_bc6.dds").unwrap();
dds.write(&mut dds_file).expect("Failed to write dds file");
}
// BC7
{
let mut dds = Dds::new_dxgi(NewDxgiParams {
Expand Down
Loading