fix(tracker-native): stride-aware RGB32 capture (handle bottom-up + padding)
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s

Media Foundation commonly delivers RGB32 bottom-up (negative MF_MT_DEFAULT_STRIDE);
a flat top-down memcpy would make the preview and published feed upside-down.
read_frame now copies row by row honoring the signed stride (flip when negative,
handle padded strides), producing a top-down BGRA frame per the MS Image Stride
spec. Orientation is logged at open.
This commit is contained in:
kinect-bot committed 2026-11-25 19:14:07 -05:00
1 parent 5239ae5b81
commit b30deb7cc5
2 files changed
+16 -7

No files matched your search

+15 -7
View File
@@ -154,11 +154,13 @@ bool Camera::open(const std::wstring& symbolic_link, int width, int height) {
SafeRelease(&cur);
}
TraceLog("camera open OK: negotiated %dx%d default_stride=%ld (expect top-down +%d)",
width, height, stride, width * 4);
if (stride == 0) stride = width * 4;
TraceLog("camera open OK: negotiated %dx%d default_stride=%ld (%s)",
width, height, stride, stride < 0 ? "bottom-up -> flipped" : "top-down");
reader_ = reader;
width_ = width;
height_ = height;
stride_ = static_cast<int>(stride);
return true;
}
@@ -179,16 +181,22 @@ bool Camera::read_frame(std::vector<uint8_t>& bgra, int& width, int& height) {
BYTE* data = nullptr;
DWORD max_len = 0, cur_len = 0;
if (SUCCEEDED(buffer->Lock(&data, &max_len, &cur_len))) {
const size_t need = static_cast<size_t>(width_) * height_ * 4u;
const size_t row_bytes = static_cast<size_t>(width_) * 4u;
const size_t need = row_bytes * height_;
const int abs_stride = stride_ < 0 ? -stride_ : stride_;
static unsigned logged = 0;
if (logged < 3) {
TraceLog("read_frame: buffer=%lu bytes, need=%zu (%dx%d*4)",
static_cast<unsigned long>(cur_len), need, width_, height_);
TraceLog("read_frame: buffer=%lu bytes, need=%zu (%dx%d*4) stride=%d",
static_cast<unsigned long>(cur_len), need, width_, height_, stride_);
++logged;
}
if (cur_len >= need) {
if (cur_len >= static_cast<DWORD>(static_cast<size_t>(abs_stride) * height_)) {
bgra.resize(need);
std::memcpy(bgra.data(), data, need);
for (int y = 0; y < height_; ++y) {
const int src_row = stride_ < 0 ? (height_ - 1 - y) : y;
std::memcpy(bgra.data() + static_cast<size_t>(y) * row_bytes,
data + static_cast<size_t>(src_row) * abs_stride, row_bytes);
}
width = width_;
height = height_;
ok = true;
+1
View File
@@ -36,6 +36,7 @@ class Camera {
void* reader_ = nullptr;
int width_ = 0;
int height_ = 0;
int stride_ = 0;
};
}