fix: enhance JPEG validation and add corresponding tests

This commit is contained in:
ob-yalian
2026-09-15 19:45:58 +08:00
parent 24f977d528
commit 7a5f11ae39
2 changed files with 34 additions and 2 deletions
@@ -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