31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
106 if (hdr_size > data_size) {
114 "unsupported header version: %d\n", version);
120 if (width != avctx->
width || height != avctx->
height) {
122 "picture dimension changed: old: %d x %d, new: %d x %d\n",
130 "unsupported frame type: %d\n", ctx->
frame_type);
156 "unsupported picture format: %d\n", ctx->
pic_format);
185 if (ptr - buf > hdr_size - 64) {
200 if (ptr - buf > hdr_size - 64) {
220 int i, hdr_size, pic_data_size, num_slices;
221 int slice_width_factor, slice_height_factor;
222 int remainder, num_x_slices;
223 const uint8_t *data_ptr, *index_ptr;
225 hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
226 if (hdr_size < 8 || hdr_size > data_size) {
231 pic_data_size =
AV_RB32(buf + 1);
232 if (pic_data_size > data_size) {
237 slice_width_factor = buf[7] >> 4;
238 slice_height_factor = buf[7] & 0xF;
239 if (slice_width_factor > 3 || slice_height_factor) {
241 "unsupported slice dimension: %d x %d\n",
242 1 << slice_width_factor, 1 << slice_height_factor);
254 remainder = ctx->
num_x_mbs & ((1 << slice_width_factor) - 1);
255 num_x_slices = (ctx->
num_x_mbs >> slice_width_factor) + (remainder & 1) +
256 ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
258 num_slices = num_x_slices * ctx->
num_y_mbs;
259 if (num_slices !=
AV_RB16(buf + 5)) {
272 if (hdr_size + num_slices * 2 > data_size) {
278 index_ptr = buf + hdr_size;
279 data_ptr = index_ptr + num_slices * 2;
281 for (i = 0; i < num_slices; i++) {
284 data_ptr +=
AV_RB16(index_ptr + i * 2);
289 if (data_ptr > buf + data_size) {
294 return pic_data_size;
303 unsigned int rice_order, exp_order, switch_bits;
304 unsigned int buf, code;
305 int log, prefix_len,
len;
312 switch_bits = (codebook & 3) + 1;
313 rice_order = codebook >> 5;
314 exp_order = (codebook >> 2) & 7;
318 if (log < switch_bits) {
324 prefix_len = log + 1;
325 code = (log << rice_order) +
NEG_USR32(buf << prefix_len, rice_order);
329 len = (log << 1) - switch_bits + exp_order + 1;
330 code =
NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
339 #define LSB2SIGN(x) (-((x) & 1))
340 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
359 for (i = 1; i < nblocks; i++, out += 64) {
362 sign = -(((delta >> 15) & 1) ^ (code & 1));
363 delta = (((code + 1) >> 1) ^ sign) - sign;
374 int blocks_per_slice,
375 int plane_size_factor,
378 int pos, block_mask,
run,
level, sign, run_cb_index, lev_cb_index;
379 int max_coeffs, bits_left;
385 max_coeffs = blocks_per_slice << 6;
386 block_mask = blocks_per_slice - 1;
388 for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
393 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
401 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
409 if (pos >= max_coeffs)
413 out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
414 (level ^ sign) - sign;
427 int linesize,
int mbs_per_slice,
428 int blocks_per_mb,
int plane_size_factor,
429 const int16_t *qmat,
int is_chroma)
433 int mb_num, blocks_per_slice,
ret;
435 blocks_per_slice = mbs_per_slice * blocks_per_mb;
437 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
452 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
453 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
455 if (blocks_per_mb > 2) {
456 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
459 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
461 if (blocks_per_mb > 2) {
462 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
467 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
468 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
470 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
472 if (blocks_per_mb > 2) {
473 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
475 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
487 const int mask = (1 << num_bits) - 1;
488 int i, idx,
val, alpha_val;
498 val =
get_bits(gb, num_bits == 16 ? 7 : 4);
500 val = (val + 2) >> 1;
504 alpha_val = (alpha_val +
val) & mask;
506 dst[idx++] = alpha_val >> 6;
508 dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
509 if (idx >= num_coeffs) {
516 if (idx + val > num_coeffs)
517 val = num_coeffs - idx;
519 for (i = 0; i <
val; i++)
520 dst[idx++] = alpha_val >> 6;
522 for (i = 0; i <
val; i++)
523 dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
524 }
while (idx < num_coeffs);
532 uint16_t *out_ptr,
int linesize,
539 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
550 for (i = 0; i < 16; i++) {
551 memcpy(out_ptr, block_ptr, 16 * mbs_per_slice *
sizeof(*out_ptr));
552 out_ptr += linesize >> 1;
553 block_ptr += 16 * mbs_per_slice;
561 int mb_x_pos = td->
x_pos;
562 int mb_y_pos = td->
y_pos;
567 uint8_t *y_data, *u_data, *v_data, *a_data;
569 int i, sf, slice_width_factor;
570 int slice_data_size, hdr_size;
571 int y_data_size, u_data_size, v_data_size, a_data_size;
572 int y_linesize, u_linesize, v_linesize, a_linesize;
579 slice_width_factor =
av_log2(mbs_per_slice);
581 y_data = pic->
data[0];
582 u_data = pic->
data[1];
583 v_data = pic->
data[2];
584 a_data = pic->
data[3];
592 y_data += y_linesize;
593 u_data += u_linesize;
594 v_data += v_linesize;
596 a_data += a_linesize;
603 y_data += (mb_y_pos << 4) * y_linesize + (mb_x_pos << 5);
604 u_data += (mb_y_pos << 4) * u_linesize + (mb_x_pos << ctx->
mb_chroma_factor);
605 v_data += (mb_y_pos << 4) * v_linesize + (mb_x_pos << ctx->
mb_chroma_factor);
607 a_data += (mb_y_pos << 4) * a_linesize + (mb_x_pos << 5);
609 if (slice_data_size < 6) {
615 hdr_size = buf[0] >> 3;
617 y_data_size =
AV_RB16(buf + 2);
618 coff[1] = coff[0] + y_data_size;
619 u_data_size =
AV_RB16(buf + 4);
620 coff[2] = coff[1] + u_data_size;
621 v_data_size = hdr_size > 7 ?
AV_RB16(buf + 6) : slice_data_size - coff[2];
622 coff[3] = coff[2] + v_data_size;
623 a_data_size = ctx->
alpha_info ? slice_data_size - coff[3] : 0;
627 if (v_data_size < 0 || a_data_size < 0 || hdr_size < 6) {
632 sf = av_clip(buf[1], 1, 224);
633 sf = sf > 128 ? (sf - 96) << 2 : sf;
639 for (i = 0; i < 64; i++) {
647 (uint16_t*) y_data, y_linesize,
648 mbs_per_slice, 4, slice_width_factor + 2,
656 (uint16_t*) u_data, u_linesize,
665 (uint16_t*) v_data, v_linesize,
673 if (a_data && a_data_size)
675 (uint16_t*) a_data, a_linesize,
685 int slice_num, slice_width, x_pos, y_pos;
690 for (y_pos = 0; y_pos < ctx->
num_y_mbs; y_pos++) {
693 for (x_pos = 0; x_pos < ctx->
num_x_mbs && slice_width;
694 x_pos += slice_width) {
695 while (ctx->
num_x_mbs - x_pos < slice_width)
713 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
720 int buf_size = avpkt->
size;
721 int frame_hdr_size, pic_num, pic_data_size;
728 if (buf_size < 28 || buf_size <
AV_RB32(buf) ||
737 if (frame_hdr_size < 0)
747 if (pic_data_size < 0)
774 .
name =
"prores_lgpl",