comparison msmpeg4.c @ 299:fb9e77674bd4 libavcodec

minor optimizations / simplifications
author michaelni
date Fri, 29 Mar 2002 01:53:59 +0000
parents 75091bfc577b
children d874359e58f1
comparison
equal deleted inserted replaced
298:e20de99b6295 299:fb9e77674bd4
224 } 224 }
225 225
226 /* predict coded block */ 226 /* predict coded block */
227 static inline int coded_block_pred(MpegEncContext * s, int n, UINT8 **coded_block_ptr) 227 static inline int coded_block_pred(MpegEncContext * s, int n, UINT8 **coded_block_ptr)
228 { 228 {
229 int x, y, wrap, pred, a, b, c; 229 int xy, wrap, pred, a, b, c;
230 230
231 x = 2 * s->mb_x + 1 + (n & 1); 231 xy = s->block_index[n];
232 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); 232 wrap = s->block_wrap[0];
233 wrap = s->mb_width * 2 + 2;
234 233
235 /* B C 234 /* B C
236 * A X 235 * A X
237 */ 236 */
238 a = s->coded_block[(x - 1) + (y) * wrap]; 237 a = s->coded_block[xy - 1 ];
239 b = s->coded_block[(x - 1) + (y - 1) * wrap]; 238 b = s->coded_block[xy - 1 - wrap];
240 c = s->coded_block[(x) + (y - 1) * wrap]; 239 c = s->coded_block[xy - wrap];
241 240
242 if (b == c) { 241 if (b == c) {
243 pred = a; 242 pred = a;
244 } else { 243 } else {
245 pred = c; 244 pred = c;
246 } 245 }
247 246
248 /* store value */ 247 /* store value */
249 *coded_block_ptr = &s->coded_block[(x) + (y) * wrap]; 248 *coded_block_ptr = &s->coded_block[xy];
250 249
251 return pred; 250 return pred;
252 } 251 }
253 252
254 static void msmpeg4_encode_motion(MpegEncContext * s, 253 static void msmpeg4_encode_motion(MpegEncContext * s,
400 399
401 /* dir = 0: left, dir = 1: top prediction */ 400 /* dir = 0: left, dir = 1: top prediction */
402 static int msmpeg4_pred_dc(MpegEncContext * s, int n, 401 static int msmpeg4_pred_dc(MpegEncContext * s, int n,
403 INT16 **dc_val_ptr, int *dir_ptr) 402 INT16 **dc_val_ptr, int *dir_ptr)
404 { 403 {
405 int a, b, c, xy, wrap, pred, scale; 404 int a, b, c, wrap, pred, scale;
406 INT16 *dc_val; 405 INT16 *dc_val;
407 406
408 /* find prediction */ 407 /* find prediction */
409 if (n < 4) { 408 if (n < 4) {
410 wrap = s->mb_width * 2 + 2;
411 xy = 2 * s->mb_y + 1 + ((n & 2) >> 1);
412 xy *= wrap;
413 xy += 2 * s->mb_x + 1 + (n & 1);
414 dc_val = s->dc_val[0];
415 scale = s->y_dc_scale; 409 scale = s->y_dc_scale;
416 } else { 410 } else {
417 wrap = s->mb_width + 2;
418 xy = s->mb_y + 1;
419 xy *= wrap;
420 xy += s->mb_x + 1;
421 dc_val = s->dc_val[n - 4 + 1];
422 scale = s->c_dc_scale; 411 scale = s->c_dc_scale;
423 } 412 }
413 wrap = s->block_wrap[n];
414 dc_val= s->dc_val[0] + s->block_index[n];
424 415
425 /* B C 416 /* B C
426 * A X 417 * A X
427 */ 418 */
428 a = dc_val[xy - 1]; 419 a = dc_val[ - 1];
429 b = dc_val[xy - 1 - wrap]; 420 b = dc_val[ - 1 - wrap];
430 c = dc_val[xy - wrap]; 421 c = dc_val[ - wrap];
431 422
432 /* XXX: the following solution consumes divisions, but it does not 423 /* XXX: the following solution consumes divisions, but it does not
433 necessitate to modify mpegvideo.c. The problem comes from the 424 necessitate to modify mpegvideo.c. The problem comes from the
434 fact they decided to store the quantized DC (which would lead 425 fact they decided to store the quantized DC (which would lead
435 to problems if Q could vary !) */ 426 to problems if Q could vary !) */
476 pred = a; 467 pred = a;
477 *dir_ptr = 0; 468 *dir_ptr = 0;
478 } 469 }
479 470
480 /* update predictor */ 471 /* update predictor */
481 *dc_val_ptr = &dc_val[xy]; 472 *dc_val_ptr = &dc_val[0];
482 return pred; 473 return pred;
483 } 474 }
484 475
485 #define DC_MAX 119 476 #define DC_MAX 119
486 477