[cvs] / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/decoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.37.2.10, Mon Nov 11 15:49:29 2002 UTC revision 1.37.2.17, Mon Dec 9 10:47:05 2002 UTC
# Line 79  Line 79 
79  #include "dct/fdct.h"  #include "dct/fdct.h"
80  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
81  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
82    #include "image/reduced.h"
83    
84  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
85  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
# Line 218  Line 219 
219          dec->frames = -1;          dec->frames = -1;
220          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
221          dec->low_delay = 0;          dec->low_delay = 0;
222            dec->packed_mode = 0;
223    
224          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
225    
# Line 265  Line 267 
267                                  Bitstream * bs,                                  Bitstream * bs,
268                                  const uint32_t quant,                                  const uint32_t quant,
269                                  const uint32_t intra_dc_threshold,                                  const uint32_t intra_dc_threshold,
270                                  const unsigned int bound)                                  const unsigned int bound,
271                                    const int reduced_resolution)
272  {  {
273    
274          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 278  Line 281 
281          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
282          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
283    
284            if (reduced_resolution) {
285                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
286                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
287                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
288            }else{
289          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
290          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
291          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
292            }
293    
294          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear
295    
# Line 341  Line 350 
350                  start_timer();                  start_timer();
351                  idct(&data[i * 64]);                  idct(&data[i * 64]);
352                  stop_idct_timer();                  stop_idct_timer();
353    
354          }          }
355    
356          if (dec->interlacing && pMB->field_dct) {          if (dec->interlacing && pMB->field_dct) {
# Line 349  Line 359 
359          }          }
360    
361          start_timer();          start_timer();
362    
363            if (reduced_resolution)
364            {
365                    next_block*=2;
366                    copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
367                    copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
368                    copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
369                    copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
370                    copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
371                    copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
372            }else{
373          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
374          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
375          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
376          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
377          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
378          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
379            }
380          stop_transfer_timer();          stop_transfer_timer();
381  }  }
382    
# Line 367  Line 389 
389    
390  // decode an inter macroblock  // decode an inter macroblock
391    
392    static void
393    rrv_mv_scaleup(VECTOR * mv)
394    {
395            if (mv->x > 0) {
396                    mv->x = 2*mv->x - 1;
397            } else if (mv->x < 0) {
398                    mv->x = 2*mv->x + 1;
399            }
400    
401            if (mv->y > 0) {
402                    mv->y = 2*mv->y - 1;
403            } else if (mv->y < 0) {
404                    mv->y = 2*mv->y + 1;
405            }
406    }
407    
408    
409    
410  void  void
411  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
412                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
# Line 376  Line 416 
416                                  const uint32_t cbp,                                  const uint32_t cbp,
417                                  Bitstream * bs,                                  Bitstream * bs,
418                                  const uint32_t quant,                                  const uint32_t quant,
419                                  const uint32_t rounding)                                  const uint32_t rounding,
420                                    const int reduced_resolution)
421  {  {
422    
423          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 384  Line 425 
425    
426          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
427          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
428          uint32_t next_block = stride * 8;          uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
429          uint32_t i;          uint32_t i;
430          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
431          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
432    
433          int uv_dx, uv_dy;          int uv_dx, uv_dy;
434            VECTOR mv[4];
435    
436            for (i = 0; i < 4; i++)
437            {
438                    mv[i] = pMB->mvs[i];
439                    //DPRINTF(DPRINTF_MB, "mv[%i]   orig=%i,%i   local=%i", i, pMB->mvs[i].x, pMB->mvs[i].y,                                                mv[i].x, mv[i].y);
440            }
441    
442            if (reduced_resolution) {
443                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
444                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
445                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
446                    rrv_mv_scaleup(&mv[0]);
447                    rrv_mv_scaleup(&mv[1]);
448                    rrv_mv_scaleup(&mv[2]);
449                    rrv_mv_scaleup(&mv[3]);
450            }else{
451          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
452          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
453          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
454            }
455    
456          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
457                  uv_dx = pMB->mvs[0].x;                  uv_dx = mv[0].x;
458                  uv_dy = pMB->mvs[0].y;                  uv_dy = mv[0].y;
459    
460                  if (dec->quarterpel)                  if (dec->quarterpel)
461                  {                  {
# Line 408  Line 467 
467                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
468    
469                  start_timer();                  start_timer();
470                    if (reduced_resolution)
471                    {
472                            interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
473                                                                      mv[0].x, mv[0].y, stride,  rounding);
474                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
475                                                                      uv_dx, uv_dy, stride2, rounding);
476                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
477                                                                      uv_dx, uv_dy, stride2, rounding);
478    
479                    }
480                    else
481                    {
482                  if(dec->quarterpel) {                  if(dec->quarterpel) {
483                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
484                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,
485                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                                          mv[0].x, mv[0].y, stride,  rounding);
486                  }                  }
487                  else {                  else {
488                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,                                  interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
489                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,  
                                                               pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,  
                                                                   pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,  
                                                                   pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);  
490                  }                  }
491    
492                  interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,                  interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
493                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
494                  interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,                  interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
495                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
496                    }
497                  stop_comp_timer();                  stop_comp_timer();
498    
499          } else {          } else {        /* MODE_INTER4V */
500                  int sum;                  int sum;
501    
502                  if(dec->quarterpel)                  if(dec->quarterpel)
503                          sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);                          sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
504                  else                  else
505                          sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                          sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
506    
507                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
508    
509                  if(dec->quarterpel)                  if(dec->quarterpel)
510                          sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);                          sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
511                  else                  else
512                          sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                          sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
513    
514                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
515    
516                  start_timer();                  start_timer();
517                    if (reduced_resolution)
518                    {
519                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
520                                                                      mv[0].x, mv[0].y, stride,  rounding);
521                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos,
522                                                                      mv[1].x, mv[1].y, stride,  rounding);
523                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos + 16,
524                                                                      mv[2].x, mv[2].y, stride,  rounding);
525                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos + 16,
526                                                                      mv[3].x, mv[3].y, stride,  rounding);
527                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
528                                                                      uv_dx, uv_dy, stride2, rounding);
529                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
530                                                                      uv_dx, uv_dy, stride2, rounding);
531    
532                            // set_block(pY_Cur, stride, 32, 32, 127);
533                    }
534                    else
535                    {
536                  if(dec->quarterpel) {                  if(dec->quarterpel) {
537                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
538                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,
539                                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
540                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
541                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
542                                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                                    mv[1].x, mv[1].y, stride,  rounding);
543                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
544                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
545                                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
546                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
547                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
548                                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
549                  }                  }
550                  else {                  else {
551                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
552                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
553                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
554                                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                            mv[1].x, mv[1].y, stride,  rounding);
555                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
556                                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                            mv[2].x, mv[2].y, stride,  rounding);
557                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
558                                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
559                  }                  }
560    
561                  interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,                  interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
562                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
563                  interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,                  interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
564                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
565                    }
566                  stop_comp_timer();                  stop_comp_timer();
567          }          }
568    
# Line 511  Line 597 
597          }          }
598    
599          start_timer();          start_timer();
600            if (reduced_resolution)
601            {
602                    if (cbp & 32)
603                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
604                    if (cbp & 16)
605                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
606                    if (cbp & 8)
607                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
608                    if (cbp & 4)
609                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
610                    if (cbp & 2)
611                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
612                    if (cbp & 1)
613                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
614            }
615            else
616            {
617          if (cbp & 32)          if (cbp & 32)
618                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);
619          if (cbp & 16)          if (cbp & 16)
# Line 523  Line 626 
626                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
627          if (cbp & 1)          if (cbp & 1)
628                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
629            }
630          stop_transfer_timer();          stop_transfer_timer();
631  }  }
632    
# Line 541  Line 645 
645    
646          if (reduced_resolution)          if (reduced_resolution)
647          {          {
648                  mb_width /= 2;                  mb_width = (dec->width + 31) / 32;
649                  mb_height /= 2;                  mb_height = (dec->height + 31) / 32;
650          }          }
651    
652          bound = 0;          bound = 0;
# Line 563  Line 667 
667                          {                          {
668                                  bound = read_video_packet_header(bs, dec, 0,                                  bound = read_video_packet_header(bs, dec, 0,
669                                                          &quant, NULL, NULL, &intra_dc_threshold);                                                          &quant, NULL, NULL, &intra_dc_threshold);
670                                  x = bound % dec->mb_width;                                  x = bound % mb_width;
671                                  y = bound / dec->mb_width;                                  y = bound / mb_width;
672                          }                          }
673                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
674    
# Line 599  Line 703 
703                          }                          }
704    
705                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
706                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound, reduced_resolution);
707    
708                  }                  }
709                  if(dec->out_frm)                  if(dec->out_frm)
710                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width);
711          }          }
712    
713  }  }
# Line 615  Line 719 
719                                    int x,                                    int x,
720                                    int y,                                    int y,
721                                    int k,                                    int k,
722                                    VECTOR * mv,                                    VECTOR * ret_mv,
723                                    int fcode,                                    int fcode,
724                                    const int bound)                                    const int bound)
725  {  {
# Line 626  Line 730 
730          int range = (64 * scale_fac);          int range = (64 * scale_fac);
731    
732          VECTOR pmv;          VECTOR pmv;
733          int mv_x, mv_y;          VECTOR mv;
734    
735          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
736    
737          mv_x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
738          mv_y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
739    
740          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y);          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv.x, mv.y, pmv.x, pmv.y);
741    
742          mv_x += pmv.x;          mv.x += pmv.x;
743          mv_y += pmv.y;          mv.y += pmv.y;
744    
745          if (mv_x < low) {          if (mv.x < low) {
746                  mv_x += range;                  mv.x += range;
747          } else if (mv_x > high) {          } else if (mv.x > high) {
748                  mv_x -= range;                  mv.x -= range;
749          }          }
750    
751          if (mv_y < low) {          if (mv.y < low) {
752                  mv_y += range;                  mv.y += range;
753          } else if (mv_y > high) {          } else if (mv.y > high) {
754                  mv_y -= range;                  mv.y -= range;
755          }          }
756    
757          mv->x = mv_x;          ret_mv->x = mv.x;
758          mv->y = mv_y;          ret_mv->y = mv.y;
759  }  }
760    
761    
# Line 685  Line 789 
789          uint32_t x, y;          uint32_t x, y;
790          uint32_t bound;          uint32_t bound;
791          int cp_mb, st_mb;          int cp_mb, st_mb;
792            int mb_width = dec->mb_width;
793            int mb_height = dec->mb_height;
794    
795            if (reduced_resolution)
796            {
797                    mb_width = (dec->width + 31) / 32;
798                    mb_height = (dec->height + 31) / 32;
799            }
800    
801          start_timer();          start_timer();
802          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
# Line 693  Line 805 
805    
806          bound = 0;          bound = 0;
807    
808          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
809                  cp_mb = st_mb = 0;                  cp_mb = st_mb = 0;
810                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
811                          MACROBLOCK *mb;                          MACROBLOCK *mb;
812    
813                          // skip stuffing                          // skip stuffing
# Line 706  Line 818 
818                          {                          {
819                                  bound = read_video_packet_header(bs, dec, fcode - 1,                                  bound = read_video_packet_header(bs, dec, fcode - 1,
820                                          &quant, &fcode, NULL, &intra_dc_threshold);                                          &quant, &fcode, NULL, &intra_dc_threshold);
821                                  x = bound % dec->mb_width;                                  x = bound % mb_width;
822                                  y = bound / dec->mb_width;                                  y = bound / mb_width;
823                          }                          }
824                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
825    
# Line 814  Line 926 
926                                          mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =                                          mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
927                                                  0;                                                  0;
928                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
929                                                                          intra_dc_threshold, bound);                                                                          intra_dc_threshold, bound, reduced_resolution);
930                                          continue;                                          continue;
931                                  }                                  }
932    
933                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,
934                                                                  rounding);                                                                  rounding, reduced_resolution);
935    
936                          }                          }
937                          else if (gmc_mv)        /* not coded S_VOP macroblock */                          else if (gmc_mv)        /* not coded S_VOP macroblock */
# Line 827  Line 939 
939                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
940                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);
941                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);
942                                  decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding);                                  decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);
943                          }                          }
944                          else    /* not coded P_VOP macroblock */                          else    /* not coded P_VOP macroblock */
945                          {                          {
946                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
947    
948                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
949                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
950                                  // copy macroblock directly from ref to cur                                  // copy macroblock directly from ref to cur
951    
952                                  start_timer();                                  start_timer();
953    
954                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +                                  if (reduced_resolution)
955                                                                   (16 * x),                                  {
956                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                          transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x),
957                                                                   (16 * x), dec->edged_width);                                                                           dec->refn[0].y + (32*y)*dec->edged_width + (32*x),
958                                                                             dec->edged_width);
959                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +  
960                                                                   (16 * x + 8),                                          transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x),
961                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                                                          dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x),
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x + 8),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 +  
                                                                  (8 * x),  
                                                                  dec->refn[0].u +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
