fix: 数据传输卡顿。
This commit is contained in:
parent
a9394bd73c
commit
753074d0f4
@ -51,7 +51,7 @@ async fn get_led_strip_colors() -> Result<Vec<LedColor>, String> {
|
|||||||
match colors {
|
match colors {
|
||||||
Ok(colors) => {
|
Ok(colors) => {
|
||||||
rpc::manager::Manager::global()
|
rpc::manager::Manager::global()
|
||||||
.publish_led_colors(&colors)
|
.publish_led_colors(&colors.to_vec())
|
||||||
.await;
|
.await;
|
||||||
Ok(colors)
|
Ok(colors)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use color_space::{Hsv, Rgb};
|
||||||
|
use paris::info;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
@ -58,27 +60,33 @@ impl Screenshot {
|
|||||||
XPosition::Bottom => self.height - cell_size_y..self.height,
|
XPosition::Bottom => self.height - cell_size_y..self.height,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut colors = vec![LedColor::default(); self.led_number_of_x];
|
let mut colors = Vec::new();
|
||||||
let stride = bitmap.len() / self.height;
|
let stride = bitmap.len() / self.height;
|
||||||
|
|
||||||
for pos in 0..self.led_number_of_x {
|
for pos in 0..self.led_number_of_x {
|
||||||
let mut r = 0u32;
|
let mut r = 0.0;
|
||||||
let mut g = 0u32;
|
let mut g = 0.0;
|
||||||
let mut b = 0u32;
|
let mut b = 0.0;
|
||||||
for x in pos * cell_size_x..(pos + 1) * cell_size_x {
|
for x in pos * cell_size_x..(pos + 1) * cell_size_x {
|
||||||
for y in y_range.to_owned() {
|
for y in y_range.to_owned() {
|
||||||
let i = stride * y + 4 * x;
|
let i = stride * y + 4 * x;
|
||||||
r += bitmap[i + 2] as u32;
|
r += bitmap[i + 2] as f64;
|
||||||
g += bitmap[i + 1] as u32;
|
g += bitmap[i + 1] as f64;
|
||||||
b += bitmap[i] as u32;
|
b += bitmap[i] as f64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
colors[pos] = LedColor::new(
|
let rgb = Rgb::new(
|
||||||
(r / cell_size as u32) as u8,
|
r / cell_size as f64,
|
||||||
(g / cell_size as u32) as u8,
|
g / cell_size as f64,
|
||||||
(b / cell_size as u32) as u8,
|
b / cell_size as f64,
|
||||||
);
|
);
|
||||||
|
let hsv = Hsv::from(rgb);
|
||||||
|
info!("HSV: {:?}", [hsv.h, hsv.s, hsv.v]);
|
||||||
|
let color = LedColor::from_hsv(hsv.h, hsv.s * 10.0, hsv.v / 2.0);
|
||||||
|
info!("color: {:?}", color.get_rgb());
|
||||||
|
colors.push(color);
|
||||||
}
|
}
|
||||||
|
colors.reverse();
|
||||||
return Ok(colors);
|
return Ok(colors);
|
||||||
}
|
}
|
||||||
None => Ok(vec![]),
|
None => Ok(vec![]),
|
||||||
@ -111,10 +119,8 @@ impl Screenshot {
|
|||||||
)
|
)
|
||||||
.encode(100.0);
|
.encode(100.0);
|
||||||
return base64::encode(&*webp_memory);
|
return base64::encode(&*webp_memory);
|
||||||
},
|
|
||||||
None => {
|
|
||||||
"".to_owned()
|
|
||||||
}
|
}
|
||||||
|
None => "".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ impl Manager {
|
|||||||
.client
|
.client
|
||||||
.publish(
|
.publish(
|
||||||
"screen-bg-light/desktop/colors",
|
"screen-bg-light/desktop/colors",
|
||||||
rumqttc::QoS::AtMostOnce,
|
rumqttc::QoS::AtLeastOnce,
|
||||||
false,
|
false,
|
||||||
payload,
|
payload,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user