Skip to content

Commit 905f5c5

Browse files
committed
vo_gpu_next: separate pl_bit_encoding from pl_plane_data handling
So we can use it on hwdec frames too.
1 parent 28ef6b7 commit 905f5c5

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

video/out/vo_gpu_next.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,30 @@ struct frame_priv {
425425
struct ra_hwdec *hwdec;
426426
};
427427

428+
static struct pl_bit_encoding plane_bits_from_imgfmt(enum mp_imgfmt imgfmt)
429+
{
430+
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(imgfmt);
431+
struct pl_bit_encoding bits = {0};
432+
433+
const int num_comps = mp_imgfmt_desc_get_num_comps(&desc);
434+
for (int c = 0; c < MPMIN(num_comps, 3); c++) {
435+
struct pl_bit_encoding cbits = {
436+
.sample_depth = desc.comps[c].size,
437+
.color_depth = desc.comps[c].size - abs(desc.comps[c].pad),
438+
.bit_shift = MPMAX(desc.comps[c].pad, 0),
439+
};
440+
441+
if (bits.sample_depth && !pl_bit_encoding_equal(&bits, &cbits)) {
442+
// Bit encoding differs between components, cannot handle this
443+
return (struct pl_bit_encoding) {0};
444+
}
445+
446+
bits = cbits;
447+
}
448+
449+
return bits;
450+
}
451+
428452
static int plane_data_from_imgfmt(struct pl_plane_data out_data[4],
429453
struct pl_bit_encoding *out_bits,
430454
enum mp_imgfmt imgfmt, bool use_uint)
@@ -445,7 +469,6 @@ static int plane_data_from_imgfmt(struct pl_plane_data out_data[4],
445469
if ((desc.flags & MP_IMGFLAG_TYPE_FLOAT) && (desc.flags & MP_IMGFLAG_YUV))
446470
return 0; // Floating-point YUV (currently) unsupported
447471

448-
bool has_bits = false;
449472
bool any_padded = false;
450473

451474
for (int p = 0; p < desc.num_planes; p++) {
@@ -482,28 +505,6 @@ static int plane_data_from_imgfmt(struct pl_plane_data out_data[4],
482505
data->component_pad[c] = sorted[c].offset - total_bits;
483506
total_bits += data->component_pad[c] + data->component_size[c];
484507
any_padded |= sorted[c].pad;
485-
486-
// Ignore bit encoding of alpha channel
487-
if (!out_bits || data->component_map[c] == PL_CHANNEL_A)
488-
continue;
489-
490-
struct pl_bit_encoding bits = {
491-
.sample_depth = data->component_size[c],
492-
.color_depth = sorted[c].size - abs(sorted[c].pad),
493-
.bit_shift = MPMAX(sorted[c].pad, 0),
494-
};
495-
496-
if (!has_bits) {
497-
*out_bits = bits;
498-
has_bits = true;
499-
} else {
500-
if (!pl_bit_encoding_equal(out_bits, &bits)) {
501-
// Bit encoding differs between components/planes,
502-
// cannot handle this
503-
*out_bits = (struct pl_bit_encoding) {0};
504-
out_bits = NULL;
505-
}
506-
}
507508
}
508509

509510
data->pixel_stride = desc.bpp[p] / 8;
@@ -512,8 +513,11 @@ static int plane_data_from_imgfmt(struct pl_plane_data out_data[4],
512513
: (use_uint ? PL_FMT_UINT : PL_FMT_UNORM);
513514
}
514515

515-
if (any_padded && !out_bits)
516+
if (out_bits) {
517+
plane_bits_from_imgfmt(imgfmt);
518+
} else if (any_padded) {
516519
return 0; // can't handle padded components without `pl_bit_encoding`
520+
}
517521

518522
return desc.num_planes;
519523
}

0 commit comments

Comments
 (0)