MCPcopy Create free account
hub / github.com/RustCV/RustCV / draw_text_osd

Function draw_text_osd

rustcv-backend-avf/examples/camera_view.rs:251–279  ·  view source on GitHub ↗
(buf: &mut [u32], buf_width: usize, text: &str, x: usize, y: usize, color: u32)

Source from the content-addressed store, hash-verified

249/// 先绘制半透明黑色阴影(偏移 +1,+1)再绘制前景色,增强可读性。
250#[cfg(target_os = "macos")]
251fn draw_text_osd(buf: &mut [u32], buf_width: usize, text: &str, x: usize, y: usize, color: u32) {
252 const CHAR_W: usize = 6; // 字符宽度(含右侧 1px 间距)
253
254 for (ci, ch) in text.chars().enumerate() {
255 let cx = x + ci * CHAR_W;
256 let bitmap = char_bitmap(ch);
257
258 for (row, &bits) in bitmap.iter().enumerate() {
259 for col in 0..5usize {
260 if bits & (1 << (4 - col)) != 0 {
261 // 先画黑色阴影(+1, +1 偏移),提升对比度
262 let sx = cx + col + 1;
263 let sy = y + row + 1;
264 if let Some(idx) = pixel_idx(sx, sy, buf_width, buf.len()) {
265 // 半透明黑色阴影(直接赋值,避免 alpha 混合开销)
266 buf[idx] = 0x00_10_10_10;
267 }
268
269 // 再画前景色
270 let px = cx + col;
271 let py = y + row;
272 if let Some(idx) = pixel_idx(px, py, buf_width, buf.len()) {
273 buf[idx] = color;
274 }
275 }
276 }
277 }
278 }
279}
280
281/// 计算像素在一维缓冲区中的索引,越界则返回 None。
282#[cfg(target_os = "macos")]

Callers 1

mainFunction · 0.85

Calls 2

char_bitmapFunction · 0.85
pixel_idxFunction · 0.85

Tested by

no test coverage detected