Skip to content

Commit 0223e64

Browse files
Charlie-Zhengralfbiedert
authored andcommitted
Run cargo clippy --fix
1 parent 4966c4b commit 0223e64

5 files changed

Lines changed: 29 additions & 30 deletions

File tree

openh264-sys2/build.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Target {
7575
"unix" => TargetFamily::Unix,
7676
"windows" => TargetFamily::Windows,
7777
"wasm" => TargetFamily::Wasm,
78-
_ => panic!("Unknown target family: {}", family),
78+
_ => panic!("Unknown target family: {family}"),
7979
};
8080
let os = match os.as_str() {
8181
"windows" => TargetOs::Windows,
@@ -87,7 +87,7 @@ impl Target {
8787
"dragonfly" => TargetOs::Dragonfly,
8888
"openbsd" => TargetOs::Openbsd,
8989
"netbsd" => TargetOs::Netbsd,
90-
_ => panic!("Unknown target os: {}", os),
90+
_ => panic!("Unknown target os: {os}"),
9191
};
9292
let arch = match arch.as_str() {
9393
"x86" => TargetArch::X86,
@@ -99,15 +99,15 @@ impl Target {
9999
"powerpc64" => TargetArch::Powerpc64,
100100
"s390x" => TargetArch::S390x,
101101
"wasm32" => TargetArch::Wasm32,
102-
_ => panic!("Unknown target arch: {}", arch),
102+
_ => panic!("Unknown target arch: {arch}"),
103103
};
104104
let env = match env.as_str() {
105105
"" => TargetEnv::NoEnv,
106106
"gnu" => TargetEnv::Gnu,
107107
"msvc" => TargetEnv::Msvc,
108108
"musl" => TargetEnv::Musl,
109109
"sgx" => TargetEnv::Sgx,
110-
_ => panic!("Unknown target env: {}", env),
110+
_ => panic!("Unknown target env: {env}"),
111111
};
112112

113113
Self { family, os, arch, env }
@@ -225,8 +225,7 @@ fn try_compile_nasm(cc_build_command: &mut Build, root: &str) {
225225

226226
let Some(config) = NasmConfiguration::find(target) else {
227227
println!(
228-
"No NASM configuration found for target, not using any assembly.\nTarget: {:?}",
229-
target
228+
"No NASM configuration found for target, not using any assembly.\nTarget: {target:?}"
230229
);
231230
return;
232231
};
@@ -295,9 +294,9 @@ fn compile_and_add_openh264_static_lib(name: &str, root: &str, includes: &[&str]
295294
cc_build.include(include);
296295
}
297296

298-
cc_build.compile(format!("openh264_{}", name).as_str());
297+
cc_build.compile(format!("openh264_{name}").as_str());
299298

300-
println!("cargo:rustc-link-lib=static=openh264_{}", name);
299+
println!("cargo:rustc-link-lib=static=openh264_{name}");
301300
}
302301

303302
fn main() {

openh264-sys2/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Display for Error {
3333
#[cfg(feature = "libloading")]
3434
Error::LibLoading(x) => x.fmt(f),
3535
Error::Io(x) => x.fmt(f),
36-
Error::InvalidHash(x) => format!("Invalid hash: {}", x).fmt(f),
36+
Error::InvalidHash(x) => format!("Invalid hash: {x}").fmt(f),
3737
_ => "".fmt(f),
3838
}
3939
}

openh264/src/decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl Decoder {
295295

296296
#[rustfmt::skip]
297297
unsafe {
298-
raw_api.initialize(&config.params).ok()?;
298+
raw_api.initialize(&raw const config.params).ok()?;
299299
raw_api.set_option(DECODER_OPTION_TRACE_LEVEL, addr_of_mut!(config.debug).cast()).ok()?;
300300
raw_api.set_option(DECODER_OPTION_NUM_OF_THREADS, addr_of_mut!(config.num_threads).cast()).ok()?;
301301
raw_api.set_option(DECODER_OPTION_ERROR_CON_IDC, addr_of_mut!(config.error_concealment).cast()).ok()?;
@@ -347,7 +347,7 @@ impl Decoder {
347347
packet.as_ptr(),
348348
packet.len() as i32,
349349
from_mut(&mut dst).cast(),
350-
&mut buffer_info,
350+
&raw mut buffer_info,
351351
)
352352
.ok()?;
353353
}
@@ -387,7 +387,7 @@ impl Decoder {
387387

388388
if let Some(image) = unsafe { DecodedYUV::from_raw_open264_ptrs(&dst, &buffer_info) } {
389389
frames.push(image);
390-
};
390+
}
391391
}
392392

393393
Ok(frames)
@@ -419,7 +419,7 @@ impl Decoder {
419419
/// # Ok(())
420420
/// # }
421421
/// ```
422-
pub unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI {
422+
pub const unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI {
423423
&mut self.raw_api
424424
}
425425

@@ -444,7 +444,7 @@ impl Decoder {
444444
let mut buffer_info = SBufferInfo::default();
445445

446446
unsafe {
447-
self.raw_api().flush_frame(from_mut(&mut dst).cast(), &mut buffer_info).ok()?;
447+
self.raw_api().flush_frame(from_mut(&mut dst).cast(), &raw mut buffer_info).ok()?;
448448
Ok((dst, buffer_info))
449449
}
450450
}

openh264/src/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl Encoder {
696696
};
697697

698698
unsafe {
699-
self.raw_api.encode_frame(&source, &mut self.bit_stream_info).ok()?;
699+
self.raw_api.encode_frame(&raw const source, &raw mut self.bit_stream_info).ok()?;
700700
}
701701

702702
Ok(EncodedBitStream {
@@ -721,7 +721,7 @@ impl Encoder {
721721

722722
let mut params = SEncParamExt::default();
723723

724-
unsafe { self.raw_api.get_default_params(&mut params).ok()? };
724+
unsafe { self.raw_api.get_default_params(&raw mut params).ok()? };
725725

726726
params.iPicWidth = width as c_int; // If we do .into() instead, could this fail to compile on some platforms?
727727
params.iPicHeight = height as c_int; // If we do .into() instead, could this fail to compile on some platforms?
@@ -776,7 +776,7 @@ impl Encoder {
776776
unsafe {
777777
if self.previous_dimensions.is_none() {
778778
// First time we call initialize_ext
779-
self.raw_api.initialize_ext(&params).ok()?;
779+
self.raw_api.initialize_ext(&raw const params).ok()?;
780780
self.raw_api.set_option(ENCODER_OPTION_TRACE_LEVEL, addr_of_mut!(self.config.debug).cast()).ok()?;
781781
self.raw_api.set_option(ENCODER_OPTION_DATAFORMAT, addr_of_mut!(self.config.data_format).cast()).ok()?;
782782
} else {
@@ -807,7 +807,7 @@ impl Encoder {
807807
/// # Safety
808808
///
809809
/// You must not set parameters the encoder relies on, we recommend checking the source.
810-
pub unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI {
810+
pub const unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI {
811811
&mut self.raw_api
812812
}
813813
}
@@ -893,7 +893,7 @@ impl<'a> EncodedBitStream<'a> {
893893
return Err(Error::msg(&format!("failed to write: {e}")));
894894
}
895895
_ => {}
896-
};
896+
}
897897
}
898898
}
899899
Ok(())

openh264/src/formats/yuv2rgb.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ macro_rules! f32x8_from_slice_with_blocksize {
2020
}};
2121
}
2222

23-
pub(crate) const Y_MUL: f32 = 255.0 / 219.0;
24-
pub(crate) const RV_MUL: f32 = 255.0 / 224.0 * 1.402;
25-
pub(crate) const GV_MUL: f32 = -255.0 / 224.0 * 1.402 * 0.299 / 0.687;
26-
pub(crate) const GU_MUL: f32 = -255.0 / 224.0 * 1.772 * 0.114 / 0.587;
27-
pub(crate) const BU_MUL: f32 = 255.0 / 224.0 * 1.772;
23+
const Y_MUL: f32 = 255.0 / 219.0;
24+
const RV_MUL: f32 = 255.0 / 224.0 * 1.402;
25+
const GV_MUL: f32 = -255.0 / 224.0 * 1.402 * 0.299 / 0.687;
26+
const GU_MUL: f32 = -255.0 / 224.0 * 1.772 * 0.114 / 0.587;
27+
const BU_MUL: f32 = 255.0 / 224.0 * 1.772;
2828

2929
/// Write RGB8 data from YUV420 using scalar (non SIMD) math.
3030
pub fn write_rgb8_scalar(
@@ -46,9 +46,9 @@ pub fn write_rgb8_scalar(
4646

4747
// Convert limited range YUV to RGB
4848
// https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion
49-
let y_mul = Y_MUL * (y_plane[base_y] as f32 - 16.0);
50-
let u = u_plane[base_u] as f32 - 128.0;
51-
let v = v_plane[base_v] as f32 - 128.0;
49+
let y_mul = Y_MUL * (f32::from(y_plane[base_y]) - 16.0);
50+
let u = f32::from(u_plane[base_u]) - 128.0;
51+
let v = f32::from(v_plane[base_v]) - 128.0;
5252

5353
rgb_pixel[0] = RV_MUL.mul_add(v, y_mul) as u8;
5454
rgb_pixel[1] = GV_MUL.mul_add(v, GU_MUL.mul_add(u, y_mul)) as u8;
@@ -188,9 +188,9 @@ pub fn write_rgba8_scalar(
188188

189189
// Convert limited range YUV to RGB
190190
// https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion
191-
let y_mul = Y_MUL * (y_plane[base_y] as f32 - 16.0);
192-
let u = u_plane[base_u] as f32 - 128.0;
193-
let v = v_plane[base_v] as f32 - 128.0;
191+
let y_mul = Y_MUL * (f32::from(y_plane[base_y]) - 16.0);
192+
let u = f32::from(u_plane[base_u]) - 128.0;
193+
let v = f32::from(v_plane[base_v]) - 128.0;
194194

195195
rgb_pixel[0] = RV_MUL.mul_add(v, y_mul) as u8;
196196
rgb_pixel[1] = GV_MUL.mul_add(v, GU_MUL.mul_add(u, y_mul)) as u8;

0 commit comments

Comments
 (0)