ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
TestPatternBinding Class Reference

Public Member Functions

 TestPatternBinding (int width, int height)
 ~TestPatternBinding ()
 TestPatternBinding (const TestPatternBinding &)=delete
TestPatternBinding & operator= (const TestPatternBinding &)=delete
bool valid () const
int error () const
void close ()
bool render (int width, int height, int index, double time, bool cadence, PatternPixels output)

Detailed Description

Definition at line 12 of file test_pattern.cpp.

Constructor & Destructor Documentation

◆ TestPatternBinding() [1/2]

TestPatternBinding::TestPatternBinding ( int width,
int height )
inline

Definition at line 14 of file test_pattern.cpp.

14 {
15 if (test_pattern_create(width, height, &pattern_) != ASCIICHAT_OK)
16 pattern_ = nullptr;
17 }
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
@ ASCIICHAT_OK
Definition error_codes.h:50
asciichat_error_t test_pattern_create(int width, int height, test_pattern_t **out)

References ASCIICHAT_OK, height, test_pattern_create(), and width.

Referenced by operator=(), and TestPatternBinding().

◆ ~TestPatternBinding()

TestPatternBinding::~TestPatternBinding ( )
inline

Definition at line 18 of file test_pattern.cpp.

18 {
19 close();
20 }

References close().

◆ TestPatternBinding() [2/2]

TestPatternBinding::TestPatternBinding ( const TestPatternBinding & )
delete

References TestPatternBinding().

Member Function Documentation

◆ close()

void TestPatternBinding::close ( )
inline

Definition at line 29 of file test_pattern.cpp.

29 {
30 if (!pattern_)
31 return;
32 test_pattern_destroy(pattern_);
33 pattern_ = nullptr;
34 }
void test_pattern_destroy(test_pattern_t *p)

References test_pattern_destroy().

Referenced by EMSCRIPTEN_BINDINGS(), and ~TestPatternBinding().

◆ error()

int TestPatternBinding::error ( ) const
inline

Definition at line 26 of file test_pattern.cpp.

26 {
27 return valid() ? 0 : ERROR_INIT;
28 }
@ ERROR_INIT
Definition error_codes.h:60

References ERROR_INIT, and valid().

Referenced by EMSCRIPTEN_BINDINGS().

◆ operator=()

TestPatternBinding & TestPatternBinding::operator= ( const TestPatternBinding & )
delete

References TestPatternBinding().

◆ render()

bool TestPatternBinding::render ( int width,
int height,
int index,
double time,
bool cadence,
PatternPixels output )
inline

Definition at line 35 of file test_pattern.cpp.

35 {
36 if (!pattern_) {
37 SET_ERRNO(ERROR_INVALID_STATE, "Test pattern is not initialized");
38 return false;
39 }
40 if (width <= 0 || height <= 0 || static_cast<uint64_t>(width) * static_cast<uint64_t>(height) * 4 != output["length"].as<size_t>()) {
41 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid test pattern image: %dx%d", width, height);
42 return false;
43 }
44 if (test_pattern_resize(pattern_, width, height) != ASCIICHAT_OK || test_pattern_render(pattern_, index, time, cadence) != ASCIICHAT_OK)
45 return false;
46 const uint8_t *pixels = test_pattern_rgba(pattern_);
47 if (!pixels)
48 return false;
49 output.call<void>("set", emscripten::val(emscripten::typed_memory_view(output["length"].as<size_t>(), pixels)));
50 return true;
51 }
#define SET_ERRNO(code,...)
unsigned long long uint64_t
unsigned char uint8_t
@ ERROR_INVALID_STATE
@ ERROR_INVALID_PARAM
static bool size_t index
Definition queries.h:10
asciichat_error_t test_pattern_render(test_pattern_t *p, int index, double time_ms, bool cadence)
const uint8_t * test_pattern_rgba(test_pattern_t *p)
asciichat_error_t test_pattern_resize(test_pattern_t *p, int width, int height)

References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, height, index, SET_ERRNO, test_pattern_render(), test_pattern_resize(), test_pattern_rgba(), and width.

Referenced by EMSCRIPTEN_BINDINGS().

◆ valid()

bool TestPatternBinding::valid ( ) const
inline

Definition at line 23 of file test_pattern.cpp.

23 {
24 return pattern_ != nullptr;
25 }

Referenced by EMSCRIPTEN_BINDINGS(), and error().


The documentation for this class was generated from the following file: