Lines Matching refs:ctx

153 static av_cold void free_frame_buffers(Indeo3DecodeContext *ctx)
157 ctx->width = ctx->height = 0;
160 av_freep(&ctx->planes[p].buffers[0]);
161 av_freep(&ctx->planes[p].buffers[1]);
162 ctx->planes[p].pixels[0] = ctx->planes[p].pixels[1] = 0;
167 static av_cold int allocate_frame_buffers(Indeo3DecodeContext *ctx,
182 ctx->width = luma_width ;
183 ctx->height = luma_height;
201 ctx->planes[p].pitch = !p ? luma_pitch : chroma_pitch;
202 ctx->planes[p].width = !p ? luma_width : chroma_width;
203 ctx->planes[p].height = !p ? luma_height : chroma_height;
205 ctx->planes[p].buffers[0] = av_malloc(!p ? luma_size : chroma_size);
206 ctx->planes[p].buffers[1] = av_malloc(!p ? luma_size : chroma_size);
208 if (!ctx->planes[p].buffers[0] || !ctx->planes[p].buffers[1])
212 memset(ctx->planes[p].buffers[0], 0x40, ctx->planes[p].pitch);
213 memset(ctx->planes[p].buffers[1], 0x40, ctx->planes[p].pitch);
216 ctx->planes[p].pixels[0] = ctx->planes[p].buffers[0] + ctx->planes[p].pitch;
217 ctx->planes[p].pixels[1] = ctx->planes[p].buffers[1] + ctx->planes[p].pitch;
218 memset(ctx->planes[p].pixels[0], 0, ctx->planes[p].pitch * ctx->planes[p].height);
219 memset(ctx->planes[p].pixels[1], 0, ctx->planes[p].pitch * ctx->planes[p].height);
229 * @param ctx pointer to the decoder context
233 static int copy_cell(Indeo3DecodeContext *ctx, Plane *plane, Cell *cell)
240 dst = plane->pixels[ctx->buf_sel] + offset_dst;
251 av_log(ctx->avctx, AV_LOG_ERROR,
257 src = plane->pixels[ctx->buf_sel ^ 1] + offset;
265 ctx->hdsp.put_pixels_tab[0][0](dst, src, plane->pitch, h);
270 ctx->hdsp.put_pixels_tab[1][0](dst, src, plane->pitch, h);
275 ctx->hdsp.put_pixels_tab[2][0](dst, src, plane->pitch, h);
427 static int decode_cell_data(Indeo3DecodeContext *ctx, Cell *cell,
575 * @param ctx pointer to the decoder context
583 static int decode_cell(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
601 block = plane->pixels[ctx->buf_sel] + offset;
609 int ret = copy_cell(ctx, plane, cell);
621 av_log(ctx->avctx, AV_LOG_ERROR,
627 ref_block = plane->pixels[ctx->buf_sel ^ 1] + offset;
634 code = ctx->alt_quant[vq_index];
635 prim_indx = (code >> 4) + ctx->cb_offset;
636 second_indx = (code & 0xF) + ctx->cb_offset;
638 vq_index += ctx->cb_offset;
673 error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch,
680 error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch,
690 error = decode_cell_data(ctx, cell, block, ref_block, plane->pitch,
735 ctx->skip_bits += (n); \
736 ctx->need_resync = 1
739 if (ctx->need_resync && !(get_bits_count(&ctx->gb) & 7)) { \
740 skip_bits_long(&ctx->gb, ctx->skip_bits); \
741 ctx->skip_bits = 0; \
742 ctx->need_resync = 0; \
754 static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
785 while (get_bits_left(&ctx->gb) >= 2) { /* loop until return */
787 switch (code = get_bits(&ctx->gb, 2)) {
790 if (parse_bintree(ctx, avctx, plane, code, &curr_cell, depth - 1, strip_width))
799 code = get_bits(&ctx->gb, 2);
811 ret = copy_cell(ctx, plane, &curr_cell);
819 if (!ctx->need_resync)
820 ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
821 if (ctx->next_cell_data >= ctx->last_byte) {
825 mv_idx = *(ctx->next_cell_data++);
826 if (mv_idx >= ctx->num_vectors) {
830 curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx << 1];
834 if (!ctx->need_resync)
835 ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
838 bytes_used = decode_cell(ctx, avctx, plane, &curr_cell,
839 ctx->next_cell_data, ctx->last_byte);
844 ctx->next_cell_data += bytes_used;
855 static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
866 av_log(ctx->avctx, AV_LOG_ERROR,
873 ctx->num_vectors = num_vectors;
874 ctx->mc_vectors = num_vectors ? data : 0;
877 init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3);
878 ctx->skip_bits = 0;
879 ctx->need_resync = 0;
881 ctx->last_byte = data + data_size;
890 return parse_bintree(ctx, avctx, plane, INTRA_NULL, &curr_cell, CELL_STACK_MAX, strip_width);
896 static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
928 ctx->frame_num = frame_num;
929 ctx->frame_flags = bytestream2_get_le16(&gb);
930 ctx->data_size = (bytestream2_get_le32(&gb) + 7) >> 3;
931 ctx->cb_offset = bytestream2_get_byte(&gb);
933 if (ctx->data_size == 16)
935 ctx->data_size = FFMIN(ctx->data_size, buf_size - 16);
945 if (width != ctx->width || height != ctx->height) {
957 free_frame_buffers(ctx);
958 if ((res = allocate_frame_buffers(ctx, avctx, width, height)) < 0)
976 ends[j] = ctx->data_size;
982 ctx->y_data_size = ends[0] - starts[0];
983 ctx->v_data_size = ends[1] - starts[1];
984 ctx->u_data_size = ends[2] - starts[2];
986 FFMAX3(y_offset, v_offset, u_offset) >= ctx->data_size - 16 ||
988 FFMIN3(ctx->y_data_size, ctx->v_data_size, ctx->u_data_size) <= 0) {
993 ctx->y_data_ptr = bs_hdr + y_offset;
994 ctx->v_data_ptr = bs_hdr + v_offset;
995 ctx->u_data_ptr = bs_hdr + u_offset;
996 ctx->alt_quant = gb.buffer;
998 if (ctx->data_size == 16) {
1003 if (ctx->frame_flags & BS_8BIT_PEL) {
1008 if (ctx->frame_flags & BS_MV_X_HALF || ctx->frame_flags & BS_MV_Y_HALF) {
1055 Indeo3DecodeContext *ctx = avctx->priv_data;
1057 ctx->avctx = avctx;
1062 ff_hpeldsp_init(&ctx->hdsp, avctx->flags);
1064 return allocate_frame_buffers(ctx, avctx, avctx->width, avctx->height);
1071 Indeo3DecodeContext *ctx = avctx->priv_data;
1076 res = decode_frame_headers(ctx, avctx, buf, buf_size);
1088 if (ctx->frame_flags & BS_NONREF &&
1093 if (!(ctx->frame_flags & BS_KEYFRAME) && avctx->skip_frame >= AVDISCARD_NONKEY)
1097 ctx->buf_sel = (ctx->frame_flags >> BS_BUFFER) & 1;
1103 if ((res = decode_plane(ctx, avctx, ctx->planes, ctx->y_data_ptr, ctx->y_data_size, 40)))
1107 if ((res = decode_plane(ctx, avctx, &ctx->planes[1], ctx->u_data_ptr, ctx->u_data_size, 10)))
1110 if ((res = decode_plane(ctx, avctx, &ctx->planes[2], ctx->v_data_ptr, ctx->v_data_size, 10)))
1113 output_plane(&ctx->planes[0], ctx->buf_sel,
1116 output_plane(&ctx->planes[1], ctx->buf_sel,
1119 output_plane(&ctx->planes[2], ctx->buf_sel,