Skip to content

Commit 02f47c8

Browse files
haasnsfan5
authored andcommitted
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 a310a65 commit 02f47c8

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
@@ -201,11 +201,25 @@ void mp_image_sethwfmt(struct mp_image *mpi, enum mp_imgfmt hw_fmt, enum mp_imgf
201201
#else
202202
: PL_ALPHA_UNKNOWN;
203203
#endif
204-
mpi->params.repr.bits = (struct pl_bit_encoding) {
205-
.sample_depth = fmt.comps[0].size,
206-
.color_depth = fmt.comps[0].size - abs(fmt.comps[0].pad),
207-
.bit_shift = MPMAX(0, fmt.comps[0].pad),
208-
};
204+
// Calculate bit encoding from all components (excluding alpha)
205+
struct pl_bit_encoding bits = {0};
206+
const int num_comps = mp_imgfmt_desc_get_num_comps(&fmt);
207+
for (int c = 0; c < MPMIN(num_comps, 3); c++) {
208+
struct pl_bit_encoding cbits = {
209+
.sample_depth = fmt.comps[c].size,
210+
.color_depth = fmt.comps[c].size - abs(fmt.comps[c].pad),
211+
.bit_shift = MPMAX(fmt.comps[c].pad, 0),
212+
};
213+
214+
if (bits.sample_depth && !pl_bit_encoding_equal(&bits, &cbits)) {
215+
// Bit encoding differs between components, cannot handle this
216+
bits = (struct pl_bit_encoding) {0};
217+
break;
218+
}
219+
220+
bits = cbits;
221+
}
222+
mpi->params.repr.bits = bits;
209223
}
210224

211225
void mp_image_setfmt(struct mp_image *mpi, enum mp_imgfmt fmt)

0 commit comments

Comments
 (0)