962                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
963    
964                                  transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 +                                          transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x),
965                                                                   (8 * x),                                                                           dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x),
                                                                  dec->refn[0].v +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
966                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
967                                    }
968                                    else
969                                    {
970                                            transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
971                                                                             dec->refn[0].y + (16*y)*dec->edged_width + (16*x),
972                                                                             dec->edged_width);
973    
974                                            transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),
975                                                                            dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x),
976                                                                            dec->edged_width/2);
977    
978                                            transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),
979                                                                             dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),
980                                                                             dec->edged_width/2);
981                                    }
982    
983                                  stop_transfer_timer();                                  stop_transfer_timer();
984    
# Line 965  Line 1073 
1073                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1074                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1075    
1076                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1077                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1078                            uv_dx /= 2;
1079                            uv_dy /= 2;
1080                    }
1081    
1082                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1083                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1084          } else {          } else {
1085                  int sum;                  int sum;
1086    
1087                    if(dec->quarterpel)
1088                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1089                    else
1090                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1091    
1092                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1093    
1094                    if(dec->quarterpel)
1095                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1096                    else
1097                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1098                  uv_dy =  
1099                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1100          }          }
1101    
1102          start_timer();          start_timer();
1103            if(dec->quarterpel) {
1104                    interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64,
1105                                                                        dec->refh.y + 128, 16*x_pos, 16*y_pos,
1106                                                                        pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1107            }
1108            else {
1109          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,
1110                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1111          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos,
1112                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                        pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1113          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8,
1114                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1115                                                    0);                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8,
1116          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1117                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,          }
1118                                                    0);  
1119          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
1120                                                    uv_dx, uv_dy, stride2, 0);                                                    uv_dx, uv_dy, stride2, 0);
1121          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
# Line 1080  Line 1202 
1202                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1203                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1204    
                 uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;  
                 uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;  
   
