mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
UsbCamera: In JPEG mode, get size from image instead of mode (#1222)
Some cameras will accept a different resolution as the mode but then provide JPEG images of a different size. Trust the JPEG image size if available. This also validates the JPEG image is actually JPEG.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "Handle.h"
|
||||
#include "JpegUtil.h"
|
||||
#include "Log.h"
|
||||
#include "Notifier.h"
|
||||
#include "Telemetry.h"
|
||||
@@ -400,12 +401,21 @@ void UsbCameraImpl::CameraThreadMain() {
|
||||
continue;
|
||||
}
|
||||
|
||||
PutFrame(static_cast<VideoMode::PixelFormat>(m_mode.pixelFormat),
|
||||
m_mode.width, m_mode.height,
|
||||
wpi::StringRef(
|
||||
static_cast<const char*>(m_buffers[buf.index].m_data),
|
||||
static_cast<size_t>(buf.bytesused)),
|
||||
wpi::Now()); // TODO: time
|
||||
wpi::StringRef image{
|
||||
static_cast<const char*>(m_buffers[buf.index].m_data),
|
||||
static_cast<size_t>(buf.bytesused)};
|
||||
int width = m_mode.width;
|
||||
int height = m_mode.height;
|
||||
bool good = true;
|
||||
if (m_mode.pixelFormat == VideoMode::kMJPEG &&
|
||||
!GetJpegSize(image, &width, &height)) {
|
||||
SWARNING("invalid JPEG image received from camera");
|
||||
good = false;
|
||||
}
|
||||
if (good) {
|
||||
PutFrame(static_cast<VideoMode::PixelFormat>(m_mode.pixelFormat),
|
||||
width, height, image, wpi::Now()); // TODO: time
|
||||
}
|
||||
}
|
||||
|
||||
// Requeue buffer
|
||||
|
||||
Reference in New Issue
Block a user