File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff 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
210224static void mp_image_destructor (void * ptr )
You can’t perform that action at this time.
0 commit comments