Cmpto J2K dec.: allow custom pitch for UYVY and RGB

Removed assertion to check standard pitch - non-standard ones should be
already supported. This allows decoding to framebuffers, where pitch
is not equal to line width, i. e. also for tiled video assembled to one
buffer.
This commit is contained in:
Martin Pulec
2020-04-22 08:42:45 +02:00
parent 28a64da913
commit 4dbc261590

View File

@@ -284,12 +284,6 @@ static int j2k_decompress_reconfigure(void *state, struct video_desc desc,
{
struct state_decompress_j2k *s = (struct state_decompress_j2k *) state;
/**
* @todo
* Different pitch can be fixed with custom output format (as for RGBA).
*/
assert(out_codec == RGBA || pitch == vc_get_linesize(desc.width, out_codec));
if (out_codec == VIDEO_CODEC_NONE) { // probe format
s->out_codec = VIDEO_CODEC_NONE;
s->desc = desc;
@@ -326,30 +320,50 @@ static int j2k_decompress_reconfigure(void *state, struct video_desc desc,
get_codec_name(out_codec));
abort();
}
if (cmpto_sf) {
if (cmpto_sf && pitch == vc_get_linesize(desc.width, out_codec)) {
CHECK_OK(cmpto_j2k_dec_cfg_set_samples_format_type(s->settings, cmpto_sf),
"Error setting sample format type", return false);
} else { // RGBA with non-standard shift or pitch
if (rshift % 8 != 0 || gshift % 8 != 0 || bshift % 8 != 0) {
LOG(LOG_LEVEL_ERROR) << MOD_NAME "Component shifts not aligned to a "
"byte boundary is not supported.\n";
return false;
}
} else { // non-standard pitch or RGBA with non-standard shift
cmpto_j2k_dec_comp_format fmt[3] = {};
const int shifts[3] = { rshift, gshift, bshift };
// set default values
for (int i = 0; i < 3; ++i) {
fmt[i].comp_index = i;
fmt[i].data_type = CMPTO_INT8;
fmt[i].offset = shifts[i] / 8;
fmt[i].stride_x = 4;
fmt[i].offset = i;
fmt[i].stride_x = get_bpp(out_codec);
fmt[i].stride_y = pitch;
fmt[i].bit_depth = 8;
fmt[i].bit_depth = get_bits_per_component(out_codec);
fmt[i].bit_shift = 0;
fmt[i].is_or_combined = 0;
fmt[i].is_signed = 0;
fmt[i].sampling_factor_x = 1;
fmt[i].sampling_factor_y = 1;
}
// overrides
if (out_codec == RGBA) {
if (rshift % 8 != 0 || gshift % 8 != 0 || bshift % 8 != 0) {
LOG(LOG_LEVEL_ERROR) << MOD_NAME "Component shifts not aligned to a "
"byte boundary is not supported.\n";
return false;
}
fmt[0].offset = rshift / 8;
fmt[1].offset = gshift / 8;
fmt[2].offset = bshift / 8;
} else if (out_codec == UYVY) {
fmt[0].offset = 1;
fmt[0].stride_x = 2;
fmt[1].offset = 0;
fmt[1].stride_x = 4;
fmt[1].sampling_factor_x = 2;
fmt[2].offset = 2;
fmt[2].stride_x = 4;
fmt[2].sampling_factor_x = 2;
} else if (out_codec != RGB) { // RGB doesn't need any override
LOG(LOG_LEVEL_ERROR) << MOD_NAME "Decoding to " << get_codec_name(out_codec)
<< " with custom pitch is not yet supported.\n";
return false;
}
CHECK_OK(cmpto_j2k_dec_cfg_set_samples_format(s->settings, fmt, 3),
"Error setting sample format", return false);
}