31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
111 if (hdr_size > data_size) {
119 "unsupported header version: %d\n", version);
125 if (width != avctx->
width || height != avctx->
height) {
127 "picture dimension changed: old: %d x %d, new: %d x %d\n",
135 "unsupported frame type: %d\n", ctx->
frame_type);
151 "unsupported picture format: %d\n", ctx->
pic_format);
184 if (ptr - buf > hdr_size - 64) {
199 if (ptr - buf > hdr_size - 64) {
219 int i, hdr_size, pic_data_size, num_slices;
220 int slice_width_factor, slice_height_factor;
221 int remainder, num_x_slices;
222 const uint8_t *data_ptr, *index_ptr;
224 hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
225 if (hdr_size < 8 || hdr_size > data_size) {
230 pic_data_size =
AV_RB32(buf + 1);
231 if (pic_data_size > data_size) {
236 slice_width_factor = buf[7] >> 4;
237 slice_height_factor = buf[7] & 0xF;
238 if (slice_width_factor > 3 || slice_height_factor) {
240 "unsupported slice dimension: %d x %d\n",
241 1 << slice_width_factor, 1 << slice_height_factor);
253 remainder = ctx->
num_x_mbs & ((1 << slice_width_factor) - 1);
254 num_x_slices = (ctx->
num_x_mbs >> slice_width_factor) + (remainder & 1) +
255 ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
257 num_slices = num_x_slices * ctx->
num_y_mbs;
258 if (num_slices !=
AV_RB16(buf + 5)) {
271 if (hdr_size + num_slices * 2 > data_size) {
277 index_ptr = buf + hdr_size;
278 data_ptr = index_ptr + num_slices * 2;
280 for (i = 0; i < num_slices; i++) {
283 data_ptr +=
AV_RB16(index_ptr + i * 2);
288 if (data_ptr > buf + data_size) {
293 return pic_data_size;
302 unsigned int rice_order, exp_order, switch_bits;
303 unsigned int buf, code;
304 int log, prefix_len,
len;
311 switch_bits = (codebook & 3) + 1;
312 rice_order = codebook >> 5;
313 exp_order = (codebook >> 2) & 7;
317 if (log < switch_bits) {
323 prefix_len = log + 1;
324 code = (log << rice_order) +
NEG_USR32(buf << prefix_len, rice_order);
328 len = (log << 1) - switch_bits + exp_order + 1;
329 code =
NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
338 #define LSB2SIGN(x) (-((x) & 1))
339 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
358 for (i = 1; i < nblocks; i++, out += 64) {
361 sign = -(((delta >> 15) & 1) ^ (code & 1));
362 delta = (((code + 1) >> 1) ^ sign) - sign;
373 int blocks_per_slice,
374 int plane_size_factor,
377 int pos, block_mask,
run,
level, sign, run_cb_index, lev_cb_index;
378 int max_coeffs, bits_left;
384 max_coeffs = blocks_per_slice << 6;
385 block_mask = blocks_per_slice - 1;
387 for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
392 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
398 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
404 if (pos >= max_coeffs)
408 out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
409 (level ^ sign) - sign;
419 int data_size, uint16_t *out_ptr,
420 int linesize,
int mbs_per_slice,
421 int blocks_per_mb,
int plane_size_factor,
422 const int16_t *qmat,
int is_chroma)
426 int mb_num, blocks_per_slice;
428 blocks_per_slice = mbs_per_slice * blocks_per_mb;
430 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
443 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
444 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
446 if (blocks_per_mb > 2) {
447 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
450 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
452 if (blocks_per_mb > 2) {
453 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
458 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
459 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
461 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
463 if (blocks_per_mb > 2) {
464 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
466 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
478 int mb_x_pos = td->
x_pos;
479 int mb_y_pos = td->
y_pos;
484 uint8_t *y_data, *u_data, *v_data;
486 int i, sf, slice_width_factor;
487 int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size;
488 int y_linesize, u_linesize, v_linesize;
493 slice_width_factor =
av_log2(mbs_per_slice);
495 y_data = pic->
data[0];
496 u_data = pic->
data[1];
497 v_data = pic->
data[2];
504 y_data += y_linesize;
505 u_data += u_linesize;
506 v_data += v_linesize;
513 if (slice_data_size < 6) {
519 hdr_size = buf[0] >> 3;
520 y_data_size =
AV_RB16(buf + 2);
521 u_data_size =
AV_RB16(buf + 4);
522 v_data_size = hdr_size > 7 ?
AV_RB16(buf + 6) :
523 slice_data_size - y_data_size - u_data_size - hdr_size;
525 if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size ||
526 v_data_size < 0 || hdr_size < 6) {
531 sf = av_clip(buf[1], 1, 224);
532 sf = sf > 128 ? (sf - 96) << 2 : sf;
538 for (i = 0; i < 64; i++) {
546 (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
547 (mb_x_pos << 5)), y_linesize,
548 mbs_per_slice, 4, slice_width_factor + 2,
553 (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize +
562 (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize +
575 int slice_num, slice_width, x_pos, y_pos;
580 for (y_pos = 0; y_pos < ctx->
num_y_mbs; y_pos++) {
583 for (x_pos = 0; x_pos < ctx->
num_x_mbs && slice_width;
584 x_pos += slice_width) {
585 while (ctx->
num_x_mbs - x_pos < slice_width)
603 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
611 int buf_size = avpkt->
size;
612 int frame_hdr_size, pic_num, pic_data_size;
615 if (buf_size < 28 || buf_size <
AV_RB32(buf) ||
624 if (frame_hdr_size < 0)
629 if (picture->
data[0])
638 if (pic_data_size < 0)
668 .
name =
"prores_lgpl",