mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 09:40:30 +00:00
Testcard: simplify the control flow a bit
This commit is contained in:
@@ -620,26 +620,24 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
|
||||
auto free_deleter = static_cast<void (*)(unsigned char*)>([](unsigned char *ptr){ free(ptr); });
|
||||
auto delarr_deleter = static_cast<void (*)(unsigned char*)>([](unsigned char *ptr){ delete [] ptr; });
|
||||
|
||||
codec_t codec_first = s->frame->color_spec; // intermediate pixfmt used for with 2-step conversions
|
||||
if (s->frame->color_spec == I420 || s->frame->color_spec == v210 || s->frame->color_spec == UYVY || s->frame->color_spec == YUYV
|
||||
|| s->frame->color_spec == RG48 || s->frame->color_spec == R12L || s->frame->color_spec == R10k
|
||||
|| s->frame->color_spec == RGB || s->frame->color_spec == Y216) {
|
||||
codec_t codec_to = s->frame->color_spec;
|
||||
if (s->frame->color_spec == I420 || s->frame->color_spec == v210 || s->frame->color_spec == YUYV || s->frame->color_spec == Y216) { // no direct conversion from RGBA
|
||||
codec_to = UYVY;
|
||||
if (s->frame->color_spec == Y216 || s->frame->color_spec == v210) { ///< those codecs will continue with @ref second_step
|
||||
codec_first = UYVY;
|
||||
}
|
||||
codec_t codec_intermediate = s->frame->color_spec;
|
||||
|
||||
/// first step - conversion from RGBA
|
||||
if (s->frame->color_spec != RGBA) {
|
||||
// these codecs do not have direct conversion from RGBA - use @ref second_conversion_step
|
||||
if (s->frame->color_spec == I420 || s->frame->color_spec == v210 || s->frame->color_spec == YUYV || s->frame->color_spec == Y216) {
|
||||
codec_intermediate = UYVY;
|
||||
}
|
||||
if (s->frame->color_spec == R12L) {
|
||||
codec_first = codec_to = RGB;
|
||||
codec_intermediate = RGB;
|
||||
}
|
||||
auto decoder = get_decoder_from_to(RGBA, codec_to, true);
|
||||
|
||||
auto decoder = get_decoder_from_to(RGBA, codec_intermediate, true);
|
||||
assert(decoder != nullptr);
|
||||
auto src = move(data);
|
||||
data = decltype(data)(new unsigned char [s->frame->tiles[0].height * vc_get_linesize(s->frame->tiles[0].width, codec_to) + headroom], delarr_deleter);
|
||||
data = decltype(data)(new unsigned char [s->frame->tiles[0].height * vc_get_linesize(s->frame->tiles[0].width, codec_intermediate) + headroom], delarr_deleter);
|
||||
size_t src_linesize = vc_get_linesize(s->frame->tiles[0].width, RGBA);
|
||||
size_t dst_linesize = vc_get_linesize(s->frame->tiles[0].width, codec_to);
|
||||
size_t dst_linesize = vc_get_linesize(s->frame->tiles[0].width, codec_intermediate);
|
||||
auto *in = src.get();
|
||||
auto *out = data.get();
|
||||
for (unsigned int i = 0; i < s->frame->tiles[0].height; ++i) {
|
||||
@@ -649,18 +647,21 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
|
||||
}
|
||||
}
|
||||
|
||||
/// @anchor second_conversion_step for some codecs
|
||||
if (s->frame->color_spec == I420) {
|
||||
auto src = move(data);
|
||||
data = decltype(data)(reinterpret_cast<unsigned char *>((toI420(reinterpret_cast<char *>(src.get()), s->frame->tiles[0].width, s->frame->tiles[0].height))), free_deleter);
|
||||
}
|
||||
|
||||
if (codec_first != s->frame->color_spec) { ///< @anchor second_step
|
||||
} else if (s->frame->color_spec == YUYV) {
|
||||
for (unsigned int i = 0; i < s->frame->tiles[0].data_len; i += 2) {
|
||||
swap(data[i], data[i + 1]);
|
||||
}
|
||||
} else if (codec_intermediate != s->frame->color_spec) {
|
||||
auto src = move(data);
|
||||
data = decltype(data)(new unsigned char[s->frame->tiles[0].data_len], delarr_deleter);
|
||||
auto decoder = get_decoder_from_to(codec_first, s->frame->color_spec, true);
|
||||
auto decoder = get_decoder_from_to(codec_intermediate, s->frame->color_spec, true);
|
||||
assert(decoder != nullptr);
|
||||
|
||||
int src_linesize = vc_get_linesize(s->frame->tiles[0].width, codec_first);
|
||||
int src_linesize = vc_get_linesize(s->frame->tiles[0].width, codec_intermediate);
|
||||
int dst_linesize = vc_get_linesize(s->frame->tiles[0].width, s->frame->color_spec);
|
||||
for (int i = 0; i < (int) vf_get_tile(s->frame, 0)->height; ++i) {
|
||||
decoder(data.get() + i * dst_linesize,
|
||||
@@ -668,12 +669,6 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
|
||||
}
|
||||
}
|
||||
|
||||
if(s->frame->color_spec == YUYV) {
|
||||
for (unsigned int i = 0; i < s->frame->tiles[0].data_len; i += 2) {
|
||||
swap(data[i], data[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(vf_get_tile(s->frame, 0)->data, data.get(), s->frame->tiles[0].data_len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user