1205                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
1206                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
1207    
1208                  b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1209                  b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1210                            uv_dx /= 2;
1211                            uv_dy /= 2;
1212    
1213                            b_uv_dx /= 2;
1214                            b_uv_dy /= 2;
1215                    }
1216    
1217                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1218                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1219    
1220                    b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1221                    b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1222          } else {          } else {
1223                  int sum;                  int sum;
1224    
1225                    if(dec->quarterpel)
1226                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1227                    else
1228                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1229    
1230                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1231    
1232                    if(dec->quarterpel)
1233                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1234                    else
1235                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1236                  uv_dy =  
1237                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
1238                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1239                                                                    (ABS(sum) / 16) * 2));  
1240                    if(dec->quarterpel)
1241                  sum =                          sum = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
1242                          pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x +                  else
1243                          pMB->b_mvs[3].x;                          sum = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1244                  b_uv_dx =  
1245                          (sum ==                  b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1246                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1247                                                                    (ABS(sum) / 16) * 2));                  if(dec->quarterpel)
1248                            sum = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
1249                  sum =                  else
1250                          pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y +                          sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1251                          pMB->b_mvs[3].y;  
1252                  b_uv_dy =                  b_uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1253          }          }
1254    
1255    
1256          start_timer();          start_timer();
1257            if(dec->quarterpel) {
1258                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1259                            interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1260                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1261                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1262                    else {
1263                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1264                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1265                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1266                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1267                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1268                                                                                pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1269                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1270                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1271                                                                                pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1272                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1273                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1274                                                                                pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1275                    }
1276            }
1277            else {
1278          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,
1279                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1280          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,
# Line 1131  Line 1284 
1284          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1285                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
1286                                                    0);                                                    0);
1287            }
1288    
1289          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
1290                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1291          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,
1292                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1293    
1294    
1295            if(dec->quarterpel) {
1296                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1297                            interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1298                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1299                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1300                    else {
1301                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1302                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1303                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1304                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1305                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1306                                                                                pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1307                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1308                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1309                                                                                pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1310                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1311                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1312                                                                                pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1313                    }
1314            }
1315            else {
1316          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,
1317                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1318          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
# Line 1148  Line 1324 
1324          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
1325                                                    16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y,                                                    16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y,
1326                                                    stride, 0);                                                    stride, 0);
1327            }
1328    
1329          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,
1330                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1331          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,
# Line 1156  Line 1334 
1334          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1335                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1336                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,
1337                                                  stride, 0);                                                  stride, 1, 8);
1338    
1339          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1340                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1341                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,
1342                                                  stride, 0);                                                  stride, 1, 8);
1343    
1344          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1345                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1346                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1347                                                  stride, 0);                                                  stride, 1, 8);
1348    
1349          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1350                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1351                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1352                                                  stride, 0);                                                  stride, 1, 8);
1353    
1354          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1355                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1356                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,
1357                                                  stride2, 0);                                                  stride2, 1, 8);
1358    
1359          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1360                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1361                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,
1362                                                  stride2, 0);                                                  stride2, 1, 8);
1363    
1364          stop_comp_timer();          stop_comp_timer();
1365    
# Line 1463  Line 1641 
1641          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1642          VECTOR gmc_mv[5];          VECTOR gmc_mv[5];
1643          uint32_t vop_type;          uint32_t vop_type;
1644            int success = 0;
1645    
1646          start_global_timer();          start_global_timer();
1647    
# Line 1482  Line 1661 
1661                  return XVID_ERR_OK;                  return XVID_ERR_OK;
1662          }          }
1663    
1664    start:
1665          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
1666          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
1667          dec->frames++;          dec->frames++;
# Line 1491  Line 1671 
1671                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1672                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);
1673    
1674          DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type);          //DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type);
1675    
1676            if (vop_type == -1 && success)
1677                    goto done;
1678    
1679          if (vop_type == -2 || vop_type == -3)          if (vop_type == -2 || vop_type == -3)
1680          {          {
# Line 1562  Line 1745 
1745          default:          default:
1746                  if (stats)                  if (stats)
1747                          stats->notify = 0;                          stats->notify = 0;
1748    
1749                    emms();
1750                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1751          }          }
1752    
1753  #ifdef BFRAMES_DEC_DEBUG  
1754          if (frame->length != BitstreamPos(&bs) / 8){          /* reduced resolution deblocking filter */
1755                  DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);  
1756            if (reduced_resolution)
1757            {
1758                    const int rmb_width = (dec->width + 31) / 32;
1759                    const int rmb_height = (dec->height + 31) / 32;
1760                    const int edged_width2 = dec->edged_width /2;
1761                    int i,j;
1762    
1763                    /* horizontal deblocking */
1764    
1765                    for (j = 1; j < rmb_height*2; j++)      // luma: j,i in block units
1766                    for (i = 0; i < rmb_width*2; i++)
1767                    {
1768                            if (dec->mbs[(j-1)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED ||
1769                                    dec->mbs[(j+0)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED)
1770                            {
1771                                    xvid_HFilter_31_C(dec->cur.y + (j*16 - 1)*dec->edged_width + i*16,
1772                                                                  dec->cur.y + (j*16 + 0)*dec->edged_width + i*16, 2);
1773                            }
1774          }          }
 #endif  
         frame->length = BitstreamPos(&bs) / 8;  
1775    
1776                    for (j = 1; j < rmb_height; j++)        // chroma
1777                    for (i = 0; i < rmb_width; i++)
1778                    {
1779                            if (dec->mbs[(j-1)*dec->mb_width + i].mode != MODE_NOT_CODED ||
1780                                    dec->mbs[(j+0)*dec->mb_width + i].mode != MODE_NOT_CODED)
1781                            {
1782                                    hfilter_31(dec->cur.u + (j*16 - 1)*edged_width2 + i*16,
1783                                                                      dec->cur.u + (j*16 + 0)*edged_width2 + i*16, 2);
1784                                    hfilter_31(dec->cur.v + (j*16 - 1)*edged_width2 + i*16,
1785                                                                      dec->cur.v + (j*16 + 0)*edged_width2 + i*16, 2);
1786                            }
1787                    }
1788    
1789                    /* vertical deblocking */
1790    
1791                    for (j = 0; j < rmb_height*2; j++)              // luma: i,j in block units
1792                    for (i = 1; i < rmb_width*2; i++)
1793                    {
1794                            if (dec->mbs[(j/2)*dec->mb_width + (i-1)/2].mode != MODE_NOT_CODED ||
1795                                    dec->mbs[(j/2)*dec->mb_width + (i+0)/2].mode != MODE_NOT_CODED)
1796                            {
1797                                    vfilter_31(dec->cur.y + (j*16)*dec->edged_width + i*16 - 1,
1798                                                                  dec->cur.y + (j*16)*dec->edged_width + i*16 + 0,
1799                                                                      dec->edged_width, 2);
1800                            }
1801                    }
1802    
1803                    for (j = 0; j < rmb_height; j++)        // chroma
1804                    for (i = 1; i < rmb_width; i++)
1805                    {
1806                            if (dec->mbs[j*dec->mb_width + i - 1].mode != MODE_NOT_CODED ||
1807                                    dec->mbs[j*dec->mb_width + i + 0].mode != MODE_NOT_CODED)
1808                            {
1809                                    vfilter_31(dec->cur.u + (j*16)*edged_width2 + i*16 - 1,
1810                                                                      dec->cur.u + (j*16)*edged_width2 + i*16 + 0,
1811                                                                      edged_width2, 2);
1812                                    vfilter_31(dec->cur.v + (j*16)*edged_width2 + i*16 - 1,
1813                                                                      dec->cur.v + (j*16)*edged_width2 + i*16 + 0,
1814                                                                      edged_width2, 2);
1815                            }
1816                    }
1817            }
1818    
1819            BitstreamByteAlign(&bs);
1820    
1821  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1822          // test if no B_VOP          // test if no B_VOP
1823          if (dec->low_delay || dec->frames == 0) {          if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) {
1824  #endif  #endif
1825                  image_output(&dec->cur, dec->width, dec->height, dec->edged_width,                  image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1826                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
1827    
1828  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1829          } else {          } else {
1830                  if (dec->frames >= 1) {                  if (dec->frames >= 1 && !(dec->packed_mode)) {
1831                          start_timer();                          start_timer();
1832                          if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) {
1833                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
# Line 1614  Line 1859 
1859                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1860          }          }
1861    
1862    
1863            if (success == 0 && dec->packed_mode)
1864            {
1865                    success = 1;
1866            //      if (frame->length > BitstreamPos(&bs) / 8)      // multiple vops packed together
1867                    goto start;
1868            }
1869    
1870    done :
1871    
1872            frame->length = BitstreamPos(&bs) / 8;
1873    
1874          if (stats)          if (stats)
1875          {          {
1876                  stats->notify = XVID_DEC_VOP;                  stats->notify = XVID_DEC_VOP;

Legend:
Removed from v.1.37.2.10  
changed lines
  Added in v.1.37.2.17

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4