Mercurial > libavcodec.hg
comparison mpegvideo.c @ 2385:4605a8b188c3 libavcodec
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
author | michael |
---|---|
date | Sat, 11 Dec 2004 18:33:18 +0000 |
parents | 23e7af611c34 |
children | ce45e1dd4b09 |
comparison
equal
deleted
inserted
replaced
2384:6ffcdd96ae99 | 2385:4605a8b188c3 |
---|---|
107 static uint8_t default_fcode_tab[MAX_MV*2+1]; | 107 static uint8_t default_fcode_tab[MAX_MV*2+1]; |
108 | 108 |
109 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; | 109 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; |
110 | 110 |
111 static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], | 111 static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], |
112 const uint16_t *quant_matrix, int bias, int qmin, int qmax) | 112 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) |
113 { | 113 { |
114 int qscale; | 114 int qscale; |
115 int shift=0; | |
115 | 116 |
116 for(qscale=qmin; qscale<=qmax; qscale++){ | 117 for(qscale=qmin; qscale<=qmax; qscale++){ |
117 int i; | 118 int i; |
118 if (dsp->fdct == ff_jpeg_fdct_islow | 119 if (dsp->fdct == ff_jpeg_fdct_islow |
119 #ifdef FAAN_POSTSCALE | 120 #ifdef FAAN_POSTSCALE |
159 | 160 |
160 if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; | 161 if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; |
161 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); | 162 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); |
162 } | 163 } |
163 } | 164 } |
165 | |
166 for(i=intra; i<64; i++){ | |
167 while(((8191LL * qmat[qscale][i]) >> shift) > INT_MAX){ | |
168 shift++; | |
169 } | |
170 } | |
171 } | |
172 if(shift){ | |
173 av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger then %d, overflows possible\n", QMAT_SHIFT - shift); | |
164 } | 174 } |
165 } | 175 } |
166 | 176 |
167 static inline void update_qscale(MpegEncContext *s){ | 177 static inline void update_qscale(MpegEncContext *s){ |
168 s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | 178 s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); |
1244 | 1254 |
1245 /* precompute matrix */ | 1255 /* precompute matrix */ |
1246 /* for mjpeg, we do include qscale in the matrix */ | 1256 /* for mjpeg, we do include qscale in the matrix */ |
1247 if (s->out_format != FMT_MJPEG) { | 1257 if (s->out_format != FMT_MJPEG) { |
1248 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, | 1258 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
1249 s->intra_matrix, s->intra_quant_bias, 1, 31); | 1259 s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); |
1250 convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, | 1260 convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, |
1251 s->inter_matrix, s->inter_quant_bias, 1, 31); | 1261 s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); |
1252 } | 1262 } |
1253 | 1263 |
1254 if(ff_rate_control_init(s) < 0) | 1264 if(ff_rate_control_init(s) < 0) |
1255 return -1; | 1265 return -1; |
1256 | 1266 |
5288 int j= s->dsp.idct_permutation[i]; | 5298 int j= s->dsp.idct_permutation[i]; |
5289 | 5299 |
5290 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); | 5300 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
5291 } | 5301 } |
5292 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, | 5302 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
5293 s->intra_matrix, s->intra_quant_bias, 8, 8); | 5303 s->intra_matrix, s->intra_quant_bias, 8, 8, 1); |
5294 s->qscale= 8; | 5304 s->qscale= 8; |
5295 } | 5305 } |
5296 | 5306 |
5297 //FIXME var duplication | 5307 //FIXME var duplication |
5298 s->current_picture_ptr->key_frame= | 5308 s->current_picture_ptr->key_frame= |