Skip to content

Commit 02df683

Browse files
committed
mp_image: check all components for pl_bit_encoding in mp_image_setfmt
This matches the full logic used in vo_gpu_next.
1 parent 28ef6b7 commit 02df683

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

video/mp_image.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,25 @@ void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
200200
#else
201201
: PL_ALPHA_UNKNOWN;
202202
#endif
203-
mpi->params.repr.bits = (struct pl_bit_encoding) {
204-
.sample_depth = fmt.comps[0].size,
205-
.color_depth = fmt.comps[0].size - abs(fmt.comps[0].pad),
206-
.bit_shift = MPMAX(0, fmt.comps[0].pad),
207-
};
203+
// Calculate bit encoding from all components (excluding alpha)
204+
struct pl_bit_encoding bits = {0};
205+
const int num_comps = mp_imgfmt_desc_get_num_comps(&fmt);
206+
for (int c = 0; c < MPMIN(num_comps, 3); c++) {
207+
struct pl_bit_encoding cbits = {
208+
.sample_depth = fmt.comps[c].size,
209+
.color_depth = fmt.comps[c].size - abs(fmt.comps[c].pad),
210+
.bit_shift = MPMAX(fmt.comps[c].pad, 0),
211+
};
212+
213+
if (bits.sample_depth && !pl_bit_encoding_equal(&bits, &cbits)) {
214+
// Bit encoding differs between components, cannot handle this
215+
bits = (struct pl_bit_encoding) {0};
216+
break;
217+
}
218+
219+
bits = cbits;
220+
}
221+
mpi->params.repr.bits = bits;
208222
}
209223

210224
static void mp_image_destructor(void *ptr)

0 commit comments

Comments
 (0)