mcomp4x4_c.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:9k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: mcomp_c.c 323 2005-11-01 20:52:32Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "../common.h"
  24. #include "softidct.h"
  25. #if !defined(MIPS64)
  26. #define CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,y,x,r) 
  27. int i; 
  28. for (i=0;i<4;++i) 
  29. Dst[0] = (uint8_t)((Src[0]*(4-x)*(4-y) + Src[1]*x*(4-y) + Src[SrcPitch+0]*(4-x)*y + Src[SrcPitch+1]*x*y + 8-r) >> 4); 
  30. Dst[1] = (uint8_t)((Src[1]*(4-x)*(4-y) + Src[2]*x*(4-y) + Src[SrcPitch+1]*(4-x)*y + Src[SrcPitch+2]*x*y + 8-r) >> 4); 
  31. Dst[2] = (uint8_t)((Src[2]*(4-x)*(4-y) + Src[3]*x*(4-y) + Src[SrcPitch+2]*(4-x)*y + Src[SrcPitch+3]*x*y + 8-r) >> 4); 
  32. Dst[3] = (uint8_t)((Src[3]*(4-x)*(4-y) + Src[4]*x*(4-y) + Src[SrcPitch+3]*(4-x)*y + Src[SrcPitch+4]*x*y + 8-r) >> 4); 
  33. Dst += DstPitch; 
  34. Src += SrcPitch; 
  35. }
  36. void STDCALL CopyBlock4x4_01(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  37. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,1,0); }
  38. void STDCALL CopyBlock4x4_02(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  39. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,2,0); }
  40. void STDCALL CopyBlock4x4_03(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  41. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,3,0); }
  42. void STDCALL CopyBlock4x4_10(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  43. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,0,0); }
  44. void STDCALL CopyBlock4x4_11(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  45. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,1,0); }
  46. void STDCALL CopyBlock4x4_12(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  47. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,2,0); }
  48. void STDCALL CopyBlock4x4_13(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  49. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,3,0); }
  50. void STDCALL CopyBlock4x4_20(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  51. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,0,0); }
  52. void STDCALL CopyBlock4x4_21(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  53. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,1,0); }
  54. void STDCALL CopyBlock4x4_22(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  55. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,2,0); }
  56. void STDCALL CopyBlock4x4_23(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  57. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,3,0); }
  58. void STDCALL CopyBlock4x4_30(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  59. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,0,0); }
  60. void STDCALL CopyBlock4x4_31(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  61. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,1,0); }
  62. void STDCALL CopyBlock4x4_32(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  63. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,2,0); }
  64. void STDCALL CopyBlock4x4_33(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  65. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,3,0); }
  66. void STDCALL CopyBlock4x4_01R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  67. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,1,1); }
  68. void STDCALL CopyBlock4x4_02R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  69. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,2,1); }
  70. void STDCALL CopyBlock4x4_03R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  71. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,0,3,1); }
  72. void STDCALL CopyBlock4x4_10R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  73. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,0,1); }
  74. void STDCALL CopyBlock4x4_11R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  75. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,1,1); }
  76. void STDCALL CopyBlock4x4_12R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  77. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,2,1); }
  78. void STDCALL CopyBlock4x4_13R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  79. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,1,3,1); }
  80. void STDCALL CopyBlock4x4_20R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  81. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,0,1); }
  82. void STDCALL CopyBlock4x4_21R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  83. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,1,1); }
  84. void STDCALL CopyBlock4x4_22R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  85. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,2,1); }
  86. void STDCALL CopyBlock4x4_23R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  87. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,2,3,1); }
  88. void STDCALL CopyBlock4x4_30R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  89. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,0,1); }
  90. void STDCALL CopyBlock4x4_31R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  91. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,1,1); }
  92. void STDCALL CopyBlock4x4_32R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  93. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,2,1); }
  94. void STDCALL CopyBlock4x4_33R(uint8_t *Src, uint8_t *Dst, int SrcPitch, int DstPitch)
  95. { CopyBlock4x4_XX(Src,Dst,SrcPitch,DstPitch,3,3,1); }
  96. // possible memory aligning problem with source
  97. void STDCALL CopyBlock4x4_00(uint8_t *Src, uint8_t *Dst, int SrcPitch,int DstPitch)
  98. {
  99. int i;
  100. for (i=0;i<4;++i)
  101. {
  102. Dst[0] = Src[0];
  103. Dst[1] = Src[1];
  104. Dst[2] = Src[2];
  105. Dst[3] = Src[3];
  106. Dst += DstPitch;
  107. Src += SrcPitch;
  108. }
  109. }
  110. #ifndef MIPS32
  111. // Dst[p] = Src[p]
  112. void STDCALL CopyBlock4x4(uint8_t *Src, uint8_t *Dst, int SrcPitch,int DstPitch)
  113. {
  114. uint32_t a,b,c,d;
  115. a=((uint32_t*)Src)[0]; Src += SrcPitch;
  116. b=((uint32_t*)Src)[0]; Src += SrcPitch;
  117. c=((uint32_t*)Src)[0]; Src += SrcPitch;
  118. d=((uint32_t*)Src)[0];
  119. ((uint32_t*)Dst)[0]=a; Dst += DstPitch;
  120. ((uint32_t*)Dst)[0]=b; Dst += DstPitch;
  121. ((uint32_t*)Dst)[0]=c; Dst += DstPitch;
  122. ((uint32_t*)Dst)[0]=d;
  123. }
  124. #define AddBlock4x4_XX(Src,Dst,SrcPitch,y,x) 
  125. int i; 
  126. for (i=0;i<4;++i) 
  127. Dst[0] = (uint8_t)((((Src[0]*(4-x)*(4-y) + Src[1]*x*(4-y) + Src[SrcPitch+0]*(4-x)*y + Src[SrcPitch+1]*x*y + 8) >> 4) + Dst[0] + 1) >> 1); 
  128. Dst[1] = (uint8_t)((((Src[1]*(4-x)*(4-y) + Src[2]*x*(4-y) + Src[SrcPitch+1]*(4-x)*y + Src[SrcPitch+2]*x*y + 8) >> 4) + Dst[1] + 1) >> 1); 
  129. Dst[2] = (uint8_t)((((Src[2]*(4-x)*(4-y) + Src[3]*x*(4-y) + Src[SrcPitch+2]*(4-x)*y + Src[SrcPitch+3]*x*y + 8) >> 4) + Dst[2] + 1) >> 1); 
  130. Dst[3] = (uint8_t)((((Src[3]*(4-x)*(4-y) + Src[4]*x*(4-y) + Src[SrcPitch+3]*(4-x)*y + Src[SrcPitch+4]*x*y + 8) >> 4) + Dst[3] + 1) >> 1); 
  131. Dst += 8; 
  132. Src += SrcPitch; 
  133. }
  134. void STDCALL AddBlock4x4_00(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  135. { AddBlock4x4_XX(Src,Dst,SrcPitch,0,0); }
  136. void STDCALL AddBlock4x4_01(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  137. { AddBlock4x4_XX(Src,Dst,SrcPitch,0,1); }
  138. void STDCALL AddBlock4x4_02(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  139. { AddBlock4x4_XX(Src,Dst,SrcPitch,0,2); }
  140. void STDCALL AddBlock4x4_03(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  141. { AddBlock4x4_XX(Src,Dst,SrcPitch,0,3); }
  142. void STDCALL AddBlock4x4_10(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  143. { AddBlock4x4_XX(Src,Dst,SrcPitch,1,0); }
  144. void STDCALL AddBlock4x4_11(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  145. { AddBlock4x4_XX(Src,Dst,SrcPitch,1,1); }
  146. void STDCALL AddBlock4x4_12(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  147. { AddBlock4x4_XX(Src,Dst,SrcPitch,1,2); }
  148. void STDCALL AddBlock4x4_13(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  149. { AddBlock4x4_XX(Src,Dst,SrcPitch,1,3); }
  150. void STDCALL AddBlock4x4_20(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  151. { AddBlock4x4_XX(Src,Dst,SrcPitch,2,0); }
  152. void STDCALL AddBlock4x4_21(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  153. { AddBlock4x4_XX(Src,Dst,SrcPitch,2,1); }
  154. void STDCALL AddBlock4x4_22(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  155. { AddBlock4x4_XX(Src,Dst,SrcPitch,2,2); }
  156. void STDCALL AddBlock4x4_23(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  157. { AddBlock4x4_XX(Src,Dst,SrcPitch,2,3); }
  158. void STDCALL AddBlock4x4_30(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  159. { AddBlock4x4_XX(Src,Dst,SrcPitch,3,0); }
  160. void STDCALL AddBlock4x4_31(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  161. { AddBlock4x4_XX(Src,Dst,SrcPitch,3,1); }
  162. void STDCALL AddBlock4x4_32(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  163. { AddBlock4x4_XX(Src,Dst,SrcPitch,3,2); }
  164. void STDCALL AddBlock4x4_33(uint8_t *Src, uint8_t *Dst, int SrcPitch)
  165. { AddBlock4x4_XX(Src,Dst,SrcPitch,3,3); }
  166. #endif
  167. #endif