An attempt at getting image data back
This commit is contained in:
14
spider-cam/libcamera/test/stream/meson.build
Normal file
14
spider-cam/libcamera/test/stream/meson.build
Normal file
@@ -0,0 +1,14 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
stream_tests = [
|
||||
{'name': 'stream_colorspace', 'sources': ['stream_colorspace.cpp']},
|
||||
{'name': 'stream_formats', 'sources': ['stream_formats.cpp']},
|
||||
]
|
||||
|
||||
foreach test : stream_tests
|
||||
exe = executable(test['name'], test['sources'],
|
||||
dependencies : libcamera_public,
|
||||
link_with : test_libraries,
|
||||
include_directories : test_includes_internal)
|
||||
test(test['name'], exe, suite : 'stream')
|
||||
endforeach
|
||||
96
spider-cam/libcamera/test/stream/stream_colorspace.cpp
Normal file
96
spider-cam/libcamera/test/stream/stream_colorspace.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2022, Ideas on Board Oy.
|
||||
*
|
||||
* Stream colorspace adjustment test
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <libcamera/camera.h>
|
||||
#include <libcamera/formats.h>
|
||||
#include <libcamera/stream.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
|
||||
class TestCameraConfiguration : public CameraConfiguration
|
||||
{
|
||||
public:
|
||||
TestCameraConfiguration()
|
||||
: CameraConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
Status validate() override
|
||||
{
|
||||
return validateColorSpaces();
|
||||
}
|
||||
};
|
||||
|
||||
class StreamColorSpaceTest : public Test
|
||||
{
|
||||
protected:
|
||||
int run()
|
||||
{
|
||||
TestCameraConfiguration config;
|
||||
|
||||
StreamConfiguration cfg;
|
||||
cfg.size = { 640, 320 };
|
||||
cfg.pixelFormat = formats::YUV422;
|
||||
cfg.colorSpace = ColorSpace::Srgb;
|
||||
config.addConfiguration(cfg);
|
||||
|
||||
StreamConfiguration &streamCfg = config.at(0);
|
||||
|
||||
/*
|
||||
* YUV pixelformat with sRGB colorspace should have Y'CbCr encoding
|
||||
* adjusted.
|
||||
*/
|
||||
config.validate();
|
||||
if (streamCfg.colorSpace->ycbcrEncoding == ColorSpace::YcbcrEncoding::None) {
|
||||
cerr << "YUV format must have YCbCr encoding" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
/*
|
||||
* For YUV pixelFormat, encoding should be picked up according
|
||||
* to primaries and transfer function, if 'None' is specified.
|
||||
*/
|
||||
streamCfg.pixelFormat = formats::YUV422;
|
||||
streamCfg.colorSpace = ColorSpace(ColorSpace::Primaries::Rec2020,
|
||||
ColorSpace::TransferFunction::Rec709,
|
||||
ColorSpace::YcbcrEncoding::None,
|
||||
ColorSpace::Range::Limited);
|
||||
config.validate();
|
||||
if (streamCfg.colorSpace->ycbcrEncoding != ColorSpace::YcbcrEncoding::Rec2020) {
|
||||
cerr << "Failed to adjust colorspace Y'CbCr encoding according"
|
||||
<< " to primaries and transfer function" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
/* For RGB pixelFormat, Sycc colorspace should get adjusted to sRGB. */
|
||||
streamCfg.pixelFormat = formats::RGB888;
|
||||
streamCfg.colorSpace = ColorSpace::Sycc;
|
||||
config.validate();
|
||||
if (streamCfg.colorSpace != ColorSpace::Srgb) {
|
||||
cerr << "RGB format's colorspace should be set to Srgb" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
/* Raw formats should always set colorspace to ColorSpace::Raw. */
|
||||
streamCfg.pixelFormat = formats::SBGGR8;
|
||||
streamCfg.colorSpace = ColorSpace::Rec709;
|
||||
config.validate();
|
||||
if (streamCfg.colorSpace != ColorSpace::Raw) {
|
||||
cerr << "Raw format must always have Raw colorspace" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
return TestPass;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_REGISTER(StreamColorSpaceTest)
|
||||
101
spider-cam/libcamera/test/stream/stream_formats.cpp
Normal file
101
spider-cam/libcamera/test/stream/stream_formats.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* StreamFormats test
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/stream.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
|
||||
class StreamFormatsTest : public Test
|
||||
{
|
||||
protected:
|
||||
int testSizes(std::string name, std::vector<Size> test, std::vector<Size> valid)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
for (Size &size : test) {
|
||||
pass = false;
|
||||
|
||||
for (Size &validSize : valid) {
|
||||
if (size == validSize) {
|
||||
pass = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pass)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!pass) {
|
||||
cout << "Failed " << name << endl;
|
||||
cout << "Sizes to test:" << endl;
|
||||
for (Size &size : test)
|
||||
cout << size << endl;
|
||||
cout << "Valid sizes:" << endl;
|
||||
for (Size &size : valid)
|
||||
cout << size << endl;
|
||||
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
return TestPass;
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
/* Test discrete sizes */
|
||||
StreamFormats discrete({
|
||||
{ PixelFormat(1), { SizeRange({ 100, 100 }), SizeRange({ 200, 200 }) } },
|
||||
{ PixelFormat(2), { SizeRange({ 300, 300 }), SizeRange({ 400, 400 }) } },
|
||||
});
|
||||
|
||||
if (testSizes("discrete 1", discrete.sizes(PixelFormat(1)),
|
||||
{ Size(100, 100), Size(200, 200) }))
|
||||
return TestFail;
|
||||
if (testSizes("discrete 2", discrete.sizes(PixelFormat(2)),
|
||||
{ Size(300, 300), Size(400, 400) }))
|
||||
return TestFail;
|
||||
|
||||
/* Test range sizes */
|
||||
StreamFormats range({
|
||||
{ PixelFormat(1), { SizeRange({ 640, 480 }, { 640, 480 }) } },
|
||||
{ PixelFormat(2), { SizeRange({ 640, 480 }, { 800, 600 }, 8, 8) } },
|
||||
{ PixelFormat(3), { SizeRange({ 640, 480 }, { 800, 600 }, 16, 16) } },
|
||||
{ PixelFormat(4), { SizeRange({ 128, 128 }, { 4096, 4096 }, 128, 128) } },
|
||||
});
|
||||
|
||||
if (testSizes("range 1", range.sizes(PixelFormat(1)), { Size(640, 480) }))
|
||||
return TestFail;
|
||||
|
||||
if (testSizes("range 2", range.sizes(PixelFormat(2)), {
|
||||
Size(640, 480), Size(720, 480),
|
||||
Size(720, 576), Size(768, 480),
|
||||
Size(800, 600) }))
|
||||
return TestFail;
|
||||
|
||||
if (testSizes("range 3", range.sizes(PixelFormat(3)), {
|
||||
Size(640, 480), Size(720, 480),
|
||||
Size(720, 576), Size(768, 480) }))
|
||||
return TestFail;
|
||||
|
||||
if (testSizes("range 4", range.sizes(PixelFormat(4)), {
|
||||
Size(1024, 768), Size(1280, 1024),
|
||||
Size(2048, 1152), Size(2048, 1536),
|
||||
Size(2560, 2048), Size(3200, 2048), }))
|
||||
return TestFail;
|
||||
|
||||
return TestPass;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_REGISTER(StreamFormatsTest)
|
||||
Reference in New Issue
Block a user