mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
refactor: add non_zero_suggestions clippy extra-pedantic lint (#895)
This commit is contained in:
@@ -130,6 +130,7 @@ unnecessary_box_returns = "warn"
|
||||
# == Extra-pedantic clippy == #
|
||||
allow_attributes = "warn"
|
||||
disallowed_script_idents = "warn"
|
||||
non_zero_suggestions = "warn"
|
||||
renamed_function_params = "warn"
|
||||
collection_is_never_read = "warn"
|
||||
copy_iterator = "warn"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#![allow(clippy::print_stderr)]
|
||||
#![allow(clippy::print_stdout)]
|
||||
|
||||
use core::num::NonZero;
|
||||
use core::time::Duration;
|
||||
use std::io::Write;
|
||||
use std::time::Instant;
|
||||
@@ -145,7 +146,7 @@ impl RdpServerDisplayUpdates for DisplayUpdates {
|
||||
height: self.desktop_size.height.try_into().unwrap(),
|
||||
format: PixelFormat::RgbX32,
|
||||
data: buf.into(),
|
||||
stride,
|
||||
stride: NonZero::new(stride).unwrap(),
|
||||
});
|
||||
Some(up)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn rfx_enc_tile_bench(c: &mut Criterion) {
|
||||
height: NonZero::new(64).unwrap(),
|
||||
format: ironrdp_server::PixelFormat::ARgb32,
|
||||
data: vec![0; 64 * 64 * 4].into(),
|
||||
stride: 64 * 4,
|
||||
stride: NonZero::new(64 * 4).unwrap(),
|
||||
};
|
||||
c.bench_function("rfx_enc_tile", |b| b.iter(|| rfx_enc_tile(&bitmap, &quant, algo, 0, 0)));
|
||||
}
|
||||
@@ -31,7 +31,7 @@ pub fn rfx_enc_bench(c: &mut Criterion) {
|
||||
height: NonZero::new(2048).unwrap(),
|
||||
format: ironrdp_server::PixelFormat::ARgb32,
|
||||
data: vec![0; 2048 * 2048 * 4].into(),
|
||||
stride: 64 * 4,
|
||||
stride: NonZero::new(64 * 4).unwrap(),
|
||||
};
|
||||
c.bench_function("rfx_enc", |b| b.iter(|| rfx_enc(&bitmap, &quant, algo)));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use core::num::NonZeroU16;
|
||||
use core::num::{NonZeroU16, NonZeroUsize};
|
||||
|
||||
use anyhow::Result;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
@@ -76,7 +76,7 @@ impl TryInto<Framebuffer> for BitmapUpdate {
|
||||
height: self.height,
|
||||
format: self.format,
|
||||
data: self.data.into(),
|
||||
stride: self.stride,
|
||||
stride: self.stride.get(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -84,8 +84,8 @@ impl TryInto<Framebuffer> for BitmapUpdate {
|
||||
impl Framebuffer {
|
||||
pub fn new(width: NonZeroU16, height: NonZeroU16, format: PixelFormat) -> Self {
|
||||
let mut data = BytesMut::new();
|
||||
let w = usize::from(width.get());
|
||||
let h = usize::from(height.get());
|
||||
let w = NonZeroUsize::from(width).get();
|
||||
let h = NonZeroUsize::from(height).get();
|
||||
let bpp = usize::from(format.bytes_per_pixel());
|
||||
data.resize(bpp * w * h, 0);
|
||||
|
||||
@@ -106,8 +106,8 @@ impl Framebuffer {
|
||||
let bpp = usize::from(self.format.bytes_per_pixel());
|
||||
let x = usize::from(bitmap.x);
|
||||
let y = usize::from(bitmap.y);
|
||||
let width = usize::from(bitmap.width.get());
|
||||
let height = usize::from(bitmap.height.get());
|
||||
let width = NonZeroUsize::from(bitmap.width).get();
|
||||
let height = NonZeroUsize::from(bitmap.height).get();
|
||||
|
||||
let data = &mut self.data;
|
||||
let start = y * self.stride + x * bpp;
|
||||
@@ -115,8 +115,9 @@ impl Framebuffer {
|
||||
let dst = &mut data[start..end];
|
||||
|
||||
for y in 0..height {
|
||||
let start = y * bitmap.stride;
|
||||
let start = y * bitmap.stride.get();
|
||||
let end = start + width * bpp;
|
||||
|
||||
let src = bitmap.data.slice(start..end);
|
||||
|
||||
let start = y * self.stride;
|
||||
@@ -155,7 +156,7 @@ pub struct BitmapUpdate {
|
||||
pub height: NonZeroU16,
|
||||
pub format: PixelFormat,
|
||||
pub data: Bytes,
|
||||
pub stride: usize,
|
||||
pub stride: NonZeroUsize,
|
||||
}
|
||||
|
||||
impl BitmapUpdate {
|
||||
@@ -177,6 +178,7 @@ impl BitmapUpdate {
|
||||
///
|
||||
/// ```
|
||||
/// # use core::num::NonZeroU16;
|
||||
/// # use std::num::NonZeroUsize;
|
||||
/// # use bytes::Bytes;
|
||||
/// # use ironrdp_graphics::image_processing::PixelFormat;
|
||||
/// # use ironrdp_server::BitmapUpdate;
|
||||
@@ -187,7 +189,7 @@ impl BitmapUpdate {
|
||||
/// height: NonZeroU16::new(100).unwrap(),
|
||||
/// format: PixelFormat::ARgb32,
|
||||
/// data: Bytes::from(vec![0; 40000]),
|
||||
/// stride: 400,
|
||||
/// stride: NonZeroUsize::new(400).unwrap(),
|
||||
/// };
|
||||
///
|
||||
/// let sub_region = original.sub(10, 10, NonZeroU16::new(50).unwrap(), NonZeroU16::new(50).unwrap());
|
||||
@@ -199,8 +201,8 @@ impl BitmapUpdate {
|
||||
None
|
||||
} else {
|
||||
let bpp = usize::from(self.format.bytes_per_pixel());
|
||||
let start = usize::from(y) * self.stride + usize::from(x) * bpp;
|
||||
let end = start + usize::from(height.get() - 1) * self.stride + usize::from(width.get()) * bpp;
|
||||
let start = usize::from(y) * self.stride.get() + usize::from(x) * bpp;
|
||||
let end = start + usize::from(height.get() - 1) * self.stride.get() + usize::from(width.get()) * bpp;
|
||||
Some(Self {
|
||||
x: self.x + x,
|
||||
y: self.y + y,
|
||||
@@ -296,7 +298,7 @@ pub trait RdpServerDisplay: Send {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::num::NonZeroU16;
|
||||
use core::num::{NonZeroU16, NonZeroUsize};
|
||||
|
||||
use ironrdp_graphics::diff::Rect;
|
||||
use ironrdp_graphics::image_processing::PixelFormat;
|
||||
@@ -312,9 +314,9 @@ mod tests {
|
||||
let mut fb = Framebuffer::new(width, height, fmt);
|
||||
|
||||
let width = 15;
|
||||
let stride = width * bpp;
|
||||
let stride = NonZeroUsize::new(width * bpp).unwrap();
|
||||
let height = 20;
|
||||
let data = vec![1u8; height * stride];
|
||||
let data = vec![1u8; height * stride.get()];
|
||||
let update = BitmapUpdate {
|
||||
x: 1,
|
||||
y: 2,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use core::num::NonZeroUsize;
|
||||
|
||||
use ironrdp_core::{invalid_field_err, Encode, EncodeResult, WriteCursor};
|
||||
use ironrdp_graphics::image_processing::PixelFormat;
|
||||
use ironrdp_graphics::rdp6::{ABgrChannels, ARgbChannels, BgrAChannels, BitmapStreamEncoder, RgbAChannels};
|
||||
@@ -33,20 +35,21 @@ impl BitmapEncoder {
|
||||
let chunk_height = usize::from(u16::MAX) / row_len;
|
||||
|
||||
let mut cursor = WriteCursor::new(output);
|
||||
let chunks = bitmap.data.chunks(bitmap.stride * chunk_height);
|
||||
let stride = bitmap.stride.get();
|
||||
let chunks = bitmap.data.chunks(stride * chunk_height);
|
||||
|
||||
let total = u16::try_from(chunks.size_hint().0).unwrap();
|
||||
BitmapUpdateData::encode_header(total, &mut cursor)?;
|
||||
|
||||
for (i, chunk) in chunks.enumerate() {
|
||||
let height = chunk.len() / bitmap.stride;
|
||||
let height = chunk.len() / stride;
|
||||
let top = usize::from(bitmap.y) + i * chunk_height;
|
||||
|
||||
let encoder = BitmapStreamEncoder::new(usize::from(bitmap.width.get()), height);
|
||||
let encoder = BitmapStreamEncoder::new(NonZeroUsize::from(bitmap.width).get(), height);
|
||||
|
||||
let len = {
|
||||
let pixels = chunk
|
||||
.chunks(bitmap.stride)
|
||||
.chunks(stride)
|
||||
.map(|row| &row[..row_len])
|
||||
.rev()
|
||||
.flat_map(|row| row.chunks(bytes_per_pixel));
|
||||
|
||||
@@ -203,7 +203,7 @@ impl UpdateEncoder {
|
||||
width.get().into(),
|
||||
height.get().into(),
|
||||
&bitmap.data,
|
||||
bitmap.stride,
|
||||
bitmap.stride.get(),
|
||||
bitmap.width.get().into(),
|
||||
bitmap.height.get().into(),
|
||||
bitmap.x.into(),
|
||||
@@ -356,7 +356,7 @@ impl BitmapUpdateHandler for NoneHandler {
|
||||
fn handle(&mut self, bitmap: &BitmapUpdate) -> Result<UpdateFragmenter> {
|
||||
let stride = usize::from(bitmap.format.bytes_per_pixel()) * usize::from(bitmap.width.get());
|
||||
let mut data = Vec::with_capacity(stride * usize::from(bitmap.height.get()));
|
||||
for row in bitmap.data.chunks(bitmap.stride).rev() {
|
||||
for row in bitmap.data.chunks(bitmap.stride.get()).rev() {
|
||||
data.extend_from_slice(&row[..stride]);
|
||||
}
|
||||
set_surface(bitmap, CodecId::None as u8, &data)
|
||||
@@ -542,7 +542,7 @@ fn qoi_encode(bitmap: &BitmapUpdate) -> Result<Vec<u8>> {
|
||||
RgbX32 => qoi::RawChannels::Rgbx,
|
||||
};
|
||||
let enc = qoi::EncoderBuilder::new(&bitmap.data, bitmap.width.get().into(), bitmap.height.get().into())
|
||||
.stride(bitmap.stride)
|
||||
.stride(bitmap.stride.get())
|
||||
.raw_channels(raw_channels)
|
||||
.build()?;
|
||||
Ok(enc.encode_to_vec()?)
|
||||
|
||||
@@ -188,21 +188,13 @@ impl<'a> UpdateEncoder<'a> {
|
||||
let y = tile_y * 64;
|
||||
let tile_width = core::cmp::min(width - x, 64);
|
||||
let tile_height = core::cmp::min(height - y, 64);
|
||||
let input = &self.bitmap.data[y * self.bitmap.stride + x * bpp..];
|
||||
let stride = self.bitmap.stride.get();
|
||||
let input = &self.bitmap.data[y * stride + x * bpp..];
|
||||
|
||||
let y = &mut [0i16; 4096];
|
||||
let cb = &mut [0i16; 4096];
|
||||
let cr = &mut [0i16; 4096];
|
||||
to_64x64_ycbcr_tile(
|
||||
input,
|
||||
tile_width,
|
||||
tile_height,
|
||||
self.bitmap.stride,
|
||||
self.bitmap.format,
|
||||
y,
|
||||
cb,
|
||||
cr,
|
||||
);
|
||||
to_64x64_ycbcr_tile(input, tile_width, tile_height, stride, self.bitmap.format, y, cb, cr);
|
||||
|
||||
let (y_data, buf) = buf.split_at_mut(4096);
|
||||
let (cb_data, cr_data) = buf.split_at_mut(4096);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern crate tracing;
|
||||
|
||||
use core::net::SocketAddr;
|
||||
use core::num::NonZeroU16;
|
||||
use core::num::{NonZero, NonZeroU16, NonZeroUsize};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -163,11 +163,13 @@ impl RdpServerDisplayUpdates for DisplayUpdates {
|
||||
let height = NonZeroU16::new(rng.random_range(1..=HEIGHT.checked_sub(y).unwrap())).unwrap();
|
||||
let x: u16 = rng.random_range(0..WIDTH);
|
||||
let width = NonZeroU16::new(rng.random_range(1..=WIDTH.checked_sub(x).unwrap())).unwrap();
|
||||
let capacity = usize::from(width.get())
|
||||
.checked_mul(usize::from(height.get()))
|
||||
let capacity = NonZeroUsize::from(width)
|
||||
.checked_mul(NonZeroUsize::from(height))
|
||||
.unwrap()
|
||||
.get()
|
||||
.checked_mul(4)
|
||||
.unwrap();
|
||||
|
||||
let mut data = Vec::with_capacity(capacity);
|
||||
for _ in 0..(data.capacity() / 4) {
|
||||
data.push(rng.random());
|
||||
@@ -177,6 +179,7 @@ impl RdpServerDisplayUpdates for DisplayUpdates {
|
||||
}
|
||||
|
||||
info!("get_update +{x}+{y} {width}x{height}");
|
||||
let stride = NonZeroUsize::from(width).checked_mul(NonZero::new(4).unwrap()).unwrap();
|
||||
let bitmap = BitmapUpdate {
|
||||
x,
|
||||
y,
|
||||
@@ -184,7 +187,7 @@ impl RdpServerDisplayUpdates for DisplayUpdates {
|
||||
height,
|
||||
format: PixelFormat::BgrA32,
|
||||
data: data.into(),
|
||||
stride: usize::from(width.get()).checked_mul(4).unwrap(),
|
||||
stride,
|
||||
};
|
||||
Some(DisplayUpdate::Bitmap(bitmap))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user