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

Function draw_fps_overlay

rustcv-camera/examples/camera_demo.rs:84–124  ·  view source on GitHub ↗

Draw FPS value as white pixels in the top-left corner. 在左上角用白色像素绘制 FPS 数值。 Uses a minimal 5x7 bitmap font — no external font dependencies. 使用最小的 5x7 位图字体 —— 无外部字体依赖。

(buf: &mut [u32], stride: usize, fps: f64)

Source from the content-addressed store, hash-verified

82/// Uses a minimal 5x7 bitmap font — no external font dependencies.
83/// 使用最小的 5x7 位图字体 —— 无外部字体依赖。
84fn draw_fps_overlay(buf: &mut [u32], stride: usize, fps: f64) {
85 let text = format!("FPS: {:.1}", fps);
86 let scale = 2; // 2x scale for visibility / 2 倍放大以便可见
87 let x0 = 8;
88 let y0 = 8;
89
90 // Draw black background rectangle.
91 // 绘制黑色背景矩形。
92 let text_w = text.len() * 6 * scale;
93 let text_h = 7 * scale;
94 for dy in 0..text_h + 4 {
95 for dx in 0..text_w + 8 {
96 let px = x0 + dx - 2;
97 let py = y0 + dy - 2;
98 if py < buf.len() / stride && px < stride {
99 buf[py * stride + px] = 0x00000000;
100 }
101 }
102 }
103
104 // Draw each character.
105 // 绘制每个字符。
106 for (ci, ch) in text.chars().enumerate() {
107 let glyph = char_glyph(ch);
108 for (row, &glyph_row) in glyph.iter().enumerate() {
109 for col in 0..5 {
110 if glyph_row & (1 << (4 - col)) != 0 {
111 for sy in 0..scale {
112 for sx in 0..scale {
113 let px = x0 + ci * 6 * scale + col * scale + sx;
114 let py = y0 + row * scale + sy;
115 if py < buf.len() / stride && px < stride {
116 buf[py * stride + px] = 0x00FFFFFF; // white
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124}
125
126/// Minimal 5x7 bitmap font glyph for a character.
127/// 字符的最小 5x7 位图字体字形。

Callers 1

mainFunction · 0.70

Calls 1

char_glyphFunction · 0.70

Tested by

no test coverage detected