#include "avcodec.h"
#include "dct.h"
#include "dsputil.h"
+#include "idctdsp.h"
#include "mpeg12.h"
#include "mpegvideo.h"
#include "h261.h"
#include "h263.h"
+#include "mjpegenc_common.h"
#include "mathops.h"
#include "mpegutils.h"
#include "mjpegenc.h"
{ NULL },
};
-void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
+void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64],
uint16_t (*qmat16)[2][64],
const uint16_t *quant_matrix,
int bias, int qmin, int qmax, int intra)
{
+ DSPContext *dsp = &s->dsp;
int qscale;
int shift = 0;
dsp->fdct == ff_jpeg_fdct_islow_10 ||
dsp->fdct == ff_faandct) {
for (i = 0; i < 64; i++) {
- const int j = dsp->idct_permutation[i];
+ const int j = s->idsp.idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905
* Assume x = ff_aanscales[i] * qscale * quant_matrix[i]
* 19952 <= x <= 249205026
}
} else if (dsp->fdct == ff_fdct_ifast) {
for (i = 0; i < 64; i++) {
- const int j = dsp->idct_permutation[i];
+ const int j = s->idsp.idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905
* Assume x = ff_aanscales[i] * qscale * quant_matrix[i]
* 19952 <= x <= 249205026
}
} else {
for (i = 0; i < 64; i++) {
- const int j = dsp->idct_permutation[i];
+ const int j = s->idsp.idct_permutation[i];
/* We can safely suppose that 16 <= quant_matrix[i] <= 255
* Assume x = qscale * quant_matrix[i]
* So 16 <= x <= 7905
if (ff_MPV_common_init(s) < 0)
return -1;
+ ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
ff_qpeldsp_init(&s->qdsp);
s->avctx->coded_frame = s->current_picture.f;
/* init q matrix */
for (i = 0; i < 64; i++) {
- int j = s->dsp.idct_permutation[i];
+ int j = s->idsp.idct_permutation[i];
if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 &&
s->mpeg_quant) {
s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
/* precompute matrix */
/* for mjpeg, we do include qscale in the matrix */
if (s->out_format != FMT_MJPEG) {
- ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
+ ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16,
s->intra_matrix, s->intra_quant_bias, avctx->qmin,
31, 1);
- ff_convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16,
+ ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16,
s->inter_matrix, s->inter_quant_bias, avctx->qmin,
31, 0);
}
int offset = x + y * stride;
int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride,
16);
- int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8;
+ int mean = (s->mpvencdsp.pix_sum(src + offset, stride) + 128) >> 8;
int sae = get_sae(src + offset, mean, stride);
acc += sae + 500 < sad;
}
}
if ((s->width & 15) || (s->height & (vpad-1))) {
- s->dsp.draw_edges(dst, dst_stride,
- w, h,
- 16>>h_shift,
- vpad>>v_shift,
- EDGE_BOTTOM);
+ s->mpvencdsp.draw_edges(dst, dst_stride,
+ w, h,
+ 16>>h_shift,
+ vpad>>v_shift,
+ EDGE_BOTTOM);
}
}
}
for (i = 0; i < s->max_b_frames + 2; i++) {
Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
s->next_picture_ptr;
+ uint8_t *data[4];
if (pre_input_ptr && (!i || s->input_picture[i - 1])) {
pre_input = *pre_input_ptr;
+ memcpy(data, pre_input_ptr->f->data, sizeof(data));
if (!pre_input.shared && i) {
- pre_input.f->data[0] += INPLACE_OFFSET;
- pre_input.f->data[1] += INPLACE_OFFSET;
- pre_input.f->data[2] += INPLACE_OFFSET;
+ data[0] += INPLACE_OFFSET;
+ data[1] += INPLACE_OFFSET;
+ data[2] += INPLACE_OFFSET;
}
- s->dsp.shrink[scale](s->tmp_frames[i]->data[0], s->tmp_frames[i]->linesize[0],
- pre_input.f->data[0], pre_input.f->linesize[0],
- c->width, c->height);
- s->dsp.shrink[scale](s->tmp_frames[i]->data[1], s->tmp_frames[i]->linesize[1],
- pre_input.f->data[1], pre_input.f->linesize[1],
- c->width >> 1, c->height >> 1);
- s->dsp.shrink[scale](s->tmp_frames[i]->data[2], s->tmp_frames[i]->linesize[2],
- pre_input.f->data[2], pre_input.f->linesize[2],
- c->width >> 1, c->height >> 1);
+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0],
+ s->tmp_frames[i]->linesize[0],
+ data[0],
+ pre_input.f->linesize[0],
+ c->width, c->height);
+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1],
+ s->tmp_frames[i]->linesize[1],
+ data[1],
+ pre_input.f->linesize[1],
+ c->width >> 1, c->height >> 1);
+ s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2],
+ s->tmp_frames[i]->linesize[2],
+ data[2],
+ pre_input.f->linesize[2],
+ c->width >> 1, c->height >> 1);
}
}
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
- s->dsp.draw_edges(s->current_picture.f->data[0], s->current_picture.f->linesize[0],
- s->h_edge_pos, s->v_edge_pos,
- EDGE_WIDTH, EDGE_WIDTH,
- EDGE_TOP | EDGE_BOTTOM);
- s->dsp.draw_edges(s->current_picture.f->data[1], s->current_picture.f->linesize[1],
- s->h_edge_pos >> hshift, s->v_edge_pos >> vshift,
- EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
- EDGE_TOP | EDGE_BOTTOM);
- s->dsp.draw_edges(s->current_picture.f->data[2], s->current_picture.f->linesize[2],
- s->h_edge_pos >> hshift, s->v_edge_pos >> vshift,
- EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
- EDGE_TOP | EDGE_BOTTOM);
+ s->mpvencdsp.draw_edges(s->current_picture.f->data[0],
+ s->current_picture.f->linesize[0],
+ s->h_edge_pos, s->v_edge_pos,
+ EDGE_WIDTH, EDGE_WIDTH,
+ EDGE_TOP | EDGE_BOTTOM);
+ s->mpvencdsp.draw_edges(s->current_picture.f->data[1],
+ s->current_picture.f->linesize[1],
+ s->h_edge_pos >> hshift,
+ s->v_edge_pos >> vshift,
+ EDGE_WIDTH >> hshift,
+ EDGE_WIDTH >> vshift,
+ EDGE_TOP | EDGE_BOTTOM);
+ s->mpvencdsp.draw_edges(s->current_picture.f->data[2],
+ s->current_picture.f->linesize[2],
+ s->h_edge_pos >> hshift,
+ s->v_edge_pos >> vshift,
+ EDGE_WIDTH >> hshift,
+ EDGE_WIDTH >> vshift,
+ EDGE_TOP | EDGE_BOTTOM);
}
emms_c();
(mb_y * mb_block_height * wrap_c) + mb_x * mb_block_width;
if((mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) && s->codec_id != AV_CODEC_ID_AMV){
- uint8_t *ebuf = s->edge_emu_buffer + 32;
+ uint8_t *ebuf = s->edge_emu_buffer + 36 * wrap_y;
int cw = (s->width + s->chroma_x_shift) >> s->chroma_x_shift;
int ch = (s->height + s->chroma_y_shift) >> s->chroma_y_shift;
s->vdsp.emulated_edge_mc(ebuf, ptr_y,
16, 16, mb_x * 16, mb_y * 16,
s->width, s->height);
ptr_y = ebuf;
- s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb,
+ s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y, ptr_cb,
wrap_c, wrap_c,
mb_block_width, mb_block_height,
mb_x * mb_block_width, mb_y * mb_block_height,
cw, ch);
- ptr_cb = ebuf + 18 * wrap_y;
- s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 16, ptr_cr,
+ ptr_cb = ebuf + 16 * wrap_y;
+ s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y + 16, ptr_cr,
wrap_c, wrap_c,
mb_block_width, mb_block_height,
mb_x * mb_block_width, mb_y * mb_block_height,
cw, ch);
- ptr_cr = ebuf + 18 * wrap_y + 16;
+ ptr_cr = ebuf + 16 * wrap_y + 16;
}
if (s->mb_intra) {
int yy = mb_y * 16;
uint8_t *pix = s->new_picture.f->data[0] + (yy * s->linesize) + xx;
int varc;
- int sum = s->dsp.pix_sum(pix, s->linesize);
+ int sum = s->mpvencdsp.pix_sum(pix, s->linesize);
- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500 + 128)>>8;
+ varc = (s->mpvencdsp.pix_norm1(pix, s->linesize) -
+ (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
/* for mjpeg, we do include qscale in the matrix */
for(i=1;i<64;i++){
- int j= s->dsp.idct_permutation[i];
+ int j = s->idsp.idct_permutation[i];
s->chroma_intra_matrix[j] = av_clip_uint8((chroma_matrix[i] * s->qscale) >> 3);
s-> intra_matrix[j] = av_clip_uint8(( luma_matrix[i] * s->qscale) >> 3);
s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision];
s->chroma_intra_matrix[0] =
s->intra_matrix[0] = ff_mpeg2_dc_scale_table[s->intra_dc_precision][8];
- ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
+ ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16,
s->intra_matrix, s->intra_quant_bias, 8, 8, 1);
- ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16,
+ ff_convert_matrix(s, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16,
s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1);
s->qscale= 8;
}
static const uint8_t y[32]={13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13};
static const uint8_t c[32]={14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14};
for(i=1;i<64;i++){
- int j= s->dsp.idct_permutation[ff_zigzag_direct[i]];
+ int j= s->idsp.idct_permutation[ff_zigzag_direct[i]];
s->intra_matrix[j] = sp5x_quant_table[5*2+0][i];
s->chroma_intra_matrix[j] = sp5x_quant_table[5*2+1][i];
s->c_dc_scale_table= c;
s->intra_matrix[0] = 13;
s->chroma_intra_matrix[0] = 14;
- ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
+ ff_convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16,
s->intra_matrix, s->intra_quant_bias, 8, 8, 1);
- ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16,
+ ff_convert_matrix(s, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16,
s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1);
s->qscale= 8;
}
if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
unquant_coeff= alevel*qmul + qadd;
}else{ //MPEG1
- j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize
+ j = s->idsp.idct_permutation[scantable[i]]; // FIXME: optimize
if(s->mb_intra){
unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3;
unquant_coeff = (unquant_coeff - 1) | 1;
#endif
if(basis[0][0] == 0)
- build_basis(s->dsp.idct_permutation);
+ build_basis(s->idsp.idct_permutation);
qmul= qscale*2;
qadd= (qscale-1)|1;
run_tab[rle_index++]=run;
run=0;
- s->dsp.add_8x8basis(rem, basis[j], coeff);
+ s->mpvencdsp.add_8x8basis(rem, basis[j], coeff);
}else{
run++;
}
{START_TIMER
#endif
for(;;){
- int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
+ int best_score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], 0);
int best_coeff=0;
int best_change=0;
int run2, best_unquant_change=0, analyze_gradient;
if(new_coeff >= 2048 || new_coeff < 0)
continue;
- score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
+ score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0],
+ new_coeff - old_coeff);
if(score<best_score){
best_score= score;
best_coeff= 0;
unquant_change= new_coeff - old_coeff;
av_assert2((score < 100*lambda && score > -100*lambda) || lambda==0);
- score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change);
+ score += s->mpvencdsp.try_8x8basis(rem, weight, basis[j],
+ unquant_change);
if(score<best_score){
best_score= score;
best_coeff= i;
}
}
- s->dsp.add_8x8basis(rem, basis[j], best_unquant_change);
+ s->mpvencdsp.add_8x8basis(rem, basis[j], best_unquant_change);
}else{
break;
}
*overflow= s->max_qcoeff < max; //overflow might have happened
/* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
- if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
- ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
+ if (s->idsp.idct_permutation_type != FF_NO_IDCT_PERM)
+ ff_block_permute(block, s->idsp.idct_permutation,
+ scantable, last_non_zero);
return last_non_zero;
}