dsputil.c 164 KB

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