#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avcodec.h"
-#include "dsputil.h"
+#include "me_cmp.h"
#include "snow_dwt.h"
#include "internal.h"
#include "snow.h"
}
}
+int ff_snow_get_buffer(SnowContext *s, AVFrame *frame)
+{
+ int ret, i;
+ int edges_needed = av_codec_is_encoder(s->avctx->codec);
+
+ frame->width = s->avctx->width ;
+ frame->height = s->avctx->height;
+ if (edges_needed) {
+ frame->width += 2 * EDGE_WIDTH;
+ frame->height += 2 * EDGE_WIDTH;
+ }
+ if ((ret = ff_get_buffer(s->avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
+ return ret;
+ if (edges_needed) {
+ for (i = 0; frame->data[i]; i++) {
+ int offset = (EDGE_WIDTH >> (i ? s->chroma_v_shift : 0)) *
+ frame->linesize[i] +
+ (EDGE_WIDTH >> (i ? s->chroma_h_shift : 0));
+ frame->data[i] += offset;
+ }
+ frame->width = s->avctx->width;
+ frame->height = s->avctx->height;
+ }
+
+ return 0;
+}
+
void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts
int plane_index, level, orientation;
s->b_height= h;
av_free(s->block);
- s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2));
+ s->block= av_mallocz_array(w * h, sizeof(BlockNode) << (s->block_max_depth*2));
if (!s->block)
return AVERROR(ENOMEM);
av_assert2(s->chroma_h_shift == s->chroma_v_shift); // only one mv_scale
- av_assert2(b_w>1 && b_h>1);
av_assert2((tab_index>=0 && tab_index<4) || b_w==32);
- if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)) || !s->plane[plane_index].fast_mc )
+ if( (dx&3) || (dy&3)
+ || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h)
+ || (b_w&(b_w-1))
+ || b_w == 1
+ || b_h == 1
+ || !s->plane[plane_index].fast_mc )
mc_block(&s->plane[plane_index], dst, src, stride, b_w, b_h, dx, dy);
else if(b_w==32){
int y;
s->avctx= avctx;
s->max_ref_frames=1; //just make sure it's not an invalid value in case of no initial keyframe
- ff_dsputil_init(&s->dsp, avctx);
+ ff_me_cmp_init(&s->mecc, avctx);
ff_hpeldsp_init(&s->hdsp, avctx->flags);
ff_videodsp_init(&s->vdsp, 8);
ff_dwt_init(&s->dwt);
ff_h264qpel_init(&s->h264qpel, 8);
#define mcf(dx,dy)\
- s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\
- s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
+ s->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\
+ s->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
- s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\
- s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
+ s->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\
+ s->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
mcf( 0, 0)
width= s->avctx->width;
height= s->avctx->height;
- FF_ALLOCZ_OR_GOTO(avctx, s->spatial_idwt_buffer, width * height * sizeof(IDWTELEM), fail);
- FF_ALLOCZ_OR_GOTO(avctx, s->spatial_dwt_buffer, width * height * sizeof(DWTELEM), fail); //FIXME this does not belong here
- FF_ALLOCZ_OR_GOTO(avctx, s->temp_dwt_buffer, width * sizeof(DWTELEM), fail);
- FF_ALLOCZ_OR_GOTO(avctx, s->temp_idwt_buffer, width * sizeof(IDWTELEM), fail);
- FF_ALLOC_OR_GOTO(avctx, s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) * sizeof(*s->run_buffer), fail);
+ FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->spatial_idwt_buffer, width, height * sizeof(IDWTELEM), fail);
+ FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->spatial_dwt_buffer, width, height * sizeof(DWTELEM), fail); //FIXME this does not belong here
+ FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->temp_dwt_buffer, width, sizeof(DWTELEM), fail);
+ FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->temp_idwt_buffer, width, sizeof(IDWTELEM), fail);
+ FF_ALLOC_ARRAY_OR_GOTO(avctx, s->run_buffer, ((width + 1) >> 1), ((height + 1) >> 1) * sizeof(*s->run_buffer), fail);
for(i=0; i<MAX_REF_FRAMES; i++) {
for(j=0; j<MAX_REF_FRAMES; j++)
if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
- FF_ALLOCZ_OR_GOTO(avctx, s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256)*7*MB_SIZE, fail);
+ FF_ALLOCZ_ARRAY_OR_GOTO(avctx, s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256), 7*MB_SIZE, fail);
emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
FF_ALLOC_OR_GOTO(avctx, s->emu_edge_buffer, emu_buf_size, fail);
}
b->parent= &s->plane[plane_index].band[level-1][orientation];
//FIXME avoid this realloc
av_freep(&b->x_coeff);
- b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff));
+ b->x_coeff=av_mallocz_array(((b->width+1) * b->height+1), sizeof(x_and_coeff));
if (!b->x_coeff)
goto fail;
}
int ff_snow_frame_start(SnowContext *s){
AVFrame *tmp;
int i, ret;
- int w= s->avctx->width; //FIXME round up to x16 ?
- int h= s->avctx->height;
-
- if (s->current_picture->data[0] && !(s->avctx->flags&CODEC_FLAG_EMU_EDGE)) {
- s->dsp.draw_edges(s->current_picture->data[0],
- s->current_picture->linesize[0], w , h ,
- EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM);
- if (s->current_picture->data[2]) {
- s->dsp.draw_edges(s->current_picture->data[1],
- s->current_picture->linesize[1], w>>s->chroma_h_shift, h>>s->chroma_v_shift,
- EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM);
- s->dsp.draw_edges(s->current_picture->data[2],
- s->current_picture->linesize[2], w>>s->chroma_h_shift, h>>s->chroma_v_shift,
- EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM);
- }
- }
ff_snow_release_buffer(s->avctx);
return -1;
}
}
-
- if ((ret = ff_get_buffer(s->avctx, s->current_picture, AV_GET_BUFFER_FLAG_REF)) < 0)
+ if ((ret = ff_snow_get_buffer(s, s->current_picture)) < 0)
return ret;
s->current_picture->key_frame= s->keyframe;
for(i=0; i<MAX_REF_FRAMES; i++){
av_freep(&s->ref_mvs[i]);
av_freep(&s->ref_scores[i]);
- if(s->last_picture[i]->data[0]) {
+ if(s->last_picture[i] && s->last_picture[i]->data[0]) {
av_assert0(s->last_picture[i]->data[0] != s->current_picture->data[0]);
}
av_frame_free(&s->last_picture[i]);