From 34e2b565c696874e2ab49047a1b3331ae8bbe04b Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 21 Mar 2025 11:16:58 +0200 Subject: kms++util: Add draw_test_pattern() with C ABI Add a draw_test_pattern for C ABI (i.e. not C++). This function can be easily called from Python with ctypes, without any kind of bindings. Experimental, ABI can change. Signed-off-by: Tomi Valkeinen --- kms++util/src/testpat.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'kms++util/src') diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp index 0f69952..a123a1f 100644 --- a/kms++util/src/testpat.cpp +++ b/kms++util/src/testpat.cpp @@ -475,3 +475,45 @@ void draw_test_pattern(IFramebuffer& fb, const TestPatternOptions& options) } } // namespace kms + +extern "C" { + +int c_draw_test_pattern(struct CDrawTestPatternParameters* params) +{ + using namespace kms; + + try { + auto fmt = fourcc_to_pixel_format(params->fourcc); + + ExtCPUFramebuffer fb(params->width, + params->height, + fmt, + params->buffers, + params->sizes, + params->pitches, + params->offsets); + + RecStandard rec; + if (params->rec_standard == 0) + rec = RecStandard::BT601; + else if (params->rec_standard == 1) + rec = RecStandard::BT709; + else if (params->rec_standard == 2) + rec = RecStandard::BT2020; + else + return -1; + + TestPatternOptions options; + options.pattern = params->pattern; + options.rec = rec; + options.range = params->full_range ? ColorRange::Full : ColorRange::Limited; + + draw_test_pattern(fb, options); + } catch (const exception&) { + return -1; + } + + return 0; +} + +} -- cgit v1.2.3