diff options
| author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-03-21 11:16:58 +0200 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-03-26 15:52:08 +0200 |
| commit | 34e2b565c696874e2ab49047a1b3331ae8bbe04b (patch) | |
| tree | a20376d0c44d581303aea8dcb781d696725974e5 /kms++util | |
| parent | 5bdc68ff90fecb13b8576bb208f73cfc0f949575 (diff) | |
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 <tomi.valkeinen@ideasonboard.com>
Diffstat (limited to 'kms++util')
| -rw-r--r-- | kms++util/inc/kms++util/kms++util.h | 20 | ||||
| -rw-r--r-- | kms++util/src/testpat.cpp | 42 |
2 files changed, 62 insertions, 0 deletions
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; +} + +} |
