mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-09 22:29:48 +08:00
fix: enhance JPEG validation and add corresponding tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "orbbec_camera/utils.h"
|
||||
@@ -32,6 +33,14 @@ OBCameraDistortion makeDistortion(OBCameraDistortionModel model) {
|
||||
return distortion;
|
||||
}
|
||||
|
||||
std::shared_ptr<ob::ColorFrame> makeMjpegFrame(const std::vector<uint8_t>& data) {
|
||||
auto frame = ob::FrameFactory::createFrame(OB_FRAME_COLOR, OB_FORMAT_MJPG,
|
||||
static_cast<uint32_t>(data.size()));
|
||||
auto color_frame = frame->as<ob::ColorFrame>();
|
||||
std::memcpy(color_frame->getData(), data.data(), data.size());
|
||||
return color_frame;
|
||||
}
|
||||
|
||||
TEST(CameraInfoDistortionTest, ConvertsBrownConradyToPlumbBob) {
|
||||
const auto intrinsic = makeIntrinsic();
|
||||
const auto distortion = makeDistortion(OB_DISTORTION_BROWN_CONRADY);
|
||||
@@ -69,5 +78,17 @@ TEST(CameraInfoDistortionTest, ConvertsKannalaBrandtToEquidistant) {
|
||||
std::vector<double>({distortion.k1, distortion.k2, distortion.k3, distortion.k4}));
|
||||
}
|
||||
|
||||
TEST(JpegValidationTest, AcceptsEoiBeforeZeroPadding) {
|
||||
const auto frame = makeMjpegFrame({0xFF, 0xD8, 0x01, 0x02, 0xFF, 0xD9, 0x00, 0x00});
|
||||
|
||||
EXPECT_TRUE(isValidJPEG(frame));
|
||||
}
|
||||
|
||||
TEST(JpegValidationTest, RejectsMjpegWithoutEoi) {
|
||||
const auto frame = makeMjpegFrame({0xFF, 0xD8, 0x01, 0x02, 0x00, 0x00});
|
||||
|
||||
EXPECT_FALSE(isValidJPEG(frame));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace orbbec_camera
|
||||
|
||||
Reference in New Issue
Block a user