Skip to content

Commit

Permalink
vdisp/sdl2: enable R10k
Browse files Browse the repository at this point in the history
Seem to be working now (but requires a byte swap for the R10k pixels
values).

refer to GH-412
  • Loading branch information
MartinPulec committed Sep 18, 2024
1 parent 7b39536 commit 3c9e260
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/utils/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,4 @@ bool invalid_arg_is_numeric(const char *what) {
}
return strncmp(what, "stoi", 4) == 0 || strncmp(what, "stod", 4) == 0;
}

29 changes: 26 additions & 3 deletions src/video_display/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <string.h> // for NULL, strlen, strcmp, strstr, strchr
#include <time.h> // for timespec_get, TIME_UTC, timespec

#include "compat/htonl.h" // for htonl
#include "debug.h" // for log_msg, LOG_LEVEL_ERROR, LOG_LEVEL_W...
#include "host.h" // for get_commandline_param, exit_uv, ADD_T...
#include "keyboard_control.h" // for keycontrol_register_key, keycontrol_s...
Expand Down Expand Up @@ -396,6 +397,11 @@ static bool display_sdl2_reconfigure(void *state, struct video_desc desc)
if (desc.interlacing == INTERLACED_MERGED && s->deinterlace == DEINT_OFF) {
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Receiving interlaced video but deinterlacing is off - suggesting toggling it on (press 'd' or pass cmdline option)\n");
}
if (desc.color_spec == R10k) {
MSG(WARNING,
"Displaying 10-bit RGB, which is experimentat. In case of "
"problems use '--param sdl2-r10k=no` and please report.\n");
}

pthread_mutex_lock(&s->lock);

Expand Down Expand Up @@ -444,16 +450,17 @@ static uint32_t get_ug_to_sdl_format(codec_t ug_codec) {
}

ADD_TO_PARAM("sdl2-r10k",
"* sdl2-r10k\n"
" Enable 10-bit RGB support for SDL2 (EXPERIMENTAL)\n");
"* sdl2-r10k[=no]\n"
" Enable/disable 10-bit RGB support for SDL2 (default: enabled)\n");

static int get_supported_pfs(codec_t *codecs) {
int count = 0;

for (unsigned int i = 0; i < sizeof pf_mapping / sizeof pf_mapping[0]; ++i) {
codecs[count++] = pf_mapping[i].first;
}
if (get_commandline_param("sdl2-r10k") != NULL) {
const char *sdl2_r10k_req = get_commandline_param("sdl2-r10k");
if (sdl2_r10k_req == NULL || strcmp(sdl2_r10k_req, "no") != 0) {
codecs[count++] = R10k;
}
return count;
Expand Down Expand Up @@ -823,6 +830,16 @@ static struct video_frame *display_sdl2_getf(void *state)
return buffer;
}

static void
r10k_to_sdl2(size_t count, uint32_t *buf)
{
unsigned int i = 0;
for (; i < count; ++i) {
uint32_t val = htonl(*buf);
*buf++ = val >> 2;
}
}

static bool display_sdl2_putf(void *state, struct video_frame *frame, long long timeout_ns)
{
struct state_sdl2 *s = (struct state_sdl2 *)state;
Expand All @@ -837,6 +854,12 @@ static bool display_sdl2_putf(void *state, struct video_frame *frame, long long
return true;
}

// fix endianity
if (frame->color_spec == R10k) {
r10k_to_sdl2(frame->tiles[0].data_len / 4,
(uint32_t *) frame->tiles[0].data);
}

pthread_mutex_lock(&s->lock);
if (timeout_ns == PUTF_DISCARD) {
assert(frame != NULL);
Expand Down

0 comments on commit 3c9e260

Please sign in to comment.