motion_comp_mmx.c
上传用户:aoeyumen
上传日期:2007-01-06
资源大小:3329k
文件大小:3k
源码类别:

DVD

开发平台:

Unix_Linux

  1. /*
  2.  *  motion_comp_mmx.c
  3.  *
  4.  *  Copyright (C) Aaron Holtzman <aholtzma@ess.engr.uvic.ca> - Nov 1999
  5.  *
  6.  *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
  7.  *
  8.  *  mpeg2dec is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  mpeg2dec is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 
  21.  *
  22.  */
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include "mpeg2.h"
  26. #include "mpeg2_internal.h"
  27. #include "mb_buffer.h"
  28. #include "motion_comp.h"
  29. #include "motion_comp_mmx.h"
  30. //Combine the prediction and intra coded block into current frame
  31. static void
  32. motion_comp_block(uint_8 *pred,sint_16 *block,uint_8 *dest,uint_32 pitch)
  33. {
  34. asm volatile (
  35. "movq    (%1),%%mm0nt"
  36. "packuswb 8(%1),%%mm0nt"
  37. "movq   %%mm0,(%0)nt"
  38. "addl %2,%0nt"
  39. "movq   16(%1),%%mm0nt"
  40. "packuswb 24(%1),%%mm0nt"
  41. "movq   %%mm0,(%0)nt"
  42. "addl %2,%0nt"
  43. "movq   32(%1),%%mm0nt"
  44. "packuswb 40(%1),%%mm0nt"
  45. "movq   %%mm0,(%0)nt"
  46. "addl %2,%0nt"
  47. "movq   48(%1),%%mm0nt"
  48. "packuswb 56(%1),%%mm0nt"
  49. "movq   %%mm0,(%0)nt"
  50. "addl %2,%0nt"
  51. "movq   64(%1),%%mm0nt"
  52. "packuswb 72(%1),%%mm0nt"
  53. "movq   %%mm0,(%0)nt"
  54. "addl %2,%0nt"
  55. "movq   80(%1),%%mm0nt"
  56. "packuswb 88(%1),%%mm0nt"
  57. "movq   %%mm0,(%0)nt"
  58. "addl %2,%0nt"
  59. "movq   96(%1),%%mm0nt"
  60. "packuswb 104(%1),%%mm0nt"
  61. "movq   %%mm0,(%0)nt"
  62. "addl %2,%0nt"
  63. "movq   112(%1),%%mm0nt"
  64. "packuswb 120(%1),%%mm0nt"
  65. "movq   %%mm0,(%0)nt"
  66. :"+r" (dest): "r" (block),"r" (pitch));
  67. }
  68. void
  69. motion_comp_mmx(picture_t *picture,mb_buffer_t *mb_buffer)
  70. {
  71. macroblock_t *mb   = mb_buffer->macroblocks;
  72. uint_32 num_blocks = mb_buffer->num_blocks;
  73. uint_32 i;
  74. uint_32 width,x,y;
  75. uint_32 mb_width;
  76. uint_32 pitch;
  77. uint_32 d;
  78. uint_8 *dst;
  79. width = picture->coded_picture_width;
  80. mb_width = picture->coded_picture_width >> 4;
  81. for(i=0;i<num_blocks;i++)
  82. {
  83. if(mb[i].skipped)
  84. continue;
  85. //handle interlaced blocks
  86. if (mb[i].dct_type) 
  87. {
  88. d = 1;
  89. pitch = width *2;
  90. }
  91. else 
  92. {
  93. d = 8;
  94. pitch = width;
  95. }
  96. x = mb[i].mba % mb_width;
  97. y = mb[i].mba / mb_width;
  98. //Do y component
  99. dst = &picture->current_frame[0][x * 16 + y * width * 16];
  100. motion_comp_block(0, mb[i].y_blocks       , dst                , pitch);
  101. motion_comp_block(0, mb[i].y_blocks +   64, dst + 8            , pitch);
  102. motion_comp_block(0, mb[i].y_blocks + 2*64, dst + width * d    , pitch);
  103. motion_comp_block(0, mb[i].y_blocks + 3*64, dst + width * d + 8, pitch);
  104. //Do Cr component
  105. dst = &picture->current_frame[1][x * 8 + y * width/2 * 8];
  106. motion_comp_block(0, mb[i].cr_blocks, dst, width/2);
  107. //Do Cb component
  108. dst = &picture->current_frame[2][x * 8 + y * width/2 * 8];
  109. motion_comp_block(0, mb[i].cb_blocks, dst, width/2);
  110. }
  111. asm volatile("emmsnt");
  112. }