dsputil.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176
  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * DSP utils
  27. */
  28. #include "libavutil/imgutils.h"
  29. #include "avcodec.h"
  30. #include "dsputil.h"
  31. #include "simple_idct.h"
  32. #include "faandct.h"
  33. #include "faanidct.h"
  34. #include "mathops.h"
  35. #include "mpegvideo.h"
  36. #include "config.h"
  37. #include "ac3dec.h"
  38. #include "vorbis.h"
  39. #include "png.h"
  40. uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  41. uint32_t ff_squareTbl[512] = {0, };
  42. #define BIT_DEPTH 9
  43. #include "dsputil_template.c"
  44. #undef BIT_DEPTH
  45. #define BIT_DEPTH 10
  46. #include "dsputil_template.c"
  47. #undef BIT_DEPTH
  48. #define BIT_DEPTH 8
  49. #include "dsputil_template.c"
  50. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  51. #define pb_7f (~0UL/255 * 0x7f)
  52. #define pb_80 (~0UL/255 * 0x80)
  53. const uint8_t ff_zigzag_direct[64] = {
  54. 0, 1, 8, 16, 9, 2, 3, 10,
  55. 17, 24, 32, 25, 18, 11, 4, 5,
  56. 12, 19, 26, 33, 40, 48, 41, 34,
  57. 27, 20, 13, 6, 7, 14, 21, 28,
  58. 35, 42, 49, 56, 57, 50, 43, 36,
  59. 29, 22, 15, 23, 30, 37, 44, 51,
  60. 58, 59, 52, 45, 38, 31, 39, 46,
  61. 53, 60, 61, 54, 47, 55, 62, 63
  62. };
  63. /* Specific zigzag scan for 248 idct. NOTE that unlike the
  64. specification, we interleave the fields */
  65. const uint8_t ff_zigzag248_direct[64] = {
  66. 0, 8, 1, 9, 16, 24, 2, 10,
  67. 17, 25, 32, 40, 48, 56, 33, 41,
  68. 18, 26, 3, 11, 4, 12, 19, 27,
  69. 34, 42, 49, 57, 50, 58, 35, 43,
  70. 20, 28, 5, 13, 6, 14, 21, 29,
  71. 36, 44, 51, 59, 52, 60, 37, 45,
  72. 22, 30, 7, 15, 23, 31, 38, 46,
  73. 53, 61, 54, 62, 39, 47, 55, 63,
  74. };
  75. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  76. DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64];
  77. const uint8_t ff_alternate_horizontal_scan[64] = {
  78. 0, 1, 2, 3, 8, 9, 16, 17,
  79. 10, 11, 4, 5, 6, 7, 15, 14,
  80. 13, 12, 19, 18, 24, 25, 32, 33,
  81. 26, 27, 20, 21, 22, 23, 28, 29,
  82. 30, 31, 34, 35, 40, 41, 48, 49,
  83. 42, 43, 36, 37, 38, 39, 44, 45,
  84. 46, 47, 50, 51, 56, 57, 58, 59,
  85. 52, 53, 54, 55, 60, 61, 62, 63,
  86. };
  87. const uint8_t ff_alternate_vertical_scan[64] = {
  88. 0, 8, 16, 24, 1, 9, 2, 10,
  89. 17, 25, 32, 40, 48, 56, 57, 49,
  90. 41, 33, 26, 18, 3, 11, 4, 12,
  91. 19, 27, 34, 42, 50, 58, 35, 43,
  92. 51, 59, 20, 28, 5, 13, 6, 14,
  93. 21, 29, 36, 44, 52, 60, 37, 45,
  94. 53, 61, 22, 30, 7, 15, 23, 31,
  95. 38, 46, 54, 62, 39, 47, 55, 63,
  96. };
  97. /* Input permutation for the simple_idct_mmx */
  98. static const uint8_t simple_mmx_permutation[64]={
  99. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  100. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  101. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  102. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  103. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  104. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  105. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  106. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  107. };
  108. static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
  109. void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
  110. int i;
  111. int end;
  112. st->scantable= src_scantable;
  113. for(i=0; i<64; i++){
  114. int j;
  115. j = src_scantable[i];
  116. st->permutated[i] = permutation[j];
  117. #if ARCH_PPC
  118. st->inverse[j] = i;
  119. #endif
  120. }
  121. end=-1;
  122. for(i=0; i<64; i++){
  123. int j;
  124. j = st->permutated[i];
  125. if(j>end) end=j;
  126. st->raster_end[i]= end;
  127. }
  128. }
  129. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  130. int idct_permutation_type)
  131. {
  132. int i;
  133. switch(idct_permutation_type){
  134. case FF_NO_IDCT_PERM:
  135. for(i=0; i<64; i++)
  136. idct_permutation[i]= i;
  137. break;
  138. case FF_LIBMPEG2_IDCT_PERM:
  139. for(i=0; i<64; i++)
  140. idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  141. break;
  142. case FF_SIMPLE_IDCT_PERM:
  143. for(i=0; i<64; i++)
  144. idct_permutation[i]= simple_mmx_permutation[i];
  145. break;
  146. case FF_TRANSPOSE_IDCT_PERM:
  147. for(i=0; i<64; i++)
  148. idct_permutation[i]= ((i&7)<<3) | (i>>3);
  149. break;
  150. case FF_PARTTRANS_IDCT_PERM:
  151. for(i=0; i<64; i++)
  152. idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  153. break;
  154. case FF_SSE2_IDCT_PERM:
  155. for(i=0; i<64; i++)
  156. idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
  157. break;
  158. default:
  159. av_log(NULL, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  160. }
  161. }
  162. static int pix_sum_c(uint8_t * pix, int line_size)
  163. {
  164. int s, i, j;
  165. s = 0;
  166. for (i = 0; i < 16; i++) {
  167. for (j = 0; j < 16; j += 8) {
  168. s += pix[0];
  169. s += pix[1];
  170. s += pix[2];
  171. s += pix[3];
  172. s += pix[4];
  173. s += pix[5];
  174. s += pix[6];
  175. s += pix[7];
  176. pix += 8;
  177. }
  178. pix += line_size - 16;
  179. }
  180. return s;
  181. }
  182. static int pix_norm1_c(uint8_t * pix, int line_size)
  183. {
  184. int s, i, j;
  185. uint32_t *sq = ff_squareTbl + 256;
  186. s = 0;
  187. for (i = 0; i < 16; i++) {
  188. for (j = 0; j < 16; j += 8) {
  189. #if 0
  190. s += sq[pix[0]];
  191. s += sq[pix[1]];
  192. s += sq[pix[2]];
  193. s += sq[pix[3]];
  194. s += sq[pix[4]];
  195. s += sq[pix[5]];
  196. s += sq[pix[6]];
  197. s += sq[pix[7]];
  198. #else
  199. #if HAVE_FAST_64BIT
  200. register uint64_t x=*(uint64_t*)pix;
  201. s += sq[x&0xff];
  202. s += sq[(x>>8)&0xff];
  203. s += sq[(x>>16)&0xff];
  204. s += sq[(x>>24)&0xff];
  205. s += sq[(x>>32)&0xff];
  206. s += sq[(x>>40)&0xff];
  207. s += sq[(x>>48)&0xff];
  208. s += sq[(x>>56)&0xff];
  209. #else
  210. register uint32_t x=*(uint32_t*)pix;
  211. s += sq[x&0xff];
  212. s += sq[(x>>8)&0xff];
  213. s += sq[(x>>16)&0xff];
  214. s += sq[(x>>24)&0xff];
  215. x=*(uint32_t*)(pix+4);
  216. s += sq[x&0xff];
  217. s += sq[(x>>8)&0xff];
  218. s += sq[(x>>16)&0xff];
  219. s += sq[(x>>24)&0xff];
  220. #endif
  221. #endif
  222. pix += 8;
  223. }
  224. pix += line_size - 16;
  225. }
  226. return s;
  227. }
  228. static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
  229. int i;
  230. for(i=0; i+8<=w; i+=8){
  231. dst[i+0]= av_bswap32(src[i+0]);
  232. dst[i+1]= av_bswap32(src[i+1]);
  233. dst[i+2]= av_bswap32(src[i+2]);
  234. dst[i+3]= av_bswap32(src[i+3]);
  235. dst[i+4]= av_bswap32(src[i+4]);
  236. dst[i+5]= av_bswap32(src[i+5]);
  237. dst[i+6]= av_bswap32(src[i+6]);
  238. dst[i+7]= av_bswap32(src[i+7]);
  239. }
  240. for(;i<w; i++){
  241. dst[i+0]= av_bswap32(src[i+0]);
  242. }
  243. }
  244. static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
  245. {
  246. while (len--)
  247. *dst++ = av_bswap16(*src++);
  248. }
  249. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  250. {
  251. int s, i;
  252. uint32_t *sq = ff_squareTbl + 256;
  253. s = 0;
  254. for (i = 0; i < h; i++) {
  255. s += sq[pix1[0] - pix2[0]];
  256. s += sq[pix1[1] - pix2[1]];
  257. s += sq[pix1[2] - pix2[2]];
  258. s += sq[pix1[3] - pix2[3]];
  259. pix1 += line_size;
  260. pix2 += line_size;
  261. }
  262. return s;
  263. }
  264. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  265. {
  266. int s, i;
  267. uint32_t *sq = ff_squareTbl + 256;
  268. s = 0;
  269. for (i = 0; i < h; i++) {
  270. s += sq[pix1[0] - pix2[0]];
  271. s += sq[pix1[1] - pix2[1]];
  272. s += sq[pix1[2] - pix2[2]];
  273. s += sq[pix1[3] - pix2[3]];
  274. s += sq[pix1[4] - pix2[4]];
  275. s += sq[pix1[5] - pix2[5]];
  276. s += sq[pix1[6] - pix2[6]];
  277. s += sq[pix1[7] - pix2[7]];
  278. pix1 += line_size;
  279. pix2 += line_size;
  280. }
  281. return s;
  282. }
  283. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  284. {
  285. int s, i;
  286. uint32_t *sq = ff_squareTbl + 256;
  287. s = 0;
  288. for (i = 0; i < h; i++) {
  289. s += sq[pix1[ 0] - pix2[ 0]];
  290. s += sq[pix1[ 1] - pix2[ 1]];
  291. s += sq[pix1[ 2] - pix2[ 2]];
  292. s += sq[pix1[ 3] - pix2[ 3]];
  293. s += sq[pix1[ 4] - pix2[ 4]];
  294. s += sq[pix1[ 5] - pix2[ 5]];
  295. s += sq[pix1[ 6] - pix2[ 6]];
  296. s += sq[pix1[ 7] - pix2[ 7]];
  297. s += sq[pix1[ 8] - pix2[ 8]];
  298. s += sq[pix1[ 9] - pix2[ 9]];
  299. s += sq[pix1[10] - pix2[10]];
  300. s += sq[pix1[11] - pix2[11]];
  301. s += sq[pix1[12] - pix2[12]];
  302. s += sq[pix1[13] - pix2[13]];
  303. s += sq[pix1[14] - pix2[14]];
  304. s += sq[pix1[15] - pix2[15]];
  305. pix1 += line_size;
  306. pix2 += line_size;
  307. }
  308. return s;
  309. }
  310. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  311. const uint8_t *s2, int stride){
  312. int i;
  313. /* read the pixels */
  314. for(i=0;i<8;i++) {
  315. block[0] = s1[0] - s2[0];
  316. block[1] = s1[1] - s2[1];
  317. block[2] = s1[2] - s2[2];
  318. block[3] = s1[3] - s2[3];
  319. block[4] = s1[4] - s2[4];
  320. block[5] = s1[5] - s2[5];
  321. block[6] = s1[6] - s2[6];
  322. block[7] = s1[7] - s2[7];
  323. s1 += stride;
  324. s2 += stride;
  325. block += 8;
  326. }
  327. }
  328. void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  329. int line_size)
  330. {
  331. int i;
  332. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  333. /* read the pixels */
  334. for(i=0;i<8;i++) {
  335. pixels[0] = cm[block[0]];
  336. pixels[1] = cm[block[1]];
  337. pixels[2] = cm[block[2]];
  338. pixels[3] = cm[block[3]];
  339. pixels[4] = cm[block[4]];
  340. pixels[5] = cm[block[5]];
  341. pixels[6] = cm[block[6]];
  342. pixels[7] = cm[block[7]];
  343. pixels += line_size;
  344. block += 8;
  345. }
  346. }
  347. static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  348. int line_size)
  349. {
  350. int i;
  351. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  352. /* read the pixels */
  353. for(i=0;i<4;i++) {
  354. pixels[0] = cm[block[0]];
  355. pixels[1] = cm[block[1]];
  356. pixels[2] = cm[block[2]];
  357. pixels[3] = cm[block[3]];
  358. pixels += line_size;
  359. block += 8;
  360. }
  361. }
  362. static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  363. int line_size)
  364. {
  365. int i;
  366. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  367. /* read the pixels */
  368. for(i=0;i<2;i++) {
  369. pixels[0] = cm[block[0]];
  370. pixels[1] = cm[block[1]];
  371. pixels += line_size;
  372. block += 8;
  373. }
  374. }
  375. void ff_put_signed_pixels_clamped_c(const DCTELEM *block,
  376. uint8_t *restrict pixels,
  377. int line_size)
  378. {
  379. int i, j;
  380. for (i = 0; i < 8; i++) {
  381. for (j = 0; j < 8; j++) {
  382. if (*block < -128)
  383. *pixels = 0;
  384. else if (*block > 127)
  385. *pixels = 255;
  386. else
  387. *pixels = (uint8_t)(*block + 128);
  388. block++;
  389. pixels++;
  390. }
  391. pixels += (line_size - 8);
  392. }
  393. }
  394. void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  395. int line_size)
  396. {
  397. int i;
  398. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  399. /* read the pixels */
  400. for(i=0;i<8;i++) {
  401. pixels[0] = cm[pixels[0] + block[0]];
  402. pixels[1] = cm[pixels[1] + block[1]];
  403. pixels[2] = cm[pixels[2] + block[2]];
  404. pixels[3] = cm[pixels[3] + block[3]];
  405. pixels[4] = cm[pixels[4] + block[4]];
  406. pixels[5] = cm[pixels[5] + block[5]];
  407. pixels[6] = cm[pixels[6] + block[6]];
  408. pixels[7] = cm[pixels[7] + block[7]];
  409. pixels += line_size;
  410. block += 8;
  411. }
  412. }
  413. static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  414. int line_size)
  415. {
  416. int i;
  417. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  418. /* read the pixels */
  419. for(i=0;i<4;i++) {
  420. pixels[0] = cm[pixels[0] + block[0]];
  421. pixels[1] = cm[pixels[1] + block[1]];
  422. pixels[2] = cm[pixels[2] + block[2]];
  423. pixels[3] = cm[pixels[3] + block[3]];
  424. pixels += line_size;
  425. block += 8;
  426. }
  427. }
  428. static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  429. int line_size)
  430. {
  431. int i;
  432. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  433. /* read the pixels */
  434. for(i=0;i<2;i++) {
  435. pixels[0] = cm[pixels[0] + block[0]];
  436. pixels[1] = cm[pixels[1] + block[1]];
  437. pixels += line_size;
  438. block += 8;
  439. }
  440. }
  441. static int sum_abs_dctelem_c(DCTELEM *block)
  442. {
  443. int sum=0, i;
  444. for(i=0; i<64; i++)
  445. sum+= FFABS(block[i]);
  446. return sum;
  447. }
  448. static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
  449. {
  450. int i;
  451. for (i = 0; i < h; i++) {
  452. memset(block, value, 16);
  453. block += line_size;
  454. }
  455. }
  456. static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
  457. {
  458. int i;
  459. for (i = 0; i < h; i++) {
  460. memset(block, value, 8);
  461. block += line_size;
  462. }
  463. }
  464. #define avg2(a,b) ((a+b+1)>>1)
  465. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  466. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  467. {
  468. const int A=(16-x16)*(16-y16);
  469. const int B=( x16)*(16-y16);
  470. const int C=(16-x16)*( y16);
  471. const int D=( x16)*( y16);
  472. int i;
  473. for(i=0; i<h; i++)
  474. {
  475. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  476. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  477. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  478. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  479. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  480. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  481. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  482. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  483. dst+= stride;
  484. src+= stride;
  485. }
  486. }
  487. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  488. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  489. {
  490. int y, vx, vy;
  491. const int s= 1<<shift;
  492. width--;
  493. height--;
  494. for(y=0; y<h; y++){
  495. int x;
  496. vx= ox;
  497. vy= oy;
  498. for(x=0; x<8; x++){ //XXX FIXME optimize
  499. int src_x, src_y, frac_x, frac_y, index;
  500. src_x= vx>>16;
  501. src_y= vy>>16;
  502. frac_x= src_x&(s-1);
  503. frac_y= src_y&(s-1);
  504. src_x>>=shift;
  505. src_y>>=shift;
  506. if((unsigned)src_x < width){
  507. if((unsigned)src_y < height){
  508. index= src_x + src_y*stride;
  509. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  510. + src[index +1]* frac_x )*(s-frac_y)
  511. + ( src[index+stride ]*(s-frac_x)
  512. + src[index+stride+1]* frac_x )* frac_y
  513. + r)>>(shift*2);
  514. }else{
  515. index= src_x + av_clip(src_y, 0, height)*stride;
  516. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  517. + src[index +1]* frac_x )*s
  518. + r)>>(shift*2);
  519. }
  520. }else{
  521. if((unsigned)src_y < height){
  522. index= av_clip(src_x, 0, width) + src_y*stride;
  523. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  524. + src[index+stride ]* frac_y )*s
  525. + r)>>(shift*2);
  526. }else{
  527. index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
  528. dst[y*stride + x]= src[index ];
  529. }
  530. }
  531. vx+= dxx;
  532. vy+= dyx;
  533. }
  534. ox += dxy;
  535. oy += dyy;
  536. }
  537. }
  538. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  539. switch(width){
  540. case 2: put_pixels2_8_c (dst, src, stride, height); break;
  541. case 4: put_pixels4_8_c (dst, src, stride, height); break;
  542. case 8: put_pixels8_8_c (dst, src, stride, height); break;
  543. case 16:put_pixels16_8_c(dst, src, stride, height); break;
  544. }
  545. }
  546. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  547. int i,j;
  548. for (i=0; i < height; i++) {
  549. for (j=0; j < width; j++) {
  550. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  551. }
  552. src += stride;
  553. dst += stride;
  554. }
  555. }
  556. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  557. int i,j;
  558. for (i=0; i < height; i++) {
  559. for (j=0; j < width; j++) {
  560. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  561. }
  562. src += stride;
  563. dst += stride;
  564. }
  565. }
  566. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  567. int i,j;
  568. for (i=0; i < height; i++) {
  569. for (j=0; j < width; j++) {
  570. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  571. }
  572. src += stride;
  573. dst += stride;
  574. }
  575. }
  576. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  577. int i,j;
  578. for (i=0; i < height; i++) {
  579. for (j=0; j < width; j++) {
  580. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  581. }
  582. src += stride;
  583. dst += stride;
  584. }
  585. }
  586. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  587. int i,j;
  588. for (i=0; i < height; i++) {
  589. for (j=0; j < width; j++) {
  590. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  591. }
  592. src += stride;
  593. dst += stride;
  594. }
  595. }
  596. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  597. int i,j;
  598. for (i=0; i < height; i++) {
  599. for (j=0; j < width; j++) {
  600. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  601. }
  602. src += stride;
  603. dst += stride;
  604. }
  605. }
  606. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  607. int i,j;
  608. for (i=0; i < height; i++) {
  609. for (j=0; j < width; j++) {
  610. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  611. }
  612. src += stride;
  613. dst += stride;
  614. }
  615. }
  616. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  617. int i,j;
  618. for (i=0; i < height; i++) {
  619. for (j=0; j < width; j++) {
  620. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  621. }
  622. src += stride;
  623. dst += stride;
  624. }
  625. }
  626. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  627. switch(width){
  628. case 2: avg_pixels2_8_c (dst, src, stride, height); break;
  629. case 4: avg_pixels4_8_c (dst, src, stride, height); break;
  630. case 8: avg_pixels8_8_c (dst, src, stride, height); break;
  631. case 16:avg_pixels16_8_c(dst, src, stride, height); break;
  632. }
  633. }
  634. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  635. int i,j;
  636. for (i=0; i < height; i++) {
  637. for (j=0; j < width; j++) {
  638. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  639. }
  640. src += stride;
  641. dst += stride;
  642. }
  643. }
  644. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  645. int i,j;
  646. for (i=0; i < height; i++) {
  647. for (j=0; j < width; j++) {
  648. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  649. }
  650. src += stride;
  651. dst += stride;
  652. }
  653. }
  654. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  655. int i,j;
  656. for (i=0; i < height; i++) {
  657. for (j=0; j < width; j++) {
  658. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  659. }
  660. src += stride;
  661. dst += stride;
  662. }
  663. }
  664. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  665. int i,j;
  666. for (i=0; i < height; i++) {
  667. for (j=0; j < width; j++) {
  668. dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  669. }
  670. src += stride;
  671. dst += stride;
  672. }
  673. }
  674. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  675. int i,j;
  676. for (i=0; i < height; i++) {
  677. for (j=0; j < width; j++) {
  678. dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  679. }
  680. src += stride;
  681. dst += stride;
  682. }
  683. }
  684. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  685. int i,j;
  686. for (i=0; i < height; i++) {
  687. for (j=0; j < width; j++) {
  688. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  689. }
  690. src += stride;
  691. dst += stride;
  692. }
  693. }
  694. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  695. int i,j;
  696. for (i=0; i < height; i++) {
  697. for (j=0; j < width; j++) {
  698. dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  699. }
  700. src += stride;
  701. dst += stride;
  702. }
  703. }
  704. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  705. int i,j;
  706. for (i=0; i < height; i++) {
  707. for (j=0; j < width; j++) {
  708. dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  709. }
  710. src += stride;
  711. dst += stride;
  712. }
  713. }
  714. #define QPEL_MC(r, OPNAME, RND, OP) \
  715. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  716. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  717. int i;\
  718. for(i=0; i<h; i++)\
  719. {\
  720. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  721. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  722. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  723. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  724. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  725. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  726. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  727. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  728. dst+=dstStride;\
  729. src+=srcStride;\
  730. }\
  731. }\
  732. \
  733. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  734. const int w=8;\
  735. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  736. int i;\
  737. for(i=0; i<w; i++)\
  738. {\
  739. const int src0= src[0*srcStride];\
  740. const int src1= src[1*srcStride];\
  741. const int src2= src[2*srcStride];\
  742. const int src3= src[3*srcStride];\
  743. const int src4= src[4*srcStride];\
  744. const int src5= src[5*srcStride];\
  745. const int src6= src[6*srcStride];\
  746. const int src7= src[7*srcStride];\
  747. const int src8= src[8*srcStride];\
  748. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  749. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  750. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  751. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  752. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  753. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  754. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  755. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  756. dst++;\
  757. src++;\
  758. }\
  759. }\
  760. \
  761. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  762. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  763. int i;\
  764. \
  765. for(i=0; i<h; i++)\
  766. {\
  767. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  768. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  769. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  770. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  771. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  772. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  773. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  774. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  775. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  776. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  777. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  778. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  779. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  780. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  781. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  782. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  783. dst+=dstStride;\
  784. src+=srcStride;\
  785. }\
  786. }\
  787. \
  788. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  789. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  790. int i;\
  791. const int w=16;\
  792. for(i=0; i<w; i++)\
  793. {\
  794. const int src0= src[0*srcStride];\
  795. const int src1= src[1*srcStride];\
  796. const int src2= src[2*srcStride];\
  797. const int src3= src[3*srcStride];\
  798. const int src4= src[4*srcStride];\
  799. const int src5= src[5*srcStride];\
  800. const int src6= src[6*srcStride];\
  801. const int src7= src[7*srcStride];\
  802. const int src8= src[8*srcStride];\
  803. const int src9= src[9*srcStride];\
  804. const int src10= src[10*srcStride];\
  805. const int src11= src[11*srcStride];\
  806. const int src12= src[12*srcStride];\
  807. const int src13= src[13*srcStride];\
  808. const int src14= src[14*srcStride];\
  809. const int src15= src[15*srcStride];\
  810. const int src16= src[16*srcStride];\
  811. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  812. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  813. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  814. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  815. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  816. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  817. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  818. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  819. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  820. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  821. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  822. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  823. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  824. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  825. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  826. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  827. dst++;\
  828. src++;\
  829. }\
  830. }\
  831. \
  832. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  833. uint8_t half[64];\
  834. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  835. OPNAME ## pixels8_l2_8(dst, src, half, stride, stride, 8, 8);\
  836. }\
  837. \
  838. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  839. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  840. }\
  841. \
  842. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  843. uint8_t half[64];\
  844. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  845. OPNAME ## pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);\
  846. }\
  847. \
  848. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  849. uint8_t full[16*9];\
  850. uint8_t half[64];\
  851. copy_block9(full, src, 16, stride, 9);\
  852. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  853. OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);\
  854. }\
  855. \
  856. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  857. uint8_t full[16*9];\
  858. copy_block9(full, src, 16, stride, 9);\
  859. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  860. }\
  861. \
  862. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  863. uint8_t full[16*9];\
  864. uint8_t half[64];\
  865. copy_block9(full, src, 16, stride, 9);\
  866. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  867. OPNAME ## pixels8_l2_8(dst, full+16, half, stride, 16, 8, 8);\
  868. }\
  869. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  870. uint8_t full[16*9];\
  871. uint8_t halfH[72];\
  872. uint8_t halfV[64];\
  873. uint8_t halfHV[64];\
  874. copy_block9(full, src, 16, stride, 9);\
  875. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  876. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  877. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  878. OPNAME ## pixels8_l4_8(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  879. }\
  880. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  881. uint8_t full[16*9];\
  882. uint8_t halfH[72];\
  883. uint8_t halfHV[64];\
  884. copy_block9(full, src, 16, stride, 9);\
  885. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  886. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  887. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  888. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  889. }\
  890. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  891. uint8_t full[16*9];\
  892. uint8_t halfH[72];\
  893. uint8_t halfV[64];\
  894. uint8_t halfHV[64];\
  895. copy_block9(full, src, 16, stride, 9);\
  896. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  897. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  898. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  899. OPNAME ## pixels8_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  900. }\
  901. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  902. uint8_t full[16*9];\
  903. uint8_t halfH[72];\
  904. uint8_t halfHV[64];\
  905. copy_block9(full, src, 16, stride, 9);\
  906. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  907. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  908. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  909. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  910. }\
  911. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  912. uint8_t full[16*9];\
  913. uint8_t halfH[72];\
  914. uint8_t halfV[64];\
  915. uint8_t halfHV[64];\
  916. copy_block9(full, src, 16, stride, 9);\
  917. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  918. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  919. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  920. OPNAME ## pixels8_l4_8(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  921. }\
  922. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  923. uint8_t full[16*9];\
  924. uint8_t halfH[72];\
  925. uint8_t halfHV[64];\
  926. copy_block9(full, src, 16, stride, 9);\
  927. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  928. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  929. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  930. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  931. }\
  932. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  933. uint8_t full[16*9];\
  934. uint8_t halfH[72];\
  935. uint8_t halfV[64];\
  936. uint8_t halfHV[64];\
  937. copy_block9(full, src, 16, stride, 9);\
  938. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  939. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  940. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  941. OPNAME ## pixels8_l4_8(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  942. }\
  943. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  944. uint8_t full[16*9];\
  945. uint8_t halfH[72];\
  946. uint8_t halfHV[64];\
  947. copy_block9(full, src, 16, stride, 9);\
  948. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  949. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  950. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  951. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  952. }\
  953. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  954. uint8_t halfH[72];\
  955. uint8_t halfHV[64];\
  956. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  957. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  958. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  959. }\
  960. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  961. uint8_t halfH[72];\
  962. uint8_t halfHV[64];\
  963. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  964. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  965. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  966. }\
  967. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  968. uint8_t full[16*9];\
  969. uint8_t halfH[72];\
  970. uint8_t halfV[64];\
  971. uint8_t halfHV[64];\
  972. copy_block9(full, src, 16, stride, 9);\
  973. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  974. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  975. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  976. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  977. }\
  978. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  979. uint8_t full[16*9];\
  980. uint8_t halfH[72];\
  981. copy_block9(full, src, 16, stride, 9);\
  982. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  983. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  984. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  985. }\
  986. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  987. uint8_t full[16*9];\
  988. uint8_t halfH[72];\
  989. uint8_t halfV[64];\
  990. uint8_t halfHV[64];\
  991. copy_block9(full, src, 16, stride, 9);\
  992. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  993. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  994. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  995. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  996. }\
  997. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  998. uint8_t full[16*9];\
  999. uint8_t halfH[72];\
  1000. copy_block9(full, src, 16, stride, 9);\
  1001. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1002. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  1003. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1004. }\
  1005. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1006. uint8_t halfH[72];\
  1007. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1008. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1009. }\
  1010. \
  1011. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1012. uint8_t half[256];\
  1013. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1014. OPNAME ## pixels16_l2_8(dst, src, half, stride, stride, 16, 16);\
  1015. }\
  1016. \
  1017. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1018. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1019. }\
  1020. \
  1021. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1022. uint8_t half[256];\
  1023. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1024. OPNAME ## pixels16_l2_8(dst, src+1, half, stride, stride, 16, 16);\
  1025. }\
  1026. \
  1027. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1028. uint8_t full[24*17];\
  1029. uint8_t half[256];\
  1030. copy_block17(full, src, 24, stride, 17);\
  1031. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1032. OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);\
  1033. }\
  1034. \
  1035. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1036. uint8_t full[24*17];\
  1037. copy_block17(full, src, 24, stride, 17);\
  1038. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1039. }\
  1040. \
  1041. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1042. uint8_t full[24*17];\
  1043. uint8_t half[256];\
  1044. copy_block17(full, src, 24, stride, 17);\
  1045. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1046. OPNAME ## pixels16_l2_8(dst, full+24, half, stride, 24, 16, 16);\
  1047. }\
  1048. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1049. uint8_t full[24*17];\
  1050. uint8_t halfH[272];\
  1051. uint8_t halfV[256];\
  1052. uint8_t halfHV[256];\
  1053. copy_block17(full, src, 24, stride, 17);\
  1054. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1055. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1056. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1057. OPNAME ## pixels16_l4_8(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1058. }\
  1059. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1060. uint8_t full[24*17];\
  1061. uint8_t halfH[272];\
  1062. uint8_t halfHV[256];\
  1063. copy_block17(full, src, 24, stride, 17);\
  1064. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1065. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1066. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1067. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1068. }\
  1069. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1070. uint8_t full[24*17];\
  1071. uint8_t halfH[272];\
  1072. uint8_t halfV[256];\
  1073. uint8_t halfHV[256];\
  1074. copy_block17(full, src, 24, stride, 17);\
  1075. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1076. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1077. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1078. OPNAME ## pixels16_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1079. }\
  1080. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1081. uint8_t full[24*17];\
  1082. uint8_t halfH[272];\
  1083. uint8_t halfHV[256];\
  1084. copy_block17(full, src, 24, stride, 17);\
  1085. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1086. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1087. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1088. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1089. }\
  1090. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1091. uint8_t full[24*17];\
  1092. uint8_t halfH[272];\
  1093. uint8_t halfV[256];\
  1094. uint8_t halfHV[256];\
  1095. copy_block17(full, src, 24, stride, 17);\
  1096. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1097. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1098. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1099. OPNAME ## pixels16_l4_8(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1100. }\
  1101. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1102. uint8_t full[24*17];\
  1103. uint8_t halfH[272];\
  1104. uint8_t halfHV[256];\
  1105. copy_block17(full, src, 24, stride, 17);\
  1106. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1107. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1108. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1109. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1110. }\
  1111. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1112. uint8_t full[24*17];\
  1113. uint8_t halfH[272];\
  1114. uint8_t halfV[256];\
  1115. uint8_t halfHV[256];\
  1116. copy_block17(full, src, 24, stride, 17);\
  1117. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1118. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1119. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1120. OPNAME ## pixels16_l4_8(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1121. }\
  1122. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1123. uint8_t full[24*17];\
  1124. uint8_t halfH[272];\
  1125. uint8_t halfHV[256];\
  1126. copy_block17(full, src, 24, stride, 17);\
  1127. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1128. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1129. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1130. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1131. }\
  1132. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1133. uint8_t halfH[272];\
  1134. uint8_t halfHV[256];\
  1135. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1136. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1137. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1138. }\
  1139. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1140. uint8_t halfH[272];\
  1141. uint8_t halfHV[256];\
  1142. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1143. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1144. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1145. }\
  1146. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1147. uint8_t full[24*17];\
  1148. uint8_t halfH[272];\
  1149. uint8_t halfV[256];\
  1150. uint8_t halfHV[256];\
  1151. copy_block17(full, src, 24, stride, 17);\
  1152. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1153. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1154. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1155. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1156. }\
  1157. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1158. uint8_t full[24*17];\
  1159. uint8_t halfH[272];\
  1160. copy_block17(full, src, 24, stride, 17);\
  1161. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1162. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1163. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1164. }\
  1165. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1166. uint8_t full[24*17];\
  1167. uint8_t halfH[272];\
  1168. uint8_t halfV[256];\
  1169. uint8_t halfHV[256];\
  1170. copy_block17(full, src, 24, stride, 17);\
  1171. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1172. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1173. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1174. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1175. }\
  1176. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1177. uint8_t full[24*17];\
  1178. uint8_t halfH[272];\
  1179. copy_block17(full, src, 24, stride, 17);\
  1180. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1181. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1182. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1183. }\
  1184. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1185. uint8_t halfH[272];\
  1186. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1187. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1188. }
  1189. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1190. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1191. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1192. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1193. QPEL_MC(0, put_ , _ , op_put)
  1194. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1195. QPEL_MC(0, avg_ , _ , op_avg)
  1196. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1197. #undef op_avg
  1198. #undef op_avg_no_rnd
  1199. #undef op_put
  1200. #undef op_put_no_rnd
  1201. #define put_qpel8_mc00_c ff_put_pixels8x8_c
  1202. #define avg_qpel8_mc00_c ff_avg_pixels8x8_c
  1203. #define put_qpel16_mc00_c ff_put_pixels16x16_c
  1204. #define avg_qpel16_mc00_c ff_avg_pixels16x16_c
  1205. #define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c
  1206. #define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_8_c
  1207. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  1208. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1209. int i;
  1210. for(i=0; i<h; i++){
  1211. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  1212. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  1213. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  1214. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  1215. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  1216. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  1217. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  1218. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  1219. dst+=dstStride;
  1220. src+=srcStride;
  1221. }
  1222. }
  1223. #if CONFIG_RV40_DECODER
  1224. void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1225. put_pixels16_xy2_8_c(dst, src, stride, 16);
  1226. }
  1227. void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1228. avg_pixels16_xy2_8_c(dst, src, stride, 16);
  1229. }
  1230. void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1231. put_pixels8_xy2_8_c(dst, src, stride, 8);
  1232. }
  1233. void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1234. avg_pixels8_xy2_8_c(dst, src, stride, 8);
  1235. }
  1236. #endif /* CONFIG_RV40_DECODER */
  1237. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  1238. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1239. int i;
  1240. for(i=0; i<w; i++){
  1241. const int src_1= src[ -srcStride];
  1242. const int src0 = src[0 ];
  1243. const int src1 = src[ srcStride];
  1244. const int src2 = src[2*srcStride];
  1245. const int src3 = src[3*srcStride];
  1246. const int src4 = src[4*srcStride];
  1247. const int src5 = src[5*srcStride];
  1248. const int src6 = src[6*srcStride];
  1249. const int src7 = src[7*srcStride];
  1250. const int src8 = src[8*srcStride];
  1251. const int src9 = src[9*srcStride];
  1252. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  1253. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  1254. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  1255. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  1256. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  1257. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  1258. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  1259. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  1260. src++;
  1261. dst++;
  1262. }
  1263. }
  1264. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  1265. uint8_t half[64];
  1266. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1267. put_pixels8_l2_8(dst, src, half, stride, stride, 8, 8);
  1268. }
  1269. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  1270. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  1271. }
  1272. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  1273. uint8_t half[64];
  1274. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1275. put_pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);
  1276. }
  1277. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  1278. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  1279. }
  1280. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  1281. uint8_t halfH[88];
  1282. uint8_t halfV[64];
  1283. uint8_t halfHV[64];
  1284. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1285. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  1286. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1287. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1288. }
  1289. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  1290. uint8_t halfH[88];
  1291. uint8_t halfV[64];
  1292. uint8_t halfHV[64];
  1293. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1294. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  1295. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1296. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1297. }
  1298. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  1299. uint8_t halfH[88];
  1300. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1301. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  1302. }
  1303. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  1304. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1305. int x;
  1306. const int strength= ff_h263_loop_filter_strength[qscale];
  1307. for(x=0; x<8; x++){
  1308. int d1, d2, ad1;
  1309. int p0= src[x-2*stride];
  1310. int p1= src[x-1*stride];
  1311. int p2= src[x+0*stride];
  1312. int p3= src[x+1*stride];
  1313. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1314. if (d<-2*strength) d1= 0;
  1315. else if(d<- strength) d1=-2*strength - d;
  1316. else if(d< strength) d1= d;
  1317. else if(d< 2*strength) d1= 2*strength - d;
  1318. else d1= 0;
  1319. p1 += d1;
  1320. p2 -= d1;
  1321. if(p1&256) p1= ~(p1>>31);
  1322. if(p2&256) p2= ~(p2>>31);
  1323. src[x-1*stride] = p1;
  1324. src[x+0*stride] = p2;
  1325. ad1= FFABS(d1)>>1;
  1326. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1327. src[x-2*stride] = p0 - d2;
  1328. src[x+ stride] = p3 + d2;
  1329. }
  1330. }
  1331. }
  1332. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  1333. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1334. int y;
  1335. const int strength= ff_h263_loop_filter_strength[qscale];
  1336. for(y=0; y<8; y++){
  1337. int d1, d2, ad1;
  1338. int p0= src[y*stride-2];
  1339. int p1= src[y*stride-1];
  1340. int p2= src[y*stride+0];
  1341. int p3= src[y*stride+1];
  1342. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1343. if (d<-2*strength) d1= 0;
  1344. else if(d<- strength) d1=-2*strength - d;
  1345. else if(d< strength) d1= d;
  1346. else if(d< 2*strength) d1= 2*strength - d;
  1347. else d1= 0;
  1348. p1 += d1;
  1349. p2 -= d1;
  1350. if(p1&256) p1= ~(p1>>31);
  1351. if(p2&256) p2= ~(p2>>31);
  1352. src[y*stride-1] = p1;
  1353. src[y*stride+0] = p2;
  1354. ad1= FFABS(d1)>>1;
  1355. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1356. src[y*stride-2] = p0 - d2;
  1357. src[y*stride+1] = p3 + d2;
  1358. }
  1359. }
  1360. }
  1361. static void h261_loop_filter_c(uint8_t *src, int stride){
  1362. int x,y,xy,yz;
  1363. int temp[64];
  1364. for(x=0; x<8; x++){
  1365. temp[x ] = 4*src[x ];
  1366. temp[x + 7*8] = 4*src[x + 7*stride];
  1367. }
  1368. for(y=1; y<7; y++){
  1369. for(x=0; x<8; x++){
  1370. xy = y * stride + x;
  1371. yz = y * 8 + x;
  1372. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  1373. }
  1374. }
  1375. for(y=0; y<8; y++){
  1376. src[ y*stride] = (temp[ y*8] + 2)>>2;
  1377. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  1378. for(x=1; x<7; x++){
  1379. xy = y * stride + x;
  1380. yz = y * 8 + x;
  1381. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  1382. }
  1383. }
  1384. }
  1385. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1386. {
  1387. int s, i;
  1388. s = 0;
  1389. for(i=0;i<h;i++) {
  1390. s += abs(pix1[0] - pix2[0]);
  1391. s += abs(pix1[1] - pix2[1]);
  1392. s += abs(pix1[2] - pix2[2]);
  1393. s += abs(pix1[3] - pix2[3]);
  1394. s += abs(pix1[4] - pix2[4]);
  1395. s += abs(pix1[5] - pix2[5]);
  1396. s += abs(pix1[6] - pix2[6]);
  1397. s += abs(pix1[7] - pix2[7]);
  1398. s += abs(pix1[8] - pix2[8]);
  1399. s += abs(pix1[9] - pix2[9]);
  1400. s += abs(pix1[10] - pix2[10]);
  1401. s += abs(pix1[11] - pix2[11]);
  1402. s += abs(pix1[12] - pix2[12]);
  1403. s += abs(pix1[13] - pix2[13]);
  1404. s += abs(pix1[14] - pix2[14]);
  1405. s += abs(pix1[15] - pix2[15]);
  1406. pix1 += line_size;
  1407. pix2 += line_size;
  1408. }
  1409. return s;
  1410. }
  1411. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1412. {
  1413. int s, i;
  1414. s = 0;
  1415. for(i=0;i<h;i++) {
  1416. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1417. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1418. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1419. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1420. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1421. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1422. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1423. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1424. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1425. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1426. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1427. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1428. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1429. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1430. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1431. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1432. pix1 += line_size;
  1433. pix2 += line_size;
  1434. }
  1435. return s;
  1436. }
  1437. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1438. {
  1439. int s, i;
  1440. uint8_t *pix3 = pix2 + line_size;
  1441. s = 0;
  1442. for(i=0;i<h;i++) {
  1443. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1444. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1445. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1446. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1447. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1448. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1449. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1450. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1451. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1452. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1453. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1454. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1455. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1456. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1457. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1458. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1459. pix1 += line_size;
  1460. pix2 += line_size;
  1461. pix3 += line_size;
  1462. }
  1463. return s;
  1464. }
  1465. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1466. {
  1467. int s, i;
  1468. uint8_t *pix3 = pix2 + line_size;
  1469. s = 0;
  1470. for(i=0;i<h;i++) {
  1471. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1472. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1473. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1474. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1475. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1476. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1477. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1478. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1479. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1480. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1481. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1482. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1483. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1484. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1485. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1486. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1487. pix1 += line_size;
  1488. pix2 += line_size;
  1489. pix3 += line_size;
  1490. }
  1491. return s;
  1492. }
  1493. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1494. {
  1495. int s, i;
  1496. s = 0;
  1497. for(i=0;i<h;i++) {
  1498. s += abs(pix1[0] - pix2[0]);
  1499. s += abs(pix1[1] - pix2[1]);
  1500. s += abs(pix1[2] - pix2[2]);
  1501. s += abs(pix1[3] - pix2[3]);
  1502. s += abs(pix1[4] - pix2[4]);
  1503. s += abs(pix1[5] - pix2[5]);
  1504. s += abs(pix1[6] - pix2[6]);
  1505. s += abs(pix1[7] - pix2[7]);
  1506. pix1 += line_size;
  1507. pix2 += line_size;
  1508. }
  1509. return s;
  1510. }
  1511. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1512. {
  1513. int s, i;
  1514. s = 0;
  1515. for(i=0;i<h;i++) {
  1516. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1517. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1518. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1519. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1520. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1521. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1522. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1523. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1524. pix1 += line_size;
  1525. pix2 += line_size;
  1526. }
  1527. return s;
  1528. }
  1529. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1530. {
  1531. int s, i;
  1532. uint8_t *pix3 = pix2 + line_size;
  1533. s = 0;
  1534. for(i=0;i<h;i++) {
  1535. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1536. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1537. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1538. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1539. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1540. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1541. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1542. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1543. pix1 += line_size;
  1544. pix2 += line_size;
  1545. pix3 += line_size;
  1546. }
  1547. return s;
  1548. }
  1549. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1550. {
  1551. int s, i;
  1552. uint8_t *pix3 = pix2 + line_size;
  1553. s = 0;
  1554. for(i=0;i<h;i++) {
  1555. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1556. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1557. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1558. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1559. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1560. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1561. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1562. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1563. pix1 += line_size;
  1564. pix2 += line_size;
  1565. pix3 += line_size;
  1566. }
  1567. return s;
  1568. }
  1569. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1570. MpegEncContext *c = v;
  1571. int score1=0;
  1572. int score2=0;
  1573. int x,y;
  1574. for(y=0; y<h; y++){
  1575. for(x=0; x<16; x++){
  1576. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1577. }
  1578. if(y+1<h){
  1579. for(x=0; x<15; x++){
  1580. score2+= FFABS( s1[x ] - s1[x +stride]
  1581. - s1[x+1] + s1[x+1+stride])
  1582. -FFABS( s2[x ] - s2[x +stride]
  1583. - s2[x+1] + s2[x+1+stride]);
  1584. }
  1585. }
  1586. s1+= stride;
  1587. s2+= stride;
  1588. }
  1589. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1590. else return score1 + FFABS(score2)*8;
  1591. }
  1592. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1593. MpegEncContext *c = v;
  1594. int score1=0;
  1595. int score2=0;
  1596. int x,y;
  1597. for(y=0; y<h; y++){
  1598. for(x=0; x<8; x++){
  1599. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1600. }
  1601. if(y+1<h){
  1602. for(x=0; x<7; x++){
  1603. score2+= FFABS( s1[x ] - s1[x +stride]
  1604. - s1[x+1] + s1[x+1+stride])
  1605. -FFABS( s2[x ] - s2[x +stride]
  1606. - s2[x+1] + s2[x+1+stride]);
  1607. }
  1608. }
  1609. s1+= stride;
  1610. s2+= stride;
  1611. }
  1612. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1613. else return score1 + FFABS(score2)*8;
  1614. }
  1615. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  1616. int i;
  1617. unsigned int sum=0;
  1618. for(i=0; i<8*8; i++){
  1619. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  1620. int w= weight[i];
  1621. b>>= RECON_SHIFT;
  1622. assert(-512<b && b<512);
  1623. sum += (w*b)*(w*b)>>4;
  1624. }
  1625. return sum>>2;
  1626. }
  1627. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  1628. int i;
  1629. for(i=0; i<8*8; i++){
  1630. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  1631. }
  1632. }
  1633. /**
  1634. * Permute an 8x8 block.
  1635. * @param block the block which will be permuted according to the given permutation vector
  1636. * @param permutation the permutation vector
  1637. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  1638. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  1639. * (inverse) permutated to scantable order!
  1640. */
  1641. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  1642. {
  1643. int i;
  1644. DCTELEM temp[64];
  1645. if(last<=0) return;
  1646. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  1647. for(i=0; i<=last; i++){
  1648. const int j= scantable[i];
  1649. temp[j]= block[j];
  1650. block[j]=0;
  1651. }
  1652. for(i=0; i<=last; i++){
  1653. const int j= scantable[i];
  1654. const int perm_j= permutation[j];
  1655. block[perm_j]= temp[j];
  1656. }
  1657. }
  1658. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  1659. return 0;
  1660. }
  1661. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  1662. int i;
  1663. memset(cmp, 0, sizeof(void*)*6);
  1664. for(i=0; i<6; i++){
  1665. switch(type&0xFF){
  1666. case FF_CMP_SAD:
  1667. cmp[i]= c->sad[i];
  1668. break;
  1669. case FF_CMP_SATD:
  1670. cmp[i]= c->hadamard8_diff[i];
  1671. break;
  1672. case FF_CMP_SSE:
  1673. cmp[i]= c->sse[i];
  1674. break;
  1675. case FF_CMP_DCT:
  1676. cmp[i]= c->dct_sad[i];
  1677. break;
  1678. case FF_CMP_DCT264:
  1679. cmp[i]= c->dct264_sad[i];
  1680. break;
  1681. case FF_CMP_DCTMAX:
  1682. cmp[i]= c->dct_max[i];
  1683. break;
  1684. case FF_CMP_PSNR:
  1685. cmp[i]= c->quant_psnr[i];
  1686. break;
  1687. case FF_CMP_BIT:
  1688. cmp[i]= c->bit[i];
  1689. break;
  1690. case FF_CMP_RD:
  1691. cmp[i]= c->rd[i];
  1692. break;
  1693. case FF_CMP_VSAD:
  1694. cmp[i]= c->vsad[i];
  1695. break;
  1696. case FF_CMP_VSSE:
  1697. cmp[i]= c->vsse[i];
  1698. break;
  1699. case FF_CMP_ZERO:
  1700. cmp[i]= zero_cmp;
  1701. break;
  1702. case FF_CMP_NSSE:
  1703. cmp[i]= c->nsse[i];
  1704. break;
  1705. #if CONFIG_DWT
  1706. case FF_CMP_W53:
  1707. cmp[i]= c->w53[i];
  1708. break;
  1709. case FF_CMP_W97:
  1710. cmp[i]= c->w97[i];
  1711. break;
  1712. #endif
  1713. default:
  1714. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  1715. }
  1716. }
  1717. }
  1718. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  1719. long i;
  1720. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1721. long a = *(long*)(src+i);
  1722. long b = *(long*)(dst+i);
  1723. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  1724. }
  1725. for(; i<w; i++)
  1726. dst[i+0] += src[i+0];
  1727. }
  1728. static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  1729. long i;
  1730. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1731. long a = *(long*)(src1+i);
  1732. long b = *(long*)(src2+i);
  1733. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  1734. }
  1735. for(; i<w; i++)
  1736. dst[i] = src1[i]+src2[i];
  1737. }
  1738. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  1739. long i;
  1740. #if !HAVE_FAST_UNALIGNED
  1741. if((long)src2 & (sizeof(long)-1)){
  1742. for(i=0; i+7<w; i+=8){
  1743. dst[i+0] = src1[i+0]-src2[i+0];
  1744. dst[i+1] = src1[i+1]-src2[i+1];
  1745. dst[i+2] = src1[i+2]-src2[i+2];
  1746. dst[i+3] = src1[i+3]-src2[i+3];
  1747. dst[i+4] = src1[i+4]-src2[i+4];
  1748. dst[i+5] = src1[i+5]-src2[i+5];
  1749. dst[i+6] = src1[i+6]-src2[i+6];
  1750. dst[i+7] = src1[i+7]-src2[i+7];
  1751. }
  1752. }else
  1753. #endif
  1754. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1755. long a = *(long*)(src1+i);
  1756. long b = *(long*)(src2+i);
  1757. *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
  1758. }
  1759. for(; i<w; i++)
  1760. dst[i+0] = src1[i+0]-src2[i+0];
  1761. }
  1762. static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
  1763. int i;
  1764. uint8_t l, lt;
  1765. l= *left;
  1766. lt= *left_top;
  1767. for(i=0; i<w; i++){
  1768. l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
  1769. lt= src1[i];
  1770. dst[i]= l;
  1771. }
  1772. *left= l;
  1773. *left_top= lt;
  1774. }
  1775. static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){
  1776. int i;
  1777. uint8_t l, lt;
  1778. l= *left;
  1779. lt= *left_top;
  1780. for(i=0; i<w; i++){
  1781. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  1782. lt= src1[i];
  1783. l= src2[i];
  1784. dst[i]= l - pred;
  1785. }
  1786. *left= l;
  1787. *left_top= lt;
  1788. }
  1789. static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
  1790. int i;
  1791. for(i=0; i<w-1; i++){
  1792. acc+= src[i];
  1793. dst[i]= acc;
  1794. i++;
  1795. acc+= src[i];
  1796. dst[i]= acc;
  1797. }
  1798. for(; i<w; i++){
  1799. acc+= src[i];
  1800. dst[i]= acc;
  1801. }
  1802. return acc;
  1803. }
  1804. #if HAVE_BIGENDIAN
  1805. #define B 3
  1806. #define G 2
  1807. #define R 1
  1808. #define A 0
  1809. #else
  1810. #define B 0
  1811. #define G 1
  1812. #define R 2
  1813. #define A 3
  1814. #endif
  1815. static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
  1816. int i;
  1817. int r,g,b,a;
  1818. r= *red;
  1819. g= *green;
  1820. b= *blue;
  1821. a= *alpha;
  1822. for(i=0; i<w; i++){
  1823. b+= src[4*i+B];
  1824. g+= src[4*i+G];
  1825. r+= src[4*i+R];
  1826. a+= src[4*i+A];
  1827. dst[4*i+B]= b;
  1828. dst[4*i+G]= g;
  1829. dst[4*i+R]= r;
  1830. dst[4*i+A]= a;
  1831. }
  1832. *red= r;
  1833. *green= g;
  1834. *blue= b;
  1835. *alpha= a;
  1836. }
  1837. #undef B
  1838. #undef G
  1839. #undef R
  1840. #undef A
  1841. #define BUTTERFLY2(o1,o2,i1,i2) \
  1842. o1= (i1)+(i2);\
  1843. o2= (i1)-(i2);
  1844. #define BUTTERFLY1(x,y) \
  1845. {\
  1846. int a,b;\
  1847. a= x;\
  1848. b= y;\
  1849. x= a+b;\
  1850. y= a-b;\
  1851. }
  1852. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  1853. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  1854. int i;
  1855. int temp[64];
  1856. int sum=0;
  1857. assert(h==8);
  1858. for(i=0; i<8; i++){
  1859. //FIXME try pointer walks
  1860. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
  1861. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
  1862. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
  1863. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
  1864. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1865. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1866. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1867. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1868. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1869. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1870. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1871. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1872. }
  1873. for(i=0; i<8; i++){
  1874. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1875. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1876. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1877. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1878. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1879. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1880. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1881. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1882. sum +=
  1883. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1884. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1885. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1886. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1887. }
  1888. return sum;
  1889. }
  1890. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  1891. int i;
  1892. int temp[64];
  1893. int sum=0;
  1894. assert(h==8);
  1895. for(i=0; i<8; i++){
  1896. //FIXME try pointer walks
  1897. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  1898. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  1899. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  1900. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  1901. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1902. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1903. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1904. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1905. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1906. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1907. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1908. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1909. }
  1910. for(i=0; i<8; i++){
  1911. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1912. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1913. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1914. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1915. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1916. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1917. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1918. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1919. sum +=
  1920. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1921. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1922. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1923. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1924. }
  1925. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  1926. return sum;
  1927. }
  1928. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1929. MpegEncContext * const s= (MpegEncContext *)c;
  1930. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1931. assert(h==8);
  1932. s->dsp.diff_pixels(temp, src1, src2, stride);
  1933. s->dsp.fdct(temp);
  1934. return s->dsp.sum_abs_dctelem(temp);
  1935. }
  1936. #if CONFIG_GPL
  1937. #define DCT8_1D {\
  1938. const int s07 = SRC(0) + SRC(7);\
  1939. const int s16 = SRC(1) + SRC(6);\
  1940. const int s25 = SRC(2) + SRC(5);\
  1941. const int s34 = SRC(3) + SRC(4);\
  1942. const int a0 = s07 + s34;\
  1943. const int a1 = s16 + s25;\
  1944. const int a2 = s07 - s34;\
  1945. const int a3 = s16 - s25;\
  1946. const int d07 = SRC(0) - SRC(7);\
  1947. const int d16 = SRC(1) - SRC(6);\
  1948. const int d25 = SRC(2) - SRC(5);\
  1949. const int d34 = SRC(3) - SRC(4);\
  1950. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  1951. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  1952. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  1953. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  1954. DST(0, a0 + a1 ) ;\
  1955. DST(1, a4 + (a7>>2)) ;\
  1956. DST(2, a2 + (a3>>1)) ;\
  1957. DST(3, a5 + (a6>>2)) ;\
  1958. DST(4, a0 - a1 ) ;\
  1959. DST(5, a6 - (a5>>2)) ;\
  1960. DST(6, (a2>>1) - a3 ) ;\
  1961. DST(7, (a4>>2) - a7 ) ;\
  1962. }
  1963. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1964. MpegEncContext * const s= (MpegEncContext *)c;
  1965. DCTELEM dct[8][8];
  1966. int i;
  1967. int sum=0;
  1968. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  1969. #define SRC(x) dct[i][x]
  1970. #define DST(x,v) dct[i][x]= v
  1971. for( i = 0; i < 8; i++ )
  1972. DCT8_1D
  1973. #undef SRC
  1974. #undef DST
  1975. #define SRC(x) dct[x][i]
  1976. #define DST(x,v) sum += FFABS(v)
  1977. for( i = 0; i < 8; i++ )
  1978. DCT8_1D
  1979. #undef SRC
  1980. #undef DST
  1981. return sum;
  1982. }
  1983. #endif
  1984. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1985. MpegEncContext * const s= (MpegEncContext *)c;
  1986. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1987. int sum=0, i;
  1988. assert(h==8);
  1989. s->dsp.diff_pixels(temp, src1, src2, stride);
  1990. s->dsp.fdct(temp);
  1991. for(i=0; i<64; i++)
  1992. sum= FFMAX(sum, FFABS(temp[i]));
  1993. return sum;
  1994. }
  1995. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1996. MpegEncContext * const s= (MpegEncContext *)c;
  1997. LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
  1998. DCTELEM * const bak = temp+64;
  1999. int sum=0, i;
  2000. assert(h==8);
  2001. s->mb_intra=0;
  2002. s->dsp.diff_pixels(temp, src1, src2, stride);
  2003. memcpy(bak, temp, 64*sizeof(DCTELEM));
  2004. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2005. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2006. ff_simple_idct_8(temp); //FIXME
  2007. for(i=0; i<64; i++)
  2008. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  2009. return sum;
  2010. }
  2011. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2012. MpegEncContext * const s= (MpegEncContext *)c;
  2013. const uint8_t *scantable= s->intra_scantable.permutated;
  2014. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  2015. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  2016. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  2017. int i, last, run, bits, level, distortion, start_i;
  2018. const int esc_length= s->ac_esc_length;
  2019. uint8_t * length;
  2020. uint8_t * last_length;
  2021. assert(h==8);
  2022. copy_block8(lsrc1, src1, 8, stride, 8);
  2023. copy_block8(lsrc2, src2, 8, stride, 8);
  2024. s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  2025. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2026. bits=0;
  2027. if (s->mb_intra) {
  2028. start_i = 1;
  2029. length = s->intra_ac_vlc_length;
  2030. last_length= s->intra_ac_vlc_last_length;
  2031. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2032. } else {
  2033. start_i = 0;
  2034. length = s->inter_ac_vlc_length;
  2035. last_length= s->inter_ac_vlc_last_length;
  2036. }
  2037. if(last>=start_i){
  2038. run=0;
  2039. for(i=start_i; i<last; i++){
  2040. int j= scantable[i];
  2041. level= temp[j];
  2042. if(level){
  2043. level+=64;
  2044. if((level&(~127)) == 0){
  2045. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2046. }else
  2047. bits+= esc_length;
  2048. run=0;
  2049. }else
  2050. run++;
  2051. }
  2052. i= scantable[last];
  2053. level= temp[i] + 64;
  2054. assert(level - 64);
  2055. if((level&(~127)) == 0){
  2056. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2057. }else
  2058. bits+= esc_length;
  2059. }
  2060. if(last>=0){
  2061. if(s->mb_intra)
  2062. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  2063. else
  2064. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2065. }
  2066. s->dsp.idct_add(lsrc2, 8, temp);
  2067. distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  2068. return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  2069. }
  2070. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2071. MpegEncContext * const s= (MpegEncContext *)c;
  2072. const uint8_t *scantable= s->intra_scantable.permutated;
  2073. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  2074. int i, last, run, bits, level, start_i;
  2075. const int esc_length= s->ac_esc_length;
  2076. uint8_t * length;
  2077. uint8_t * last_length;
  2078. assert(h==8);
  2079. s->dsp.diff_pixels(temp, src1, src2, stride);
  2080. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2081. bits=0;
  2082. if (s->mb_intra) {
  2083. start_i = 1;
  2084. length = s->intra_ac_vlc_length;
  2085. last_length= s->intra_ac_vlc_last_length;
  2086. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2087. } else {
  2088. start_i = 0;
  2089. length = s->inter_ac_vlc_length;
  2090. last_length= s->inter_ac_vlc_last_length;
  2091. }
  2092. if(last>=start_i){
  2093. run=0;
  2094. for(i=start_i; i<last; i++){
  2095. int j= scantable[i];
  2096. level= temp[j];
  2097. if(level){
  2098. level+=64;
  2099. if((level&(~127)) == 0){
  2100. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2101. }else
  2102. bits+= esc_length;
  2103. run=0;
  2104. }else
  2105. run++;
  2106. }
  2107. i= scantable[last];
  2108. level= temp[i] + 64;
  2109. assert(level - 64);
  2110. if((level&(~127)) == 0){
  2111. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2112. }else
  2113. bits+= esc_length;
  2114. }
  2115. return bits;
  2116. }
  2117. #define VSAD_INTRA(size) \
  2118. static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2119. int score=0; \
  2120. int x,y; \
  2121. \
  2122. for(y=1; y<h; y++){ \
  2123. for(x=0; x<size; x+=4){ \
  2124. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
  2125. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
  2126. } \
  2127. s+= stride; \
  2128. } \
  2129. \
  2130. return score; \
  2131. }
  2132. VSAD_INTRA(8)
  2133. VSAD_INTRA(16)
  2134. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2135. int score=0;
  2136. int x,y;
  2137. for(y=1; y<h; y++){
  2138. for(x=0; x<16; x++){
  2139. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2140. }
  2141. s1+= stride;
  2142. s2+= stride;
  2143. }
  2144. return score;
  2145. }
  2146. #define SQ(a) ((a)*(a))
  2147. #define VSSE_INTRA(size) \
  2148. static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2149. int score=0; \
  2150. int x,y; \
  2151. \
  2152. for(y=1; y<h; y++){ \
  2153. for(x=0; x<size; x+=4){ \
  2154. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
  2155. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
  2156. } \
  2157. s+= stride; \
  2158. } \
  2159. \
  2160. return score; \
  2161. }
  2162. VSSE_INTRA(8)
  2163. VSSE_INTRA(16)
  2164. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2165. int score=0;
  2166. int x,y;
  2167. for(y=1; y<h; y++){
  2168. for(x=0; x<16; x++){
  2169. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2170. }
  2171. s1+= stride;
  2172. s2+= stride;
  2173. }
  2174. return score;
  2175. }
  2176. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  2177. int size){
  2178. int score=0;
  2179. int i;
  2180. for(i=0; i<size; i++)
  2181. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  2182. return score;
  2183. }
  2184. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  2185. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  2186. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  2187. #if CONFIG_GPL
  2188. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  2189. #endif
  2190. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  2191. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  2192. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  2193. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  2194. static void vector_fmul_c(float *dst, const float *src0, const float *src1, int len){
  2195. int i;
  2196. for(i=0; i<len; i++)
  2197. dst[i] = src0[i] * src1[i];
  2198. }
  2199. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  2200. int i;
  2201. src1 += len-1;
  2202. for(i=0; i<len; i++)
  2203. dst[i] = src0[i] * src1[-i];
  2204. }
  2205. static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
  2206. int i;
  2207. for(i=0; i<len; i++)
  2208. dst[i] = src0[i] * src1[i] + src2[i];
  2209. }
  2210. static void vector_fmul_window_c(float *dst, const float *src0,
  2211. const float *src1, const float *win, int len)
  2212. {
  2213. int i,j;
  2214. dst += len;
  2215. win += len;
  2216. src0+= len;
  2217. for(i=-len, j=len-1; i<0; i++, j--) {
  2218. float s0 = src0[i];
  2219. float s1 = src1[j];
  2220. float wi = win[i];
  2221. float wj = win[j];
  2222. dst[i] = s0*wj - s1*wi;
  2223. dst[j] = s0*wi + s1*wj;
  2224. }
  2225. }
  2226. static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
  2227. int len)
  2228. {
  2229. int i;
  2230. for (i = 0; i < len; i++)
  2231. dst[i] = src[i] * mul;
  2232. }
  2233. static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
  2234. int len)
  2235. {
  2236. int i;
  2237. for (i = 0; i < len; i++)
  2238. dst[i] += src[i] * mul;
  2239. }
  2240. static void butterflies_float_c(float *restrict v1, float *restrict v2,
  2241. int len)
  2242. {
  2243. int i;
  2244. for (i = 0; i < len; i++) {
  2245. float t = v1[i] - v2[i];
  2246. v1[i] += v2[i];
  2247. v2[i] = t;
  2248. }
  2249. }
  2250. static void butterflies_float_interleave_c(float *dst, const float *src0,
  2251. const float *src1, int len)
  2252. {
  2253. int i;
  2254. for (i = 0; i < len; i++) {
  2255. float f1 = src0[i];
  2256. float f2 = src1[i];
  2257. dst[2*i ] = f1 + f2;
  2258. dst[2*i + 1] = f1 - f2;
  2259. }
  2260. }
  2261. static float scalarproduct_float_c(const float *v1, const float *v2, int len)
  2262. {
  2263. float p = 0.0;
  2264. int i;
  2265. for (i = 0; i < len; i++)
  2266. p += v1[i] * v2[i];
  2267. return p;
  2268. }
  2269. static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
  2270. uint32_t maxi, uint32_t maxisign)
  2271. {
  2272. if(a > mini) return mini;
  2273. else if((a^(1U<<31)) > maxisign) return maxi;
  2274. else return a;
  2275. }
  2276. static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
  2277. int i;
  2278. uint32_t mini = *(uint32_t*)min;
  2279. uint32_t maxi = *(uint32_t*)max;
  2280. uint32_t maxisign = maxi ^ (1U<<31);
  2281. uint32_t *dsti = (uint32_t*)dst;
  2282. const uint32_t *srci = (const uint32_t*)src;
  2283. for(i=0; i<len; i+=8) {
  2284. dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
  2285. dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
  2286. dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
  2287. dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
  2288. dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
  2289. dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
  2290. dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
  2291. dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
  2292. }
  2293. }
  2294. static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
  2295. int i;
  2296. if(min < 0 && max > 0) {
  2297. vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
  2298. } else {
  2299. for(i=0; i < len; i+=8) {
  2300. dst[i ] = av_clipf(src[i ], min, max);
  2301. dst[i + 1] = av_clipf(src[i + 1], min, max);
  2302. dst[i + 2] = av_clipf(src[i + 2], min, max);
  2303. dst[i + 3] = av_clipf(src[i + 3], min, max);
  2304. dst[i + 4] = av_clipf(src[i + 4], min, max);
  2305. dst[i + 5] = av_clipf(src[i + 5], min, max);
  2306. dst[i + 6] = av_clipf(src[i + 6], min, max);
  2307. dst[i + 7] = av_clipf(src[i + 7], min, max);
  2308. }
  2309. }
  2310. }
  2311. static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order, int shift)
  2312. {
  2313. int res = 0;
  2314. while (order--)
  2315. res += (*v1++ * *v2++) >> shift;
  2316. return res;
  2317. }
  2318. static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul)
  2319. {
  2320. int res = 0;
  2321. while (order--) {
  2322. res += *v1 * *v2++;
  2323. *v1++ += mul * *v3++;
  2324. }
  2325. return res;
  2326. }
  2327. static void apply_window_int16_c(int16_t *output, const int16_t *input,
  2328. const int16_t *window, unsigned int len)
  2329. {
  2330. int i;
  2331. int len2 = len >> 1;
  2332. for (i = 0; i < len2; i++) {
  2333. int16_t w = window[i];
  2334. output[i] = (MUL16(input[i], w) + (1 << 14)) >> 15;
  2335. output[len-i-1] = (MUL16(input[len-i-1], w) + (1 << 14)) >> 15;
  2336. }
  2337. }
  2338. static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min,
  2339. int32_t max, unsigned int len)
  2340. {
  2341. do {
  2342. *dst++ = av_clip(*src++, min, max);
  2343. *dst++ = av_clip(*src++, min, max);
  2344. *dst++ = av_clip(*src++, min, max);
  2345. *dst++ = av_clip(*src++, min, max);
  2346. *dst++ = av_clip(*src++, min, max);
  2347. *dst++ = av_clip(*src++, min, max);
  2348. *dst++ = av_clip(*src++, min, max);
  2349. *dst++ = av_clip(*src++, min, max);
  2350. len -= 8;
  2351. } while (len > 0);
  2352. }
  2353. #define W0 2048
  2354. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  2355. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  2356. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  2357. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  2358. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  2359. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  2360. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  2361. static void wmv2_idct_row(short * b)
  2362. {
  2363. int s1,s2;
  2364. int a0,a1,a2,a3,a4,a5,a6,a7;
  2365. /*step 1*/
  2366. a1 = W1*b[1]+W7*b[7];
  2367. a7 = W7*b[1]-W1*b[7];
  2368. a5 = W5*b[5]+W3*b[3];
  2369. a3 = W3*b[5]-W5*b[3];
  2370. a2 = W2*b[2]+W6*b[6];
  2371. a6 = W6*b[2]-W2*b[6];
  2372. a0 = W0*b[0]+W0*b[4];
  2373. a4 = W0*b[0]-W0*b[4];
  2374. /*step 2*/
  2375. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  2376. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2377. /*step 3*/
  2378. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  2379. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  2380. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  2381. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  2382. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  2383. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  2384. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  2385. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  2386. }
  2387. static void wmv2_idct_col(short * b)
  2388. {
  2389. int s1,s2;
  2390. int a0,a1,a2,a3,a4,a5,a6,a7;
  2391. /*step 1, with extended precision*/
  2392. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  2393. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  2394. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  2395. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  2396. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  2397. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  2398. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  2399. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  2400. /*step 2*/
  2401. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  2402. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2403. /*step 3*/
  2404. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  2405. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  2406. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  2407. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  2408. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  2409. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  2410. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  2411. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  2412. }
  2413. void ff_wmv2_idct_c(short * block){
  2414. int i;
  2415. for(i=0;i<64;i+=8){
  2416. wmv2_idct_row(block+i);
  2417. }
  2418. for(i=0;i<8;i++){
  2419. wmv2_idct_col(block+i);
  2420. }
  2421. }
  2422. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  2423. converted */
  2424. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  2425. {
  2426. ff_wmv2_idct_c(block);
  2427. ff_put_pixels_clamped_c(block, dest, line_size);
  2428. }
  2429. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  2430. {
  2431. ff_wmv2_idct_c(block);
  2432. ff_add_pixels_clamped_c(block, dest, line_size);
  2433. }
  2434. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  2435. {
  2436. j_rev_dct (block);
  2437. ff_put_pixels_clamped_c(block, dest, line_size);
  2438. }
  2439. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  2440. {
  2441. j_rev_dct (block);
  2442. ff_add_pixels_clamped_c(block, dest, line_size);
  2443. }
  2444. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  2445. {
  2446. j_rev_dct4 (block);
  2447. put_pixels_clamped4_c(block, dest, line_size);
  2448. }
  2449. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  2450. {
  2451. j_rev_dct4 (block);
  2452. add_pixels_clamped4_c(block, dest, line_size);
  2453. }
  2454. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  2455. {
  2456. j_rev_dct2 (block);
  2457. put_pixels_clamped2_c(block, dest, line_size);
  2458. }
  2459. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  2460. {
  2461. j_rev_dct2 (block);
  2462. add_pixels_clamped2_c(block, dest, line_size);
  2463. }
  2464. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  2465. {
  2466. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2467. dest[0] = cm[(block[0] + 4)>>3];
  2468. }
  2469. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  2470. {
  2471. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2472. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  2473. }
  2474. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  2475. /* init static data */
  2476. av_cold void dsputil_static_init(void)
  2477. {
  2478. int i;
  2479. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  2480. for(i=0;i<MAX_NEG_CROP;i++) {
  2481. ff_cropTbl[i] = 0;
  2482. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  2483. }
  2484. for(i=0;i<512;i++) {
  2485. ff_squareTbl[i] = (i - 256) * (i - 256);
  2486. }
  2487. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  2488. }
  2489. int ff_check_alignment(void){
  2490. static int did_fail=0;
  2491. LOCAL_ALIGNED_16(int, aligned, [4]);
  2492. if((intptr_t)aligned & 15){
  2493. if(!did_fail){
  2494. #if HAVE_MMX || HAVE_ALTIVEC
  2495. av_log(NULL, AV_LOG_ERROR,
  2496. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  2497. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  2498. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  2499. "Do not report crashes to Libav developers.\n");
  2500. #endif
  2501. did_fail=1;
  2502. }
  2503. return -1;
  2504. }
  2505. return 0;
  2506. }
  2507. av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  2508. {
  2509. int i;
  2510. ff_check_alignment();
  2511. #if CONFIG_ENCODERS
  2512. if (avctx->bits_per_raw_sample == 10) {
  2513. c->fdct = ff_jpeg_fdct_islow_10;
  2514. c->fdct248 = ff_fdct248_islow_10;
  2515. } else {
  2516. if(avctx->dct_algo==FF_DCT_FASTINT) {
  2517. c->fdct = fdct_ifast;
  2518. c->fdct248 = fdct_ifast248;
  2519. }
  2520. else if(avctx->dct_algo==FF_DCT_FAAN) {
  2521. c->fdct = ff_faandct;
  2522. c->fdct248 = ff_faandct248;
  2523. }
  2524. else {
  2525. c->fdct = ff_jpeg_fdct_islow_8; //slow/accurate/default
  2526. c->fdct248 = ff_fdct248_islow_8;
  2527. }
  2528. }
  2529. #endif //CONFIG_ENCODERS
  2530. if(avctx->lowres==1){
  2531. c->idct_put= ff_jref_idct4_put;
  2532. c->idct_add= ff_jref_idct4_add;
  2533. c->idct = j_rev_dct4;
  2534. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2535. }else if(avctx->lowres==2){
  2536. c->idct_put= ff_jref_idct2_put;
  2537. c->idct_add= ff_jref_idct2_add;
  2538. c->idct = j_rev_dct2;
  2539. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2540. }else if(avctx->lowres==3){
  2541. c->idct_put= ff_jref_idct1_put;
  2542. c->idct_add= ff_jref_idct1_add;
  2543. c->idct = j_rev_dct1;
  2544. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2545. }else{
  2546. if (avctx->bits_per_raw_sample == 10) {
  2547. c->idct_put = ff_simple_idct_put_10;
  2548. c->idct_add = ff_simple_idct_add_10;
  2549. c->idct = ff_simple_idct_10;
  2550. c->idct_permutation_type = FF_NO_IDCT_PERM;
  2551. } else {
  2552. if(avctx->idct_algo==FF_IDCT_INT){
  2553. c->idct_put= ff_jref_idct_put;
  2554. c->idct_add= ff_jref_idct_add;
  2555. c->idct = j_rev_dct;
  2556. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2557. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
  2558. avctx->idct_algo==FF_IDCT_VP3){
  2559. c->idct_put= ff_vp3_idct_put_c;
  2560. c->idct_add= ff_vp3_idct_add_c;
  2561. c->idct = ff_vp3_idct_c;
  2562. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2563. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  2564. c->idct_put= ff_wmv2_idct_put_c;
  2565. c->idct_add= ff_wmv2_idct_add_c;
  2566. c->idct = ff_wmv2_idct_c;
  2567. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2568. }else if(avctx->idct_algo==FF_IDCT_FAAN){
  2569. c->idct_put= ff_faanidct_put;
  2570. c->idct_add= ff_faanidct_add;
  2571. c->idct = ff_faanidct;
  2572. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2573. }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
  2574. c->idct_put= ff_ea_idct_put_c;
  2575. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2576. }else{ //accurate/default
  2577. c->idct_put = ff_simple_idct_put_8;
  2578. c->idct_add = ff_simple_idct_add_8;
  2579. c->idct = ff_simple_idct_8;
  2580. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2581. }
  2582. }
  2583. }
  2584. c->diff_pixels = diff_pixels_c;
  2585. c->put_pixels_clamped = ff_put_pixels_clamped_c;
  2586. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_c;
  2587. c->add_pixels_clamped = ff_add_pixels_clamped_c;
  2588. c->sum_abs_dctelem = sum_abs_dctelem_c;
  2589. c->gmc1 = gmc1_c;
  2590. c->gmc = ff_gmc_c;
  2591. c->pix_sum = pix_sum_c;
  2592. c->pix_norm1 = pix_norm1_c;
  2593. c->fill_block_tab[0] = fill_block16_c;
  2594. c->fill_block_tab[1] = fill_block8_c;
  2595. /* TODO [0] 16 [1] 8 */
  2596. c->pix_abs[0][0] = pix_abs16_c;
  2597. c->pix_abs[0][1] = pix_abs16_x2_c;
  2598. c->pix_abs[0][2] = pix_abs16_y2_c;
  2599. c->pix_abs[0][3] = pix_abs16_xy2_c;
  2600. c->pix_abs[1][0] = pix_abs8_c;
  2601. c->pix_abs[1][1] = pix_abs8_x2_c;
  2602. c->pix_abs[1][2] = pix_abs8_y2_c;
  2603. c->pix_abs[1][3] = pix_abs8_xy2_c;
  2604. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  2605. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  2606. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  2607. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  2608. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  2609. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  2610. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  2611. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  2612. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  2613. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  2614. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  2615. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  2616. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  2617. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  2618. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  2619. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  2620. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  2621. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  2622. #define dspfunc(PFX, IDX, NUM) \
  2623. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  2624. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  2625. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  2626. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  2627. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  2628. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  2629. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  2630. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  2631. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  2632. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  2633. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  2634. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  2635. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  2636. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  2637. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  2638. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  2639. dspfunc(put_qpel, 0, 16);
  2640. dspfunc(put_no_rnd_qpel, 0, 16);
  2641. dspfunc(avg_qpel, 0, 16);
  2642. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  2643. dspfunc(put_qpel, 1, 8);
  2644. dspfunc(put_no_rnd_qpel, 1, 8);
  2645. dspfunc(avg_qpel, 1, 8);
  2646. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  2647. #undef dspfunc
  2648. #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
  2649. ff_mlp_init(c, avctx);
  2650. #endif
  2651. #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
  2652. ff_intrax8dsp_init(c,avctx);
  2653. #endif
  2654. c->put_mspel_pixels_tab[0]= ff_put_pixels8x8_c;
  2655. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  2656. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  2657. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  2658. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  2659. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  2660. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  2661. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  2662. #define SET_CMP_FUNC(name) \
  2663. c->name[0]= name ## 16_c;\
  2664. c->name[1]= name ## 8x8_c;
  2665. SET_CMP_FUNC(hadamard8_diff)
  2666. c->hadamard8_diff[4]= hadamard8_intra16_c;
  2667. c->hadamard8_diff[5]= hadamard8_intra8x8_c;
  2668. SET_CMP_FUNC(dct_sad)
  2669. SET_CMP_FUNC(dct_max)
  2670. #if CONFIG_GPL
  2671. SET_CMP_FUNC(dct264_sad)
  2672. #endif
  2673. c->sad[0]= pix_abs16_c;
  2674. c->sad[1]= pix_abs8_c;
  2675. c->sse[0]= sse16_c;
  2676. c->sse[1]= sse8_c;
  2677. c->sse[2]= sse4_c;
  2678. SET_CMP_FUNC(quant_psnr)
  2679. SET_CMP_FUNC(rd)
  2680. SET_CMP_FUNC(bit)
  2681. c->vsad[0]= vsad16_c;
  2682. c->vsad[4]= vsad_intra16_c;
  2683. c->vsad[5]= vsad_intra8_c;
  2684. c->vsse[0]= vsse16_c;
  2685. c->vsse[4]= vsse_intra16_c;
  2686. c->vsse[5]= vsse_intra8_c;
  2687. c->nsse[0]= nsse16_c;
  2688. c->nsse[1]= nsse8_c;
  2689. #if CONFIG_DWT
  2690. ff_dsputil_init_dwt(c);
  2691. #endif
  2692. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  2693. c->add_bytes= add_bytes_c;
  2694. c->add_bytes_l2= add_bytes_l2_c;
  2695. c->diff_bytes= diff_bytes_c;
  2696. c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
  2697. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  2698. c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
  2699. c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
  2700. c->bswap_buf= bswap_buf;
  2701. c->bswap16_buf = bswap16_buf;
  2702. #if CONFIG_PNG_DECODER
  2703. c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
  2704. #endif
  2705. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2706. c->h263_h_loop_filter= h263_h_loop_filter_c;
  2707. c->h263_v_loop_filter= h263_v_loop_filter_c;
  2708. }
  2709. if (CONFIG_VP3_DECODER) {
  2710. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
  2711. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
  2712. c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c;
  2713. }
  2714. c->h261_loop_filter= h261_loop_filter_c;
  2715. c->try_8x8basis= try_8x8basis_c;
  2716. c->add_8x8basis= add_8x8basis_c;
  2717. #if CONFIG_VORBIS_DECODER
  2718. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  2719. #endif
  2720. #if CONFIG_AC3_DECODER
  2721. c->ac3_downmix = ff_ac3_downmix_c;
  2722. #endif
  2723. c->vector_fmul = vector_fmul_c;
  2724. c->vector_fmul_reverse = vector_fmul_reverse_c;
  2725. c->vector_fmul_add = vector_fmul_add_c;
  2726. c->vector_fmul_window = vector_fmul_window_c;
  2727. c->vector_clipf = vector_clipf_c;
  2728. c->scalarproduct_int16 = scalarproduct_int16_c;
  2729. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
  2730. c->apply_window_int16 = apply_window_int16_c;
  2731. c->vector_clip_int32 = vector_clip_int32_c;
  2732. c->scalarproduct_float = scalarproduct_float_c;
  2733. c->butterflies_float = butterflies_float_c;
  2734. c->butterflies_float_interleave = butterflies_float_interleave_c;
  2735. c->vector_fmul_scalar = vector_fmul_scalar_c;
  2736. c->vector_fmac_scalar = vector_fmac_scalar_c;
  2737. c->shrink[0]= av_image_copy_plane;
  2738. c->shrink[1]= ff_shrink22;
  2739. c->shrink[2]= ff_shrink44;
  2740. c->shrink[3]= ff_shrink88;
  2741. c->prefetch= just_return;
  2742. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  2743. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  2744. #undef FUNC
  2745. #undef FUNCC
  2746. #define FUNC(f, depth) f ## _ ## depth
  2747. #define FUNCC(f, depth) f ## _ ## depth ## _c
  2748. #define dspfunc1(PFX, IDX, NUM, depth)\
  2749. c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## _pixels ## NUM , depth);\
  2750. c->PFX ## _pixels_tab[IDX][1] = FUNCC(PFX ## _pixels ## NUM ## _x2 , depth);\
  2751. c->PFX ## _pixels_tab[IDX][2] = FUNCC(PFX ## _pixels ## NUM ## _y2 , depth);\
  2752. c->PFX ## _pixels_tab[IDX][3] = FUNCC(PFX ## _pixels ## NUM ## _xy2, depth)
  2753. #define dspfunc2(PFX, IDX, NUM, depth)\
  2754. c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth);\
  2755. c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth);\
  2756. c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth);\
  2757. c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth);\
  2758. c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth);\
  2759. c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth);\
  2760. c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth);\
  2761. c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth);\
  2762. c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth);\
  2763. c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth);\
  2764. c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth);\
  2765. c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth);\
  2766. c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth);\
  2767. c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth);\
  2768. c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth);\
  2769. c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth)
  2770. #define BIT_DEPTH_FUNCS(depth, dct)\
  2771. c->get_pixels = FUNCC(get_pixels ## dct , depth);\
  2772. c->draw_edges = FUNCC(draw_edges , depth);\
  2773. c->emulated_edge_mc = FUNC (ff_emulated_edge_mc , depth);\
  2774. c->clear_block = FUNCC(clear_block ## dct , depth);\
  2775. c->clear_blocks = FUNCC(clear_blocks ## dct , depth);\
  2776. c->add_pixels8 = FUNCC(add_pixels8 ## dct , depth);\
  2777. c->add_pixels4 = FUNCC(add_pixels4 ## dct , depth);\
  2778. c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\
  2779. c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\
  2780. \
  2781. c->put_h264_chroma_pixels_tab[0] = FUNCC(put_h264_chroma_mc8 , depth);\
  2782. c->put_h264_chroma_pixels_tab[1] = FUNCC(put_h264_chroma_mc4 , depth);\
  2783. c->put_h264_chroma_pixels_tab[2] = FUNCC(put_h264_chroma_mc2 , depth);\
  2784. c->avg_h264_chroma_pixels_tab[0] = FUNCC(avg_h264_chroma_mc8 , depth);\
  2785. c->avg_h264_chroma_pixels_tab[1] = FUNCC(avg_h264_chroma_mc4 , depth);\
  2786. c->avg_h264_chroma_pixels_tab[2] = FUNCC(avg_h264_chroma_mc2 , depth);\
  2787. \
  2788. dspfunc1(put , 0, 16, depth);\
  2789. dspfunc1(put , 1, 8, depth);\
  2790. dspfunc1(put , 2, 4, depth);\
  2791. dspfunc1(put , 3, 2, depth);\
  2792. dspfunc1(put_no_rnd, 0, 16, depth);\
  2793. dspfunc1(put_no_rnd, 1, 8, depth);\
  2794. dspfunc1(avg , 0, 16, depth);\
  2795. dspfunc1(avg , 1, 8, depth);\
  2796. dspfunc1(avg , 2, 4, depth);\
  2797. dspfunc1(avg , 3, 2, depth);\
  2798. dspfunc1(avg_no_rnd, 0, 16, depth);\
  2799. dspfunc1(avg_no_rnd, 1, 8, depth);\
  2800. \
  2801. dspfunc2(put_h264_qpel, 0, 16, depth);\
  2802. dspfunc2(put_h264_qpel, 1, 8, depth);\
  2803. dspfunc2(put_h264_qpel, 2, 4, depth);\
  2804. dspfunc2(put_h264_qpel, 3, 2, depth);\
  2805. dspfunc2(avg_h264_qpel, 0, 16, depth);\
  2806. dspfunc2(avg_h264_qpel, 1, 8, depth);\
  2807. dspfunc2(avg_h264_qpel, 2, 4, depth);
  2808. switch (avctx->bits_per_raw_sample) {
  2809. case 9:
  2810. if (c->dct_bits == 32) {
  2811. BIT_DEPTH_FUNCS(9, _32);
  2812. } else {
  2813. BIT_DEPTH_FUNCS(9, _16);
  2814. }
  2815. break;
  2816. case 10:
  2817. if (c->dct_bits == 32) {
  2818. BIT_DEPTH_FUNCS(10, _32);
  2819. } else {
  2820. BIT_DEPTH_FUNCS(10, _16);
  2821. }
  2822. break;
  2823. default:
  2824. av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample);
  2825. case 8:
  2826. BIT_DEPTH_FUNCS(8, _16);
  2827. break;
  2828. }
  2829. if (HAVE_MMX) dsputil_init_mmx (c, avctx);
  2830. if (ARCH_ARM) dsputil_init_arm (c, avctx);
  2831. if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
  2832. if (HAVE_VIS) dsputil_init_vis (c, avctx);
  2833. if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
  2834. if (ARCH_PPC) dsputil_init_ppc (c, avctx);
  2835. if (HAVE_MMI) dsputil_init_mmi (c, avctx);
  2836. if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
  2837. if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
  2838. for(i=0; i<64; i++){
  2839. if(!c->put_2tap_qpel_pixels_tab[0][i])
  2840. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  2841. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  2842. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  2843. }
  2844. ff_init_scantable_permutation(c->idct_permutation,
  2845. c->idct_permutation_type);
  2846. }