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/inc/kms++util/kms++util.h | 20 ++++++++++++++++++ kms++util/src/testpat.cpp | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'kms++util') diff --git a/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h index 3006a28..6522632 100644 --- a/kms++util/inc/kms++util/kms++util.h +++ b/kms++util/inc/kms++util/kms++util.h @@ -84,3 +84,23 @@ void draw_test_pattern_multi(IFramebuffer& fb, const TestPatternOptions& options fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ exit(-1); \ } + +extern "C" { + +struct CDrawTestPatternParameters { + uint32_t width; + uint32_t height; + uint32_t fourcc;; + uint8_t* buffers[4]; + uint32_t sizes[4]; + uint32_t pitches[4]; + uint32_t offsets[4]; + + const char* pattern; + uint32_t rec_standard; + bool full_range; +}; + +int c_draw_test_pattern(struct CDrawTestPatternParameters* params); + +} 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