convert_argb.cc 276 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903
  1. /*
  2. * Copyright 2011 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "libyuv/convert_argb.h"
  11. #include <assert.h>
  12. #include "libyuv/convert_from_argb.h"
  13. #include "libyuv/cpu_id.h"
  14. #include "libyuv/planar_functions.h" // For CopyPlane and ARGBShuffle.
  15. #include "libyuv/rotate_argb.h"
  16. #include "libyuv/row.h"
  17. #include "libyuv/scale_row.h" // For ScaleRowUp2_Linear and ScaleRowUp2_Bilinear
  18. #include "libyuv/video_common.h"
  19. #ifdef __cplusplus
  20. namespace libyuv {
  21. extern "C" {
  22. #endif
  23. // Copy ARGB with optional flipping
  24. LIBYUV_API
  25. int ARGBCopy(const uint8_t* src_argb,
  26. int src_stride_argb,
  27. uint8_t* dst_argb,
  28. int dst_stride_argb,
  29. int width,
  30. int height) {
  31. if (!src_argb || !dst_argb || width <= 0 || height == 0) {
  32. return -1;
  33. }
  34. // Negative height means invert the image.
  35. if (height < 0) {
  36. height = -height;
  37. src_argb = src_argb + (height - 1) * src_stride_argb;
  38. src_stride_argb = -src_stride_argb;
  39. }
  40. CopyPlane(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width * 4,
  41. height);
  42. return 0;
  43. }
  44. // Convert I420 to ARGB with matrix.
  45. LIBYUV_API
  46. int I420ToARGBMatrix(const uint8_t* src_y,
  47. int src_stride_y,
  48. const uint8_t* src_u,
  49. int src_stride_u,
  50. const uint8_t* src_v,
  51. int src_stride_v,
  52. uint8_t* dst_argb,
  53. int dst_stride_argb,
  54. const struct YuvConstants* yuvconstants,
  55. int width,
  56. int height) {
  57. int y;
  58. void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  59. const uint8_t* v_buf, uint8_t* rgb_buf,
  60. const struct YuvConstants* yuvconstants, int width) =
  61. I422ToARGBRow_C;
  62. assert(yuvconstants);
  63. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  64. return -1;
  65. }
  66. // Negative height means invert the image.
  67. if (height < 0) {
  68. height = -height;
  69. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  70. dst_stride_argb = -dst_stride_argb;
  71. }
  72. #if defined(HAS_I422TOARGBROW_SSSE3)
  73. if (TestCpuFlag(kCpuHasSSSE3)) {
  74. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  75. if (IS_ALIGNED(width, 8)) {
  76. I422ToARGBRow = I422ToARGBRow_SSSE3;
  77. }
  78. }
  79. #endif
  80. #if defined(HAS_I422TOARGBROW_AVX2)
  81. if (TestCpuFlag(kCpuHasAVX2)) {
  82. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  83. if (IS_ALIGNED(width, 16)) {
  84. I422ToARGBRow = I422ToARGBRow_AVX2;
  85. }
  86. }
  87. #endif
  88. #if defined(HAS_I422TOARGBROW_AVX512BW)
  89. if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) ==
  90. (kCpuHasAVX512BW | kCpuHasAVX512VL)) {
  91. I422ToARGBRow = I422ToARGBRow_Any_AVX512BW;
  92. if (IS_ALIGNED(width, 32)) {
  93. I422ToARGBRow = I422ToARGBRow_AVX512BW;
  94. }
  95. }
  96. #endif
  97. #if defined(HAS_I422TOARGBROW_NEON)
  98. if (TestCpuFlag(kCpuHasNEON)) {
  99. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  100. if (IS_ALIGNED(width, 8)) {
  101. I422ToARGBRow = I422ToARGBRow_NEON;
  102. }
  103. }
  104. #endif
  105. #if defined(HAS_I422TOARGBROW_SVE2)
  106. if (TestCpuFlag(kCpuHasSVE2)) {
  107. I422ToARGBRow = I422ToARGBRow_SVE2;
  108. }
  109. #endif
  110. #if defined(HAS_I422TOARGBROW_MSA)
  111. if (TestCpuFlag(kCpuHasMSA)) {
  112. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  113. if (IS_ALIGNED(width, 8)) {
  114. I422ToARGBRow = I422ToARGBRow_MSA;
  115. }
  116. }
  117. #endif
  118. #if defined(HAS_I422TOARGBROW_LSX)
  119. if (TestCpuFlag(kCpuHasLSX)) {
  120. I422ToARGBRow = I422ToARGBRow_Any_LSX;
  121. if (IS_ALIGNED(width, 16)) {
  122. I422ToARGBRow = I422ToARGBRow_LSX;
  123. }
  124. }
  125. #endif
  126. #if defined(HAS_I422TOARGBROW_LASX)
  127. if (TestCpuFlag(kCpuHasLASX)) {
  128. I422ToARGBRow = I422ToARGBRow_Any_LASX;
  129. if (IS_ALIGNED(width, 32)) {
  130. I422ToARGBRow = I422ToARGBRow_LASX;
  131. }
  132. }
  133. #endif
  134. #if defined(HAS_I422TOARGBROW_RVV)
  135. if (TestCpuFlag(kCpuHasRVV)) {
  136. I422ToARGBRow = I422ToARGBRow_RVV;
  137. }
  138. #endif
  139. for (y = 0; y < height; ++y) {
  140. I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  141. dst_argb += dst_stride_argb;
  142. src_y += src_stride_y;
  143. if (y & 1) {
  144. src_u += src_stride_u;
  145. src_v += src_stride_v;
  146. }
  147. }
  148. return 0;
  149. }
  150. // Convert I420 to ARGB.
  151. LIBYUV_API
  152. int I420ToARGB(const uint8_t* src_y,
  153. int src_stride_y,
  154. const uint8_t* src_u,
  155. int src_stride_u,
  156. const uint8_t* src_v,
  157. int src_stride_v,
  158. uint8_t* dst_argb,
  159. int dst_stride_argb,
  160. int width,
  161. int height) {
  162. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  163. src_stride_v, dst_argb, dst_stride_argb,
  164. &kYuvI601Constants, width, height);
  165. }
  166. // Convert I420 to ABGR.
  167. LIBYUV_API
  168. int I420ToABGR(const uint8_t* src_y,
  169. int src_stride_y,
  170. const uint8_t* src_u,
  171. int src_stride_u,
  172. const uint8_t* src_v,
  173. int src_stride_v,
  174. uint8_t* dst_abgr,
  175. int dst_stride_abgr,
  176. int width,
  177. int height) {
  178. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  179. src_stride_v, // Swap U and V
  180. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  181. &kYvuI601Constants, // Use Yvu matrix
  182. width, height);
  183. }
  184. // Convert J420 to ARGB.
  185. LIBYUV_API
  186. int J420ToARGB(const uint8_t* src_y,
  187. int src_stride_y,
  188. const uint8_t* src_u,
  189. int src_stride_u,
  190. const uint8_t* src_v,
  191. int src_stride_v,
  192. uint8_t* dst_argb,
  193. int dst_stride_argb,
  194. int width,
  195. int height) {
  196. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  197. src_stride_v, dst_argb, dst_stride_argb,
  198. &kYuvJPEGConstants, width, height);
  199. }
  200. // Convert J420 to ABGR.
  201. LIBYUV_API
  202. int J420ToABGR(const uint8_t* src_y,
  203. int src_stride_y,
  204. const uint8_t* src_u,
  205. int src_stride_u,
  206. const uint8_t* src_v,
  207. int src_stride_v,
  208. uint8_t* dst_abgr,
  209. int dst_stride_abgr,
  210. int width,
  211. int height) {
  212. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  213. src_stride_v, // Swap U and V
  214. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  215. &kYvuJPEGConstants, // Use Yvu matrix
  216. width, height);
  217. }
  218. // Convert H420 to ARGB.
  219. LIBYUV_API
  220. int H420ToARGB(const uint8_t* src_y,
  221. int src_stride_y,
  222. const uint8_t* src_u,
  223. int src_stride_u,
  224. const uint8_t* src_v,
  225. int src_stride_v,
  226. uint8_t* dst_argb,
  227. int dst_stride_argb,
  228. int width,
  229. int height) {
  230. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  231. src_stride_v, dst_argb, dst_stride_argb,
  232. &kYuvH709Constants, width, height);
  233. }
  234. // Convert H420 to ABGR.
  235. LIBYUV_API
  236. int H420ToABGR(const uint8_t* src_y,
  237. int src_stride_y,
  238. const uint8_t* src_u,
  239. int src_stride_u,
  240. const uint8_t* src_v,
  241. int src_stride_v,
  242. uint8_t* dst_abgr,
  243. int dst_stride_abgr,
  244. int width,
  245. int height) {
  246. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  247. src_stride_v, // Swap U and V
  248. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  249. &kYvuH709Constants, // Use Yvu matrix
  250. width, height);
  251. }
  252. // Convert U420 to ARGB.
  253. LIBYUV_API
  254. int U420ToARGB(const uint8_t* src_y,
  255. int src_stride_y,
  256. const uint8_t* src_u,
  257. int src_stride_u,
  258. const uint8_t* src_v,
  259. int src_stride_v,
  260. uint8_t* dst_argb,
  261. int dst_stride_argb,
  262. int width,
  263. int height) {
  264. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  265. src_stride_v, dst_argb, dst_stride_argb,
  266. &kYuv2020Constants, width, height);
  267. }
  268. // Convert U420 to ABGR.
  269. LIBYUV_API
  270. int U420ToABGR(const uint8_t* src_y,
  271. int src_stride_y,
  272. const uint8_t* src_u,
  273. int src_stride_u,
  274. const uint8_t* src_v,
  275. int src_stride_v,
  276. uint8_t* dst_abgr,
  277. int dst_stride_abgr,
  278. int width,
  279. int height) {
  280. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  281. src_stride_v, // Swap U and V
  282. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  283. &kYvu2020Constants, // Use Yvu matrix
  284. width, height);
  285. }
  286. // Convert I422 to ARGB with matrix.
  287. LIBYUV_API
  288. int I422ToARGBMatrix(const uint8_t* src_y,
  289. int src_stride_y,
  290. const uint8_t* src_u,
  291. int src_stride_u,
  292. const uint8_t* src_v,
  293. int src_stride_v,
  294. uint8_t* dst_argb,
  295. int dst_stride_argb,
  296. const struct YuvConstants* yuvconstants,
  297. int width,
  298. int height) {
  299. int y;
  300. void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  301. const uint8_t* v_buf, uint8_t* rgb_buf,
  302. const struct YuvConstants* yuvconstants, int width) =
  303. I422ToARGBRow_C;
  304. assert(yuvconstants);
  305. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  306. return -1;
  307. }
  308. // Negative height means invert the image.
  309. if (height < 0) {
  310. height = -height;
  311. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  312. dst_stride_argb = -dst_stride_argb;
  313. }
  314. // Coalesce rows.
  315. if (src_stride_y == width && src_stride_u * 2 == width &&
  316. src_stride_v * 2 == width && dst_stride_argb == width * 4) {
  317. width *= height;
  318. height = 1;
  319. src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0;
  320. }
  321. #if defined(HAS_I422TOARGBROW_SSSE3)
  322. if (TestCpuFlag(kCpuHasSSSE3)) {
  323. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  324. if (IS_ALIGNED(width, 8)) {
  325. I422ToARGBRow = I422ToARGBRow_SSSE3;
  326. }
  327. }
  328. #endif
  329. #if defined(HAS_I422TOARGBROW_AVX2)
  330. if (TestCpuFlag(kCpuHasAVX2)) {
  331. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  332. if (IS_ALIGNED(width, 16)) {
  333. I422ToARGBRow = I422ToARGBRow_AVX2;
  334. }
  335. }
  336. #endif
  337. #if defined(HAS_I422TOARGBROW_AVX512BW)
  338. if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) ==
  339. (kCpuHasAVX512BW | kCpuHasAVX512VL)) {
  340. I422ToARGBRow = I422ToARGBRow_Any_AVX512BW;
  341. if (IS_ALIGNED(width, 32)) {
  342. I422ToARGBRow = I422ToARGBRow_AVX512BW;
  343. }
  344. }
  345. #endif
  346. #if defined(HAS_I422TOARGBROW_NEON)
  347. if (TestCpuFlag(kCpuHasNEON)) {
  348. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  349. if (IS_ALIGNED(width, 8)) {
  350. I422ToARGBRow = I422ToARGBRow_NEON;
  351. }
  352. }
  353. #endif
  354. #if defined(HAS_I422TOARGBROW_SVE2)
  355. if (TestCpuFlag(kCpuHasSVE2)) {
  356. I422ToARGBRow = I422ToARGBRow_SVE2;
  357. }
  358. #endif
  359. #if defined(HAS_I422TOARGBROW_MSA)
  360. if (TestCpuFlag(kCpuHasMSA)) {
  361. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  362. if (IS_ALIGNED(width, 8)) {
  363. I422ToARGBRow = I422ToARGBRow_MSA;
  364. }
  365. }
  366. #endif
  367. #if defined(HAS_I422TOARGBROW_LSX)
  368. if (TestCpuFlag(kCpuHasLSX)) {
  369. I422ToARGBRow = I422ToARGBRow_Any_LSX;
  370. if (IS_ALIGNED(width, 16)) {
  371. I422ToARGBRow = I422ToARGBRow_LSX;
  372. }
  373. }
  374. #endif
  375. #if defined(HAS_I422TOARGBROW_LASX)
  376. if (TestCpuFlag(kCpuHasLASX)) {
  377. I422ToARGBRow = I422ToARGBRow_Any_LASX;
  378. if (IS_ALIGNED(width, 32)) {
  379. I422ToARGBRow = I422ToARGBRow_LASX;
  380. }
  381. }
  382. #endif
  383. #if defined(HAS_I422TOARGBROW_RVV)
  384. if (TestCpuFlag(kCpuHasRVV)) {
  385. I422ToARGBRow = I422ToARGBRow_RVV;
  386. }
  387. #endif
  388. for (y = 0; y < height; ++y) {
  389. I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  390. dst_argb += dst_stride_argb;
  391. src_y += src_stride_y;
  392. src_u += src_stride_u;
  393. src_v += src_stride_v;
  394. }
  395. return 0;
  396. }
  397. // Convert I422 to ARGB.
  398. LIBYUV_API
  399. int I422ToARGB(const uint8_t* src_y,
  400. int src_stride_y,
  401. const uint8_t* src_u,
  402. int src_stride_u,
  403. const uint8_t* src_v,
  404. int src_stride_v,
  405. uint8_t* dst_argb,
  406. int dst_stride_argb,
  407. int width,
  408. int height) {
  409. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  410. src_stride_v, dst_argb, dst_stride_argb,
  411. &kYuvI601Constants, width, height);
  412. }
  413. // Convert I422 to ABGR.
  414. LIBYUV_API
  415. int I422ToABGR(const uint8_t* src_y,
  416. int src_stride_y,
  417. const uint8_t* src_u,
  418. int src_stride_u,
  419. const uint8_t* src_v,
  420. int src_stride_v,
  421. uint8_t* dst_abgr,
  422. int dst_stride_abgr,
  423. int width,
  424. int height) {
  425. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  426. src_stride_v, // Swap U and V
  427. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  428. &kYvuI601Constants, // Use Yvu matrix
  429. width, height);
  430. }
  431. // Convert J422 to ARGB.
  432. LIBYUV_API
  433. int J422ToARGB(const uint8_t* src_y,
  434. int src_stride_y,
  435. const uint8_t* src_u,
  436. int src_stride_u,
  437. const uint8_t* src_v,
  438. int src_stride_v,
  439. uint8_t* dst_argb,
  440. int dst_stride_argb,
  441. int width,
  442. int height) {
  443. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  444. src_stride_v, dst_argb, dst_stride_argb,
  445. &kYuvJPEGConstants, width, height);
  446. }
  447. // Convert J422 to ABGR.
  448. LIBYUV_API
  449. int J422ToABGR(const uint8_t* src_y,
  450. int src_stride_y,
  451. const uint8_t* src_u,
  452. int src_stride_u,
  453. const uint8_t* src_v,
  454. int src_stride_v,
  455. uint8_t* dst_abgr,
  456. int dst_stride_abgr,
  457. int width,
  458. int height) {
  459. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  460. src_stride_v, // Swap U and V
  461. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  462. &kYvuJPEGConstants, // Use Yvu matrix
  463. width, height);
  464. }
  465. // Convert H422 to ARGB.
  466. LIBYUV_API
  467. int H422ToARGB(const uint8_t* src_y,
  468. int src_stride_y,
  469. const uint8_t* src_u,
  470. int src_stride_u,
  471. const uint8_t* src_v,
  472. int src_stride_v,
  473. uint8_t* dst_argb,
  474. int dst_stride_argb,
  475. int width,
  476. int height) {
  477. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  478. src_stride_v, dst_argb, dst_stride_argb,
  479. &kYuvH709Constants, width, height);
  480. }
  481. // Convert H422 to ABGR.
  482. LIBYUV_API
  483. int H422ToABGR(const uint8_t* src_y,
  484. int src_stride_y,
  485. const uint8_t* src_u,
  486. int src_stride_u,
  487. const uint8_t* src_v,
  488. int src_stride_v,
  489. uint8_t* dst_abgr,
  490. int dst_stride_abgr,
  491. int width,
  492. int height) {
  493. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  494. src_stride_v, // Swap U and V
  495. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  496. &kYvuH709Constants, // Use Yvu matrix
  497. width, height);
  498. }
  499. // Convert U422 to ARGB.
  500. LIBYUV_API
  501. int U422ToARGB(const uint8_t* src_y,
  502. int src_stride_y,
  503. const uint8_t* src_u,
  504. int src_stride_u,
  505. const uint8_t* src_v,
  506. int src_stride_v,
  507. uint8_t* dst_argb,
  508. int dst_stride_argb,
  509. int width,
  510. int height) {
  511. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  512. src_stride_v, dst_argb, dst_stride_argb,
  513. &kYuv2020Constants, width, height);
  514. }
  515. // Convert U422 to ABGR.
  516. LIBYUV_API
  517. int U422ToABGR(const uint8_t* src_y,
  518. int src_stride_y,
  519. const uint8_t* src_u,
  520. int src_stride_u,
  521. const uint8_t* src_v,
  522. int src_stride_v,
  523. uint8_t* dst_abgr,
  524. int dst_stride_abgr,
  525. int width,
  526. int height) {
  527. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  528. src_stride_v, // Swap U and V
  529. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  530. &kYvu2020Constants, // Use Yvu matrix
  531. width, height);
  532. }
  533. // Convert I444 to ARGB with matrix.
  534. LIBYUV_API
  535. int I444ToARGBMatrix(const uint8_t* src_y,
  536. int src_stride_y,
  537. const uint8_t* src_u,
  538. int src_stride_u,
  539. const uint8_t* src_v,
  540. int src_stride_v,
  541. uint8_t* dst_argb,
  542. int dst_stride_argb,
  543. const struct YuvConstants* yuvconstants,
  544. int width,
  545. int height) {
  546. int y;
  547. void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  548. const uint8_t* v_buf, uint8_t* rgb_buf,
  549. const struct YuvConstants* yuvconstants, int width) =
  550. I444ToARGBRow_C;
  551. assert(yuvconstants);
  552. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  553. return -1;
  554. }
  555. // Negative height means invert the image.
  556. if (height < 0) {
  557. height = -height;
  558. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  559. dst_stride_argb = -dst_stride_argb;
  560. }
  561. // Coalesce rows.
  562. if (src_stride_y == width && src_stride_u == width && src_stride_v == width &&
  563. dst_stride_argb == width * 4) {
  564. width *= height;
  565. height = 1;
  566. src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0;
  567. }
  568. #if defined(HAS_I444TOARGBROW_SSSE3)
  569. if (TestCpuFlag(kCpuHasSSSE3)) {
  570. I444ToARGBRow = I444ToARGBRow_Any_SSSE3;
  571. if (IS_ALIGNED(width, 8)) {
  572. I444ToARGBRow = I444ToARGBRow_SSSE3;
  573. }
  574. }
  575. #endif
  576. #if defined(HAS_I444TOARGBROW_AVX2)
  577. if (TestCpuFlag(kCpuHasAVX2)) {
  578. I444ToARGBRow = I444ToARGBRow_Any_AVX2;
  579. if (IS_ALIGNED(width, 16)) {
  580. I444ToARGBRow = I444ToARGBRow_AVX2;
  581. }
  582. }
  583. #endif
  584. #if defined(HAS_I444TOARGBROW_NEON)
  585. if (TestCpuFlag(kCpuHasNEON)) {
  586. I444ToARGBRow = I444ToARGBRow_Any_NEON;
  587. if (IS_ALIGNED(width, 8)) {
  588. I444ToARGBRow = I444ToARGBRow_NEON;
  589. }
  590. }
  591. #endif
  592. #if defined(HAS_I444TOARGBROW_SVE2)
  593. if (TestCpuFlag(kCpuHasSVE2)) {
  594. I444ToARGBRow = I444ToARGBRow_SVE2;
  595. }
  596. #endif
  597. #if defined(HAS_I444TOARGBROW_MSA)
  598. if (TestCpuFlag(kCpuHasMSA)) {
  599. I444ToARGBRow = I444ToARGBRow_Any_MSA;
  600. if (IS_ALIGNED(width, 8)) {
  601. I444ToARGBRow = I444ToARGBRow_MSA;
  602. }
  603. }
  604. #endif
  605. #if defined(HAS_I444TOARGBROW_LSX)
  606. if (TestCpuFlag(kCpuHasLSX)) {
  607. I444ToARGBRow = I444ToARGBRow_Any_LSX;
  608. if (IS_ALIGNED(width, 16)) {
  609. I444ToARGBRow = I444ToARGBRow_LSX;
  610. }
  611. }
  612. #endif
  613. #if defined(HAS_I444TOARGBROW_RVV)
  614. if (TestCpuFlag(kCpuHasRVV)) {
  615. I444ToARGBRow = I444ToARGBRow_RVV;
  616. }
  617. #endif
  618. for (y = 0; y < height; ++y) {
  619. I444ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  620. dst_argb += dst_stride_argb;
  621. src_y += src_stride_y;
  622. src_u += src_stride_u;
  623. src_v += src_stride_v;
  624. }
  625. return 0;
  626. }
  627. // Convert I444 to ARGB.
  628. LIBYUV_API
  629. int I444ToARGB(const uint8_t* src_y,
  630. int src_stride_y,
  631. const uint8_t* src_u,
  632. int src_stride_u,
  633. const uint8_t* src_v,
  634. int src_stride_v,
  635. uint8_t* dst_argb,
  636. int dst_stride_argb,
  637. int width,
  638. int height) {
  639. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  640. src_stride_v, dst_argb, dst_stride_argb,
  641. &kYuvI601Constants, width, height);
  642. }
  643. // Convert I444 to ABGR.
  644. LIBYUV_API
  645. int I444ToABGR(const uint8_t* src_y,
  646. int src_stride_y,
  647. const uint8_t* src_u,
  648. int src_stride_u,
  649. const uint8_t* src_v,
  650. int src_stride_v,
  651. uint8_t* dst_abgr,
  652. int dst_stride_abgr,
  653. int width,
  654. int height) {
  655. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  656. src_stride_v, // Swap U and V
  657. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  658. &kYvuI601Constants, // Use Yvu matrix
  659. width, height);
  660. }
  661. // Convert J444 to ARGB.
  662. LIBYUV_API
  663. int J444ToARGB(const uint8_t* src_y,
  664. int src_stride_y,
  665. const uint8_t* src_u,
  666. int src_stride_u,
  667. const uint8_t* src_v,
  668. int src_stride_v,
  669. uint8_t* dst_argb,
  670. int dst_stride_argb,
  671. int width,
  672. int height) {
  673. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  674. src_stride_v, dst_argb, dst_stride_argb,
  675. &kYuvJPEGConstants, width, height);
  676. }
  677. // Convert J444 to ABGR.
  678. LIBYUV_API
  679. int J444ToABGR(const uint8_t* src_y,
  680. int src_stride_y,
  681. const uint8_t* src_u,
  682. int src_stride_u,
  683. const uint8_t* src_v,
  684. int src_stride_v,
  685. uint8_t* dst_abgr,
  686. int dst_stride_abgr,
  687. int width,
  688. int height) {
  689. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  690. src_stride_v, // Swap U and V
  691. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  692. &kYvuJPEGConstants, // Use Yvu matrix
  693. width, height);
  694. }
  695. // Convert H444 to ARGB.
  696. LIBYUV_API
  697. int H444ToARGB(const uint8_t* src_y,
  698. int src_stride_y,
  699. const uint8_t* src_u,
  700. int src_stride_u,
  701. const uint8_t* src_v,
  702. int src_stride_v,
  703. uint8_t* dst_argb,
  704. int dst_stride_argb,
  705. int width,
  706. int height) {
  707. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  708. src_stride_v, dst_argb, dst_stride_argb,
  709. &kYuvH709Constants, width, height);
  710. }
  711. // Convert H444 to ABGR.
  712. LIBYUV_API
  713. int H444ToABGR(const uint8_t* src_y,
  714. int src_stride_y,
  715. const uint8_t* src_u,
  716. int src_stride_u,
  717. const uint8_t* src_v,
  718. int src_stride_v,
  719. uint8_t* dst_abgr,
  720. int dst_stride_abgr,
  721. int width,
  722. int height) {
  723. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  724. src_stride_v, // Swap U and V
  725. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  726. &kYvuH709Constants, // Use Yvu matrix
  727. width, height);
  728. }
  729. // Convert U444 to ARGB.
  730. LIBYUV_API
  731. int U444ToARGB(const uint8_t* src_y,
  732. int src_stride_y,
  733. const uint8_t* src_u,
  734. int src_stride_u,
  735. const uint8_t* src_v,
  736. int src_stride_v,
  737. uint8_t* dst_argb,
  738. int dst_stride_argb,
  739. int width,
  740. int height) {
  741. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  742. src_stride_v, dst_argb, dst_stride_argb,
  743. &kYuv2020Constants, width, height);
  744. }
  745. // Convert U444 to ABGR.
  746. LIBYUV_API
  747. int U444ToABGR(const uint8_t* src_y,
  748. int src_stride_y,
  749. const uint8_t* src_u,
  750. int src_stride_u,
  751. const uint8_t* src_v,
  752. int src_stride_v,
  753. uint8_t* dst_abgr,
  754. int dst_stride_abgr,
  755. int width,
  756. int height) {
  757. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  758. src_stride_v, // Swap U and V
  759. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  760. &kYvu2020Constants, // Use Yvu matrix
  761. width, height);
  762. }
  763. // Convert I444 to RGB24 with matrix.
  764. LIBYUV_API
  765. int I444ToRGB24Matrix(const uint8_t* src_y,
  766. int src_stride_y,
  767. const uint8_t* src_u,
  768. int src_stride_u,
  769. const uint8_t* src_v,
  770. int src_stride_v,
  771. uint8_t* dst_rgb24,
  772. int dst_stride_rgb24,
  773. const struct YuvConstants* yuvconstants,
  774. int width,
  775. int height) {
  776. int y;
  777. void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  778. const uint8_t* v_buf, uint8_t* rgb_buf,
  779. const struct YuvConstants* yuvconstants, int width) =
  780. I444ToRGB24Row_C;
  781. assert(yuvconstants);
  782. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  783. return -1;
  784. }
  785. // Negative height means invert the image.
  786. if (height < 0) {
  787. height = -height;
  788. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  789. dst_stride_rgb24 = -dst_stride_rgb24;
  790. }
  791. // Coalesce rows.
  792. if (src_stride_y == width && src_stride_u == width && src_stride_v == width &&
  793. dst_stride_rgb24 == width * 3) {
  794. width *= height;
  795. height = 1;
  796. src_stride_y = src_stride_u = src_stride_v = dst_stride_rgb24 = 0;
  797. }
  798. #if defined(HAS_I444TORGB24ROW_SSSE3)
  799. if (TestCpuFlag(kCpuHasSSSE3)) {
  800. I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3;
  801. if (IS_ALIGNED(width, 16)) {
  802. I444ToRGB24Row = I444ToRGB24Row_SSSE3;
  803. }
  804. }
  805. #endif
  806. #if defined(HAS_I444TORGB24ROW_AVX2)
  807. if (TestCpuFlag(kCpuHasAVX2)) {
  808. I444ToRGB24Row = I444ToRGB24Row_Any_AVX2;
  809. if (IS_ALIGNED(width, 32)) {
  810. I444ToRGB24Row = I444ToRGB24Row_AVX2;
  811. }
  812. }
  813. #endif
  814. #if defined(HAS_I444TORGB24ROW_NEON)
  815. if (TestCpuFlag(kCpuHasNEON)) {
  816. I444ToRGB24Row = I444ToRGB24Row_Any_NEON;
  817. if (IS_ALIGNED(width, 8)) {
  818. I444ToRGB24Row = I444ToRGB24Row_NEON;
  819. }
  820. }
  821. #endif
  822. #if defined(HAS_I444TORGB24ROW_MSA)
  823. if (TestCpuFlag(kCpuHasMSA)) {
  824. I444ToRGB24Row = I444ToRGB24Row_Any_MSA;
  825. if (IS_ALIGNED(width, 8)) {
  826. I444ToRGB24Row = I444ToRGB24Row_MSA;
  827. }
  828. }
  829. #endif
  830. #if defined(HAS_I444TORGB24ROW_LSX)
  831. if (TestCpuFlag(kCpuHasLSX)) {
  832. I444ToRGB24Row = I444ToRGB24Row_Any_LSX;
  833. if (IS_ALIGNED(width, 16)) {
  834. I444ToRGB24Row = I444ToRGB24Row_LSX;
  835. }
  836. }
  837. #endif
  838. #if defined(HAS_I444TORGB24ROW_RVV)
  839. if (TestCpuFlag(kCpuHasRVV)) {
  840. I444ToRGB24Row = I444ToRGB24Row_RVV;
  841. }
  842. #endif
  843. for (y = 0; y < height; ++y) {
  844. I444ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width);
  845. dst_rgb24 += dst_stride_rgb24;
  846. src_y += src_stride_y;
  847. src_u += src_stride_u;
  848. src_v += src_stride_v;
  849. }
  850. return 0;
  851. }
  852. // Convert I444 to RGB24.
  853. LIBYUV_API
  854. int I444ToRGB24(const uint8_t* src_y,
  855. int src_stride_y,
  856. const uint8_t* src_u,
  857. int src_stride_u,
  858. const uint8_t* src_v,
  859. int src_stride_v,
  860. uint8_t* dst_rgb24,
  861. int dst_stride_rgb24,
  862. int width,
  863. int height) {
  864. return I444ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  865. src_stride_v, dst_rgb24, dst_stride_rgb24,
  866. &kYuvI601Constants, width, height);
  867. }
  868. // Convert I444 to RAW.
  869. LIBYUV_API
  870. int I444ToRAW(const uint8_t* src_y,
  871. int src_stride_y,
  872. const uint8_t* src_u,
  873. int src_stride_u,
  874. const uint8_t* src_v,
  875. int src_stride_v,
  876. uint8_t* dst_raw,
  877. int dst_stride_raw,
  878. int width,
  879. int height) {
  880. return I444ToRGB24Matrix(src_y, src_stride_y, src_v,
  881. src_stride_v, // Swap U and V
  882. src_u, src_stride_u, dst_raw, dst_stride_raw,
  883. &kYvuI601Constants, // Use Yvu matrix
  884. width, height);
  885. }
  886. // Convert 10 bit YUV to ARGB with matrix.
  887. // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to
  888. // multiply 10 bit yuv into high bits to allow any number of bits.
  889. LIBYUV_API
  890. int I010ToAR30Matrix(const uint16_t* src_y,
  891. int src_stride_y,
  892. const uint16_t* src_u,
  893. int src_stride_u,
  894. const uint16_t* src_v,
  895. int src_stride_v,
  896. uint8_t* dst_ar30,
  897. int dst_stride_ar30,
  898. const struct YuvConstants* yuvconstants,
  899. int width,
  900. int height) {
  901. int y;
  902. void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  903. const uint16_t* v_buf, uint8_t* rgb_buf,
  904. const struct YuvConstants* yuvconstants, int width) =
  905. I210ToAR30Row_C;
  906. assert(yuvconstants);
  907. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  908. return -1;
  909. }
  910. // Negative height means invert the image.
  911. if (height < 0) {
  912. height = -height;
  913. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  914. dst_stride_ar30 = -dst_stride_ar30;
  915. }
  916. #if defined(HAS_I210TOAR30ROW_NEON)
  917. if (TestCpuFlag(kCpuHasNEON)) {
  918. I210ToAR30Row = I210ToAR30Row_Any_NEON;
  919. if (IS_ALIGNED(width, 8)) {
  920. I210ToAR30Row = I210ToAR30Row_NEON;
  921. }
  922. }
  923. #endif
  924. #if defined(HAS_I210TOAR30ROW_SSSE3)
  925. if (TestCpuFlag(kCpuHasSSSE3)) {
  926. I210ToAR30Row = I210ToAR30Row_Any_SSSE3;
  927. if (IS_ALIGNED(width, 8)) {
  928. I210ToAR30Row = I210ToAR30Row_SSSE3;
  929. }
  930. }
  931. #endif
  932. #if defined(HAS_I210TOAR30ROW_AVX2)
  933. if (TestCpuFlag(kCpuHasAVX2)) {
  934. I210ToAR30Row = I210ToAR30Row_Any_AVX2;
  935. if (IS_ALIGNED(width, 16)) {
  936. I210ToAR30Row = I210ToAR30Row_AVX2;
  937. }
  938. }
  939. #endif
  940. for (y = 0; y < height; ++y) {
  941. I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  942. dst_ar30 += dst_stride_ar30;
  943. src_y += src_stride_y;
  944. if (y & 1) {
  945. src_u += src_stride_u;
  946. src_v += src_stride_v;
  947. }
  948. }
  949. return 0;
  950. }
  951. // Convert I010 to AR30.
  952. LIBYUV_API
  953. int I010ToAR30(const uint16_t* src_y,
  954. int src_stride_y,
  955. const uint16_t* src_u,
  956. int src_stride_u,
  957. const uint16_t* src_v,
  958. int src_stride_v,
  959. uint8_t* dst_ar30,
  960. int dst_stride_ar30,
  961. int width,
  962. int height) {
  963. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  964. src_stride_v, dst_ar30, dst_stride_ar30,
  965. &kYuvI601Constants, width, height);
  966. }
  967. // Convert H010 to AR30.
  968. LIBYUV_API
  969. int H010ToAR30(const uint16_t* src_y,
  970. int src_stride_y,
  971. const uint16_t* src_u,
  972. int src_stride_u,
  973. const uint16_t* src_v,
  974. int src_stride_v,
  975. uint8_t* dst_ar30,
  976. int dst_stride_ar30,
  977. int width,
  978. int height) {
  979. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  980. src_stride_v, dst_ar30, dst_stride_ar30,
  981. &kYuvH709Constants, width, height);
  982. }
  983. // Convert U010 to AR30.
  984. LIBYUV_API
  985. int U010ToAR30(const uint16_t* src_y,
  986. int src_stride_y,
  987. const uint16_t* src_u,
  988. int src_stride_u,
  989. const uint16_t* src_v,
  990. int src_stride_v,
  991. uint8_t* dst_ar30,
  992. int dst_stride_ar30,
  993. int width,
  994. int height) {
  995. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  996. src_stride_v, dst_ar30, dst_stride_ar30,
  997. &kYuv2020Constants, width, height);
  998. }
  999. // Convert I010 to AB30.
  1000. LIBYUV_API
  1001. int I010ToAB30(const uint16_t* src_y,
  1002. int src_stride_y,
  1003. const uint16_t* src_u,
  1004. int src_stride_u,
  1005. const uint16_t* src_v,
  1006. int src_stride_v,
  1007. uint8_t* dst_ab30,
  1008. int dst_stride_ab30,
  1009. int width,
  1010. int height) {
  1011. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1012. src_stride_u, dst_ab30, dst_stride_ab30,
  1013. &kYvuI601Constants, width, height);
  1014. }
  1015. // Convert H010 to AB30.
  1016. LIBYUV_API
  1017. int H010ToAB30(const uint16_t* src_y,
  1018. int src_stride_y,
  1019. const uint16_t* src_u,
  1020. int src_stride_u,
  1021. const uint16_t* src_v,
  1022. int src_stride_v,
  1023. uint8_t* dst_ab30,
  1024. int dst_stride_ab30,
  1025. int width,
  1026. int height) {
  1027. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1028. src_stride_u, dst_ab30, dst_stride_ab30,
  1029. &kYvuH709Constants, width, height);
  1030. }
  1031. // Convert U010 to AB30.
  1032. LIBYUV_API
  1033. int U010ToAB30(const uint16_t* src_y,
  1034. int src_stride_y,
  1035. const uint16_t* src_u,
  1036. int src_stride_u,
  1037. const uint16_t* src_v,
  1038. int src_stride_v,
  1039. uint8_t* dst_ab30,
  1040. int dst_stride_ab30,
  1041. int width,
  1042. int height) {
  1043. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1044. src_stride_u, dst_ab30, dst_stride_ab30,
  1045. &kYuv2020Constants, width, height);
  1046. }
  1047. // Convert 12 bit YUV to ARGB with matrix.
  1048. // TODO(fbarchard): Consider passing scale multiplier to I212ToARGB to
  1049. // multiply 12 bit yuv into high bits to allow any number of bits.
  1050. LIBYUV_API
  1051. int I012ToAR30Matrix(const uint16_t* src_y,
  1052. int src_stride_y,
  1053. const uint16_t* src_u,
  1054. int src_stride_u,
  1055. const uint16_t* src_v,
  1056. int src_stride_v,
  1057. uint8_t* dst_ar30,
  1058. int dst_stride_ar30,
  1059. const struct YuvConstants* yuvconstants,
  1060. int width,
  1061. int height) {
  1062. int y;
  1063. void (*I212ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  1064. const uint16_t* v_buf, uint8_t* rgb_buf,
  1065. const struct YuvConstants* yuvconstants, int width) =
  1066. I212ToAR30Row_C;
  1067. assert(yuvconstants);
  1068. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  1069. return -1;
  1070. }
  1071. // Negative height means invert the image.
  1072. if (height < 0) {
  1073. height = -height;
  1074. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  1075. dst_stride_ar30 = -dst_stride_ar30;
  1076. }
  1077. #if defined(HAS_I212TOAR30ROW_SSSE3)
  1078. if (TestCpuFlag(kCpuHasSSSE3)) {
  1079. I212ToAR30Row = I212ToAR30Row_Any_SSSE3;
  1080. if (IS_ALIGNED(width, 8)) {
  1081. I212ToAR30Row = I212ToAR30Row_SSSE3;
  1082. }
  1083. }
  1084. #endif
  1085. #if defined(HAS_I212TOAR30ROW_AVX2)
  1086. if (TestCpuFlag(kCpuHasAVX2)) {
  1087. I212ToAR30Row = I212ToAR30Row_Any_AVX2;
  1088. if (IS_ALIGNED(width, 16)) {
  1089. I212ToAR30Row = I212ToAR30Row_AVX2;
  1090. }
  1091. }
  1092. #endif
  1093. #if defined(HAS_I212TOAR30ROW_NEON)
  1094. if (TestCpuFlag(kCpuHasNEON)) {
  1095. I212ToAR30Row = I212ToAR30Row_Any_NEON;
  1096. if (IS_ALIGNED(width, 8)) {
  1097. I212ToAR30Row = I212ToAR30Row_NEON;
  1098. }
  1099. }
  1100. #endif
  1101. for (y = 0; y < height; ++y) {
  1102. I212ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  1103. dst_ar30 += dst_stride_ar30;
  1104. src_y += src_stride_y;
  1105. if (y & 1) {
  1106. src_u += src_stride_u;
  1107. src_v += src_stride_v;
  1108. }
  1109. }
  1110. return 0;
  1111. }
  1112. // Convert 10 bit YUV to ARGB with matrix.
  1113. // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to
  1114. // multiply 10 bit yuv into high bits to allow any number of bits.
  1115. LIBYUV_API
  1116. int I210ToAR30Matrix(const uint16_t* src_y,
  1117. int src_stride_y,
  1118. const uint16_t* src_u,
  1119. int src_stride_u,
  1120. const uint16_t* src_v,
  1121. int src_stride_v,
  1122. uint8_t* dst_ar30,
  1123. int dst_stride_ar30,
  1124. const struct YuvConstants* yuvconstants,
  1125. int width,
  1126. int height) {
  1127. int y;
  1128. void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  1129. const uint16_t* v_buf, uint8_t* rgb_buf,
  1130. const struct YuvConstants* yuvconstants, int width) =
  1131. I210ToAR30Row_C;
  1132. assert(yuvconstants);
  1133. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  1134. return -1;
  1135. }
  1136. // Negative height means invert the image.
  1137. if (height < 0) {
  1138. height = -height;
  1139. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  1140. dst_stride_ar30 = -dst_stride_ar30;
  1141. }
  1142. #if defined(HAS_I210TOAR30ROW_NEON)
  1143. if (TestCpuFlag(kCpuHasNEON)) {
  1144. I210ToAR30Row = I210ToAR30Row_Any_NEON;
  1145. if (IS_ALIGNED(width, 8)) {
  1146. I210ToAR30Row = I210ToAR30Row_NEON;
  1147. }
  1148. }
  1149. #endif
  1150. #if defined(HAS_I210TOAR30ROW_SSSE3)
  1151. if (TestCpuFlag(kCpuHasSSSE3)) {
  1152. I210ToAR30Row = I210ToAR30Row_Any_SSSE3;
  1153. if (IS_ALIGNED(width, 8)) {
  1154. I210ToAR30Row = I210ToAR30Row_SSSE3;
  1155. }
  1156. }
  1157. #endif
  1158. #if defined(HAS_I210TOAR30ROW_AVX2)
  1159. if (TestCpuFlag(kCpuHasAVX2)) {
  1160. I210ToAR30Row = I210ToAR30Row_Any_AVX2;
  1161. if (IS_ALIGNED(width, 16)) {
  1162. I210ToAR30Row = I210ToAR30Row_AVX2;
  1163. }
  1164. }
  1165. #endif
  1166. for (y = 0; y < height; ++y) {
  1167. I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  1168. dst_ar30 += dst_stride_ar30;
  1169. src_y += src_stride_y;
  1170. src_u += src_stride_u;
  1171. src_v += src_stride_v;
  1172. }
  1173. return 0;
  1174. }
  1175. // Convert I210 to AR30.
  1176. LIBYUV_API
  1177. int I210ToAR30(const uint16_t* src_y,
  1178. int src_stride_y,
  1179. const uint16_t* src_u,
  1180. int src_stride_u,
  1181. const uint16_t* src_v,
  1182. int src_stride_v,
  1183. uint8_t* dst_ar30,
  1184. int dst_stride_ar30,
  1185. int width,
  1186. int height) {
  1187. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1188. src_stride_v, dst_ar30, dst_stride_ar30,
  1189. &kYuvI601Constants, width, height);
  1190. }
  1191. // Convert H210 to AR30.
  1192. LIBYUV_API
  1193. int H210ToAR30(const uint16_t* src_y,
  1194. int src_stride_y,
  1195. const uint16_t* src_u,
  1196. int src_stride_u,
  1197. const uint16_t* src_v,
  1198. int src_stride_v,
  1199. uint8_t* dst_ar30,
  1200. int dst_stride_ar30,
  1201. int width,
  1202. int height) {
  1203. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1204. src_stride_v, dst_ar30, dst_stride_ar30,
  1205. &kYuvH709Constants, width, height);
  1206. }
  1207. // Convert U210 to AR30.
  1208. LIBYUV_API
  1209. int U210ToAR30(const uint16_t* src_y,
  1210. int src_stride_y,
  1211. const uint16_t* src_u,
  1212. int src_stride_u,
  1213. const uint16_t* src_v,
  1214. int src_stride_v,
  1215. uint8_t* dst_ar30,
  1216. int dst_stride_ar30,
  1217. int width,
  1218. int height) {
  1219. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1220. src_stride_v, dst_ar30, dst_stride_ar30,
  1221. &kYuv2020Constants, width, height);
  1222. }
  1223. // Convert I210 to AB30.
  1224. LIBYUV_API
  1225. int I210ToAB30(const uint16_t* src_y,
  1226. int src_stride_y,
  1227. const uint16_t* src_u,
  1228. int src_stride_u,
  1229. const uint16_t* src_v,
  1230. int src_stride_v,
  1231. uint8_t* dst_ab30,
  1232. int dst_stride_ab30,
  1233. int width,
  1234. int height) {
  1235. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1236. src_stride_u, dst_ab30, dst_stride_ab30,
  1237. &kYvuI601Constants, width, height);
  1238. }
  1239. // Convert H210 to AB30.
  1240. LIBYUV_API
  1241. int H210ToAB30(const uint16_t* src_y,
  1242. int src_stride_y,
  1243. const uint16_t* src_u,
  1244. int src_stride_u,
  1245. const uint16_t* src_v,
  1246. int src_stride_v,
  1247. uint8_t* dst_ab30,
  1248. int dst_stride_ab30,
  1249. int width,
  1250. int height) {
  1251. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1252. src_stride_u, dst_ab30, dst_stride_ab30,
  1253. &kYvuH709Constants, width, height);
  1254. }
  1255. // Convert U210 to AB30.
  1256. LIBYUV_API
  1257. int U210ToAB30(const uint16_t* src_y,
  1258. int src_stride_y,
  1259. const uint16_t* src_u,
  1260. int src_stride_u,
  1261. const uint16_t* src_v,
  1262. int src_stride_v,
  1263. uint8_t* dst_ab30,
  1264. int dst_stride_ab30,
  1265. int width,
  1266. int height) {
  1267. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  1268. src_stride_u, dst_ab30, dst_stride_ab30,
  1269. &kYuv2020Constants, width, height);
  1270. }
  1271. LIBYUV_API
  1272. int I410ToAR30Matrix(const uint16_t* src_y,
  1273. int src_stride_y,
  1274. const uint16_t* src_u,
  1275. int src_stride_u,
  1276. const uint16_t* src_v,
  1277. int src_stride_v,
  1278. uint8_t* dst_ar30,
  1279. int dst_stride_ar30,
  1280. const struct YuvConstants* yuvconstants,
  1281. int width,
  1282. int height) {
  1283. int y;
  1284. void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  1285. const uint16_t* v_buf, uint8_t* rgb_buf,
  1286. const struct YuvConstants* yuvconstants, int width) =
  1287. I410ToAR30Row_C;
  1288. assert(yuvconstants);
  1289. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  1290. return -1;
  1291. }
  1292. // Negative height means invert the image.
  1293. if (height < 0) {
  1294. height = -height;
  1295. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  1296. dst_stride_ar30 = -dst_stride_ar30;
  1297. }
  1298. #if defined(HAS_I410TOAR30ROW_NEON)
  1299. if (TestCpuFlag(kCpuHasNEON)) {
  1300. I410ToAR30Row = I410ToAR30Row_Any_NEON;
  1301. if (IS_ALIGNED(width, 8)) {
  1302. I410ToAR30Row = I410ToAR30Row_NEON;
  1303. }
  1304. }
  1305. #endif
  1306. #if defined(HAS_I410TOAR30ROW_SSSE3)
  1307. if (TestCpuFlag(kCpuHasSSSE3)) {
  1308. I410ToAR30Row = I410ToAR30Row_Any_SSSE3;
  1309. if (IS_ALIGNED(width, 8)) {
  1310. I410ToAR30Row = I410ToAR30Row_SSSE3;
  1311. }
  1312. }
  1313. #endif
  1314. #if defined(HAS_I410TOAR30ROW_AVX2)
  1315. if (TestCpuFlag(kCpuHasAVX2)) {
  1316. I410ToAR30Row = I410ToAR30Row_Any_AVX2;
  1317. if (IS_ALIGNED(width, 16)) {
  1318. I410ToAR30Row = I410ToAR30Row_AVX2;
  1319. }
  1320. }
  1321. #endif
  1322. for (y = 0; y < height; ++y) {
  1323. I410ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  1324. dst_ar30 += dst_stride_ar30;
  1325. src_y += src_stride_y;
  1326. src_u += src_stride_u;
  1327. src_v += src_stride_v;
  1328. }
  1329. return 0;
  1330. }
  1331. // Convert 10 bit YUV to ARGB with matrix.
  1332. LIBYUV_API
  1333. int I010ToARGBMatrix(const uint16_t* src_y,
  1334. int src_stride_y,
  1335. const uint16_t* src_u,
  1336. int src_stride_u,
  1337. const uint16_t* src_v,
  1338. int src_stride_v,
  1339. uint8_t* dst_argb,
  1340. int dst_stride_argb,
  1341. const struct YuvConstants* yuvconstants,
  1342. int width,
  1343. int height) {
  1344. int y;
  1345. void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1346. const uint16_t* v_buf, uint8_t* rgb_buf,
  1347. const struct YuvConstants* yuvconstants, int width) =
  1348. I210ToARGBRow_C;
  1349. assert(yuvconstants);
  1350. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1351. return -1;
  1352. }
  1353. // Negative height means invert the image.
  1354. if (height < 0) {
  1355. height = -height;
  1356. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1357. dst_stride_argb = -dst_stride_argb;
  1358. }
  1359. #if defined(HAS_I210TOARGBROW_SSSE3)
  1360. if (TestCpuFlag(kCpuHasSSSE3)) {
  1361. I210ToARGBRow = I210ToARGBRow_Any_SSSE3;
  1362. if (IS_ALIGNED(width, 8)) {
  1363. I210ToARGBRow = I210ToARGBRow_SSSE3;
  1364. }
  1365. }
  1366. #endif
  1367. #if defined(HAS_I210TOARGBROW_NEON)
  1368. if (TestCpuFlag(kCpuHasNEON)) {
  1369. I210ToARGBRow = I210ToARGBRow_Any_NEON;
  1370. if (IS_ALIGNED(width, 8)) {
  1371. I210ToARGBRow = I210ToARGBRow_NEON;
  1372. }
  1373. }
  1374. #endif
  1375. #if defined(HAS_I210TOARGBROW_AVX2)
  1376. if (TestCpuFlag(kCpuHasAVX2)) {
  1377. I210ToARGBRow = I210ToARGBRow_Any_AVX2;
  1378. if (IS_ALIGNED(width, 16)) {
  1379. I210ToARGBRow = I210ToARGBRow_AVX2;
  1380. }
  1381. }
  1382. #endif
  1383. for (y = 0; y < height; ++y) {
  1384. I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1385. dst_argb += dst_stride_argb;
  1386. src_y += src_stride_y;
  1387. if (y & 1) {
  1388. src_u += src_stride_u;
  1389. src_v += src_stride_v;
  1390. }
  1391. }
  1392. return 0;
  1393. }
  1394. // Convert I010 to ARGB.
  1395. LIBYUV_API
  1396. int I010ToARGB(const uint16_t* src_y,
  1397. int src_stride_y,
  1398. const uint16_t* src_u,
  1399. int src_stride_u,
  1400. const uint16_t* src_v,
  1401. int src_stride_v,
  1402. uint8_t* dst_argb,
  1403. int dst_stride_argb,
  1404. int width,
  1405. int height) {
  1406. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1407. src_stride_v, dst_argb, dst_stride_argb,
  1408. &kYuvI601Constants, width, height);
  1409. }
  1410. // Convert I010 to ABGR.
  1411. LIBYUV_API
  1412. int I010ToABGR(const uint16_t* src_y,
  1413. int src_stride_y,
  1414. const uint16_t* src_u,
  1415. int src_stride_u,
  1416. const uint16_t* src_v,
  1417. int src_stride_v,
  1418. uint8_t* dst_abgr,
  1419. int dst_stride_abgr,
  1420. int width,
  1421. int height) {
  1422. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1423. src_stride_v, // Swap U and V
  1424. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1425. &kYvuI601Constants, // Use Yvu matrix
  1426. width, height);
  1427. }
  1428. // Convert H010 to ARGB.
  1429. LIBYUV_API
  1430. int H010ToARGB(const uint16_t* src_y,
  1431. int src_stride_y,
  1432. const uint16_t* src_u,
  1433. int src_stride_u,
  1434. const uint16_t* src_v,
  1435. int src_stride_v,
  1436. uint8_t* dst_argb,
  1437. int dst_stride_argb,
  1438. int width,
  1439. int height) {
  1440. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1441. src_stride_v, dst_argb, dst_stride_argb,
  1442. &kYuvH709Constants, width, height);
  1443. }
  1444. // Convert H010 to ABGR.
  1445. LIBYUV_API
  1446. int H010ToABGR(const uint16_t* src_y,
  1447. int src_stride_y,
  1448. const uint16_t* src_u,
  1449. int src_stride_u,
  1450. const uint16_t* src_v,
  1451. int src_stride_v,
  1452. uint8_t* dst_abgr,
  1453. int dst_stride_abgr,
  1454. int width,
  1455. int height) {
  1456. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1457. src_stride_v, // Swap U and V
  1458. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1459. &kYvuH709Constants, // Use Yvu matrix
  1460. width, height);
  1461. }
  1462. // Convert U010 to ARGB.
  1463. LIBYUV_API
  1464. int U010ToARGB(const uint16_t* src_y,
  1465. int src_stride_y,
  1466. const uint16_t* src_u,
  1467. int src_stride_u,
  1468. const uint16_t* src_v,
  1469. int src_stride_v,
  1470. uint8_t* dst_argb,
  1471. int dst_stride_argb,
  1472. int width,
  1473. int height) {
  1474. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1475. src_stride_v, dst_argb, dst_stride_argb,
  1476. &kYuv2020Constants, width, height);
  1477. }
  1478. // Convert U010 to ABGR.
  1479. LIBYUV_API
  1480. int U010ToABGR(const uint16_t* src_y,
  1481. int src_stride_y,
  1482. const uint16_t* src_u,
  1483. int src_stride_u,
  1484. const uint16_t* src_v,
  1485. int src_stride_v,
  1486. uint8_t* dst_abgr,
  1487. int dst_stride_abgr,
  1488. int width,
  1489. int height) {
  1490. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1491. src_stride_v, // Swap U and V
  1492. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1493. &kYvu2020Constants, // Use Yvu matrix
  1494. width, height);
  1495. }
  1496. // Convert 12 bit YUV to ARGB with matrix.
  1497. LIBYUV_API
  1498. int I012ToARGBMatrix(const uint16_t* src_y,
  1499. int src_stride_y,
  1500. const uint16_t* src_u,
  1501. int src_stride_u,
  1502. const uint16_t* src_v,
  1503. int src_stride_v,
  1504. uint8_t* dst_argb,
  1505. int dst_stride_argb,
  1506. const struct YuvConstants* yuvconstants,
  1507. int width,
  1508. int height) {
  1509. int y;
  1510. void (*I212ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1511. const uint16_t* v_buf, uint8_t* rgb_buf,
  1512. const struct YuvConstants* yuvconstants, int width) =
  1513. I212ToARGBRow_C;
  1514. assert(yuvconstants);
  1515. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1516. return -1;
  1517. }
  1518. // Negative height means invert the image.
  1519. if (height < 0) {
  1520. height = -height;
  1521. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1522. dst_stride_argb = -dst_stride_argb;
  1523. }
  1524. #if defined(HAS_I212TOARGBROW_SSSE3)
  1525. if (TestCpuFlag(kCpuHasSSSE3)) {
  1526. I212ToARGBRow = I212ToARGBRow_Any_SSSE3;
  1527. if (IS_ALIGNED(width, 8)) {
  1528. I212ToARGBRow = I212ToARGBRow_SSSE3;
  1529. }
  1530. }
  1531. #endif
  1532. #if defined(HAS_I212TOARGBROW_AVX2)
  1533. if (TestCpuFlag(kCpuHasAVX2)) {
  1534. I212ToARGBRow = I212ToARGBRow_Any_AVX2;
  1535. if (IS_ALIGNED(width, 16)) {
  1536. I212ToARGBRow = I212ToARGBRow_AVX2;
  1537. }
  1538. }
  1539. #endif
  1540. #if defined(HAS_I212TOARGBROW_NEON)
  1541. if (TestCpuFlag(kCpuHasNEON)) {
  1542. I212ToARGBRow = I212ToARGBRow_Any_NEON;
  1543. if (IS_ALIGNED(width, 8)) {
  1544. I212ToARGBRow = I212ToARGBRow_NEON;
  1545. }
  1546. }
  1547. #endif
  1548. for (y = 0; y < height; ++y) {
  1549. I212ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1550. dst_argb += dst_stride_argb;
  1551. src_y += src_stride_y;
  1552. if (y & 1) {
  1553. src_u += src_stride_u;
  1554. src_v += src_stride_v;
  1555. }
  1556. }
  1557. return 0;
  1558. }
  1559. // Convert 10 bit 422 YUV to ARGB with matrix.
  1560. LIBYUV_API
  1561. int I210ToARGBMatrix(const uint16_t* src_y,
  1562. int src_stride_y,
  1563. const uint16_t* src_u,
  1564. int src_stride_u,
  1565. const uint16_t* src_v,
  1566. int src_stride_v,
  1567. uint8_t* dst_argb,
  1568. int dst_stride_argb,
  1569. const struct YuvConstants* yuvconstants,
  1570. int width,
  1571. int height) {
  1572. int y;
  1573. void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1574. const uint16_t* v_buf, uint8_t* rgb_buf,
  1575. const struct YuvConstants* yuvconstants, int width) =
  1576. I210ToARGBRow_C;
  1577. assert(yuvconstants);
  1578. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1579. return -1;
  1580. }
  1581. // Negative height means invert the image.
  1582. if (height < 0) {
  1583. height = -height;
  1584. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1585. dst_stride_argb = -dst_stride_argb;
  1586. }
  1587. #if defined(HAS_I210TOARGBROW_SSSE3)
  1588. if (TestCpuFlag(kCpuHasSSSE3)) {
  1589. I210ToARGBRow = I210ToARGBRow_Any_SSSE3;
  1590. if (IS_ALIGNED(width, 8)) {
  1591. I210ToARGBRow = I210ToARGBRow_SSSE3;
  1592. }
  1593. }
  1594. #endif
  1595. #if defined(HAS_I210TOARGBROW_NEON)
  1596. if (TestCpuFlag(kCpuHasNEON)) {
  1597. I210ToARGBRow = I210ToARGBRow_Any_NEON;
  1598. if (IS_ALIGNED(width, 8)) {
  1599. I210ToARGBRow = I210ToARGBRow_NEON;
  1600. }
  1601. }
  1602. #endif
  1603. #if defined(HAS_I210TOARGBROW_AVX2)
  1604. if (TestCpuFlag(kCpuHasAVX2)) {
  1605. I210ToARGBRow = I210ToARGBRow_Any_AVX2;
  1606. if (IS_ALIGNED(width, 16)) {
  1607. I210ToARGBRow = I210ToARGBRow_AVX2;
  1608. }
  1609. }
  1610. #endif
  1611. for (y = 0; y < height; ++y) {
  1612. I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1613. dst_argb += dst_stride_argb;
  1614. src_y += src_stride_y;
  1615. src_u += src_stride_u;
  1616. src_v += src_stride_v;
  1617. }
  1618. return 0;
  1619. }
  1620. // Convert I210 to ARGB.
  1621. LIBYUV_API
  1622. int I210ToARGB(const uint16_t* src_y,
  1623. int src_stride_y,
  1624. const uint16_t* src_u,
  1625. int src_stride_u,
  1626. const uint16_t* src_v,
  1627. int src_stride_v,
  1628. uint8_t* dst_argb,
  1629. int dst_stride_argb,
  1630. int width,
  1631. int height) {
  1632. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1633. src_stride_v, dst_argb, dst_stride_argb,
  1634. &kYuvI601Constants, width, height);
  1635. }
  1636. // Convert I210 to ABGR.
  1637. LIBYUV_API
  1638. int I210ToABGR(const uint16_t* src_y,
  1639. int src_stride_y,
  1640. const uint16_t* src_u,
  1641. int src_stride_u,
  1642. const uint16_t* src_v,
  1643. int src_stride_v,
  1644. uint8_t* dst_abgr,
  1645. int dst_stride_abgr,
  1646. int width,
  1647. int height) {
  1648. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1649. src_stride_v, // Swap U and V
  1650. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1651. &kYvuI601Constants, // Use Yvu matrix
  1652. width, height);
  1653. }
  1654. // Convert H210 to ARGB.
  1655. LIBYUV_API
  1656. int H210ToARGB(const uint16_t* src_y,
  1657. int src_stride_y,
  1658. const uint16_t* src_u,
  1659. int src_stride_u,
  1660. const uint16_t* src_v,
  1661. int src_stride_v,
  1662. uint8_t* dst_argb,
  1663. int dst_stride_argb,
  1664. int width,
  1665. int height) {
  1666. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1667. src_stride_v, dst_argb, dst_stride_argb,
  1668. &kYuvH709Constants, width, height);
  1669. }
  1670. // Convert H210 to ABGR.
  1671. LIBYUV_API
  1672. int H210ToABGR(const uint16_t* src_y,
  1673. int src_stride_y,
  1674. const uint16_t* src_u,
  1675. int src_stride_u,
  1676. const uint16_t* src_v,
  1677. int src_stride_v,
  1678. uint8_t* dst_abgr,
  1679. int dst_stride_abgr,
  1680. int width,
  1681. int height) {
  1682. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1683. src_stride_v, // Swap U and V
  1684. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1685. &kYvuH709Constants, // Use Yvu matrix
  1686. width, height);
  1687. }
  1688. // Convert U210 to ARGB.
  1689. LIBYUV_API
  1690. int U210ToARGB(const uint16_t* src_y,
  1691. int src_stride_y,
  1692. const uint16_t* src_u,
  1693. int src_stride_u,
  1694. const uint16_t* src_v,
  1695. int src_stride_v,
  1696. uint8_t* dst_argb,
  1697. int dst_stride_argb,
  1698. int width,
  1699. int height) {
  1700. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1701. src_stride_v, dst_argb, dst_stride_argb,
  1702. &kYuv2020Constants, width, height);
  1703. }
  1704. // Convert U210 to ABGR.
  1705. LIBYUV_API
  1706. int U210ToABGR(const uint16_t* src_y,
  1707. int src_stride_y,
  1708. const uint16_t* src_u,
  1709. int src_stride_u,
  1710. const uint16_t* src_v,
  1711. int src_stride_v,
  1712. uint8_t* dst_abgr,
  1713. int dst_stride_abgr,
  1714. int width,
  1715. int height) {
  1716. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1717. src_stride_v, // Swap U and V
  1718. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1719. &kYvu2020Constants, // Use Yvu matrix
  1720. width, height);
  1721. }
  1722. LIBYUV_API
  1723. int I410ToARGBMatrix(const uint16_t* src_y,
  1724. int src_stride_y,
  1725. const uint16_t* src_u,
  1726. int src_stride_u,
  1727. const uint16_t* src_v,
  1728. int src_stride_v,
  1729. uint8_t* dst_argb,
  1730. int dst_stride_argb,
  1731. const struct YuvConstants* yuvconstants,
  1732. int width,
  1733. int height) {
  1734. int y;
  1735. void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1736. const uint16_t* v_buf, uint8_t* rgb_buf,
  1737. const struct YuvConstants* yuvconstants, int width) =
  1738. I410ToARGBRow_C;
  1739. assert(yuvconstants);
  1740. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1741. return -1;
  1742. }
  1743. // Negative height means invert the image.
  1744. if (height < 0) {
  1745. height = -height;
  1746. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1747. dst_stride_argb = -dst_stride_argb;
  1748. }
  1749. #if defined(HAS_I410TOARGBROW_SSSE3)
  1750. if (TestCpuFlag(kCpuHasSSSE3)) {
  1751. I410ToARGBRow = I410ToARGBRow_Any_SSSE3;
  1752. if (IS_ALIGNED(width, 8)) {
  1753. I410ToARGBRow = I410ToARGBRow_SSSE3;
  1754. }
  1755. }
  1756. #endif
  1757. #if defined(HAS_I410TOARGBROW_NEON)
  1758. if (TestCpuFlag(kCpuHasNEON)) {
  1759. I410ToARGBRow = I410ToARGBRow_Any_NEON;
  1760. if (IS_ALIGNED(width, 8)) {
  1761. I410ToARGBRow = I410ToARGBRow_NEON;
  1762. }
  1763. }
  1764. #endif
  1765. #if defined(HAS_I410TOARGBROW_AVX2)
  1766. if (TestCpuFlag(kCpuHasAVX2)) {
  1767. I410ToARGBRow = I410ToARGBRow_Any_AVX2;
  1768. if (IS_ALIGNED(width, 16)) {
  1769. I410ToARGBRow = I410ToARGBRow_AVX2;
  1770. }
  1771. }
  1772. #endif
  1773. for (y = 0; y < height; ++y) {
  1774. I410ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1775. dst_argb += dst_stride_argb;
  1776. src_y += src_stride_y;
  1777. src_u += src_stride_u;
  1778. src_v += src_stride_v;
  1779. }
  1780. return 0;
  1781. }
  1782. LIBYUV_API
  1783. int P010ToARGBMatrix(const uint16_t* src_y,
  1784. int src_stride_y,
  1785. const uint16_t* src_uv,
  1786. int src_stride_uv,
  1787. uint8_t* dst_argb,
  1788. int dst_stride_argb,
  1789. const struct YuvConstants* yuvconstants,
  1790. int width,
  1791. int height) {
  1792. int y;
  1793. void (*P210ToARGBRow)(
  1794. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  1795. const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C;
  1796. assert(yuvconstants);
  1797. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  1798. return -1;
  1799. }
  1800. // Negative height means invert the image.
  1801. if (height < 0) {
  1802. height = -height;
  1803. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1804. dst_stride_argb = -dst_stride_argb;
  1805. }
  1806. #if defined(HAS_P210TOARGBROW_SSSE3)
  1807. if (TestCpuFlag(kCpuHasSSSE3)) {
  1808. P210ToARGBRow = P210ToARGBRow_Any_SSSE3;
  1809. if (IS_ALIGNED(width, 8)) {
  1810. P210ToARGBRow = P210ToARGBRow_SSSE3;
  1811. }
  1812. }
  1813. #endif
  1814. #if defined(HAS_P210TOARGBROW_AVX2)
  1815. if (TestCpuFlag(kCpuHasAVX2)) {
  1816. P210ToARGBRow = P210ToARGBRow_Any_AVX2;
  1817. if (IS_ALIGNED(width, 16)) {
  1818. P210ToARGBRow = P210ToARGBRow_AVX2;
  1819. }
  1820. }
  1821. #endif
  1822. #if defined(HAS_P210TOARGBROW_NEON)
  1823. if (TestCpuFlag(kCpuHasNEON)) {
  1824. P210ToARGBRow = P210ToARGBRow_Any_NEON;
  1825. if (IS_ALIGNED(width, 8)) {
  1826. P210ToARGBRow = P210ToARGBRow_NEON;
  1827. }
  1828. }
  1829. #endif
  1830. for (y = 0; y < height; ++y) {
  1831. P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width);
  1832. dst_argb += dst_stride_argb;
  1833. src_y += src_stride_y;
  1834. if (y & 1) {
  1835. src_uv += src_stride_uv;
  1836. }
  1837. }
  1838. return 0;
  1839. }
  1840. LIBYUV_API
  1841. int P210ToARGBMatrix(const uint16_t* src_y,
  1842. int src_stride_y,
  1843. const uint16_t* src_uv,
  1844. int src_stride_uv,
  1845. uint8_t* dst_argb,
  1846. int dst_stride_argb,
  1847. const struct YuvConstants* yuvconstants,
  1848. int width,
  1849. int height) {
  1850. int y;
  1851. void (*P210ToARGBRow)(
  1852. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  1853. const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C;
  1854. assert(yuvconstants);
  1855. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  1856. return -1;
  1857. }
  1858. // Negative height means invert the image.
  1859. if (height < 0) {
  1860. height = -height;
  1861. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1862. dst_stride_argb = -dst_stride_argb;
  1863. }
  1864. #if defined(HAS_P210TOARGBROW_SSSE3)
  1865. if (TestCpuFlag(kCpuHasSSSE3)) {
  1866. P210ToARGBRow = P210ToARGBRow_Any_SSSE3;
  1867. if (IS_ALIGNED(width, 8)) {
  1868. P210ToARGBRow = P210ToARGBRow_SSSE3;
  1869. }
  1870. }
  1871. #endif
  1872. #if defined(HAS_P210TOARGBROW_AVX2)
  1873. if (TestCpuFlag(kCpuHasAVX2)) {
  1874. P210ToARGBRow = P210ToARGBRow_Any_AVX2;
  1875. if (IS_ALIGNED(width, 16)) {
  1876. P210ToARGBRow = P210ToARGBRow_AVX2;
  1877. }
  1878. }
  1879. #endif
  1880. #if defined(HAS_P210TOARGBROW_NEON)
  1881. if (TestCpuFlag(kCpuHasNEON)) {
  1882. P210ToARGBRow = P210ToARGBRow_Any_NEON;
  1883. if (IS_ALIGNED(width, 8)) {
  1884. P210ToARGBRow = P210ToARGBRow_NEON;
  1885. }
  1886. }
  1887. #endif
  1888. for (y = 0; y < height; ++y) {
  1889. P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width);
  1890. dst_argb += dst_stride_argb;
  1891. src_y += src_stride_y;
  1892. src_uv += src_stride_uv;
  1893. }
  1894. return 0;
  1895. }
  1896. LIBYUV_API
  1897. int P010ToAR30Matrix(const uint16_t* src_y,
  1898. int src_stride_y,
  1899. const uint16_t* src_uv,
  1900. int src_stride_uv,
  1901. uint8_t* dst_ar30,
  1902. int dst_stride_ar30,
  1903. const struct YuvConstants* yuvconstants,
  1904. int width,
  1905. int height) {
  1906. int y;
  1907. void (*P210ToAR30Row)(
  1908. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  1909. const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C;
  1910. assert(yuvconstants);
  1911. if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) {
  1912. return -1;
  1913. }
  1914. // Negative height means invert the image.
  1915. if (height < 0) {
  1916. height = -height;
  1917. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  1918. dst_stride_ar30 = -dst_stride_ar30;
  1919. }
  1920. #if defined(HAS_P210TOAR30ROW_SSSE3)
  1921. if (TestCpuFlag(kCpuHasSSSE3)) {
  1922. P210ToAR30Row = P210ToAR30Row_Any_SSSE3;
  1923. if (IS_ALIGNED(width, 8)) {
  1924. P210ToAR30Row = P210ToAR30Row_SSSE3;
  1925. }
  1926. }
  1927. #endif
  1928. #if defined(HAS_P210TOAR30ROW_AVX2)
  1929. if (TestCpuFlag(kCpuHasAVX2)) {
  1930. P210ToAR30Row = P210ToAR30Row_Any_AVX2;
  1931. if (IS_ALIGNED(width, 16)) {
  1932. P210ToAR30Row = P210ToAR30Row_AVX2;
  1933. }
  1934. }
  1935. #endif
  1936. #if defined(HAS_P210TOAR30ROW_NEON)
  1937. if (TestCpuFlag(kCpuHasNEON)) {
  1938. P210ToAR30Row = P210ToAR30Row_Any_NEON;
  1939. if (IS_ALIGNED(width, 8)) {
  1940. P210ToAR30Row = P210ToAR30Row_NEON;
  1941. }
  1942. }
  1943. #endif
  1944. for (y = 0; y < height; ++y) {
  1945. P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width);
  1946. dst_ar30 += dst_stride_ar30;
  1947. src_y += src_stride_y;
  1948. if (y & 1) {
  1949. src_uv += src_stride_uv;
  1950. }
  1951. }
  1952. return 0;
  1953. }
  1954. LIBYUV_API
  1955. int P210ToAR30Matrix(const uint16_t* src_y,
  1956. int src_stride_y,
  1957. const uint16_t* src_uv,
  1958. int src_stride_uv,
  1959. uint8_t* dst_ar30,
  1960. int dst_stride_ar30,
  1961. const struct YuvConstants* yuvconstants,
  1962. int width,
  1963. int height) {
  1964. int y;
  1965. void (*P210ToAR30Row)(
  1966. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  1967. const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C;
  1968. assert(yuvconstants);
  1969. if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) {
  1970. return -1;
  1971. }
  1972. // Negative height means invert the image.
  1973. if (height < 0) {
  1974. height = -height;
  1975. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  1976. dst_stride_ar30 = -dst_stride_ar30;
  1977. }
  1978. #if defined(HAS_P210TOAR30ROW_SSSE3)
  1979. if (TestCpuFlag(kCpuHasSSSE3)) {
  1980. P210ToAR30Row = P210ToAR30Row_Any_SSSE3;
  1981. if (IS_ALIGNED(width, 8)) {
  1982. P210ToAR30Row = P210ToAR30Row_SSSE3;
  1983. }
  1984. }
  1985. #endif
  1986. #if defined(HAS_P210TOAR30ROW_AVX2)
  1987. if (TestCpuFlag(kCpuHasAVX2)) {
  1988. P210ToAR30Row = P210ToAR30Row_Any_AVX2;
  1989. if (IS_ALIGNED(width, 16)) {
  1990. P210ToAR30Row = P210ToAR30Row_AVX2;
  1991. }
  1992. }
  1993. #endif
  1994. #if defined(HAS_P210TOAR30ROW_NEON)
  1995. if (TestCpuFlag(kCpuHasNEON)) {
  1996. P210ToAR30Row = P210ToAR30Row_Any_NEON;
  1997. if (IS_ALIGNED(width, 8)) {
  1998. P210ToAR30Row = P210ToAR30Row_NEON;
  1999. }
  2000. }
  2001. #endif
  2002. for (y = 0; y < height; ++y) {
  2003. P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width);
  2004. dst_ar30 += dst_stride_ar30;
  2005. src_y += src_stride_y;
  2006. src_uv += src_stride_uv;
  2007. }
  2008. return 0;
  2009. }
  2010. // Convert I420 with Alpha to preattenuated ARGB with matrix.
  2011. LIBYUV_API
  2012. int I420AlphaToARGBMatrix(const uint8_t* src_y,
  2013. int src_stride_y,
  2014. const uint8_t* src_u,
  2015. int src_stride_u,
  2016. const uint8_t* src_v,
  2017. int src_stride_v,
  2018. const uint8_t* src_a,
  2019. int src_stride_a,
  2020. uint8_t* dst_argb,
  2021. int dst_stride_argb,
  2022. const struct YuvConstants* yuvconstants,
  2023. int width,
  2024. int height,
  2025. int attenuate) {
  2026. int y;
  2027. void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  2028. const uint8_t* v_buf, const uint8_t* a_buf,
  2029. uint8_t* dst_argb,
  2030. const struct YuvConstants* yuvconstants,
  2031. int width) = I422AlphaToARGBRow_C;
  2032. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2033. int width) = ARGBAttenuateRow_C;
  2034. assert(yuvconstants);
  2035. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2036. height == 0) {
  2037. return -1;
  2038. }
  2039. // Negative height means invert the image.
  2040. if (height < 0) {
  2041. height = -height;
  2042. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2043. dst_stride_argb = -dst_stride_argb;
  2044. }
  2045. #if defined(HAS_I422ALPHATOARGBROW_SSSE3)
  2046. if (TestCpuFlag(kCpuHasSSSE3)) {
  2047. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3;
  2048. if (IS_ALIGNED(width, 8)) {
  2049. I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3;
  2050. }
  2051. }
  2052. #endif
  2053. #if defined(HAS_I422ALPHATOARGBROW_AVX2)
  2054. if (TestCpuFlag(kCpuHasAVX2)) {
  2055. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2;
  2056. if (IS_ALIGNED(width, 16)) {
  2057. I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2;
  2058. }
  2059. }
  2060. #endif
  2061. #if defined(HAS_I422ALPHATOARGBROW_NEON)
  2062. if (TestCpuFlag(kCpuHasNEON)) {
  2063. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON;
  2064. if (IS_ALIGNED(width, 8)) {
  2065. I422AlphaToARGBRow = I422AlphaToARGBRow_NEON;
  2066. }
  2067. }
  2068. #endif
  2069. #if defined(HAS_I422ALPHATOARGBROW_SVE2)
  2070. if (TestCpuFlag(kCpuHasSVE2)) {
  2071. I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2;
  2072. }
  2073. #endif
  2074. #if defined(HAS_I422ALPHATOARGBROW_MSA)
  2075. if (TestCpuFlag(kCpuHasMSA)) {
  2076. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_MSA;
  2077. if (IS_ALIGNED(width, 8)) {
  2078. I422AlphaToARGBRow = I422AlphaToARGBRow_MSA;
  2079. }
  2080. }
  2081. #endif
  2082. #if defined(HAS_I422ALPHATOARGBROW_LSX)
  2083. if (TestCpuFlag(kCpuHasLSX)) {
  2084. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX;
  2085. if (IS_ALIGNED(width, 16)) {
  2086. I422AlphaToARGBRow = I422AlphaToARGBRow_LSX;
  2087. }
  2088. }
  2089. #endif
  2090. #if defined(HAS_I422ALPHATOARGBROW_LASX)
  2091. if (TestCpuFlag(kCpuHasLASX)) {
  2092. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX;
  2093. if (IS_ALIGNED(width, 16)) {
  2094. I422AlphaToARGBRow = I422AlphaToARGBRow_LASX;
  2095. }
  2096. }
  2097. #endif
  2098. #if defined(HAS_I422ALPHATOARGBROW_RVV)
  2099. if (TestCpuFlag(kCpuHasRVV)) {
  2100. I422AlphaToARGBRow = I422AlphaToARGBRow_RVV;
  2101. }
  2102. #endif
  2103. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2104. if (TestCpuFlag(kCpuHasSSSE3)) {
  2105. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2106. if (IS_ALIGNED(width, 4)) {
  2107. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2108. }
  2109. }
  2110. #endif
  2111. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2112. if (TestCpuFlag(kCpuHasAVX2)) {
  2113. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2114. if (IS_ALIGNED(width, 8)) {
  2115. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2116. }
  2117. }
  2118. #endif
  2119. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2120. if (TestCpuFlag(kCpuHasNEON)) {
  2121. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2122. if (IS_ALIGNED(width, 8)) {
  2123. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2124. }
  2125. }
  2126. #endif
  2127. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2128. if (TestCpuFlag(kCpuHasMSA)) {
  2129. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2130. if (IS_ALIGNED(width, 8)) {
  2131. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2132. }
  2133. }
  2134. #endif
  2135. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2136. if (TestCpuFlag(kCpuHasRVV)) {
  2137. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2138. }
  2139. #endif
  2140. for (y = 0; y < height; ++y) {
  2141. I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2142. width);
  2143. if (attenuate) {
  2144. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2145. }
  2146. dst_argb += dst_stride_argb;
  2147. src_a += src_stride_a;
  2148. src_y += src_stride_y;
  2149. if (y & 1) {
  2150. src_u += src_stride_u;
  2151. src_v += src_stride_v;
  2152. }
  2153. }
  2154. return 0;
  2155. }
  2156. // Convert I422 with Alpha to preattenuated ARGB with matrix.
  2157. LIBYUV_API
  2158. int I422AlphaToARGBMatrix(const uint8_t* src_y,
  2159. int src_stride_y,
  2160. const uint8_t* src_u,
  2161. int src_stride_u,
  2162. const uint8_t* src_v,
  2163. int src_stride_v,
  2164. const uint8_t* src_a,
  2165. int src_stride_a,
  2166. uint8_t* dst_argb,
  2167. int dst_stride_argb,
  2168. const struct YuvConstants* yuvconstants,
  2169. int width,
  2170. int height,
  2171. int attenuate) {
  2172. int y;
  2173. void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  2174. const uint8_t* v_buf, const uint8_t* a_buf,
  2175. uint8_t* dst_argb,
  2176. const struct YuvConstants* yuvconstants,
  2177. int width) = I422AlphaToARGBRow_C;
  2178. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2179. int width) = ARGBAttenuateRow_C;
  2180. assert(yuvconstants);
  2181. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2182. height == 0) {
  2183. return -1;
  2184. }
  2185. // Negative height means invert the image.
  2186. if (height < 0) {
  2187. height = -height;
  2188. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2189. dst_stride_argb = -dst_stride_argb;
  2190. }
  2191. #if defined(HAS_I422ALPHATOARGBROW_SSSE3)
  2192. if (TestCpuFlag(kCpuHasSSSE3)) {
  2193. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3;
  2194. if (IS_ALIGNED(width, 8)) {
  2195. I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3;
  2196. }
  2197. }
  2198. #endif
  2199. #if defined(HAS_I422ALPHATOARGBROW_AVX2)
  2200. if (TestCpuFlag(kCpuHasAVX2)) {
  2201. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2;
  2202. if (IS_ALIGNED(width, 16)) {
  2203. I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2;
  2204. }
  2205. }
  2206. #endif
  2207. #if defined(HAS_I422ALPHATOARGBROW_NEON)
  2208. if (TestCpuFlag(kCpuHasNEON)) {
  2209. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON;
  2210. if (IS_ALIGNED(width, 8)) {
  2211. I422AlphaToARGBRow = I422AlphaToARGBRow_NEON;
  2212. }
  2213. }
  2214. #endif
  2215. #if defined(HAS_I422ALPHATOARGBROW_SVE2)
  2216. if (TestCpuFlag(kCpuHasSVE2)) {
  2217. I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2;
  2218. }
  2219. #endif
  2220. #if defined(HAS_I422ALPHATOARGBROW_MSA)
  2221. if (TestCpuFlag(kCpuHasMSA)) {
  2222. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_MSA;
  2223. if (IS_ALIGNED(width, 8)) {
  2224. I422AlphaToARGBRow = I422AlphaToARGBRow_MSA;
  2225. }
  2226. }
  2227. #endif
  2228. #if defined(HAS_I422ALPHATOARGBROW_LSX)
  2229. if (TestCpuFlag(kCpuHasLSX)) {
  2230. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX;
  2231. if (IS_ALIGNED(width, 16)) {
  2232. I422AlphaToARGBRow = I422AlphaToARGBRow_LSX;
  2233. }
  2234. }
  2235. #endif
  2236. #if defined(HAS_I422ALPHATOARGBROW_LASX)
  2237. if (TestCpuFlag(kCpuHasLASX)) {
  2238. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX;
  2239. if (IS_ALIGNED(width, 16)) {
  2240. I422AlphaToARGBRow = I422AlphaToARGBRow_LASX;
  2241. }
  2242. }
  2243. #endif
  2244. #if defined(HAS_I422ALPHATOARGBROW_RVV)
  2245. if (TestCpuFlag(kCpuHasRVV)) {
  2246. I422AlphaToARGBRow = I422AlphaToARGBRow_RVV;
  2247. }
  2248. #endif
  2249. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2250. if (TestCpuFlag(kCpuHasSSSE3)) {
  2251. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2252. if (IS_ALIGNED(width, 4)) {
  2253. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2254. }
  2255. }
  2256. #endif
  2257. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2258. if (TestCpuFlag(kCpuHasAVX2)) {
  2259. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2260. if (IS_ALIGNED(width, 8)) {
  2261. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2262. }
  2263. }
  2264. #endif
  2265. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2266. if (TestCpuFlag(kCpuHasNEON)) {
  2267. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2268. if (IS_ALIGNED(width, 8)) {
  2269. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2270. }
  2271. }
  2272. #endif
  2273. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2274. if (TestCpuFlag(kCpuHasMSA)) {
  2275. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2276. if (IS_ALIGNED(width, 8)) {
  2277. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2278. }
  2279. }
  2280. #endif
  2281. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2282. if (TestCpuFlag(kCpuHasRVV)) {
  2283. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2284. }
  2285. #endif
  2286. for (y = 0; y < height; ++y) {
  2287. I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2288. width);
  2289. if (attenuate) {
  2290. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2291. }
  2292. dst_argb += dst_stride_argb;
  2293. src_a += src_stride_a;
  2294. src_y += src_stride_y;
  2295. src_u += src_stride_u;
  2296. src_v += src_stride_v;
  2297. }
  2298. return 0;
  2299. }
  2300. // Convert I444 with Alpha to preattenuated ARGB with matrix.
  2301. LIBYUV_API
  2302. int I444AlphaToARGBMatrix(const uint8_t* src_y,
  2303. int src_stride_y,
  2304. const uint8_t* src_u,
  2305. int src_stride_u,
  2306. const uint8_t* src_v,
  2307. int src_stride_v,
  2308. const uint8_t* src_a,
  2309. int src_stride_a,
  2310. uint8_t* dst_argb,
  2311. int dst_stride_argb,
  2312. const struct YuvConstants* yuvconstants,
  2313. int width,
  2314. int height,
  2315. int attenuate) {
  2316. int y;
  2317. void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  2318. const uint8_t* v_buf, const uint8_t* a_buf,
  2319. uint8_t* dst_argb,
  2320. const struct YuvConstants* yuvconstants,
  2321. int width) = I444AlphaToARGBRow_C;
  2322. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2323. int width) = ARGBAttenuateRow_C;
  2324. assert(yuvconstants);
  2325. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2326. height == 0) {
  2327. return -1;
  2328. }
  2329. // Negative height means invert the image.
  2330. if (height < 0) {
  2331. height = -height;
  2332. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2333. dst_stride_argb = -dst_stride_argb;
  2334. }
  2335. #if defined(HAS_I444ALPHATOARGBROW_SSSE3)
  2336. if (TestCpuFlag(kCpuHasSSSE3)) {
  2337. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3;
  2338. if (IS_ALIGNED(width, 8)) {
  2339. I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3;
  2340. }
  2341. }
  2342. #endif
  2343. #if defined(HAS_I444ALPHATOARGBROW_AVX2)
  2344. if (TestCpuFlag(kCpuHasAVX2)) {
  2345. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2;
  2346. if (IS_ALIGNED(width, 16)) {
  2347. I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2;
  2348. }
  2349. }
  2350. #endif
  2351. #if defined(HAS_I444ALPHATOARGBROW_NEON)
  2352. if (TestCpuFlag(kCpuHasNEON)) {
  2353. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON;
  2354. if (IS_ALIGNED(width, 8)) {
  2355. I444AlphaToARGBRow = I444AlphaToARGBRow_NEON;
  2356. }
  2357. }
  2358. #endif
  2359. #if defined(HAS_I444ALPHATOARGBROW_SVE2)
  2360. if (TestCpuFlag(kCpuHasSVE2)) {
  2361. I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2;
  2362. }
  2363. #endif
  2364. #if defined(HAS_I444ALPHATOARGBROW_MSA)
  2365. if (TestCpuFlag(kCpuHasMSA)) {
  2366. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_MSA;
  2367. if (IS_ALIGNED(width, 8)) {
  2368. I444AlphaToARGBRow = I444AlphaToARGBRow_MSA;
  2369. }
  2370. }
  2371. #endif
  2372. #if defined(HAS_I444ALPHATOARGBROW_RVV)
  2373. if (TestCpuFlag(kCpuHasRVV)) {
  2374. I444AlphaToARGBRow = I444AlphaToARGBRow_RVV;
  2375. }
  2376. #endif
  2377. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2378. if (TestCpuFlag(kCpuHasSSSE3)) {
  2379. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2380. if (IS_ALIGNED(width, 4)) {
  2381. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2382. }
  2383. }
  2384. #endif
  2385. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2386. if (TestCpuFlag(kCpuHasAVX2)) {
  2387. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2388. if (IS_ALIGNED(width, 8)) {
  2389. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2390. }
  2391. }
  2392. #endif
  2393. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2394. if (TestCpuFlag(kCpuHasNEON)) {
  2395. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2396. if (IS_ALIGNED(width, 8)) {
  2397. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2398. }
  2399. }
  2400. #endif
  2401. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2402. if (TestCpuFlag(kCpuHasMSA)) {
  2403. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2404. if (IS_ALIGNED(width, 8)) {
  2405. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2406. }
  2407. }
  2408. #endif
  2409. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2410. if (TestCpuFlag(kCpuHasRVV)) {
  2411. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2412. }
  2413. #endif
  2414. for (y = 0; y < height; ++y) {
  2415. I444AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2416. width);
  2417. if (attenuate) {
  2418. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2419. }
  2420. dst_argb += dst_stride_argb;
  2421. src_a += src_stride_a;
  2422. src_y += src_stride_y;
  2423. src_u += src_stride_u;
  2424. src_v += src_stride_v;
  2425. }
  2426. return 0;
  2427. }
  2428. // Convert I420 with Alpha to ARGB.
  2429. LIBYUV_API
  2430. int I420AlphaToARGB(const uint8_t* src_y,
  2431. int src_stride_y,
  2432. const uint8_t* src_u,
  2433. int src_stride_u,
  2434. const uint8_t* src_v,
  2435. int src_stride_v,
  2436. const uint8_t* src_a,
  2437. int src_stride_a,
  2438. uint8_t* dst_argb,
  2439. int dst_stride_argb,
  2440. int width,
  2441. int height,
  2442. int attenuate) {
  2443. return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2444. src_stride_v, src_a, src_stride_a, dst_argb,
  2445. dst_stride_argb, &kYuvI601Constants, width,
  2446. height, attenuate);
  2447. }
  2448. // Convert I420 with Alpha to ABGR.
  2449. LIBYUV_API
  2450. int I420AlphaToABGR(const uint8_t* src_y,
  2451. int src_stride_y,
  2452. const uint8_t* src_u,
  2453. int src_stride_u,
  2454. const uint8_t* src_v,
  2455. int src_stride_v,
  2456. const uint8_t* src_a,
  2457. int src_stride_a,
  2458. uint8_t* dst_abgr,
  2459. int dst_stride_abgr,
  2460. int width,
  2461. int height,
  2462. int attenuate) {
  2463. return I420AlphaToARGBMatrix(
  2464. src_y, src_stride_y, src_v, src_stride_v, // Swap U and V
  2465. src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr,
  2466. &kYvuI601Constants, // Use Yvu matrix
  2467. width, height, attenuate);
  2468. }
  2469. // Convert I422 with Alpha to ARGB.
  2470. LIBYUV_API
  2471. int I422AlphaToARGB(const uint8_t* src_y,
  2472. int src_stride_y,
  2473. const uint8_t* src_u,
  2474. int src_stride_u,
  2475. const uint8_t* src_v,
  2476. int src_stride_v,
  2477. const uint8_t* src_a,
  2478. int src_stride_a,
  2479. uint8_t* dst_argb,
  2480. int dst_stride_argb,
  2481. int width,
  2482. int height,
  2483. int attenuate) {
  2484. return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2485. src_stride_v, src_a, src_stride_a, dst_argb,
  2486. dst_stride_argb, &kYuvI601Constants, width,
  2487. height, attenuate);
  2488. }
  2489. // Convert I422 with Alpha to ABGR.
  2490. LIBYUV_API
  2491. int I422AlphaToABGR(const uint8_t* src_y,
  2492. int src_stride_y,
  2493. const uint8_t* src_u,
  2494. int src_stride_u,
  2495. const uint8_t* src_v,
  2496. int src_stride_v,
  2497. const uint8_t* src_a,
  2498. int src_stride_a,
  2499. uint8_t* dst_abgr,
  2500. int dst_stride_abgr,
  2501. int width,
  2502. int height,
  2503. int attenuate) {
  2504. return I422AlphaToARGBMatrix(
  2505. src_y, src_stride_y, src_v, src_stride_v, // Swap U and V
  2506. src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr,
  2507. &kYvuI601Constants, // Use Yvu matrix
  2508. width, height, attenuate);
  2509. }
  2510. // Convert I444 with Alpha to ARGB.
  2511. LIBYUV_API
  2512. int I444AlphaToARGB(const uint8_t* src_y,
  2513. int src_stride_y,
  2514. const uint8_t* src_u,
  2515. int src_stride_u,
  2516. const uint8_t* src_v,
  2517. int src_stride_v,
  2518. const uint8_t* src_a,
  2519. int src_stride_a,
  2520. uint8_t* dst_argb,
  2521. int dst_stride_argb,
  2522. int width,
  2523. int height,
  2524. int attenuate) {
  2525. return I444AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2526. src_stride_v, src_a, src_stride_a, dst_argb,
  2527. dst_stride_argb, &kYuvI601Constants, width,
  2528. height, attenuate);
  2529. }
  2530. // Convert I444 with Alpha to ABGR.
  2531. LIBYUV_API
  2532. int I444AlphaToABGR(const uint8_t* src_y,
  2533. int src_stride_y,
  2534. const uint8_t* src_u,
  2535. int src_stride_u,
  2536. const uint8_t* src_v,
  2537. int src_stride_v,
  2538. const uint8_t* src_a,
  2539. int src_stride_a,
  2540. uint8_t* dst_abgr,
  2541. int dst_stride_abgr,
  2542. int width,
  2543. int height,
  2544. int attenuate) {
  2545. return I444AlphaToARGBMatrix(
  2546. src_y, src_stride_y, src_v, src_stride_v, // Swap U and V
  2547. src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr,
  2548. &kYvuI601Constants, // Use Yvu matrix
  2549. width, height, attenuate);
  2550. }
  2551. // Convert I010 with Alpha to preattenuated ARGB with matrix.
  2552. LIBYUV_API
  2553. int I010AlphaToARGBMatrix(const uint16_t* src_y,
  2554. int src_stride_y,
  2555. const uint16_t* src_u,
  2556. int src_stride_u,
  2557. const uint16_t* src_v,
  2558. int src_stride_v,
  2559. const uint16_t* src_a,
  2560. int src_stride_a,
  2561. uint8_t* dst_argb,
  2562. int dst_stride_argb,
  2563. const struct YuvConstants* yuvconstants,
  2564. int width,
  2565. int height,
  2566. int attenuate) {
  2567. int y;
  2568. void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  2569. const uint16_t* v_buf, const uint16_t* a_buf,
  2570. uint8_t* dst_argb,
  2571. const struct YuvConstants* yuvconstants,
  2572. int width) = I210AlphaToARGBRow_C;
  2573. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2574. int width) = ARGBAttenuateRow_C;
  2575. assert(yuvconstants);
  2576. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2577. height == 0) {
  2578. return -1;
  2579. }
  2580. // Negative height means invert the image.
  2581. if (height < 0) {
  2582. height = -height;
  2583. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2584. dst_stride_argb = -dst_stride_argb;
  2585. }
  2586. #if defined(HAS_I210ALPHATOARGBROW_NEON)
  2587. if (TestCpuFlag(kCpuHasNEON)) {
  2588. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON;
  2589. if (IS_ALIGNED(width, 8)) {
  2590. I210AlphaToARGBRow = I210AlphaToARGBRow_NEON;
  2591. }
  2592. }
  2593. #endif
  2594. #if defined(HAS_I210ALPHATOARGBROW_SSSE3)
  2595. if (TestCpuFlag(kCpuHasSSSE3)) {
  2596. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3;
  2597. if (IS_ALIGNED(width, 8)) {
  2598. I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3;
  2599. }
  2600. }
  2601. #endif
  2602. #if defined(HAS_I210ALPHATOARGBROW_AVX2)
  2603. if (TestCpuFlag(kCpuHasAVX2)) {
  2604. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2;
  2605. if (IS_ALIGNED(width, 16)) {
  2606. I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2;
  2607. }
  2608. }
  2609. #endif
  2610. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2611. if (TestCpuFlag(kCpuHasSSSE3)) {
  2612. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2613. if (IS_ALIGNED(width, 4)) {
  2614. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2615. }
  2616. }
  2617. #endif
  2618. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2619. if (TestCpuFlag(kCpuHasAVX2)) {
  2620. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2621. if (IS_ALIGNED(width, 8)) {
  2622. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2623. }
  2624. }
  2625. #endif
  2626. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2627. if (TestCpuFlag(kCpuHasNEON)) {
  2628. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2629. if (IS_ALIGNED(width, 8)) {
  2630. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2631. }
  2632. }
  2633. #endif
  2634. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2635. if (TestCpuFlag(kCpuHasMSA)) {
  2636. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2637. if (IS_ALIGNED(width, 8)) {
  2638. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2639. }
  2640. }
  2641. #endif
  2642. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2643. if (TestCpuFlag(kCpuHasRVV)) {
  2644. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2645. }
  2646. #endif
  2647. for (y = 0; y < height; ++y) {
  2648. I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2649. width);
  2650. if (attenuate) {
  2651. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2652. }
  2653. dst_argb += dst_stride_argb;
  2654. src_a += src_stride_a;
  2655. src_y += src_stride_y;
  2656. if (y & 1) {
  2657. src_u += src_stride_u;
  2658. src_v += src_stride_v;
  2659. }
  2660. }
  2661. return 0;
  2662. }
  2663. // Convert I210 with Alpha to preattenuated ARGB with matrix.
  2664. LIBYUV_API
  2665. int I210AlphaToARGBMatrix(const uint16_t* src_y,
  2666. int src_stride_y,
  2667. const uint16_t* src_u,
  2668. int src_stride_u,
  2669. const uint16_t* src_v,
  2670. int src_stride_v,
  2671. const uint16_t* src_a,
  2672. int src_stride_a,
  2673. uint8_t* dst_argb,
  2674. int dst_stride_argb,
  2675. const struct YuvConstants* yuvconstants,
  2676. int width,
  2677. int height,
  2678. int attenuate) {
  2679. int y;
  2680. void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  2681. const uint16_t* v_buf, const uint16_t* a_buf,
  2682. uint8_t* dst_argb,
  2683. const struct YuvConstants* yuvconstants,
  2684. int width) = I210AlphaToARGBRow_C;
  2685. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2686. int width) = ARGBAttenuateRow_C;
  2687. assert(yuvconstants);
  2688. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2689. height == 0) {
  2690. return -1;
  2691. }
  2692. // Negative height means invert the image.
  2693. if (height < 0) {
  2694. height = -height;
  2695. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2696. dst_stride_argb = -dst_stride_argb;
  2697. }
  2698. #if defined(HAS_I210ALPHATOARGBROW_NEON)
  2699. if (TestCpuFlag(kCpuHasNEON)) {
  2700. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON;
  2701. if (IS_ALIGNED(width, 8)) {
  2702. I210AlphaToARGBRow = I210AlphaToARGBRow_NEON;
  2703. }
  2704. }
  2705. #endif
  2706. #if defined(HAS_I210ALPHATOARGBROW_SSSE3)
  2707. if (TestCpuFlag(kCpuHasSSSE3)) {
  2708. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3;
  2709. if (IS_ALIGNED(width, 8)) {
  2710. I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3;
  2711. }
  2712. }
  2713. #endif
  2714. #if defined(HAS_I210ALPHATOARGBROW_AVX2)
  2715. if (TestCpuFlag(kCpuHasAVX2)) {
  2716. I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2;
  2717. if (IS_ALIGNED(width, 16)) {
  2718. I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2;
  2719. }
  2720. }
  2721. #endif
  2722. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2723. if (TestCpuFlag(kCpuHasSSSE3)) {
  2724. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2725. if (IS_ALIGNED(width, 4)) {
  2726. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2727. }
  2728. }
  2729. #endif
  2730. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2731. if (TestCpuFlag(kCpuHasAVX2)) {
  2732. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2733. if (IS_ALIGNED(width, 8)) {
  2734. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2735. }
  2736. }
  2737. #endif
  2738. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2739. if (TestCpuFlag(kCpuHasNEON)) {
  2740. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2741. if (IS_ALIGNED(width, 8)) {
  2742. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2743. }
  2744. }
  2745. #endif
  2746. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2747. if (TestCpuFlag(kCpuHasMSA)) {
  2748. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2749. if (IS_ALIGNED(width, 8)) {
  2750. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2751. }
  2752. }
  2753. #endif
  2754. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2755. if (TestCpuFlag(kCpuHasRVV)) {
  2756. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2757. }
  2758. #endif
  2759. for (y = 0; y < height; ++y) {
  2760. I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2761. width);
  2762. if (attenuate) {
  2763. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2764. }
  2765. dst_argb += dst_stride_argb;
  2766. src_a += src_stride_a;
  2767. src_y += src_stride_y;
  2768. src_u += src_stride_u;
  2769. src_v += src_stride_v;
  2770. }
  2771. return 0;
  2772. }
  2773. // Convert I410 with Alpha to preattenuated ARGB with matrix.
  2774. LIBYUV_API
  2775. int I410AlphaToARGBMatrix(const uint16_t* src_y,
  2776. int src_stride_y,
  2777. const uint16_t* src_u,
  2778. int src_stride_u,
  2779. const uint16_t* src_v,
  2780. int src_stride_v,
  2781. const uint16_t* src_a,
  2782. int src_stride_a,
  2783. uint8_t* dst_argb,
  2784. int dst_stride_argb,
  2785. const struct YuvConstants* yuvconstants,
  2786. int width,
  2787. int height,
  2788. int attenuate) {
  2789. int y;
  2790. void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  2791. const uint16_t* v_buf, const uint16_t* a_buf,
  2792. uint8_t* dst_argb,
  2793. const struct YuvConstants* yuvconstants,
  2794. int width) = I410AlphaToARGBRow_C;
  2795. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  2796. int width) = ARGBAttenuateRow_C;
  2797. assert(yuvconstants);
  2798. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  2799. height == 0) {
  2800. return -1;
  2801. }
  2802. // Negative height means invert the image.
  2803. if (height < 0) {
  2804. height = -height;
  2805. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2806. dst_stride_argb = -dst_stride_argb;
  2807. }
  2808. #if defined(HAS_I410ALPHATOARGBROW_NEON)
  2809. if (TestCpuFlag(kCpuHasNEON)) {
  2810. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON;
  2811. if (IS_ALIGNED(width, 8)) {
  2812. I410AlphaToARGBRow = I410AlphaToARGBRow_NEON;
  2813. }
  2814. }
  2815. #endif
  2816. #if defined(HAS_I410ALPHATOARGBROW_SSSE3)
  2817. if (TestCpuFlag(kCpuHasSSSE3)) {
  2818. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3;
  2819. if (IS_ALIGNED(width, 8)) {
  2820. I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3;
  2821. }
  2822. }
  2823. #endif
  2824. #if defined(HAS_I410ALPHATOARGBROW_AVX2)
  2825. if (TestCpuFlag(kCpuHasAVX2)) {
  2826. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2;
  2827. if (IS_ALIGNED(width, 16)) {
  2828. I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2;
  2829. }
  2830. }
  2831. #endif
  2832. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  2833. if (TestCpuFlag(kCpuHasSSSE3)) {
  2834. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  2835. if (IS_ALIGNED(width, 4)) {
  2836. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  2837. }
  2838. }
  2839. #endif
  2840. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  2841. if (TestCpuFlag(kCpuHasAVX2)) {
  2842. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  2843. if (IS_ALIGNED(width, 8)) {
  2844. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  2845. }
  2846. }
  2847. #endif
  2848. #if defined(HAS_ARGBATTENUATEROW_NEON)
  2849. if (TestCpuFlag(kCpuHasNEON)) {
  2850. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  2851. if (IS_ALIGNED(width, 8)) {
  2852. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  2853. }
  2854. }
  2855. #endif
  2856. #if defined(HAS_ARGBATTENUATEROW_MSA)
  2857. if (TestCpuFlag(kCpuHasMSA)) {
  2858. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  2859. if (IS_ALIGNED(width, 8)) {
  2860. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  2861. }
  2862. }
  2863. #endif
  2864. #if defined(HAS_ARGBATTENUATEROW_RVV)
  2865. if (TestCpuFlag(kCpuHasRVV)) {
  2866. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  2867. }
  2868. #endif
  2869. for (y = 0; y < height; ++y) {
  2870. I410AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  2871. width);
  2872. if (attenuate) {
  2873. ARGBAttenuateRow(dst_argb, dst_argb, width);
  2874. }
  2875. dst_argb += dst_stride_argb;
  2876. src_a += src_stride_a;
  2877. src_y += src_stride_y;
  2878. src_u += src_stride_u;
  2879. src_v += src_stride_v;
  2880. }
  2881. return 0;
  2882. }
  2883. // Convert I400 to ARGB with matrix.
  2884. LIBYUV_API
  2885. int I400ToARGBMatrix(const uint8_t* src_y,
  2886. int src_stride_y,
  2887. uint8_t* dst_argb,
  2888. int dst_stride_argb,
  2889. const struct YuvConstants* yuvconstants,
  2890. int width,
  2891. int height) {
  2892. int y;
  2893. void (*I400ToARGBRow)(const uint8_t* y_buf, uint8_t* rgb_buf,
  2894. const struct YuvConstants* yuvconstants, int width) =
  2895. I400ToARGBRow_C;
  2896. assert(yuvconstants);
  2897. if (!src_y || !dst_argb || width <= 0 || height == 0) {
  2898. return -1;
  2899. }
  2900. // Negative height means invert the image.
  2901. if (height < 0) {
  2902. height = -height;
  2903. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2904. dst_stride_argb = -dst_stride_argb;
  2905. }
  2906. // Coalesce rows.
  2907. if (src_stride_y == width && dst_stride_argb == width * 4) {
  2908. width *= height;
  2909. height = 1;
  2910. src_stride_y = dst_stride_argb = 0;
  2911. }
  2912. #if defined(HAS_I400TOARGBROW_SSE2)
  2913. if (TestCpuFlag(kCpuHasSSE2)) {
  2914. I400ToARGBRow = I400ToARGBRow_Any_SSE2;
  2915. if (IS_ALIGNED(width, 8)) {
  2916. I400ToARGBRow = I400ToARGBRow_SSE2;
  2917. }
  2918. }
  2919. #endif
  2920. #if defined(HAS_I400TOARGBROW_AVX2)
  2921. if (TestCpuFlag(kCpuHasAVX2)) {
  2922. I400ToARGBRow = I400ToARGBRow_Any_AVX2;
  2923. if (IS_ALIGNED(width, 16)) {
  2924. I400ToARGBRow = I400ToARGBRow_AVX2;
  2925. }
  2926. }
  2927. #endif
  2928. #if defined(HAS_I400TOARGBROW_NEON)
  2929. if (TestCpuFlag(kCpuHasNEON)) {
  2930. I400ToARGBRow = I400ToARGBRow_Any_NEON;
  2931. if (IS_ALIGNED(width, 8)) {
  2932. I400ToARGBRow = I400ToARGBRow_NEON;
  2933. }
  2934. }
  2935. #endif
  2936. #if defined(HAS_I400TOARGBROW_SVE2)
  2937. if (TestCpuFlag(kCpuHasSVE2)) {
  2938. I400ToARGBRow = I400ToARGBRow_SVE2;
  2939. }
  2940. #endif
  2941. #if defined(HAS_I400TOARGBROW_MSA)
  2942. if (TestCpuFlag(kCpuHasMSA)) {
  2943. I400ToARGBRow = I400ToARGBRow_Any_MSA;
  2944. if (IS_ALIGNED(width, 16)) {
  2945. I400ToARGBRow = I400ToARGBRow_MSA;
  2946. }
  2947. }
  2948. #endif
  2949. #if defined(HAS_I400TOARGBROW_LSX)
  2950. if (TestCpuFlag(kCpuHasLSX)) {
  2951. I400ToARGBRow = I400ToARGBRow_Any_LSX;
  2952. if (IS_ALIGNED(width, 16)) {
  2953. I400ToARGBRow = I400ToARGBRow_LSX;
  2954. }
  2955. }
  2956. #endif
  2957. #if defined(HAS_I400TOARGBROW_RVV)
  2958. if (TestCpuFlag(kCpuHasRVV)) {
  2959. I400ToARGBRow = I400ToARGBRow_RVV;
  2960. }
  2961. #endif
  2962. for (y = 0; y < height; ++y) {
  2963. I400ToARGBRow(src_y, dst_argb, yuvconstants, width);
  2964. dst_argb += dst_stride_argb;
  2965. src_y += src_stride_y;
  2966. }
  2967. return 0;
  2968. }
  2969. // Convert I400 to ARGB.
  2970. LIBYUV_API
  2971. int I400ToARGB(const uint8_t* src_y,
  2972. int src_stride_y,
  2973. uint8_t* dst_argb,
  2974. int dst_stride_argb,
  2975. int width,
  2976. int height) {
  2977. return I400ToARGBMatrix(src_y, src_stride_y, dst_argb, dst_stride_argb,
  2978. &kYuvI601Constants, width, height);
  2979. }
  2980. // Convert J400 to ARGB.
  2981. LIBYUV_API
  2982. int J400ToARGB(const uint8_t* src_y,
  2983. int src_stride_y,
  2984. uint8_t* dst_argb,
  2985. int dst_stride_argb,
  2986. int width,
  2987. int height) {
  2988. int y;
  2989. void (*J400ToARGBRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) =
  2990. J400ToARGBRow_C;
  2991. if (!src_y || !dst_argb || width <= 0 || height == 0) {
  2992. return -1;
  2993. }
  2994. // Negative height means invert the image.
  2995. if (height < 0) {
  2996. height = -height;
  2997. src_y = src_y + (height - 1) * src_stride_y;
  2998. src_stride_y = -src_stride_y;
  2999. }
  3000. // Coalesce rows.
  3001. if (src_stride_y == width && dst_stride_argb == width * 4) {
  3002. width *= height;
  3003. height = 1;
  3004. src_stride_y = dst_stride_argb = 0;
  3005. }
  3006. #if defined(HAS_J400TOARGBROW_SSE2)
  3007. if (TestCpuFlag(kCpuHasSSE2)) {
  3008. J400ToARGBRow = J400ToARGBRow_Any_SSE2;
  3009. if (IS_ALIGNED(width, 8)) {
  3010. J400ToARGBRow = J400ToARGBRow_SSE2;
  3011. }
  3012. }
  3013. #endif
  3014. #if defined(HAS_J400TOARGBROW_AVX2)
  3015. if (TestCpuFlag(kCpuHasAVX2)) {
  3016. J400ToARGBRow = J400ToARGBRow_Any_AVX2;
  3017. if (IS_ALIGNED(width, 16)) {
  3018. J400ToARGBRow = J400ToARGBRow_AVX2;
  3019. }
  3020. }
  3021. #endif
  3022. #if defined(HAS_J400TOARGBROW_NEON)
  3023. if (TestCpuFlag(kCpuHasNEON)) {
  3024. J400ToARGBRow = J400ToARGBRow_Any_NEON;
  3025. if (IS_ALIGNED(width, 8)) {
  3026. J400ToARGBRow = J400ToARGBRow_NEON;
  3027. }
  3028. }
  3029. #endif
  3030. #if defined(HAS_J400TOARGBROW_MSA)
  3031. if (TestCpuFlag(kCpuHasMSA)) {
  3032. J400ToARGBRow = J400ToARGBRow_Any_MSA;
  3033. if (IS_ALIGNED(width, 16)) {
  3034. J400ToARGBRow = J400ToARGBRow_MSA;
  3035. }
  3036. }
  3037. #endif
  3038. #if defined(HAS_J400TOARGBROW_LSX)
  3039. if (TestCpuFlag(kCpuHasLSX)) {
  3040. J400ToARGBRow = J400ToARGBRow_Any_LSX;
  3041. if (IS_ALIGNED(width, 16)) {
  3042. J400ToARGBRow = J400ToARGBRow_LSX;
  3043. }
  3044. }
  3045. #endif
  3046. #if defined(HAS_J400TOARGBROW_RVV)
  3047. if (TestCpuFlag(kCpuHasRVV)) {
  3048. J400ToARGBRow = J400ToARGBRow_RVV;
  3049. }
  3050. #endif
  3051. for (y = 0; y < height; ++y) {
  3052. J400ToARGBRow(src_y, dst_argb, width);
  3053. src_y += src_stride_y;
  3054. dst_argb += dst_stride_argb;
  3055. }
  3056. return 0;
  3057. }
  3058. #ifndef __riscv
  3059. // Shuffle table for converting BGRA to ARGB.
  3060. static const uvec8 kShuffleMaskBGRAToARGB = {
  3061. 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u};
  3062. // Shuffle table for converting ABGR to ARGB.
  3063. static const uvec8 kShuffleMaskABGRToARGB = {
  3064. 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u};
  3065. // Shuffle table for converting RGBA to ARGB.
  3066. static const uvec8 kShuffleMaskRGBAToARGB = {
  3067. 1u, 2u, 3u, 0u, 5u, 6u, 7u, 4u, 9u, 10u, 11u, 8u, 13u, 14u, 15u, 12u};
  3068. // Shuffle table for converting AR64 to AB64.
  3069. static const uvec8 kShuffleMaskAR64ToAB64 = {
  3070. 4u, 5u, 2u, 3u, 0u, 1u, 6u, 7u, 12u, 13u, 10u, 11u, 8u, 9u, 14u, 15u};
  3071. // Convert BGRA to ARGB.
  3072. LIBYUV_API
  3073. int BGRAToARGB(const uint8_t* src_bgra,
  3074. int src_stride_bgra,
  3075. uint8_t* dst_argb,
  3076. int dst_stride_argb,
  3077. int width,
  3078. int height) {
  3079. return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb,
  3080. (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height);
  3081. }
  3082. // Convert ARGB to BGRA (same as BGRAToARGB).
  3083. LIBYUV_API
  3084. int ARGBToBGRA(const uint8_t* src_bgra,
  3085. int src_stride_bgra,
  3086. uint8_t* dst_argb,
  3087. int dst_stride_argb,
  3088. int width,
  3089. int height) {
  3090. return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb,
  3091. (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height);
  3092. }
  3093. // Convert ABGR to ARGB.
  3094. LIBYUV_API
  3095. int ABGRToARGB(const uint8_t* src_abgr,
  3096. int src_stride_abgr,
  3097. uint8_t* dst_argb,
  3098. int dst_stride_argb,
  3099. int width,
  3100. int height) {
  3101. return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb,
  3102. (const uint8_t*)&kShuffleMaskABGRToARGB, width, height);
  3103. }
  3104. // Convert ARGB to ABGR to (same as ABGRToARGB).
  3105. LIBYUV_API
  3106. int ARGBToABGR(const uint8_t* src_abgr,
  3107. int src_stride_abgr,
  3108. uint8_t* dst_argb,
  3109. int dst_stride_argb,
  3110. int width,
  3111. int height) {
  3112. return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb,
  3113. (const uint8_t*)&kShuffleMaskABGRToARGB, width, height);
  3114. }
  3115. // Convert RGBA to ARGB.
  3116. LIBYUV_API
  3117. int RGBAToARGB(const uint8_t* src_rgba,
  3118. int src_stride_rgba,
  3119. uint8_t* dst_argb,
  3120. int dst_stride_argb,
  3121. int width,
  3122. int height) {
  3123. return ARGBShuffle(src_rgba, src_stride_rgba, dst_argb, dst_stride_argb,
  3124. (const uint8_t*)&kShuffleMaskRGBAToARGB, width, height);
  3125. }
  3126. // Convert AR64 To AB64.
  3127. LIBYUV_API
  3128. int AR64ToAB64(const uint16_t* src_ar64,
  3129. int src_stride_ar64,
  3130. uint16_t* dst_ab64,
  3131. int dst_stride_ab64,
  3132. int width,
  3133. int height) {
  3134. return AR64Shuffle(src_ar64, src_stride_ar64, dst_ab64, dst_stride_ab64,
  3135. (const uint8_t*)&kShuffleMaskAR64ToAB64, width, height);
  3136. }
  3137. #else
  3138. // Convert BGRA to ARGB (same as ARGBToBGRA).
  3139. LIBYUV_API
  3140. int BGRAToARGB(const uint8_t* src_bgra,
  3141. int src_stride_bgra,
  3142. uint8_t* dst_argb,
  3143. int dst_stride_argb,
  3144. int width,
  3145. int height) {
  3146. return ARGBToBGRA(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, width,
  3147. height);
  3148. }
  3149. // Convert ARGB to BGRA.
  3150. LIBYUV_API
  3151. int ARGBToBGRA(const uint8_t* src_argb,
  3152. int src_stride_argb,
  3153. uint8_t* dst_bgra,
  3154. int dst_stride_bgra,
  3155. int width,
  3156. int height) {
  3157. int y;
  3158. void (*ARGBToBGRARow)(const uint8_t* src_argb, uint8_t* dst_bgra, int width) =
  3159. ARGBToBGRARow_C;
  3160. if (!src_argb || !dst_bgra || width <= 0 || height == 0) {
  3161. return -1;
  3162. }
  3163. // Negative height means invert the image.
  3164. if (height < 0) {
  3165. height = -height;
  3166. src_argb = src_argb + (height - 1) * src_stride_argb;
  3167. src_stride_argb = -src_stride_argb;
  3168. }
  3169. // Coalesce rows.
  3170. if (src_stride_argb == width * 4 && dst_stride_bgra == width * 4) {
  3171. width *= height;
  3172. height = 1;
  3173. src_stride_argb = dst_stride_bgra = 0;
  3174. }
  3175. #if defined(HAS_ARGBTOBGRAROW_RVV)
  3176. if (TestCpuFlag(kCpuHasRVV)) {
  3177. ARGBToBGRARow = ARGBToBGRARow_RVV;
  3178. }
  3179. #endif
  3180. for (y = 0; y < height; ++y) {
  3181. ARGBToBGRARow(src_argb, dst_bgra, width);
  3182. src_argb += src_stride_argb;
  3183. dst_bgra += dst_stride_bgra;
  3184. }
  3185. return 0;
  3186. }
  3187. // Convert ARGB to ABGR.
  3188. LIBYUV_API
  3189. int ARGBToABGR(const uint8_t* src_argb,
  3190. int src_stride_argb,
  3191. uint8_t* dst_abgr,
  3192. int dst_stride_abgr,
  3193. int width,
  3194. int height) {
  3195. int y;
  3196. void (*ARGBToABGRRow)(const uint8_t* src_argb, uint8_t* dst_abgr, int width) =
  3197. ARGBToABGRRow_C;
  3198. if (!src_argb || !dst_abgr || width <= 0 || height == 0) {
  3199. return -1;
  3200. }
  3201. // Negative height means invert the image.
  3202. if (height < 0) {
  3203. height = -height;
  3204. src_argb = src_argb + (height - 1) * src_stride_argb;
  3205. src_stride_argb = -src_stride_argb;
  3206. }
  3207. // Coalesce rows.
  3208. if (src_stride_argb == width * 4 && dst_stride_abgr == width * 4) {
  3209. width *= height;
  3210. height = 1;
  3211. src_stride_argb = dst_stride_abgr = 0;
  3212. }
  3213. #if defined(HAS_ARGBTOABGRROW_RVV)
  3214. if (TestCpuFlag(kCpuHasRVV)) {
  3215. ARGBToABGRRow = ARGBToABGRRow_RVV;
  3216. }
  3217. #endif
  3218. for (y = 0; y < height; ++y) {
  3219. ARGBToABGRRow(src_argb, dst_abgr, width);
  3220. src_argb += src_stride_argb;
  3221. dst_abgr += dst_stride_abgr;
  3222. }
  3223. return 0;
  3224. }
  3225. // Convert ABGR to ARGB (same as ARGBToABGR).
  3226. LIBYUV_API
  3227. int ABGRToARGB(const uint8_t* src_abgr,
  3228. int src_stride_abgr,
  3229. uint8_t* dst_argb,
  3230. int dst_stride_argb,
  3231. int width,
  3232. int height) {
  3233. return ARGBToABGR(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, width,
  3234. height);
  3235. }
  3236. // Convert RGBA to ARGB.
  3237. LIBYUV_API
  3238. int RGBAToARGB(const uint8_t* src_rgba,
  3239. int src_stride_rgba,
  3240. uint8_t* dst_argb,
  3241. int dst_stride_argb,
  3242. int width,
  3243. int height) {
  3244. int y;
  3245. void (*RGBAToARGBRow)(const uint8_t* src_rgba, uint8_t* dst_argb, int width) =
  3246. RGBAToARGBRow_C;
  3247. if (!src_rgba || !dst_argb || width <= 0 || height == 0) {
  3248. return -1;
  3249. }
  3250. // Negative height means invert the image.
  3251. if (height < 0) {
  3252. height = -height;
  3253. src_rgba = src_rgba + (height - 1) * src_stride_rgba;
  3254. src_stride_rgba = -src_stride_rgba;
  3255. }
  3256. // Coalesce rows.
  3257. if (src_stride_rgba == width * 4 && dst_stride_argb == width * 4) {
  3258. width *= height;
  3259. height = 1;
  3260. src_stride_rgba = dst_stride_argb = 0;
  3261. }
  3262. #if defined(HAS_RGBATOARGBROW_RVV)
  3263. if (TestCpuFlag(kCpuHasRVV)) {
  3264. RGBAToARGBRow = RGBAToARGBRow_RVV;
  3265. }
  3266. #endif
  3267. for (y = 0; y < height; ++y) {
  3268. RGBAToARGBRow(src_rgba, dst_argb, width);
  3269. src_rgba += src_stride_rgba;
  3270. dst_argb += dst_stride_argb;
  3271. }
  3272. return 0;
  3273. }
  3274. // Convert AR64 To AB64.
  3275. LIBYUV_API
  3276. int AR64ToAB64(const uint16_t* src_ar64,
  3277. int src_stride_ar64,
  3278. uint16_t* dst_ab64,
  3279. int dst_stride_ab64,
  3280. int width,
  3281. int height) {
  3282. int y;
  3283. void (*AR64ToAB64Row)(const uint16_t* src_ar64, uint16_t* dst_ab64,
  3284. int width) = AR64ToAB64Row_C;
  3285. if (!src_ar64 || !dst_ab64 || width <= 0 || height == 0) {
  3286. return -1;
  3287. }
  3288. // Negative height means invert the image.
  3289. if (height < 0) {
  3290. height = -height;
  3291. src_ar64 = src_ar64 + (height - 1) * src_stride_ar64;
  3292. src_stride_ar64 = -src_stride_ar64;
  3293. }
  3294. // Coalesce rows.
  3295. if (src_stride_ar64 == width * 4 && dst_stride_ab64 == width * 4) {
  3296. width *= height;
  3297. height = 1;
  3298. src_stride_ar64 = dst_stride_ab64 = 0;
  3299. }
  3300. #if defined(HAS_AR64TOAB64ROW_RVV)
  3301. if (TestCpuFlag(kCpuHasRVV)) {
  3302. AR64ToAB64Row = AR64ToAB64Row_RVV;
  3303. }
  3304. #endif
  3305. for (y = 0; y < height; ++y) {
  3306. AR64ToAB64Row(src_ar64, dst_ab64, width);
  3307. src_ar64 += src_stride_ar64;
  3308. dst_ab64 += dst_stride_ab64;
  3309. }
  3310. return 0;
  3311. }
  3312. #endif
  3313. // Convert RGB24 to ARGB.
  3314. LIBYUV_API
  3315. int RGB24ToARGB(const uint8_t* src_rgb24,
  3316. int src_stride_rgb24,
  3317. uint8_t* dst_argb,
  3318. int dst_stride_argb,
  3319. int width,
  3320. int height) {
  3321. int y;
  3322. void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) =
  3323. RGB24ToARGBRow_C;
  3324. if (!src_rgb24 || !dst_argb || width <= 0 || height == 0) {
  3325. return -1;
  3326. }
  3327. // Negative height means invert the image.
  3328. if (height < 0) {
  3329. height = -height;
  3330. src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24;
  3331. src_stride_rgb24 = -src_stride_rgb24;
  3332. }
  3333. // Coalesce rows.
  3334. if (src_stride_rgb24 == width * 3 && dst_stride_argb == width * 4) {
  3335. width *= height;
  3336. height = 1;
  3337. src_stride_rgb24 = dst_stride_argb = 0;
  3338. }
  3339. #if defined(HAS_RGB24TOARGBROW_SSSE3)
  3340. if (TestCpuFlag(kCpuHasSSSE3)) {
  3341. RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3;
  3342. if (IS_ALIGNED(width, 16)) {
  3343. RGB24ToARGBRow = RGB24ToARGBRow_SSSE3;
  3344. }
  3345. }
  3346. #endif
  3347. #if defined(HAS_RGB24TOARGBROW_NEON)
  3348. if (TestCpuFlag(kCpuHasNEON)) {
  3349. RGB24ToARGBRow = RGB24ToARGBRow_Any_NEON;
  3350. if (IS_ALIGNED(width, 8)) {
  3351. RGB24ToARGBRow = RGB24ToARGBRow_NEON;
  3352. }
  3353. }
  3354. #endif
  3355. #if defined(HAS_RGB24TOARGBROW_SVE2)
  3356. if (TestCpuFlag(kCpuHasSVE2)) {
  3357. RGB24ToARGBRow = RGB24ToARGBRow_SVE2;
  3358. }
  3359. #endif
  3360. #if defined(HAS_RGB24TOARGBROW_MSA)
  3361. if (TestCpuFlag(kCpuHasMSA)) {
  3362. RGB24ToARGBRow = RGB24ToARGBRow_Any_MSA;
  3363. if (IS_ALIGNED(width, 16)) {
  3364. RGB24ToARGBRow = RGB24ToARGBRow_MSA;
  3365. }
  3366. }
  3367. #endif
  3368. #if defined(HAS_RGB24TOARGBROW_LSX)
  3369. if (TestCpuFlag(kCpuHasLSX)) {
  3370. RGB24ToARGBRow = RGB24ToARGBRow_Any_LSX;
  3371. if (IS_ALIGNED(width, 16)) {
  3372. RGB24ToARGBRow = RGB24ToARGBRow_LSX;
  3373. }
  3374. }
  3375. #endif
  3376. #if defined(HAS_RGB24TOARGBROW_LASX)
  3377. if (TestCpuFlag(kCpuHasLASX)) {
  3378. RGB24ToARGBRow = RGB24ToARGBRow_Any_LASX;
  3379. if (IS_ALIGNED(width, 32)) {
  3380. RGB24ToARGBRow = RGB24ToARGBRow_LASX;
  3381. }
  3382. }
  3383. #endif
  3384. #if defined(HAS_RGB24TOARGBROW_RVV)
  3385. if (TestCpuFlag(kCpuHasRVV)) {
  3386. RGB24ToARGBRow = RGB24ToARGBRow_RVV;
  3387. }
  3388. #endif
  3389. for (y = 0; y < height; ++y) {
  3390. RGB24ToARGBRow(src_rgb24, dst_argb, width);
  3391. src_rgb24 += src_stride_rgb24;
  3392. dst_argb += dst_stride_argb;
  3393. }
  3394. return 0;
  3395. }
  3396. // Convert RAW to ARGB.
  3397. LIBYUV_API
  3398. int RAWToARGB(const uint8_t* src_raw,
  3399. int src_stride_raw,
  3400. uint8_t* dst_argb,
  3401. int dst_stride_argb,
  3402. int width,
  3403. int height) {
  3404. int y;
  3405. void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) =
  3406. RAWToARGBRow_C;
  3407. if (!src_raw || !dst_argb || width <= 0 || height == 0) {
  3408. return -1;
  3409. }
  3410. // Negative height means invert the image.
  3411. if (height < 0) {
  3412. height = -height;
  3413. src_raw = src_raw + (height - 1) * src_stride_raw;
  3414. src_stride_raw = -src_stride_raw;
  3415. }
  3416. // Coalesce rows.
  3417. if (src_stride_raw == width * 3 && dst_stride_argb == width * 4) {
  3418. width *= height;
  3419. height = 1;
  3420. src_stride_raw = dst_stride_argb = 0;
  3421. }
  3422. #if defined(HAS_RAWTOARGBROW_SSSE3)
  3423. if (TestCpuFlag(kCpuHasSSSE3)) {
  3424. RAWToARGBRow = RAWToARGBRow_Any_SSSE3;
  3425. if (IS_ALIGNED(width, 16)) {
  3426. RAWToARGBRow = RAWToARGBRow_SSSE3;
  3427. }
  3428. }
  3429. #endif
  3430. #if defined(HAS_RAWTOARGBROW_NEON)
  3431. if (TestCpuFlag(kCpuHasNEON)) {
  3432. RAWToARGBRow = RAWToARGBRow_Any_NEON;
  3433. if (IS_ALIGNED(width, 8)) {
  3434. RAWToARGBRow = RAWToARGBRow_NEON;
  3435. }
  3436. }
  3437. #endif
  3438. #if defined(HAS_RAWTOARGBROW_SVE2)
  3439. if (TestCpuFlag(kCpuHasSVE2)) {
  3440. RAWToARGBRow = RAWToARGBRow_SVE2;
  3441. }
  3442. #endif
  3443. #if defined(HAS_RAWTOARGBROW_MSA)
  3444. if (TestCpuFlag(kCpuHasMSA)) {
  3445. RAWToARGBRow = RAWToARGBRow_Any_MSA;
  3446. if (IS_ALIGNED(width, 16)) {
  3447. RAWToARGBRow = RAWToARGBRow_MSA;
  3448. }
  3449. }
  3450. #endif
  3451. #if defined(HAS_RAWTOARGBROW_LSX)
  3452. if (TestCpuFlag(kCpuHasLSX)) {
  3453. RAWToARGBRow = RAWToARGBRow_Any_LSX;
  3454. if (IS_ALIGNED(width, 16)) {
  3455. RAWToARGBRow = RAWToARGBRow_LSX;
  3456. }
  3457. }
  3458. #endif
  3459. #if defined(HAS_RAWTOARGBROW_LASX)
  3460. if (TestCpuFlag(kCpuHasLASX)) {
  3461. RAWToARGBRow = RAWToARGBRow_Any_LASX;
  3462. if (IS_ALIGNED(width, 32)) {
  3463. RAWToARGBRow = RAWToARGBRow_LASX;
  3464. }
  3465. }
  3466. #endif
  3467. #if defined(HAS_RAWTOARGBROW_RVV)
  3468. if (TestCpuFlag(kCpuHasRVV)) {
  3469. RAWToARGBRow = RAWToARGBRow_RVV;
  3470. }
  3471. #endif
  3472. for (y = 0; y < height; ++y) {
  3473. RAWToARGBRow(src_raw, dst_argb, width);
  3474. src_raw += src_stride_raw;
  3475. dst_argb += dst_stride_argb;
  3476. }
  3477. return 0;
  3478. }
  3479. // Convert RAW to RGBA.
  3480. LIBYUV_API
  3481. int RAWToRGBA(const uint8_t* src_raw,
  3482. int src_stride_raw,
  3483. uint8_t* dst_rgba,
  3484. int dst_stride_rgba,
  3485. int width,
  3486. int height) {
  3487. int y;
  3488. void (*RAWToRGBARow)(const uint8_t* src_rgb, uint8_t* dst_rgba, int width) =
  3489. RAWToRGBARow_C;
  3490. if (!src_raw || !dst_rgba || width <= 0 || height == 0) {
  3491. return -1;
  3492. }
  3493. // Negative height means invert the image.
  3494. if (height < 0) {
  3495. height = -height;
  3496. src_raw = src_raw + (height - 1) * src_stride_raw;
  3497. src_stride_raw = -src_stride_raw;
  3498. }
  3499. // Coalesce rows.
  3500. if (src_stride_raw == width * 3 && dst_stride_rgba == width * 4) {
  3501. width *= height;
  3502. height = 1;
  3503. src_stride_raw = dst_stride_rgba = 0;
  3504. }
  3505. #if defined(HAS_RAWTORGBAROW_SSSE3)
  3506. if (TestCpuFlag(kCpuHasSSSE3)) {
  3507. RAWToRGBARow = RAWToRGBARow_Any_SSSE3;
  3508. if (IS_ALIGNED(width, 16)) {
  3509. RAWToRGBARow = RAWToRGBARow_SSSE3;
  3510. }
  3511. }
  3512. #endif
  3513. #if defined(HAS_RAWTORGBAROW_NEON)
  3514. if (TestCpuFlag(kCpuHasNEON)) {
  3515. RAWToRGBARow = RAWToRGBARow_Any_NEON;
  3516. if (IS_ALIGNED(width, 8)) {
  3517. RAWToRGBARow = RAWToRGBARow_NEON;
  3518. }
  3519. }
  3520. #endif
  3521. #if defined(HAS_RAWTORGBAROW_SVE2)
  3522. if (TestCpuFlag(kCpuHasSVE2)) {
  3523. RAWToRGBARow = RAWToRGBARow_SVE2;
  3524. }
  3525. #endif
  3526. #if defined(HAS_RAWTORGBAROW_RVV)
  3527. if (TestCpuFlag(kCpuHasRVV)) {
  3528. RAWToRGBARow = RAWToRGBARow_RVV;
  3529. }
  3530. #endif
  3531. for (y = 0; y < height; ++y) {
  3532. RAWToRGBARow(src_raw, dst_rgba, width);
  3533. src_raw += src_stride_raw;
  3534. dst_rgba += dst_stride_rgba;
  3535. }
  3536. return 0;
  3537. }
  3538. // Convert RGB565 to ARGB.
  3539. LIBYUV_API
  3540. int RGB565ToARGB(const uint8_t* src_rgb565,
  3541. int src_stride_rgb565,
  3542. uint8_t* dst_argb,
  3543. int dst_stride_argb,
  3544. int width,
  3545. int height) {
  3546. int y;
  3547. void (*RGB565ToARGBRow)(const uint8_t* src_rgb565, uint8_t* dst_argb,
  3548. int width) = RGB565ToARGBRow_C;
  3549. if (!src_rgb565 || !dst_argb || width <= 0 || height == 0) {
  3550. return -1;
  3551. }
  3552. // Negative height means invert the image.
  3553. if (height < 0) {
  3554. height = -height;
  3555. src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565;
  3556. src_stride_rgb565 = -src_stride_rgb565;
  3557. }
  3558. // Coalesce rows.
  3559. if (src_stride_rgb565 == width * 2 && dst_stride_argb == width * 4) {
  3560. width *= height;
  3561. height = 1;
  3562. src_stride_rgb565 = dst_stride_argb = 0;
  3563. }
  3564. #if defined(HAS_RGB565TOARGBROW_SSE2)
  3565. if (TestCpuFlag(kCpuHasSSE2)) {
  3566. RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2;
  3567. if (IS_ALIGNED(width, 8)) {
  3568. RGB565ToARGBRow = RGB565ToARGBRow_SSE2;
  3569. }
  3570. }
  3571. #endif
  3572. #if defined(HAS_RGB565TOARGBROW_AVX2)
  3573. if (TestCpuFlag(kCpuHasAVX2)) {
  3574. RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2;
  3575. if (IS_ALIGNED(width, 16)) {
  3576. RGB565ToARGBRow = RGB565ToARGBRow_AVX2;
  3577. }
  3578. }
  3579. #endif
  3580. #if defined(HAS_RGB565TOARGBROW_NEON)
  3581. if (TestCpuFlag(kCpuHasNEON)) {
  3582. RGB565ToARGBRow = RGB565ToARGBRow_Any_NEON;
  3583. if (IS_ALIGNED(width, 8)) {
  3584. RGB565ToARGBRow = RGB565ToARGBRow_NEON;
  3585. }
  3586. }
  3587. #endif
  3588. #if defined(HAS_RGB565TOARGBROW_MSA)
  3589. if (TestCpuFlag(kCpuHasMSA)) {
  3590. RGB565ToARGBRow = RGB565ToARGBRow_Any_MSA;
  3591. if (IS_ALIGNED(width, 16)) {
  3592. RGB565ToARGBRow = RGB565ToARGBRow_MSA;
  3593. }
  3594. }
  3595. #endif
  3596. #if defined(HAS_RGB565TOARGBROW_LSX)
  3597. if (TestCpuFlag(kCpuHasLSX)) {
  3598. RGB565ToARGBRow = RGB565ToARGBRow_Any_LSX;
  3599. if (IS_ALIGNED(width, 16)) {
  3600. RGB565ToARGBRow = RGB565ToARGBRow_LSX;
  3601. }
  3602. }
  3603. #endif
  3604. #if defined(HAS_RGB565TOARGBROW_LASX)
  3605. if (TestCpuFlag(kCpuHasLASX)) {
  3606. RGB565ToARGBRow = RGB565ToARGBRow_Any_LASX;
  3607. if (IS_ALIGNED(width, 32)) {
  3608. RGB565ToARGBRow = RGB565ToARGBRow_LASX;
  3609. }
  3610. }
  3611. #endif
  3612. for (y = 0; y < height; ++y) {
  3613. RGB565ToARGBRow(src_rgb565, dst_argb, width);
  3614. src_rgb565 += src_stride_rgb565;
  3615. dst_argb += dst_stride_argb;
  3616. }
  3617. return 0;
  3618. }
  3619. // Convert ARGB1555 to ARGB.
  3620. LIBYUV_API
  3621. int ARGB1555ToARGB(const uint8_t* src_argb1555,
  3622. int src_stride_argb1555,
  3623. uint8_t* dst_argb,
  3624. int dst_stride_argb,
  3625. int width,
  3626. int height) {
  3627. int y;
  3628. void (*ARGB1555ToARGBRow)(const uint8_t* src_argb1555, uint8_t* dst_argb,
  3629. int width) = ARGB1555ToARGBRow_C;
  3630. if (!src_argb1555 || !dst_argb || width <= 0 || height == 0) {
  3631. return -1;
  3632. }
  3633. // Negative height means invert the image.
  3634. if (height < 0) {
  3635. height = -height;
  3636. src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555;
  3637. src_stride_argb1555 = -src_stride_argb1555;
  3638. }
  3639. // Coalesce rows.
  3640. if (src_stride_argb1555 == width * 2 && dst_stride_argb == width * 4) {
  3641. width *= height;
  3642. height = 1;
  3643. src_stride_argb1555 = dst_stride_argb = 0;
  3644. }
  3645. #if defined(HAS_ARGB1555TOARGBROW_SSE2)
  3646. if (TestCpuFlag(kCpuHasSSE2)) {
  3647. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2;
  3648. if (IS_ALIGNED(width, 8)) {
  3649. ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2;
  3650. }
  3651. }
  3652. #endif
  3653. #if defined(HAS_ARGB1555TOARGBROW_AVX2)
  3654. if (TestCpuFlag(kCpuHasAVX2)) {
  3655. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2;
  3656. if (IS_ALIGNED(width, 16)) {
  3657. ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX2;
  3658. }
  3659. }
  3660. #endif
  3661. #if defined(HAS_ARGB1555TOARGBROW_NEON)
  3662. if (TestCpuFlag(kCpuHasNEON)) {
  3663. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_NEON;
  3664. if (IS_ALIGNED(width, 8)) {
  3665. ARGB1555ToARGBRow = ARGB1555ToARGBRow_NEON;
  3666. }
  3667. }
  3668. #endif
  3669. #if defined(HAS_ARGB1555TOARGBROW_SVE2)
  3670. if (TestCpuFlag(kCpuHasSVE2)) {
  3671. ARGB1555ToARGBRow = ARGB1555ToARGBRow_SVE2;
  3672. }
  3673. #endif
  3674. #if defined(HAS_ARGB1555TOARGBROW_MSA)
  3675. if (TestCpuFlag(kCpuHasMSA)) {
  3676. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_MSA;
  3677. if (IS_ALIGNED(width, 16)) {
  3678. ARGB1555ToARGBRow = ARGB1555ToARGBRow_MSA;
  3679. }
  3680. }
  3681. #endif
  3682. #if defined(HAS_ARGB1555TOARGBROW_LSX)
  3683. if (TestCpuFlag(kCpuHasLSX)) {
  3684. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LSX;
  3685. if (IS_ALIGNED(width, 16)) {
  3686. ARGB1555ToARGBRow = ARGB1555ToARGBRow_LSX;
  3687. }
  3688. }
  3689. #endif
  3690. #if defined(HAS_ARGB1555TOARGBROW_LASX)
  3691. if (TestCpuFlag(kCpuHasLASX)) {
  3692. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LASX;
  3693. if (IS_ALIGNED(width, 32)) {
  3694. ARGB1555ToARGBRow = ARGB1555ToARGBRow_LASX;
  3695. }
  3696. }
  3697. #endif
  3698. for (y = 0; y < height; ++y) {
  3699. ARGB1555ToARGBRow(src_argb1555, dst_argb, width);
  3700. src_argb1555 += src_stride_argb1555;
  3701. dst_argb += dst_stride_argb;
  3702. }
  3703. return 0;
  3704. }
  3705. // Convert ARGB4444 to ARGB.
  3706. LIBYUV_API
  3707. int ARGB4444ToARGB(const uint8_t* src_argb4444,
  3708. int src_stride_argb4444,
  3709. uint8_t* dst_argb,
  3710. int dst_stride_argb,
  3711. int width,
  3712. int height) {
  3713. int y;
  3714. void (*ARGB4444ToARGBRow)(const uint8_t* src_argb4444, uint8_t* dst_argb,
  3715. int width) = ARGB4444ToARGBRow_C;
  3716. if (!src_argb4444 || !dst_argb || width <= 0 || height == 0) {
  3717. return -1;
  3718. }
  3719. // Negative height means invert the image.
  3720. if (height < 0) {
  3721. height = -height;
  3722. src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444;
  3723. src_stride_argb4444 = -src_stride_argb4444;
  3724. }
  3725. // Coalesce rows.
  3726. if (src_stride_argb4444 == width * 2 && dst_stride_argb == width * 4) {
  3727. width *= height;
  3728. height = 1;
  3729. src_stride_argb4444 = dst_stride_argb = 0;
  3730. }
  3731. #if defined(HAS_ARGB4444TOARGBROW_SSE2)
  3732. if (TestCpuFlag(kCpuHasSSE2)) {
  3733. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2;
  3734. if (IS_ALIGNED(width, 8)) {
  3735. ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2;
  3736. }
  3737. }
  3738. #endif
  3739. #if defined(HAS_ARGB4444TOARGBROW_AVX2)
  3740. if (TestCpuFlag(kCpuHasAVX2)) {
  3741. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2;
  3742. if (IS_ALIGNED(width, 16)) {
  3743. ARGB4444ToARGBRow = ARGB4444ToARGBRow_AVX2;
  3744. }
  3745. }
  3746. #endif
  3747. #if defined(HAS_ARGB4444TOARGBROW_NEON)
  3748. if (TestCpuFlag(kCpuHasNEON)) {
  3749. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_NEON;
  3750. if (IS_ALIGNED(width, 8)) {
  3751. ARGB4444ToARGBRow = ARGB4444ToARGBRow_NEON;
  3752. }
  3753. }
  3754. #endif
  3755. #if defined(HAS_ARGB4444TOARGBROW_MSA)
  3756. if (TestCpuFlag(kCpuHasMSA)) {
  3757. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MSA;
  3758. if (IS_ALIGNED(width, 16)) {
  3759. ARGB4444ToARGBRow = ARGB4444ToARGBRow_MSA;
  3760. }
  3761. }
  3762. #endif
  3763. #if defined(HAS_ARGB4444TOARGBROW_LSX)
  3764. if (TestCpuFlag(kCpuHasLSX)) {
  3765. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LSX;
  3766. if (IS_ALIGNED(width, 16)) {
  3767. ARGB4444ToARGBRow = ARGB4444ToARGBRow_LSX;
  3768. }
  3769. }
  3770. #endif
  3771. #if defined(HAS_ARGB4444TOARGBROW_LASX)
  3772. if (TestCpuFlag(kCpuHasLASX)) {
  3773. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LASX;
  3774. if (IS_ALIGNED(width, 32)) {
  3775. ARGB4444ToARGBRow = ARGB4444ToARGBRow_LASX;
  3776. }
  3777. }
  3778. #endif
  3779. for (y = 0; y < height; ++y) {
  3780. ARGB4444ToARGBRow(src_argb4444, dst_argb, width);
  3781. src_argb4444 += src_stride_argb4444;
  3782. dst_argb += dst_stride_argb;
  3783. }
  3784. return 0;
  3785. }
  3786. // Convert AR30 to ARGB.
  3787. LIBYUV_API
  3788. int AR30ToARGB(const uint8_t* src_ar30,
  3789. int src_stride_ar30,
  3790. uint8_t* dst_argb,
  3791. int dst_stride_argb,
  3792. int width,
  3793. int height) {
  3794. int y;
  3795. if (!src_ar30 || !dst_argb || width <= 0 || height == 0) {
  3796. return -1;
  3797. }
  3798. // Negative height means invert the image.
  3799. if (height < 0) {
  3800. height = -height;
  3801. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  3802. src_stride_ar30 = -src_stride_ar30;
  3803. }
  3804. // Coalesce rows.
  3805. if (src_stride_ar30 == width * 4 && dst_stride_argb == width * 4) {
  3806. width *= height;
  3807. height = 1;
  3808. src_stride_ar30 = dst_stride_argb = 0;
  3809. }
  3810. for (y = 0; y < height; ++y) {
  3811. AR30ToARGBRow_C(src_ar30, dst_argb, width);
  3812. src_ar30 += src_stride_ar30;
  3813. dst_argb += dst_stride_argb;
  3814. }
  3815. return 0;
  3816. }
  3817. // Convert AR30 to ABGR.
  3818. LIBYUV_API
  3819. int AR30ToABGR(const uint8_t* src_ar30,
  3820. int src_stride_ar30,
  3821. uint8_t* dst_abgr,
  3822. int dst_stride_abgr,
  3823. int width,
  3824. int height) {
  3825. int y;
  3826. if (!src_ar30 || !dst_abgr || width <= 0 || height == 0) {
  3827. return -1;
  3828. }
  3829. // Negative height means invert the image.
  3830. if (height < 0) {
  3831. height = -height;
  3832. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  3833. src_stride_ar30 = -src_stride_ar30;
  3834. }
  3835. // Coalesce rows.
  3836. if (src_stride_ar30 == width * 4 && dst_stride_abgr == width * 4) {
  3837. width *= height;
  3838. height = 1;
  3839. src_stride_ar30 = dst_stride_abgr = 0;
  3840. }
  3841. for (y = 0; y < height; ++y) {
  3842. AR30ToABGRRow_C(src_ar30, dst_abgr, width);
  3843. src_ar30 += src_stride_ar30;
  3844. dst_abgr += dst_stride_abgr;
  3845. }
  3846. return 0;
  3847. }
  3848. // Convert AR30 to AB30.
  3849. LIBYUV_API
  3850. int AR30ToAB30(const uint8_t* src_ar30,
  3851. int src_stride_ar30,
  3852. uint8_t* dst_ab30,
  3853. int dst_stride_ab30,
  3854. int width,
  3855. int height) {
  3856. int y;
  3857. if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0) {
  3858. return -1;
  3859. }
  3860. // Negative height means invert the image.
  3861. if (height < 0) {
  3862. height = -height;
  3863. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  3864. src_stride_ar30 = -src_stride_ar30;
  3865. }
  3866. // Coalesce rows.
  3867. if (src_stride_ar30 == width * 4 && dst_stride_ab30 == width * 4) {
  3868. width *= height;
  3869. height = 1;
  3870. src_stride_ar30 = dst_stride_ab30 = 0;
  3871. }
  3872. for (y = 0; y < height; ++y) {
  3873. AR30ToAB30Row_C(src_ar30, dst_ab30, width);
  3874. src_ar30 += src_stride_ar30;
  3875. dst_ab30 += dst_stride_ab30;
  3876. }
  3877. return 0;
  3878. }
  3879. // Convert AR64 to ARGB.
  3880. LIBYUV_API
  3881. int AR64ToARGB(const uint16_t* src_ar64,
  3882. int src_stride_ar64,
  3883. uint8_t* dst_argb,
  3884. int dst_stride_argb,
  3885. int width,
  3886. int height) {
  3887. int y;
  3888. void (*AR64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb,
  3889. int width) = AR64ToARGBRow_C;
  3890. if (!src_ar64 || !dst_argb || width <= 0 || height == 0) {
  3891. return -1;
  3892. }
  3893. // Negative height means invert the image.
  3894. if (height < 0) {
  3895. height = -height;
  3896. src_ar64 = src_ar64 + (height - 1) * src_stride_ar64;
  3897. src_stride_ar64 = -src_stride_ar64;
  3898. }
  3899. // Coalesce rows.
  3900. if (src_stride_ar64 == width * 4 && dst_stride_argb == width * 4) {
  3901. width *= height;
  3902. height = 1;
  3903. src_stride_ar64 = dst_stride_argb = 0;
  3904. }
  3905. #if defined(HAS_AR64TOARGBROW_SSSE3)
  3906. if (TestCpuFlag(kCpuHasSSSE3)) {
  3907. AR64ToARGBRow = AR64ToARGBRow_Any_SSSE3;
  3908. if (IS_ALIGNED(width, 4)) {
  3909. AR64ToARGBRow = AR64ToARGBRow_SSSE3;
  3910. }
  3911. }
  3912. #endif
  3913. #if defined(HAS_AR64TOARGBROW_AVX2)
  3914. if (TestCpuFlag(kCpuHasAVX2)) {
  3915. AR64ToARGBRow = AR64ToARGBRow_Any_AVX2;
  3916. if (IS_ALIGNED(width, 8)) {
  3917. AR64ToARGBRow = AR64ToARGBRow_AVX2;
  3918. }
  3919. }
  3920. #endif
  3921. #if defined(HAS_AR64TOARGBROW_NEON)
  3922. if (TestCpuFlag(kCpuHasNEON)) {
  3923. AR64ToARGBRow = AR64ToARGBRow_Any_NEON;
  3924. if (IS_ALIGNED(width, 8)) {
  3925. AR64ToARGBRow = AR64ToARGBRow_NEON;
  3926. }
  3927. }
  3928. #endif
  3929. #if defined(HAS_AR64TOARGBROW_RVV)
  3930. if (TestCpuFlag(kCpuHasRVV)) {
  3931. AR64ToARGBRow = AR64ToARGBRow_RVV;
  3932. }
  3933. #endif
  3934. for (y = 0; y < height; ++y) {
  3935. AR64ToARGBRow(src_ar64, dst_argb, width);
  3936. src_ar64 += src_stride_ar64;
  3937. dst_argb += dst_stride_argb;
  3938. }
  3939. return 0;
  3940. }
  3941. // Convert AB64 to ARGB.
  3942. LIBYUV_API
  3943. int AB64ToARGB(const uint16_t* src_ab64,
  3944. int src_stride_ab64,
  3945. uint8_t* dst_argb,
  3946. int dst_stride_argb,
  3947. int width,
  3948. int height) {
  3949. int y;
  3950. void (*AB64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb,
  3951. int width) = AB64ToARGBRow_C;
  3952. if (!src_ab64 || !dst_argb || width <= 0 || height == 0) {
  3953. return -1;
  3954. }
  3955. // Negative height means invert the image.
  3956. if (height < 0) {
  3957. height = -height;
  3958. src_ab64 = src_ab64 + (height - 1) * src_stride_ab64;
  3959. src_stride_ab64 = -src_stride_ab64;
  3960. }
  3961. // Coalesce rows.
  3962. if (src_stride_ab64 == width * 4 && dst_stride_argb == width * 4) {
  3963. width *= height;
  3964. height = 1;
  3965. src_stride_ab64 = dst_stride_argb = 0;
  3966. }
  3967. #if defined(HAS_AB64TOARGBROW_SSSE3)
  3968. if (TestCpuFlag(kCpuHasSSSE3)) {
  3969. AB64ToARGBRow = AB64ToARGBRow_Any_SSSE3;
  3970. if (IS_ALIGNED(width, 4)) {
  3971. AB64ToARGBRow = AB64ToARGBRow_SSSE3;
  3972. }
  3973. }
  3974. #endif
  3975. #if defined(HAS_AB64TOARGBROW_AVX2)
  3976. if (TestCpuFlag(kCpuHasAVX2)) {
  3977. AB64ToARGBRow = AB64ToARGBRow_Any_AVX2;
  3978. if (IS_ALIGNED(width, 8)) {
  3979. AB64ToARGBRow = AB64ToARGBRow_AVX2;
  3980. }
  3981. }
  3982. #endif
  3983. #if defined(HAS_AB64TOARGBROW_NEON)
  3984. if (TestCpuFlag(kCpuHasNEON)) {
  3985. AB64ToARGBRow = AB64ToARGBRow_Any_NEON;
  3986. if (IS_ALIGNED(width, 8)) {
  3987. AB64ToARGBRow = AB64ToARGBRow_NEON;
  3988. }
  3989. }
  3990. #endif
  3991. #if defined(HAS_AB64TOARGBROW_RVV)
  3992. if (TestCpuFlag(kCpuHasRVV)) {
  3993. AB64ToARGBRow = AB64ToARGBRow_RVV;
  3994. }
  3995. #endif
  3996. for (y = 0; y < height; ++y) {
  3997. AB64ToARGBRow(src_ab64, dst_argb, width);
  3998. src_ab64 += src_stride_ab64;
  3999. dst_argb += dst_stride_argb;
  4000. }
  4001. return 0;
  4002. }
  4003. // Convert NV12 to ARGB with matrix.
  4004. LIBYUV_API
  4005. int NV12ToARGBMatrix(const uint8_t* src_y,
  4006. int src_stride_y,
  4007. const uint8_t* src_uv,
  4008. int src_stride_uv,
  4009. uint8_t* dst_argb,
  4010. int dst_stride_argb,
  4011. const struct YuvConstants* yuvconstants,
  4012. int width,
  4013. int height) {
  4014. int y;
  4015. void (*NV12ToARGBRow)(
  4016. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  4017. const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C;
  4018. assert(yuvconstants);
  4019. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  4020. return -1;
  4021. }
  4022. // Negative height means invert the image.
  4023. if (height < 0) {
  4024. height = -height;
  4025. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  4026. dst_stride_argb = -dst_stride_argb;
  4027. }
  4028. #if defined(HAS_NV12TOARGBROW_SSSE3)
  4029. if (TestCpuFlag(kCpuHasSSSE3)) {
  4030. NV12ToARGBRow = NV12ToARGBRow_Any_SSSE3;
  4031. if (IS_ALIGNED(width, 8)) {
  4032. NV12ToARGBRow = NV12ToARGBRow_SSSE3;
  4033. }
  4034. }
  4035. #endif
  4036. #if defined(HAS_NV12TOARGBROW_AVX2)
  4037. if (TestCpuFlag(kCpuHasAVX2)) {
  4038. NV12ToARGBRow = NV12ToARGBRow_Any_AVX2;
  4039. if (IS_ALIGNED(width, 16)) {
  4040. NV12ToARGBRow = NV12ToARGBRow_AVX2;
  4041. }
  4042. }
  4043. #endif
  4044. #if defined(HAS_NV12TOARGBROW_NEON)
  4045. if (TestCpuFlag(kCpuHasNEON)) {
  4046. NV12ToARGBRow = NV12ToARGBRow_Any_NEON;
  4047. if (IS_ALIGNED(width, 8)) {
  4048. NV12ToARGBRow = NV12ToARGBRow_NEON;
  4049. }
  4050. }
  4051. #endif
  4052. #if defined(HAS_NV12TOARGBROW_SVE2)
  4053. if (TestCpuFlag(kCpuHasSVE2)) {
  4054. NV12ToARGBRow = NV12ToARGBRow_SVE2;
  4055. }
  4056. #endif
  4057. #if defined(HAS_NV12TOARGBROW_MSA)
  4058. if (TestCpuFlag(kCpuHasMSA)) {
  4059. NV12ToARGBRow = NV12ToARGBRow_Any_MSA;
  4060. if (IS_ALIGNED(width, 8)) {
  4061. NV12ToARGBRow = NV12ToARGBRow_MSA;
  4062. }
  4063. }
  4064. #endif
  4065. #if defined(HAS_NV12TOARGBROW_LSX)
  4066. if (TestCpuFlag(kCpuHasLSX)) {
  4067. NV12ToARGBRow = NV12ToARGBRow_Any_LSX;
  4068. if (IS_ALIGNED(width, 8)) {
  4069. NV12ToARGBRow = NV12ToARGBRow_LSX;
  4070. }
  4071. }
  4072. #endif
  4073. #if defined(HAS_NV12TOARGBROW_LASX)
  4074. if (TestCpuFlag(kCpuHasLASX)) {
  4075. NV12ToARGBRow = NV12ToARGBRow_Any_LASX;
  4076. if (IS_ALIGNED(width, 16)) {
  4077. NV12ToARGBRow = NV12ToARGBRow_LASX;
  4078. }
  4079. }
  4080. #endif
  4081. #if defined(HAS_NV12TOARGBROW_RVV)
  4082. if (TestCpuFlag(kCpuHasRVV)) {
  4083. NV12ToARGBRow = NV12ToARGBRow_RVV;
  4084. }
  4085. #endif
  4086. for (y = 0; y < height; ++y) {
  4087. NV12ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width);
  4088. dst_argb += dst_stride_argb;
  4089. src_y += src_stride_y;
  4090. if (y & 1) {
  4091. src_uv += src_stride_uv;
  4092. }
  4093. }
  4094. return 0;
  4095. }
  4096. // Convert NV21 to ARGB with matrix.
  4097. LIBYUV_API
  4098. int NV21ToARGBMatrix(const uint8_t* src_y,
  4099. int src_stride_y,
  4100. const uint8_t* src_vu,
  4101. int src_stride_vu,
  4102. uint8_t* dst_argb,
  4103. int dst_stride_argb,
  4104. const struct YuvConstants* yuvconstants,
  4105. int width,
  4106. int height) {
  4107. int y;
  4108. void (*NV21ToARGBRow)(
  4109. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  4110. const struct YuvConstants* yuvconstants, int width) = NV21ToARGBRow_C;
  4111. assert(yuvconstants);
  4112. if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0) {
  4113. return -1;
  4114. }
  4115. // Negative height means invert the image.
  4116. if (height < 0) {
  4117. height = -height;
  4118. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  4119. dst_stride_argb = -dst_stride_argb;
  4120. }
  4121. #if defined(HAS_NV21TOARGBROW_SSSE3)
  4122. if (TestCpuFlag(kCpuHasSSSE3)) {
  4123. NV21ToARGBRow = NV21ToARGBRow_Any_SSSE3;
  4124. if (IS_ALIGNED(width, 8)) {
  4125. NV21ToARGBRow = NV21ToARGBRow_SSSE3;
  4126. }
  4127. }
  4128. #endif
  4129. #if defined(HAS_NV21TOARGBROW_AVX2)
  4130. if (TestCpuFlag(kCpuHasAVX2)) {
  4131. NV21ToARGBRow = NV21ToARGBRow_Any_AVX2;
  4132. if (IS_ALIGNED(width, 16)) {
  4133. NV21ToARGBRow = NV21ToARGBRow_AVX2;
  4134. }
  4135. }
  4136. #endif
  4137. #if defined(HAS_NV21TOARGBROW_NEON)
  4138. if (TestCpuFlag(kCpuHasNEON)) {
  4139. NV21ToARGBRow = NV21ToARGBRow_Any_NEON;
  4140. if (IS_ALIGNED(width, 8)) {
  4141. NV21ToARGBRow = NV21ToARGBRow_NEON;
  4142. }
  4143. }
  4144. #endif
  4145. #if defined(HAS_NV21TOARGBROW_SVE2)
  4146. if (TestCpuFlag(kCpuHasSVE2)) {
  4147. NV21ToARGBRow = NV21ToARGBRow_SVE2;
  4148. }
  4149. #endif
  4150. #if defined(HAS_NV21TOARGBROW_MSA)
  4151. if (TestCpuFlag(kCpuHasMSA)) {
  4152. NV21ToARGBRow = NV21ToARGBRow_Any_MSA;
  4153. if (IS_ALIGNED(width, 8)) {
  4154. NV21ToARGBRow = NV21ToARGBRow_MSA;
  4155. }
  4156. }
  4157. #endif
  4158. #if defined(HAS_NV21TOARGBROW_LSX)
  4159. if (TestCpuFlag(kCpuHasLSX)) {
  4160. NV21ToARGBRow = NV21ToARGBRow_Any_LSX;
  4161. if (IS_ALIGNED(width, 8)) {
  4162. NV21ToARGBRow = NV21ToARGBRow_LSX;
  4163. }
  4164. }
  4165. #endif
  4166. #if defined(HAS_NV21TOARGBROW_LASX)
  4167. if (TestCpuFlag(kCpuHasLASX)) {
  4168. NV21ToARGBRow = NV21ToARGBRow_Any_LASX;
  4169. if (IS_ALIGNED(width, 16)) {
  4170. NV21ToARGBRow = NV21ToARGBRow_LASX;
  4171. }
  4172. }
  4173. #endif
  4174. #if defined(HAS_NV21TOARGBROW_RVV)
  4175. if (TestCpuFlag(kCpuHasRVV)) {
  4176. NV21ToARGBRow = NV21ToARGBRow_RVV;
  4177. }
  4178. #endif
  4179. for (y = 0; y < height; ++y) {
  4180. NV21ToARGBRow(src_y, src_vu, dst_argb, yuvconstants, width);
  4181. dst_argb += dst_stride_argb;
  4182. src_y += src_stride_y;
  4183. if (y & 1) {
  4184. src_vu += src_stride_vu;
  4185. }
  4186. }
  4187. return 0;
  4188. }
  4189. // Convert NV12 to ARGB.
  4190. LIBYUV_API
  4191. int NV12ToARGB(const uint8_t* src_y,
  4192. int src_stride_y,
  4193. const uint8_t* src_uv,
  4194. int src_stride_uv,
  4195. uint8_t* dst_argb,
  4196. int dst_stride_argb,
  4197. int width,
  4198. int height) {
  4199. return NV12ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_argb,
  4200. dst_stride_argb, &kYuvI601Constants, width, height);
  4201. }
  4202. // Convert NV21 to ARGB.
  4203. LIBYUV_API
  4204. int NV21ToARGB(const uint8_t* src_y,
  4205. int src_stride_y,
  4206. const uint8_t* src_vu,
  4207. int src_stride_vu,
  4208. uint8_t* dst_argb,
  4209. int dst_stride_argb,
  4210. int width,
  4211. int height) {
  4212. return NV21ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_argb,
  4213. dst_stride_argb, &kYuvI601Constants, width, height);
  4214. }
  4215. // Convert NV12 to ABGR.
  4216. // To output ABGR instead of ARGB swap the UV and use a mirrored yuv matrix.
  4217. // To swap the UV use NV12 instead of NV21.LIBYUV_API
  4218. LIBYUV_API
  4219. int NV12ToABGR(const uint8_t* src_y,
  4220. int src_stride_y,
  4221. const uint8_t* src_uv,
  4222. int src_stride_uv,
  4223. uint8_t* dst_abgr,
  4224. int dst_stride_abgr,
  4225. int width,
  4226. int height) {
  4227. return NV21ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_abgr,
  4228. dst_stride_abgr, &kYvuI601Constants, width, height);
  4229. }
  4230. // Convert NV21 to ABGR.
  4231. LIBYUV_API
  4232. int NV21ToABGR(const uint8_t* src_y,
  4233. int src_stride_y,
  4234. const uint8_t* src_vu,
  4235. int src_stride_vu,
  4236. uint8_t* dst_abgr,
  4237. int dst_stride_abgr,
  4238. int width,
  4239. int height) {
  4240. return NV12ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_abgr,
  4241. dst_stride_abgr, &kYvuI601Constants, width, height);
  4242. }
  4243. // TODO(fbarchard): Consider SSSE3 2 step conversion.
  4244. // Convert NV12 to RGB24 with matrix.
  4245. LIBYUV_API
  4246. int NV12ToRGB24Matrix(const uint8_t* src_y,
  4247. int src_stride_y,
  4248. const uint8_t* src_uv,
  4249. int src_stride_uv,
  4250. uint8_t* dst_rgb24,
  4251. int dst_stride_rgb24,
  4252. const struct YuvConstants* yuvconstants,
  4253. int width,
  4254. int height) {
  4255. int y;
  4256. void (*NV12ToRGB24Row)(
  4257. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  4258. const struct YuvConstants* yuvconstants, int width) = NV12ToRGB24Row_C;
  4259. assert(yuvconstants);
  4260. if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0) {
  4261. return -1;
  4262. }
  4263. // Negative height means invert the image.
  4264. if (height < 0) {
  4265. height = -height;
  4266. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  4267. dst_stride_rgb24 = -dst_stride_rgb24;
  4268. }
  4269. #if defined(HAS_NV12TORGB24ROW_NEON)
  4270. if (TestCpuFlag(kCpuHasNEON)) {
  4271. NV12ToRGB24Row = NV12ToRGB24Row_Any_NEON;
  4272. if (IS_ALIGNED(width, 8)) {
  4273. NV12ToRGB24Row = NV12ToRGB24Row_NEON;
  4274. }
  4275. }
  4276. #endif
  4277. #if defined(HAS_NV12TORGB24ROW_SSSE3)
  4278. if (TestCpuFlag(kCpuHasSSSE3)) {
  4279. NV12ToRGB24Row = NV12ToRGB24Row_Any_SSSE3;
  4280. if (IS_ALIGNED(width, 16)) {
  4281. NV12ToRGB24Row = NV12ToRGB24Row_SSSE3;
  4282. }
  4283. }
  4284. #endif
  4285. #if defined(HAS_NV12TORGB24ROW_AVX2)
  4286. if (TestCpuFlag(kCpuHasAVX2)) {
  4287. NV12ToRGB24Row = NV12ToRGB24Row_Any_AVX2;
  4288. if (IS_ALIGNED(width, 32)) {
  4289. NV12ToRGB24Row = NV12ToRGB24Row_AVX2;
  4290. }
  4291. }
  4292. #endif
  4293. #if defined(HAS_NV12TORGB24ROW_RVV)
  4294. if (TestCpuFlag(kCpuHasRVV)) {
  4295. NV12ToRGB24Row = NV12ToRGB24Row_RVV;
  4296. }
  4297. #endif
  4298. for (y = 0; y < height; ++y) {
  4299. NV12ToRGB24Row(src_y, src_uv, dst_rgb24, yuvconstants, width);
  4300. dst_rgb24 += dst_stride_rgb24;
  4301. src_y += src_stride_y;
  4302. if (y & 1) {
  4303. src_uv += src_stride_uv;
  4304. }
  4305. }
  4306. return 0;
  4307. }
  4308. // Convert NV21 to RGB24 with matrix.
  4309. LIBYUV_API
  4310. int NV21ToRGB24Matrix(const uint8_t* src_y,
  4311. int src_stride_y,
  4312. const uint8_t* src_vu,
  4313. int src_stride_vu,
  4314. uint8_t* dst_rgb24,
  4315. int dst_stride_rgb24,
  4316. const struct YuvConstants* yuvconstants,
  4317. int width,
  4318. int height) {
  4319. int y;
  4320. void (*NV21ToRGB24Row)(
  4321. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  4322. const struct YuvConstants* yuvconstants, int width) = NV21ToRGB24Row_C;
  4323. assert(yuvconstants);
  4324. if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0) {
  4325. return -1;
  4326. }
  4327. // Negative height means invert the image.
  4328. if (height < 0) {
  4329. height = -height;
  4330. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  4331. dst_stride_rgb24 = -dst_stride_rgb24;
  4332. }
  4333. #if defined(HAS_NV21TORGB24ROW_NEON)
  4334. if (TestCpuFlag(kCpuHasNEON)) {
  4335. NV21ToRGB24Row = NV21ToRGB24Row_Any_NEON;
  4336. if (IS_ALIGNED(width, 8)) {
  4337. NV21ToRGB24Row = NV21ToRGB24Row_NEON;
  4338. }
  4339. }
  4340. #endif
  4341. #if defined(HAS_NV21TORGB24ROW_SSSE3)
  4342. if (TestCpuFlag(kCpuHasSSSE3)) {
  4343. NV21ToRGB24Row = NV21ToRGB24Row_Any_SSSE3;
  4344. if (IS_ALIGNED(width, 16)) {
  4345. NV21ToRGB24Row = NV21ToRGB24Row_SSSE3;
  4346. }
  4347. }
  4348. #endif
  4349. #if defined(HAS_NV21TORGB24ROW_AVX2)
  4350. if (TestCpuFlag(kCpuHasAVX2)) {
  4351. NV21ToRGB24Row = NV21ToRGB24Row_Any_AVX2;
  4352. if (IS_ALIGNED(width, 32)) {
  4353. NV21ToRGB24Row = NV21ToRGB24Row_AVX2;
  4354. }
  4355. }
  4356. #endif
  4357. #if defined(HAS_NV21TORGB24ROW_RVV)
  4358. if (TestCpuFlag(kCpuHasRVV)) {
  4359. NV21ToRGB24Row = NV21ToRGB24Row_RVV;
  4360. }
  4361. #endif
  4362. for (y = 0; y < height; ++y) {
  4363. NV21ToRGB24Row(src_y, src_vu, dst_rgb24, yuvconstants, width);
  4364. dst_rgb24 += dst_stride_rgb24;
  4365. src_y += src_stride_y;
  4366. if (y & 1) {
  4367. src_vu += src_stride_vu;
  4368. }
  4369. }
  4370. return 0;
  4371. }
  4372. // Convert NV12 to RGB24.
  4373. LIBYUV_API
  4374. int NV12ToRGB24(const uint8_t* src_y,
  4375. int src_stride_y,
  4376. const uint8_t* src_uv,
  4377. int src_stride_uv,
  4378. uint8_t* dst_rgb24,
  4379. int dst_stride_rgb24,
  4380. int width,
  4381. int height) {
  4382. return NV12ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  4383. dst_rgb24, dst_stride_rgb24, &kYuvI601Constants,
  4384. width, height);
  4385. }
  4386. // Convert NV21 to RGB24.
  4387. LIBYUV_API
  4388. int NV21ToRGB24(const uint8_t* src_y,
  4389. int src_stride_y,
  4390. const uint8_t* src_vu,
  4391. int src_stride_vu,
  4392. uint8_t* dst_rgb24,
  4393. int dst_stride_rgb24,
  4394. int width,
  4395. int height) {
  4396. return NV21ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu,
  4397. dst_rgb24, dst_stride_rgb24, &kYuvI601Constants,
  4398. width, height);
  4399. }
  4400. // Convert NV12 to RAW.
  4401. LIBYUV_API
  4402. int NV12ToRAW(const uint8_t* src_y,
  4403. int src_stride_y,
  4404. const uint8_t* src_uv,
  4405. int src_stride_uv,
  4406. uint8_t* dst_raw,
  4407. int dst_stride_raw,
  4408. int width,
  4409. int height) {
  4410. return NV21ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_raw,
  4411. dst_stride_raw, &kYvuI601Constants, width, height);
  4412. }
  4413. // Convert NV21 to RAW.
  4414. LIBYUV_API
  4415. int NV21ToRAW(const uint8_t* src_y,
  4416. int src_stride_y,
  4417. const uint8_t* src_vu,
  4418. int src_stride_vu,
  4419. uint8_t* dst_raw,
  4420. int dst_stride_raw,
  4421. int width,
  4422. int height) {
  4423. return NV12ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_raw,
  4424. dst_stride_raw, &kYvuI601Constants, width, height);
  4425. }
  4426. // Convert NV21 to YUV24
  4427. int NV21ToYUV24(const uint8_t* src_y,
  4428. int src_stride_y,
  4429. const uint8_t* src_vu,
  4430. int src_stride_vu,
  4431. uint8_t* dst_yuv24,
  4432. int dst_stride_yuv24,
  4433. int width,
  4434. int height) {
  4435. int y;
  4436. void (*NV21ToYUV24Row)(const uint8_t* src_y, const uint8_t* src_vu,
  4437. uint8_t* dst_yuv24, int width) = NV21ToYUV24Row_C;
  4438. if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0) {
  4439. return -1;
  4440. }
  4441. // Negative height means invert the image.
  4442. if (height < 0) {
  4443. height = -height;
  4444. dst_yuv24 = dst_yuv24 + (height - 1) * dst_stride_yuv24;
  4445. dst_stride_yuv24 = -dst_stride_yuv24;
  4446. }
  4447. #if defined(HAS_NV21TOYUV24ROW_NEON)
  4448. if (TestCpuFlag(kCpuHasNEON)) {
  4449. NV21ToYUV24Row = NV21ToYUV24Row_Any_NEON;
  4450. if (IS_ALIGNED(width, 16)) {
  4451. NV21ToYUV24Row = NV21ToYUV24Row_NEON;
  4452. }
  4453. }
  4454. #endif
  4455. #if defined(HAS_NV21TOYUV24ROW_SSSE3)
  4456. if (TestCpuFlag(kCpuHasSSSE3)) {
  4457. NV21ToYUV24Row = NV21ToYUV24Row_Any_SSSE3;
  4458. if (IS_ALIGNED(width, 16)) {
  4459. NV21ToYUV24Row = NV21ToYUV24Row_SSSE3;
  4460. }
  4461. }
  4462. #endif
  4463. #if defined(HAS_NV21TOYUV24ROW_AVX2)
  4464. if (TestCpuFlag(kCpuHasAVX2)) {
  4465. NV21ToYUV24Row = NV21ToYUV24Row_Any_AVX2;
  4466. if (IS_ALIGNED(width, 32)) {
  4467. NV21ToYUV24Row = NV21ToYUV24Row_AVX2;
  4468. }
  4469. }
  4470. #endif
  4471. for (y = 0; y < height; ++y) {
  4472. NV21ToYUV24Row(src_y, src_vu, dst_yuv24, width);
  4473. dst_yuv24 += dst_stride_yuv24;
  4474. src_y += src_stride_y;
  4475. if (y & 1) {
  4476. src_vu += src_stride_vu;
  4477. }
  4478. }
  4479. return 0;
  4480. }
  4481. // Convert YUY2 to ARGB with matrix.
  4482. LIBYUV_API
  4483. int YUY2ToARGBMatrix(const uint8_t* src_yuy2,
  4484. int src_stride_yuy2,
  4485. uint8_t* dst_argb,
  4486. int dst_stride_argb,
  4487. const struct YuvConstants* yuvconstants,
  4488. int width,
  4489. int height) {
  4490. int y;
  4491. void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb,
  4492. const struct YuvConstants* yuvconstants, int width) =
  4493. YUY2ToARGBRow_C;
  4494. if (!src_yuy2 || !dst_argb || width <= 0 || height == 0) {
  4495. return -1;
  4496. }
  4497. // Negative height means invert the image.
  4498. if (height < 0) {
  4499. height = -height;
  4500. src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2;
  4501. src_stride_yuy2 = -src_stride_yuy2;
  4502. }
  4503. // Coalesce rows.
  4504. if (src_stride_yuy2 == width * 2 && dst_stride_argb == width * 4) {
  4505. width *= height;
  4506. height = 1;
  4507. src_stride_yuy2 = dst_stride_argb = 0;
  4508. }
  4509. #if defined(HAS_YUY2TOARGBROW_SSSE3)
  4510. if (TestCpuFlag(kCpuHasSSSE3)) {
  4511. YUY2ToARGBRow = YUY2ToARGBRow_Any_SSSE3;
  4512. if (IS_ALIGNED(width, 16)) {
  4513. YUY2ToARGBRow = YUY2ToARGBRow_SSSE3;
  4514. }
  4515. }
  4516. #endif
  4517. #if defined(HAS_YUY2TOARGBROW_AVX2)
  4518. if (TestCpuFlag(kCpuHasAVX2)) {
  4519. YUY2ToARGBRow = YUY2ToARGBRow_Any_AVX2;
  4520. if (IS_ALIGNED(width, 32)) {
  4521. YUY2ToARGBRow = YUY2ToARGBRow_AVX2;
  4522. }
  4523. }
  4524. #endif
  4525. #if defined(HAS_YUY2TOARGBROW_NEON)
  4526. if (TestCpuFlag(kCpuHasNEON)) {
  4527. YUY2ToARGBRow = YUY2ToARGBRow_Any_NEON;
  4528. if (IS_ALIGNED(width, 8)) {
  4529. YUY2ToARGBRow = YUY2ToARGBRow_NEON;
  4530. }
  4531. }
  4532. #endif
  4533. #if defined(HAS_YUY2TOARGBROW_SVE2)
  4534. if (TestCpuFlag(kCpuHasSVE2)) {
  4535. YUY2ToARGBRow = YUY2ToARGBRow_SVE2;
  4536. }
  4537. #endif
  4538. #if defined(HAS_YUY2TOARGBROW_MSA)
  4539. if (TestCpuFlag(kCpuHasMSA)) {
  4540. YUY2ToARGBRow = YUY2ToARGBRow_Any_MSA;
  4541. if (IS_ALIGNED(width, 8)) {
  4542. YUY2ToARGBRow = YUY2ToARGBRow_MSA;
  4543. }
  4544. }
  4545. #endif
  4546. #if defined(HAS_YUY2TOARGBROW_LSX)
  4547. if (TestCpuFlag(kCpuHasLSX)) {
  4548. YUY2ToARGBRow = YUY2ToARGBRow_Any_LSX;
  4549. if (IS_ALIGNED(width, 8)) {
  4550. YUY2ToARGBRow = YUY2ToARGBRow_LSX;
  4551. }
  4552. }
  4553. #endif
  4554. for (y = 0; y < height; ++y) {
  4555. YUY2ToARGBRow(src_yuy2, dst_argb, yuvconstants, width);
  4556. src_yuy2 += src_stride_yuy2;
  4557. dst_argb += dst_stride_argb;
  4558. }
  4559. return 0;
  4560. }
  4561. // Convert YUY2 to ARGB.
  4562. LIBYUV_API
  4563. int YUY2ToARGB(const uint8_t* src_yuy2,
  4564. int src_stride_yuy2,
  4565. uint8_t* dst_argb,
  4566. int dst_stride_argb,
  4567. int width,
  4568. int height) {
  4569. return YUY2ToARGBMatrix(src_yuy2, src_stride_yuy2, dst_argb, dst_stride_argb,
  4570. &kYuvI601Constants, width, height);
  4571. }
  4572. // Convert UYVY to ARGB with matrix.
  4573. LIBYUV_API
  4574. int UYVYToARGBMatrix(const uint8_t* src_uyvy,
  4575. int src_stride_uyvy,
  4576. uint8_t* dst_argb,
  4577. int dst_stride_argb,
  4578. const struct YuvConstants* yuvconstants,
  4579. int width,
  4580. int height) {
  4581. int y;
  4582. void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb,
  4583. const struct YuvConstants* yuvconstants, int width) =
  4584. UYVYToARGBRow_C;
  4585. if (!src_uyvy || !dst_argb || width <= 0 || height == 0) {
  4586. return -1;
  4587. }
  4588. // Negative height means invert the image.
  4589. if (height < 0) {
  4590. height = -height;
  4591. src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy;
  4592. src_stride_uyvy = -src_stride_uyvy;
  4593. }
  4594. // Coalesce rows.
  4595. if (src_stride_uyvy == width * 2 && dst_stride_argb == width * 4) {
  4596. width *= height;
  4597. height = 1;
  4598. src_stride_uyvy = dst_stride_argb = 0;
  4599. }
  4600. #if defined(HAS_UYVYTOARGBROW_SSSE3)
  4601. if (TestCpuFlag(kCpuHasSSSE3)) {
  4602. UYVYToARGBRow = UYVYToARGBRow_Any_SSSE3;
  4603. if (IS_ALIGNED(width, 16)) {
  4604. UYVYToARGBRow = UYVYToARGBRow_SSSE3;
  4605. }
  4606. }
  4607. #endif
  4608. #if defined(HAS_UYVYTOARGBROW_AVX2)
  4609. if (TestCpuFlag(kCpuHasAVX2)) {
  4610. UYVYToARGBRow = UYVYToARGBRow_Any_AVX2;
  4611. if (IS_ALIGNED(width, 32)) {
  4612. UYVYToARGBRow = UYVYToARGBRow_AVX2;
  4613. }
  4614. }
  4615. #endif
  4616. #if defined(HAS_UYVYTOARGBROW_NEON)
  4617. if (TestCpuFlag(kCpuHasNEON)) {
  4618. UYVYToARGBRow = UYVYToARGBRow_Any_NEON;
  4619. if (IS_ALIGNED(width, 8)) {
  4620. UYVYToARGBRow = UYVYToARGBRow_NEON;
  4621. }
  4622. }
  4623. #endif
  4624. #if defined(HAS_UYVYTOARGBROW_SVE2)
  4625. if (TestCpuFlag(kCpuHasSVE2)) {
  4626. UYVYToARGBRow = UYVYToARGBRow_SVE2;
  4627. }
  4628. #endif
  4629. #if defined(HAS_UYVYTOARGBROW_MSA)
  4630. if (TestCpuFlag(kCpuHasMSA)) {
  4631. UYVYToARGBRow = UYVYToARGBRow_Any_MSA;
  4632. if (IS_ALIGNED(width, 8)) {
  4633. UYVYToARGBRow = UYVYToARGBRow_MSA;
  4634. }
  4635. }
  4636. #endif
  4637. #if defined(HAS_UYVYTOARGBROW_LSX)
  4638. if (TestCpuFlag(kCpuHasLSX)) {
  4639. UYVYToARGBRow = UYVYToARGBRow_Any_LSX;
  4640. if (IS_ALIGNED(width, 8)) {
  4641. UYVYToARGBRow = UYVYToARGBRow_LSX;
  4642. }
  4643. }
  4644. #endif
  4645. for (y = 0; y < height; ++y) {
  4646. UYVYToARGBRow(src_uyvy, dst_argb, yuvconstants, width);
  4647. src_uyvy += src_stride_uyvy;
  4648. dst_argb += dst_stride_argb;
  4649. }
  4650. return 0;
  4651. }
  4652. // Convert UYVY to ARGB.
  4653. LIBYUV_API
  4654. int UYVYToARGB(const uint8_t* src_uyvy,
  4655. int src_stride_uyvy,
  4656. uint8_t* dst_argb,
  4657. int dst_stride_argb,
  4658. int width,
  4659. int height) {
  4660. return UYVYToARGBMatrix(src_uyvy, src_stride_uyvy, dst_argb, dst_stride_argb,
  4661. &kYuvI601Constants, width, height);
  4662. }
  4663. static void WeavePixels(const uint8_t* src_u,
  4664. const uint8_t* src_v,
  4665. int src_pixel_stride_uv,
  4666. uint8_t* dst_uv,
  4667. int width) {
  4668. int i;
  4669. for (i = 0; i < width; ++i) {
  4670. dst_uv[0] = *src_u;
  4671. dst_uv[1] = *src_v;
  4672. dst_uv += 2;
  4673. src_u += src_pixel_stride_uv;
  4674. src_v += src_pixel_stride_uv;
  4675. }
  4676. }
  4677. // Convert Android420 to ARGB with matrix.
  4678. LIBYUV_API
  4679. int Android420ToARGBMatrix(const uint8_t* src_y,
  4680. int src_stride_y,
  4681. const uint8_t* src_u,
  4682. int src_stride_u,
  4683. const uint8_t* src_v,
  4684. int src_stride_v,
  4685. int src_pixel_stride_uv,
  4686. uint8_t* dst_argb,
  4687. int dst_stride_argb,
  4688. const struct YuvConstants* yuvconstants,
  4689. int width,
  4690. int height) {
  4691. int y;
  4692. uint8_t* dst_uv;
  4693. const ptrdiff_t vu_off = src_v - src_u;
  4694. int halfwidth = (width + 1) >> 1;
  4695. int halfheight = (height + 1) >> 1;
  4696. assert(yuvconstants);
  4697. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  4698. return -1;
  4699. }
  4700. // Negative height means invert the image.
  4701. if (height < 0) {
  4702. height = -height;
  4703. halfheight = (height + 1) >> 1;
  4704. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  4705. dst_stride_argb = -dst_stride_argb;
  4706. }
  4707. // I420
  4708. if (src_pixel_stride_uv == 1) {
  4709. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  4710. src_stride_v, dst_argb, dst_stride_argb,
  4711. yuvconstants, width, height);
  4712. // NV21
  4713. }
  4714. if (src_pixel_stride_uv == 2 && vu_off == -1 &&
  4715. src_stride_u == src_stride_v) {
  4716. return NV21ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, dst_argb,
  4717. dst_stride_argb, yuvconstants, width, height);
  4718. // NV12
  4719. }
  4720. if (src_pixel_stride_uv == 2 && vu_off == 1 && src_stride_u == src_stride_v) {
  4721. return NV12ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, dst_argb,
  4722. dst_stride_argb, yuvconstants, width, height);
  4723. }
  4724. // General case fallback creates NV12
  4725. align_buffer_64(plane_uv, halfwidth * 2 * halfheight);
  4726. if (!plane_uv)
  4727. return 1;
  4728. dst_uv = plane_uv;
  4729. for (y = 0; y < halfheight; ++y) {
  4730. WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth);
  4731. src_u += src_stride_u;
  4732. src_v += src_stride_v;
  4733. dst_uv += halfwidth * 2;
  4734. }
  4735. NV12ToARGBMatrix(src_y, src_stride_y, plane_uv, halfwidth * 2, dst_argb,
  4736. dst_stride_argb, yuvconstants, width, height);
  4737. free_aligned_buffer_64(plane_uv);
  4738. return 0;
  4739. }
  4740. // Convert Android420 to ARGB.
  4741. LIBYUV_API
  4742. int Android420ToARGB(const uint8_t* src_y,
  4743. int src_stride_y,
  4744. const uint8_t* src_u,
  4745. int src_stride_u,
  4746. const uint8_t* src_v,
  4747. int src_stride_v,
  4748. int src_pixel_stride_uv,
  4749. uint8_t* dst_argb,
  4750. int dst_stride_argb,
  4751. int width,
  4752. int height) {
  4753. return Android420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  4754. src_stride_v, src_pixel_stride_uv, dst_argb,
  4755. dst_stride_argb, &kYuvI601Constants, width,
  4756. height);
  4757. }
  4758. // Convert Android420 to ABGR.
  4759. LIBYUV_API
  4760. int Android420ToABGR(const uint8_t* src_y,
  4761. int src_stride_y,
  4762. const uint8_t* src_u,
  4763. int src_stride_u,
  4764. const uint8_t* src_v,
  4765. int src_stride_v,
  4766. int src_pixel_stride_uv,
  4767. uint8_t* dst_abgr,
  4768. int dst_stride_abgr,
  4769. int width,
  4770. int height) {
  4771. return Android420ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  4772. src_stride_u, src_pixel_stride_uv, dst_abgr,
  4773. dst_stride_abgr, &kYvuI601Constants, width,
  4774. height);
  4775. }
  4776. // Convert I422 to RGBA with matrix.
  4777. LIBYUV_API
  4778. int I422ToRGBAMatrix(const uint8_t* src_y,
  4779. int src_stride_y,
  4780. const uint8_t* src_u,
  4781. int src_stride_u,
  4782. const uint8_t* src_v,
  4783. int src_stride_v,
  4784. uint8_t* dst_rgba,
  4785. int dst_stride_rgba,
  4786. const struct YuvConstants* yuvconstants,
  4787. int width,
  4788. int height) {
  4789. int y;
  4790. void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf,
  4791. const uint8_t* v_buf, uint8_t* rgb_buf,
  4792. const struct YuvConstants* yuvconstants, int width) =
  4793. I422ToRGBARow_C;
  4794. assert(yuvconstants);
  4795. if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) {
  4796. return -1;
  4797. }
  4798. // Negative height means invert the image.
  4799. if (height < 0) {
  4800. height = -height;
  4801. dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba;
  4802. dst_stride_rgba = -dst_stride_rgba;
  4803. }
  4804. #if defined(HAS_I422TORGBAROW_SSSE3)
  4805. if (TestCpuFlag(kCpuHasSSSE3)) {
  4806. I422ToRGBARow = I422ToRGBARow_Any_SSSE3;
  4807. if (IS_ALIGNED(width, 8)) {
  4808. I422ToRGBARow = I422ToRGBARow_SSSE3;
  4809. }
  4810. }
  4811. #endif
  4812. #if defined(HAS_I422TORGBAROW_AVX2)
  4813. if (TestCpuFlag(kCpuHasAVX2)) {
  4814. I422ToRGBARow = I422ToRGBARow_Any_AVX2;
  4815. if (IS_ALIGNED(width, 16)) {
  4816. I422ToRGBARow = I422ToRGBARow_AVX2;
  4817. }
  4818. }
  4819. #endif
  4820. #if defined(HAS_I422TORGBAROW_NEON)
  4821. if (TestCpuFlag(kCpuHasNEON)) {
  4822. I422ToRGBARow = I422ToRGBARow_Any_NEON;
  4823. if (IS_ALIGNED(width, 8)) {
  4824. I422ToRGBARow = I422ToRGBARow_NEON;
  4825. }
  4826. }
  4827. #endif
  4828. #if defined(HAS_I422TORGBAROW_SVE2)
  4829. if (TestCpuFlag(kCpuHasSVE2)) {
  4830. I422ToRGBARow = I422ToRGBARow_SVE2;
  4831. }
  4832. #endif
  4833. #if defined(HAS_I422TORGBAROW_MSA)
  4834. if (TestCpuFlag(kCpuHasMSA)) {
  4835. I422ToRGBARow = I422ToRGBARow_Any_MSA;
  4836. if (IS_ALIGNED(width, 8)) {
  4837. I422ToRGBARow = I422ToRGBARow_MSA;
  4838. }
  4839. }
  4840. #endif
  4841. #if defined(HAS_I422TORGBAROW_LSX)
  4842. if (TestCpuFlag(kCpuHasLSX)) {
  4843. I422ToRGBARow = I422ToRGBARow_Any_LSX;
  4844. if (IS_ALIGNED(width, 16)) {
  4845. I422ToRGBARow = I422ToRGBARow_LSX;
  4846. }
  4847. }
  4848. #endif
  4849. #if defined(HAS_I422TORGBAROW_LASX)
  4850. if (TestCpuFlag(kCpuHasLASX)) {
  4851. I422ToRGBARow = I422ToRGBARow_Any_LASX;
  4852. if (IS_ALIGNED(width, 32)) {
  4853. I422ToRGBARow = I422ToRGBARow_LASX;
  4854. }
  4855. }
  4856. #endif
  4857. #if defined(HAS_I422TORGBAROW_RVV)
  4858. if (TestCpuFlag(kCpuHasRVV)) {
  4859. I422ToRGBARow = I422ToRGBARow_RVV;
  4860. }
  4861. #endif
  4862. for (y = 0; y < height; ++y) {
  4863. I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width);
  4864. dst_rgba += dst_stride_rgba;
  4865. src_y += src_stride_y;
  4866. src_u += src_stride_u;
  4867. src_v += src_stride_v;
  4868. }
  4869. return 0;
  4870. }
  4871. // Convert I422 to RGBA.
  4872. LIBYUV_API
  4873. int I422ToRGBA(const uint8_t* src_y,
  4874. int src_stride_y,
  4875. const uint8_t* src_u,
  4876. int src_stride_u,
  4877. const uint8_t* src_v,
  4878. int src_stride_v,
  4879. uint8_t* dst_rgba,
  4880. int dst_stride_rgba,
  4881. int width,
  4882. int height) {
  4883. return I422ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  4884. src_stride_v, dst_rgba, dst_stride_rgba,
  4885. &kYuvI601Constants, width, height);
  4886. }
  4887. // Convert I422 to BGRA.
  4888. LIBYUV_API
  4889. int I422ToBGRA(const uint8_t* src_y,
  4890. int src_stride_y,
  4891. const uint8_t* src_u,
  4892. int src_stride_u,
  4893. const uint8_t* src_v,
  4894. int src_stride_v,
  4895. uint8_t* dst_bgra,
  4896. int dst_stride_bgra,
  4897. int width,
  4898. int height) {
  4899. return I422ToRGBAMatrix(src_y, src_stride_y, src_v,
  4900. src_stride_v, // Swap U and V
  4901. src_u, src_stride_u, dst_bgra, dst_stride_bgra,
  4902. &kYvuI601Constants, // Use Yvu matrix
  4903. width, height);
  4904. }
  4905. // Convert NV12 to RGB565 with matrix.
  4906. LIBYUV_API
  4907. int NV12ToRGB565Matrix(const uint8_t* src_y,
  4908. int src_stride_y,
  4909. const uint8_t* src_uv,
  4910. int src_stride_uv,
  4911. uint8_t* dst_rgb565,
  4912. int dst_stride_rgb565,
  4913. const struct YuvConstants* yuvconstants,
  4914. int width,
  4915. int height) {
  4916. int y;
  4917. void (*NV12ToRGB565Row)(
  4918. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  4919. const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C;
  4920. assert(yuvconstants);
  4921. if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0) {
  4922. return -1;
  4923. }
  4924. // Negative height means invert the image.
  4925. if (height < 0) {
  4926. height = -height;
  4927. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  4928. dst_stride_rgb565 = -dst_stride_rgb565;
  4929. }
  4930. #if defined(HAS_NV12TORGB565ROW_SSSE3)
  4931. if (TestCpuFlag(kCpuHasSSSE3)) {
  4932. NV12ToRGB565Row = NV12ToRGB565Row_Any_SSSE3;
  4933. if (IS_ALIGNED(width, 8)) {
  4934. NV12ToRGB565Row = NV12ToRGB565Row_SSSE3;
  4935. }
  4936. }
  4937. #endif
  4938. #if defined(HAS_NV12TORGB565ROW_AVX2)
  4939. if (TestCpuFlag(kCpuHasAVX2)) {
  4940. NV12ToRGB565Row = NV12ToRGB565Row_Any_AVX2;
  4941. if (IS_ALIGNED(width, 16)) {
  4942. NV12ToRGB565Row = NV12ToRGB565Row_AVX2;
  4943. }
  4944. }
  4945. #endif
  4946. #if defined(HAS_NV12TORGB565ROW_NEON)
  4947. if (TestCpuFlag(kCpuHasNEON)) {
  4948. NV12ToRGB565Row = NV12ToRGB565Row_Any_NEON;
  4949. if (IS_ALIGNED(width, 8)) {
  4950. NV12ToRGB565Row = NV12ToRGB565Row_NEON;
  4951. }
  4952. }
  4953. #endif
  4954. #if defined(HAS_NV12TORGB565ROW_MSA)
  4955. if (TestCpuFlag(kCpuHasMSA)) {
  4956. NV12ToRGB565Row = NV12ToRGB565Row_Any_MSA;
  4957. if (IS_ALIGNED(width, 8)) {
  4958. NV12ToRGB565Row = NV12ToRGB565Row_MSA;
  4959. }
  4960. }
  4961. #endif
  4962. #if defined(HAS_NV12TORGB565ROW_LSX)
  4963. if (TestCpuFlag(kCpuHasLSX)) {
  4964. NV12ToRGB565Row = NV12ToRGB565Row_Any_LSX;
  4965. if (IS_ALIGNED(width, 8)) {
  4966. NV12ToRGB565Row = NV12ToRGB565Row_LSX;
  4967. }
  4968. }
  4969. #endif
  4970. #if defined(HAS_NV12TORGB565ROW_LASX)
  4971. if (TestCpuFlag(kCpuHasLASX)) {
  4972. NV12ToRGB565Row = NV12ToRGB565Row_Any_LASX;
  4973. if (IS_ALIGNED(width, 16)) {
  4974. NV12ToRGB565Row = NV12ToRGB565Row_LASX;
  4975. }
  4976. }
  4977. #endif
  4978. for (y = 0; y < height; ++y) {
  4979. NV12ToRGB565Row(src_y, src_uv, dst_rgb565, yuvconstants, width);
  4980. dst_rgb565 += dst_stride_rgb565;
  4981. src_y += src_stride_y;
  4982. if (y & 1) {
  4983. src_uv += src_stride_uv;
  4984. }
  4985. }
  4986. return 0;
  4987. }
  4988. // Convert NV12 to RGB565.
  4989. LIBYUV_API
  4990. int NV12ToRGB565(const uint8_t* src_y,
  4991. int src_stride_y,
  4992. const uint8_t* src_uv,
  4993. int src_stride_uv,
  4994. uint8_t* dst_rgb565,
  4995. int dst_stride_rgb565,
  4996. int width,
  4997. int height) {
  4998. return NV12ToRGB565Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  4999. dst_rgb565, dst_stride_rgb565, &kYuvI601Constants,
  5000. width, height);
  5001. }
  5002. // Convert I422 to RGBA with matrix.
  5003. LIBYUV_API
  5004. int I420ToRGBAMatrix(const uint8_t* src_y,
  5005. int src_stride_y,
  5006. const uint8_t* src_u,
  5007. int src_stride_u,
  5008. const uint8_t* src_v,
  5009. int src_stride_v,
  5010. uint8_t* dst_rgba,
  5011. int dst_stride_rgba,
  5012. const struct YuvConstants* yuvconstants,
  5013. int width,
  5014. int height) {
  5015. int y;
  5016. void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf,
  5017. const uint8_t* v_buf, uint8_t* rgb_buf,
  5018. const struct YuvConstants* yuvconstants, int width) =
  5019. I422ToRGBARow_C;
  5020. assert(yuvconstants);
  5021. if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) {
  5022. return -1;
  5023. }
  5024. // Negative height means invert the image.
  5025. if (height < 0) {
  5026. height = -height;
  5027. dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba;
  5028. dst_stride_rgba = -dst_stride_rgba;
  5029. }
  5030. #if defined(HAS_I422TORGBAROW_SSSE3)
  5031. if (TestCpuFlag(kCpuHasSSSE3)) {
  5032. I422ToRGBARow = I422ToRGBARow_Any_SSSE3;
  5033. if (IS_ALIGNED(width, 8)) {
  5034. I422ToRGBARow = I422ToRGBARow_SSSE3;
  5035. }
  5036. }
  5037. #endif
  5038. #if defined(HAS_I422TORGBAROW_AVX2)
  5039. if (TestCpuFlag(kCpuHasAVX2)) {
  5040. I422ToRGBARow = I422ToRGBARow_Any_AVX2;
  5041. if (IS_ALIGNED(width, 16)) {
  5042. I422ToRGBARow = I422ToRGBARow_AVX2;
  5043. }
  5044. }
  5045. #endif
  5046. #if defined(HAS_I422TORGBAROW_NEON)
  5047. if (TestCpuFlag(kCpuHasNEON)) {
  5048. I422ToRGBARow = I422ToRGBARow_Any_NEON;
  5049. if (IS_ALIGNED(width, 8)) {
  5050. I422ToRGBARow = I422ToRGBARow_NEON;
  5051. }
  5052. }
  5053. #endif
  5054. #if defined(HAS_I422TORGBAROW_SVE2)
  5055. if (TestCpuFlag(kCpuHasSVE2)) {
  5056. I422ToRGBARow = I422ToRGBARow_SVE2;
  5057. }
  5058. #endif
  5059. #if defined(HAS_I422TORGBAROW_MSA)
  5060. if (TestCpuFlag(kCpuHasMSA)) {
  5061. I422ToRGBARow = I422ToRGBARow_Any_MSA;
  5062. if (IS_ALIGNED(width, 8)) {
  5063. I422ToRGBARow = I422ToRGBARow_MSA;
  5064. }
  5065. }
  5066. #endif
  5067. #if defined(HAS_I422TORGBAROW_LSX)
  5068. if (TestCpuFlag(kCpuHasLSX)) {
  5069. I422ToRGBARow = I422ToRGBARow_Any_LSX;
  5070. if (IS_ALIGNED(width, 16)) {
  5071. I422ToRGBARow = I422ToRGBARow_LSX;
  5072. }
  5073. }
  5074. #endif
  5075. #if defined(HAS_I422TORGBAROW_LASX)
  5076. if (TestCpuFlag(kCpuHasLASX)) {
  5077. I422ToRGBARow = I422ToRGBARow_Any_LASX;
  5078. if (IS_ALIGNED(width, 32)) {
  5079. I422ToRGBARow = I422ToRGBARow_LASX;
  5080. }
  5081. }
  5082. #endif
  5083. #if defined(HAS_I422TORGBAROW_RVV)
  5084. if (TestCpuFlag(kCpuHasRVV)) {
  5085. I422ToRGBARow = I422ToRGBARow_RVV;
  5086. }
  5087. #endif
  5088. for (y = 0; y < height; ++y) {
  5089. I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width);
  5090. dst_rgba += dst_stride_rgba;
  5091. src_y += src_stride_y;
  5092. if (y & 1) {
  5093. src_u += src_stride_u;
  5094. src_v += src_stride_v;
  5095. }
  5096. }
  5097. return 0;
  5098. }
  5099. // Convert I420 to RGBA.
  5100. LIBYUV_API
  5101. int I420ToRGBA(const uint8_t* src_y,
  5102. int src_stride_y,
  5103. const uint8_t* src_u,
  5104. int src_stride_u,
  5105. const uint8_t* src_v,
  5106. int src_stride_v,
  5107. uint8_t* dst_rgba,
  5108. int dst_stride_rgba,
  5109. int width,
  5110. int height) {
  5111. return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5112. src_stride_v, dst_rgba, dst_stride_rgba,
  5113. &kYuvI601Constants, width, height);
  5114. }
  5115. // Convert I420 to BGRA.
  5116. LIBYUV_API
  5117. int I420ToBGRA(const uint8_t* src_y,
  5118. int src_stride_y,
  5119. const uint8_t* src_u,
  5120. int src_stride_u,
  5121. const uint8_t* src_v,
  5122. int src_stride_v,
  5123. uint8_t* dst_bgra,
  5124. int dst_stride_bgra,
  5125. int width,
  5126. int height) {
  5127. return I420ToRGBAMatrix(src_y, src_stride_y, src_v,
  5128. src_stride_v, // Swap U and V
  5129. src_u, src_stride_u, dst_bgra, dst_stride_bgra,
  5130. &kYvuI601Constants, // Use Yvu matrix
  5131. width, height);
  5132. }
  5133. // Convert I420 to RGB24 with matrix.
  5134. LIBYUV_API
  5135. int I420ToRGB24Matrix(const uint8_t* src_y,
  5136. int src_stride_y,
  5137. const uint8_t* src_u,
  5138. int src_stride_u,
  5139. const uint8_t* src_v,
  5140. int src_stride_v,
  5141. uint8_t* dst_rgb24,
  5142. int dst_stride_rgb24,
  5143. const struct YuvConstants* yuvconstants,
  5144. int width,
  5145. int height) {
  5146. int y;
  5147. void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5148. const uint8_t* v_buf, uint8_t* rgb_buf,
  5149. const struct YuvConstants* yuvconstants, int width) =
  5150. I422ToRGB24Row_C;
  5151. assert(yuvconstants);
  5152. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  5153. return -1;
  5154. }
  5155. // Negative height means invert the image.
  5156. if (height < 0) {
  5157. height = -height;
  5158. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  5159. dst_stride_rgb24 = -dst_stride_rgb24;
  5160. }
  5161. #if defined(HAS_I422TORGB24ROW_SSSE3)
  5162. if (TestCpuFlag(kCpuHasSSSE3)) {
  5163. I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3;
  5164. if (IS_ALIGNED(width, 16)) {
  5165. I422ToRGB24Row = I422ToRGB24Row_SSSE3;
  5166. }
  5167. }
  5168. #endif
  5169. #if defined(HAS_I422TORGB24ROW_AVX2)
  5170. if (TestCpuFlag(kCpuHasAVX2)) {
  5171. I422ToRGB24Row = I422ToRGB24Row_Any_AVX2;
  5172. if (IS_ALIGNED(width, 32)) {
  5173. I422ToRGB24Row = I422ToRGB24Row_AVX2;
  5174. }
  5175. }
  5176. #endif
  5177. #if defined(HAS_I422TORGB24ROW_NEON)
  5178. if (TestCpuFlag(kCpuHasNEON)) {
  5179. I422ToRGB24Row = I422ToRGB24Row_Any_NEON;
  5180. if (IS_ALIGNED(width, 8)) {
  5181. I422ToRGB24Row = I422ToRGB24Row_NEON;
  5182. }
  5183. }
  5184. #endif
  5185. #if defined(HAS_I422TORGB24ROW_MSA)
  5186. if (TestCpuFlag(kCpuHasMSA)) {
  5187. I422ToRGB24Row = I422ToRGB24Row_Any_MSA;
  5188. if (IS_ALIGNED(width, 16)) {
  5189. I422ToRGB24Row = I422ToRGB24Row_MSA;
  5190. }
  5191. }
  5192. #endif
  5193. #if defined(HAS_I422TORGB24ROW_LSX)
  5194. if (TestCpuFlag(kCpuHasLSX)) {
  5195. I422ToRGB24Row = I422ToRGB24Row_Any_LSX;
  5196. if (IS_ALIGNED(width, 16)) {
  5197. I422ToRGB24Row = I422ToRGB24Row_LSX;
  5198. }
  5199. }
  5200. #endif
  5201. #if defined(HAS_I422TORGB24ROW_LASX)
  5202. if (TestCpuFlag(kCpuHasLASX)) {
  5203. I422ToRGB24Row = I422ToRGB24Row_Any_LASX;
  5204. if (IS_ALIGNED(width, 32)) {
  5205. I422ToRGB24Row = I422ToRGB24Row_LASX;
  5206. }
  5207. }
  5208. #endif
  5209. #if defined(HAS_I422TORGB24ROW_RVV)
  5210. if (TestCpuFlag(kCpuHasRVV)) {
  5211. I422ToRGB24Row = I422ToRGB24Row_RVV;
  5212. }
  5213. #endif
  5214. for (y = 0; y < height; ++y) {
  5215. I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width);
  5216. dst_rgb24 += dst_stride_rgb24;
  5217. src_y += src_stride_y;
  5218. if (y & 1) {
  5219. src_u += src_stride_u;
  5220. src_v += src_stride_v;
  5221. }
  5222. }
  5223. return 0;
  5224. }
  5225. // Convert I420 to RGB24.
  5226. LIBYUV_API
  5227. int I420ToRGB24(const uint8_t* src_y,
  5228. int src_stride_y,
  5229. const uint8_t* src_u,
  5230. int src_stride_u,
  5231. const uint8_t* src_v,
  5232. int src_stride_v,
  5233. uint8_t* dst_rgb24,
  5234. int dst_stride_rgb24,
  5235. int width,
  5236. int height) {
  5237. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5238. src_stride_v, dst_rgb24, dst_stride_rgb24,
  5239. &kYuvI601Constants, width, height);
  5240. }
  5241. // Convert I420 to RAW.
  5242. LIBYUV_API
  5243. int I420ToRAW(const uint8_t* src_y,
  5244. int src_stride_y,
  5245. const uint8_t* src_u,
  5246. int src_stride_u,
  5247. const uint8_t* src_v,
  5248. int src_stride_v,
  5249. uint8_t* dst_raw,
  5250. int dst_stride_raw,
  5251. int width,
  5252. int height) {
  5253. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  5254. src_stride_v, // Swap U and V
  5255. src_u, src_stride_u, dst_raw, dst_stride_raw,
  5256. &kYvuI601Constants, // Use Yvu matrix
  5257. width, height);
  5258. }
  5259. // Convert J420 to RGB24.
  5260. LIBYUV_API
  5261. int J420ToRGB24(const uint8_t* src_y,
  5262. int src_stride_y,
  5263. const uint8_t* src_u,
  5264. int src_stride_u,
  5265. const uint8_t* src_v,
  5266. int src_stride_v,
  5267. uint8_t* dst_rgb24,
  5268. int dst_stride_rgb24,
  5269. int width,
  5270. int height) {
  5271. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5272. src_stride_v, dst_rgb24, dst_stride_rgb24,
  5273. &kYuvJPEGConstants, width, height);
  5274. }
  5275. // Convert J420 to RAW.
  5276. LIBYUV_API
  5277. int J420ToRAW(const uint8_t* src_y,
  5278. int src_stride_y,
  5279. const uint8_t* src_u,
  5280. int src_stride_u,
  5281. const uint8_t* src_v,
  5282. int src_stride_v,
  5283. uint8_t* dst_raw,
  5284. int dst_stride_raw,
  5285. int width,
  5286. int height) {
  5287. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  5288. src_stride_v, // Swap U and V
  5289. src_u, src_stride_u, dst_raw, dst_stride_raw,
  5290. &kYvuJPEGConstants, // Use Yvu matrix
  5291. width, height);
  5292. }
  5293. // Convert H420 to RGB24.
  5294. LIBYUV_API
  5295. int H420ToRGB24(const uint8_t* src_y,
  5296. int src_stride_y,
  5297. const uint8_t* src_u,
  5298. int src_stride_u,
  5299. const uint8_t* src_v,
  5300. int src_stride_v,
  5301. uint8_t* dst_rgb24,
  5302. int dst_stride_rgb24,
  5303. int width,
  5304. int height) {
  5305. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5306. src_stride_v, dst_rgb24, dst_stride_rgb24,
  5307. &kYuvH709Constants, width, height);
  5308. }
  5309. // Convert H420 to RAW.
  5310. LIBYUV_API
  5311. int H420ToRAW(const uint8_t* src_y,
  5312. int src_stride_y,
  5313. const uint8_t* src_u,
  5314. int src_stride_u,
  5315. const uint8_t* src_v,
  5316. int src_stride_v,
  5317. uint8_t* dst_raw,
  5318. int dst_stride_raw,
  5319. int width,
  5320. int height) {
  5321. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  5322. src_stride_v, // Swap U and V
  5323. src_u, src_stride_u, dst_raw, dst_stride_raw,
  5324. &kYvuH709Constants, // Use Yvu matrix
  5325. width, height);
  5326. }
  5327. // Convert I422 to RGB24 with matrix.
  5328. LIBYUV_API
  5329. int I422ToRGB24Matrix(const uint8_t* src_y,
  5330. int src_stride_y,
  5331. const uint8_t* src_u,
  5332. int src_stride_u,
  5333. const uint8_t* src_v,
  5334. int src_stride_v,
  5335. uint8_t* dst_rgb24,
  5336. int dst_stride_rgb24,
  5337. const struct YuvConstants* yuvconstants,
  5338. int width,
  5339. int height) {
  5340. int y;
  5341. void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5342. const uint8_t* v_buf, uint8_t* rgb_buf,
  5343. const struct YuvConstants* yuvconstants, int width) =
  5344. I422ToRGB24Row_C;
  5345. assert(yuvconstants);
  5346. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  5347. return -1;
  5348. }
  5349. // Negative height means invert the image.
  5350. if (height < 0) {
  5351. height = -height;
  5352. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  5353. dst_stride_rgb24 = -dst_stride_rgb24;
  5354. }
  5355. #if defined(HAS_I422TORGB24ROW_SSSE3)
  5356. if (TestCpuFlag(kCpuHasSSSE3)) {
  5357. I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3;
  5358. if (IS_ALIGNED(width, 16)) {
  5359. I422ToRGB24Row = I422ToRGB24Row_SSSE3;
  5360. }
  5361. }
  5362. #endif
  5363. #if defined(HAS_I422TORGB24ROW_AVX2)
  5364. if (TestCpuFlag(kCpuHasAVX2)) {
  5365. I422ToRGB24Row = I422ToRGB24Row_Any_AVX2;
  5366. if (IS_ALIGNED(width, 32)) {
  5367. I422ToRGB24Row = I422ToRGB24Row_AVX2;
  5368. }
  5369. }
  5370. #endif
  5371. #if defined(HAS_I422TORGB24ROW_NEON)
  5372. if (TestCpuFlag(kCpuHasNEON)) {
  5373. I422ToRGB24Row = I422ToRGB24Row_Any_NEON;
  5374. if (IS_ALIGNED(width, 8)) {
  5375. I422ToRGB24Row = I422ToRGB24Row_NEON;
  5376. }
  5377. }
  5378. #endif
  5379. #if defined(HAS_I422TORGB24ROW_MSA)
  5380. if (TestCpuFlag(kCpuHasMSA)) {
  5381. I422ToRGB24Row = I422ToRGB24Row_Any_MSA;
  5382. if (IS_ALIGNED(width, 16)) {
  5383. I422ToRGB24Row = I422ToRGB24Row_MSA;
  5384. }
  5385. }
  5386. #endif
  5387. #if defined(HAS_I422TORGB24ROW_LSX)
  5388. if (TestCpuFlag(kCpuHasLSX)) {
  5389. I422ToRGB24Row = I422ToRGB24Row_Any_LSX;
  5390. if (IS_ALIGNED(width, 16)) {
  5391. I422ToRGB24Row = I422ToRGB24Row_LSX;
  5392. }
  5393. }
  5394. #endif
  5395. #if defined(HAS_I422TORGB24ROW_LASX)
  5396. if (TestCpuFlag(kCpuHasLASX)) {
  5397. I422ToRGB24Row = I422ToRGB24Row_Any_LASX;
  5398. if (IS_ALIGNED(width, 32)) {
  5399. I422ToRGB24Row = I422ToRGB24Row_LASX;
  5400. }
  5401. }
  5402. #endif
  5403. #if defined(HAS_I422TORGB24ROW_RVV)
  5404. if (TestCpuFlag(kCpuHasRVV)) {
  5405. I422ToRGB24Row = I422ToRGB24Row_RVV;
  5406. }
  5407. #endif
  5408. for (y = 0; y < height; ++y) {
  5409. I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width);
  5410. dst_rgb24 += dst_stride_rgb24;
  5411. src_y += src_stride_y;
  5412. src_u += src_stride_u;
  5413. src_v += src_stride_v;
  5414. }
  5415. return 0;
  5416. }
  5417. // Convert I422 to RGB24.
  5418. LIBYUV_API
  5419. int I422ToRGB24(const uint8_t* src_y,
  5420. int src_stride_y,
  5421. const uint8_t* src_u,
  5422. int src_stride_u,
  5423. const uint8_t* src_v,
  5424. int src_stride_v,
  5425. uint8_t* dst_rgb24,
  5426. int dst_stride_rgb24,
  5427. int width,
  5428. int height) {
  5429. return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5430. src_stride_v, dst_rgb24, dst_stride_rgb24,
  5431. &kYuvI601Constants, width, height);
  5432. }
  5433. // Convert I422 to RAW.
  5434. LIBYUV_API
  5435. int I422ToRAW(const uint8_t* src_y,
  5436. int src_stride_y,
  5437. const uint8_t* src_u,
  5438. int src_stride_u,
  5439. const uint8_t* src_v,
  5440. int src_stride_v,
  5441. uint8_t* dst_raw,
  5442. int dst_stride_raw,
  5443. int width,
  5444. int height) {
  5445. return I422ToRGB24Matrix(src_y, src_stride_y, src_v,
  5446. src_stride_v, // Swap U and V
  5447. src_u, src_stride_u, dst_raw, dst_stride_raw,
  5448. &kYvuI601Constants, // Use Yvu matrix
  5449. width, height);
  5450. }
  5451. // Convert I420 to ARGB1555.
  5452. LIBYUV_API
  5453. int I420ToARGB1555(const uint8_t* src_y,
  5454. int src_stride_y,
  5455. const uint8_t* src_u,
  5456. int src_stride_u,
  5457. const uint8_t* src_v,
  5458. int src_stride_v,
  5459. uint8_t* dst_argb1555,
  5460. int dst_stride_argb1555,
  5461. int width,
  5462. int height) {
  5463. int y;
  5464. void (*I422ToARGB1555Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5465. const uint8_t* v_buf, uint8_t* rgb_buf,
  5466. const struct YuvConstants* yuvconstants,
  5467. int width) = I422ToARGB1555Row_C;
  5468. if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 ||
  5469. height == 0) {
  5470. return -1;
  5471. }
  5472. // Negative height means invert the image.
  5473. if (height < 0) {
  5474. height = -height;
  5475. dst_argb1555 = dst_argb1555 + (height - 1) * dst_stride_argb1555;
  5476. dst_stride_argb1555 = -dst_stride_argb1555;
  5477. }
  5478. #if defined(HAS_I422TOARGB1555ROW_SSSE3)
  5479. if (TestCpuFlag(kCpuHasSSSE3)) {
  5480. I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3;
  5481. if (IS_ALIGNED(width, 8)) {
  5482. I422ToARGB1555Row = I422ToARGB1555Row_SSSE3;
  5483. }
  5484. }
  5485. #endif
  5486. #if defined(HAS_I422TOARGB1555ROW_AVX2)
  5487. if (TestCpuFlag(kCpuHasAVX2)) {
  5488. I422ToARGB1555Row = I422ToARGB1555Row_Any_AVX2;
  5489. if (IS_ALIGNED(width, 16)) {
  5490. I422ToARGB1555Row = I422ToARGB1555Row_AVX2;
  5491. }
  5492. }
  5493. #endif
  5494. #if defined(HAS_I422TOARGB1555ROW_NEON)
  5495. if (TestCpuFlag(kCpuHasNEON)) {
  5496. I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON;
  5497. if (IS_ALIGNED(width, 8)) {
  5498. I422ToARGB1555Row = I422ToARGB1555Row_NEON;
  5499. }
  5500. }
  5501. #endif
  5502. #if defined(HAS_I422TOARGB1555ROW_MSA)
  5503. if (TestCpuFlag(kCpuHasMSA)) {
  5504. I422ToARGB1555Row = I422ToARGB1555Row_Any_MSA;
  5505. if (IS_ALIGNED(width, 8)) {
  5506. I422ToARGB1555Row = I422ToARGB1555Row_MSA;
  5507. }
  5508. }
  5509. #endif
  5510. #if defined(HAS_I422TOARGB1555ROW_LSX)
  5511. if (TestCpuFlag(kCpuHasLSX)) {
  5512. I422ToARGB1555Row = I422ToARGB1555Row_Any_LSX;
  5513. if (IS_ALIGNED(width, 16)) {
  5514. I422ToARGB1555Row = I422ToARGB1555Row_LSX;
  5515. }
  5516. }
  5517. #endif
  5518. #if defined(HAS_I422TOARGB1555ROW_LASX)
  5519. if (TestCpuFlag(kCpuHasLASX)) {
  5520. I422ToARGB1555Row = I422ToARGB1555Row_Any_LASX;
  5521. if (IS_ALIGNED(width, 8)) {
  5522. I422ToARGB1555Row = I422ToARGB1555Row_LASX;
  5523. }
  5524. }
  5525. #endif
  5526. for (y = 0; y < height; ++y) {
  5527. I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, &kYuvI601Constants,
  5528. width);
  5529. dst_argb1555 += dst_stride_argb1555;
  5530. src_y += src_stride_y;
  5531. if (y & 1) {
  5532. src_u += src_stride_u;
  5533. src_v += src_stride_v;
  5534. }
  5535. }
  5536. return 0;
  5537. }
  5538. // Convert I420 to ARGB4444.
  5539. LIBYUV_API
  5540. int I420ToARGB4444(const uint8_t* src_y,
  5541. int src_stride_y,
  5542. const uint8_t* src_u,
  5543. int src_stride_u,
  5544. const uint8_t* src_v,
  5545. int src_stride_v,
  5546. uint8_t* dst_argb4444,
  5547. int dst_stride_argb4444,
  5548. int width,
  5549. int height) {
  5550. int y;
  5551. void (*I422ToARGB4444Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5552. const uint8_t* v_buf, uint8_t* rgb_buf,
  5553. const struct YuvConstants* yuvconstants,
  5554. int width) = I422ToARGB4444Row_C;
  5555. if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 ||
  5556. height == 0) {
  5557. return -1;
  5558. }
  5559. // Negative height means invert the image.
  5560. if (height < 0) {
  5561. height = -height;
  5562. dst_argb4444 = dst_argb4444 + (height - 1) * dst_stride_argb4444;
  5563. dst_stride_argb4444 = -dst_stride_argb4444;
  5564. }
  5565. #if defined(HAS_I422TOARGB4444ROW_SSSE3)
  5566. if (TestCpuFlag(kCpuHasSSSE3)) {
  5567. I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3;
  5568. if (IS_ALIGNED(width, 8)) {
  5569. I422ToARGB4444Row = I422ToARGB4444Row_SSSE3;
  5570. }
  5571. }
  5572. #endif
  5573. #if defined(HAS_I422TOARGB4444ROW_AVX2)
  5574. if (TestCpuFlag(kCpuHasAVX2)) {
  5575. I422ToARGB4444Row = I422ToARGB4444Row_Any_AVX2;
  5576. if (IS_ALIGNED(width, 16)) {
  5577. I422ToARGB4444Row = I422ToARGB4444Row_AVX2;
  5578. }
  5579. }
  5580. #endif
  5581. #if defined(HAS_I422TOARGB4444ROW_NEON)
  5582. if (TestCpuFlag(kCpuHasNEON)) {
  5583. I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON;
  5584. if (IS_ALIGNED(width, 8)) {
  5585. I422ToARGB4444Row = I422ToARGB4444Row_NEON;
  5586. }
  5587. }
  5588. #endif
  5589. #if defined(HAS_I422TOARGB4444ROW_MSA)
  5590. if (TestCpuFlag(kCpuHasMSA)) {
  5591. I422ToARGB4444Row = I422ToARGB4444Row_Any_MSA;
  5592. if (IS_ALIGNED(width, 8)) {
  5593. I422ToARGB4444Row = I422ToARGB4444Row_MSA;
  5594. }
  5595. }
  5596. #endif
  5597. #if defined(HAS_I422TOARGB4444ROW_LSX)
  5598. if (TestCpuFlag(kCpuHasLSX)) {
  5599. I422ToARGB4444Row = I422ToARGB4444Row_Any_LSX;
  5600. if (IS_ALIGNED(width, 16)) {
  5601. I422ToARGB4444Row = I422ToARGB4444Row_LSX;
  5602. }
  5603. }
  5604. #endif
  5605. #if defined(HAS_I422TOARGB4444ROW_LASX)
  5606. if (TestCpuFlag(kCpuHasLASX)) {
  5607. I422ToARGB4444Row = I422ToARGB4444Row_Any_LASX;
  5608. if (IS_ALIGNED(width, 8)) {
  5609. I422ToARGB4444Row = I422ToARGB4444Row_LASX;
  5610. }
  5611. }
  5612. #endif
  5613. for (y = 0; y < height; ++y) {
  5614. I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, &kYuvI601Constants,
  5615. width);
  5616. dst_argb4444 += dst_stride_argb4444;
  5617. src_y += src_stride_y;
  5618. if (y & 1) {
  5619. src_u += src_stride_u;
  5620. src_v += src_stride_v;
  5621. }
  5622. }
  5623. return 0;
  5624. }
  5625. // Convert I420 to RGB565 with specified color matrix.
  5626. LIBYUV_API
  5627. int I420ToRGB565Matrix(const uint8_t* src_y,
  5628. int src_stride_y,
  5629. const uint8_t* src_u,
  5630. int src_stride_u,
  5631. const uint8_t* src_v,
  5632. int src_stride_v,
  5633. uint8_t* dst_rgb565,
  5634. int dst_stride_rgb565,
  5635. const struct YuvConstants* yuvconstants,
  5636. int width,
  5637. int height) {
  5638. int y;
  5639. void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5640. const uint8_t* v_buf, uint8_t* rgb_buf,
  5641. const struct YuvConstants* yuvconstants, int width) =
  5642. I422ToRGB565Row_C;
  5643. assert(yuvconstants);
  5644. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  5645. return -1;
  5646. }
  5647. // Negative height means invert the image.
  5648. if (height < 0) {
  5649. height = -height;
  5650. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  5651. dst_stride_rgb565 = -dst_stride_rgb565;
  5652. }
  5653. #if defined(HAS_I422TORGB565ROW_SSSE3)
  5654. if (TestCpuFlag(kCpuHasSSSE3)) {
  5655. I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3;
  5656. if (IS_ALIGNED(width, 8)) {
  5657. I422ToRGB565Row = I422ToRGB565Row_SSSE3;
  5658. }
  5659. }
  5660. #endif
  5661. #if defined(HAS_I422TORGB565ROW_AVX2)
  5662. if (TestCpuFlag(kCpuHasAVX2)) {
  5663. I422ToRGB565Row = I422ToRGB565Row_Any_AVX2;
  5664. if (IS_ALIGNED(width, 16)) {
  5665. I422ToRGB565Row = I422ToRGB565Row_AVX2;
  5666. }
  5667. }
  5668. #endif
  5669. #if defined(HAS_I422TORGB565ROW_NEON)
  5670. if (TestCpuFlag(kCpuHasNEON)) {
  5671. I422ToRGB565Row = I422ToRGB565Row_Any_NEON;
  5672. if (IS_ALIGNED(width, 8)) {
  5673. I422ToRGB565Row = I422ToRGB565Row_NEON;
  5674. }
  5675. }
  5676. #endif
  5677. #if defined(HAS_I422TORGB565ROW_MSA)
  5678. if (TestCpuFlag(kCpuHasMSA)) {
  5679. I422ToRGB565Row = I422ToRGB565Row_Any_MSA;
  5680. if (IS_ALIGNED(width, 8)) {
  5681. I422ToRGB565Row = I422ToRGB565Row_MSA;
  5682. }
  5683. }
  5684. #endif
  5685. #if defined(HAS_I422TORGB565ROW_LSX)
  5686. if (TestCpuFlag(kCpuHasLSX)) {
  5687. I422ToRGB565Row = I422ToRGB565Row_Any_LSX;
  5688. if (IS_ALIGNED(width, 16)) {
  5689. I422ToRGB565Row = I422ToRGB565Row_LSX;
  5690. }
  5691. }
  5692. #endif
  5693. #if defined(HAS_I422TORGB565ROW_LASX)
  5694. if (TestCpuFlag(kCpuHasLASX)) {
  5695. I422ToRGB565Row = I422ToRGB565Row_Any_LASX;
  5696. if (IS_ALIGNED(width, 32)) {
  5697. I422ToRGB565Row = I422ToRGB565Row_LASX;
  5698. }
  5699. }
  5700. #endif
  5701. for (y = 0; y < height; ++y) {
  5702. I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width);
  5703. dst_rgb565 += dst_stride_rgb565;
  5704. src_y += src_stride_y;
  5705. if (y & 1) {
  5706. src_u += src_stride_u;
  5707. src_v += src_stride_v;
  5708. }
  5709. }
  5710. return 0;
  5711. }
  5712. // Convert I420 to RGB565.
  5713. LIBYUV_API
  5714. int I420ToRGB565(const uint8_t* src_y,
  5715. int src_stride_y,
  5716. const uint8_t* src_u,
  5717. int src_stride_u,
  5718. const uint8_t* src_v,
  5719. int src_stride_v,
  5720. uint8_t* dst_rgb565,
  5721. int dst_stride_rgb565,
  5722. int width,
  5723. int height) {
  5724. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5725. src_stride_v, dst_rgb565, dst_stride_rgb565,
  5726. &kYuvI601Constants, width, height);
  5727. }
  5728. // Convert J420 to RGB565.
  5729. LIBYUV_API
  5730. int J420ToRGB565(const uint8_t* src_y,
  5731. int src_stride_y,
  5732. const uint8_t* src_u,
  5733. int src_stride_u,
  5734. const uint8_t* src_v,
  5735. int src_stride_v,
  5736. uint8_t* dst_rgb565,
  5737. int dst_stride_rgb565,
  5738. int width,
  5739. int height) {
  5740. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5741. src_stride_v, dst_rgb565, dst_stride_rgb565,
  5742. &kYuvJPEGConstants, width, height);
  5743. }
  5744. // Convert H420 to RGB565.
  5745. LIBYUV_API
  5746. int H420ToRGB565(const uint8_t* src_y,
  5747. int src_stride_y,
  5748. const uint8_t* src_u,
  5749. int src_stride_u,
  5750. const uint8_t* src_v,
  5751. int src_stride_v,
  5752. uint8_t* dst_rgb565,
  5753. int dst_stride_rgb565,
  5754. int width,
  5755. int height) {
  5756. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5757. src_stride_v, dst_rgb565, dst_stride_rgb565,
  5758. &kYuvH709Constants, width, height);
  5759. }
  5760. // Convert I422 to RGB565 with specified color matrix.
  5761. LIBYUV_API
  5762. int I422ToRGB565Matrix(const uint8_t* src_y,
  5763. int src_stride_y,
  5764. const uint8_t* src_u,
  5765. int src_stride_u,
  5766. const uint8_t* src_v,
  5767. int src_stride_v,
  5768. uint8_t* dst_rgb565,
  5769. int dst_stride_rgb565,
  5770. const struct YuvConstants* yuvconstants,
  5771. int width,
  5772. int height) {
  5773. int y;
  5774. void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  5775. const uint8_t* v_buf, uint8_t* rgb_buf,
  5776. const struct YuvConstants* yuvconstants, int width) =
  5777. I422ToRGB565Row_C;
  5778. assert(yuvconstants);
  5779. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  5780. return -1;
  5781. }
  5782. // Negative height means invert the image.
  5783. if (height < 0) {
  5784. height = -height;
  5785. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  5786. dst_stride_rgb565 = -dst_stride_rgb565;
  5787. }
  5788. #if defined(HAS_I422TORGB565ROW_SSSE3)
  5789. if (TestCpuFlag(kCpuHasSSSE3)) {
  5790. I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3;
  5791. if (IS_ALIGNED(width, 8)) {
  5792. I422ToRGB565Row = I422ToRGB565Row_SSSE3;
  5793. }
  5794. }
  5795. #endif
  5796. #if defined(HAS_I422TORGB565ROW_AVX2)
  5797. if (TestCpuFlag(kCpuHasAVX2)) {
  5798. I422ToRGB565Row = I422ToRGB565Row_Any_AVX2;
  5799. if (IS_ALIGNED(width, 16)) {
  5800. I422ToRGB565Row = I422ToRGB565Row_AVX2;
  5801. }
  5802. }
  5803. #endif
  5804. #if defined(HAS_I422TORGB565ROW_NEON)
  5805. if (TestCpuFlag(kCpuHasNEON)) {
  5806. I422ToRGB565Row = I422ToRGB565Row_Any_NEON;
  5807. if (IS_ALIGNED(width, 8)) {
  5808. I422ToRGB565Row = I422ToRGB565Row_NEON;
  5809. }
  5810. }
  5811. #endif
  5812. #if defined(HAS_I422TORGB565ROW_MSA)
  5813. if (TestCpuFlag(kCpuHasMSA)) {
  5814. I422ToRGB565Row = I422ToRGB565Row_Any_MSA;
  5815. if (IS_ALIGNED(width, 8)) {
  5816. I422ToRGB565Row = I422ToRGB565Row_MSA;
  5817. }
  5818. }
  5819. #endif
  5820. #if defined(HAS_I422TORGB565ROW_LSX)
  5821. if (TestCpuFlag(kCpuHasLSX)) {
  5822. I422ToRGB565Row = I422ToRGB565Row_Any_LSX;
  5823. if (IS_ALIGNED(width, 16)) {
  5824. I422ToRGB565Row = I422ToRGB565Row_LSX;
  5825. }
  5826. }
  5827. #endif
  5828. #if defined(HAS_I422TORGB565ROW_LASX)
  5829. if (TestCpuFlag(kCpuHasLASX)) {
  5830. I422ToRGB565Row = I422ToRGB565Row_Any_LASX;
  5831. if (IS_ALIGNED(width, 32)) {
  5832. I422ToRGB565Row = I422ToRGB565Row_LASX;
  5833. }
  5834. }
  5835. #endif
  5836. for (y = 0; y < height; ++y) {
  5837. I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width);
  5838. dst_rgb565 += dst_stride_rgb565;
  5839. src_y += src_stride_y;
  5840. src_u += src_stride_u;
  5841. src_v += src_stride_v;
  5842. }
  5843. return 0;
  5844. }
  5845. // Convert I422 to RGB565.
  5846. LIBYUV_API
  5847. int I422ToRGB565(const uint8_t* src_y,
  5848. int src_stride_y,
  5849. const uint8_t* src_u,
  5850. int src_stride_u,
  5851. const uint8_t* src_v,
  5852. int src_stride_v,
  5853. uint8_t* dst_rgb565,
  5854. int dst_stride_rgb565,
  5855. int width,
  5856. int height) {
  5857. return I422ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  5858. src_stride_v, dst_rgb565, dst_stride_rgb565,
  5859. &kYuvI601Constants, width, height);
  5860. }
  5861. // Ordered 8x8 dither for 888 to 565. Values from 0 to 7.
  5862. static const uint8_t kDither565_4x4[16] = {
  5863. 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2,
  5864. };
  5865. // Convert I420 to RGB565 with dithering.
  5866. LIBYUV_API
  5867. int I420ToRGB565Dither(const uint8_t* src_y,
  5868. int src_stride_y,
  5869. const uint8_t* src_u,
  5870. int src_stride_u,
  5871. const uint8_t* src_v,
  5872. int src_stride_v,
  5873. uint8_t* dst_rgb565,
  5874. int dst_stride_rgb565,
  5875. const uint8_t* dither4x4,
  5876. int width,
  5877. int height) {
  5878. int y;
  5879. void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  5880. const uint8_t* v_buf, uint8_t* rgb_buf,
  5881. const struct YuvConstants* yuvconstants, int width) =
  5882. I422ToARGBRow_C;
  5883. void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb,
  5884. uint32_t dither4, int width) =
  5885. ARGBToRGB565DitherRow_C;
  5886. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  5887. return -1;
  5888. }
  5889. // Negative height means invert the image.
  5890. if (height < 0) {
  5891. height = -height;
  5892. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  5893. dst_stride_rgb565 = -dst_stride_rgb565;
  5894. }
  5895. if (!dither4x4) {
  5896. dither4x4 = kDither565_4x4;
  5897. }
  5898. #if defined(HAS_I422TOARGBROW_SSSE3)
  5899. if (TestCpuFlag(kCpuHasSSSE3)) {
  5900. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  5901. if (IS_ALIGNED(width, 8)) {
  5902. I422ToARGBRow = I422ToARGBRow_SSSE3;
  5903. }
  5904. }
  5905. #endif
  5906. #if defined(HAS_I422TOARGBROW_AVX2)
  5907. if (TestCpuFlag(kCpuHasAVX2)) {
  5908. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  5909. if (IS_ALIGNED(width, 16)) {
  5910. I422ToARGBRow = I422ToARGBRow_AVX2;
  5911. }
  5912. }
  5913. #endif
  5914. #if defined(HAS_I422TOARGBROW_AVX512BW)
  5915. if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) ==
  5916. (kCpuHasAVX512BW | kCpuHasAVX512VL)) {
  5917. I422ToARGBRow = I422ToARGBRow_Any_AVX512BW;
  5918. if (IS_ALIGNED(width, 32)) {
  5919. I422ToARGBRow = I422ToARGBRow_AVX512BW;
  5920. }
  5921. }
  5922. #endif
  5923. #if defined(HAS_I422TOARGBROW_NEON)
  5924. if (TestCpuFlag(kCpuHasNEON)) {
  5925. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  5926. if (IS_ALIGNED(width, 8)) {
  5927. I422ToARGBRow = I422ToARGBRow_NEON;
  5928. }
  5929. }
  5930. #endif
  5931. #if defined(HAS_I422TOARGBROW_SVE2)
  5932. if (TestCpuFlag(kCpuHasSVE2)) {
  5933. I422ToARGBRow = I422ToARGBRow_SVE2;
  5934. }
  5935. #endif
  5936. #if defined(HAS_I422TOARGBROW_MSA)
  5937. if (TestCpuFlag(kCpuHasMSA)) {
  5938. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  5939. if (IS_ALIGNED(width, 8)) {
  5940. I422ToARGBRow = I422ToARGBRow_MSA;
  5941. }
  5942. }
  5943. #endif
  5944. #if defined(HAS_I422TOARGBROW_LSX)
  5945. if (TestCpuFlag(kCpuHasLSX)) {
  5946. I422ToARGBRow = I422ToARGBRow_Any_LSX;
  5947. if (IS_ALIGNED(width, 16)) {
  5948. I422ToARGBRow = I422ToARGBRow_LSX;
  5949. }
  5950. }
  5951. #endif
  5952. #if defined(HAS_I422TOARGBROW_LASX)
  5953. if (TestCpuFlag(kCpuHasLASX)) {
  5954. I422ToARGBRow = I422ToARGBRow_Any_LASX;
  5955. if (IS_ALIGNED(width, 32)) {
  5956. I422ToARGBRow = I422ToARGBRow_LASX;
  5957. }
  5958. }
  5959. #endif
  5960. #if defined(HAS_I422TOARGBROW_RVV)
  5961. if (TestCpuFlag(kCpuHasRVV)) {
  5962. I422ToARGBRow = I422ToARGBRow_RVV;
  5963. }
  5964. #endif
  5965. #if defined(HAS_ARGBTORGB565DITHERROW_SSE2)
  5966. if (TestCpuFlag(kCpuHasSSE2)) {
  5967. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2;
  5968. if (IS_ALIGNED(width, 4)) {
  5969. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2;
  5970. }
  5971. }
  5972. #endif
  5973. #if defined(HAS_ARGBTORGB565DITHERROW_AVX2)
  5974. if (TestCpuFlag(kCpuHasAVX2)) {
  5975. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2;
  5976. if (IS_ALIGNED(width, 8)) {
  5977. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2;
  5978. }
  5979. }
  5980. #endif
  5981. #if defined(HAS_ARGBTORGB565DITHERROW_NEON)
  5982. if (TestCpuFlag(kCpuHasNEON)) {
  5983. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON;
  5984. if (IS_ALIGNED(width, 8)) {
  5985. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON;
  5986. }
  5987. }
  5988. #endif
  5989. #if defined(HAS_ARGBTORGB565DITHERROW_SVE2)
  5990. if (TestCpuFlag(kCpuHasSVE2)) {
  5991. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SVE2;
  5992. }
  5993. #endif
  5994. #if defined(HAS_ARGBTORGB565DITHERROW_MSA)
  5995. if (TestCpuFlag(kCpuHasMSA)) {
  5996. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MSA;
  5997. if (IS_ALIGNED(width, 8)) {
  5998. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MSA;
  5999. }
  6000. }
  6001. #endif
  6002. #if defined(HAS_ARGBTORGB565DITHERROW_LSX)
  6003. if (TestCpuFlag(kCpuHasLSX)) {
  6004. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LSX;
  6005. if (IS_ALIGNED(width, 8)) {
  6006. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LSX;
  6007. }
  6008. }
  6009. #endif
  6010. #if defined(HAS_ARGBTORGB565DITHERROW_LASX)
  6011. if (TestCpuFlag(kCpuHasLASX)) {
  6012. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LASX;
  6013. if (IS_ALIGNED(width, 16)) {
  6014. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LASX;
  6015. }
  6016. }
  6017. #endif
  6018. {
  6019. // Allocate a row of argb.
  6020. align_buffer_64(row_argb, width * 4);
  6021. if (!row_argb)
  6022. return 1;
  6023. for (y = 0; y < height; ++y) {
  6024. I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width);
  6025. ARGBToRGB565DitherRow(row_argb, dst_rgb565,
  6026. *(const uint32_t*)(dither4x4 + ((y & 3) << 2)),
  6027. width);
  6028. dst_rgb565 += dst_stride_rgb565;
  6029. src_y += src_stride_y;
  6030. if (y & 1) {
  6031. src_u += src_stride_u;
  6032. src_v += src_stride_v;
  6033. }
  6034. }
  6035. free_aligned_buffer_64(row_argb);
  6036. }
  6037. return 0;
  6038. }
  6039. // Convert I420 to AR30 with matrix.
  6040. LIBYUV_API
  6041. int I420ToAR30Matrix(const uint8_t* src_y,
  6042. int src_stride_y,
  6043. const uint8_t* src_u,
  6044. int src_stride_u,
  6045. const uint8_t* src_v,
  6046. int src_stride_v,
  6047. uint8_t* dst_ar30,
  6048. int dst_stride_ar30,
  6049. const struct YuvConstants* yuvconstants,
  6050. int width,
  6051. int height) {
  6052. int y;
  6053. void (*I422ToAR30Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  6054. const uint8_t* v_buf, uint8_t* rgb_buf,
  6055. const struct YuvConstants* yuvconstants, int width) =
  6056. I422ToAR30Row_C;
  6057. assert(yuvconstants);
  6058. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  6059. return -1;
  6060. }
  6061. // Negative height means invert the image.
  6062. if (height < 0) {
  6063. height = -height;
  6064. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  6065. dst_stride_ar30 = -dst_stride_ar30;
  6066. }
  6067. #if defined(HAS_I422TOAR30ROW_SSSE3)
  6068. if (TestCpuFlag(kCpuHasSSSE3)) {
  6069. I422ToAR30Row = I422ToAR30Row_Any_SSSE3;
  6070. if (IS_ALIGNED(width, 8)) {
  6071. I422ToAR30Row = I422ToAR30Row_SSSE3;
  6072. }
  6073. }
  6074. #endif
  6075. #if defined(HAS_I422TOAR30ROW_AVX2)
  6076. if (TestCpuFlag(kCpuHasAVX2)) {
  6077. I422ToAR30Row = I422ToAR30Row_Any_AVX2;
  6078. if (IS_ALIGNED(width, 16)) {
  6079. I422ToAR30Row = I422ToAR30Row_AVX2;
  6080. }
  6081. }
  6082. #endif
  6083. #if defined(HAS_I422TOAR30ROW_NEON)
  6084. if (TestCpuFlag(kCpuHasNEON)) {
  6085. I422ToAR30Row = I422ToAR30Row_Any_NEON;
  6086. if (IS_ALIGNED(width, 8)) {
  6087. I422ToAR30Row = I422ToAR30Row_NEON;
  6088. }
  6089. }
  6090. #endif
  6091. for (y = 0; y < height; ++y) {
  6092. I422ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  6093. dst_ar30 += dst_stride_ar30;
  6094. src_y += src_stride_y;
  6095. if (y & 1) {
  6096. src_u += src_stride_u;
  6097. src_v += src_stride_v;
  6098. }
  6099. }
  6100. return 0;
  6101. }
  6102. // Convert I420 to AR30.
  6103. LIBYUV_API
  6104. int I420ToAR30(const uint8_t* src_y,
  6105. int src_stride_y,
  6106. const uint8_t* src_u,
  6107. int src_stride_u,
  6108. const uint8_t* src_v,
  6109. int src_stride_v,
  6110. uint8_t* dst_ar30,
  6111. int dst_stride_ar30,
  6112. int width,
  6113. int height) {
  6114. return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  6115. src_stride_v, dst_ar30, dst_stride_ar30,
  6116. &kYuvI601Constants, width, height);
  6117. }
  6118. // Convert H420 to AR30.
  6119. LIBYUV_API
  6120. int H420ToAR30(const uint8_t* src_y,
  6121. int src_stride_y,
  6122. const uint8_t* src_u,
  6123. int src_stride_u,
  6124. const uint8_t* src_v,
  6125. int src_stride_v,
  6126. uint8_t* dst_ar30,
  6127. int dst_stride_ar30,
  6128. int width,
  6129. int height) {
  6130. return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  6131. src_stride_v, dst_ar30, dst_stride_ar30,
  6132. &kYvuH709Constants, width, height);
  6133. }
  6134. // Convert I420 to AB30.
  6135. LIBYUV_API
  6136. int I420ToAB30(const uint8_t* src_y,
  6137. int src_stride_y,
  6138. const uint8_t* src_u,
  6139. int src_stride_u,
  6140. const uint8_t* src_v,
  6141. int src_stride_v,
  6142. uint8_t* dst_ab30,
  6143. int dst_stride_ab30,
  6144. int width,
  6145. int height) {
  6146. return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  6147. src_stride_u, dst_ab30, dst_stride_ab30,
  6148. &kYvuI601Constants, width, height);
  6149. }
  6150. // Convert H420 to AB30.
  6151. LIBYUV_API
  6152. int H420ToAB30(const uint8_t* src_y,
  6153. int src_stride_y,
  6154. const uint8_t* src_u,
  6155. int src_stride_u,
  6156. const uint8_t* src_v,
  6157. int src_stride_v,
  6158. uint8_t* dst_ab30,
  6159. int dst_stride_ab30,
  6160. int width,
  6161. int height) {
  6162. return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  6163. src_stride_u, dst_ab30, dst_stride_ab30,
  6164. &kYvuH709Constants, width, height);
  6165. }
  6166. static int I420ToARGBMatrixBilinear(const uint8_t* src_y,
  6167. int src_stride_y,
  6168. const uint8_t* src_u,
  6169. int src_stride_u,
  6170. const uint8_t* src_v,
  6171. int src_stride_v,
  6172. uint8_t* dst_argb,
  6173. int dst_stride_argb,
  6174. const struct YuvConstants* yuvconstants,
  6175. int width,
  6176. int height) {
  6177. int y;
  6178. void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  6179. const uint8_t* v_buf, uint8_t* rgb_buf,
  6180. const struct YuvConstants* yuvconstants, int width) =
  6181. I444ToARGBRow_C;
  6182. void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride,
  6183. uint8_t* dst_ptr, ptrdiff_t dst_stride,
  6184. int dst_width) = ScaleRowUp2_Bilinear_Any_C;
  6185. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  6186. int dst_width) = ScaleRowUp2_Linear_Any_C;
  6187. assert(yuvconstants);
  6188. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  6189. return -1;
  6190. }
  6191. // Negative height means invert the image.
  6192. if (height < 0) {
  6193. height = -height;
  6194. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  6195. dst_stride_argb = -dst_stride_argb;
  6196. }
  6197. #if defined(HAS_I444TOARGBROW_SSSE3)
  6198. if (TestCpuFlag(kCpuHasSSSE3)) {
  6199. I444ToARGBRow = I444ToARGBRow_Any_SSSE3;
  6200. if (IS_ALIGNED(width, 8)) {
  6201. I444ToARGBRow = I444ToARGBRow_SSSE3;
  6202. }
  6203. }
  6204. #endif
  6205. #if defined(HAS_I444TOARGBROW_AVX2)
  6206. if (TestCpuFlag(kCpuHasAVX2)) {
  6207. I444ToARGBRow = I444ToARGBRow_Any_AVX2;
  6208. if (IS_ALIGNED(width, 16)) {
  6209. I444ToARGBRow = I444ToARGBRow_AVX2;
  6210. }
  6211. }
  6212. #endif
  6213. #if defined(HAS_I444TOARGBROW_NEON)
  6214. if (TestCpuFlag(kCpuHasNEON)) {
  6215. I444ToARGBRow = I444ToARGBRow_Any_NEON;
  6216. if (IS_ALIGNED(width, 8)) {
  6217. I444ToARGBRow = I444ToARGBRow_NEON;
  6218. }
  6219. }
  6220. #endif
  6221. #if defined(HAS_I444TOARGBROW_SVE2)
  6222. if (TestCpuFlag(kCpuHasSVE2)) {
  6223. I444ToARGBRow = I444ToARGBRow_SVE2;
  6224. }
  6225. #endif
  6226. #if defined(HAS_I444TOARGBROW_MSA)
  6227. if (TestCpuFlag(kCpuHasMSA)) {
  6228. I444ToARGBRow = I444ToARGBRow_Any_MSA;
  6229. if (IS_ALIGNED(width, 8)) {
  6230. I444ToARGBRow = I444ToARGBRow_MSA;
  6231. }
  6232. }
  6233. #endif
  6234. #if defined(HAS_I444TOARGBROW_LASX)
  6235. if (TestCpuFlag(kCpuHasLASX)) {
  6236. I444ToARGBRow = I444ToARGBRow_Any_LASX;
  6237. if (IS_ALIGNED(width, 32)) {
  6238. I444ToARGBRow = I444ToARGBRow_LASX;
  6239. }
  6240. }
  6241. #endif
  6242. #if defined(HAS_I444TOARGBROW_RVV)
  6243. if (TestCpuFlag(kCpuHasRVV)) {
  6244. I444ToARGBRow = I444ToARGBRow_RVV;
  6245. }
  6246. #endif
  6247. #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2)
  6248. if (TestCpuFlag(kCpuHasSSE2)) {
  6249. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2;
  6250. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  6251. }
  6252. #endif
  6253. #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3)
  6254. if (TestCpuFlag(kCpuHasSSSE3)) {
  6255. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3;
  6256. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  6257. }
  6258. #endif
  6259. #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2)
  6260. if (TestCpuFlag(kCpuHasAVX2)) {
  6261. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2;
  6262. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  6263. }
  6264. #endif
  6265. #if defined(HAS_SCALEROWUP2_BILINEAR_NEON)
  6266. if (TestCpuFlag(kCpuHasNEON)) {
  6267. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON;
  6268. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  6269. }
  6270. #endif
  6271. #if defined(HAS_SCALEROWUP2_BILINEAR_RVV)
  6272. if (TestCpuFlag(kCpuHasRVV)) {
  6273. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV;
  6274. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  6275. }
  6276. #endif
  6277. // alloc 4 lines temp
  6278. const int row_size = (width + 31) & ~31;
  6279. align_buffer_64(row, row_size * 4);
  6280. uint8_t* temp_u_1 = row;
  6281. uint8_t* temp_u_2 = row + row_size;
  6282. uint8_t* temp_v_1 = row + row_size * 2;
  6283. uint8_t* temp_v_2 = row + row_size * 3;
  6284. if (!row)
  6285. return 1;
  6286. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  6287. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  6288. I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6289. dst_argb += dst_stride_argb;
  6290. src_y += src_stride_y;
  6291. for (y = 0; y < height - 2; y += 2) {
  6292. Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width);
  6293. Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width);
  6294. I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6295. dst_argb += dst_stride_argb;
  6296. src_y += src_stride_y;
  6297. I444ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width);
  6298. dst_argb += dst_stride_argb;
  6299. src_y += src_stride_y;
  6300. src_u += src_stride_u;
  6301. src_v += src_stride_v;
  6302. }
  6303. if (!(height & 1)) {
  6304. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  6305. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  6306. I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6307. }
  6308. free_aligned_buffer_64(row);
  6309. return 0;
  6310. }
  6311. static int I422ToARGBMatrixLinear(const uint8_t* src_y,
  6312. int src_stride_y,
  6313. const uint8_t* src_u,
  6314. int src_stride_u,
  6315. const uint8_t* src_v,
  6316. int src_stride_v,
  6317. uint8_t* dst_argb,
  6318. int dst_stride_argb,
  6319. const struct YuvConstants* yuvconstants,
  6320. int width,
  6321. int height) {
  6322. int y;
  6323. void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  6324. const uint8_t* v_buf, uint8_t* rgb_buf,
  6325. const struct YuvConstants* yuvconstants, int width) =
  6326. I444ToARGBRow_C;
  6327. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  6328. int dst_width) = ScaleRowUp2_Linear_Any_C;
  6329. assert(yuvconstants);
  6330. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  6331. return -1;
  6332. }
  6333. // Negative height means invert the image.
  6334. if (height < 0) {
  6335. height = -height;
  6336. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  6337. dst_stride_argb = -dst_stride_argb;
  6338. }
  6339. #if defined(HAS_I444TOARGBROW_SSSE3)
  6340. if (TestCpuFlag(kCpuHasSSSE3)) {
  6341. I444ToARGBRow = I444ToARGBRow_Any_SSSE3;
  6342. if (IS_ALIGNED(width, 8)) {
  6343. I444ToARGBRow = I444ToARGBRow_SSSE3;
  6344. }
  6345. }
  6346. #endif
  6347. #if defined(HAS_I444TOARGBROW_AVX2)
  6348. if (TestCpuFlag(kCpuHasAVX2)) {
  6349. I444ToARGBRow = I444ToARGBRow_Any_AVX2;
  6350. if (IS_ALIGNED(width, 16)) {
  6351. I444ToARGBRow = I444ToARGBRow_AVX2;
  6352. }
  6353. }
  6354. #endif
  6355. #if defined(HAS_I444TOARGBROW_NEON)
  6356. if (TestCpuFlag(kCpuHasNEON)) {
  6357. I444ToARGBRow = I444ToARGBRow_Any_NEON;
  6358. if (IS_ALIGNED(width, 8)) {
  6359. I444ToARGBRow = I444ToARGBRow_NEON;
  6360. }
  6361. }
  6362. #endif
  6363. #if defined(HAS_I444TOARGBROW_SVE2)
  6364. if (TestCpuFlag(kCpuHasSVE2)) {
  6365. I444ToARGBRow = I444ToARGBRow_SVE2;
  6366. }
  6367. #endif
  6368. #if defined(HAS_I444TOARGBROW_MSA)
  6369. if (TestCpuFlag(kCpuHasMSA)) {
  6370. I444ToARGBRow = I444ToARGBRow_Any_MSA;
  6371. if (IS_ALIGNED(width, 8)) {
  6372. I444ToARGBRow = I444ToARGBRow_MSA;
  6373. }
  6374. }
  6375. #endif
  6376. #if defined(HAS_I444TOARGBROW_LASX)
  6377. if (TestCpuFlag(kCpuHasLASX)) {
  6378. I444ToARGBRow = I444ToARGBRow_Any_LASX;
  6379. if (IS_ALIGNED(width, 32)) {
  6380. I444ToARGBRow = I444ToARGBRow_LASX;
  6381. }
  6382. }
  6383. #endif
  6384. #if defined(HAS_I444TOARGBROW_RVV)
  6385. if (TestCpuFlag(kCpuHasRVV)) {
  6386. I444ToARGBRow = I444ToARGBRow_RVV;
  6387. }
  6388. #endif
  6389. #if defined(HAS_SCALEROWUP2_LINEAR_SSE2)
  6390. if (TestCpuFlag(kCpuHasSSE2)) {
  6391. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  6392. }
  6393. #endif
  6394. #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3)
  6395. if (TestCpuFlag(kCpuHasSSSE3)) {
  6396. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  6397. }
  6398. #endif
  6399. #if defined(HAS_SCALEROWUP2_LINEAR_AVX2)
  6400. if (TestCpuFlag(kCpuHasAVX2)) {
  6401. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  6402. }
  6403. #endif
  6404. #if defined(HAS_SCALEROWUP2_LINEAR_NEON)
  6405. if (TestCpuFlag(kCpuHasNEON)) {
  6406. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  6407. }
  6408. #endif
  6409. #if defined(HAS_SCALEROWUP2_LINEAR_RVV)
  6410. if (TestCpuFlag(kCpuHasRVV)) {
  6411. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  6412. }
  6413. #endif
  6414. // alloc 2 lines temp
  6415. const int row_size = (width + 31) & ~31;
  6416. align_buffer_64(row, row_size * 2);
  6417. uint8_t* temp_u = row;
  6418. uint8_t* temp_v = row + row_size;
  6419. if (!row)
  6420. return 1;
  6421. for (y = 0; y < height; ++y) {
  6422. ScaleRowUp2_Linear(src_u, temp_u, width);
  6423. ScaleRowUp2_Linear(src_v, temp_v, width);
  6424. I444ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width);
  6425. dst_argb += dst_stride_argb;
  6426. src_y += src_stride_y;
  6427. src_u += src_stride_u;
  6428. src_v += src_stride_v;
  6429. }
  6430. free_aligned_buffer_64(row);
  6431. return 0;
  6432. }
  6433. static int I420ToRGB24MatrixBilinear(const uint8_t* src_y,
  6434. int src_stride_y,
  6435. const uint8_t* src_u,
  6436. int src_stride_u,
  6437. const uint8_t* src_v,
  6438. int src_stride_v,
  6439. uint8_t* dst_rgb24,
  6440. int dst_stride_rgb24,
  6441. const struct YuvConstants* yuvconstants,
  6442. int width,
  6443. int height) {
  6444. int y;
  6445. void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  6446. const uint8_t* v_buf, uint8_t* rgb_buf,
  6447. const struct YuvConstants* yuvconstants, int width) =
  6448. I444ToRGB24Row_C;
  6449. void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride,
  6450. uint8_t* dst_ptr, ptrdiff_t dst_stride,
  6451. int dst_width) = ScaleRowUp2_Bilinear_Any_C;
  6452. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  6453. int dst_width) = ScaleRowUp2_Linear_Any_C;
  6454. assert(yuvconstants);
  6455. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  6456. return -1;
  6457. }
  6458. // Negative height means invert the image.
  6459. if (height < 0) {
  6460. height = -height;
  6461. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  6462. dst_stride_rgb24 = -dst_stride_rgb24;
  6463. }
  6464. #if defined(HAS_I444TORGB24ROW_SSSE3)
  6465. if (TestCpuFlag(kCpuHasSSSE3)) {
  6466. I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3;
  6467. if (IS_ALIGNED(width, 16)) {
  6468. I444ToRGB24Row = I444ToRGB24Row_SSSE3;
  6469. }
  6470. }
  6471. #endif
  6472. #if defined(HAS_I444TORGB24ROW_AVX2)
  6473. if (TestCpuFlag(kCpuHasAVX2)) {
  6474. I444ToRGB24Row = I444ToRGB24Row_Any_AVX2;
  6475. if (IS_ALIGNED(width, 32)) {
  6476. I444ToRGB24Row = I444ToRGB24Row_AVX2;
  6477. }
  6478. }
  6479. #endif
  6480. #if defined(HAS_I444TORGB24ROW_NEON)
  6481. if (TestCpuFlag(kCpuHasNEON)) {
  6482. I444ToRGB24Row = I444ToRGB24Row_Any_NEON;
  6483. if (IS_ALIGNED(width, 8)) {
  6484. I444ToRGB24Row = I444ToRGB24Row_NEON;
  6485. }
  6486. }
  6487. #endif
  6488. #if defined(HAS_I444TORGB24ROW_MSA)
  6489. if (TestCpuFlag(kCpuHasMSA)) {
  6490. I444ToRGB24Row = I444ToRGB24Row_Any_MSA;
  6491. if (IS_ALIGNED(width, 8)) {
  6492. I444ToRGB24Row = I444ToRGB24Row_MSA;
  6493. }
  6494. }
  6495. #endif
  6496. #if defined(HAS_I444TORGB24ROW_LASX)
  6497. if (TestCpuFlag(kCpuHasLASX)) {
  6498. I444ToRGB24Row = I444ToRGB24Row_Any_LASX;
  6499. if (IS_ALIGNED(width, 32)) {
  6500. I444ToRGB24Row = I444ToRGB24Row_LASX;
  6501. }
  6502. }
  6503. #endif
  6504. #if defined(HAS_I444TORGB24ROW_RVV)
  6505. if (TestCpuFlag(kCpuHasRVV)) {
  6506. I444ToRGB24Row = I444ToRGB24Row_RVV;
  6507. }
  6508. #endif
  6509. #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2)
  6510. if (TestCpuFlag(kCpuHasSSE2)) {
  6511. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2;
  6512. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  6513. }
  6514. #endif
  6515. #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3)
  6516. if (TestCpuFlag(kCpuHasSSSE3)) {
  6517. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3;
  6518. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  6519. }
  6520. #endif
  6521. #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2)
  6522. if (TestCpuFlag(kCpuHasAVX2)) {
  6523. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2;
  6524. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  6525. }
  6526. #endif
  6527. #if defined(HAS_SCALEROWUP2_BILINEAR_NEON)
  6528. if (TestCpuFlag(kCpuHasNEON)) {
  6529. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON;
  6530. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  6531. }
  6532. #endif
  6533. #if defined(HAS_SCALEROWUP2_BILINEAR_RVV)
  6534. if (TestCpuFlag(kCpuHasRVV)) {
  6535. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV;
  6536. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  6537. }
  6538. #endif
  6539. // alloc 4 lines temp
  6540. const int row_size = (width + 31) & ~31;
  6541. align_buffer_64(row, row_size * 4);
  6542. uint8_t* temp_u_1 = row;
  6543. uint8_t* temp_u_2 = row + row_size;
  6544. uint8_t* temp_v_1 = row + row_size * 2;
  6545. uint8_t* temp_v_2 = row + row_size * 3;
  6546. if (!row)
  6547. return 1;
  6548. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  6549. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  6550. I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width);
  6551. dst_rgb24 += dst_stride_rgb24;
  6552. src_y += src_stride_y;
  6553. for (y = 0; y < height - 2; y += 2) {
  6554. Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width);
  6555. Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width);
  6556. I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width);
  6557. dst_rgb24 += dst_stride_rgb24;
  6558. src_y += src_stride_y;
  6559. I444ToRGB24Row(src_y, temp_u_2, temp_v_2, dst_rgb24, yuvconstants, width);
  6560. dst_rgb24 += dst_stride_rgb24;
  6561. src_y += src_stride_y;
  6562. src_u += src_stride_u;
  6563. src_v += src_stride_v;
  6564. }
  6565. if (!(height & 1)) {
  6566. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  6567. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  6568. I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width);
  6569. }
  6570. free_aligned_buffer_64(row);
  6571. return 0;
  6572. }
  6573. static int I010ToAR30MatrixBilinear(const uint16_t* src_y,
  6574. int src_stride_y,
  6575. const uint16_t* src_u,
  6576. int src_stride_u,
  6577. const uint16_t* src_v,
  6578. int src_stride_v,
  6579. uint8_t* dst_ar30,
  6580. int dst_stride_ar30,
  6581. const struct YuvConstants* yuvconstants,
  6582. int width,
  6583. int height) {
  6584. int y;
  6585. void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  6586. const uint16_t* v_buf, uint8_t* rgb_buf,
  6587. const struct YuvConstants* yuvconstants, int width) =
  6588. I410ToAR30Row_C;
  6589. void (*Scale2RowUp_Bilinear_12)(
  6590. const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr,
  6591. ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C;
  6592. void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  6593. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  6594. assert(yuvconstants);
  6595. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  6596. return -1;
  6597. }
  6598. // Negative height means invert the image.
  6599. if (height < 0) {
  6600. height = -height;
  6601. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  6602. dst_stride_ar30 = -dst_stride_ar30;
  6603. }
  6604. #if defined(HAS_I410TOAR30ROW_NEON)
  6605. if (TestCpuFlag(kCpuHasNEON)) {
  6606. I410ToAR30Row = I410ToAR30Row_Any_NEON;
  6607. if (IS_ALIGNED(width, 8)) {
  6608. I410ToAR30Row = I410ToAR30Row_NEON;
  6609. }
  6610. }
  6611. #endif
  6612. #if defined(HAS_I410TOAR30ROW_SSSE3)
  6613. if (TestCpuFlag(kCpuHasSSSE3)) {
  6614. I410ToAR30Row = I410ToAR30Row_Any_SSSE3;
  6615. if (IS_ALIGNED(width, 8)) {
  6616. I410ToAR30Row = I410ToAR30Row_SSSE3;
  6617. }
  6618. }
  6619. #endif
  6620. #if defined(HAS_I410TOAR30ROW_AVX2)
  6621. if (TestCpuFlag(kCpuHasAVX2)) {
  6622. I410ToAR30Row = I410ToAR30Row_Any_AVX2;
  6623. if (IS_ALIGNED(width, 16)) {
  6624. I410ToAR30Row = I410ToAR30Row_AVX2;
  6625. }
  6626. }
  6627. #endif
  6628. #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3)
  6629. if (TestCpuFlag(kCpuHasSSSE3)) {
  6630. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3;
  6631. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3;
  6632. }
  6633. #endif
  6634. #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2)
  6635. if (TestCpuFlag(kCpuHasAVX2)) {
  6636. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2;
  6637. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2;
  6638. }
  6639. #endif
  6640. #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON)
  6641. if (TestCpuFlag(kCpuHasNEON)) {
  6642. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON;
  6643. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON;
  6644. }
  6645. #endif
  6646. // alloc 4 lines temp
  6647. const int row_size = (width + 31) & ~31;
  6648. align_buffer_64(row, row_size * 4 * sizeof(uint16_t));
  6649. uint16_t* temp_u_1 = (uint16_t*)(row);
  6650. uint16_t* temp_u_2 = (uint16_t*)(row) + row_size;
  6651. uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2;
  6652. uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3;
  6653. if (!row)
  6654. return 1;
  6655. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  6656. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  6657. I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width);
  6658. dst_ar30 += dst_stride_ar30;
  6659. src_y += src_stride_y;
  6660. for (y = 0; y < height - 2; y += 2) {
  6661. Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width);
  6662. Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width);
  6663. I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width);
  6664. dst_ar30 += dst_stride_ar30;
  6665. src_y += src_stride_y;
  6666. I410ToAR30Row(src_y, temp_u_2, temp_v_2, dst_ar30, yuvconstants, width);
  6667. dst_ar30 += dst_stride_ar30;
  6668. src_y += src_stride_y;
  6669. src_u += src_stride_u;
  6670. src_v += src_stride_v;
  6671. }
  6672. if (!(height & 1)) {
  6673. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  6674. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  6675. I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width);
  6676. }
  6677. free_aligned_buffer_64(row);
  6678. return 0;
  6679. }
  6680. static int I210ToAR30MatrixLinear(const uint16_t* src_y,
  6681. int src_stride_y,
  6682. const uint16_t* src_u,
  6683. int src_stride_u,
  6684. const uint16_t* src_v,
  6685. int src_stride_v,
  6686. uint8_t* dst_ar30,
  6687. int dst_stride_ar30,
  6688. const struct YuvConstants* yuvconstants,
  6689. int width,
  6690. int height) {
  6691. int y;
  6692. void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  6693. const uint16_t* v_buf, uint8_t* rgb_buf,
  6694. const struct YuvConstants* yuvconstants, int width) =
  6695. I410ToAR30Row_C;
  6696. void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  6697. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  6698. assert(yuvconstants);
  6699. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  6700. return -1;
  6701. }
  6702. // Negative height means invert the image.
  6703. if (height < 0) {
  6704. height = -height;
  6705. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  6706. dst_stride_ar30 = -dst_stride_ar30;
  6707. }
  6708. #if defined(HAS_I410TOAR30ROW_NEON)
  6709. if (TestCpuFlag(kCpuHasNEON)) {
  6710. I410ToAR30Row = I410ToAR30Row_Any_NEON;
  6711. if (IS_ALIGNED(width, 8)) {
  6712. I410ToAR30Row = I410ToAR30Row_NEON;
  6713. }
  6714. }
  6715. #endif
  6716. #if defined(HAS_I410TOAR30ROW_SSSE3)
  6717. if (TestCpuFlag(kCpuHasSSSE3)) {
  6718. I410ToAR30Row = I410ToAR30Row_Any_SSSE3;
  6719. if (IS_ALIGNED(width, 8)) {
  6720. I410ToAR30Row = I410ToAR30Row_SSSE3;
  6721. }
  6722. }
  6723. #endif
  6724. #if defined(HAS_I410TOAR30ROW_AVX2)
  6725. if (TestCpuFlag(kCpuHasAVX2)) {
  6726. I410ToAR30Row = I410ToAR30Row_Any_AVX2;
  6727. if (IS_ALIGNED(width, 16)) {
  6728. I410ToAR30Row = I410ToAR30Row_AVX2;
  6729. }
  6730. }
  6731. #endif
  6732. #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3)
  6733. if (TestCpuFlag(kCpuHasSSSE3)) {
  6734. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3;
  6735. }
  6736. #endif
  6737. #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2)
  6738. if (TestCpuFlag(kCpuHasAVX2)) {
  6739. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2;
  6740. }
  6741. #endif
  6742. #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON)
  6743. if (TestCpuFlag(kCpuHasNEON)) {
  6744. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON;
  6745. }
  6746. #endif
  6747. // alloc 2 lines temp
  6748. const int row_size = (width + 31) & ~31;
  6749. align_buffer_64(row, row_size * 2 * sizeof(uint16_t));
  6750. uint16_t* temp_u = (uint16_t*)(row);
  6751. uint16_t* temp_v = (uint16_t*)(row) + row_size;
  6752. if (!row)
  6753. return 1;
  6754. for (y = 0; y < height; ++y) {
  6755. ScaleRowUp2_Linear_12(src_u, temp_u, width);
  6756. ScaleRowUp2_Linear_12(src_v, temp_v, width);
  6757. I410ToAR30Row(src_y, temp_u, temp_v, dst_ar30, yuvconstants, width);
  6758. dst_ar30 += dst_stride_ar30;
  6759. src_y += src_stride_y;
  6760. src_u += src_stride_u;
  6761. src_v += src_stride_v;
  6762. }
  6763. free_aligned_buffer_64(row);
  6764. return 0;
  6765. }
  6766. static int I010ToARGBMatrixBilinear(const uint16_t* src_y,
  6767. int src_stride_y,
  6768. const uint16_t* src_u,
  6769. int src_stride_u,
  6770. const uint16_t* src_v,
  6771. int src_stride_v,
  6772. uint8_t* dst_argb,
  6773. int dst_stride_argb,
  6774. const struct YuvConstants* yuvconstants,
  6775. int width,
  6776. int height) {
  6777. int y;
  6778. void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  6779. const uint16_t* v_buf, uint8_t* rgb_buf,
  6780. const struct YuvConstants* yuvconstants, int width) =
  6781. I410ToARGBRow_C;
  6782. void (*Scale2RowUp_Bilinear_12)(
  6783. const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr,
  6784. ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C;
  6785. void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  6786. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  6787. assert(yuvconstants);
  6788. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  6789. return -1;
  6790. }
  6791. // Negative height means invert the image.
  6792. if (height < 0) {
  6793. height = -height;
  6794. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  6795. dst_stride_argb = -dst_stride_argb;
  6796. }
  6797. #if defined(HAS_I410TOARGBROW_SSSE3)
  6798. if (TestCpuFlag(kCpuHasSSSE3)) {
  6799. I410ToARGBRow = I410ToARGBRow_Any_SSSE3;
  6800. if (IS_ALIGNED(width, 8)) {
  6801. I410ToARGBRow = I410ToARGBRow_SSSE3;
  6802. }
  6803. }
  6804. #endif
  6805. #if defined(HAS_I410TOARGBROW_NEON)
  6806. if (TestCpuFlag(kCpuHasNEON)) {
  6807. I410ToARGBRow = I410ToARGBRow_Any_NEON;
  6808. if (IS_ALIGNED(width, 8)) {
  6809. I410ToARGBRow = I410ToARGBRow_NEON;
  6810. }
  6811. }
  6812. #endif
  6813. #if defined(HAS_I410TOARGBROW_AVX2)
  6814. if (TestCpuFlag(kCpuHasAVX2)) {
  6815. I410ToARGBRow = I410ToARGBRow_Any_AVX2;
  6816. if (IS_ALIGNED(width, 16)) {
  6817. I410ToARGBRow = I410ToARGBRow_AVX2;
  6818. }
  6819. }
  6820. #endif
  6821. #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3)
  6822. if (TestCpuFlag(kCpuHasSSSE3)) {
  6823. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3;
  6824. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3;
  6825. }
  6826. #endif
  6827. #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2)
  6828. if (TestCpuFlag(kCpuHasAVX2)) {
  6829. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2;
  6830. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2;
  6831. }
  6832. #endif
  6833. #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON)
  6834. if (TestCpuFlag(kCpuHasNEON)) {
  6835. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON;
  6836. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON;
  6837. }
  6838. #endif
  6839. // alloc 4 lines temp
  6840. const int row_size = (width + 31) & ~31;
  6841. align_buffer_64(row, row_size * 4 * sizeof(uint16_t));
  6842. uint16_t* temp_u_1 = (uint16_t*)(row);
  6843. uint16_t* temp_u_2 = (uint16_t*)(row) + row_size;
  6844. uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2;
  6845. uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3;
  6846. if (!row)
  6847. return 1;
  6848. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  6849. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  6850. I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6851. dst_argb += dst_stride_argb;
  6852. src_y += src_stride_y;
  6853. for (y = 0; y < height - 2; y += 2) {
  6854. Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width);
  6855. Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width);
  6856. I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6857. dst_argb += dst_stride_argb;
  6858. src_y += src_stride_y;
  6859. I410ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width);
  6860. dst_argb += dst_stride_argb;
  6861. src_y += src_stride_y;
  6862. src_u += src_stride_u;
  6863. src_v += src_stride_v;
  6864. }
  6865. if (!(height & 1)) {
  6866. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  6867. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  6868. I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width);
  6869. }
  6870. free_aligned_buffer_64(row);
  6871. return 0;
  6872. }
  6873. static int I210ToARGBMatrixLinear(const uint16_t* src_y,
  6874. int src_stride_y,
  6875. const uint16_t* src_u,
  6876. int src_stride_u,
  6877. const uint16_t* src_v,
  6878. int src_stride_v,
  6879. uint8_t* dst_argb,
  6880. int dst_stride_argb,
  6881. const struct YuvConstants* yuvconstants,
  6882. int width,
  6883. int height) {
  6884. int y;
  6885. void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  6886. const uint16_t* v_buf, uint8_t* rgb_buf,
  6887. const struct YuvConstants* yuvconstants, int width) =
  6888. I410ToARGBRow_C;
  6889. void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  6890. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  6891. assert(yuvconstants);
  6892. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  6893. return -1;
  6894. }
  6895. // Negative height means invert the image.
  6896. if (height < 0) {
  6897. height = -height;
  6898. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  6899. dst_stride_argb = -dst_stride_argb;
  6900. }
  6901. #if defined(HAS_I410TOARGBROW_SSSE3)
  6902. if (TestCpuFlag(kCpuHasSSSE3)) {
  6903. I410ToARGBRow = I410ToARGBRow_Any_SSSE3;
  6904. if (IS_ALIGNED(width, 8)) {
  6905. I410ToARGBRow = I410ToARGBRow_SSSE3;
  6906. }
  6907. }
  6908. #endif
  6909. #if defined(HAS_I410TOARGBROW_NEON)
  6910. if (TestCpuFlag(kCpuHasNEON)) {
  6911. I410ToARGBRow = I410ToARGBRow_Any_NEON;
  6912. if (IS_ALIGNED(width, 8)) {
  6913. I410ToARGBRow = I410ToARGBRow_NEON;
  6914. }
  6915. }
  6916. #endif
  6917. #if defined(HAS_I410TOARGBROW_AVX2)
  6918. if (TestCpuFlag(kCpuHasAVX2)) {
  6919. I410ToARGBRow = I410ToARGBRow_Any_AVX2;
  6920. if (IS_ALIGNED(width, 16)) {
  6921. I410ToARGBRow = I410ToARGBRow_AVX2;
  6922. }
  6923. }
  6924. #endif
  6925. #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3)
  6926. if (TestCpuFlag(kCpuHasSSSE3)) {
  6927. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3;
  6928. }
  6929. #endif
  6930. #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2)
  6931. if (TestCpuFlag(kCpuHasAVX2)) {
  6932. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2;
  6933. }
  6934. #endif
  6935. #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON)
  6936. if (TestCpuFlag(kCpuHasNEON)) {
  6937. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON;
  6938. }
  6939. #endif
  6940. // alloc 2 lines temp
  6941. const int row_size = (width + 31) & ~31;
  6942. align_buffer_64(row, row_size * 2 * sizeof(uint16_t));
  6943. uint16_t* temp_u = (uint16_t*)(row);
  6944. uint16_t* temp_v = (uint16_t*)(row) + row_size;
  6945. if (!row)
  6946. return 1;
  6947. for (y = 0; y < height; ++y) {
  6948. ScaleRowUp2_Linear_12(src_u, temp_u, width);
  6949. ScaleRowUp2_Linear_12(src_v, temp_v, width);
  6950. I410ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width);
  6951. dst_argb += dst_stride_argb;
  6952. src_y += src_stride_y;
  6953. src_u += src_stride_u;
  6954. src_v += src_stride_v;
  6955. }
  6956. free_aligned_buffer_64(row);
  6957. return 0;
  6958. }
  6959. static int I420AlphaToARGBMatrixBilinear(
  6960. const uint8_t* src_y,
  6961. int src_stride_y,
  6962. const uint8_t* src_u,
  6963. int src_stride_u,
  6964. const uint8_t* src_v,
  6965. int src_stride_v,
  6966. const uint8_t* src_a,
  6967. int src_stride_a,
  6968. uint8_t* dst_argb,
  6969. int dst_stride_argb,
  6970. const struct YuvConstants* yuvconstants,
  6971. int width,
  6972. int height,
  6973. int attenuate) {
  6974. int y;
  6975. void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  6976. const uint8_t* v_buf, const uint8_t* a_buf,
  6977. uint8_t* dst_argb,
  6978. const struct YuvConstants* yuvconstants,
  6979. int width) = I444AlphaToARGBRow_C;
  6980. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  6981. int width) = ARGBAttenuateRow_C;
  6982. void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride,
  6983. uint8_t* dst_ptr, ptrdiff_t dst_stride,
  6984. int dst_width) = ScaleRowUp2_Bilinear_Any_C;
  6985. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  6986. int dst_width) = ScaleRowUp2_Linear_Any_C;
  6987. assert(yuvconstants);
  6988. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  6989. height == 0) {
  6990. return -1;
  6991. }
  6992. // Negative height means invert the image.
  6993. if (height < 0) {
  6994. height = -height;
  6995. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  6996. dst_stride_argb = -dst_stride_argb;
  6997. }
  6998. #if defined(HAS_I444ALPHATOARGBROW_SSSE3)
  6999. if (TestCpuFlag(kCpuHasSSSE3)) {
  7000. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3;
  7001. if (IS_ALIGNED(width, 8)) {
  7002. I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3;
  7003. }
  7004. }
  7005. #endif
  7006. #if defined(HAS_I444ALPHATOARGBROW_AVX2)
  7007. if (TestCpuFlag(kCpuHasAVX2)) {
  7008. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2;
  7009. if (IS_ALIGNED(width, 16)) {
  7010. I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2;
  7011. }
  7012. }
  7013. #endif
  7014. #if defined(HAS_I444ALPHATOARGBROW_NEON)
  7015. if (TestCpuFlag(kCpuHasNEON)) {
  7016. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON;
  7017. if (IS_ALIGNED(width, 8)) {
  7018. I444AlphaToARGBRow = I444AlphaToARGBRow_NEON;
  7019. }
  7020. }
  7021. #endif
  7022. #if defined(HAS_I444ALPHATOARGBROW_SVE2)
  7023. if (TestCpuFlag(kCpuHasSVE2)) {
  7024. I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2;
  7025. }
  7026. #endif
  7027. #if defined(HAS_I444ALPHATOARGBROW_MSA)
  7028. if (TestCpuFlag(kCpuHasMSA)) {
  7029. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_MSA;
  7030. if (IS_ALIGNED(width, 8)) {
  7031. I444AlphaToARGBRow = I444AlphaToARGBRow_MSA;
  7032. }
  7033. }
  7034. #endif
  7035. #if defined(HAS_I444ALPHATOARGBROW_LASX)
  7036. if (TestCpuFlag(kCpuHasLASX)) {
  7037. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_LASX;
  7038. if (IS_ALIGNED(width, 16)) {
  7039. I444AlphaToARGBRow = I444AlphaToARGBRow_LASX;
  7040. }
  7041. }
  7042. #endif
  7043. #if defined(HAS_I444ALPHATOARGBROW_RVV)
  7044. if (TestCpuFlag(kCpuHasRVV)) {
  7045. I444AlphaToARGBRow = I444AlphaToARGBRow_RVV;
  7046. }
  7047. #endif
  7048. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  7049. if (TestCpuFlag(kCpuHasSSSE3)) {
  7050. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  7051. if (IS_ALIGNED(width, 4)) {
  7052. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  7053. }
  7054. }
  7055. #endif
  7056. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  7057. if (TestCpuFlag(kCpuHasAVX2)) {
  7058. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  7059. if (IS_ALIGNED(width, 8)) {
  7060. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  7061. }
  7062. }
  7063. #endif
  7064. #if defined(HAS_ARGBATTENUATEROW_NEON)
  7065. if (TestCpuFlag(kCpuHasNEON)) {
  7066. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  7067. if (IS_ALIGNED(width, 8)) {
  7068. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  7069. }
  7070. }
  7071. #endif
  7072. #if defined(HAS_ARGBATTENUATEROW_MSA)
  7073. if (TestCpuFlag(kCpuHasMSA)) {
  7074. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  7075. if (IS_ALIGNED(width, 8)) {
  7076. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  7077. }
  7078. }
  7079. #endif
  7080. #if defined(HAS_ARGBATTENUATEROW_RVV)
  7081. if (TestCpuFlag(kCpuHasRVV)) {
  7082. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  7083. }
  7084. #endif
  7085. #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2)
  7086. if (TestCpuFlag(kCpuHasSSE2)) {
  7087. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2;
  7088. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  7089. }
  7090. #endif
  7091. #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3)
  7092. if (TestCpuFlag(kCpuHasSSSE3)) {
  7093. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3;
  7094. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  7095. }
  7096. #endif
  7097. #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2)
  7098. if (TestCpuFlag(kCpuHasAVX2)) {
  7099. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2;
  7100. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  7101. }
  7102. #endif
  7103. #if defined(HAS_SCALEROWUP2_BILINEAR_NEON)
  7104. if (TestCpuFlag(kCpuHasNEON)) {
  7105. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON;
  7106. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  7107. }
  7108. #endif
  7109. #if defined(HAS_SCALEROWUP2_BILINEAR_RVV)
  7110. if (TestCpuFlag(kCpuHasRVV)) {
  7111. Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV;
  7112. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  7113. }
  7114. #endif
  7115. // alloc 4 lines temp
  7116. const int row_size = (width + 31) & ~31;
  7117. align_buffer_64(row, row_size * 4);
  7118. uint8_t* temp_u_1 = row;
  7119. uint8_t* temp_u_2 = row + row_size;
  7120. uint8_t* temp_v_1 = row + row_size * 2;
  7121. uint8_t* temp_v_2 = row + row_size * 3;
  7122. if (!row)
  7123. return 1;
  7124. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  7125. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  7126. I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7127. width);
  7128. if (attenuate) {
  7129. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7130. }
  7131. dst_argb += dst_stride_argb;
  7132. src_y += src_stride_y;
  7133. src_a += src_stride_a;
  7134. for (y = 0; y < height - 2; y += 2) {
  7135. Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width);
  7136. Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width);
  7137. I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7138. width);
  7139. if (attenuate) {
  7140. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7141. }
  7142. dst_argb += dst_stride_argb;
  7143. src_y += src_stride_y;
  7144. src_a += src_stride_a;
  7145. I444AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants,
  7146. width);
  7147. if (attenuate) {
  7148. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7149. }
  7150. dst_argb += dst_stride_argb;
  7151. src_y += src_stride_y;
  7152. src_u += src_stride_u;
  7153. src_v += src_stride_v;
  7154. src_a += src_stride_a;
  7155. }
  7156. if (!(height & 1)) {
  7157. ScaleRowUp2_Linear(src_u, temp_u_1, width);
  7158. ScaleRowUp2_Linear(src_v, temp_v_1, width);
  7159. I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7160. width);
  7161. if (attenuate) {
  7162. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7163. }
  7164. }
  7165. free_aligned_buffer_64(row);
  7166. return 0;
  7167. }
  7168. static int I422AlphaToARGBMatrixLinear(const uint8_t* src_y,
  7169. int src_stride_y,
  7170. const uint8_t* src_u,
  7171. int src_stride_u,
  7172. const uint8_t* src_v,
  7173. int src_stride_v,
  7174. const uint8_t* src_a,
  7175. int src_stride_a,
  7176. uint8_t* dst_argb,
  7177. int dst_stride_argb,
  7178. const struct YuvConstants* yuvconstants,
  7179. int width,
  7180. int height,
  7181. int attenuate) {
  7182. int y;
  7183. void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  7184. const uint8_t* v_buf, const uint8_t* a_buf,
  7185. uint8_t* dst_argb,
  7186. const struct YuvConstants* yuvconstants,
  7187. int width) = I444AlphaToARGBRow_C;
  7188. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  7189. int width) = ARGBAttenuateRow_C;
  7190. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  7191. int dst_width) = ScaleRowUp2_Linear_Any_C;
  7192. assert(yuvconstants);
  7193. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  7194. height == 0) {
  7195. return -1;
  7196. }
  7197. // Negative height means invert the image.
  7198. if (height < 0) {
  7199. height = -height;
  7200. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  7201. dst_stride_argb = -dst_stride_argb;
  7202. }
  7203. #if defined(HAS_I444ALPHATOARGBROW_SSSE3)
  7204. if (TestCpuFlag(kCpuHasSSSE3)) {
  7205. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3;
  7206. if (IS_ALIGNED(width, 8)) {
  7207. I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3;
  7208. }
  7209. }
  7210. #endif
  7211. #if defined(HAS_I444ALPHATOARGBROW_AVX2)
  7212. if (TestCpuFlag(kCpuHasAVX2)) {
  7213. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2;
  7214. if (IS_ALIGNED(width, 16)) {
  7215. I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2;
  7216. }
  7217. }
  7218. #endif
  7219. #if defined(HAS_I444ALPHATOARGBROW_NEON)
  7220. if (TestCpuFlag(kCpuHasNEON)) {
  7221. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON;
  7222. if (IS_ALIGNED(width, 8)) {
  7223. I444AlphaToARGBRow = I444AlphaToARGBRow_NEON;
  7224. }
  7225. }
  7226. #endif
  7227. #if defined(HAS_I444ALPHATOARGBROW_SVE2)
  7228. if (TestCpuFlag(kCpuHasSVE2)) {
  7229. I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2;
  7230. }
  7231. #endif
  7232. #if defined(HAS_I444ALPHATOARGBROW_MSA)
  7233. if (TestCpuFlag(kCpuHasMSA)) {
  7234. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_MSA;
  7235. if (IS_ALIGNED(width, 8)) {
  7236. I444AlphaToARGBRow = I444AlphaToARGBRow_MSA;
  7237. }
  7238. }
  7239. #endif
  7240. #if defined(HAS_I444ALPHATOARGBROW_LASX)
  7241. if (TestCpuFlag(kCpuHasLASX)) {
  7242. I444AlphaToARGBRow = I444AlphaToARGBRow_Any_LASX;
  7243. if (IS_ALIGNED(width, 16)) {
  7244. I444AlphaToARGBRow = I444AlphaToARGBRow_LASX;
  7245. }
  7246. }
  7247. #endif
  7248. #if defined(HAS_I444ALPHATOARGBROW_RVV)
  7249. if (TestCpuFlag(kCpuHasRVV)) {
  7250. I444AlphaToARGBRow = I444AlphaToARGBRow_RVV;
  7251. }
  7252. #endif
  7253. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  7254. if (TestCpuFlag(kCpuHasSSSE3)) {
  7255. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  7256. if (IS_ALIGNED(width, 4)) {
  7257. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  7258. }
  7259. }
  7260. #endif
  7261. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  7262. if (TestCpuFlag(kCpuHasAVX2)) {
  7263. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  7264. if (IS_ALIGNED(width, 8)) {
  7265. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  7266. }
  7267. }
  7268. #endif
  7269. #if defined(HAS_ARGBATTENUATEROW_NEON)
  7270. if (TestCpuFlag(kCpuHasNEON)) {
  7271. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  7272. if (IS_ALIGNED(width, 8)) {
  7273. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  7274. }
  7275. }
  7276. #endif
  7277. #if defined(HAS_ARGBATTENUATEROW_MSA)
  7278. if (TestCpuFlag(kCpuHasMSA)) {
  7279. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  7280. if (IS_ALIGNED(width, 8)) {
  7281. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  7282. }
  7283. }
  7284. #endif
  7285. #if defined(HAS_ARGBATTENUATEROW_RVV)
  7286. if (TestCpuFlag(kCpuHasRVV)) {
  7287. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  7288. }
  7289. #endif
  7290. #if defined(HAS_SCALEROWUP2_LINEAR_SSE2)
  7291. if (TestCpuFlag(kCpuHasSSE2)) {
  7292. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  7293. }
  7294. #endif
  7295. #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3)
  7296. if (TestCpuFlag(kCpuHasSSSE3)) {
  7297. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  7298. }
  7299. #endif
  7300. #if defined(HAS_SCALEROWUP2_LINEAR_AVX2)
  7301. if (TestCpuFlag(kCpuHasAVX2)) {
  7302. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  7303. }
  7304. #endif
  7305. #if defined(HAS_SCALEROWUP2_LINEAR_NEON)
  7306. if (TestCpuFlag(kCpuHasNEON)) {
  7307. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  7308. }
  7309. #endif
  7310. #if defined(HAS_SCALEROWUP2_LINEAR_RVV)
  7311. if (TestCpuFlag(kCpuHasRVV)) {
  7312. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  7313. }
  7314. #endif
  7315. // alloc 2 lines temp
  7316. const int row_size = (width + 31) & ~31;
  7317. align_buffer_64(row, row_size * 2);
  7318. uint8_t* temp_u = row;
  7319. uint8_t* temp_v = row + row_size;
  7320. if (!row)
  7321. return 1;
  7322. for (y = 0; y < height; ++y) {
  7323. ScaleRowUp2_Linear(src_u, temp_u, width);
  7324. ScaleRowUp2_Linear(src_v, temp_v, width);
  7325. I444AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants,
  7326. width);
  7327. if (attenuate) {
  7328. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7329. }
  7330. dst_argb += dst_stride_argb;
  7331. src_a += src_stride_a;
  7332. src_y += src_stride_y;
  7333. src_u += src_stride_u;
  7334. src_v += src_stride_v;
  7335. }
  7336. free_aligned_buffer_64(row);
  7337. return 0;
  7338. }
  7339. static int I010AlphaToARGBMatrixBilinear(
  7340. const uint16_t* src_y,
  7341. int src_stride_y,
  7342. const uint16_t* src_u,
  7343. int src_stride_u,
  7344. const uint16_t* src_v,
  7345. int src_stride_v,
  7346. const uint16_t* src_a,
  7347. int src_stride_a,
  7348. uint8_t* dst_argb,
  7349. int dst_stride_argb,
  7350. const struct YuvConstants* yuvconstants,
  7351. int width,
  7352. int height,
  7353. int attenuate) {
  7354. int y;
  7355. void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  7356. const uint16_t* v_buf, const uint16_t* a_buf,
  7357. uint8_t* dst_argb,
  7358. const struct YuvConstants* yuvconstants,
  7359. int width) = I410AlphaToARGBRow_C;
  7360. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  7361. int width) = ARGBAttenuateRow_C;
  7362. void (*Scale2RowUp_Bilinear_12)(
  7363. const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr,
  7364. ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C;
  7365. void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  7366. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  7367. assert(yuvconstants);
  7368. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  7369. height == 0) {
  7370. return -1;
  7371. }
  7372. // Negative height means invert the image.
  7373. if (height < 0) {
  7374. height = -height;
  7375. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  7376. dst_stride_argb = -dst_stride_argb;
  7377. }
  7378. #if defined(HAS_I410ALPHATOARGBROW_NEON)
  7379. if (TestCpuFlag(kCpuHasNEON)) {
  7380. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON;
  7381. if (IS_ALIGNED(width, 8)) {
  7382. I410AlphaToARGBRow = I410AlphaToARGBRow_NEON;
  7383. }
  7384. }
  7385. #endif
  7386. #if defined(HAS_I410ALPHATOARGBROW_SSSE3)
  7387. if (TestCpuFlag(kCpuHasSSSE3)) {
  7388. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3;
  7389. if (IS_ALIGNED(width, 8)) {
  7390. I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3;
  7391. }
  7392. }
  7393. #endif
  7394. #if defined(HAS_I410ALPHATOARGBROW_AVX2)
  7395. if (TestCpuFlag(kCpuHasAVX2)) {
  7396. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2;
  7397. if (IS_ALIGNED(width, 16)) {
  7398. I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2;
  7399. }
  7400. }
  7401. #endif
  7402. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  7403. if (TestCpuFlag(kCpuHasSSSE3)) {
  7404. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  7405. if (IS_ALIGNED(width, 4)) {
  7406. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  7407. }
  7408. }
  7409. #endif
  7410. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  7411. if (TestCpuFlag(kCpuHasAVX2)) {
  7412. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  7413. if (IS_ALIGNED(width, 8)) {
  7414. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  7415. }
  7416. }
  7417. #endif
  7418. #if defined(HAS_ARGBATTENUATEROW_NEON)
  7419. if (TestCpuFlag(kCpuHasNEON)) {
  7420. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  7421. if (IS_ALIGNED(width, 8)) {
  7422. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  7423. }
  7424. }
  7425. #endif
  7426. #if defined(HAS_ARGBATTENUATEROW_MSA)
  7427. if (TestCpuFlag(kCpuHasMSA)) {
  7428. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  7429. if (IS_ALIGNED(width, 8)) {
  7430. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  7431. }
  7432. }
  7433. #endif
  7434. #if defined(HAS_ARGBATTENUATEROW_RVV)
  7435. if (TestCpuFlag(kCpuHasRVV)) {
  7436. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  7437. }
  7438. #endif
  7439. #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3)
  7440. if (TestCpuFlag(kCpuHasSSSE3)) {
  7441. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3;
  7442. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3;
  7443. }
  7444. #endif
  7445. #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2)
  7446. if (TestCpuFlag(kCpuHasAVX2)) {
  7447. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2;
  7448. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2;
  7449. }
  7450. #endif
  7451. #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON)
  7452. if (TestCpuFlag(kCpuHasNEON)) {
  7453. Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON;
  7454. ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON;
  7455. }
  7456. #endif
  7457. // alloc 4 lines temp
  7458. const int row_size = (width + 31) & ~31;
  7459. align_buffer_64(row, row_size * 4 * sizeof(uint16_t));
  7460. uint16_t* temp_u_1 = (uint16_t*)(row);
  7461. uint16_t* temp_u_2 = (uint16_t*)(row) + row_size;
  7462. uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2;
  7463. uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3;
  7464. if (!row)
  7465. return 1;
  7466. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  7467. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  7468. I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7469. width);
  7470. if (attenuate) {
  7471. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7472. }
  7473. dst_argb += dst_stride_argb;
  7474. src_y += src_stride_y;
  7475. src_a += src_stride_a;
  7476. for (y = 0; y < height - 2; y += 2) {
  7477. Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width);
  7478. Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width);
  7479. I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7480. width);
  7481. if (attenuate) {
  7482. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7483. }
  7484. dst_argb += dst_stride_argb;
  7485. src_y += src_stride_y;
  7486. src_a += src_stride_a;
  7487. I410AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants,
  7488. width);
  7489. if (attenuate) {
  7490. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7491. }
  7492. dst_argb += dst_stride_argb;
  7493. src_y += src_stride_y;
  7494. src_a += src_stride_a;
  7495. src_u += src_stride_u;
  7496. src_v += src_stride_v;
  7497. }
  7498. if (!(height & 1)) {
  7499. ScaleRowUp2_Linear_12(src_u, temp_u_1, width);
  7500. ScaleRowUp2_Linear_12(src_v, temp_v_1, width);
  7501. I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants,
  7502. width);
  7503. if (attenuate) {
  7504. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7505. }
  7506. }
  7507. free_aligned_buffer_64(row);
  7508. return 0;
  7509. }
  7510. static int I210AlphaToARGBMatrixLinear(const uint16_t* src_y,
  7511. int src_stride_y,
  7512. const uint16_t* src_u,
  7513. int src_stride_u,
  7514. const uint16_t* src_v,
  7515. int src_stride_v,
  7516. const uint16_t* src_a,
  7517. int src_stride_a,
  7518. uint8_t* dst_argb,
  7519. int dst_stride_argb,
  7520. const struct YuvConstants* yuvconstants,
  7521. int width,
  7522. int height,
  7523. int attenuate) {
  7524. int y;
  7525. void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  7526. const uint16_t* v_buf, const uint16_t* a_buf,
  7527. uint8_t* dst_argb,
  7528. const struct YuvConstants* yuvconstants,
  7529. int width) = I410AlphaToARGBRow_C;
  7530. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  7531. int width) = ARGBAttenuateRow_C;
  7532. void (*ScaleRowUp2_Linear)(const uint16_t* src_ptr, uint16_t* dst_ptr,
  7533. int dst_width) = ScaleRowUp2_Linear_16_Any_C;
  7534. assert(yuvconstants);
  7535. if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 ||
  7536. height == 0) {
  7537. return -1;
  7538. }
  7539. // Negative height means invert the image.
  7540. if (height < 0) {
  7541. height = -height;
  7542. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  7543. dst_stride_argb = -dst_stride_argb;
  7544. }
  7545. #if defined(HAS_I410ALPHATOARGBROW_NEON)
  7546. if (TestCpuFlag(kCpuHasNEON)) {
  7547. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON;
  7548. if (IS_ALIGNED(width, 8)) {
  7549. I410AlphaToARGBRow = I410AlphaToARGBRow_NEON;
  7550. }
  7551. }
  7552. #endif
  7553. #if defined(HAS_I410ALPHATOARGBROW_SSSE3)
  7554. if (TestCpuFlag(kCpuHasSSSE3)) {
  7555. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3;
  7556. if (IS_ALIGNED(width, 8)) {
  7557. I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3;
  7558. }
  7559. }
  7560. #endif
  7561. #if defined(HAS_I410ALPHATOARGBROW_AVX2)
  7562. if (TestCpuFlag(kCpuHasAVX2)) {
  7563. I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2;
  7564. if (IS_ALIGNED(width, 16)) {
  7565. I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2;
  7566. }
  7567. }
  7568. #endif
  7569. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  7570. if (TestCpuFlag(kCpuHasSSSE3)) {
  7571. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  7572. if (IS_ALIGNED(width, 4)) {
  7573. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  7574. }
  7575. }
  7576. #endif
  7577. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  7578. if (TestCpuFlag(kCpuHasAVX2)) {
  7579. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  7580. if (IS_ALIGNED(width, 8)) {
  7581. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  7582. }
  7583. }
  7584. #endif
  7585. #if defined(HAS_ARGBATTENUATEROW_NEON)
  7586. if (TestCpuFlag(kCpuHasNEON)) {
  7587. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  7588. if (IS_ALIGNED(width, 8)) {
  7589. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  7590. }
  7591. }
  7592. #endif
  7593. #if defined(HAS_ARGBATTENUATEROW_MSA)
  7594. if (TestCpuFlag(kCpuHasMSA)) {
  7595. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  7596. if (IS_ALIGNED(width, 8)) {
  7597. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  7598. }
  7599. }
  7600. #endif
  7601. #if defined(HAS_ARGBATTENUATEROW_RVV)
  7602. if (TestCpuFlag(kCpuHasRVV)) {
  7603. ARGBAttenuateRow = ARGBAttenuateRow_RVV;
  7604. }
  7605. #endif
  7606. #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3)
  7607. if (TestCpuFlag(kCpuHasSSSE3)) {
  7608. ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_SSSE3;
  7609. }
  7610. #endif
  7611. #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2)
  7612. if (TestCpuFlag(kCpuHasAVX2)) {
  7613. ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_AVX2;
  7614. }
  7615. #endif
  7616. #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON)
  7617. if (TestCpuFlag(kCpuHasNEON)) {
  7618. ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_NEON;
  7619. }
  7620. #endif
  7621. // alloc 2 lines temp
  7622. const int row_size = (width + 31) & ~31;
  7623. align_buffer_64(row, row_size * 2 * sizeof(uint16_t));
  7624. uint16_t* temp_u = (uint16_t*)(row);
  7625. uint16_t* temp_v = (uint16_t*)(row) + row_size;
  7626. if (!row)
  7627. return 1;
  7628. for (y = 0; y < height; ++y) {
  7629. ScaleRowUp2_Linear(src_u, temp_u, width);
  7630. ScaleRowUp2_Linear(src_v, temp_v, width);
  7631. I410AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants,
  7632. width);
  7633. if (attenuate) {
  7634. ARGBAttenuateRow(dst_argb, dst_argb, width);
  7635. }
  7636. dst_argb += dst_stride_argb;
  7637. src_a += src_stride_a;
  7638. src_y += src_stride_y;
  7639. src_u += src_stride_u;
  7640. src_v += src_stride_v;
  7641. }
  7642. free_aligned_buffer_64(row);
  7643. return 0;
  7644. }
  7645. static int P010ToARGBMatrixBilinear(const uint16_t* src_y,
  7646. int src_stride_y,
  7647. const uint16_t* src_uv,
  7648. int src_stride_uv,
  7649. uint8_t* dst_argb,
  7650. int dst_stride_argb,
  7651. const struct YuvConstants* yuvconstants,
  7652. int width,
  7653. int height) {
  7654. int y;
  7655. void (*P410ToARGBRow)(
  7656. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  7657. const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C;
  7658. void (*Scale2RowUp_Bilinear_16)(
  7659. const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr,
  7660. ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C;
  7661. assert(yuvconstants);
  7662. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  7663. return -1;
  7664. }
  7665. // Negative height means invert the image.
  7666. if (height < 0) {
  7667. height = -height;
  7668. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  7669. dst_stride_argb = -dst_stride_argb;
  7670. }
  7671. #if defined(HAS_P410TOARGBROW_SSSE3)
  7672. if (TestCpuFlag(kCpuHasSSSE3)) {
  7673. P410ToARGBRow = P410ToARGBRow_Any_SSSE3;
  7674. if (IS_ALIGNED(width, 8)) {
  7675. P410ToARGBRow = P410ToARGBRow_SSSE3;
  7676. }
  7677. }
  7678. #endif
  7679. #if defined(HAS_P410TOARGBROW_AVX2)
  7680. if (TestCpuFlag(kCpuHasAVX2)) {
  7681. P410ToARGBRow = P410ToARGBRow_Any_AVX2;
  7682. if (IS_ALIGNED(width, 16)) {
  7683. P410ToARGBRow = P410ToARGBRow_AVX2;
  7684. }
  7685. }
  7686. #endif
  7687. #if defined(HAS_P410TOARGBROW_NEON)
  7688. if (TestCpuFlag(kCpuHasNEON)) {
  7689. P410ToARGBRow = P410ToARGBRow_Any_NEON;
  7690. if (IS_ALIGNED(width, 8)) {
  7691. P410ToARGBRow = P410ToARGBRow_NEON;
  7692. }
  7693. }
  7694. #endif
  7695. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41
  7696. if (TestCpuFlag(kCpuHasSSE41)) {
  7697. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41;
  7698. }
  7699. #endif
  7700. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2
  7701. if (TestCpuFlag(kCpuHasAVX2)) {
  7702. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2;
  7703. }
  7704. #endif
  7705. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON
  7706. if (TestCpuFlag(kCpuHasNEON)) {
  7707. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON;
  7708. }
  7709. #endif
  7710. // alloc 2 lines temp
  7711. const int row_size = (2 * width + 31) & ~31;
  7712. align_buffer_64(row, row_size * 2 * sizeof(uint16_t));
  7713. uint16_t* temp_uv_1 = (uint16_t*)(row);
  7714. uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size;
  7715. if (!row)
  7716. return 1;
  7717. Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width);
  7718. P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width);
  7719. dst_argb += dst_stride_argb;
  7720. src_y += src_stride_y;
  7721. for (y = 0; y < height - 2; y += 2) {
  7722. Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width);
  7723. P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width);
  7724. dst_argb += dst_stride_argb;
  7725. src_y += src_stride_y;
  7726. P410ToARGBRow(src_y, temp_uv_2, dst_argb, yuvconstants, width);
  7727. dst_argb += dst_stride_argb;
  7728. src_y += src_stride_y;
  7729. src_uv += src_stride_uv;
  7730. }
  7731. if (!(height & 1)) {
  7732. Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width);
  7733. P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width);
  7734. }
  7735. free_aligned_buffer_64(row);
  7736. return 0;
  7737. }
  7738. static int P210ToARGBMatrixLinear(const uint16_t* src_y,
  7739. int src_stride_y,
  7740. const uint16_t* src_uv,
  7741. int src_stride_uv,
  7742. uint8_t* dst_argb,
  7743. int dst_stride_argb,
  7744. const struct YuvConstants* yuvconstants,
  7745. int width,
  7746. int height) {
  7747. int y;
  7748. void (*P410ToARGBRow)(
  7749. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  7750. const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C;
  7751. void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv,
  7752. int dst_width) = ScaleUVRowUp2_Linear_16_Any_C;
  7753. assert(yuvconstants);
  7754. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  7755. return -1;
  7756. }
  7757. // Negative height means invert the image.
  7758. if (height < 0) {
  7759. height = -height;
  7760. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  7761. dst_stride_argb = -dst_stride_argb;
  7762. }
  7763. #if defined(HAS_P410TOARGBROW_SSSE3)
  7764. if (TestCpuFlag(kCpuHasSSSE3)) {
  7765. P410ToARGBRow = P410ToARGBRow_Any_SSSE3;
  7766. if (IS_ALIGNED(width, 8)) {
  7767. P410ToARGBRow = P410ToARGBRow_SSSE3;
  7768. }
  7769. }
  7770. #endif
  7771. #if defined(HAS_P410TOARGBROW_AVX2)
  7772. if (TestCpuFlag(kCpuHasAVX2)) {
  7773. P410ToARGBRow = P410ToARGBRow_Any_AVX2;
  7774. if (IS_ALIGNED(width, 16)) {
  7775. P410ToARGBRow = P410ToARGBRow_AVX2;
  7776. }
  7777. }
  7778. #endif
  7779. #if defined(HAS_P410TOARGBROW_NEON)
  7780. if (TestCpuFlag(kCpuHasNEON)) {
  7781. P410ToARGBRow = P410ToARGBRow_Any_NEON;
  7782. if (IS_ALIGNED(width, 8)) {
  7783. P410ToARGBRow = P410ToARGBRow_NEON;
  7784. }
  7785. }
  7786. #endif
  7787. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41
  7788. if (TestCpuFlag(kCpuHasSSE41)) {
  7789. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41;
  7790. }
  7791. #endif
  7792. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2
  7793. if (TestCpuFlag(kCpuHasAVX2)) {
  7794. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2;
  7795. }
  7796. #endif
  7797. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON
  7798. if (TestCpuFlag(kCpuHasNEON)) {
  7799. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON;
  7800. }
  7801. #endif
  7802. const int row_size = (2 * width + 31) & ~31;
  7803. align_buffer_64(row, row_size * sizeof(uint16_t));
  7804. uint16_t* temp_uv = (uint16_t*)(row);
  7805. if (!row)
  7806. return 1;
  7807. for (y = 0; y < height; ++y) {
  7808. ScaleRowUp2_Linear(src_uv, temp_uv, width);
  7809. P410ToARGBRow(src_y, temp_uv, dst_argb, yuvconstants, width);
  7810. dst_argb += dst_stride_argb;
  7811. src_y += src_stride_y;
  7812. src_uv += src_stride_uv;
  7813. }
  7814. free_aligned_buffer_64(row);
  7815. return 0;
  7816. }
  7817. static int P010ToAR30MatrixBilinear(const uint16_t* src_y,
  7818. int src_stride_y,
  7819. const uint16_t* src_uv,
  7820. int src_stride_uv,
  7821. uint8_t* dst_ar30,
  7822. int dst_stride_ar30,
  7823. const struct YuvConstants* yuvconstants,
  7824. int width,
  7825. int height) {
  7826. int y;
  7827. void (*P410ToAR30Row)(
  7828. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  7829. const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C;
  7830. void (*Scale2RowUp_Bilinear_16)(
  7831. const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr,
  7832. ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C;
  7833. assert(yuvconstants);
  7834. if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) {
  7835. return -1;
  7836. }
  7837. // Negative height means invert the image.
  7838. if (height < 0) {
  7839. height = -height;
  7840. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  7841. dst_stride_ar30 = -dst_stride_ar30;
  7842. }
  7843. #if defined(HAS_P410TOAR30ROW_SSSE3)
  7844. if (TestCpuFlag(kCpuHasSSSE3)) {
  7845. P410ToAR30Row = P410ToAR30Row_Any_SSSE3;
  7846. if (IS_ALIGNED(width, 8)) {
  7847. P410ToAR30Row = P410ToAR30Row_SSSE3;
  7848. }
  7849. }
  7850. #endif
  7851. #if defined(HAS_P410TOAR30ROW_AVX2)
  7852. if (TestCpuFlag(kCpuHasAVX2)) {
  7853. P410ToAR30Row = P410ToAR30Row_Any_AVX2;
  7854. if (IS_ALIGNED(width, 16)) {
  7855. P410ToAR30Row = P410ToAR30Row_AVX2;
  7856. }
  7857. }
  7858. #endif
  7859. #if defined(HAS_P410TOAR30ROW_NEON)
  7860. if (TestCpuFlag(kCpuHasNEON)) {
  7861. P410ToAR30Row = P410ToAR30Row_Any_NEON;
  7862. if (IS_ALIGNED(width, 8)) {
  7863. P410ToAR30Row = P410ToAR30Row_NEON;
  7864. }
  7865. }
  7866. #endif
  7867. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41
  7868. if (TestCpuFlag(kCpuHasSSE41)) {
  7869. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41;
  7870. }
  7871. #endif
  7872. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2
  7873. if (TestCpuFlag(kCpuHasAVX2)) {
  7874. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2;
  7875. }
  7876. #endif
  7877. #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON
  7878. if (TestCpuFlag(kCpuHasNEON)) {
  7879. Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON;
  7880. }
  7881. #endif
  7882. // alloc 2 lines temp
  7883. const int row_size = (2 * width + 31) & ~31;
  7884. align_buffer_64(row, row_size * 2 * sizeof(uint16_t));
  7885. uint16_t* temp_uv_1 = (uint16_t*)(row);
  7886. uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size;
  7887. if (!row)
  7888. return 1;
  7889. Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width);
  7890. P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width);
  7891. dst_ar30 += dst_stride_ar30;
  7892. src_y += src_stride_y;
  7893. for (y = 0; y < height - 2; y += 2) {
  7894. Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width);
  7895. P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width);
  7896. dst_ar30 += dst_stride_ar30;
  7897. src_y += src_stride_y;
  7898. P410ToAR30Row(src_y, temp_uv_2, dst_ar30, yuvconstants, width);
  7899. dst_ar30 += dst_stride_ar30;
  7900. src_y += src_stride_y;
  7901. src_uv += src_stride_uv;
  7902. }
  7903. if (!(height & 1)) {
  7904. Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width);
  7905. P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width);
  7906. }
  7907. free_aligned_buffer_64(row);
  7908. return 0;
  7909. }
  7910. static int P210ToAR30MatrixLinear(const uint16_t* src_y,
  7911. int src_stride_y,
  7912. const uint16_t* src_uv,
  7913. int src_stride_uv,
  7914. uint8_t* dst_ar30,
  7915. int dst_stride_ar30,
  7916. const struct YuvConstants* yuvconstants,
  7917. int width,
  7918. int height) {
  7919. int y;
  7920. void (*P410ToAR30Row)(
  7921. const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf,
  7922. const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C;
  7923. void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv,
  7924. int dst_width) = ScaleUVRowUp2_Linear_16_Any_C;
  7925. assert(yuvconstants);
  7926. if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) {
  7927. return -1;
  7928. }
  7929. // Negative height means invert the image.
  7930. if (height < 0) {
  7931. height = -height;
  7932. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  7933. dst_stride_ar30 = -dst_stride_ar30;
  7934. }
  7935. #if defined(HAS_P410TOAR30ROW_SSSE3)
  7936. if (TestCpuFlag(kCpuHasSSSE3)) {
  7937. P410ToAR30Row = P410ToAR30Row_Any_SSSE3;
  7938. if (IS_ALIGNED(width, 8)) {
  7939. P410ToAR30Row = P410ToAR30Row_SSSE3;
  7940. }
  7941. }
  7942. #endif
  7943. #if defined(HAS_P410TOAR30ROW_AVX2)
  7944. if (TestCpuFlag(kCpuHasAVX2)) {
  7945. P410ToAR30Row = P410ToAR30Row_Any_AVX2;
  7946. if (IS_ALIGNED(width, 16)) {
  7947. P410ToAR30Row = P410ToAR30Row_AVX2;
  7948. }
  7949. }
  7950. #endif
  7951. #if defined(HAS_P410TOAR30ROW_NEON)
  7952. if (TestCpuFlag(kCpuHasNEON)) {
  7953. P410ToAR30Row = P410ToAR30Row_Any_NEON;
  7954. if (IS_ALIGNED(width, 8)) {
  7955. P410ToAR30Row = P410ToAR30Row_NEON;
  7956. }
  7957. }
  7958. #endif
  7959. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41
  7960. if (TestCpuFlag(kCpuHasSSE41)) {
  7961. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41;
  7962. }
  7963. #endif
  7964. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2
  7965. if (TestCpuFlag(kCpuHasAVX2)) {
  7966. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2;
  7967. }
  7968. #endif
  7969. #ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON
  7970. if (TestCpuFlag(kCpuHasNEON)) {
  7971. ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON;
  7972. }
  7973. #endif
  7974. const int row_size = (2 * width + 31) & ~31;
  7975. align_buffer_64(row, row_size * sizeof(uint16_t));
  7976. uint16_t* temp_uv = (uint16_t*)(row);
  7977. if (!row)
  7978. return 1;
  7979. for (y = 0; y < height; ++y) {
  7980. ScaleRowUp2_Linear(src_uv, temp_uv, width);
  7981. P410ToAR30Row(src_y, temp_uv, dst_ar30, yuvconstants, width);
  7982. dst_ar30 += dst_stride_ar30;
  7983. src_y += src_stride_y;
  7984. src_uv += src_stride_uv;
  7985. }
  7986. free_aligned_buffer_64(row);
  7987. return 0;
  7988. }
  7989. static int I422ToRGB24MatrixLinear(const uint8_t* src_y,
  7990. int src_stride_y,
  7991. const uint8_t* src_u,
  7992. int src_stride_u,
  7993. const uint8_t* src_v,
  7994. int src_stride_v,
  7995. uint8_t* dst_rgb24,
  7996. int dst_stride_rgb24,
  7997. const struct YuvConstants* yuvconstants,
  7998. int width,
  7999. int height) {
  8000. int y;
  8001. void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  8002. const uint8_t* v_buf, uint8_t* rgb_buf,
  8003. const struct YuvConstants* yuvconstants, int width) =
  8004. I444ToRGB24Row_C;
  8005. void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr,
  8006. int dst_width) = ScaleRowUp2_Linear_Any_C;
  8007. assert(yuvconstants);
  8008. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  8009. return -1;
  8010. }
  8011. // Negative height means invert the image.
  8012. if (height < 0) {
  8013. height = -height;
  8014. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  8015. dst_stride_rgb24 = -dst_stride_rgb24;
  8016. }
  8017. #if defined(HAS_I444TORGB24ROW_SSSE3)
  8018. if (TestCpuFlag(kCpuHasSSSE3)) {
  8019. I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3;
  8020. if (IS_ALIGNED(width, 16)) {
  8021. I444ToRGB24Row = I444ToRGB24Row_SSSE3;
  8022. }
  8023. }
  8024. #endif
  8025. #if defined(HAS_I444TORGB24ROW_AVX2)
  8026. if (TestCpuFlag(kCpuHasAVX2)) {
  8027. I444ToRGB24Row = I444ToRGB24Row_Any_AVX2;
  8028. if (IS_ALIGNED(width, 32)) {
  8029. I444ToRGB24Row = I444ToRGB24Row_AVX2;
  8030. }
  8031. }
  8032. #endif
  8033. #if defined(HAS_I444TORGB24ROW_NEON)
  8034. if (TestCpuFlag(kCpuHasNEON)) {
  8035. I444ToRGB24Row = I444ToRGB24Row_Any_NEON;
  8036. if (IS_ALIGNED(width, 8)) {
  8037. I444ToRGB24Row = I444ToRGB24Row_NEON;
  8038. }
  8039. }
  8040. #endif
  8041. #if defined(HAS_I444TORGB24ROW_RVV)
  8042. if (TestCpuFlag(kCpuHasRVV)) {
  8043. I444ToRGB24Row = I444ToRGB24Row_RVV;
  8044. }
  8045. #endif
  8046. #if defined(HAS_SCALEROWUP2_LINEAR_SSE2)
  8047. if (TestCpuFlag(kCpuHasSSE2)) {
  8048. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2;
  8049. }
  8050. #endif
  8051. #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3)
  8052. if (TestCpuFlag(kCpuHasSSSE3)) {
  8053. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3;
  8054. }
  8055. #endif
  8056. #if defined(HAS_SCALEROWUP2_LINEAR_AVX2)
  8057. if (TestCpuFlag(kCpuHasAVX2)) {
  8058. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2;
  8059. }
  8060. #endif
  8061. #if defined(HAS_SCALEROWUP2_LINEAR_NEON)
  8062. if (TestCpuFlag(kCpuHasNEON)) {
  8063. ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON;
  8064. }
  8065. #endif
  8066. #if defined(HAS_SCALEROWUP2_LINEAR_RVV)
  8067. if (TestCpuFlag(kCpuHasRVV)) {
  8068. ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV;
  8069. }
  8070. #endif
  8071. // alloc 2 lines temp
  8072. const int row_size = (width + 31) & ~31;
  8073. align_buffer_64(row, row_size * 2);
  8074. uint8_t* temp_u = row;
  8075. uint8_t* temp_v = row + row_size;
  8076. if (!row)
  8077. return 1;
  8078. for (y = 0; y < height; ++y) {
  8079. ScaleRowUp2_Linear(src_u, temp_u, width);
  8080. ScaleRowUp2_Linear(src_v, temp_v, width);
  8081. I444ToRGB24Row(src_y, temp_u, temp_v, dst_rgb24, yuvconstants, width);
  8082. dst_rgb24 += dst_stride_rgb24;
  8083. src_y += src_stride_y;
  8084. src_u += src_stride_u;
  8085. src_v += src_stride_v;
  8086. }
  8087. free_aligned_buffer_64(row);
  8088. return 0;
  8089. }
  8090. LIBYUV_API
  8091. int I422ToRGB24MatrixFilter(const uint8_t* src_y,
  8092. int src_stride_y,
  8093. const uint8_t* src_u,
  8094. int src_stride_u,
  8095. const uint8_t* src_v,
  8096. int src_stride_v,
  8097. uint8_t* dst_rgb24,
  8098. int dst_stride_rgb24,
  8099. const struct YuvConstants* yuvconstants,
  8100. int width,
  8101. int height,
  8102. enum FilterMode filter) {
  8103. switch (filter) {
  8104. case kFilterNone:
  8105. return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8106. src_stride_v, dst_rgb24, dst_stride_rgb24,
  8107. yuvconstants, width, height);
  8108. case kFilterBilinear:
  8109. case kFilterBox:
  8110. case kFilterLinear:
  8111. return I422ToRGB24MatrixLinear(
  8112. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8113. dst_rgb24, dst_stride_rgb24, yuvconstants, width, height);
  8114. }
  8115. return -1;
  8116. }
  8117. LIBYUV_API
  8118. int I420ToARGBMatrixFilter(const uint8_t* src_y,
  8119. int src_stride_y,
  8120. const uint8_t* src_u,
  8121. int src_stride_u,
  8122. const uint8_t* src_v,
  8123. int src_stride_v,
  8124. uint8_t* dst_argb,
  8125. int dst_stride_argb,
  8126. const struct YuvConstants* yuvconstants,
  8127. int width,
  8128. int height,
  8129. enum FilterMode filter) {
  8130. switch (filter) {
  8131. case kFilterNone:
  8132. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8133. src_stride_v, dst_argb, dst_stride_argb,
  8134. yuvconstants, width, height);
  8135. case kFilterBilinear:
  8136. case kFilterBox:
  8137. return I420ToARGBMatrixBilinear(
  8138. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8139. dst_argb, dst_stride_argb, yuvconstants, width, height);
  8140. case kFilterLinear:
  8141. // Actually we can do this, but probably there's no usage.
  8142. return -1;
  8143. }
  8144. return -1;
  8145. }
  8146. LIBYUV_API
  8147. int I422ToARGBMatrixFilter(const uint8_t* src_y,
  8148. int src_stride_y,
  8149. const uint8_t* src_u,
  8150. int src_stride_u,
  8151. const uint8_t* src_v,
  8152. int src_stride_v,
  8153. uint8_t* dst_argb,
  8154. int dst_stride_argb,
  8155. const struct YuvConstants* yuvconstants,
  8156. int width,
  8157. int height,
  8158. enum FilterMode filter) {
  8159. switch (filter) {
  8160. case kFilterNone:
  8161. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8162. src_stride_v, dst_argb, dst_stride_argb,
  8163. yuvconstants, width, height);
  8164. case kFilterBilinear:
  8165. case kFilterBox:
  8166. case kFilterLinear:
  8167. return I422ToARGBMatrixLinear(
  8168. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8169. dst_argb, dst_stride_argb, yuvconstants, width, height);
  8170. }
  8171. return -1;
  8172. }
  8173. LIBYUV_API
  8174. int I420ToRGB24MatrixFilter(const uint8_t* src_y,
  8175. int src_stride_y,
  8176. const uint8_t* src_u,
  8177. int src_stride_u,
  8178. const uint8_t* src_v,
  8179. int src_stride_v,
  8180. uint8_t* dst_rgb24,
  8181. int dst_stride_rgb24,
  8182. const struct YuvConstants* yuvconstants,
  8183. int width,
  8184. int height,
  8185. enum FilterMode filter) {
  8186. switch (filter) {
  8187. case kFilterNone:
  8188. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8189. src_stride_v, dst_rgb24, dst_stride_rgb24,
  8190. yuvconstants, width, height);
  8191. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8192. case kFilterBilinear:
  8193. case kFilterBox:
  8194. return I420ToRGB24MatrixBilinear(
  8195. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8196. dst_rgb24, dst_stride_rgb24, yuvconstants, width, height);
  8197. }
  8198. return -1;
  8199. }
  8200. LIBYUV_API
  8201. int I010ToAR30MatrixFilter(const uint16_t* src_y,
  8202. int src_stride_y,
  8203. const uint16_t* src_u,
  8204. int src_stride_u,
  8205. const uint16_t* src_v,
  8206. int src_stride_v,
  8207. uint8_t* dst_ar30,
  8208. int dst_stride_ar30,
  8209. const struct YuvConstants* yuvconstants,
  8210. int width,
  8211. int height,
  8212. enum FilterMode filter) {
  8213. switch (filter) {
  8214. case kFilterNone:
  8215. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8216. src_stride_v, dst_ar30, dst_stride_ar30,
  8217. yuvconstants, width, height);
  8218. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8219. case kFilterBilinear:
  8220. case kFilterBox:
  8221. return I010ToAR30MatrixBilinear(
  8222. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8223. dst_ar30, dst_stride_ar30, yuvconstants, width, height);
  8224. }
  8225. return -1;
  8226. }
  8227. LIBYUV_API
  8228. int I210ToAR30MatrixFilter(const uint16_t* src_y,
  8229. int src_stride_y,
  8230. const uint16_t* src_u,
  8231. int src_stride_u,
  8232. const uint16_t* src_v,
  8233. int src_stride_v,
  8234. uint8_t* dst_ar30,
  8235. int dst_stride_ar30,
  8236. const struct YuvConstants* yuvconstants,
  8237. int width,
  8238. int height,
  8239. enum FilterMode filter) {
  8240. switch (filter) {
  8241. case kFilterNone:
  8242. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8243. src_stride_v, dst_ar30, dst_stride_ar30,
  8244. yuvconstants, width, height);
  8245. case kFilterBilinear:
  8246. case kFilterBox:
  8247. case kFilterLinear:
  8248. return I210ToAR30MatrixLinear(
  8249. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8250. dst_ar30, dst_stride_ar30, yuvconstants, width, height);
  8251. }
  8252. return -1;
  8253. }
  8254. LIBYUV_API
  8255. int I010ToARGBMatrixFilter(const uint16_t* src_y,
  8256. int src_stride_y,
  8257. const uint16_t* src_u,
  8258. int src_stride_u,
  8259. const uint16_t* src_v,
  8260. int src_stride_v,
  8261. uint8_t* dst_argb,
  8262. int dst_stride_argb,
  8263. const struct YuvConstants* yuvconstants,
  8264. int width,
  8265. int height,
  8266. enum FilterMode filter) {
  8267. switch (filter) {
  8268. case kFilterNone:
  8269. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8270. src_stride_v, dst_argb, dst_stride_argb,
  8271. yuvconstants, width, height);
  8272. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8273. case kFilterBilinear:
  8274. case kFilterBox:
  8275. return I010ToARGBMatrixBilinear(
  8276. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8277. dst_argb, dst_stride_argb, yuvconstants, width, height);
  8278. }
  8279. return -1;
  8280. }
  8281. LIBYUV_API
  8282. int I210ToARGBMatrixFilter(const uint16_t* src_y,
  8283. int src_stride_y,
  8284. const uint16_t* src_u,
  8285. int src_stride_u,
  8286. const uint16_t* src_v,
  8287. int src_stride_v,
  8288. uint8_t* dst_argb,
  8289. int dst_stride_argb,
  8290. const struct YuvConstants* yuvconstants,
  8291. int width,
  8292. int height,
  8293. enum FilterMode filter) {
  8294. switch (filter) {
  8295. case kFilterNone:
  8296. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  8297. src_stride_v, dst_argb, dst_stride_argb,
  8298. yuvconstants, width, height);
  8299. case kFilterBilinear:
  8300. case kFilterBox:
  8301. case kFilterLinear:
  8302. return I210ToARGBMatrixLinear(
  8303. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
  8304. dst_argb, dst_stride_argb, yuvconstants, width, height);
  8305. }
  8306. return -1;
  8307. }
  8308. LIBYUV_API
  8309. int I420AlphaToARGBMatrixFilter(const uint8_t* src_y,
  8310. int src_stride_y,
  8311. const uint8_t* src_u,
  8312. int src_stride_u,
  8313. const uint8_t* src_v,
  8314. int src_stride_v,
  8315. const uint8_t* src_a,
  8316. int src_stride_a,
  8317. uint8_t* dst_argb,
  8318. int dst_stride_argb,
  8319. const struct YuvConstants* yuvconstants,
  8320. int width,
  8321. int height,
  8322. int attenuate,
  8323. enum FilterMode filter) {
  8324. switch (filter) {
  8325. case kFilterNone:
  8326. return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u,
  8327. src_v, src_stride_v, src_a, src_stride_a,
  8328. dst_argb, dst_stride_argb, yuvconstants,
  8329. width, height, attenuate);
  8330. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8331. case kFilterBilinear:
  8332. case kFilterBox:
  8333. return I420AlphaToARGBMatrixBilinear(
  8334. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a,
  8335. src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height,
  8336. attenuate);
  8337. }
  8338. return -1;
  8339. }
  8340. LIBYUV_API
  8341. int I422AlphaToARGBMatrixFilter(const uint8_t* src_y,
  8342. int src_stride_y,
  8343. const uint8_t* src_u,
  8344. int src_stride_u,
  8345. const uint8_t* src_v,
  8346. int src_stride_v,
  8347. const uint8_t* src_a,
  8348. int src_stride_a,
  8349. uint8_t* dst_argb,
  8350. int dst_stride_argb,
  8351. const struct YuvConstants* yuvconstants,
  8352. int width,
  8353. int height,
  8354. int attenuate,
  8355. enum FilterMode filter) {
  8356. switch (filter) {
  8357. case kFilterNone:
  8358. return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u,
  8359. src_v, src_stride_v, src_a, src_stride_a,
  8360. dst_argb, dst_stride_argb, yuvconstants,
  8361. width, height, attenuate);
  8362. case kFilterBilinear:
  8363. case kFilterBox:
  8364. case kFilterLinear:
  8365. return I422AlphaToARGBMatrixLinear(
  8366. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a,
  8367. src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height,
  8368. attenuate);
  8369. }
  8370. return -1;
  8371. }
  8372. LIBYUV_API
  8373. int I010AlphaToARGBMatrixFilter(const uint16_t* src_y,
  8374. int src_stride_y,
  8375. const uint16_t* src_u,
  8376. int src_stride_u,
  8377. const uint16_t* src_v,
  8378. int src_stride_v,
  8379. const uint16_t* src_a,
  8380. int src_stride_a,
  8381. uint8_t* dst_argb,
  8382. int dst_stride_argb,
  8383. const struct YuvConstants* yuvconstants,
  8384. int width,
  8385. int height,
  8386. int attenuate,
  8387. enum FilterMode filter) {
  8388. switch (filter) {
  8389. case kFilterNone:
  8390. return I010AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u,
  8391. src_v, src_stride_v, src_a, src_stride_a,
  8392. dst_argb, dst_stride_argb, yuvconstants,
  8393. width, height, attenuate);
  8394. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8395. case kFilterBilinear:
  8396. case kFilterBox:
  8397. return I010AlphaToARGBMatrixBilinear(
  8398. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a,
  8399. src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height,
  8400. attenuate);
  8401. }
  8402. return -1;
  8403. }
  8404. LIBYUV_API
  8405. int I210AlphaToARGBMatrixFilter(const uint16_t* src_y,
  8406. int src_stride_y,
  8407. const uint16_t* src_u,
  8408. int src_stride_u,
  8409. const uint16_t* src_v,
  8410. int src_stride_v,
  8411. const uint16_t* src_a,
  8412. int src_stride_a,
  8413. uint8_t* dst_argb,
  8414. int dst_stride_argb,
  8415. const struct YuvConstants* yuvconstants,
  8416. int width,
  8417. int height,
  8418. int attenuate,
  8419. enum FilterMode filter) {
  8420. switch (filter) {
  8421. case kFilterNone:
  8422. return I210AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u,
  8423. src_v, src_stride_v, src_a, src_stride_a,
  8424. dst_argb, dst_stride_argb, yuvconstants,
  8425. width, height, attenuate);
  8426. case kFilterBilinear:
  8427. case kFilterBox:
  8428. case kFilterLinear:
  8429. return I210AlphaToARGBMatrixLinear(
  8430. src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a,
  8431. src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height,
  8432. attenuate);
  8433. }
  8434. return -1;
  8435. }
  8436. // TODO(fb): Verify this function works correctly. P010 is like NV12 but 10 bit
  8437. // UV is biplanar.
  8438. LIBYUV_API
  8439. int P010ToARGBMatrixFilter(const uint16_t* src_y,
  8440. int src_stride_y,
  8441. const uint16_t* src_uv,
  8442. int src_stride_uv,
  8443. uint8_t* dst_argb,
  8444. int dst_stride_argb,
  8445. const struct YuvConstants* yuvconstants,
  8446. int width,
  8447. int height,
  8448. enum FilterMode filter) {
  8449. switch (filter) {
  8450. case kFilterNone:
  8451. return P010ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv,
  8452. dst_argb, dst_stride_argb, yuvconstants, width,
  8453. height);
  8454. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8455. case kFilterBilinear:
  8456. case kFilterBox:
  8457. return P010ToARGBMatrixBilinear(src_y, src_stride_y, src_uv,
  8458. src_stride_uv, dst_argb, dst_stride_argb,
  8459. yuvconstants, width, height);
  8460. }
  8461. return -1;
  8462. }
  8463. LIBYUV_API
  8464. int P210ToARGBMatrixFilter(const uint16_t* src_y,
  8465. int src_stride_y,
  8466. const uint16_t* src_uv,
  8467. int src_stride_uv,
  8468. uint8_t* dst_argb,
  8469. int dst_stride_argb,
  8470. const struct YuvConstants* yuvconstants,
  8471. int width,
  8472. int height,
  8473. enum FilterMode filter) {
  8474. switch (filter) {
  8475. case kFilterNone:
  8476. return P210ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv,
  8477. dst_argb, dst_stride_argb, yuvconstants, width,
  8478. height);
  8479. case kFilterBilinear:
  8480. case kFilterBox:
  8481. case kFilterLinear:
  8482. return P210ToARGBMatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv,
  8483. dst_argb, dst_stride_argb, yuvconstants,
  8484. width, height);
  8485. }
  8486. return -1;
  8487. }
  8488. LIBYUV_API
  8489. int P010ToAR30MatrixFilter(const uint16_t* src_y,
  8490. int src_stride_y,
  8491. const uint16_t* src_uv,
  8492. int src_stride_uv,
  8493. uint8_t* dst_ar30,
  8494. int dst_stride_ar30,
  8495. const struct YuvConstants* yuvconstants,
  8496. int width,
  8497. int height,
  8498. enum FilterMode filter) {
  8499. switch (filter) {
  8500. case kFilterNone:
  8501. return P010ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  8502. dst_ar30, dst_stride_ar30, yuvconstants, width,
  8503. height);
  8504. case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0
  8505. case kFilterBilinear:
  8506. case kFilterBox:
  8507. return P010ToAR30MatrixBilinear(src_y, src_stride_y, src_uv,
  8508. src_stride_uv, dst_ar30, dst_stride_ar30,
  8509. yuvconstants, width, height);
  8510. }
  8511. return -1;
  8512. }
  8513. LIBYUV_API
  8514. int P210ToAR30MatrixFilter(const uint16_t* src_y,
  8515. int src_stride_y,
  8516. const uint16_t* src_uv,
  8517. int src_stride_uv,
  8518. uint8_t* dst_ar30,
  8519. int dst_stride_ar30,
  8520. const struct YuvConstants* yuvconstants,
  8521. int width,
  8522. int height,
  8523. enum FilterMode filter) {
  8524. switch (filter) {
  8525. case kFilterNone:
  8526. return P210ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  8527. dst_ar30, dst_stride_ar30, yuvconstants, width,
  8528. height);
  8529. case kFilterBilinear:
  8530. case kFilterBox:
  8531. case kFilterLinear:
  8532. return P210ToAR30MatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv,
  8533. dst_ar30, dst_stride_ar30, yuvconstants,
  8534. width, height);
  8535. }
  8536. return -1;
  8537. }
  8538. #ifdef __cplusplus
  8539. } // extern "C"
  8540. } // namespace libyuv
  8541. #endif