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

Method ensure_size

rustcv-camera/src/mat.rs:65–74  ·  view source on GitHub ↗

Ensure the internal buffer is large enough for the given dimensions. 确保内部缓冲区对于给定尺寸足够大。 If the size matches the current allocation, no reallocation occurs. This is key for zero-allocation frame decoding: call `read()` in a loop with the same Mat, and memory is allocated only once (on the first frame). 如果大小与当前分配匹配,则不会重新分配。 这是零分配帧解码的关键:在循环中使用同一个 Mat 调用 `read()`, 内存仅分配一次(在第一帧时)。

(&mut self, rows: u32, cols: u32, channels: u32)

Source from the content-addressed store, hash-verified

63 /// 这是零分配帧解码的关键:在循环中使用同一个 Mat 调用 `read()`,
64 /// 内存仅分配一次(在第一帧时)。
65 pub(crate) fn ensure_size(&mut self, rows: u32, cols: u32, channels: u32) {
66 let needed = (rows as usize) * (cols as usize) * (channels as usize);
67 if self.data.len() != needed {
68 self.data.resize(needed, 0);
69 }
70 self.rows = rows;
71 self.cols = cols;
72 self.channels = channels;
73 self.step = (cols as usize) * (channels as usize);
74 }
75
76 /// Returns `true` if this Mat contains no data.
77 /// 如果此 Mat 不包含数据则返回 `true`。

Callers 1

decode_frameFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected