dsputil.c 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700
  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 FFmpeg.
  9. *
  10. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file libavcodec/dsputil.c
  26. * DSP utils
  27. */
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "simple_idct.h"
  31. #include "faandct.h"
  32. #include "faanidct.h"
  33. #include "mathops.h"
  34. #include "h263.h"
  35. #include "snow.h"
  36. /* snow.c */
  37. void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count);
  38. /* vorbis.c */
  39. void vorbis_inverse_coupling(float *mag, float *ang, int blocksize);
  40. /* ac3dec.c */
  41. void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
  42. /* flacenc.c */
  43. void ff_flac_compute_autocorr(const int32_t *data, int len, int lag, double *autoc);
  44. /* pngdec.c */
  45. void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
  46. /* eaidct.c */
  47. void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
  48. uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  49. uint32_t ff_squareTbl[512] = {0, };
  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_8(uint16_t, inv_zigzag_direct16[64]) = {0, };
  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. /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
  98. const uint32_t ff_inverse[256]={
  99. 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
  100. 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
  101. 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
  102. 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
  103. 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
  104. 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
  105. 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
  106. 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
  107. 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
  108. 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
  109. 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
  110. 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
  111. 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
  112. 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
  113. 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
  114. 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
  115. 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
  116. 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
  117. 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
  118. 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
  119. 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
  120. 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
  121. 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
  122. 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
  123. 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
  124. 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
  125. 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
  126. 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
  127. 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
  128. 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
  129. 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
  130. 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
  131. };
  132. /* Input permutation for the simple_idct_mmx */
  133. static const uint8_t simple_mmx_permutation[64]={
  134. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  135. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  136. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  137. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  138. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  139. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  140. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  141. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  142. };
  143. static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
  144. void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
  145. int i;
  146. int end;
  147. st->scantable= src_scantable;
  148. for(i=0; i<64; i++){
  149. int j;
  150. j = src_scantable[i];
  151. st->permutated[i] = permutation[j];
  152. #if ARCH_PPC
  153. st->inverse[j] = i;
  154. #endif
  155. }
  156. end=-1;
  157. for(i=0; i<64; i++){
  158. int j;
  159. j = st->permutated[i];
  160. if(j>end) end=j;
  161. st->raster_end[i]= end;
  162. }
  163. }
  164. static int pix_sum_c(uint8_t * pix, int line_size)
  165. {
  166. int s, i, j;
  167. s = 0;
  168. for (i = 0; i < 16; i++) {
  169. for (j = 0; j < 16; j += 8) {
  170. s += pix[0];
  171. s += pix[1];
  172. s += pix[2];
  173. s += pix[3];
  174. s += pix[4];
  175. s += pix[5];
  176. s += pix[6];
  177. s += pix[7];
  178. pix += 8;
  179. }
  180. pix += line_size - 16;
  181. }
  182. return s;
  183. }
  184. static int pix_norm1_c(uint8_t * pix, int line_size)
  185. {
  186. int s, i, j;
  187. uint32_t *sq = ff_squareTbl + 256;
  188. s = 0;
  189. for (i = 0; i < 16; i++) {
  190. for (j = 0; j < 16; j += 8) {
  191. #if 0
  192. s += sq[pix[0]];
  193. s += sq[pix[1]];
  194. s += sq[pix[2]];
  195. s += sq[pix[3]];
  196. s += sq[pix[4]];
  197. s += sq[pix[5]];
  198. s += sq[pix[6]];
  199. s += sq[pix[7]];
  200. #else
  201. #if LONG_MAX > 2147483647
  202. register uint64_t x=*(uint64_t*)pix;
  203. s += sq[x&0xff];
  204. s += sq[(x>>8)&0xff];
  205. s += sq[(x>>16)&0xff];
  206. s += sq[(x>>24)&0xff];
  207. s += sq[(x>>32)&0xff];
  208. s += sq[(x>>40)&0xff];
  209. s += sq[(x>>48)&0xff];
  210. s += sq[(x>>56)&0xff];
  211. #else
  212. register uint32_t x=*(uint32_t*)pix;
  213. s += sq[x&0xff];
  214. s += sq[(x>>8)&0xff];
  215. s += sq[(x>>16)&0xff];
  216. s += sq[(x>>24)&0xff];
  217. x=*(uint32_t*)(pix+4);
  218. s += sq[x&0xff];
  219. s += sq[(x>>8)&0xff];
  220. s += sq[(x>>16)&0xff];
  221. s += sq[(x>>24)&0xff];
  222. #endif
  223. #endif
  224. pix += 8;
  225. }
  226. pix += line_size - 16;
  227. }
  228. return s;
  229. }
  230. static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
  231. int i;
  232. for(i=0; i+8<=w; i+=8){
  233. dst[i+0]= bswap_32(src[i+0]);
  234. dst[i+1]= bswap_32(src[i+1]);
  235. dst[i+2]= bswap_32(src[i+2]);
  236. dst[i+3]= bswap_32(src[i+3]);
  237. dst[i+4]= bswap_32(src[i+4]);
  238. dst[i+5]= bswap_32(src[i+5]);
  239. dst[i+6]= bswap_32(src[i+6]);
  240. dst[i+7]= bswap_32(src[i+7]);
  241. }
  242. for(;i<w; i++){
  243. dst[i+0]= bswap_32(src[i+0]);
  244. }
  245. }
  246. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  247. {
  248. int s, i;
  249. uint32_t *sq = ff_squareTbl + 256;
  250. s = 0;
  251. for (i = 0; i < h; i++) {
  252. s += sq[pix1[0] - pix2[0]];
  253. s += sq[pix1[1] - pix2[1]];
  254. s += sq[pix1[2] - pix2[2]];
  255. s += sq[pix1[3] - pix2[3]];
  256. pix1 += line_size;
  257. pix2 += line_size;
  258. }
  259. return s;
  260. }
  261. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  262. {
  263. int s, i;
  264. uint32_t *sq = ff_squareTbl + 256;
  265. s = 0;
  266. for (i = 0; i < h; i++) {
  267. s += sq[pix1[0] - pix2[0]];
  268. s += sq[pix1[1] - pix2[1]];
  269. s += sq[pix1[2] - pix2[2]];
  270. s += sq[pix1[3] - pix2[3]];
  271. s += sq[pix1[4] - pix2[4]];
  272. s += sq[pix1[5] - pix2[5]];
  273. s += sq[pix1[6] - pix2[6]];
  274. s += sq[pix1[7] - pix2[7]];
  275. pix1 += line_size;
  276. pix2 += line_size;
  277. }
  278. return s;
  279. }
  280. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  281. {
  282. int s, i;
  283. uint32_t *sq = ff_squareTbl + 256;
  284. s = 0;
  285. for (i = 0; i < h; i++) {
  286. s += sq[pix1[ 0] - pix2[ 0]];
  287. s += sq[pix1[ 1] - pix2[ 1]];
  288. s += sq[pix1[ 2] - pix2[ 2]];
  289. s += sq[pix1[ 3] - pix2[ 3]];
  290. s += sq[pix1[ 4] - pix2[ 4]];
  291. s += sq[pix1[ 5] - pix2[ 5]];
  292. s += sq[pix1[ 6] - pix2[ 6]];
  293. s += sq[pix1[ 7] - pix2[ 7]];
  294. s += sq[pix1[ 8] - pix2[ 8]];
  295. s += sq[pix1[ 9] - pix2[ 9]];
  296. s += sq[pix1[10] - pix2[10]];
  297. s += sq[pix1[11] - pix2[11]];
  298. s += sq[pix1[12] - pix2[12]];
  299. s += sq[pix1[13] - pix2[13]];
  300. s += sq[pix1[14] - pix2[14]];
  301. s += sq[pix1[15] - pix2[15]];
  302. pix1 += line_size;
  303. pix2 += line_size;
  304. }
  305. return s;
  306. }
  307. #if CONFIG_SNOW_ENCODER //dwt is in snow.c
  308. static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){
  309. int s, i, j;
  310. const int dec_count= w==8 ? 3 : 4;
  311. int tmp[32*32];
  312. int level, ori;
  313. static const int scale[2][2][4][4]={
  314. {
  315. {
  316. // 9/7 8x8 dec=3
  317. {268, 239, 239, 213},
  318. { 0, 224, 224, 152},
  319. { 0, 135, 135, 110},
  320. },{
  321. // 9/7 16x16 or 32x32 dec=4
  322. {344, 310, 310, 280},
  323. { 0, 320, 320, 228},
  324. { 0, 175, 175, 136},
  325. { 0, 129, 129, 102},
  326. }
  327. },{
  328. {
  329. // 5/3 8x8 dec=3
  330. {275, 245, 245, 218},
  331. { 0, 230, 230, 156},
  332. { 0, 138, 138, 113},
  333. },{
  334. // 5/3 16x16 or 32x32 dec=4
  335. {352, 317, 317, 286},
  336. { 0, 328, 328, 233},
  337. { 0, 180, 180, 140},
  338. { 0, 132, 132, 105},
  339. }
  340. }
  341. };
  342. for (i = 0; i < h; i++) {
  343. for (j = 0; j < w; j+=4) {
  344. tmp[32*i+j+0] = (pix1[j+0] - pix2[j+0])<<4;
  345. tmp[32*i+j+1] = (pix1[j+1] - pix2[j+1])<<4;
  346. tmp[32*i+j+2] = (pix1[j+2] - pix2[j+2])<<4;
  347. tmp[32*i+j+3] = (pix1[j+3] - pix2[j+3])<<4;
  348. }
  349. pix1 += line_size;
  350. pix2 += line_size;
  351. }
  352. ff_spatial_dwt(tmp, w, h, 32, type, dec_count);
  353. s=0;
  354. assert(w==h);
  355. for(level=0; level<dec_count; level++){
  356. for(ori= level ? 1 : 0; ori<4; ori++){
  357. int size= w>>(dec_count-level);
  358. int sx= (ori&1) ? size : 0;
  359. int stride= 32<<(dec_count-level);
  360. int sy= (ori&2) ? stride>>1 : 0;
  361. for(i=0; i<size; i++){
  362. for(j=0; j<size; j++){
  363. int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
  364. s += FFABS(v);
  365. }
  366. }
  367. }
  368. }
  369. assert(s>=0);
  370. return s>>9;
  371. }
  372. static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  373. return w_c(v, pix1, pix2, line_size, 8, h, 1);
  374. }
  375. static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  376. return w_c(v, pix1, pix2, line_size, 8, h, 0);
  377. }
  378. static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  379. return w_c(v, pix1, pix2, line_size, 16, h, 1);
  380. }
  381. static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  382. return w_c(v, pix1, pix2, line_size, 16, h, 0);
  383. }
  384. int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  385. return w_c(v, pix1, pix2, line_size, 32, h, 1);
  386. }
  387. int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  388. return w_c(v, pix1, pix2, line_size, 32, h, 0);
  389. }
  390. #endif
  391. /* draw the edges of width 'w' of an image of size width, height */
  392. //FIXME check that this is ok for mpeg4 interlaced
  393. static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
  394. {
  395. uint8_t *ptr, *last_line;
  396. int i;
  397. last_line = buf + (height - 1) * wrap;
  398. for(i=0;i<w;i++) {
  399. /* top and bottom */
  400. memcpy(buf - (i + 1) * wrap, buf, width);
  401. memcpy(last_line + (i + 1) * wrap, last_line, width);
  402. }
  403. /* left and right */
  404. ptr = buf;
  405. for(i=0;i<height;i++) {
  406. memset(ptr - w, ptr[0], w);
  407. memset(ptr + width, ptr[width-1], w);
  408. ptr += wrap;
  409. }
  410. /* corners */
  411. for(i=0;i<w;i++) {
  412. memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
  413. memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
  414. memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
  415. memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
  416. }
  417. }
  418. /**
  419. * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
  420. * @param buf destination buffer
  421. * @param src source buffer
  422. * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
  423. * @param block_w width of block
  424. * @param block_h height of block
  425. * @param src_x x coordinate of the top left sample of the block in the source buffer
  426. * @param src_y y coordinate of the top left sample of the block in the source buffer
  427. * @param w width of the source buffer
  428. * @param h height of the source buffer
  429. */
  430. void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
  431. int src_x, int src_y, int w, int h){
  432. int x, y;
  433. int start_y, start_x, end_y, end_x;
  434. if(src_y>= h){
  435. src+= (h-1-src_y)*linesize;
  436. src_y=h-1;
  437. }else if(src_y<=-block_h){
  438. src+= (1-block_h-src_y)*linesize;
  439. src_y=1-block_h;
  440. }
  441. if(src_x>= w){
  442. src+= (w-1-src_x);
  443. src_x=w-1;
  444. }else if(src_x<=-block_w){
  445. src+= (1-block_w-src_x);
  446. src_x=1-block_w;
  447. }
  448. start_y= FFMAX(0, -src_y);
  449. start_x= FFMAX(0, -src_x);
  450. end_y= FFMIN(block_h, h-src_y);
  451. end_x= FFMIN(block_w, w-src_x);
  452. // copy existing part
  453. for(y=start_y; y<end_y; y++){
  454. for(x=start_x; x<end_x; x++){
  455. buf[x + y*linesize]= src[x + y*linesize];
  456. }
  457. }
  458. //top
  459. for(y=0; y<start_y; y++){
  460. for(x=start_x; x<end_x; x++){
  461. buf[x + y*linesize]= buf[x + start_y*linesize];
  462. }
  463. }
  464. //bottom
  465. for(y=end_y; y<block_h; y++){
  466. for(x=start_x; x<end_x; x++){
  467. buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
  468. }
  469. }
  470. for(y=0; y<block_h; y++){
  471. //left
  472. for(x=0; x<start_x; x++){
  473. buf[x + y*linesize]= buf[start_x + y*linesize];
  474. }
  475. //right
  476. for(x=end_x; x<block_w; x++){
  477. buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
  478. }
  479. }
  480. }
  481. static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  482. {
  483. int i;
  484. /* read the pixels */
  485. for(i=0;i<8;i++) {
  486. block[0] = pixels[0];
  487. block[1] = pixels[1];
  488. block[2] = pixels[2];
  489. block[3] = pixels[3];
  490. block[4] = pixels[4];
  491. block[5] = pixels[5];
  492. block[6] = pixels[6];
  493. block[7] = pixels[7];
  494. pixels += line_size;
  495. block += 8;
  496. }
  497. }
  498. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  499. const uint8_t *s2, int stride){
  500. int i;
  501. /* read the pixels */
  502. for(i=0;i<8;i++) {
  503. block[0] = s1[0] - s2[0];
  504. block[1] = s1[1] - s2[1];
  505. block[2] = s1[2] - s2[2];
  506. block[3] = s1[3] - s2[3];
  507. block[4] = s1[4] - s2[4];
  508. block[5] = s1[5] - s2[5];
  509. block[6] = s1[6] - s2[6];
  510. block[7] = s1[7] - s2[7];
  511. s1 += stride;
  512. s2 += stride;
  513. block += 8;
  514. }
  515. }
  516. static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  517. int line_size)
  518. {
  519. int i;
  520. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  521. /* read the pixels */
  522. for(i=0;i<8;i++) {
  523. pixels[0] = cm[block[0]];
  524. pixels[1] = cm[block[1]];
  525. pixels[2] = cm[block[2]];
  526. pixels[3] = cm[block[3]];
  527. pixels[4] = cm[block[4]];
  528. pixels[5] = cm[block[5]];
  529. pixels[6] = cm[block[6]];
  530. pixels[7] = cm[block[7]];
  531. pixels += line_size;
  532. block += 8;
  533. }
  534. }
  535. static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  536. int line_size)
  537. {
  538. int i;
  539. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  540. /* read the pixels */
  541. for(i=0;i<4;i++) {
  542. pixels[0] = cm[block[0]];
  543. pixels[1] = cm[block[1]];
  544. pixels[2] = cm[block[2]];
  545. pixels[3] = cm[block[3]];
  546. pixels += line_size;
  547. block += 8;
  548. }
  549. }
  550. static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  551. int line_size)
  552. {
  553. int i;
  554. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  555. /* read the pixels */
  556. for(i=0;i<2;i++) {
  557. pixels[0] = cm[block[0]];
  558. pixels[1] = cm[block[1]];
  559. pixels += line_size;
  560. block += 8;
  561. }
  562. }
  563. static void put_signed_pixels_clamped_c(const DCTELEM *block,
  564. uint8_t *restrict pixels,
  565. int line_size)
  566. {
  567. int i, j;
  568. for (i = 0; i < 8; i++) {
  569. for (j = 0; j < 8; j++) {
  570. if (*block < -128)
  571. *pixels = 0;
  572. else if (*block > 127)
  573. *pixels = 255;
  574. else
  575. *pixels = (uint8_t)(*block + 128);
  576. block++;
  577. pixels++;
  578. }
  579. pixels += (line_size - 8);
  580. }
  581. }
  582. static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  583. int line_size)
  584. {
  585. int i;
  586. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  587. /* read the pixels */
  588. for(i=0;i<8;i++) {
  589. pixels[0] = cm[pixels[0] + block[0]];
  590. pixels[1] = cm[pixels[1] + block[1]];
  591. pixels[2] = cm[pixels[2] + block[2]];
  592. pixels[3] = cm[pixels[3] + block[3]];
  593. pixels[4] = cm[pixels[4] + block[4]];
  594. pixels[5] = cm[pixels[5] + block[5]];
  595. pixels[6] = cm[pixels[6] + block[6]];
  596. pixels[7] = cm[pixels[7] + block[7]];
  597. pixels += line_size;
  598. block += 8;
  599. }
  600. }
  601. static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  602. int line_size)
  603. {
  604. int i;
  605. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  606. /* read the pixels */
  607. for(i=0;i<4;i++) {
  608. pixels[0] = cm[pixels[0] + block[0]];
  609. pixels[1] = cm[pixels[1] + block[1]];
  610. pixels[2] = cm[pixels[2] + block[2]];
  611. pixels[3] = cm[pixels[3] + block[3]];
  612. pixels += line_size;
  613. block += 8;
  614. }
  615. }
  616. static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  617. int line_size)
  618. {
  619. int i;
  620. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  621. /* read the pixels */
  622. for(i=0;i<2;i++) {
  623. pixels[0] = cm[pixels[0] + block[0]];
  624. pixels[1] = cm[pixels[1] + block[1]];
  625. pixels += line_size;
  626. block += 8;
  627. }
  628. }
  629. static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
  630. {
  631. int i;
  632. for(i=0;i<8;i++) {
  633. pixels[0] += block[0];
  634. pixels[1] += block[1];
  635. pixels[2] += block[2];
  636. pixels[3] += block[3];
  637. pixels[4] += block[4];
  638. pixels[5] += block[5];
  639. pixels[6] += block[6];
  640. pixels[7] += block[7];
  641. pixels += line_size;
  642. block += 8;
  643. }
  644. }
  645. static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
  646. {
  647. int i;
  648. for(i=0;i<4;i++) {
  649. pixels[0] += block[0];
  650. pixels[1] += block[1];
  651. pixels[2] += block[2];
  652. pixels[3] += block[3];
  653. pixels += line_size;
  654. block += 4;
  655. }
  656. }
  657. static int sum_abs_dctelem_c(DCTELEM *block)
  658. {
  659. int sum=0, i;
  660. for(i=0; i<64; i++)
  661. sum+= FFABS(block[i]);
  662. return sum;
  663. }
  664. #if 0
  665. #define PIXOP2(OPNAME, OP) \
  666. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  667. {\
  668. int i;\
  669. for(i=0; i<h; i++){\
  670. OP(*((uint64_t*)block), AV_RN64(pixels));\
  671. pixels+=line_size;\
  672. block +=line_size;\
  673. }\
  674. }\
  675. \
  676. static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  677. {\
  678. int i;\
  679. for(i=0; i<h; i++){\
  680. const uint64_t a= AV_RN64(pixels );\
  681. const uint64_t b= AV_RN64(pixels+1);\
  682. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  683. pixels+=line_size;\
  684. block +=line_size;\
  685. }\
  686. }\
  687. \
  688. static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  689. {\
  690. int i;\
  691. for(i=0; i<h; i++){\
  692. const uint64_t a= AV_RN64(pixels );\
  693. const uint64_t b= AV_RN64(pixels+1);\
  694. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  695. pixels+=line_size;\
  696. block +=line_size;\
  697. }\
  698. }\
  699. \
  700. static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  701. {\
  702. int i;\
  703. for(i=0; i<h; i++){\
  704. const uint64_t a= AV_RN64(pixels );\
  705. const uint64_t b= AV_RN64(pixels+line_size);\
  706. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  707. pixels+=line_size;\
  708. block +=line_size;\
  709. }\
  710. }\
  711. \
  712. static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  713. {\
  714. int i;\
  715. for(i=0; i<h; i++){\
  716. const uint64_t a= AV_RN64(pixels );\
  717. const uint64_t b= AV_RN64(pixels+line_size);\
  718. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  719. pixels+=line_size;\
  720. block +=line_size;\
  721. }\
  722. }\
  723. \
  724. static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  725. {\
  726. int i;\
  727. const uint64_t a= AV_RN64(pixels );\
  728. const uint64_t b= AV_RN64(pixels+1);\
  729. uint64_t l0= (a&0x0303030303030303ULL)\
  730. + (b&0x0303030303030303ULL)\
  731. + 0x0202020202020202ULL;\
  732. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  733. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  734. uint64_t l1,h1;\
  735. \
  736. pixels+=line_size;\
  737. for(i=0; i<h; i+=2){\
  738. uint64_t a= AV_RN64(pixels );\
  739. uint64_t b= AV_RN64(pixels+1);\
  740. l1= (a&0x0303030303030303ULL)\
  741. + (b&0x0303030303030303ULL);\
  742. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  743. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  744. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  745. pixels+=line_size;\
  746. block +=line_size;\
  747. a= AV_RN64(pixels );\
  748. b= AV_RN64(pixels+1);\
  749. l0= (a&0x0303030303030303ULL)\
  750. + (b&0x0303030303030303ULL)\
  751. + 0x0202020202020202ULL;\
  752. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  753. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  754. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  755. pixels+=line_size;\
  756. block +=line_size;\
  757. }\
  758. }\
  759. \
  760. static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  761. {\
  762. int i;\
  763. const uint64_t a= AV_RN64(pixels );\
  764. const uint64_t b= AV_RN64(pixels+1);\
  765. uint64_t l0= (a&0x0303030303030303ULL)\
  766. + (b&0x0303030303030303ULL)\
  767. + 0x0101010101010101ULL;\
  768. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  769. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  770. uint64_t l1,h1;\
  771. \
  772. pixels+=line_size;\
  773. for(i=0; i<h; i+=2){\
  774. uint64_t a= AV_RN64(pixels );\
  775. uint64_t b= AV_RN64(pixels+1);\
  776. l1= (a&0x0303030303030303ULL)\
  777. + (b&0x0303030303030303ULL);\
  778. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  779. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  780. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  781. pixels+=line_size;\
  782. block +=line_size;\
  783. a= AV_RN64(pixels );\
  784. b= AV_RN64(pixels+1);\
  785. l0= (a&0x0303030303030303ULL)\
  786. + (b&0x0303030303030303ULL)\
  787. + 0x0101010101010101ULL;\
  788. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  789. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  790. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  791. pixels+=line_size;\
  792. block +=line_size;\
  793. }\
  794. }\
  795. \
  796. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
  797. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
  798. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
  799. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
  800. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
  801. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
  802. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
  803. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  804. #else // 64 bit variant
  805. #define PIXOP2(OPNAME, OP) \
  806. static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  807. int i;\
  808. for(i=0; i<h; i++){\
  809. OP(*((uint16_t*)(block )), AV_RN16(pixels ));\
  810. pixels+=line_size;\
  811. block +=line_size;\
  812. }\
  813. }\
  814. static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  815. int i;\
  816. for(i=0; i<h; i++){\
  817. OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
  818. pixels+=line_size;\
  819. block +=line_size;\
  820. }\
  821. }\
  822. static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  823. int i;\
  824. for(i=0; i<h; i++){\
  825. OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
  826. OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\
  827. pixels+=line_size;\
  828. block +=line_size;\
  829. }\
  830. }\
  831. static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  832. OPNAME ## _pixels8_c(block, pixels, line_size, h);\
  833. }\
  834. \
  835. static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  836. int src_stride1, int src_stride2, int h){\
  837. int i;\
  838. for(i=0; i<h; i++){\
  839. uint32_t a,b;\
  840. a= AV_RN32(&src1[i*src_stride1 ]);\
  841. b= AV_RN32(&src2[i*src_stride2 ]);\
  842. OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
  843. a= AV_RN32(&src1[i*src_stride1+4]);\
  844. b= AV_RN32(&src2[i*src_stride2+4]);\
  845. OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
  846. }\
  847. }\
  848. \
  849. static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  850. int src_stride1, int src_stride2, int h){\
  851. int i;\
  852. for(i=0; i<h; i++){\
  853. uint32_t a,b;\
  854. a= AV_RN32(&src1[i*src_stride1 ]);\
  855. b= AV_RN32(&src2[i*src_stride2 ]);\
  856. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  857. a= AV_RN32(&src1[i*src_stride1+4]);\
  858. b= AV_RN32(&src2[i*src_stride2+4]);\
  859. OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
  860. }\
  861. }\
  862. \
  863. static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  864. int src_stride1, int src_stride2, int h){\
  865. int i;\
  866. for(i=0; i<h; i++){\
  867. uint32_t a,b;\
  868. a= AV_RN32(&src1[i*src_stride1 ]);\
  869. b= AV_RN32(&src2[i*src_stride2 ]);\
  870. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  871. }\
  872. }\
  873. \
  874. static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  875. int src_stride1, int src_stride2, int h){\
  876. int i;\
  877. for(i=0; i<h; i++){\
  878. uint32_t a,b;\
  879. a= AV_RN16(&src1[i*src_stride1 ]);\
  880. b= AV_RN16(&src2[i*src_stride2 ]);\
  881. OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  882. }\
  883. }\
  884. \
  885. static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  886. int src_stride1, int src_stride2, int h){\
  887. OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  888. OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  889. }\
  890. \
  891. static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  892. int src_stride1, int src_stride2, int h){\
  893. OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  894. OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  895. }\
  896. \
  897. static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  898. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  899. }\
  900. \
  901. static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  902. OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  903. }\
  904. \
  905. static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  906. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  907. }\
  908. \
  909. static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  910. OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  911. }\
  912. \
  913. static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  914. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  915. int i;\
  916. for(i=0; i<h; i++){\
  917. uint32_t a, b, c, d, l0, l1, h0, h1;\
  918. a= AV_RN32(&src1[i*src_stride1]);\
  919. b= AV_RN32(&src2[i*src_stride2]);\
  920. c= AV_RN32(&src3[i*src_stride3]);\
  921. d= AV_RN32(&src4[i*src_stride4]);\
  922. l0= (a&0x03030303UL)\
  923. + (b&0x03030303UL)\
  924. + 0x02020202UL;\
  925. h0= ((a&0xFCFCFCFCUL)>>2)\
  926. + ((b&0xFCFCFCFCUL)>>2);\
  927. l1= (c&0x03030303UL)\
  928. + (d&0x03030303UL);\
  929. h1= ((c&0xFCFCFCFCUL)>>2)\
  930. + ((d&0xFCFCFCFCUL)>>2);\
  931. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  932. a= AV_RN32(&src1[i*src_stride1+4]);\
  933. b= AV_RN32(&src2[i*src_stride2+4]);\
  934. c= AV_RN32(&src3[i*src_stride3+4]);\
  935. d= AV_RN32(&src4[i*src_stride4+4]);\
  936. l0= (a&0x03030303UL)\
  937. + (b&0x03030303UL)\
  938. + 0x02020202UL;\
  939. h0= ((a&0xFCFCFCFCUL)>>2)\
  940. + ((b&0xFCFCFCFCUL)>>2);\
  941. l1= (c&0x03030303UL)\
  942. + (d&0x03030303UL);\
  943. h1= ((c&0xFCFCFCFCUL)>>2)\
  944. + ((d&0xFCFCFCFCUL)>>2);\
  945. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  946. }\
  947. }\
  948. \
  949. static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  950. OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  951. }\
  952. \
  953. static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  954. OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  955. }\
  956. \
  957. static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  958. OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  959. }\
  960. \
  961. static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  962. OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  963. }\
  964. \
  965. static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  966. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  967. int i;\
  968. for(i=0; i<h; i++){\
  969. uint32_t a, b, c, d, l0, l1, h0, h1;\
  970. a= AV_RN32(&src1[i*src_stride1]);\
  971. b= AV_RN32(&src2[i*src_stride2]);\
  972. c= AV_RN32(&src3[i*src_stride3]);\
  973. d= AV_RN32(&src4[i*src_stride4]);\
  974. l0= (a&0x03030303UL)\
  975. + (b&0x03030303UL)\
  976. + 0x01010101UL;\
  977. h0= ((a&0xFCFCFCFCUL)>>2)\
  978. + ((b&0xFCFCFCFCUL)>>2);\
  979. l1= (c&0x03030303UL)\
  980. + (d&0x03030303UL);\
  981. h1= ((c&0xFCFCFCFCUL)>>2)\
  982. + ((d&0xFCFCFCFCUL)>>2);\
  983. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  984. a= AV_RN32(&src1[i*src_stride1+4]);\
  985. b= AV_RN32(&src2[i*src_stride2+4]);\
  986. c= AV_RN32(&src3[i*src_stride3+4]);\
  987. d= AV_RN32(&src4[i*src_stride4+4]);\
  988. l0= (a&0x03030303UL)\
  989. + (b&0x03030303UL)\
  990. + 0x01010101UL;\
  991. h0= ((a&0xFCFCFCFCUL)>>2)\
  992. + ((b&0xFCFCFCFCUL)>>2);\
  993. l1= (c&0x03030303UL)\
  994. + (d&0x03030303UL);\
  995. h1= ((c&0xFCFCFCFCUL)>>2)\
  996. + ((d&0xFCFCFCFCUL)>>2);\
  997. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  998. }\
  999. }\
  1000. static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  1001. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  1002. OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  1003. OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  1004. }\
  1005. static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  1006. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  1007. OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  1008. OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  1009. }\
  1010. \
  1011. static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1012. {\
  1013. int i, a0, b0, a1, b1;\
  1014. a0= pixels[0];\
  1015. b0= pixels[1] + 2;\
  1016. a0 += b0;\
  1017. b0 += pixels[2];\
  1018. \
  1019. pixels+=line_size;\
  1020. for(i=0; i<h; i+=2){\
  1021. a1= pixels[0];\
  1022. b1= pixels[1];\
  1023. a1 += b1;\
  1024. b1 += pixels[2];\
  1025. \
  1026. block[0]= (a1+a0)>>2; /* FIXME non put */\
  1027. block[1]= (b1+b0)>>2;\
  1028. \
  1029. pixels+=line_size;\
  1030. block +=line_size;\
  1031. \
  1032. a0= pixels[0];\
  1033. b0= pixels[1] + 2;\
  1034. a0 += b0;\
  1035. b0 += pixels[2];\
  1036. \
  1037. block[0]= (a1+a0)>>2;\
  1038. block[1]= (b1+b0)>>2;\
  1039. pixels+=line_size;\
  1040. block +=line_size;\
  1041. }\
  1042. }\
  1043. \
  1044. static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1045. {\
  1046. int i;\
  1047. const uint32_t a= AV_RN32(pixels );\
  1048. const uint32_t b= AV_RN32(pixels+1);\
  1049. uint32_t l0= (a&0x03030303UL)\
  1050. + (b&0x03030303UL)\
  1051. + 0x02020202UL;\
  1052. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  1053. + ((b&0xFCFCFCFCUL)>>2);\
  1054. uint32_t l1,h1;\
  1055. \
  1056. pixels+=line_size;\
  1057. for(i=0; i<h; i+=2){\
  1058. uint32_t a= AV_RN32(pixels );\
  1059. uint32_t b= AV_RN32(pixels+1);\
  1060. l1= (a&0x03030303UL)\
  1061. + (b&0x03030303UL);\
  1062. h1= ((a&0xFCFCFCFCUL)>>2)\
  1063. + ((b&0xFCFCFCFCUL)>>2);\
  1064. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1065. pixels+=line_size;\
  1066. block +=line_size;\
  1067. a= AV_RN32(pixels );\
  1068. b= AV_RN32(pixels+1);\
  1069. l0= (a&0x03030303UL)\
  1070. + (b&0x03030303UL)\
  1071. + 0x02020202UL;\
  1072. h0= ((a&0xFCFCFCFCUL)>>2)\
  1073. + ((b&0xFCFCFCFCUL)>>2);\
  1074. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1075. pixels+=line_size;\
  1076. block +=line_size;\
  1077. }\
  1078. }\
  1079. \
  1080. static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1081. {\
  1082. int j;\
  1083. for(j=0; j<2; j++){\
  1084. int i;\
  1085. const uint32_t a= AV_RN32(pixels );\
  1086. const uint32_t b= AV_RN32(pixels+1);\
  1087. uint32_t l0= (a&0x03030303UL)\
  1088. + (b&0x03030303UL)\
  1089. + 0x02020202UL;\
  1090. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  1091. + ((b&0xFCFCFCFCUL)>>2);\
  1092. uint32_t l1,h1;\
  1093. \
  1094. pixels+=line_size;\
  1095. for(i=0; i<h; i+=2){\
  1096. uint32_t a= AV_RN32(pixels );\
  1097. uint32_t b= AV_RN32(pixels+1);\
  1098. l1= (a&0x03030303UL)\
  1099. + (b&0x03030303UL);\
  1100. h1= ((a&0xFCFCFCFCUL)>>2)\
  1101. + ((b&0xFCFCFCFCUL)>>2);\
  1102. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1103. pixels+=line_size;\
  1104. block +=line_size;\
  1105. a= AV_RN32(pixels );\
  1106. b= AV_RN32(pixels+1);\
  1107. l0= (a&0x03030303UL)\
  1108. + (b&0x03030303UL)\
  1109. + 0x02020202UL;\
  1110. h0= ((a&0xFCFCFCFCUL)>>2)\
  1111. + ((b&0xFCFCFCFCUL)>>2);\
  1112. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1113. pixels+=line_size;\
  1114. block +=line_size;\
  1115. }\
  1116. pixels+=4-line_size*(h+1);\
  1117. block +=4-line_size*h;\
  1118. }\
  1119. }\
  1120. \
  1121. static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1122. {\
  1123. int j;\
  1124. for(j=0; j<2; j++){\
  1125. int i;\
  1126. const uint32_t a= AV_RN32(pixels );\
  1127. const uint32_t b= AV_RN32(pixels+1);\
  1128. uint32_t l0= (a&0x03030303UL)\
  1129. + (b&0x03030303UL)\
  1130. + 0x01010101UL;\
  1131. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  1132. + ((b&0xFCFCFCFCUL)>>2);\
  1133. uint32_t l1,h1;\
  1134. \
  1135. pixels+=line_size;\
  1136. for(i=0; i<h; i+=2){\
  1137. uint32_t a= AV_RN32(pixels );\
  1138. uint32_t b= AV_RN32(pixels+1);\
  1139. l1= (a&0x03030303UL)\
  1140. + (b&0x03030303UL);\
  1141. h1= ((a&0xFCFCFCFCUL)>>2)\
  1142. + ((b&0xFCFCFCFCUL)>>2);\
  1143. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1144. pixels+=line_size;\
  1145. block +=line_size;\
  1146. a= AV_RN32(pixels );\
  1147. b= AV_RN32(pixels+1);\
  1148. l0= (a&0x03030303UL)\
  1149. + (b&0x03030303UL)\
  1150. + 0x01010101UL;\
  1151. h0= ((a&0xFCFCFCFCUL)>>2)\
  1152. + ((b&0xFCFCFCFCUL)>>2);\
  1153. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1154. pixels+=line_size;\
  1155. block +=line_size;\
  1156. }\
  1157. pixels+=4-line_size*(h+1);\
  1158. block +=4-line_size*h;\
  1159. }\
  1160. }\
  1161. \
  1162. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
  1163. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
  1164. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
  1165. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
  1166. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
  1167. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
  1168. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
  1169. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
  1170. #define op_avg(a, b) a = rnd_avg32(a, b)
  1171. #endif
  1172. #define op_put(a, b) a = b
  1173. PIXOP2(avg, op_avg)
  1174. PIXOP2(put, op_put)
  1175. #undef op_avg
  1176. #undef op_put
  1177. #define avg2(a,b) ((a+b+1)>>1)
  1178. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  1179. static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1180. put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
  1181. }
  1182. static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1183. put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
  1184. }
  1185. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  1186. {
  1187. const int A=(16-x16)*(16-y16);
  1188. const int B=( x16)*(16-y16);
  1189. const int C=(16-x16)*( y16);
  1190. const int D=( x16)*( y16);
  1191. int i;
  1192. for(i=0; i<h; i++)
  1193. {
  1194. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  1195. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  1196. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  1197. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  1198. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  1199. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  1200. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  1201. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  1202. dst+= stride;
  1203. src+= stride;
  1204. }
  1205. }
  1206. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1207. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1208. {
  1209. int y, vx, vy;
  1210. const int s= 1<<shift;
  1211. width--;
  1212. height--;
  1213. for(y=0; y<h; y++){
  1214. int x;
  1215. vx= ox;
  1216. vy= oy;
  1217. for(x=0; x<8; x++){ //XXX FIXME optimize
  1218. int src_x, src_y, frac_x, frac_y, index;
  1219. src_x= vx>>16;
  1220. src_y= vy>>16;
  1221. frac_x= src_x&(s-1);
  1222. frac_y= src_y&(s-1);
  1223. src_x>>=shift;
  1224. src_y>>=shift;
  1225. if((unsigned)src_x < width){
  1226. if((unsigned)src_y < height){
  1227. index= src_x + src_y*stride;
  1228. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1229. + src[index +1]* frac_x )*(s-frac_y)
  1230. + ( src[index+stride ]*(s-frac_x)
  1231. + src[index+stride+1]* frac_x )* frac_y
  1232. + r)>>(shift*2);
  1233. }else{
  1234. index= src_x + av_clip(src_y, 0, height)*stride;
  1235. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1236. + src[index +1]* frac_x )*s
  1237. + r)>>(shift*2);
  1238. }
  1239. }else{
  1240. if((unsigned)src_y < height){
  1241. index= av_clip(src_x, 0, width) + src_y*stride;
  1242. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  1243. + src[index+stride ]* frac_y )*s
  1244. + r)>>(shift*2);
  1245. }else{
  1246. index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
  1247. dst[y*stride + x]= src[index ];
  1248. }
  1249. }
  1250. vx+= dxx;
  1251. vy+= dyx;
  1252. }
  1253. ox += dxy;
  1254. oy += dyy;
  1255. }
  1256. }
  1257. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1258. switch(width){
  1259. case 2: put_pixels2_c (dst, src, stride, height); break;
  1260. case 4: put_pixels4_c (dst, src, stride, height); break;
  1261. case 8: put_pixels8_c (dst, src, stride, height); break;
  1262. case 16:put_pixels16_c(dst, src, stride, height); break;
  1263. }
  1264. }
  1265. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1266. int i,j;
  1267. for (i=0; i < height; i++) {
  1268. for (j=0; j < width; j++) {
  1269. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  1270. }
  1271. src += stride;
  1272. dst += stride;
  1273. }
  1274. }
  1275. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1276. int i,j;
  1277. for (i=0; i < height; i++) {
  1278. for (j=0; j < width; j++) {
  1279. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  1280. }
  1281. src += stride;
  1282. dst += stride;
  1283. }
  1284. }
  1285. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1286. int i,j;
  1287. for (i=0; i < height; i++) {
  1288. for (j=0; j < width; j++) {
  1289. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  1290. }
  1291. src += stride;
  1292. dst += stride;
  1293. }
  1294. }
  1295. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1296. int i,j;
  1297. for (i=0; i < height; i++) {
  1298. for (j=0; j < width; j++) {
  1299. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  1300. }
  1301. src += stride;
  1302. dst += stride;
  1303. }
  1304. }
  1305. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1306. int i,j;
  1307. for (i=0; i < height; i++) {
  1308. for (j=0; j < width; j++) {
  1309. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1310. }
  1311. src += stride;
  1312. dst += stride;
  1313. }
  1314. }
  1315. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1316. int i,j;
  1317. for (i=0; i < height; i++) {
  1318. for (j=0; j < width; j++) {
  1319. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  1320. }
  1321. src += stride;
  1322. dst += stride;
  1323. }
  1324. }
  1325. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1326. int i,j;
  1327. for (i=0; i < height; i++) {
  1328. for (j=0; j < width; j++) {
  1329. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1330. }
  1331. src += stride;
  1332. dst += stride;
  1333. }
  1334. }
  1335. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1336. int i,j;
  1337. for (i=0; i < height; i++) {
  1338. for (j=0; j < width; j++) {
  1339. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  1340. }
  1341. src += stride;
  1342. dst += stride;
  1343. }
  1344. }
  1345. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1346. switch(width){
  1347. case 2: avg_pixels2_c (dst, src, stride, height); break;
  1348. case 4: avg_pixels4_c (dst, src, stride, height); break;
  1349. case 8: avg_pixels8_c (dst, src, stride, height); break;
  1350. case 16:avg_pixels16_c(dst, src, stride, height); break;
  1351. }
  1352. }
  1353. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1354. int i,j;
  1355. for (i=0; i < height; i++) {
  1356. for (j=0; j < width; j++) {
  1357. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  1358. }
  1359. src += stride;
  1360. dst += stride;
  1361. }
  1362. }
  1363. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1364. int i,j;
  1365. for (i=0; i < height; i++) {
  1366. for (j=0; j < width; j++) {
  1367. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  1368. }
  1369. src += stride;
  1370. dst += stride;
  1371. }
  1372. }
  1373. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1374. int i,j;
  1375. for (i=0; i < height; i++) {
  1376. for (j=0; j < width; j++) {
  1377. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  1378. }
  1379. src += stride;
  1380. dst += stride;
  1381. }
  1382. }
  1383. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1384. int i,j;
  1385. for (i=0; i < height; i++) {
  1386. for (j=0; j < width; j++) {
  1387. 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;
  1388. }
  1389. src += stride;
  1390. dst += stride;
  1391. }
  1392. }
  1393. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1394. int i,j;
  1395. for (i=0; i < height; i++) {
  1396. for (j=0; j < width; j++) {
  1397. 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;
  1398. }
  1399. src += stride;
  1400. dst += stride;
  1401. }
  1402. }
  1403. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1404. int i,j;
  1405. for (i=0; i < height; i++) {
  1406. for (j=0; j < width; j++) {
  1407. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  1408. }
  1409. src += stride;
  1410. dst += stride;
  1411. }
  1412. }
  1413. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1414. int i,j;
  1415. for (i=0; i < height; i++) {
  1416. for (j=0; j < width; j++) {
  1417. 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;
  1418. }
  1419. src += stride;
  1420. dst += stride;
  1421. }
  1422. }
  1423. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1424. int i,j;
  1425. for (i=0; i < height; i++) {
  1426. for (j=0; j < width; j++) {
  1427. 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;
  1428. }
  1429. src += stride;
  1430. dst += stride;
  1431. }
  1432. }
  1433. #if 0
  1434. #define TPEL_WIDTH(width)\
  1435. static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1436. void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
  1437. static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1438. void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
  1439. static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1440. void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
  1441. static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1442. void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
  1443. static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1444. void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
  1445. static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1446. void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
  1447. static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1448. void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
  1449. static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1450. void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
  1451. static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1452. void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
  1453. #endif
  1454. #define H264_CHROMA_MC(OPNAME, OP)\
  1455. static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1456. const int A=(8-x)*(8-y);\
  1457. const int B=( x)*(8-y);\
  1458. const int C=(8-x)*( y);\
  1459. const int D=( x)*( y);\
  1460. int i;\
  1461. \
  1462. assert(x<8 && y<8 && x>=0 && y>=0);\
  1463. \
  1464. if(D){\
  1465. for(i=0; i<h; i++){\
  1466. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1467. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1468. dst+= stride;\
  1469. src+= stride;\
  1470. }\
  1471. }else{\
  1472. const int E= B+C;\
  1473. const int step= C ? stride : 1;\
  1474. for(i=0; i<h; i++){\
  1475. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1476. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1477. dst+= stride;\
  1478. src+= stride;\
  1479. }\
  1480. }\
  1481. }\
  1482. \
  1483. static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1484. const int A=(8-x)*(8-y);\
  1485. const int B=( x)*(8-y);\
  1486. const int C=(8-x)*( y);\
  1487. const int D=( x)*( y);\
  1488. int i;\
  1489. \
  1490. assert(x<8 && y<8 && x>=0 && y>=0);\
  1491. \
  1492. if(D){\
  1493. for(i=0; i<h; i++){\
  1494. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1495. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1496. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1497. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1498. dst+= stride;\
  1499. src+= stride;\
  1500. }\
  1501. }else{\
  1502. const int E= B+C;\
  1503. const int step= C ? stride : 1;\
  1504. for(i=0; i<h; i++){\
  1505. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1506. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1507. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1508. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1509. dst+= stride;\
  1510. src+= stride;\
  1511. }\
  1512. }\
  1513. }\
  1514. \
  1515. static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1516. const int A=(8-x)*(8-y);\
  1517. const int B=( x)*(8-y);\
  1518. const int C=(8-x)*( y);\
  1519. const int D=( x)*( y);\
  1520. int i;\
  1521. \
  1522. assert(x<8 && y<8 && x>=0 && y>=0);\
  1523. \
  1524. if(D){\
  1525. for(i=0; i<h; i++){\
  1526. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1527. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1528. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1529. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1530. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  1531. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  1532. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  1533. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  1534. dst+= stride;\
  1535. src+= stride;\
  1536. }\
  1537. }else{\
  1538. const int E= B+C;\
  1539. const int step= C ? stride : 1;\
  1540. for(i=0; i<h; i++){\
  1541. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1542. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1543. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1544. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1545. OP(dst[4], (A*src[4] + E*src[step+4]));\
  1546. OP(dst[5], (A*src[5] + E*src[step+5]));\
  1547. OP(dst[6], (A*src[6] + E*src[step+6]));\
  1548. OP(dst[7], (A*src[7] + E*src[step+7]));\
  1549. dst+= stride;\
  1550. src+= stride;\
  1551. }\
  1552. }\
  1553. }
  1554. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  1555. #define op_put(a, b) a = (((b) + 32)>>6)
  1556. H264_CHROMA_MC(put_ , op_put)
  1557. H264_CHROMA_MC(avg_ , op_avg)
  1558. #undef op_avg
  1559. #undef op_put
  1560. static void put_no_rnd_h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
  1561. const int A=(8-x)*(8-y);
  1562. const int B=( x)*(8-y);
  1563. const int C=(8-x)*( y);
  1564. const int D=( x)*( y);
  1565. int i;
  1566. assert(x<8 && y<8 && x>=0 && y>=0);
  1567. for(i=0; i<h; i++)
  1568. {
  1569. dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
  1570. dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
  1571. dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
  1572. dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
  1573. dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
  1574. dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
  1575. dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
  1576. dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
  1577. dst+= stride;
  1578. src+= stride;
  1579. }
  1580. }
  1581. #define QPEL_MC(r, OPNAME, RND, OP) \
  1582. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1583. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1584. int i;\
  1585. for(i=0; i<h; i++)\
  1586. {\
  1587. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1588. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1589. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1590. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1591. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1592. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1593. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1594. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1595. dst+=dstStride;\
  1596. src+=srcStride;\
  1597. }\
  1598. }\
  1599. \
  1600. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1601. const int w=8;\
  1602. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1603. int i;\
  1604. for(i=0; i<w; i++)\
  1605. {\
  1606. const int src0= src[0*srcStride];\
  1607. const int src1= src[1*srcStride];\
  1608. const int src2= src[2*srcStride];\
  1609. const int src3= src[3*srcStride];\
  1610. const int src4= src[4*srcStride];\
  1611. const int src5= src[5*srcStride];\
  1612. const int src6= src[6*srcStride];\
  1613. const int src7= src[7*srcStride];\
  1614. const int src8= src[8*srcStride];\
  1615. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1616. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1617. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1618. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1619. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1620. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1621. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1622. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1623. dst++;\
  1624. src++;\
  1625. }\
  1626. }\
  1627. \
  1628. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1629. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1630. int i;\
  1631. \
  1632. for(i=0; i<h; i++)\
  1633. {\
  1634. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1635. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1636. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1637. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1638. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1639. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1640. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1641. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1642. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1643. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1644. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1645. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1646. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1647. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1648. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1649. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1650. dst+=dstStride;\
  1651. src+=srcStride;\
  1652. }\
  1653. }\
  1654. \
  1655. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1656. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1657. int i;\
  1658. const int w=16;\
  1659. for(i=0; i<w; i++)\
  1660. {\
  1661. const int src0= src[0*srcStride];\
  1662. const int src1= src[1*srcStride];\
  1663. const int src2= src[2*srcStride];\
  1664. const int src3= src[3*srcStride];\
  1665. const int src4= src[4*srcStride];\
  1666. const int src5= src[5*srcStride];\
  1667. const int src6= src[6*srcStride];\
  1668. const int src7= src[7*srcStride];\
  1669. const int src8= src[8*srcStride];\
  1670. const int src9= src[9*srcStride];\
  1671. const int src10= src[10*srcStride];\
  1672. const int src11= src[11*srcStride];\
  1673. const int src12= src[12*srcStride];\
  1674. const int src13= src[13*srcStride];\
  1675. const int src14= src[14*srcStride];\
  1676. const int src15= src[15*srcStride];\
  1677. const int src16= src[16*srcStride];\
  1678. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1679. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1680. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1681. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1682. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1683. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1684. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1685. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1686. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1687. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1688. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1689. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1690. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1691. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1692. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1693. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1694. dst++;\
  1695. src++;\
  1696. }\
  1697. }\
  1698. \
  1699. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1700. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1701. }\
  1702. \
  1703. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1704. uint8_t half[64];\
  1705. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1706. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1707. }\
  1708. \
  1709. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1710. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1711. }\
  1712. \
  1713. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1714. uint8_t half[64];\
  1715. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1716. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1717. }\
  1718. \
  1719. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1720. uint8_t full[16*9];\
  1721. uint8_t half[64];\
  1722. copy_block9(full, src, 16, stride, 9);\
  1723. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1724. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1725. }\
  1726. \
  1727. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1728. uint8_t full[16*9];\
  1729. copy_block9(full, src, 16, stride, 9);\
  1730. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1731. }\
  1732. \
  1733. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1734. uint8_t full[16*9];\
  1735. uint8_t half[64];\
  1736. copy_block9(full, src, 16, stride, 9);\
  1737. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1738. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1739. }\
  1740. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1741. uint8_t full[16*9];\
  1742. uint8_t halfH[72];\
  1743. uint8_t halfV[64];\
  1744. uint8_t halfHV[64];\
  1745. copy_block9(full, src, 16, stride, 9);\
  1746. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1747. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1748. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1749. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1750. }\
  1751. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1752. uint8_t full[16*9];\
  1753. uint8_t halfH[72];\
  1754. uint8_t halfHV[64];\
  1755. copy_block9(full, src, 16, stride, 9);\
  1756. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1757. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1758. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1759. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1760. }\
  1761. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1762. uint8_t full[16*9];\
  1763. uint8_t halfH[72];\
  1764. uint8_t halfV[64];\
  1765. uint8_t halfHV[64];\
  1766. copy_block9(full, src, 16, stride, 9);\
  1767. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1768. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1769. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1770. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1771. }\
  1772. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1773. uint8_t full[16*9];\
  1774. uint8_t halfH[72];\
  1775. uint8_t halfHV[64];\
  1776. copy_block9(full, src, 16, stride, 9);\
  1777. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1778. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1779. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1780. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1781. }\
  1782. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1783. uint8_t full[16*9];\
  1784. uint8_t halfH[72];\
  1785. uint8_t halfV[64];\
  1786. uint8_t halfHV[64];\
  1787. copy_block9(full, src, 16, stride, 9);\
  1788. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1789. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1790. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1791. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1792. }\
  1793. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1794. uint8_t full[16*9];\
  1795. uint8_t halfH[72];\
  1796. uint8_t halfHV[64];\
  1797. copy_block9(full, src, 16, stride, 9);\
  1798. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1799. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1800. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1801. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1802. }\
  1803. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1804. uint8_t full[16*9];\
  1805. uint8_t halfH[72];\
  1806. uint8_t halfV[64];\
  1807. uint8_t halfHV[64];\
  1808. copy_block9(full, src, 16, stride, 9);\
  1809. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1810. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1811. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1812. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1813. }\
  1814. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1815. uint8_t full[16*9];\
  1816. uint8_t halfH[72];\
  1817. uint8_t halfHV[64];\
  1818. copy_block9(full, src, 16, stride, 9);\
  1819. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1820. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1821. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1822. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1823. }\
  1824. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1825. uint8_t halfH[72];\
  1826. uint8_t halfHV[64];\
  1827. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1828. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1829. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1830. }\
  1831. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1832. uint8_t halfH[72];\
  1833. uint8_t halfHV[64];\
  1834. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1835. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1836. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1837. }\
  1838. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1839. uint8_t full[16*9];\
  1840. uint8_t halfH[72];\
  1841. uint8_t halfV[64];\
  1842. uint8_t halfHV[64];\
  1843. copy_block9(full, src, 16, stride, 9);\
  1844. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1845. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1846. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1847. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1848. }\
  1849. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1850. uint8_t full[16*9];\
  1851. uint8_t halfH[72];\
  1852. copy_block9(full, src, 16, stride, 9);\
  1853. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1854. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1855. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1856. }\
  1857. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1858. uint8_t full[16*9];\
  1859. uint8_t halfH[72];\
  1860. uint8_t halfV[64];\
  1861. uint8_t halfHV[64];\
  1862. copy_block9(full, src, 16, stride, 9);\
  1863. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1864. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1865. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1866. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1867. }\
  1868. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1869. uint8_t full[16*9];\
  1870. uint8_t halfH[72];\
  1871. copy_block9(full, src, 16, stride, 9);\
  1872. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1873. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1874. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1875. }\
  1876. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1877. uint8_t halfH[72];\
  1878. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1879. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1880. }\
  1881. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1882. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1883. }\
  1884. \
  1885. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1886. uint8_t half[256];\
  1887. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1888. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1889. }\
  1890. \
  1891. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1892. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1893. }\
  1894. \
  1895. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1896. uint8_t half[256];\
  1897. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1898. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1899. }\
  1900. \
  1901. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1902. uint8_t full[24*17];\
  1903. uint8_t half[256];\
  1904. copy_block17(full, src, 24, stride, 17);\
  1905. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1906. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1907. }\
  1908. \
  1909. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1910. uint8_t full[24*17];\
  1911. copy_block17(full, src, 24, stride, 17);\
  1912. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1913. }\
  1914. \
  1915. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1916. uint8_t full[24*17];\
  1917. uint8_t half[256];\
  1918. copy_block17(full, src, 24, stride, 17);\
  1919. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1920. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1921. }\
  1922. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1923. uint8_t full[24*17];\
  1924. uint8_t halfH[272];\
  1925. uint8_t halfV[256];\
  1926. uint8_t halfHV[256];\
  1927. copy_block17(full, src, 24, stride, 17);\
  1928. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1929. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1930. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1931. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1932. }\
  1933. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1934. uint8_t full[24*17];\
  1935. uint8_t halfH[272];\
  1936. uint8_t halfHV[256];\
  1937. copy_block17(full, src, 24, stride, 17);\
  1938. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1939. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1940. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1941. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1942. }\
  1943. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1944. uint8_t full[24*17];\
  1945. uint8_t halfH[272];\
  1946. uint8_t halfV[256];\
  1947. uint8_t halfHV[256];\
  1948. copy_block17(full, src, 24, stride, 17);\
  1949. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1950. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1951. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1952. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1953. }\
  1954. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1955. uint8_t full[24*17];\
  1956. uint8_t halfH[272];\
  1957. uint8_t halfHV[256];\
  1958. copy_block17(full, src, 24, stride, 17);\
  1959. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1960. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1961. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1962. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1963. }\
  1964. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1965. uint8_t full[24*17];\
  1966. uint8_t halfH[272];\
  1967. uint8_t halfV[256];\
  1968. uint8_t halfHV[256];\
  1969. copy_block17(full, src, 24, stride, 17);\
  1970. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1971. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1972. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1973. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1974. }\
  1975. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1976. uint8_t full[24*17];\
  1977. uint8_t halfH[272];\
  1978. uint8_t halfHV[256];\
  1979. copy_block17(full, src, 24, stride, 17);\
  1980. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1981. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1982. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1983. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1984. }\
  1985. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1986. uint8_t full[24*17];\
  1987. uint8_t halfH[272];\
  1988. uint8_t halfV[256];\
  1989. uint8_t halfHV[256];\
  1990. copy_block17(full, src, 24, stride, 17);\
  1991. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1992. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1993. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1994. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1995. }\
  1996. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1997. uint8_t full[24*17];\
  1998. uint8_t halfH[272];\
  1999. uint8_t halfHV[256];\
  2000. copy_block17(full, src, 24, stride, 17);\
  2001. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  2002. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  2003. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  2004. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  2005. }\
  2006. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2007. uint8_t halfH[272];\
  2008. uint8_t halfHV[256];\
  2009. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  2010. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  2011. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  2012. }\
  2013. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2014. uint8_t halfH[272];\
  2015. uint8_t halfHV[256];\
  2016. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  2017. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  2018. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  2019. }\
  2020. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  2021. uint8_t full[24*17];\
  2022. uint8_t halfH[272];\
  2023. uint8_t halfV[256];\
  2024. uint8_t halfHV[256];\
  2025. copy_block17(full, src, 24, stride, 17);\
  2026. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  2027. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  2028. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  2029. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  2030. }\
  2031. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2032. uint8_t full[24*17];\
  2033. uint8_t halfH[272];\
  2034. copy_block17(full, src, 24, stride, 17);\
  2035. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  2036. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  2037. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  2038. }\
  2039. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  2040. uint8_t full[24*17];\
  2041. uint8_t halfH[272];\
  2042. uint8_t halfV[256];\
  2043. uint8_t halfHV[256];\
  2044. copy_block17(full, src, 24, stride, 17);\
  2045. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  2046. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  2047. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  2048. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  2049. }\
  2050. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2051. uint8_t full[24*17];\
  2052. uint8_t halfH[272];\
  2053. copy_block17(full, src, 24, stride, 17);\
  2054. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  2055. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  2056. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  2057. }\
  2058. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2059. uint8_t halfH[272];\
  2060. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  2061. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  2062. }
  2063. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2064. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  2065. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2066. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  2067. QPEL_MC(0, put_ , _ , op_put)
  2068. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  2069. QPEL_MC(0, avg_ , _ , op_avg)
  2070. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  2071. #undef op_avg
  2072. #undef op_avg_no_rnd
  2073. #undef op_put
  2074. #undef op_put_no_rnd
  2075. #if 1
  2076. #define H264_LOWPASS(OPNAME, OP, OP2) \
  2077. static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2078. const int h=2;\
  2079. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2080. int i;\
  2081. for(i=0; i<h; i++)\
  2082. {\
  2083. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2084. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2085. dst+=dstStride;\
  2086. src+=srcStride;\
  2087. }\
  2088. }\
  2089. \
  2090. static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2091. const int w=2;\
  2092. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2093. int i;\
  2094. for(i=0; i<w; i++)\
  2095. {\
  2096. const int srcB= src[-2*srcStride];\
  2097. const int srcA= src[-1*srcStride];\
  2098. const int src0= src[0 *srcStride];\
  2099. const int src1= src[1 *srcStride];\
  2100. const int src2= src[2 *srcStride];\
  2101. const int src3= src[3 *srcStride];\
  2102. const int src4= src[4 *srcStride];\
  2103. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2104. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2105. dst++;\
  2106. src++;\
  2107. }\
  2108. }\
  2109. \
  2110. static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2111. const int h=2;\
  2112. const int w=2;\
  2113. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2114. int i;\
  2115. src -= 2*srcStride;\
  2116. for(i=0; i<h+5; i++)\
  2117. {\
  2118. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2119. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2120. tmp+=tmpStride;\
  2121. src+=srcStride;\
  2122. }\
  2123. tmp -= tmpStride*(h+5-2);\
  2124. for(i=0; i<w; i++)\
  2125. {\
  2126. const int tmpB= tmp[-2*tmpStride];\
  2127. const int tmpA= tmp[-1*tmpStride];\
  2128. const int tmp0= tmp[0 *tmpStride];\
  2129. const int tmp1= tmp[1 *tmpStride];\
  2130. const int tmp2= tmp[2 *tmpStride];\
  2131. const int tmp3= tmp[3 *tmpStride];\
  2132. const int tmp4= tmp[4 *tmpStride];\
  2133. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2134. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2135. dst++;\
  2136. tmp++;\
  2137. }\
  2138. }\
  2139. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2140. const int h=4;\
  2141. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2142. int i;\
  2143. for(i=0; i<h; i++)\
  2144. {\
  2145. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2146. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2147. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  2148. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  2149. dst+=dstStride;\
  2150. src+=srcStride;\
  2151. }\
  2152. }\
  2153. \
  2154. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2155. const int w=4;\
  2156. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2157. int i;\
  2158. for(i=0; i<w; i++)\
  2159. {\
  2160. const int srcB= src[-2*srcStride];\
  2161. const int srcA= src[-1*srcStride];\
  2162. const int src0= src[0 *srcStride];\
  2163. const int src1= src[1 *srcStride];\
  2164. const int src2= src[2 *srcStride];\
  2165. const int src3= src[3 *srcStride];\
  2166. const int src4= src[4 *srcStride];\
  2167. const int src5= src[5 *srcStride];\
  2168. const int src6= src[6 *srcStride];\
  2169. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2170. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2171. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2172. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2173. dst++;\
  2174. src++;\
  2175. }\
  2176. }\
  2177. \
  2178. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2179. const int h=4;\
  2180. const int w=4;\
  2181. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2182. int i;\
  2183. src -= 2*srcStride;\
  2184. for(i=0; i<h+5; i++)\
  2185. {\
  2186. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2187. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2188. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  2189. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  2190. tmp+=tmpStride;\
  2191. src+=srcStride;\
  2192. }\
  2193. tmp -= tmpStride*(h+5-2);\
  2194. for(i=0; i<w; i++)\
  2195. {\
  2196. const int tmpB= tmp[-2*tmpStride];\
  2197. const int tmpA= tmp[-1*tmpStride];\
  2198. const int tmp0= tmp[0 *tmpStride];\
  2199. const int tmp1= tmp[1 *tmpStride];\
  2200. const int tmp2= tmp[2 *tmpStride];\
  2201. const int tmp3= tmp[3 *tmpStride];\
  2202. const int tmp4= tmp[4 *tmpStride];\
  2203. const int tmp5= tmp[5 *tmpStride];\
  2204. const int tmp6= tmp[6 *tmpStride];\
  2205. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2206. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2207. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2208. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2209. dst++;\
  2210. tmp++;\
  2211. }\
  2212. }\
  2213. \
  2214. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2215. const int h=8;\
  2216. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2217. int i;\
  2218. for(i=0; i<h; i++)\
  2219. {\
  2220. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  2221. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  2222. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  2223. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  2224. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  2225. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  2226. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  2227. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  2228. dst+=dstStride;\
  2229. src+=srcStride;\
  2230. }\
  2231. }\
  2232. \
  2233. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2234. const int w=8;\
  2235. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2236. int i;\
  2237. for(i=0; i<w; i++)\
  2238. {\
  2239. const int srcB= src[-2*srcStride];\
  2240. const int srcA= src[-1*srcStride];\
  2241. const int src0= src[0 *srcStride];\
  2242. const int src1= src[1 *srcStride];\
  2243. const int src2= src[2 *srcStride];\
  2244. const int src3= src[3 *srcStride];\
  2245. const int src4= src[4 *srcStride];\
  2246. const int src5= src[5 *srcStride];\
  2247. const int src6= src[6 *srcStride];\
  2248. const int src7= src[7 *srcStride];\
  2249. const int src8= src[8 *srcStride];\
  2250. const int src9= src[9 *srcStride];\
  2251. const int src10=src[10*srcStride];\
  2252. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2253. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2254. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2255. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2256. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  2257. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  2258. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  2259. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  2260. dst++;\
  2261. src++;\
  2262. }\
  2263. }\
  2264. \
  2265. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2266. const int h=8;\
  2267. const int w=8;\
  2268. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2269. int i;\
  2270. src -= 2*srcStride;\
  2271. for(i=0; i<h+5; i++)\
  2272. {\
  2273. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  2274. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  2275. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  2276. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  2277. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  2278. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  2279. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  2280. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  2281. tmp+=tmpStride;\
  2282. src+=srcStride;\
  2283. }\
  2284. tmp -= tmpStride*(h+5-2);\
  2285. for(i=0; i<w; i++)\
  2286. {\
  2287. const int tmpB= tmp[-2*tmpStride];\
  2288. const int tmpA= tmp[-1*tmpStride];\
  2289. const int tmp0= tmp[0 *tmpStride];\
  2290. const int tmp1= tmp[1 *tmpStride];\
  2291. const int tmp2= tmp[2 *tmpStride];\
  2292. const int tmp3= tmp[3 *tmpStride];\
  2293. const int tmp4= tmp[4 *tmpStride];\
  2294. const int tmp5= tmp[5 *tmpStride];\
  2295. const int tmp6= tmp[6 *tmpStride];\
  2296. const int tmp7= tmp[7 *tmpStride];\
  2297. const int tmp8= tmp[8 *tmpStride];\
  2298. const int tmp9= tmp[9 *tmpStride];\
  2299. const int tmp10=tmp[10*tmpStride];\
  2300. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2301. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2302. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2303. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2304. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  2305. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  2306. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  2307. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  2308. dst++;\
  2309. tmp++;\
  2310. }\
  2311. }\
  2312. \
  2313. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2314. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2315. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2316. src += 8*srcStride;\
  2317. dst += 8*dstStride;\
  2318. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2319. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2320. }\
  2321. \
  2322. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2323. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2324. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2325. src += 8*srcStride;\
  2326. dst += 8*dstStride;\
  2327. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2328. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2329. }\
  2330. \
  2331. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2332. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2333. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2334. src += 8*srcStride;\
  2335. dst += 8*dstStride;\
  2336. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2337. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2338. }\
  2339. #define H264_MC(OPNAME, SIZE) \
  2340. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  2341. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  2342. }\
  2343. \
  2344. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  2345. uint8_t half[SIZE*SIZE];\
  2346. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2347. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  2348. }\
  2349. \
  2350. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  2351. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  2352. }\
  2353. \
  2354. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  2355. uint8_t half[SIZE*SIZE];\
  2356. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2357. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  2358. }\
  2359. \
  2360. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  2361. uint8_t full[SIZE*(SIZE+5)];\
  2362. uint8_t * const full_mid= full + SIZE*2;\
  2363. uint8_t half[SIZE*SIZE];\
  2364. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2365. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2366. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  2367. }\
  2368. \
  2369. static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  2370. uint8_t full[SIZE*(SIZE+5)];\
  2371. uint8_t * const full_mid= full + SIZE*2;\
  2372. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2373. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  2374. }\
  2375. \
  2376. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  2377. uint8_t full[SIZE*(SIZE+5)];\
  2378. uint8_t * const full_mid= full + SIZE*2;\
  2379. uint8_t half[SIZE*SIZE];\
  2380. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2381. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2382. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  2383. }\
  2384. \
  2385. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  2386. uint8_t full[SIZE*(SIZE+5)];\
  2387. uint8_t * const full_mid= full + SIZE*2;\
  2388. uint8_t halfH[SIZE*SIZE];\
  2389. uint8_t halfV[SIZE*SIZE];\
  2390. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2391. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2392. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2393. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2394. }\
  2395. \
  2396. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  2397. uint8_t full[SIZE*(SIZE+5)];\
  2398. uint8_t * const full_mid= full + SIZE*2;\
  2399. uint8_t halfH[SIZE*SIZE];\
  2400. uint8_t halfV[SIZE*SIZE];\
  2401. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2402. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2403. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2404. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2405. }\
  2406. \
  2407. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2408. uint8_t full[SIZE*(SIZE+5)];\
  2409. uint8_t * const full_mid= full + SIZE*2;\
  2410. uint8_t halfH[SIZE*SIZE];\
  2411. uint8_t halfV[SIZE*SIZE];\
  2412. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2413. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2414. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2415. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2416. }\
  2417. \
  2418. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2419. uint8_t full[SIZE*(SIZE+5)];\
  2420. uint8_t * const full_mid= full + SIZE*2;\
  2421. uint8_t halfH[SIZE*SIZE];\
  2422. uint8_t halfV[SIZE*SIZE];\
  2423. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2424. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2425. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2426. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2427. }\
  2428. \
  2429. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2430. int16_t tmp[SIZE*(SIZE+5)];\
  2431. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2432. }\
  2433. \
  2434. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2435. int16_t tmp[SIZE*(SIZE+5)];\
  2436. uint8_t halfH[SIZE*SIZE];\
  2437. uint8_t halfHV[SIZE*SIZE];\
  2438. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2439. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2440. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2441. }\
  2442. \
  2443. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2444. int16_t tmp[SIZE*(SIZE+5)];\
  2445. uint8_t halfH[SIZE*SIZE];\
  2446. uint8_t halfHV[SIZE*SIZE];\
  2447. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2448. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2449. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2450. }\
  2451. \
  2452. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2453. uint8_t full[SIZE*(SIZE+5)];\
  2454. uint8_t * const full_mid= full + SIZE*2;\
  2455. int16_t tmp[SIZE*(SIZE+5)];\
  2456. uint8_t halfV[SIZE*SIZE];\
  2457. uint8_t halfHV[SIZE*SIZE];\
  2458. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2459. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2460. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2461. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2462. }\
  2463. \
  2464. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2465. uint8_t full[SIZE*(SIZE+5)];\
  2466. uint8_t * const full_mid= full + SIZE*2;\
  2467. int16_t tmp[SIZE*(SIZE+5)];\
  2468. uint8_t halfV[SIZE*SIZE];\
  2469. uint8_t halfHV[SIZE*SIZE];\
  2470. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2471. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2472. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2473. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2474. }\
  2475. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2476. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2477. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2478. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2479. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2480. H264_LOWPASS(put_ , op_put, op2_put)
  2481. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2482. H264_MC(put_, 2)
  2483. H264_MC(put_, 4)
  2484. H264_MC(put_, 8)
  2485. H264_MC(put_, 16)
  2486. H264_MC(avg_, 4)
  2487. H264_MC(avg_, 8)
  2488. H264_MC(avg_, 16)
  2489. #undef op_avg
  2490. #undef op_put
  2491. #undef op2_avg
  2492. #undef op2_put
  2493. #endif
  2494. #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom )
  2495. #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
  2496. #define H264_WEIGHT(W,H) \
  2497. static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \
  2498. int y; \
  2499. offset <<= log2_denom; \
  2500. if(log2_denom) offset += 1<<(log2_denom-1); \
  2501. for(y=0; y<H; y++, block += stride){ \
  2502. op_scale1(0); \
  2503. op_scale1(1); \
  2504. if(W==2) continue; \
  2505. op_scale1(2); \
  2506. op_scale1(3); \
  2507. if(W==4) continue; \
  2508. op_scale1(4); \
  2509. op_scale1(5); \
  2510. op_scale1(6); \
  2511. op_scale1(7); \
  2512. if(W==8) continue; \
  2513. op_scale1(8); \
  2514. op_scale1(9); \
  2515. op_scale1(10); \
  2516. op_scale1(11); \
  2517. op_scale1(12); \
  2518. op_scale1(13); \
  2519. op_scale1(14); \
  2520. op_scale1(15); \
  2521. } \
  2522. } \
  2523. static void biweight_h264_pixels ## W ## x ## H ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
  2524. int y; \
  2525. offset = ((offset + 1) | 1) << log2_denom; \
  2526. for(y=0; y<H; y++, dst += stride, src += stride){ \
  2527. op_scale2(0); \
  2528. op_scale2(1); \
  2529. if(W==2) continue; \
  2530. op_scale2(2); \
  2531. op_scale2(3); \
  2532. if(W==4) continue; \
  2533. op_scale2(4); \
  2534. op_scale2(5); \
  2535. op_scale2(6); \
  2536. op_scale2(7); \
  2537. if(W==8) continue; \
  2538. op_scale2(8); \
  2539. op_scale2(9); \
  2540. op_scale2(10); \
  2541. op_scale2(11); \
  2542. op_scale2(12); \
  2543. op_scale2(13); \
  2544. op_scale2(14); \
  2545. op_scale2(15); \
  2546. } \
  2547. }
  2548. H264_WEIGHT(16,16)
  2549. H264_WEIGHT(16,8)
  2550. H264_WEIGHT(8,16)
  2551. H264_WEIGHT(8,8)
  2552. H264_WEIGHT(8,4)
  2553. H264_WEIGHT(4,8)
  2554. H264_WEIGHT(4,4)
  2555. H264_WEIGHT(4,2)
  2556. H264_WEIGHT(2,4)
  2557. H264_WEIGHT(2,2)
  2558. #undef op_scale1
  2559. #undef op_scale2
  2560. #undef H264_WEIGHT
  2561. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2562. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2563. int i;
  2564. for(i=0; i<h; i++){
  2565. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2566. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2567. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2568. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2569. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2570. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2571. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2572. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2573. dst+=dstStride;
  2574. src+=srcStride;
  2575. }
  2576. }
  2577. #if CONFIG_CAVS_DECODER
  2578. /* AVS specific */
  2579. void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
  2580. void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2581. put_pixels8_c(dst, src, stride, 8);
  2582. }
  2583. void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2584. avg_pixels8_c(dst, src, stride, 8);
  2585. }
  2586. void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2587. put_pixels16_c(dst, src, stride, 16);
  2588. }
  2589. void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2590. avg_pixels16_c(dst, src, stride, 16);
  2591. }
  2592. #endif /* CONFIG_CAVS_DECODER */
  2593. #if CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
  2594. /* VC-1 specific */
  2595. void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
  2596. void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) {
  2597. put_pixels8_c(dst, src, stride, 8);
  2598. }
  2599. #endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
  2600. void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
  2601. /* H264 specific */
  2602. void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx);
  2603. #if CONFIG_RV30_DECODER
  2604. void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
  2605. #endif /* CONFIG_RV30_DECODER */
  2606. #if CONFIG_RV40_DECODER
  2607. static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2608. put_pixels16_xy2_c(dst, src, stride, 16);
  2609. }
  2610. static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2611. avg_pixels16_xy2_c(dst, src, stride, 16);
  2612. }
  2613. static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2614. put_pixels8_xy2_c(dst, src, stride, 8);
  2615. }
  2616. static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2617. avg_pixels8_xy2_c(dst, src, stride, 8);
  2618. }
  2619. void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx);
  2620. #endif /* CONFIG_RV40_DECODER */
  2621. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2622. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2623. int i;
  2624. for(i=0; i<w; i++){
  2625. const int src_1= src[ -srcStride];
  2626. const int src0 = src[0 ];
  2627. const int src1 = src[ srcStride];
  2628. const int src2 = src[2*srcStride];
  2629. const int src3 = src[3*srcStride];
  2630. const int src4 = src[4*srcStride];
  2631. const int src5 = src[5*srcStride];
  2632. const int src6 = src[6*srcStride];
  2633. const int src7 = src[7*srcStride];
  2634. const int src8 = src[8*srcStride];
  2635. const int src9 = src[9*srcStride];
  2636. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2637. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2638. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2639. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2640. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2641. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2642. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2643. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2644. src++;
  2645. dst++;
  2646. }
  2647. }
  2648. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2649. put_pixels8_c(dst, src, stride, 8);
  2650. }
  2651. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2652. uint8_t half[64];
  2653. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2654. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2655. }
  2656. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2657. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2658. }
  2659. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2660. uint8_t half[64];
  2661. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2662. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2663. }
  2664. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2665. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2666. }
  2667. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2668. uint8_t halfH[88];
  2669. uint8_t halfV[64];
  2670. uint8_t halfHV[64];
  2671. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2672. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2673. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2674. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2675. }
  2676. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2677. uint8_t halfH[88];
  2678. uint8_t halfV[64];
  2679. uint8_t halfHV[64];
  2680. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2681. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2682. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2683. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2684. }
  2685. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2686. uint8_t halfH[88];
  2687. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2688. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2689. }
  2690. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2691. if(CONFIG_ANY_H263) {
  2692. int x;
  2693. const int strength= ff_h263_loop_filter_strength[qscale];
  2694. for(x=0; x<8; x++){
  2695. int d1, d2, ad1;
  2696. int p0= src[x-2*stride];
  2697. int p1= src[x-1*stride];
  2698. int p2= src[x+0*stride];
  2699. int p3= src[x+1*stride];
  2700. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2701. if (d<-2*strength) d1= 0;
  2702. else if(d<- strength) d1=-2*strength - d;
  2703. else if(d< strength) d1= d;
  2704. else if(d< 2*strength) d1= 2*strength - d;
  2705. else d1= 0;
  2706. p1 += d1;
  2707. p2 -= d1;
  2708. if(p1&256) p1= ~(p1>>31);
  2709. if(p2&256) p2= ~(p2>>31);
  2710. src[x-1*stride] = p1;
  2711. src[x+0*stride] = p2;
  2712. ad1= FFABS(d1)>>1;
  2713. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2714. src[x-2*stride] = p0 - d2;
  2715. src[x+ stride] = p3 + d2;
  2716. }
  2717. }
  2718. }
  2719. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2720. if(CONFIG_ANY_H263) {
  2721. int y;
  2722. const int strength= ff_h263_loop_filter_strength[qscale];
  2723. for(y=0; y<8; y++){
  2724. int d1, d2, ad1;
  2725. int p0= src[y*stride-2];
  2726. int p1= src[y*stride-1];
  2727. int p2= src[y*stride+0];
  2728. int p3= src[y*stride+1];
  2729. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2730. if (d<-2*strength) d1= 0;
  2731. else if(d<- strength) d1=-2*strength - d;
  2732. else if(d< strength) d1= d;
  2733. else if(d< 2*strength) d1= 2*strength - d;
  2734. else d1= 0;
  2735. p1 += d1;
  2736. p2 -= d1;
  2737. if(p1&256) p1= ~(p1>>31);
  2738. if(p2&256) p2= ~(p2>>31);
  2739. src[y*stride-1] = p1;
  2740. src[y*stride+0] = p2;
  2741. ad1= FFABS(d1)>>1;
  2742. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2743. src[y*stride-2] = p0 - d2;
  2744. src[y*stride+1] = p3 + d2;
  2745. }
  2746. }
  2747. }
  2748. static void h261_loop_filter_c(uint8_t *src, int stride){
  2749. int x,y,xy,yz;
  2750. int temp[64];
  2751. for(x=0; x<8; x++){
  2752. temp[x ] = 4*src[x ];
  2753. temp[x + 7*8] = 4*src[x + 7*stride];
  2754. }
  2755. for(y=1; y<7; y++){
  2756. for(x=0; x<8; x++){
  2757. xy = y * stride + x;
  2758. yz = y * 8 + x;
  2759. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  2760. }
  2761. }
  2762. for(y=0; y<8; y++){
  2763. src[ y*stride] = (temp[ y*8] + 2)>>2;
  2764. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  2765. for(x=1; x<7; x++){
  2766. xy = y * stride + x;
  2767. yz = y * 8 + x;
  2768. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  2769. }
  2770. }
  2771. }
  2772. static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2773. {
  2774. int i, d;
  2775. for( i = 0; i < 4; i++ ) {
  2776. if( tc0[i] < 0 ) {
  2777. pix += 4*ystride;
  2778. continue;
  2779. }
  2780. for( d = 0; d < 4; d++ ) {
  2781. const int p0 = pix[-1*xstride];
  2782. const int p1 = pix[-2*xstride];
  2783. const int p2 = pix[-3*xstride];
  2784. const int q0 = pix[0];
  2785. const int q1 = pix[1*xstride];
  2786. const int q2 = pix[2*xstride];
  2787. if( FFABS( p0 - q0 ) < alpha &&
  2788. FFABS( p1 - p0 ) < beta &&
  2789. FFABS( q1 - q0 ) < beta ) {
  2790. int tc = tc0[i];
  2791. int i_delta;
  2792. if( FFABS( p2 - p0 ) < beta ) {
  2793. pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] );
  2794. tc++;
  2795. }
  2796. if( FFABS( q2 - q0 ) < beta ) {
  2797. pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] );
  2798. tc++;
  2799. }
  2800. i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2801. pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */
  2802. pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */
  2803. }
  2804. pix += ystride;
  2805. }
  2806. }
  2807. }
  2808. static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2809. {
  2810. h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0);
  2811. }
  2812. static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2813. {
  2814. h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0);
  2815. }
  2816. static inline void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
  2817. {
  2818. int d;
  2819. for( d = 0; d < 16; d++ ) {
  2820. const int p2 = pix[-3*xstride];
  2821. const int p1 = pix[-2*xstride];
  2822. const int p0 = pix[-1*xstride];
  2823. const int q0 = pix[ 0*xstride];
  2824. const int q1 = pix[ 1*xstride];
  2825. const int q2 = pix[ 2*xstride];
  2826. if( FFABS( p0 - q0 ) < alpha &&
  2827. FFABS( p1 - p0 ) < beta &&
  2828. FFABS( q1 - q0 ) < beta ) {
  2829. if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
  2830. if( FFABS( p2 - p0 ) < beta)
  2831. {
  2832. const int p3 = pix[-4*xstride];
  2833. /* p0', p1', p2' */
  2834. pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
  2835. pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
  2836. pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
  2837. } else {
  2838. /* p0' */
  2839. pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
  2840. }
  2841. if( FFABS( q2 - q0 ) < beta)
  2842. {
  2843. const int q3 = pix[3*xstride];
  2844. /* q0', q1', q2' */
  2845. pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
  2846. pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
  2847. pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
  2848. } else {
  2849. /* q0' */
  2850. pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
  2851. }
  2852. }else{
  2853. /* p0', q0' */
  2854. pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
  2855. pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
  2856. }
  2857. }
  2858. pix += ystride;
  2859. }
  2860. }
  2861. static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2862. {
  2863. h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta);
  2864. }
  2865. static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2866. {
  2867. h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta);
  2868. }
  2869. static inline void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2870. {
  2871. int i, d;
  2872. for( i = 0; i < 4; i++ ) {
  2873. const int tc = tc0[i];
  2874. if( tc <= 0 ) {
  2875. pix += 2*ystride;
  2876. continue;
  2877. }
  2878. for( d = 0; d < 2; d++ ) {
  2879. const int p0 = pix[-1*xstride];
  2880. const int p1 = pix[-2*xstride];
  2881. const int q0 = pix[0];
  2882. const int q1 = pix[1*xstride];
  2883. if( FFABS( p0 - q0 ) < alpha &&
  2884. FFABS( p1 - p0 ) < beta &&
  2885. FFABS( q1 - q0 ) < beta ) {
  2886. int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2887. pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */
  2888. pix[0] = av_clip_uint8( q0 - delta ); /* q0' */
  2889. }
  2890. pix += ystride;
  2891. }
  2892. }
  2893. }
  2894. static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2895. {
  2896. h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0);
  2897. }
  2898. static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2899. {
  2900. h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0);
  2901. }
  2902. static inline void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
  2903. {
  2904. int d;
  2905. for( d = 0; d < 8; d++ ) {
  2906. const int p0 = pix[-1*xstride];
  2907. const int p1 = pix[-2*xstride];
  2908. const int q0 = pix[0];
  2909. const int q1 = pix[1*xstride];
  2910. if( FFABS( p0 - q0 ) < alpha &&
  2911. FFABS( p1 - p0 ) < beta &&
  2912. FFABS( q1 - q0 ) < beta ) {
  2913. pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
  2914. pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
  2915. }
  2916. pix += ystride;
  2917. }
  2918. }
  2919. static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2920. {
  2921. h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta);
  2922. }
  2923. static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2924. {
  2925. h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta);
  2926. }
  2927. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2928. {
  2929. int s, i;
  2930. s = 0;
  2931. for(i=0;i<h;i++) {
  2932. s += abs(pix1[0] - pix2[0]);
  2933. s += abs(pix1[1] - pix2[1]);
  2934. s += abs(pix1[2] - pix2[2]);
  2935. s += abs(pix1[3] - pix2[3]);
  2936. s += abs(pix1[4] - pix2[4]);
  2937. s += abs(pix1[5] - pix2[5]);
  2938. s += abs(pix1[6] - pix2[6]);
  2939. s += abs(pix1[7] - pix2[7]);
  2940. s += abs(pix1[8] - pix2[8]);
  2941. s += abs(pix1[9] - pix2[9]);
  2942. s += abs(pix1[10] - pix2[10]);
  2943. s += abs(pix1[11] - pix2[11]);
  2944. s += abs(pix1[12] - pix2[12]);
  2945. s += abs(pix1[13] - pix2[13]);
  2946. s += abs(pix1[14] - pix2[14]);
  2947. s += abs(pix1[15] - pix2[15]);
  2948. pix1 += line_size;
  2949. pix2 += line_size;
  2950. }
  2951. return s;
  2952. }
  2953. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2954. {
  2955. int s, i;
  2956. s = 0;
  2957. for(i=0;i<h;i++) {
  2958. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2959. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2960. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2961. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2962. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2963. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2964. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2965. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2966. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2967. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2968. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2969. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2970. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2971. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2972. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2973. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2974. pix1 += line_size;
  2975. pix2 += line_size;
  2976. }
  2977. return s;
  2978. }
  2979. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2980. {
  2981. int s, i;
  2982. uint8_t *pix3 = pix2 + line_size;
  2983. s = 0;
  2984. for(i=0;i<h;i++) {
  2985. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2986. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2987. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2988. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2989. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2990. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2991. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2992. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2993. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2994. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2995. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2996. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2997. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2998. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2999. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  3000. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  3001. pix1 += line_size;
  3002. pix2 += line_size;
  3003. pix3 += line_size;
  3004. }
  3005. return s;
  3006. }
  3007. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  3008. {
  3009. int s, i;
  3010. uint8_t *pix3 = pix2 + line_size;
  3011. s = 0;
  3012. for(i=0;i<h;i++) {
  3013. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  3014. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  3015. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  3016. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  3017. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  3018. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  3019. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  3020. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  3021. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  3022. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  3023. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  3024. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  3025. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  3026. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  3027. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  3028. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  3029. pix1 += line_size;
  3030. pix2 += line_size;
  3031. pix3 += line_size;
  3032. }
  3033. return s;
  3034. }
  3035. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  3036. {
  3037. int s, i;
  3038. s = 0;
  3039. for(i=0;i<h;i++) {
  3040. s += abs(pix1[0] - pix2[0]);
  3041. s += abs(pix1[1] - pix2[1]);
  3042. s += abs(pix1[2] - pix2[2]);
  3043. s += abs(pix1[3] - pix2[3]);
  3044. s += abs(pix1[4] - pix2[4]);
  3045. s += abs(pix1[5] - pix2[5]);
  3046. s += abs(pix1[6] - pix2[6]);
  3047. s += abs(pix1[7] - pix2[7]);
  3048. pix1 += line_size;
  3049. pix2 += line_size;
  3050. }
  3051. return s;
  3052. }
  3053. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  3054. {
  3055. int s, i;
  3056. s = 0;
  3057. for(i=0;i<h;i++) {
  3058. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  3059. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  3060. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  3061. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  3062. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  3063. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  3064. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  3065. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  3066. pix1 += line_size;
  3067. pix2 += line_size;
  3068. }
  3069. return s;
  3070. }
  3071. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  3072. {
  3073. int s, i;
  3074. uint8_t *pix3 = pix2 + line_size;
  3075. s = 0;
  3076. for(i=0;i<h;i++) {
  3077. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  3078. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  3079. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  3080. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  3081. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  3082. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  3083. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  3084. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  3085. pix1 += line_size;
  3086. pix2 += line_size;
  3087. pix3 += line_size;
  3088. }
  3089. return s;
  3090. }
  3091. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  3092. {
  3093. int s, i;
  3094. uint8_t *pix3 = pix2 + line_size;
  3095. s = 0;
  3096. for(i=0;i<h;i++) {
  3097. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  3098. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  3099. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  3100. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  3101. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  3102. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  3103. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  3104. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  3105. pix1 += line_size;
  3106. pix2 += line_size;
  3107. pix3 += line_size;
  3108. }
  3109. return s;
  3110. }
  3111. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  3112. MpegEncContext *c = v;
  3113. int score1=0;
  3114. int score2=0;
  3115. int x,y;
  3116. for(y=0; y<h; y++){
  3117. for(x=0; x<16; x++){
  3118. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  3119. }
  3120. if(y+1<h){
  3121. for(x=0; x<15; x++){
  3122. score2+= FFABS( s1[x ] - s1[x +stride]
  3123. - s1[x+1] + s1[x+1+stride])
  3124. -FFABS( s2[x ] - s2[x +stride]
  3125. - s2[x+1] + s2[x+1+stride]);
  3126. }
  3127. }
  3128. s1+= stride;
  3129. s2+= stride;
  3130. }
  3131. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  3132. else return score1 + FFABS(score2)*8;
  3133. }
  3134. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  3135. MpegEncContext *c = v;
  3136. int score1=0;
  3137. int score2=0;
  3138. int x,y;
  3139. for(y=0; y<h; y++){
  3140. for(x=0; x<8; x++){
  3141. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  3142. }
  3143. if(y+1<h){
  3144. for(x=0; x<7; x++){
  3145. score2+= FFABS( s1[x ] - s1[x +stride]
  3146. - s1[x+1] + s1[x+1+stride])
  3147. -FFABS( s2[x ] - s2[x +stride]
  3148. - s2[x+1] + s2[x+1+stride]);
  3149. }
  3150. }
  3151. s1+= stride;
  3152. s2+= stride;
  3153. }
  3154. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  3155. else return score1 + FFABS(score2)*8;
  3156. }
  3157. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  3158. int i;
  3159. unsigned int sum=0;
  3160. for(i=0; i<8*8; i++){
  3161. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  3162. int w= weight[i];
  3163. b>>= RECON_SHIFT;
  3164. assert(-512<b && b<512);
  3165. sum += (w*b)*(w*b)>>4;
  3166. }
  3167. return sum>>2;
  3168. }
  3169. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  3170. int i;
  3171. for(i=0; i<8*8; i++){
  3172. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  3173. }
  3174. }
  3175. /**
  3176. * permutes an 8x8 block.
  3177. * @param block the block which will be permuted according to the given permutation vector
  3178. * @param permutation the permutation vector
  3179. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  3180. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  3181. * (inverse) permutated to scantable order!
  3182. */
  3183. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  3184. {
  3185. int i;
  3186. DCTELEM temp[64];
  3187. if(last<=0) return;
  3188. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  3189. for(i=0; i<=last; i++){
  3190. const int j= scantable[i];
  3191. temp[j]= block[j];
  3192. block[j]=0;
  3193. }
  3194. for(i=0; i<=last; i++){
  3195. const int j= scantable[i];
  3196. const int perm_j= permutation[j];
  3197. block[perm_j]= temp[j];
  3198. }
  3199. }
  3200. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  3201. return 0;
  3202. }
  3203. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  3204. int i;
  3205. memset(cmp, 0, sizeof(void*)*6);
  3206. for(i=0; i<6; i++){
  3207. switch(type&0xFF){
  3208. case FF_CMP_SAD:
  3209. cmp[i]= c->sad[i];
  3210. break;
  3211. case FF_CMP_SATD:
  3212. cmp[i]= c->hadamard8_diff[i];
  3213. break;
  3214. case FF_CMP_SSE:
  3215. cmp[i]= c->sse[i];
  3216. break;
  3217. case FF_CMP_DCT:
  3218. cmp[i]= c->dct_sad[i];
  3219. break;
  3220. case FF_CMP_DCT264:
  3221. cmp[i]= c->dct264_sad[i];
  3222. break;
  3223. case FF_CMP_DCTMAX:
  3224. cmp[i]= c->dct_max[i];
  3225. break;
  3226. case FF_CMP_PSNR:
  3227. cmp[i]= c->quant_psnr[i];
  3228. break;
  3229. case FF_CMP_BIT:
  3230. cmp[i]= c->bit[i];
  3231. break;
  3232. case FF_CMP_RD:
  3233. cmp[i]= c->rd[i];
  3234. break;
  3235. case FF_CMP_VSAD:
  3236. cmp[i]= c->vsad[i];
  3237. break;
  3238. case FF_CMP_VSSE:
  3239. cmp[i]= c->vsse[i];
  3240. break;
  3241. case FF_CMP_ZERO:
  3242. cmp[i]= zero_cmp;
  3243. break;
  3244. case FF_CMP_NSSE:
  3245. cmp[i]= c->nsse[i];
  3246. break;
  3247. #if CONFIG_SNOW_ENCODER
  3248. case FF_CMP_W53:
  3249. cmp[i]= c->w53[i];
  3250. break;
  3251. case FF_CMP_W97:
  3252. cmp[i]= c->w97[i];
  3253. break;
  3254. #endif
  3255. default:
  3256. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  3257. }
  3258. }
  3259. }
  3260. static void clear_block_c(DCTELEM *block)
  3261. {
  3262. memset(block, 0, sizeof(DCTELEM)*64);
  3263. }
  3264. /**
  3265. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  3266. */
  3267. static void clear_blocks_c(DCTELEM *blocks)
  3268. {
  3269. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  3270. }
  3271. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  3272. long i;
  3273. for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
  3274. long a = *(long*)(src+i);
  3275. long b = *(long*)(dst+i);
  3276. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  3277. }
  3278. for(; i<w; i++)
  3279. dst[i+0] += src[i+0];
  3280. }
  3281. static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  3282. long i;
  3283. for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
  3284. long a = *(long*)(src1+i);
  3285. long b = *(long*)(src2+i);
  3286. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  3287. }
  3288. for(; i<w; i++)
  3289. dst[i] = src1[i]+src2[i];
  3290. }
  3291. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  3292. long i;
  3293. #if !HAVE_FAST_UNALIGNED
  3294. if((long)src2 & (sizeof(long)-1)){
  3295. for(i=0; i+7<w; i+=8){
  3296. dst[i+0] = src1[i+0]-src2[i+0];
  3297. dst[i+1] = src1[i+1]-src2[i+1];
  3298. dst[i+2] = src1[i+2]-src2[i+2];
  3299. dst[i+3] = src1[i+3]-src2[i+3];
  3300. dst[i+4] = src1[i+4]-src2[i+4];
  3301. dst[i+5] = src1[i+5]-src2[i+5];
  3302. dst[i+6] = src1[i+6]-src2[i+6];
  3303. dst[i+7] = src1[i+7]-src2[i+7];
  3304. }
  3305. }else
  3306. #endif
  3307. for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
  3308. long a = *(long*)(src1+i);
  3309. long b = *(long*)(src2+i);
  3310. *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
  3311. }
  3312. for(; i<w; i++)
  3313. dst[i+0] = src1[i+0]-src2[i+0];
  3314. }
  3315. static void add_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){
  3316. int i;
  3317. uint8_t l, lt;
  3318. l= *left;
  3319. lt= *left_top;
  3320. for(i=0; i<w; i++){
  3321. l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
  3322. lt= src1[i];
  3323. dst[i]= l;
  3324. }
  3325. *left= l;
  3326. *left_top= lt;
  3327. }
  3328. static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
  3329. int i;
  3330. uint8_t l, lt;
  3331. l= *left;
  3332. lt= *left_top;
  3333. for(i=0; i<w; i++){
  3334. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  3335. lt= src1[i];
  3336. l= src2[i];
  3337. dst[i]= l - pred;
  3338. }
  3339. *left= l;
  3340. *left_top= lt;
  3341. }
  3342. #define BUTTERFLY2(o1,o2,i1,i2) \
  3343. o1= (i1)+(i2);\
  3344. o2= (i1)-(i2);
  3345. #define BUTTERFLY1(x,y) \
  3346. {\
  3347. int a,b;\
  3348. a= x;\
  3349. b= y;\
  3350. x= a+b;\
  3351. y= a-b;\
  3352. }
  3353. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  3354. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  3355. int i;
  3356. int temp[64];
  3357. int sum=0;
  3358. assert(h==8);
  3359. for(i=0; i<8; i++){
  3360. //FIXME try pointer walks
  3361. 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]);
  3362. 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]);
  3363. 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]);
  3364. 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]);
  3365. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3366. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3367. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3368. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3369. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3370. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3371. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3372. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3373. }
  3374. for(i=0; i<8; i++){
  3375. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3376. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3377. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3378. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3379. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3380. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3381. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3382. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3383. sum +=
  3384. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3385. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3386. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3387. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3388. }
  3389. #if 0
  3390. static int maxi=0;
  3391. if(sum>maxi){
  3392. maxi=sum;
  3393. printf("MAX:%d\n", maxi);
  3394. }
  3395. #endif
  3396. return sum;
  3397. }
  3398. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  3399. int i;
  3400. int temp[64];
  3401. int sum=0;
  3402. assert(h==8);
  3403. for(i=0; i<8; i++){
  3404. //FIXME try pointer walks
  3405. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  3406. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  3407. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  3408. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  3409. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3410. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3411. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3412. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3413. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3414. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3415. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3416. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3417. }
  3418. for(i=0; i<8; i++){
  3419. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3420. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3421. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3422. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3423. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3424. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3425. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3426. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3427. sum +=
  3428. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3429. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3430. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3431. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3432. }
  3433. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  3434. return sum;
  3435. }
  3436. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3437. MpegEncContext * const s= (MpegEncContext *)c;
  3438. DECLARE_ALIGNED_16(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3439. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3440. assert(h==8);
  3441. s->dsp.diff_pixels(temp, src1, src2, stride);
  3442. s->dsp.fdct(temp);
  3443. return s->dsp.sum_abs_dctelem(temp);
  3444. }
  3445. #if CONFIG_GPL
  3446. #define DCT8_1D {\
  3447. const int s07 = SRC(0) + SRC(7);\
  3448. const int s16 = SRC(1) + SRC(6);\
  3449. const int s25 = SRC(2) + SRC(5);\
  3450. const int s34 = SRC(3) + SRC(4);\
  3451. const int a0 = s07 + s34;\
  3452. const int a1 = s16 + s25;\
  3453. const int a2 = s07 - s34;\
  3454. const int a3 = s16 - s25;\
  3455. const int d07 = SRC(0) - SRC(7);\
  3456. const int d16 = SRC(1) - SRC(6);\
  3457. const int d25 = SRC(2) - SRC(5);\
  3458. const int d34 = SRC(3) - SRC(4);\
  3459. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  3460. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  3461. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  3462. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  3463. DST(0, a0 + a1 ) ;\
  3464. DST(1, a4 + (a7>>2)) ;\
  3465. DST(2, a2 + (a3>>1)) ;\
  3466. DST(3, a5 + (a6>>2)) ;\
  3467. DST(4, a0 - a1 ) ;\
  3468. DST(5, a6 - (a5>>2)) ;\
  3469. DST(6, (a2>>1) - a3 ) ;\
  3470. DST(7, (a4>>2) - a7 ) ;\
  3471. }
  3472. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3473. MpegEncContext * const s= (MpegEncContext *)c;
  3474. DCTELEM dct[8][8];
  3475. int i;
  3476. int sum=0;
  3477. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  3478. #define SRC(x) dct[i][x]
  3479. #define DST(x,v) dct[i][x]= v
  3480. for( i = 0; i < 8; i++ )
  3481. DCT8_1D
  3482. #undef SRC
  3483. #undef DST
  3484. #define SRC(x) dct[x][i]
  3485. #define DST(x,v) sum += FFABS(v)
  3486. for( i = 0; i < 8; i++ )
  3487. DCT8_1D
  3488. #undef SRC
  3489. #undef DST
  3490. return sum;
  3491. }
  3492. #endif
  3493. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3494. MpegEncContext * const s= (MpegEncContext *)c;
  3495. DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3496. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3497. int sum=0, i;
  3498. assert(h==8);
  3499. s->dsp.diff_pixels(temp, src1, src2, stride);
  3500. s->dsp.fdct(temp);
  3501. for(i=0; i<64; i++)
  3502. sum= FFMAX(sum, FFABS(temp[i]));
  3503. return sum;
  3504. }
  3505. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3506. MpegEncContext * const s= (MpegEncContext *)c;
  3507. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]);
  3508. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3509. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  3510. int sum=0, i;
  3511. assert(h==8);
  3512. s->mb_intra=0;
  3513. s->dsp.diff_pixels(temp, src1, src2, stride);
  3514. memcpy(bak, temp, 64*sizeof(DCTELEM));
  3515. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3516. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3517. ff_simple_idct(temp); //FIXME
  3518. for(i=0; i<64; i++)
  3519. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  3520. return sum;
  3521. }
  3522. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3523. MpegEncContext * const s= (MpegEncContext *)c;
  3524. const uint8_t *scantable= s->intra_scantable.permutated;
  3525. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3526. DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]);
  3527. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3528. uint8_t * const bak= (uint8_t*)aligned_bak;
  3529. int i, last, run, bits, level, distortion, start_i;
  3530. const int esc_length= s->ac_esc_length;
  3531. uint8_t * length;
  3532. uint8_t * last_length;
  3533. assert(h==8);
  3534. for(i=0; i<8; i++){
  3535. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  3536. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  3537. }
  3538. s->dsp.diff_pixels(temp, src1, src2, stride);
  3539. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3540. bits=0;
  3541. if (s->mb_intra) {
  3542. start_i = 1;
  3543. length = s->intra_ac_vlc_length;
  3544. last_length= s->intra_ac_vlc_last_length;
  3545. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3546. } else {
  3547. start_i = 0;
  3548. length = s->inter_ac_vlc_length;
  3549. last_length= s->inter_ac_vlc_last_length;
  3550. }
  3551. if(last>=start_i){
  3552. run=0;
  3553. for(i=start_i; i<last; i++){
  3554. int j= scantable[i];
  3555. level= temp[j];
  3556. if(level){
  3557. level+=64;
  3558. if((level&(~127)) == 0){
  3559. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3560. }else
  3561. bits+= esc_length;
  3562. run=0;
  3563. }else
  3564. run++;
  3565. }
  3566. i= scantable[last];
  3567. level= temp[i] + 64;
  3568. assert(level - 64);
  3569. if((level&(~127)) == 0){
  3570. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3571. }else
  3572. bits+= esc_length;
  3573. }
  3574. if(last>=0){
  3575. if(s->mb_intra)
  3576. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  3577. else
  3578. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3579. }
  3580. s->dsp.idct_add(bak, stride, temp);
  3581. distortion= s->dsp.sse[1](NULL, bak, src1, stride, 8);
  3582. return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  3583. }
  3584. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3585. MpegEncContext * const s= (MpegEncContext *)c;
  3586. const uint8_t *scantable= s->intra_scantable.permutated;
  3587. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3588. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3589. int i, last, run, bits, level, start_i;
  3590. const int esc_length= s->ac_esc_length;
  3591. uint8_t * length;
  3592. uint8_t * last_length;
  3593. assert(h==8);
  3594. s->dsp.diff_pixels(temp, src1, src2, stride);
  3595. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3596. bits=0;
  3597. if (s->mb_intra) {
  3598. start_i = 1;
  3599. length = s->intra_ac_vlc_length;
  3600. last_length= s->intra_ac_vlc_last_length;
  3601. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3602. } else {
  3603. start_i = 0;
  3604. length = s->inter_ac_vlc_length;
  3605. last_length= s->inter_ac_vlc_last_length;
  3606. }
  3607. if(last>=start_i){
  3608. run=0;
  3609. for(i=start_i; i<last; i++){
  3610. int j= scantable[i];
  3611. level= temp[j];
  3612. if(level){
  3613. level+=64;
  3614. if((level&(~127)) == 0){
  3615. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3616. }else
  3617. bits+= esc_length;
  3618. run=0;
  3619. }else
  3620. run++;
  3621. }
  3622. i= scantable[last];
  3623. level= temp[i] + 64;
  3624. assert(level - 64);
  3625. if((level&(~127)) == 0){
  3626. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3627. }else
  3628. bits+= esc_length;
  3629. }
  3630. return bits;
  3631. }
  3632. #define VSAD_INTRA(size) \
  3633. static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  3634. int score=0; \
  3635. int x,y; \
  3636. \
  3637. for(y=1; y<h; y++){ \
  3638. for(x=0; x<size; x+=4){ \
  3639. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
  3640. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
  3641. } \
  3642. s+= stride; \
  3643. } \
  3644. \
  3645. return score; \
  3646. }
  3647. VSAD_INTRA(8)
  3648. VSAD_INTRA(16)
  3649. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3650. int score=0;
  3651. int x,y;
  3652. for(y=1; y<h; y++){
  3653. for(x=0; x<16; x++){
  3654. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3655. }
  3656. s1+= stride;
  3657. s2+= stride;
  3658. }
  3659. return score;
  3660. }
  3661. #define SQ(a) ((a)*(a))
  3662. #define VSSE_INTRA(size) \
  3663. static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  3664. int score=0; \
  3665. int x,y; \
  3666. \
  3667. for(y=1; y<h; y++){ \
  3668. for(x=0; x<size; x+=4){ \
  3669. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
  3670. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
  3671. } \
  3672. s+= stride; \
  3673. } \
  3674. \
  3675. return score; \
  3676. }
  3677. VSSE_INTRA(8)
  3678. VSSE_INTRA(16)
  3679. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3680. int score=0;
  3681. int x,y;
  3682. for(y=1; y<h; y++){
  3683. for(x=0; x<16; x++){
  3684. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3685. }
  3686. s1+= stride;
  3687. s2+= stride;
  3688. }
  3689. return score;
  3690. }
  3691. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  3692. int size){
  3693. int score=0;
  3694. int i;
  3695. for(i=0; i<size; i++)
  3696. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  3697. return score;
  3698. }
  3699. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  3700. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  3701. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  3702. #if CONFIG_GPL
  3703. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  3704. #endif
  3705. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  3706. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  3707. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  3708. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  3709. static void vector_fmul_c(float *dst, const float *src, int len){
  3710. int i;
  3711. for(i=0; i<len; i++)
  3712. dst[i] *= src[i];
  3713. }
  3714. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  3715. int i;
  3716. src1 += len-1;
  3717. for(i=0; i<len; i++)
  3718. dst[i] = src0[i] * src1[-i];
  3719. }
  3720. void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step){
  3721. int i;
  3722. for(i=0; i<len; i++)
  3723. dst[i*step] = src0[i] * src1[i] + src2[i] + src3;
  3724. }
  3725. void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){
  3726. int i,j;
  3727. dst += len;
  3728. win += len;
  3729. src0+= len;
  3730. for(i=-len, j=len-1; i<0; i++, j--) {
  3731. float s0 = src0[i];
  3732. float s1 = src1[j];
  3733. float wi = win[i];
  3734. float wj = win[j];
  3735. dst[i] = s0*wj - s1*wi + add_bias;
  3736. dst[j] = s0*wi + s1*wj + add_bias;
  3737. }
  3738. }
  3739. static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
  3740. int i;
  3741. for(i=0; i<len; i++)
  3742. dst[i] = src[i] * mul;
  3743. }
  3744. static av_always_inline int float_to_int16_one(const float *src){
  3745. int_fast32_t tmp = *(const int32_t*)src;
  3746. if(tmp & 0xf0000){
  3747. tmp = (0x43c0ffff - tmp)>>31;
  3748. // is this faster on some gcc/cpu combinations?
  3749. // if(tmp > 0x43c0ffff) tmp = 0xFFFF;
  3750. // else tmp = 0;
  3751. }
  3752. return tmp - 0x8000;
  3753. }
  3754. void ff_float_to_int16_c(int16_t *dst, const float *src, long len){
  3755. int i;
  3756. for(i=0; i<len; i++)
  3757. dst[i] = float_to_int16_one(src+i);
  3758. }
  3759. void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){
  3760. int i,j,c;
  3761. if(channels==2){
  3762. for(i=0; i<len; i++){
  3763. dst[2*i] = float_to_int16_one(src[0]+i);
  3764. dst[2*i+1] = float_to_int16_one(src[1]+i);
  3765. }
  3766. }else{
  3767. for(c=0; c<channels; c++)
  3768. for(i=0, j=c; i<len; i++, j+=channels)
  3769. dst[j] = float_to_int16_one(src[c]+i);
  3770. }
  3771. }
  3772. static void add_int16_c(int16_t * v1, int16_t * v2, int order)
  3773. {
  3774. while (order--)
  3775. *v1++ += *v2++;
  3776. }
  3777. static void sub_int16_c(int16_t * v1, int16_t * v2, int order)
  3778. {
  3779. while (order--)
  3780. *v1++ -= *v2++;
  3781. }
  3782. static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift)
  3783. {
  3784. int res = 0;
  3785. while (order--)
  3786. res += (*v1++ * *v2++) >> shift;
  3787. return res;
  3788. }
  3789. #define W0 2048
  3790. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  3791. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  3792. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  3793. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  3794. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  3795. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  3796. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  3797. static void wmv2_idct_row(short * b)
  3798. {
  3799. int s1,s2;
  3800. int a0,a1,a2,a3,a4,a5,a6,a7;
  3801. /*step 1*/
  3802. a1 = W1*b[1]+W7*b[7];
  3803. a7 = W7*b[1]-W1*b[7];
  3804. a5 = W5*b[5]+W3*b[3];
  3805. a3 = W3*b[5]-W5*b[3];
  3806. a2 = W2*b[2]+W6*b[6];
  3807. a6 = W6*b[2]-W2*b[6];
  3808. a0 = W0*b[0]+W0*b[4];
  3809. a4 = W0*b[0]-W0*b[4];
  3810. /*step 2*/
  3811. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  3812. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3813. /*step 3*/
  3814. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  3815. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  3816. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  3817. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  3818. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  3819. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  3820. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  3821. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  3822. }
  3823. static void wmv2_idct_col(short * b)
  3824. {
  3825. int s1,s2;
  3826. int a0,a1,a2,a3,a4,a5,a6,a7;
  3827. /*step 1, with extended precision*/
  3828. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  3829. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  3830. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  3831. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  3832. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  3833. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  3834. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  3835. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  3836. /*step 2*/
  3837. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  3838. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3839. /*step 3*/
  3840. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  3841. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  3842. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  3843. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  3844. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  3845. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  3846. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  3847. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  3848. }
  3849. void ff_wmv2_idct_c(short * block){
  3850. int i;
  3851. for(i=0;i<64;i+=8){
  3852. wmv2_idct_row(block+i);
  3853. }
  3854. for(i=0;i<8;i++){
  3855. wmv2_idct_col(block+i);
  3856. }
  3857. }
  3858. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  3859. converted */
  3860. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  3861. {
  3862. ff_wmv2_idct_c(block);
  3863. put_pixels_clamped_c(block, dest, line_size);
  3864. }
  3865. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  3866. {
  3867. ff_wmv2_idct_c(block);
  3868. add_pixels_clamped_c(block, dest, line_size);
  3869. }
  3870. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  3871. {
  3872. j_rev_dct (block);
  3873. put_pixels_clamped_c(block, dest, line_size);
  3874. }
  3875. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  3876. {
  3877. j_rev_dct (block);
  3878. add_pixels_clamped_c(block, dest, line_size);
  3879. }
  3880. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  3881. {
  3882. j_rev_dct4 (block);
  3883. put_pixels_clamped4_c(block, dest, line_size);
  3884. }
  3885. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  3886. {
  3887. j_rev_dct4 (block);
  3888. add_pixels_clamped4_c(block, dest, line_size);
  3889. }
  3890. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  3891. {
  3892. j_rev_dct2 (block);
  3893. put_pixels_clamped2_c(block, dest, line_size);
  3894. }
  3895. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  3896. {
  3897. j_rev_dct2 (block);
  3898. add_pixels_clamped2_c(block, dest, line_size);
  3899. }
  3900. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  3901. {
  3902. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3903. dest[0] = cm[(block[0] + 4)>>3];
  3904. }
  3905. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  3906. {
  3907. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3908. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  3909. }
  3910. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  3911. /* init static data */
  3912. void dsputil_static_init(void)
  3913. {
  3914. int i;
  3915. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  3916. for(i=0;i<MAX_NEG_CROP;i++) {
  3917. ff_cropTbl[i] = 0;
  3918. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  3919. }
  3920. for(i=0;i<512;i++) {
  3921. ff_squareTbl[i] = (i - 256) * (i - 256);
  3922. }
  3923. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  3924. }
  3925. int ff_check_alignment(void){
  3926. static int did_fail=0;
  3927. DECLARE_ALIGNED_16(int, aligned);
  3928. if((long)&aligned & 15){
  3929. if(!did_fail){
  3930. #if HAVE_MMX || HAVE_ALTIVEC
  3931. av_log(NULL, AV_LOG_ERROR,
  3932. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  3933. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  3934. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  3935. "Do not report crashes to FFmpeg developers.\n");
  3936. #endif
  3937. did_fail=1;
  3938. }
  3939. return -1;
  3940. }
  3941. return 0;
  3942. }
  3943. void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  3944. {
  3945. int i;
  3946. ff_check_alignment();
  3947. #if CONFIG_ENCODERS
  3948. if(avctx->dct_algo==FF_DCT_FASTINT) {
  3949. c->fdct = fdct_ifast;
  3950. c->fdct248 = fdct_ifast248;
  3951. }
  3952. else if(avctx->dct_algo==FF_DCT_FAAN) {
  3953. c->fdct = ff_faandct;
  3954. c->fdct248 = ff_faandct248;
  3955. }
  3956. else {
  3957. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  3958. c->fdct248 = ff_fdct248_islow;
  3959. }
  3960. #endif //CONFIG_ENCODERS
  3961. if(avctx->lowres==1){
  3962. if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
  3963. c->idct_put= ff_jref_idct4_put;
  3964. c->idct_add= ff_jref_idct4_add;
  3965. }else{
  3966. c->idct_put= ff_h264_lowres_idct_put_c;
  3967. c->idct_add= ff_h264_lowres_idct_add_c;
  3968. }
  3969. c->idct = j_rev_dct4;
  3970. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3971. }else if(avctx->lowres==2){
  3972. c->idct_put= ff_jref_idct2_put;
  3973. c->idct_add= ff_jref_idct2_add;
  3974. c->idct = j_rev_dct2;
  3975. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3976. }else if(avctx->lowres==3){
  3977. c->idct_put= ff_jref_idct1_put;
  3978. c->idct_add= ff_jref_idct1_add;
  3979. c->idct = j_rev_dct1;
  3980. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3981. }else{
  3982. if(avctx->idct_algo==FF_IDCT_INT){
  3983. c->idct_put= ff_jref_idct_put;
  3984. c->idct_add= ff_jref_idct_add;
  3985. c->idct = j_rev_dct;
  3986. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  3987. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER || CONFIG_THEORA_DECODER ) &&
  3988. avctx->idct_algo==FF_IDCT_VP3){
  3989. c->idct_put= ff_vp3_idct_put_c;
  3990. c->idct_add= ff_vp3_idct_add_c;
  3991. c->idct = ff_vp3_idct_c;
  3992. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3993. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  3994. c->idct_put= ff_wmv2_idct_put_c;
  3995. c->idct_add= ff_wmv2_idct_add_c;
  3996. c->idct = ff_wmv2_idct_c;
  3997. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3998. }else if(avctx->idct_algo==FF_IDCT_FAAN){
  3999. c->idct_put= ff_faanidct_put;
  4000. c->idct_add= ff_faanidct_add;
  4001. c->idct = ff_faanidct;
  4002. c->idct_permutation_type= FF_NO_IDCT_PERM;
  4003. }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
  4004. c->idct_put= ff_ea_idct_put_c;
  4005. c->idct_permutation_type= FF_NO_IDCT_PERM;
  4006. }else{ //accurate/default
  4007. c->idct_put= ff_simple_idct_put;
  4008. c->idct_add= ff_simple_idct_add;
  4009. c->idct = ff_simple_idct;
  4010. c->idct_permutation_type= FF_NO_IDCT_PERM;
  4011. }
  4012. }
  4013. if (CONFIG_H264_DECODER) {
  4014. c->h264_idct_add= ff_h264_idct_add_c;
  4015. c->h264_idct8_add= ff_h264_idct8_add_c;
  4016. c->h264_idct_dc_add= ff_h264_idct_dc_add_c;
  4017. c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c;
  4018. c->h264_idct_add16 = ff_h264_idct_add16_c;
  4019. c->h264_idct8_add4 = ff_h264_idct8_add4_c;
  4020. c->h264_idct_add8 = ff_h264_idct_add8_c;
  4021. c->h264_idct_add16intra= ff_h264_idct_add16intra_c;
  4022. }
  4023. c->get_pixels = get_pixels_c;
  4024. c->diff_pixels = diff_pixels_c;
  4025. c->put_pixels_clamped = put_pixels_clamped_c;
  4026. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  4027. c->add_pixels_clamped = add_pixels_clamped_c;
  4028. c->add_pixels8 = add_pixels8_c;
  4029. c->add_pixels4 = add_pixels4_c;
  4030. c->sum_abs_dctelem = sum_abs_dctelem_c;
  4031. c->gmc1 = gmc1_c;
  4032. c->gmc = ff_gmc_c;
  4033. c->clear_block = clear_block_c;
  4034. c->clear_blocks = clear_blocks_c;
  4035. c->pix_sum = pix_sum_c;
  4036. c->pix_norm1 = pix_norm1_c;
  4037. /* TODO [0] 16 [1] 8 */
  4038. c->pix_abs[0][0] = pix_abs16_c;
  4039. c->pix_abs[0][1] = pix_abs16_x2_c;
  4040. c->pix_abs[0][2] = pix_abs16_y2_c;
  4041. c->pix_abs[0][3] = pix_abs16_xy2_c;
  4042. c->pix_abs[1][0] = pix_abs8_c;
  4043. c->pix_abs[1][1] = pix_abs8_x2_c;
  4044. c->pix_abs[1][2] = pix_abs8_y2_c;
  4045. c->pix_abs[1][3] = pix_abs8_xy2_c;
  4046. #define dspfunc(PFX, IDX, NUM) \
  4047. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  4048. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  4049. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  4050. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  4051. dspfunc(put, 0, 16);
  4052. dspfunc(put_no_rnd, 0, 16);
  4053. dspfunc(put, 1, 8);
  4054. dspfunc(put_no_rnd, 1, 8);
  4055. dspfunc(put, 2, 4);
  4056. dspfunc(put, 3, 2);
  4057. dspfunc(avg, 0, 16);
  4058. dspfunc(avg_no_rnd, 0, 16);
  4059. dspfunc(avg, 1, 8);
  4060. dspfunc(avg_no_rnd, 1, 8);
  4061. dspfunc(avg, 2, 4);
  4062. dspfunc(avg, 3, 2);
  4063. #undef dspfunc
  4064. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  4065. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  4066. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  4067. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  4068. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  4069. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  4070. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  4071. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  4072. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  4073. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  4074. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  4075. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  4076. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  4077. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  4078. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  4079. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  4080. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  4081. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  4082. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  4083. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  4084. #define dspfunc(PFX, IDX, NUM) \
  4085. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  4086. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  4087. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  4088. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  4089. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  4090. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  4091. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  4092. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  4093. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  4094. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  4095. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  4096. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  4097. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  4098. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  4099. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  4100. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  4101. dspfunc(put_qpel, 0, 16);
  4102. dspfunc(put_no_rnd_qpel, 0, 16);
  4103. dspfunc(avg_qpel, 0, 16);
  4104. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  4105. dspfunc(put_qpel, 1, 8);
  4106. dspfunc(put_no_rnd_qpel, 1, 8);
  4107. dspfunc(avg_qpel, 1, 8);
  4108. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  4109. dspfunc(put_h264_qpel, 0, 16);
  4110. dspfunc(put_h264_qpel, 1, 8);
  4111. dspfunc(put_h264_qpel, 2, 4);
  4112. dspfunc(put_h264_qpel, 3, 2);
  4113. dspfunc(avg_h264_qpel, 0, 16);
  4114. dspfunc(avg_h264_qpel, 1, 8);
  4115. dspfunc(avg_h264_qpel, 2, 4);
  4116. #undef dspfunc
  4117. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  4118. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  4119. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  4120. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  4121. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  4122. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  4123. c->put_no_rnd_h264_chroma_pixels_tab[0]= put_no_rnd_h264_chroma_mc8_c;
  4124. c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c;
  4125. c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c;
  4126. c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c;
  4127. c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c;
  4128. c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c;
  4129. c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c;
  4130. c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c;
  4131. c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c;
  4132. c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c;
  4133. c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c;
  4134. c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c;
  4135. c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c;
  4136. c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c;
  4137. c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c;
  4138. c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c;
  4139. c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c;
  4140. c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c;
  4141. c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c;
  4142. c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c;
  4143. c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c;
  4144. c->draw_edges = draw_edges_c;
  4145. #if CONFIG_CAVS_DECODER
  4146. ff_cavsdsp_init(c,avctx);
  4147. #endif
  4148. #if CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
  4149. ff_vc1dsp_init(c,avctx);
  4150. #endif
  4151. #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER
  4152. ff_intrax8dsp_init(c,avctx);
  4153. #endif
  4154. #if CONFIG_RV30_DECODER
  4155. ff_rv30dsp_init(c,avctx);
  4156. #endif
  4157. #if CONFIG_RV40_DECODER
  4158. ff_rv40dsp_init(c,avctx);
  4159. c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
  4160. c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
  4161. c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
  4162. c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
  4163. #endif
  4164. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  4165. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  4166. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  4167. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  4168. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  4169. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  4170. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  4171. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  4172. #define SET_CMP_FUNC(name) \
  4173. c->name[0]= name ## 16_c;\
  4174. c->name[1]= name ## 8x8_c;
  4175. SET_CMP_FUNC(hadamard8_diff)
  4176. c->hadamard8_diff[4]= hadamard8_intra16_c;
  4177. c->hadamard8_diff[5]= hadamard8_intra8x8_c;
  4178. SET_CMP_FUNC(dct_sad)
  4179. SET_CMP_FUNC(dct_max)
  4180. #if CONFIG_GPL
  4181. SET_CMP_FUNC(dct264_sad)
  4182. #endif
  4183. c->sad[0]= pix_abs16_c;
  4184. c->sad[1]= pix_abs8_c;
  4185. c->sse[0]= sse16_c;
  4186. c->sse[1]= sse8_c;
  4187. c->sse[2]= sse4_c;
  4188. SET_CMP_FUNC(quant_psnr)
  4189. SET_CMP_FUNC(rd)
  4190. SET_CMP_FUNC(bit)
  4191. c->vsad[0]= vsad16_c;
  4192. c->vsad[4]= vsad_intra16_c;
  4193. c->vsad[5]= vsad_intra8_c;
  4194. c->vsse[0]= vsse16_c;
  4195. c->vsse[4]= vsse_intra16_c;
  4196. c->vsse[5]= vsse_intra8_c;
  4197. c->nsse[0]= nsse16_c;
  4198. c->nsse[1]= nsse8_c;
  4199. #if CONFIG_SNOW_ENCODER
  4200. c->w53[0]= w53_16_c;
  4201. c->w53[1]= w53_8_c;
  4202. c->w97[0]= w97_16_c;
  4203. c->w97[1]= w97_8_c;
  4204. #endif
  4205. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  4206. c->add_bytes= add_bytes_c;
  4207. c->add_bytes_l2= add_bytes_l2_c;
  4208. c->diff_bytes= diff_bytes_c;
  4209. c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
  4210. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  4211. c->bswap_buf= bswap_buf;
  4212. #if CONFIG_PNG_DECODER
  4213. c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
  4214. #endif
  4215. c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c;
  4216. c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c;
  4217. c->h264_v_loop_filter_luma_intra= h264_v_loop_filter_luma_intra_c;
  4218. c->h264_h_loop_filter_luma_intra= h264_h_loop_filter_luma_intra_c;
  4219. c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c;
  4220. c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c;
  4221. c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c;
  4222. c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;
  4223. c->h264_loop_filter_strength= NULL;
  4224. if (CONFIG_ANY_H263) {
  4225. c->h263_h_loop_filter= h263_h_loop_filter_c;
  4226. c->h263_v_loop_filter= h263_v_loop_filter_c;
  4227. }
  4228. if (CONFIG_VP3_DECODER || CONFIG_THEORA_DECODER) {
  4229. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
  4230. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
  4231. }
  4232. if (CONFIG_VP6_DECODER) {
  4233. c->vp6_filter_diag4= ff_vp6_filter_diag4_c;
  4234. }
  4235. c->h261_loop_filter= h261_loop_filter_c;
  4236. c->try_8x8basis= try_8x8basis_c;
  4237. c->add_8x8basis= add_8x8basis_c;
  4238. #if CONFIG_SNOW_DECODER
  4239. c->vertical_compose97i = ff_snow_vertical_compose97i;
  4240. c->horizontal_compose97i = ff_snow_horizontal_compose97i;
  4241. c->inner_add_yblock = ff_snow_inner_add_yblock;
  4242. #endif
  4243. #if CONFIG_VORBIS_DECODER
  4244. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  4245. #endif
  4246. #if CONFIG_AC3_DECODER
  4247. c->ac3_downmix = ff_ac3_downmix_c;
  4248. #endif
  4249. #if CONFIG_FLAC_ENCODER
  4250. c->flac_compute_autocorr = ff_flac_compute_autocorr;
  4251. #endif
  4252. c->vector_fmul = vector_fmul_c;
  4253. c->vector_fmul_reverse = vector_fmul_reverse_c;
  4254. c->vector_fmul_add_add = ff_vector_fmul_add_add_c;
  4255. c->vector_fmul_window = ff_vector_fmul_window_c;
  4256. c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
  4257. c->float_to_int16 = ff_float_to_int16_c;
  4258. c->float_to_int16_interleave = ff_float_to_int16_interleave_c;
  4259. c->add_int16 = add_int16_c;
  4260. c->sub_int16 = sub_int16_c;
  4261. c->scalarproduct_int16 = scalarproduct_int16_c;
  4262. c->shrink[0]= ff_img_copy_plane;
  4263. c->shrink[1]= ff_shrink22;
  4264. c->shrink[2]= ff_shrink44;
  4265. c->shrink[3]= ff_shrink88;
  4266. c->prefetch= just_return;
  4267. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  4268. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  4269. if (HAVE_MMX) dsputil_init_mmx (c, avctx);
  4270. if (ARCH_ARM) dsputil_init_arm (c, avctx);
  4271. if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
  4272. if (HAVE_VIS) dsputil_init_vis (c, avctx);
  4273. if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
  4274. if (ARCH_PPC) dsputil_init_ppc (c, avctx);
  4275. if (HAVE_MMI) dsputil_init_mmi (c, avctx);
  4276. if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
  4277. if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
  4278. for(i=0; i<64; i++){
  4279. if(!c->put_2tap_qpel_pixels_tab[0][i])
  4280. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  4281. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  4282. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  4283. }
  4284. switch(c->idct_permutation_type){
  4285. case FF_NO_IDCT_PERM:
  4286. for(i=0; i<64; i++)
  4287. c->idct_permutation[i]= i;
  4288. break;
  4289. case FF_LIBMPEG2_IDCT_PERM:
  4290. for(i=0; i<64; i++)
  4291. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  4292. break;
  4293. case FF_SIMPLE_IDCT_PERM:
  4294. for(i=0; i<64; i++)
  4295. c->idct_permutation[i]= simple_mmx_permutation[i];
  4296. break;
  4297. case FF_TRANSPOSE_IDCT_PERM:
  4298. for(i=0; i<64; i++)
  4299. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  4300. break;
  4301. case FF_PARTTRANS_IDCT_PERM:
  4302. for(i=0; i<64; i++)
  4303. c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  4304. break;
  4305. case FF_SSE2_IDCT_PERM:
  4306. for(i=0; i<64; i++)
  4307. c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
  4308. break;
  4309. default:
  4310. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  4311. }
  4312. }