convert_argb.cc 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126
  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 "libyuv/cpu_id.h"
  12. #ifdef HAVE_JPEG
  13. #include "libyuv/mjpeg_decoder.h"
  14. #endif
  15. #include "libyuv/planar_functions.h" // For CopyPlane and ARGBShuffle.
  16. #include "libyuv/rotate_argb.h"
  17. #include "libyuv/row.h"
  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. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  63. return -1;
  64. }
  65. // Negative height means invert the image.
  66. if (height < 0) {
  67. height = -height;
  68. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  69. dst_stride_argb = -dst_stride_argb;
  70. }
  71. #if defined(HAS_I422TOARGBROW_SSSE3)
  72. if (TestCpuFlag(kCpuHasSSSE3)) {
  73. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  74. if (IS_ALIGNED(width, 8)) {
  75. I422ToARGBRow = I422ToARGBRow_SSSE3;
  76. }
  77. }
  78. #endif
  79. #if defined(HAS_I422TOARGBROW_AVX2)
  80. if (TestCpuFlag(kCpuHasAVX2)) {
  81. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  82. if (IS_ALIGNED(width, 16)) {
  83. I422ToARGBRow = I422ToARGBRow_AVX2;
  84. }
  85. }
  86. #endif
  87. #if defined(HAS_I422TOARGBROW_NEON)
  88. if (TestCpuFlag(kCpuHasNEON)) {
  89. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  90. if (IS_ALIGNED(width, 8)) {
  91. I422ToARGBRow = I422ToARGBRow_NEON;
  92. }
  93. }
  94. #endif
  95. #if defined(HAS_I422TOARGBROW_MMI)
  96. if (TestCpuFlag(kCpuHasMMI)) {
  97. I422ToARGBRow = I422ToARGBRow_Any_MMI;
  98. if (IS_ALIGNED(width, 4)) {
  99. I422ToARGBRow = I422ToARGBRow_MMI;
  100. }
  101. }
  102. #endif
  103. #if defined(HAS_I422TOARGBROW_MSA)
  104. if (TestCpuFlag(kCpuHasMSA)) {
  105. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  106. if (IS_ALIGNED(width, 8)) {
  107. I422ToARGBRow = I422ToARGBRow_MSA;
  108. }
  109. }
  110. #endif
  111. for (y = 0; y < height; ++y) {
  112. I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  113. dst_argb += dst_stride_argb;
  114. src_y += src_stride_y;
  115. if (y & 1) {
  116. src_u += src_stride_u;
  117. src_v += src_stride_v;
  118. }
  119. }
  120. return 0;
  121. }
  122. // Convert I420 to ARGB.
  123. LIBYUV_API
  124. int I420ToARGB(const uint8_t* src_y,
  125. int src_stride_y,
  126. const uint8_t* src_u,
  127. int src_stride_u,
  128. const uint8_t* src_v,
  129. int src_stride_v,
  130. uint8_t* dst_argb,
  131. int dst_stride_argb,
  132. int width,
  133. int height) {
  134. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  135. src_stride_v, dst_argb, dst_stride_argb,
  136. &kYuvI601Constants, width, height);
  137. }
  138. // Convert I420 to ABGR.
  139. LIBYUV_API
  140. int I420ToABGR(const uint8_t* src_y,
  141. int src_stride_y,
  142. const uint8_t* src_u,
  143. int src_stride_u,
  144. const uint8_t* src_v,
  145. int src_stride_v,
  146. uint8_t* dst_abgr,
  147. int dst_stride_abgr,
  148. int width,
  149. int height) {
  150. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  151. src_stride_v, // Swap U and V
  152. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  153. &kYvuI601Constants, // Use Yvu matrix
  154. width, height);
  155. }
  156. // Convert J420 to ARGB.
  157. LIBYUV_API
  158. int J420ToARGB(const uint8_t* src_y,
  159. int src_stride_y,
  160. const uint8_t* src_u,
  161. int src_stride_u,
  162. const uint8_t* src_v,
  163. int src_stride_v,
  164. uint8_t* dst_argb,
  165. int dst_stride_argb,
  166. int width,
  167. int height) {
  168. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  169. src_stride_v, dst_argb, dst_stride_argb,
  170. &kYuvJPEGConstants, width, height);
  171. }
  172. // Convert J420 to ABGR.
  173. LIBYUV_API
  174. int J420ToABGR(const uint8_t* src_y,
  175. int src_stride_y,
  176. const uint8_t* src_u,
  177. int src_stride_u,
  178. const uint8_t* src_v,
  179. int src_stride_v,
  180. uint8_t* dst_abgr,
  181. int dst_stride_abgr,
  182. int width,
  183. int height) {
  184. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  185. src_stride_v, // Swap U and V
  186. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  187. &kYvuJPEGConstants, // Use Yvu matrix
  188. width, height);
  189. }
  190. // Convert H420 to ARGB.
  191. LIBYUV_API
  192. int H420ToARGB(const uint8_t* src_y,
  193. int src_stride_y,
  194. const uint8_t* src_u,
  195. int src_stride_u,
  196. const uint8_t* src_v,
  197. int src_stride_v,
  198. uint8_t* dst_argb,
  199. int dst_stride_argb,
  200. int width,
  201. int height) {
  202. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  203. src_stride_v, dst_argb, dst_stride_argb,
  204. &kYuvH709Constants, width, height);
  205. }
  206. // Convert H420 to ABGR.
  207. LIBYUV_API
  208. int H420ToABGR(const uint8_t* src_y,
  209. int src_stride_y,
  210. const uint8_t* src_u,
  211. int src_stride_u,
  212. const uint8_t* src_v,
  213. int src_stride_v,
  214. uint8_t* dst_abgr,
  215. int dst_stride_abgr,
  216. int width,
  217. int height) {
  218. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  219. src_stride_v, // Swap U and V
  220. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  221. &kYvuH709Constants, // Use Yvu matrix
  222. width, height);
  223. }
  224. // Convert U420 to ARGB.
  225. LIBYUV_API
  226. int U420ToARGB(const uint8_t* src_y,
  227. int src_stride_y,
  228. const uint8_t* src_u,
  229. int src_stride_u,
  230. const uint8_t* src_v,
  231. int src_stride_v,
  232. uint8_t* dst_argb,
  233. int dst_stride_argb,
  234. int width,
  235. int height) {
  236. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  237. src_stride_v, dst_argb, dst_stride_argb,
  238. &kYuv2020Constants, width, height);
  239. }
  240. // Convert U420 to ABGR.
  241. LIBYUV_API
  242. int U420ToABGR(const uint8_t* src_y,
  243. int src_stride_y,
  244. const uint8_t* src_u,
  245. int src_stride_u,
  246. const uint8_t* src_v,
  247. int src_stride_v,
  248. uint8_t* dst_abgr,
  249. int dst_stride_abgr,
  250. int width,
  251. int height) {
  252. return I420ToARGBMatrix(src_y, src_stride_y, src_v,
  253. src_stride_v, // Swap U and V
  254. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  255. &kYvu2020Constants, // Use Yvu matrix
  256. width, height);
  257. }
  258. // Convert I422 to ARGB with matrix.
  259. LIBYUV_API
  260. int I422ToARGBMatrix(const uint8_t* src_y,
  261. int src_stride_y,
  262. const uint8_t* src_u,
  263. int src_stride_u,
  264. const uint8_t* src_v,
  265. int src_stride_v,
  266. uint8_t* dst_argb,
  267. int dst_stride_argb,
  268. const struct YuvConstants* yuvconstants,
  269. int width,
  270. int height) {
  271. int y;
  272. void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  273. const uint8_t* v_buf, uint8_t* rgb_buf,
  274. const struct YuvConstants* yuvconstants, int width) =
  275. I422ToARGBRow_C;
  276. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  277. return -1;
  278. }
  279. // Negative height means invert the image.
  280. if (height < 0) {
  281. height = -height;
  282. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  283. dst_stride_argb = -dst_stride_argb;
  284. }
  285. // Coalesce rows.
  286. if (src_stride_y == width && src_stride_u * 2 == width &&
  287. src_stride_v * 2 == width && dst_stride_argb == width * 4) {
  288. width *= height;
  289. height = 1;
  290. src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0;
  291. }
  292. #if defined(HAS_I422TOARGBROW_SSSE3)
  293. if (TestCpuFlag(kCpuHasSSSE3)) {
  294. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  295. if (IS_ALIGNED(width, 8)) {
  296. I422ToARGBRow = I422ToARGBRow_SSSE3;
  297. }
  298. }
  299. #endif
  300. #if defined(HAS_I422TOARGBROW_AVX2)
  301. if (TestCpuFlag(kCpuHasAVX2)) {
  302. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  303. if (IS_ALIGNED(width, 16)) {
  304. I422ToARGBRow = I422ToARGBRow_AVX2;
  305. }
  306. }
  307. #endif
  308. #if defined(HAS_I422TOARGBROW_NEON)
  309. if (TestCpuFlag(kCpuHasNEON)) {
  310. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  311. if (IS_ALIGNED(width, 8)) {
  312. I422ToARGBRow = I422ToARGBRow_NEON;
  313. }
  314. }
  315. #endif
  316. #if defined(HAS_I422TOARGBROW_MMI)
  317. if (TestCpuFlag(kCpuHasMMI)) {
  318. I422ToARGBRow = I422ToARGBRow_Any_MMI;
  319. if (IS_ALIGNED(width, 4)) {
  320. I422ToARGBRow = I422ToARGBRow_MMI;
  321. }
  322. }
  323. #endif
  324. #if defined(HAS_I422TOARGBROW_MSA)
  325. if (TestCpuFlag(kCpuHasMSA)) {
  326. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  327. if (IS_ALIGNED(width, 8)) {
  328. I422ToARGBRow = I422ToARGBRow_MSA;
  329. }
  330. }
  331. #endif
  332. for (y = 0; y < height; ++y) {
  333. I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  334. dst_argb += dst_stride_argb;
  335. src_y += src_stride_y;
  336. src_u += src_stride_u;
  337. src_v += src_stride_v;
  338. }
  339. return 0;
  340. }
  341. // Convert I422 to ARGB.
  342. LIBYUV_API
  343. int I422ToARGB(const uint8_t* src_y,
  344. int src_stride_y,
  345. const uint8_t* src_u,
  346. int src_stride_u,
  347. const uint8_t* src_v,
  348. int src_stride_v,
  349. uint8_t* dst_argb,
  350. int dst_stride_argb,
  351. int width,
  352. int height) {
  353. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  354. src_stride_v, dst_argb, dst_stride_argb,
  355. &kYuvI601Constants, width, height);
  356. }
  357. // Convert I422 to ABGR.
  358. LIBYUV_API
  359. int I422ToABGR(const uint8_t* src_y,
  360. int src_stride_y,
  361. const uint8_t* src_u,
  362. int src_stride_u,
  363. const uint8_t* src_v,
  364. int src_stride_v,
  365. uint8_t* dst_abgr,
  366. int dst_stride_abgr,
  367. int width,
  368. int height) {
  369. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  370. src_stride_v, // Swap U and V
  371. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  372. &kYvuI601Constants, // Use Yvu matrix
  373. width, height);
  374. }
  375. // Convert J422 to ARGB.
  376. LIBYUV_API
  377. int J422ToARGB(const uint8_t* src_y,
  378. int src_stride_y,
  379. const uint8_t* src_u,
  380. int src_stride_u,
  381. const uint8_t* src_v,
  382. int src_stride_v,
  383. uint8_t* dst_argb,
  384. int dst_stride_argb,
  385. int width,
  386. int height) {
  387. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  388. src_stride_v, dst_argb, dst_stride_argb,
  389. &kYuvJPEGConstants, width, height);
  390. }
  391. // Convert J422 to ABGR.
  392. LIBYUV_API
  393. int J422ToABGR(const uint8_t* src_y,
  394. int src_stride_y,
  395. const uint8_t* src_u,
  396. int src_stride_u,
  397. const uint8_t* src_v,
  398. int src_stride_v,
  399. uint8_t* dst_abgr,
  400. int dst_stride_abgr,
  401. int width,
  402. int height) {
  403. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  404. src_stride_v, // Swap U and V
  405. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  406. &kYvuJPEGConstants, // Use Yvu matrix
  407. width, height);
  408. }
  409. // Convert H422 to ARGB.
  410. LIBYUV_API
  411. int H422ToARGB(const uint8_t* src_y,
  412. int src_stride_y,
  413. const uint8_t* src_u,
  414. int src_stride_u,
  415. const uint8_t* src_v,
  416. int src_stride_v,
  417. uint8_t* dst_argb,
  418. int dst_stride_argb,
  419. int width,
  420. int height) {
  421. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  422. src_stride_v, dst_argb, dst_stride_argb,
  423. &kYuvH709Constants, width, height);
  424. }
  425. // Convert H422 to ABGR.
  426. LIBYUV_API
  427. int H422ToABGR(const uint8_t* src_y,
  428. int src_stride_y,
  429. const uint8_t* src_u,
  430. int src_stride_u,
  431. const uint8_t* src_v,
  432. int src_stride_v,
  433. uint8_t* dst_abgr,
  434. int dst_stride_abgr,
  435. int width,
  436. int height) {
  437. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  438. src_stride_v, // Swap U and V
  439. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  440. &kYvuH709Constants, // Use Yvu matrix
  441. width, height);
  442. }
  443. // Convert U422 to ARGB.
  444. LIBYUV_API
  445. int U422ToARGB(const uint8_t* src_y,
  446. int src_stride_y,
  447. const uint8_t* src_u,
  448. int src_stride_u,
  449. const uint8_t* src_v,
  450. int src_stride_v,
  451. uint8_t* dst_argb,
  452. int dst_stride_argb,
  453. int width,
  454. int height) {
  455. return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  456. src_stride_v, dst_argb, dst_stride_argb,
  457. &kYuv2020Constants, width, height);
  458. }
  459. // Convert U422 to ABGR.
  460. LIBYUV_API
  461. int U422ToABGR(const uint8_t* src_y,
  462. int src_stride_y,
  463. const uint8_t* src_u,
  464. int src_stride_u,
  465. const uint8_t* src_v,
  466. int src_stride_v,
  467. uint8_t* dst_abgr,
  468. int dst_stride_abgr,
  469. int width,
  470. int height) {
  471. return I422ToARGBMatrix(src_y, src_stride_y, src_v,
  472. src_stride_v, // Swap U and V
  473. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  474. &kYvu2020Constants, // Use Yvu matrix
  475. width, height);
  476. }
  477. // Convert I444 to ARGB with matrix.
  478. LIBYUV_API
  479. int I444ToARGBMatrix(const uint8_t* src_y,
  480. int src_stride_y,
  481. const uint8_t* src_u,
  482. int src_stride_u,
  483. const uint8_t* src_v,
  484. int src_stride_v,
  485. uint8_t* dst_argb,
  486. int dst_stride_argb,
  487. const struct YuvConstants* yuvconstants,
  488. int width,
  489. int height) {
  490. int y;
  491. void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  492. const uint8_t* v_buf, uint8_t* rgb_buf,
  493. const struct YuvConstants* yuvconstants, int width) =
  494. I444ToARGBRow_C;
  495. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  496. return -1;
  497. }
  498. // Negative height means invert the image.
  499. if (height < 0) {
  500. height = -height;
  501. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  502. dst_stride_argb = -dst_stride_argb;
  503. }
  504. // Coalesce rows.
  505. if (src_stride_y == width && src_stride_u == width && src_stride_v == width &&
  506. dst_stride_argb == width * 4) {
  507. width *= height;
  508. height = 1;
  509. src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0;
  510. }
  511. #if defined(HAS_I444TOARGBROW_SSSE3)
  512. if (TestCpuFlag(kCpuHasSSSE3)) {
  513. I444ToARGBRow = I444ToARGBRow_Any_SSSE3;
  514. if (IS_ALIGNED(width, 8)) {
  515. I444ToARGBRow = I444ToARGBRow_SSSE3;
  516. }
  517. }
  518. #endif
  519. #if defined(HAS_I444TOARGBROW_AVX2)
  520. if (TestCpuFlag(kCpuHasAVX2)) {
  521. I444ToARGBRow = I444ToARGBRow_Any_AVX2;
  522. if (IS_ALIGNED(width, 16)) {
  523. I444ToARGBRow = I444ToARGBRow_AVX2;
  524. }
  525. }
  526. #endif
  527. #if defined(HAS_I444TOARGBROW_NEON)
  528. if (TestCpuFlag(kCpuHasNEON)) {
  529. I444ToARGBRow = I444ToARGBRow_Any_NEON;
  530. if (IS_ALIGNED(width, 8)) {
  531. I444ToARGBRow = I444ToARGBRow_NEON;
  532. }
  533. }
  534. #endif
  535. #if defined(HAS_I444TOARGBROW_MMI)
  536. if (TestCpuFlag(kCpuHasMMI)) {
  537. I444ToARGBRow = I444ToARGBRow_Any_MMI;
  538. if (IS_ALIGNED(width, 4)) {
  539. I444ToARGBRow = I444ToARGBRow_MMI;
  540. }
  541. }
  542. #endif
  543. #if defined(HAS_I444TOARGBROW_MSA)
  544. if (TestCpuFlag(kCpuHasMSA)) {
  545. I444ToARGBRow = I444ToARGBRow_Any_MSA;
  546. if (IS_ALIGNED(width, 8)) {
  547. I444ToARGBRow = I444ToARGBRow_MSA;
  548. }
  549. }
  550. #endif
  551. for (y = 0; y < height; ++y) {
  552. I444ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  553. dst_argb += dst_stride_argb;
  554. src_y += src_stride_y;
  555. src_u += src_stride_u;
  556. src_v += src_stride_v;
  557. }
  558. return 0;
  559. }
  560. // Convert I444 to ARGB.
  561. LIBYUV_API
  562. int I444ToARGB(const uint8_t* src_y,
  563. int src_stride_y,
  564. const uint8_t* src_u,
  565. int src_stride_u,
  566. const uint8_t* src_v,
  567. int src_stride_v,
  568. uint8_t* dst_argb,
  569. int dst_stride_argb,
  570. int width,
  571. int height) {
  572. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  573. src_stride_v, dst_argb, dst_stride_argb,
  574. &kYuvI601Constants, width, height);
  575. }
  576. // Convert I444 to ABGR.
  577. LIBYUV_API
  578. int I444ToABGR(const uint8_t* src_y,
  579. int src_stride_y,
  580. const uint8_t* src_u,
  581. int src_stride_u,
  582. const uint8_t* src_v,
  583. int src_stride_v,
  584. uint8_t* dst_abgr,
  585. int dst_stride_abgr,
  586. int width,
  587. int height) {
  588. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  589. src_stride_v, // Swap U and V
  590. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  591. &kYvuI601Constants, // Use Yvu matrix
  592. width, height);
  593. }
  594. // Convert J444 to ARGB.
  595. LIBYUV_API
  596. int J444ToARGB(const uint8_t* src_y,
  597. int src_stride_y,
  598. const uint8_t* src_u,
  599. int src_stride_u,
  600. const uint8_t* src_v,
  601. int src_stride_v,
  602. uint8_t* dst_argb,
  603. int dst_stride_argb,
  604. int width,
  605. int height) {
  606. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  607. src_stride_v, dst_argb, dst_stride_argb,
  608. &kYuvJPEGConstants, width, height);
  609. }
  610. // Convert J444 to ABGR.
  611. LIBYUV_API
  612. int J444ToABGR(const uint8_t* src_y,
  613. int src_stride_y,
  614. const uint8_t* src_u,
  615. int src_stride_u,
  616. const uint8_t* src_v,
  617. int src_stride_v,
  618. uint8_t* dst_abgr,
  619. int dst_stride_abgr,
  620. int width,
  621. int height) {
  622. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  623. src_stride_v, // Swap U and V
  624. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  625. &kYvuJPEGConstants, // Use Yvu matrix
  626. width, height);
  627. }
  628. // Convert H444 to ARGB.
  629. LIBYUV_API
  630. int H444ToARGB(const uint8_t* src_y,
  631. int src_stride_y,
  632. const uint8_t* src_u,
  633. int src_stride_u,
  634. const uint8_t* src_v,
  635. int src_stride_v,
  636. uint8_t* dst_argb,
  637. int dst_stride_argb,
  638. int width,
  639. int height) {
  640. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  641. src_stride_v, dst_argb, dst_stride_argb,
  642. &kYuvH709Constants, width, height);
  643. }
  644. // Convert H444 to ABGR.
  645. LIBYUV_API
  646. int H444ToABGR(const uint8_t* src_y,
  647. int src_stride_y,
  648. const uint8_t* src_u,
  649. int src_stride_u,
  650. const uint8_t* src_v,
  651. int src_stride_v,
  652. uint8_t* dst_abgr,
  653. int dst_stride_abgr,
  654. int width,
  655. int height) {
  656. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  657. src_stride_v, // Swap U and V
  658. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  659. &kYvuH709Constants, // Use Yvu matrix
  660. width, height);
  661. }
  662. // Convert U444 to ARGB.
  663. LIBYUV_API
  664. int U444ToARGB(const uint8_t* src_y,
  665. int src_stride_y,
  666. const uint8_t* src_u,
  667. int src_stride_u,
  668. const uint8_t* src_v,
  669. int src_stride_v,
  670. uint8_t* dst_argb,
  671. int dst_stride_argb,
  672. int width,
  673. int height) {
  674. return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  675. src_stride_v, dst_argb, dst_stride_argb,
  676. &kYuv2020Constants, width, height);
  677. }
  678. // Convert U444 to ABGR.
  679. LIBYUV_API
  680. int U444ToABGR(const uint8_t* src_y,
  681. int src_stride_y,
  682. const uint8_t* src_u,
  683. int src_stride_u,
  684. const uint8_t* src_v,
  685. int src_stride_v,
  686. uint8_t* dst_abgr,
  687. int dst_stride_abgr,
  688. int width,
  689. int height) {
  690. return I444ToARGBMatrix(src_y, src_stride_y, src_v,
  691. src_stride_v, // Swap U and V
  692. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  693. &kYvu2020Constants, // Use Yvu matrix
  694. width, height);
  695. }
  696. // Convert 10 bit YUV to ARGB with matrix.
  697. // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to
  698. // multiply 10 bit yuv into high bits to allow any number of bits.
  699. LIBYUV_API
  700. int I010ToAR30Matrix(const uint16_t* src_y,
  701. int src_stride_y,
  702. const uint16_t* src_u,
  703. int src_stride_u,
  704. const uint16_t* src_v,
  705. int src_stride_v,
  706. uint8_t* dst_ar30,
  707. int dst_stride_ar30,
  708. const struct YuvConstants* yuvconstants,
  709. int width,
  710. int height) {
  711. int y;
  712. void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  713. const uint16_t* v_buf, uint8_t* rgb_buf,
  714. const struct YuvConstants* yuvconstants, int width) =
  715. I210ToAR30Row_C;
  716. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  717. return -1;
  718. }
  719. // Negative height means invert the image.
  720. if (height < 0) {
  721. height = -height;
  722. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  723. dst_stride_ar30 = -dst_stride_ar30;
  724. }
  725. #if defined(HAS_I210TOAR30ROW_SSSE3)
  726. if (TestCpuFlag(kCpuHasSSSE3)) {
  727. I210ToAR30Row = I210ToAR30Row_Any_SSSE3;
  728. if (IS_ALIGNED(width, 8)) {
  729. I210ToAR30Row = I210ToAR30Row_SSSE3;
  730. }
  731. }
  732. #endif
  733. #if defined(HAS_I210TOAR30ROW_AVX2)
  734. if (TestCpuFlag(kCpuHasAVX2)) {
  735. I210ToAR30Row = I210ToAR30Row_Any_AVX2;
  736. if (IS_ALIGNED(width, 16)) {
  737. I210ToAR30Row = I210ToAR30Row_AVX2;
  738. }
  739. }
  740. #endif
  741. for (y = 0; y < height; ++y) {
  742. I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  743. dst_ar30 += dst_stride_ar30;
  744. src_y += src_stride_y;
  745. if (y & 1) {
  746. src_u += src_stride_u;
  747. src_v += src_stride_v;
  748. }
  749. }
  750. return 0;
  751. }
  752. // Convert I010 to AR30.
  753. LIBYUV_API
  754. int I010ToAR30(const uint16_t* src_y,
  755. int src_stride_y,
  756. const uint16_t* src_u,
  757. int src_stride_u,
  758. const uint16_t* src_v,
  759. int src_stride_v,
  760. uint8_t* dst_ar30,
  761. int dst_stride_ar30,
  762. int width,
  763. int height) {
  764. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  765. src_stride_v, dst_ar30, dst_stride_ar30,
  766. &kYuvI601Constants, width, height);
  767. }
  768. // Convert H010 to AR30.
  769. LIBYUV_API
  770. int H010ToAR30(const uint16_t* src_y,
  771. int src_stride_y,
  772. const uint16_t* src_u,
  773. int src_stride_u,
  774. const uint16_t* src_v,
  775. int src_stride_v,
  776. uint8_t* dst_ar30,
  777. int dst_stride_ar30,
  778. int width,
  779. int height) {
  780. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  781. src_stride_v, dst_ar30, dst_stride_ar30,
  782. &kYuvH709Constants, width, height);
  783. }
  784. // Convert U010 to AR30.
  785. LIBYUV_API
  786. int U010ToAR30(const uint16_t* src_y,
  787. int src_stride_y,
  788. const uint16_t* src_u,
  789. int src_stride_u,
  790. const uint16_t* src_v,
  791. int src_stride_v,
  792. uint8_t* dst_ar30,
  793. int dst_stride_ar30,
  794. int width,
  795. int height) {
  796. return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  797. src_stride_v, dst_ar30, dst_stride_ar30,
  798. &kYuv2020Constants, width, height);
  799. }
  800. // Convert I010 to AB30.
  801. LIBYUV_API
  802. int I010ToAB30(const uint16_t* src_y,
  803. int src_stride_y,
  804. const uint16_t* src_u,
  805. int src_stride_u,
  806. const uint16_t* src_v,
  807. int src_stride_v,
  808. uint8_t* dst_ab30,
  809. int dst_stride_ab30,
  810. int width,
  811. int height) {
  812. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  813. src_stride_u, dst_ab30, dst_stride_ab30,
  814. &kYvuI601Constants, width, height);
  815. }
  816. // Convert H010 to AB30.
  817. LIBYUV_API
  818. int H010ToAB30(const uint16_t* src_y,
  819. int src_stride_y,
  820. const uint16_t* src_u,
  821. int src_stride_u,
  822. const uint16_t* src_v,
  823. int src_stride_v,
  824. uint8_t* dst_ab30,
  825. int dst_stride_ab30,
  826. int width,
  827. int height) {
  828. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  829. src_stride_u, dst_ab30, dst_stride_ab30,
  830. &kYvuH709Constants, width, height);
  831. }
  832. // Convert U010 to AB30.
  833. LIBYUV_API
  834. int U010ToAB30(const uint16_t* src_y,
  835. int src_stride_y,
  836. const uint16_t* src_u,
  837. int src_stride_u,
  838. const uint16_t* src_v,
  839. int src_stride_v,
  840. uint8_t* dst_ab30,
  841. int dst_stride_ab30,
  842. int width,
  843. int height) {
  844. return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  845. src_stride_u, dst_ab30, dst_stride_ab30,
  846. &kYuv2020Constants, width, height);
  847. }
  848. // Convert 10 bit YUV to ARGB with matrix.
  849. // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to
  850. // multiply 10 bit yuv into high bits to allow any number of bits.
  851. LIBYUV_API
  852. int I210ToAR30Matrix(const uint16_t* src_y,
  853. int src_stride_y,
  854. const uint16_t* src_u,
  855. int src_stride_u,
  856. const uint16_t* src_v,
  857. int src_stride_v,
  858. uint8_t* dst_ar30,
  859. int dst_stride_ar30,
  860. const struct YuvConstants* yuvconstants,
  861. int width,
  862. int height) {
  863. int y;
  864. void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,
  865. const uint16_t* v_buf, uint8_t* rgb_buf,
  866. const struct YuvConstants* yuvconstants, int width) =
  867. I210ToAR30Row_C;
  868. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  869. return -1;
  870. }
  871. // Negative height means invert the image.
  872. if (height < 0) {
  873. height = -height;
  874. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  875. dst_stride_ar30 = -dst_stride_ar30;
  876. }
  877. #if defined(HAS_I210TOAR30ROW_SSSE3)
  878. if (TestCpuFlag(kCpuHasSSSE3)) {
  879. I210ToAR30Row = I210ToAR30Row_Any_SSSE3;
  880. if (IS_ALIGNED(width, 8)) {
  881. I210ToAR30Row = I210ToAR30Row_SSSE3;
  882. }
  883. }
  884. #endif
  885. #if defined(HAS_I210TOAR30ROW_AVX2)
  886. if (TestCpuFlag(kCpuHasAVX2)) {
  887. I210ToAR30Row = I210ToAR30Row_Any_AVX2;
  888. if (IS_ALIGNED(width, 16)) {
  889. I210ToAR30Row = I210ToAR30Row_AVX2;
  890. }
  891. }
  892. #endif
  893. for (y = 0; y < height; ++y) {
  894. I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  895. dst_ar30 += dst_stride_ar30;
  896. src_y += src_stride_y;
  897. src_u += src_stride_u;
  898. src_v += src_stride_v;
  899. }
  900. return 0;
  901. }
  902. // Convert I210 to AR30.
  903. LIBYUV_API
  904. int I210ToAR30(const uint16_t* src_y,
  905. int src_stride_y,
  906. const uint16_t* src_u,
  907. int src_stride_u,
  908. const uint16_t* src_v,
  909. int src_stride_v,
  910. uint8_t* dst_ar30,
  911. int dst_stride_ar30,
  912. int width,
  913. int height) {
  914. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  915. src_stride_v, dst_ar30, dst_stride_ar30,
  916. &kYuvI601Constants, width, height);
  917. }
  918. // Convert H210 to AR30.
  919. LIBYUV_API
  920. int H210ToAR30(const uint16_t* src_y,
  921. int src_stride_y,
  922. const uint16_t* src_u,
  923. int src_stride_u,
  924. const uint16_t* src_v,
  925. int src_stride_v,
  926. uint8_t* dst_ar30,
  927. int dst_stride_ar30,
  928. int width,
  929. int height) {
  930. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  931. src_stride_v, dst_ar30, dst_stride_ar30,
  932. &kYuvH709Constants, width, height);
  933. }
  934. // Convert U210 to AR30.
  935. LIBYUV_API
  936. int U210ToAR30(const uint16_t* src_y,
  937. int src_stride_y,
  938. const uint16_t* src_u,
  939. int src_stride_u,
  940. const uint16_t* src_v,
  941. int src_stride_v,
  942. uint8_t* dst_ar30,
  943. int dst_stride_ar30,
  944. int width,
  945. int height) {
  946. return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  947. src_stride_v, dst_ar30, dst_stride_ar30,
  948. &kYuv2020Constants, width, height);
  949. }
  950. // Convert I210 to AB30.
  951. LIBYUV_API
  952. int I210ToAB30(const uint16_t* src_y,
  953. int src_stride_y,
  954. const uint16_t* src_u,
  955. int src_stride_u,
  956. const uint16_t* src_v,
  957. int src_stride_v,
  958. uint8_t* dst_ab30,
  959. int dst_stride_ab30,
  960. int width,
  961. int height) {
  962. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  963. src_stride_u, dst_ab30, dst_stride_ab30,
  964. &kYvuI601Constants, width, height);
  965. }
  966. // Convert H210 to AB30.
  967. LIBYUV_API
  968. int H210ToAB30(const uint16_t* src_y,
  969. int src_stride_y,
  970. const uint16_t* src_u,
  971. int src_stride_u,
  972. const uint16_t* src_v,
  973. int src_stride_v,
  974. uint8_t* dst_ab30,
  975. int dst_stride_ab30,
  976. int width,
  977. int height) {
  978. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  979. src_stride_u, dst_ab30, dst_stride_ab30,
  980. &kYvuH709Constants, width, height);
  981. }
  982. // Convert U210 to AB30.
  983. LIBYUV_API
  984. int U210ToAB30(const uint16_t* src_y,
  985. int src_stride_y,
  986. const uint16_t* src_u,
  987. int src_stride_u,
  988. const uint16_t* src_v,
  989. int src_stride_v,
  990. uint8_t* dst_ab30,
  991. int dst_stride_ab30,
  992. int width,
  993. int height) {
  994. return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  995. src_stride_u, dst_ab30, dst_stride_ab30,
  996. &kYuv2020Constants, width, height);
  997. }
  998. // Convert 10 bit YUV to ARGB with matrix.
  999. LIBYUV_API
  1000. int I010ToARGBMatrix(const uint16_t* src_y,
  1001. int src_stride_y,
  1002. const uint16_t* src_u,
  1003. int src_stride_u,
  1004. const uint16_t* src_v,
  1005. int src_stride_v,
  1006. uint8_t* dst_argb,
  1007. int dst_stride_argb,
  1008. const struct YuvConstants* yuvconstants,
  1009. int width,
  1010. int height) {
  1011. int y;
  1012. void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1013. const uint16_t* v_buf, uint8_t* rgb_buf,
  1014. const struct YuvConstants* yuvconstants, int width) =
  1015. I210ToARGBRow_C;
  1016. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1017. return -1;
  1018. }
  1019. // Negative height means invert the image.
  1020. if (height < 0) {
  1021. height = -height;
  1022. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1023. dst_stride_argb = -dst_stride_argb;
  1024. }
  1025. #if defined(HAS_I210TOARGBROW_SSSE3)
  1026. if (TestCpuFlag(kCpuHasSSSE3)) {
  1027. I210ToARGBRow = I210ToARGBRow_Any_SSSE3;
  1028. if (IS_ALIGNED(width, 8)) {
  1029. I210ToARGBRow = I210ToARGBRow_SSSE3;
  1030. }
  1031. }
  1032. #endif
  1033. #if defined(HAS_I210TOARGBROW_AVX2)
  1034. if (TestCpuFlag(kCpuHasAVX2)) {
  1035. I210ToARGBRow = I210ToARGBRow_Any_AVX2;
  1036. if (IS_ALIGNED(width, 16)) {
  1037. I210ToARGBRow = I210ToARGBRow_AVX2;
  1038. }
  1039. }
  1040. #endif
  1041. #if defined(HAS_I210TOARGBROW_MMI)
  1042. if (TestCpuFlag(kCpuHasMMI)) {
  1043. I210ToARGBRow = I210ToARGBRow_Any_MMI;
  1044. if (IS_ALIGNED(width, 4)) {
  1045. I210ToARGBRow = I210ToARGBRow_MMI;
  1046. }
  1047. }
  1048. #endif
  1049. for (y = 0; y < height; ++y) {
  1050. I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1051. dst_argb += dst_stride_argb;
  1052. src_y += src_stride_y;
  1053. if (y & 1) {
  1054. src_u += src_stride_u;
  1055. src_v += src_stride_v;
  1056. }
  1057. }
  1058. return 0;
  1059. }
  1060. // Convert I010 to ARGB.
  1061. LIBYUV_API
  1062. int I010ToARGB(const uint16_t* src_y,
  1063. int src_stride_y,
  1064. const uint16_t* src_u,
  1065. int src_stride_u,
  1066. const uint16_t* src_v,
  1067. int src_stride_v,
  1068. uint8_t* dst_argb,
  1069. int dst_stride_argb,
  1070. int width,
  1071. int height) {
  1072. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1073. src_stride_v, dst_argb, dst_stride_argb,
  1074. &kYuvI601Constants, width, height);
  1075. }
  1076. // Convert I010 to ABGR.
  1077. LIBYUV_API
  1078. int I010ToABGR(const uint16_t* src_y,
  1079. int src_stride_y,
  1080. const uint16_t* src_u,
  1081. int src_stride_u,
  1082. const uint16_t* src_v,
  1083. int src_stride_v,
  1084. uint8_t* dst_abgr,
  1085. int dst_stride_abgr,
  1086. int width,
  1087. int height) {
  1088. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1089. src_stride_v, // Swap U and V
  1090. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1091. &kYvuI601Constants, // Use Yvu matrix
  1092. width, height);
  1093. }
  1094. // Convert H010 to ARGB.
  1095. LIBYUV_API
  1096. int H010ToARGB(const uint16_t* src_y,
  1097. int src_stride_y,
  1098. const uint16_t* src_u,
  1099. int src_stride_u,
  1100. const uint16_t* src_v,
  1101. int src_stride_v,
  1102. uint8_t* dst_argb,
  1103. int dst_stride_argb,
  1104. int width,
  1105. int height) {
  1106. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1107. src_stride_v, dst_argb, dst_stride_argb,
  1108. &kYuvH709Constants, width, height);
  1109. }
  1110. // Convert H010 to ABGR.
  1111. LIBYUV_API
  1112. int H010ToABGR(const uint16_t* src_y,
  1113. int src_stride_y,
  1114. const uint16_t* src_u,
  1115. int src_stride_u,
  1116. const uint16_t* src_v,
  1117. int src_stride_v,
  1118. uint8_t* dst_abgr,
  1119. int dst_stride_abgr,
  1120. int width,
  1121. int height) {
  1122. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1123. src_stride_v, // Swap U and V
  1124. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1125. &kYvuH709Constants, // Use Yvu matrix
  1126. width, height);
  1127. }
  1128. // Convert U010 to ARGB.
  1129. LIBYUV_API
  1130. int U010ToARGB(const uint16_t* src_y,
  1131. int src_stride_y,
  1132. const uint16_t* src_u,
  1133. int src_stride_u,
  1134. const uint16_t* src_v,
  1135. int src_stride_v,
  1136. uint8_t* dst_argb,
  1137. int dst_stride_argb,
  1138. int width,
  1139. int height) {
  1140. return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1141. src_stride_v, dst_argb, dst_stride_argb,
  1142. &kYuv2020Constants, width, height);
  1143. }
  1144. // Convert U010 to ABGR.
  1145. LIBYUV_API
  1146. int U010ToABGR(const uint16_t* src_y,
  1147. int src_stride_y,
  1148. const uint16_t* src_u,
  1149. int src_stride_u,
  1150. const uint16_t* src_v,
  1151. int src_stride_v,
  1152. uint8_t* dst_abgr,
  1153. int dst_stride_abgr,
  1154. int width,
  1155. int height) {
  1156. return I010ToARGBMatrix(src_y, src_stride_y, src_v,
  1157. src_stride_v, // Swap U and V
  1158. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1159. &kYvu2020Constants, // Use Yvu matrix
  1160. width, height);
  1161. }
  1162. // Convert 10 bit 422 YUV to ARGB with matrix.
  1163. LIBYUV_API
  1164. int I210ToARGBMatrix(const uint16_t* src_y,
  1165. int src_stride_y,
  1166. const uint16_t* src_u,
  1167. int src_stride_u,
  1168. const uint16_t* src_v,
  1169. int src_stride_v,
  1170. uint8_t* dst_argb,
  1171. int dst_stride_argb,
  1172. const struct YuvConstants* yuvconstants,
  1173. int width,
  1174. int height) {
  1175. int y;
  1176. void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf,
  1177. const uint16_t* v_buf, uint8_t* rgb_buf,
  1178. const struct YuvConstants* yuvconstants, int width) =
  1179. I210ToARGBRow_C;
  1180. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1181. return -1;
  1182. }
  1183. // Negative height means invert the image.
  1184. if (height < 0) {
  1185. height = -height;
  1186. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1187. dst_stride_argb = -dst_stride_argb;
  1188. }
  1189. #if defined(HAS_I210TOARGBROW_SSSE3)
  1190. if (TestCpuFlag(kCpuHasSSSE3)) {
  1191. I210ToARGBRow = I210ToARGBRow_Any_SSSE3;
  1192. if (IS_ALIGNED(width, 8)) {
  1193. I210ToARGBRow = I210ToARGBRow_SSSE3;
  1194. }
  1195. }
  1196. #endif
  1197. #if defined(HAS_I210TOARGBROW_AVX2)
  1198. if (TestCpuFlag(kCpuHasAVX2)) {
  1199. I210ToARGBRow = I210ToARGBRow_Any_AVX2;
  1200. if (IS_ALIGNED(width, 16)) {
  1201. I210ToARGBRow = I210ToARGBRow_AVX2;
  1202. }
  1203. }
  1204. #endif
  1205. #if defined(HAS_I210TOARGBROW_MMI)
  1206. if (TestCpuFlag(kCpuHasMMI)) {
  1207. I210ToARGBRow = I210ToARGBRow_Any_MMI;
  1208. if (IS_ALIGNED(width, 4)) {
  1209. I210ToARGBRow = I210ToARGBRow_MMI;
  1210. }
  1211. }
  1212. #endif
  1213. for (y = 0; y < height; ++y) {
  1214. I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);
  1215. dst_argb += dst_stride_argb;
  1216. src_y += src_stride_y;
  1217. src_u += src_stride_u;
  1218. src_v += src_stride_v;
  1219. }
  1220. return 0;
  1221. }
  1222. // Convert I210 to ARGB.
  1223. LIBYUV_API
  1224. int I210ToARGB(const uint16_t* src_y,
  1225. int src_stride_y,
  1226. const uint16_t* src_u,
  1227. int src_stride_u,
  1228. const uint16_t* src_v,
  1229. int src_stride_v,
  1230. uint8_t* dst_argb,
  1231. int dst_stride_argb,
  1232. int width,
  1233. int height) {
  1234. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1235. src_stride_v, dst_argb, dst_stride_argb,
  1236. &kYuvI601Constants, width, height);
  1237. }
  1238. // Convert I210 to ABGR.
  1239. LIBYUV_API
  1240. int I210ToABGR(const uint16_t* src_y,
  1241. int src_stride_y,
  1242. const uint16_t* src_u,
  1243. int src_stride_u,
  1244. const uint16_t* src_v,
  1245. int src_stride_v,
  1246. uint8_t* dst_abgr,
  1247. int dst_stride_abgr,
  1248. int width,
  1249. int height) {
  1250. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1251. src_stride_v, // Swap U and V
  1252. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1253. &kYvuI601Constants, // Use Yvu matrix
  1254. width, height);
  1255. }
  1256. // Convert H210 to ARGB.
  1257. LIBYUV_API
  1258. int H210ToARGB(const uint16_t* src_y,
  1259. int src_stride_y,
  1260. const uint16_t* src_u,
  1261. int src_stride_u,
  1262. const uint16_t* src_v,
  1263. int src_stride_v,
  1264. uint8_t* dst_argb,
  1265. int dst_stride_argb,
  1266. int width,
  1267. int height) {
  1268. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1269. src_stride_v, dst_argb, dst_stride_argb,
  1270. &kYuvH709Constants, width, height);
  1271. }
  1272. // Convert H210 to ABGR.
  1273. LIBYUV_API
  1274. int H210ToABGR(const uint16_t* src_y,
  1275. int src_stride_y,
  1276. const uint16_t* src_u,
  1277. int src_stride_u,
  1278. const uint16_t* src_v,
  1279. int src_stride_v,
  1280. uint8_t* dst_abgr,
  1281. int dst_stride_abgr,
  1282. int width,
  1283. int height) {
  1284. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1285. src_stride_v, // Swap U and V
  1286. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1287. &kYvuH709Constants, // Use Yvu matrix
  1288. width, height);
  1289. }
  1290. // Convert U210 to ARGB.
  1291. LIBYUV_API
  1292. int U210ToARGB(const uint16_t* src_y,
  1293. int src_stride_y,
  1294. const uint16_t* src_u,
  1295. int src_stride_u,
  1296. const uint16_t* src_v,
  1297. int src_stride_v,
  1298. uint8_t* dst_argb,
  1299. int dst_stride_argb,
  1300. int width,
  1301. int height) {
  1302. return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1303. src_stride_v, dst_argb, dst_stride_argb,
  1304. &kYuv2020Constants, width, height);
  1305. }
  1306. // Convert U210 to ABGR.
  1307. LIBYUV_API
  1308. int U210ToABGR(const uint16_t* src_y,
  1309. int src_stride_y,
  1310. const uint16_t* src_u,
  1311. int src_stride_u,
  1312. const uint16_t* src_v,
  1313. int src_stride_v,
  1314. uint8_t* dst_abgr,
  1315. int dst_stride_abgr,
  1316. int width,
  1317. int height) {
  1318. return I210ToARGBMatrix(src_y, src_stride_y, src_v,
  1319. src_stride_v, // Swap U and V
  1320. src_u, src_stride_u, dst_abgr, dst_stride_abgr,
  1321. &kYvu2020Constants, // Use Yvu matrix
  1322. width, height);
  1323. }
  1324. // Convert I420 with Alpha to preattenuated ARGB with matrix.
  1325. LIBYUV_API
  1326. int I420AlphaToARGBMatrix(const uint8_t* src_y,
  1327. int src_stride_y,
  1328. const uint8_t* src_u,
  1329. int src_stride_u,
  1330. const uint8_t* src_v,
  1331. int src_stride_v,
  1332. const uint8_t* src_a,
  1333. int src_stride_a,
  1334. uint8_t* dst_argb,
  1335. int dst_stride_argb,
  1336. const struct YuvConstants* yuvconstants,
  1337. int width,
  1338. int height,
  1339. int attenuate) {
  1340. int y;
  1341. void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  1342. const uint8_t* v_buf, const uint8_t* a_buf,
  1343. uint8_t* dst_argb,
  1344. const struct YuvConstants* yuvconstants,
  1345. int width) = I422AlphaToARGBRow_C;
  1346. void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb,
  1347. int width) = ARGBAttenuateRow_C;
  1348. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  1349. return -1;
  1350. }
  1351. // Negative height means invert the image.
  1352. if (height < 0) {
  1353. height = -height;
  1354. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1355. dst_stride_argb = -dst_stride_argb;
  1356. }
  1357. #if defined(HAS_I422ALPHATOARGBROW_SSSE3)
  1358. if (TestCpuFlag(kCpuHasSSSE3)) {
  1359. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3;
  1360. if (IS_ALIGNED(width, 8)) {
  1361. I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3;
  1362. }
  1363. }
  1364. #endif
  1365. #if defined(HAS_I422ALPHATOARGBROW_AVX2)
  1366. if (TestCpuFlag(kCpuHasAVX2)) {
  1367. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2;
  1368. if (IS_ALIGNED(width, 16)) {
  1369. I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2;
  1370. }
  1371. }
  1372. #endif
  1373. #if defined(HAS_I422ALPHATOARGBROW_NEON)
  1374. if (TestCpuFlag(kCpuHasNEON)) {
  1375. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON;
  1376. if (IS_ALIGNED(width, 8)) {
  1377. I422AlphaToARGBRow = I422AlphaToARGBRow_NEON;
  1378. }
  1379. }
  1380. #endif
  1381. #if defined(HAS_I422ALPHATOARGBROW_MMI)
  1382. if (TestCpuFlag(kCpuHasMMI)) {
  1383. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_MMI;
  1384. if (IS_ALIGNED(width, 4)) {
  1385. I422AlphaToARGBRow = I422AlphaToARGBRow_MMI;
  1386. }
  1387. }
  1388. #endif
  1389. #if defined(HAS_I422ALPHATOARGBROW_MSA)
  1390. if (TestCpuFlag(kCpuHasMSA)) {
  1391. I422AlphaToARGBRow = I422AlphaToARGBRow_Any_MSA;
  1392. if (IS_ALIGNED(width, 8)) {
  1393. I422AlphaToARGBRow = I422AlphaToARGBRow_MSA;
  1394. }
  1395. }
  1396. #endif
  1397. #if defined(HAS_ARGBATTENUATEROW_SSSE3)
  1398. if (TestCpuFlag(kCpuHasSSSE3)) {
  1399. ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3;
  1400. if (IS_ALIGNED(width, 4)) {
  1401. ARGBAttenuateRow = ARGBAttenuateRow_SSSE3;
  1402. }
  1403. }
  1404. #endif
  1405. #if defined(HAS_ARGBATTENUATEROW_AVX2)
  1406. if (TestCpuFlag(kCpuHasAVX2)) {
  1407. ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2;
  1408. if (IS_ALIGNED(width, 8)) {
  1409. ARGBAttenuateRow = ARGBAttenuateRow_AVX2;
  1410. }
  1411. }
  1412. #endif
  1413. #if defined(HAS_ARGBATTENUATEROW_NEON)
  1414. if (TestCpuFlag(kCpuHasNEON)) {
  1415. ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON;
  1416. if (IS_ALIGNED(width, 8)) {
  1417. ARGBAttenuateRow = ARGBAttenuateRow_NEON;
  1418. }
  1419. }
  1420. #endif
  1421. #if defined(HAS_ARGBATTENUATEROW_MMI)
  1422. if (TestCpuFlag(kCpuHasMMI)) {
  1423. ARGBAttenuateRow = ARGBAttenuateRow_Any_MMI;
  1424. if (IS_ALIGNED(width, 2)) {
  1425. ARGBAttenuateRow = ARGBAttenuateRow_MMI;
  1426. }
  1427. }
  1428. #endif
  1429. #if defined(HAS_ARGBATTENUATEROW_MSA)
  1430. if (TestCpuFlag(kCpuHasMSA)) {
  1431. ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA;
  1432. if (IS_ALIGNED(width, 8)) {
  1433. ARGBAttenuateRow = ARGBAttenuateRow_MSA;
  1434. }
  1435. }
  1436. #endif
  1437. for (y = 0; y < height; ++y) {
  1438. I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants,
  1439. width);
  1440. if (attenuate) {
  1441. ARGBAttenuateRow(dst_argb, dst_argb, width);
  1442. }
  1443. dst_argb += dst_stride_argb;
  1444. src_a += src_stride_a;
  1445. src_y += src_stride_y;
  1446. if (y & 1) {
  1447. src_u += src_stride_u;
  1448. src_v += src_stride_v;
  1449. }
  1450. }
  1451. return 0;
  1452. }
  1453. // Convert I420 with Alpha to ARGB.
  1454. LIBYUV_API
  1455. int I420AlphaToARGB(const uint8_t* src_y,
  1456. int src_stride_y,
  1457. const uint8_t* src_u,
  1458. int src_stride_u,
  1459. const uint8_t* src_v,
  1460. int src_stride_v,
  1461. const uint8_t* src_a,
  1462. int src_stride_a,
  1463. uint8_t* dst_argb,
  1464. int dst_stride_argb,
  1465. int width,
  1466. int height,
  1467. int attenuate) {
  1468. return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  1469. src_stride_v, src_a, src_stride_a, dst_argb,
  1470. dst_stride_argb, &kYuvI601Constants, width,
  1471. height, attenuate);
  1472. }
  1473. // Convert I420 with Alpha to ABGR.
  1474. LIBYUV_API
  1475. int I420AlphaToABGR(const uint8_t* src_y,
  1476. int src_stride_y,
  1477. const uint8_t* src_u,
  1478. int src_stride_u,
  1479. const uint8_t* src_v,
  1480. int src_stride_v,
  1481. const uint8_t* src_a,
  1482. int src_stride_a,
  1483. uint8_t* dst_abgr,
  1484. int dst_stride_abgr,
  1485. int width,
  1486. int height,
  1487. int attenuate) {
  1488. return I420AlphaToARGBMatrix(
  1489. src_y, src_stride_y, src_v, src_stride_v, // Swap U and V
  1490. src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr,
  1491. &kYvuI601Constants, // Use Yvu matrix
  1492. width, height, attenuate);
  1493. }
  1494. // Convert I400 to ARGB with matrix.
  1495. LIBYUV_API
  1496. int I400ToARGBMatrix(const uint8_t* src_y,
  1497. int src_stride_y,
  1498. uint8_t* dst_argb,
  1499. int dst_stride_argb,
  1500. const struct YuvConstants* yuvconstants,
  1501. int width,
  1502. int height) {
  1503. int y;
  1504. void (*I400ToARGBRow)(const uint8_t* y_buf, uint8_t* rgb_buf,
  1505. const struct YuvConstants* yuvconstants, int width) =
  1506. I400ToARGBRow_C;
  1507. if (!src_y || !dst_argb || width <= 0 || height == 0) {
  1508. return -1;
  1509. }
  1510. // Negative height means invert the image.
  1511. if (height < 0) {
  1512. height = -height;
  1513. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  1514. dst_stride_argb = -dst_stride_argb;
  1515. }
  1516. // Coalesce rows.
  1517. if (src_stride_y == width && dst_stride_argb == width * 4) {
  1518. width *= height;
  1519. height = 1;
  1520. src_stride_y = dst_stride_argb = 0;
  1521. }
  1522. #if defined(HAS_I400TOARGBROW_SSE2)
  1523. if (TestCpuFlag(kCpuHasSSE2)) {
  1524. I400ToARGBRow = I400ToARGBRow_Any_SSE2;
  1525. if (IS_ALIGNED(width, 8)) {
  1526. I400ToARGBRow = I400ToARGBRow_SSE2;
  1527. }
  1528. }
  1529. #endif
  1530. #if defined(HAS_I400TOARGBROW_AVX2)
  1531. if (TestCpuFlag(kCpuHasAVX2)) {
  1532. I400ToARGBRow = I400ToARGBRow_Any_AVX2;
  1533. if (IS_ALIGNED(width, 16)) {
  1534. I400ToARGBRow = I400ToARGBRow_AVX2;
  1535. }
  1536. }
  1537. #endif
  1538. #if defined(HAS_I400TOARGBROW_NEON)
  1539. if (TestCpuFlag(kCpuHasNEON)) {
  1540. I400ToARGBRow = I400ToARGBRow_Any_NEON;
  1541. if (IS_ALIGNED(width, 8)) {
  1542. I400ToARGBRow = I400ToARGBRow_NEON;
  1543. }
  1544. }
  1545. #endif
  1546. #if defined(HAS_I400TOARGBROW_MMI)
  1547. if (TestCpuFlag(kCpuHasMMI)) {
  1548. I400ToARGBRow = I400ToARGBRow_Any_MMI;
  1549. if (IS_ALIGNED(width, 8)) {
  1550. I400ToARGBRow = I400ToARGBRow_MMI;
  1551. }
  1552. }
  1553. #endif
  1554. #if defined(HAS_I400TOARGBROW_MSA)
  1555. if (TestCpuFlag(kCpuHasMSA)) {
  1556. I400ToARGBRow = I400ToARGBRow_Any_MSA;
  1557. if (IS_ALIGNED(width, 16)) {
  1558. I400ToARGBRow = I400ToARGBRow_MSA;
  1559. }
  1560. }
  1561. #endif
  1562. for (y = 0; y < height; ++y) {
  1563. I400ToARGBRow(src_y, dst_argb, yuvconstants, width);
  1564. dst_argb += dst_stride_argb;
  1565. src_y += src_stride_y;
  1566. }
  1567. return 0;
  1568. }
  1569. // Convert I400 to ARGB.
  1570. LIBYUV_API
  1571. int I400ToARGB(const uint8_t* src_y,
  1572. int src_stride_y,
  1573. uint8_t* dst_argb,
  1574. int dst_stride_argb,
  1575. int width,
  1576. int height) {
  1577. return I400ToARGBMatrix(src_y, src_stride_y, dst_argb, dst_stride_argb,
  1578. &kYuvI601Constants, width, height);
  1579. }
  1580. // Convert J400 to ARGB.
  1581. LIBYUV_API
  1582. int J400ToARGB(const uint8_t* src_y,
  1583. int src_stride_y,
  1584. uint8_t* dst_argb,
  1585. int dst_stride_argb,
  1586. int width,
  1587. int height) {
  1588. int y;
  1589. void (*J400ToARGBRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) =
  1590. J400ToARGBRow_C;
  1591. if (!src_y || !dst_argb || width <= 0 || height == 0) {
  1592. return -1;
  1593. }
  1594. // Negative height means invert the image.
  1595. if (height < 0) {
  1596. height = -height;
  1597. src_y = src_y + (height - 1) * src_stride_y;
  1598. src_stride_y = -src_stride_y;
  1599. }
  1600. // Coalesce rows.
  1601. if (src_stride_y == width && dst_stride_argb == width * 4) {
  1602. width *= height;
  1603. height = 1;
  1604. src_stride_y = dst_stride_argb = 0;
  1605. }
  1606. #if defined(HAS_J400TOARGBROW_SSE2)
  1607. if (TestCpuFlag(kCpuHasSSE2)) {
  1608. J400ToARGBRow = J400ToARGBRow_Any_SSE2;
  1609. if (IS_ALIGNED(width, 8)) {
  1610. J400ToARGBRow = J400ToARGBRow_SSE2;
  1611. }
  1612. }
  1613. #endif
  1614. #if defined(HAS_J400TOARGBROW_AVX2)
  1615. if (TestCpuFlag(kCpuHasAVX2)) {
  1616. J400ToARGBRow = J400ToARGBRow_Any_AVX2;
  1617. if (IS_ALIGNED(width, 16)) {
  1618. J400ToARGBRow = J400ToARGBRow_AVX2;
  1619. }
  1620. }
  1621. #endif
  1622. #if defined(HAS_J400TOARGBROW_NEON)
  1623. if (TestCpuFlag(kCpuHasNEON)) {
  1624. J400ToARGBRow = J400ToARGBRow_Any_NEON;
  1625. if (IS_ALIGNED(width, 8)) {
  1626. J400ToARGBRow = J400ToARGBRow_NEON;
  1627. }
  1628. }
  1629. #endif
  1630. #if defined(HAS_J400TOARGBROW_MMI)
  1631. if (TestCpuFlag(kCpuHasMMI)) {
  1632. J400ToARGBRow = J400ToARGBRow_Any_MMI;
  1633. if (IS_ALIGNED(width, 4)) {
  1634. J400ToARGBRow = J400ToARGBRow_MMI;
  1635. }
  1636. }
  1637. #endif
  1638. #if defined(HAS_J400TOARGBROW_MSA)
  1639. if (TestCpuFlag(kCpuHasMSA)) {
  1640. J400ToARGBRow = J400ToARGBRow_Any_MSA;
  1641. if (IS_ALIGNED(width, 16)) {
  1642. J400ToARGBRow = J400ToARGBRow_MSA;
  1643. }
  1644. }
  1645. #endif
  1646. for (y = 0; y < height; ++y) {
  1647. J400ToARGBRow(src_y, dst_argb, width);
  1648. src_y += src_stride_y;
  1649. dst_argb += dst_stride_argb;
  1650. }
  1651. return 0;
  1652. }
  1653. // Shuffle table for converting BGRA to ARGB.
  1654. static const uvec8 kShuffleMaskBGRAToARGB = {
  1655. 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u};
  1656. // Shuffle table for converting ABGR to ARGB.
  1657. static const uvec8 kShuffleMaskABGRToARGB = {
  1658. 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u};
  1659. // Shuffle table for converting RGBA to ARGB.
  1660. static const uvec8 kShuffleMaskRGBAToARGB = {
  1661. 1u, 2u, 3u, 0u, 5u, 6u, 7u, 4u, 9u, 10u, 11u, 8u, 13u, 14u, 15u, 12u};
  1662. // Convert BGRA to ARGB.
  1663. LIBYUV_API
  1664. int BGRAToARGB(const uint8_t* src_bgra,
  1665. int src_stride_bgra,
  1666. uint8_t* dst_argb,
  1667. int dst_stride_argb,
  1668. int width,
  1669. int height) {
  1670. return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb,
  1671. (const uint8_t*)(&kShuffleMaskBGRAToARGB), width, height);
  1672. }
  1673. // Convert ARGB to BGRA (same as BGRAToARGB).
  1674. LIBYUV_API
  1675. int ARGBToBGRA(const uint8_t* src_bgra,
  1676. int src_stride_bgra,
  1677. uint8_t* dst_argb,
  1678. int dst_stride_argb,
  1679. int width,
  1680. int height) {
  1681. return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb,
  1682. (const uint8_t*)(&kShuffleMaskBGRAToARGB), width, height);
  1683. }
  1684. // Convert ABGR to ARGB.
  1685. LIBYUV_API
  1686. int ABGRToARGB(const uint8_t* src_abgr,
  1687. int src_stride_abgr,
  1688. uint8_t* dst_argb,
  1689. int dst_stride_argb,
  1690. int width,
  1691. int height) {
  1692. return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb,
  1693. (const uint8_t*)(&kShuffleMaskABGRToARGB), width, height);
  1694. }
  1695. // Convert ARGB to ABGR to (same as ABGRToARGB).
  1696. LIBYUV_API
  1697. int ARGBToABGR(const uint8_t* src_abgr,
  1698. int src_stride_abgr,
  1699. uint8_t* dst_argb,
  1700. int dst_stride_argb,
  1701. int width,
  1702. int height) {
  1703. return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb,
  1704. (const uint8_t*)(&kShuffleMaskABGRToARGB), width, height);
  1705. }
  1706. // Convert RGBA to ARGB.
  1707. LIBYUV_API
  1708. int RGBAToARGB(const uint8_t* src_rgba,
  1709. int src_stride_rgba,
  1710. uint8_t* dst_argb,
  1711. int dst_stride_argb,
  1712. int width,
  1713. int height) {
  1714. return ARGBShuffle(src_rgba, src_stride_rgba, dst_argb, dst_stride_argb,
  1715. (const uint8_t*)(&kShuffleMaskRGBAToARGB), width, height);
  1716. }
  1717. // Convert RGB24 to ARGB.
  1718. LIBYUV_API
  1719. int RGB24ToARGB(const uint8_t* src_rgb24,
  1720. int src_stride_rgb24,
  1721. uint8_t* dst_argb,
  1722. int dst_stride_argb,
  1723. int width,
  1724. int height) {
  1725. int y;
  1726. void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) =
  1727. RGB24ToARGBRow_C;
  1728. if (!src_rgb24 || !dst_argb || width <= 0 || height == 0) {
  1729. return -1;
  1730. }
  1731. // Negative height means invert the image.
  1732. if (height < 0) {
  1733. height = -height;
  1734. src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24;
  1735. src_stride_rgb24 = -src_stride_rgb24;
  1736. }
  1737. // Coalesce rows.
  1738. if (src_stride_rgb24 == width * 3 && dst_stride_argb == width * 4) {
  1739. width *= height;
  1740. height = 1;
  1741. src_stride_rgb24 = dst_stride_argb = 0;
  1742. }
  1743. #if defined(HAS_RGB24TOARGBROW_SSSE3)
  1744. if (TestCpuFlag(kCpuHasSSSE3)) {
  1745. RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3;
  1746. if (IS_ALIGNED(width, 16)) {
  1747. RGB24ToARGBRow = RGB24ToARGBRow_SSSE3;
  1748. }
  1749. }
  1750. #endif
  1751. #if defined(HAS_RGB24TOARGBROW_NEON)
  1752. if (TestCpuFlag(kCpuHasNEON)) {
  1753. RGB24ToARGBRow = RGB24ToARGBRow_Any_NEON;
  1754. if (IS_ALIGNED(width, 8)) {
  1755. RGB24ToARGBRow = RGB24ToARGBRow_NEON;
  1756. }
  1757. }
  1758. #endif
  1759. #if defined(HAS_RGB24TOARGBROW_MMI)
  1760. if (TestCpuFlag(kCpuHasMMI)) {
  1761. RGB24ToARGBRow = RGB24ToARGBRow_Any_MMI;
  1762. if (IS_ALIGNED(width, 4)) {
  1763. RGB24ToARGBRow = RGB24ToARGBRow_MMI;
  1764. }
  1765. }
  1766. #endif
  1767. #if defined(HAS_RGB24TOARGBROW_MSA)
  1768. if (TestCpuFlag(kCpuHasMSA)) {
  1769. RGB24ToARGBRow = RGB24ToARGBRow_Any_MSA;
  1770. if (IS_ALIGNED(width, 16)) {
  1771. RGB24ToARGBRow = RGB24ToARGBRow_MSA;
  1772. }
  1773. }
  1774. #endif
  1775. for (y = 0; y < height; ++y) {
  1776. RGB24ToARGBRow(src_rgb24, dst_argb, width);
  1777. src_rgb24 += src_stride_rgb24;
  1778. dst_argb += dst_stride_argb;
  1779. }
  1780. return 0;
  1781. }
  1782. // Convert RAW to ARGB.
  1783. LIBYUV_API
  1784. int RAWToARGB(const uint8_t* src_raw,
  1785. int src_stride_raw,
  1786. uint8_t* dst_argb,
  1787. int dst_stride_argb,
  1788. int width,
  1789. int height) {
  1790. int y;
  1791. void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) =
  1792. RAWToARGBRow_C;
  1793. if (!src_raw || !dst_argb || width <= 0 || height == 0) {
  1794. return -1;
  1795. }
  1796. // Negative height means invert the image.
  1797. if (height < 0) {
  1798. height = -height;
  1799. src_raw = src_raw + (height - 1) * src_stride_raw;
  1800. src_stride_raw = -src_stride_raw;
  1801. }
  1802. // Coalesce rows.
  1803. if (src_stride_raw == width * 3 && dst_stride_argb == width * 4) {
  1804. width *= height;
  1805. height = 1;
  1806. src_stride_raw = dst_stride_argb = 0;
  1807. }
  1808. #if defined(HAS_RAWTOARGBROW_SSSE3)
  1809. if (TestCpuFlag(kCpuHasSSSE3)) {
  1810. RAWToARGBRow = RAWToARGBRow_Any_SSSE3;
  1811. if (IS_ALIGNED(width, 16)) {
  1812. RAWToARGBRow = RAWToARGBRow_SSSE3;
  1813. }
  1814. }
  1815. #endif
  1816. #if defined(HAS_RAWTOARGBROW_NEON)
  1817. if (TestCpuFlag(kCpuHasNEON)) {
  1818. RAWToARGBRow = RAWToARGBRow_Any_NEON;
  1819. if (IS_ALIGNED(width, 8)) {
  1820. RAWToARGBRow = RAWToARGBRow_NEON;
  1821. }
  1822. }
  1823. #endif
  1824. #if defined(HAS_RAWTOARGBROW_MMI)
  1825. if (TestCpuFlag(kCpuHasMMI)) {
  1826. RAWToARGBRow = RAWToARGBRow_Any_MMI;
  1827. if (IS_ALIGNED(width, 4)) {
  1828. RAWToARGBRow = RAWToARGBRow_MMI;
  1829. }
  1830. }
  1831. #endif
  1832. #if defined(HAS_RAWTOARGBROW_MSA)
  1833. if (TestCpuFlag(kCpuHasMSA)) {
  1834. RAWToARGBRow = RAWToARGBRow_Any_MSA;
  1835. if (IS_ALIGNED(width, 16)) {
  1836. RAWToARGBRow = RAWToARGBRow_MSA;
  1837. }
  1838. }
  1839. #endif
  1840. for (y = 0; y < height; ++y) {
  1841. RAWToARGBRow(src_raw, dst_argb, width);
  1842. src_raw += src_stride_raw;
  1843. dst_argb += dst_stride_argb;
  1844. }
  1845. return 0;
  1846. }
  1847. // Convert RAW to RGBA.
  1848. LIBYUV_API
  1849. int RAWToRGBA(const uint8_t* src_raw,
  1850. int src_stride_raw,
  1851. uint8_t* dst_rgba,
  1852. int dst_stride_rgba,
  1853. int width,
  1854. int height) {
  1855. int y;
  1856. void (*RAWToRGBARow)(const uint8_t* src_rgb, uint8_t* dst_rgba, int width) =
  1857. RAWToRGBARow_C;
  1858. if (!src_raw || !dst_rgba || width <= 0 || height == 0) {
  1859. return -1;
  1860. }
  1861. // Negative height means invert the image.
  1862. if (height < 0) {
  1863. height = -height;
  1864. src_raw = src_raw + (height - 1) * src_stride_raw;
  1865. src_stride_raw = -src_stride_raw;
  1866. }
  1867. // Coalesce rows.
  1868. if (src_stride_raw == width * 3 && dst_stride_rgba == width * 4) {
  1869. width *= height;
  1870. height = 1;
  1871. src_stride_raw = dst_stride_rgba = 0;
  1872. }
  1873. #if defined(HAS_RAWTORGBAROW_SSSE3)
  1874. if (TestCpuFlag(kCpuHasSSSE3)) {
  1875. RAWToRGBARow = RAWToRGBARow_Any_SSSE3;
  1876. if (IS_ALIGNED(width, 16)) {
  1877. RAWToRGBARow = RAWToRGBARow_SSSE3;
  1878. }
  1879. }
  1880. #endif
  1881. #if defined(HAS_RAWTORGBAROW_NEON)
  1882. if (TestCpuFlag(kCpuHasNEON)) {
  1883. RAWToRGBARow = RAWToRGBARow_Any_NEON;
  1884. if (IS_ALIGNED(width, 8)) {
  1885. RAWToRGBARow = RAWToRGBARow_NEON;
  1886. }
  1887. }
  1888. #endif
  1889. for (y = 0; y < height; ++y) {
  1890. RAWToRGBARow(src_raw, dst_rgba, width);
  1891. src_raw += src_stride_raw;
  1892. dst_rgba += dst_stride_rgba;
  1893. }
  1894. return 0;
  1895. }
  1896. // Convert RGB565 to ARGB.
  1897. LIBYUV_API
  1898. int RGB565ToARGB(const uint8_t* src_rgb565,
  1899. int src_stride_rgb565,
  1900. uint8_t* dst_argb,
  1901. int dst_stride_argb,
  1902. int width,
  1903. int height) {
  1904. int y;
  1905. void (*RGB565ToARGBRow)(const uint8_t* src_rgb565, uint8_t* dst_argb,
  1906. int width) = RGB565ToARGBRow_C;
  1907. if (!src_rgb565 || !dst_argb || width <= 0 || height == 0) {
  1908. return -1;
  1909. }
  1910. // Negative height means invert the image.
  1911. if (height < 0) {
  1912. height = -height;
  1913. src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565;
  1914. src_stride_rgb565 = -src_stride_rgb565;
  1915. }
  1916. // Coalesce rows.
  1917. if (src_stride_rgb565 == width * 2 && dst_stride_argb == width * 4) {
  1918. width *= height;
  1919. height = 1;
  1920. src_stride_rgb565 = dst_stride_argb = 0;
  1921. }
  1922. #if defined(HAS_RGB565TOARGBROW_SSE2)
  1923. if (TestCpuFlag(kCpuHasSSE2)) {
  1924. RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2;
  1925. if (IS_ALIGNED(width, 8)) {
  1926. RGB565ToARGBRow = RGB565ToARGBRow_SSE2;
  1927. }
  1928. }
  1929. #endif
  1930. #if defined(HAS_RGB565TOARGBROW_AVX2)
  1931. if (TestCpuFlag(kCpuHasAVX2)) {
  1932. RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2;
  1933. if (IS_ALIGNED(width, 16)) {
  1934. RGB565ToARGBRow = RGB565ToARGBRow_AVX2;
  1935. }
  1936. }
  1937. #endif
  1938. #if defined(HAS_RGB565TOARGBROW_NEON)
  1939. if (TestCpuFlag(kCpuHasNEON)) {
  1940. RGB565ToARGBRow = RGB565ToARGBRow_Any_NEON;
  1941. if (IS_ALIGNED(width, 8)) {
  1942. RGB565ToARGBRow = RGB565ToARGBRow_NEON;
  1943. }
  1944. }
  1945. #endif
  1946. #if defined(HAS_RGB565TOARGBROW_MMI)
  1947. if (TestCpuFlag(kCpuHasMMI)) {
  1948. RGB565ToARGBRow = RGB565ToARGBRow_Any_MMI;
  1949. if (IS_ALIGNED(width, 4)) {
  1950. RGB565ToARGBRow = RGB565ToARGBRow_MMI;
  1951. }
  1952. }
  1953. #endif
  1954. #if defined(HAS_RGB565TOARGBROW_MSA)
  1955. if (TestCpuFlag(kCpuHasMSA)) {
  1956. RGB565ToARGBRow = RGB565ToARGBRow_Any_MSA;
  1957. if (IS_ALIGNED(width, 16)) {
  1958. RGB565ToARGBRow = RGB565ToARGBRow_MSA;
  1959. }
  1960. }
  1961. #endif
  1962. for (y = 0; y < height; ++y) {
  1963. RGB565ToARGBRow(src_rgb565, dst_argb, width);
  1964. src_rgb565 += src_stride_rgb565;
  1965. dst_argb += dst_stride_argb;
  1966. }
  1967. return 0;
  1968. }
  1969. // Convert ARGB1555 to ARGB.
  1970. LIBYUV_API
  1971. int ARGB1555ToARGB(const uint8_t* src_argb1555,
  1972. int src_stride_argb1555,
  1973. uint8_t* dst_argb,
  1974. int dst_stride_argb,
  1975. int width,
  1976. int height) {
  1977. int y;
  1978. void (*ARGB1555ToARGBRow)(const uint8_t* src_argb1555, uint8_t* dst_argb,
  1979. int width) = ARGB1555ToARGBRow_C;
  1980. if (!src_argb1555 || !dst_argb || width <= 0 || height == 0) {
  1981. return -1;
  1982. }
  1983. // Negative height means invert the image.
  1984. if (height < 0) {
  1985. height = -height;
  1986. src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555;
  1987. src_stride_argb1555 = -src_stride_argb1555;
  1988. }
  1989. // Coalesce rows.
  1990. if (src_stride_argb1555 == width * 2 && dst_stride_argb == width * 4) {
  1991. width *= height;
  1992. height = 1;
  1993. src_stride_argb1555 = dst_stride_argb = 0;
  1994. }
  1995. #if defined(HAS_ARGB1555TOARGBROW_SSE2)
  1996. if (TestCpuFlag(kCpuHasSSE2)) {
  1997. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2;
  1998. if (IS_ALIGNED(width, 8)) {
  1999. ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2;
  2000. }
  2001. }
  2002. #endif
  2003. #if defined(HAS_ARGB1555TOARGBROW_AVX2)
  2004. if (TestCpuFlag(kCpuHasAVX2)) {
  2005. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2;
  2006. if (IS_ALIGNED(width, 16)) {
  2007. ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX2;
  2008. }
  2009. }
  2010. #endif
  2011. #if defined(HAS_ARGB1555TOARGBROW_NEON)
  2012. if (TestCpuFlag(kCpuHasNEON)) {
  2013. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_NEON;
  2014. if (IS_ALIGNED(width, 8)) {
  2015. ARGB1555ToARGBRow = ARGB1555ToARGBRow_NEON;
  2016. }
  2017. }
  2018. #endif
  2019. #if defined(HAS_ARGB1555TOARGBROW_MMI)
  2020. if (TestCpuFlag(kCpuHasMMI)) {
  2021. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_MMI;
  2022. if (IS_ALIGNED(width, 4)) {
  2023. ARGB1555ToARGBRow = ARGB1555ToARGBRow_MMI;
  2024. }
  2025. }
  2026. #endif
  2027. #if defined(HAS_ARGB1555TOARGBROW_MSA)
  2028. if (TestCpuFlag(kCpuHasMSA)) {
  2029. ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_MSA;
  2030. if (IS_ALIGNED(width, 16)) {
  2031. ARGB1555ToARGBRow = ARGB1555ToARGBRow_MSA;
  2032. }
  2033. }
  2034. #endif
  2035. for (y = 0; y < height; ++y) {
  2036. ARGB1555ToARGBRow(src_argb1555, dst_argb, width);
  2037. src_argb1555 += src_stride_argb1555;
  2038. dst_argb += dst_stride_argb;
  2039. }
  2040. return 0;
  2041. }
  2042. // Convert ARGB4444 to ARGB.
  2043. LIBYUV_API
  2044. int ARGB4444ToARGB(const uint8_t* src_argb4444,
  2045. int src_stride_argb4444,
  2046. uint8_t* dst_argb,
  2047. int dst_stride_argb,
  2048. int width,
  2049. int height) {
  2050. int y;
  2051. void (*ARGB4444ToARGBRow)(const uint8_t* src_argb4444, uint8_t* dst_argb,
  2052. int width) = ARGB4444ToARGBRow_C;
  2053. if (!src_argb4444 || !dst_argb || width <= 0 || height == 0) {
  2054. return -1;
  2055. }
  2056. // Negative height means invert the image.
  2057. if (height < 0) {
  2058. height = -height;
  2059. src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444;
  2060. src_stride_argb4444 = -src_stride_argb4444;
  2061. }
  2062. // Coalesce rows.
  2063. if (src_stride_argb4444 == width * 2 && dst_stride_argb == width * 4) {
  2064. width *= height;
  2065. height = 1;
  2066. src_stride_argb4444 = dst_stride_argb = 0;
  2067. }
  2068. #if defined(HAS_ARGB4444TOARGBROW_SSE2)
  2069. if (TestCpuFlag(kCpuHasSSE2)) {
  2070. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2;
  2071. if (IS_ALIGNED(width, 8)) {
  2072. ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2;
  2073. }
  2074. }
  2075. #endif
  2076. #if defined(HAS_ARGB4444TOARGBROW_AVX2)
  2077. if (TestCpuFlag(kCpuHasAVX2)) {
  2078. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2;
  2079. if (IS_ALIGNED(width, 16)) {
  2080. ARGB4444ToARGBRow = ARGB4444ToARGBRow_AVX2;
  2081. }
  2082. }
  2083. #endif
  2084. #if defined(HAS_ARGB4444TOARGBROW_NEON)
  2085. if (TestCpuFlag(kCpuHasNEON)) {
  2086. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_NEON;
  2087. if (IS_ALIGNED(width, 8)) {
  2088. ARGB4444ToARGBRow = ARGB4444ToARGBRow_NEON;
  2089. }
  2090. }
  2091. #endif
  2092. #if defined(HAS_ARGB4444TOARGBROW_MMI)
  2093. if (TestCpuFlag(kCpuHasMMI)) {
  2094. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MMI;
  2095. if (IS_ALIGNED(width, 4)) {
  2096. ARGB4444ToARGBRow = ARGB4444ToARGBRow_MMI;
  2097. }
  2098. }
  2099. #endif
  2100. #if defined(HAS_ARGB4444TOARGBROW_MSA)
  2101. if (TestCpuFlag(kCpuHasMSA)) {
  2102. ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MSA;
  2103. if (IS_ALIGNED(width, 16)) {
  2104. ARGB4444ToARGBRow = ARGB4444ToARGBRow_MSA;
  2105. }
  2106. }
  2107. #endif
  2108. for (y = 0; y < height; ++y) {
  2109. ARGB4444ToARGBRow(src_argb4444, dst_argb, width);
  2110. src_argb4444 += src_stride_argb4444;
  2111. dst_argb += dst_stride_argb;
  2112. }
  2113. return 0;
  2114. }
  2115. // Convert AR30 to ARGB.
  2116. LIBYUV_API
  2117. int AR30ToARGB(const uint8_t* src_ar30,
  2118. int src_stride_ar30,
  2119. uint8_t* dst_argb,
  2120. int dst_stride_argb,
  2121. int width,
  2122. int height) {
  2123. int y;
  2124. if (!src_ar30 || !dst_argb || width <= 0 || height == 0) {
  2125. return -1;
  2126. }
  2127. // Negative height means invert the image.
  2128. if (height < 0) {
  2129. height = -height;
  2130. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  2131. src_stride_ar30 = -src_stride_ar30;
  2132. }
  2133. // Coalesce rows.
  2134. if (src_stride_ar30 == width * 4 && dst_stride_argb == width * 4) {
  2135. width *= height;
  2136. height = 1;
  2137. src_stride_ar30 = dst_stride_argb = 0;
  2138. }
  2139. for (y = 0; y < height; ++y) {
  2140. AR30ToARGBRow_C(src_ar30, dst_argb, width);
  2141. src_ar30 += src_stride_ar30;
  2142. dst_argb += dst_stride_argb;
  2143. }
  2144. return 0;
  2145. }
  2146. // Convert AR30 to ABGR.
  2147. LIBYUV_API
  2148. int AR30ToABGR(const uint8_t* src_ar30,
  2149. int src_stride_ar30,
  2150. uint8_t* dst_abgr,
  2151. int dst_stride_abgr,
  2152. int width,
  2153. int height) {
  2154. int y;
  2155. if (!src_ar30 || !dst_abgr || width <= 0 || height == 0) {
  2156. return -1;
  2157. }
  2158. // Negative height means invert the image.
  2159. if (height < 0) {
  2160. height = -height;
  2161. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  2162. src_stride_ar30 = -src_stride_ar30;
  2163. }
  2164. // Coalesce rows.
  2165. if (src_stride_ar30 == width * 4 && dst_stride_abgr == width * 4) {
  2166. width *= height;
  2167. height = 1;
  2168. src_stride_ar30 = dst_stride_abgr = 0;
  2169. }
  2170. for (y = 0; y < height; ++y) {
  2171. AR30ToABGRRow_C(src_ar30, dst_abgr, width);
  2172. src_ar30 += src_stride_ar30;
  2173. dst_abgr += dst_stride_abgr;
  2174. }
  2175. return 0;
  2176. }
  2177. // Convert AR30 to AB30.
  2178. LIBYUV_API
  2179. int AR30ToAB30(const uint8_t* src_ar30,
  2180. int src_stride_ar30,
  2181. uint8_t* dst_ab30,
  2182. int dst_stride_ab30,
  2183. int width,
  2184. int height) {
  2185. int y;
  2186. if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0) {
  2187. return -1;
  2188. }
  2189. // Negative height means invert the image.
  2190. if (height < 0) {
  2191. height = -height;
  2192. src_ar30 = src_ar30 + (height - 1) * src_stride_ar30;
  2193. src_stride_ar30 = -src_stride_ar30;
  2194. }
  2195. // Coalesce rows.
  2196. if (src_stride_ar30 == width * 4 && dst_stride_ab30 == width * 4) {
  2197. width *= height;
  2198. height = 1;
  2199. src_stride_ar30 = dst_stride_ab30 = 0;
  2200. }
  2201. for (y = 0; y < height; ++y) {
  2202. AR30ToAB30Row_C(src_ar30, dst_ab30, width);
  2203. src_ar30 += src_stride_ar30;
  2204. dst_ab30 += dst_stride_ab30;
  2205. }
  2206. return 0;
  2207. }
  2208. // Convert NV12 to ARGB with matrix.
  2209. LIBYUV_API
  2210. int NV12ToARGBMatrix(const uint8_t* src_y,
  2211. int src_stride_y,
  2212. const uint8_t* src_uv,
  2213. int src_stride_uv,
  2214. uint8_t* dst_argb,
  2215. int dst_stride_argb,
  2216. const struct YuvConstants* yuvconstants,
  2217. int width,
  2218. int height) {
  2219. int y;
  2220. void (*NV12ToARGBRow)(
  2221. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  2222. const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C;
  2223. if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) {
  2224. return -1;
  2225. }
  2226. // Negative height means invert the image.
  2227. if (height < 0) {
  2228. height = -height;
  2229. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2230. dst_stride_argb = -dst_stride_argb;
  2231. }
  2232. #if defined(HAS_NV12TOARGBROW_SSSE3)
  2233. if (TestCpuFlag(kCpuHasSSSE3)) {
  2234. NV12ToARGBRow = NV12ToARGBRow_Any_SSSE3;
  2235. if (IS_ALIGNED(width, 8)) {
  2236. NV12ToARGBRow = NV12ToARGBRow_SSSE3;
  2237. }
  2238. }
  2239. #endif
  2240. #if defined(HAS_NV12TOARGBROW_AVX2)
  2241. if (TestCpuFlag(kCpuHasAVX2)) {
  2242. NV12ToARGBRow = NV12ToARGBRow_Any_AVX2;
  2243. if (IS_ALIGNED(width, 16)) {
  2244. NV12ToARGBRow = NV12ToARGBRow_AVX2;
  2245. }
  2246. }
  2247. #endif
  2248. #if defined(HAS_NV12TOARGBROW_NEON)
  2249. if (TestCpuFlag(kCpuHasNEON)) {
  2250. NV12ToARGBRow = NV12ToARGBRow_Any_NEON;
  2251. if (IS_ALIGNED(width, 8)) {
  2252. NV12ToARGBRow = NV12ToARGBRow_NEON;
  2253. }
  2254. }
  2255. #endif
  2256. #if defined(HAS_NV12TOARGBROW_MMI)
  2257. if (TestCpuFlag(kCpuHasMMI)) {
  2258. NV12ToARGBRow = NV12ToARGBRow_Any_MMI;
  2259. if (IS_ALIGNED(width, 4)) {
  2260. NV12ToARGBRow = NV12ToARGBRow_MMI;
  2261. }
  2262. }
  2263. #endif
  2264. #if defined(HAS_NV12TOARGBROW_MSA)
  2265. if (TestCpuFlag(kCpuHasMSA)) {
  2266. NV12ToARGBRow = NV12ToARGBRow_Any_MSA;
  2267. if (IS_ALIGNED(width, 8)) {
  2268. NV12ToARGBRow = NV12ToARGBRow_MSA;
  2269. }
  2270. }
  2271. #endif
  2272. for (y = 0; y < height; ++y) {
  2273. NV12ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width);
  2274. dst_argb += dst_stride_argb;
  2275. src_y += src_stride_y;
  2276. if (y & 1) {
  2277. src_uv += src_stride_uv;
  2278. }
  2279. }
  2280. return 0;
  2281. }
  2282. // Convert NV21 to ARGB with matrix.
  2283. LIBYUV_API
  2284. int NV21ToARGBMatrix(const uint8_t* src_y,
  2285. int src_stride_y,
  2286. const uint8_t* src_vu,
  2287. int src_stride_vu,
  2288. uint8_t* dst_argb,
  2289. int dst_stride_argb,
  2290. const struct YuvConstants* yuvconstants,
  2291. int width,
  2292. int height) {
  2293. int y;
  2294. void (*NV21ToARGBRow)(
  2295. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  2296. const struct YuvConstants* yuvconstants, int width) = NV21ToARGBRow_C;
  2297. if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0) {
  2298. return -1;
  2299. }
  2300. // Negative height means invert the image.
  2301. if (height < 0) {
  2302. height = -height;
  2303. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2304. dst_stride_argb = -dst_stride_argb;
  2305. }
  2306. #if defined(HAS_NV21TOARGBROW_SSSE3)
  2307. if (TestCpuFlag(kCpuHasSSSE3)) {
  2308. NV21ToARGBRow = NV21ToARGBRow_Any_SSSE3;
  2309. if (IS_ALIGNED(width, 8)) {
  2310. NV21ToARGBRow = NV21ToARGBRow_SSSE3;
  2311. }
  2312. }
  2313. #endif
  2314. #if defined(HAS_NV21TOARGBROW_AVX2)
  2315. if (TestCpuFlag(kCpuHasAVX2)) {
  2316. NV21ToARGBRow = NV21ToARGBRow_Any_AVX2;
  2317. if (IS_ALIGNED(width, 16)) {
  2318. NV21ToARGBRow = NV21ToARGBRow_AVX2;
  2319. }
  2320. }
  2321. #endif
  2322. #if defined(HAS_NV21TOARGBROW_NEON)
  2323. if (TestCpuFlag(kCpuHasNEON)) {
  2324. NV21ToARGBRow = NV21ToARGBRow_Any_NEON;
  2325. if (IS_ALIGNED(width, 8)) {
  2326. NV21ToARGBRow = NV21ToARGBRow_NEON;
  2327. }
  2328. }
  2329. #endif
  2330. #if defined(HAS_NV21TOARGBROW_MMI)
  2331. if (TestCpuFlag(kCpuHasMMI)) {
  2332. NV21ToARGBRow = NV21ToARGBRow_Any_MMI;
  2333. if (IS_ALIGNED(width, 4)) {
  2334. NV21ToARGBRow = NV21ToARGBRow_MMI;
  2335. }
  2336. }
  2337. #endif
  2338. #if defined(HAS_NV21TOARGBROW_MSA)
  2339. if (TestCpuFlag(kCpuHasMSA)) {
  2340. NV21ToARGBRow = NV21ToARGBRow_Any_MSA;
  2341. if (IS_ALIGNED(width, 8)) {
  2342. NV21ToARGBRow = NV21ToARGBRow_MSA;
  2343. }
  2344. }
  2345. #endif
  2346. for (y = 0; y < height; ++y) {
  2347. NV21ToARGBRow(src_y, src_vu, dst_argb, yuvconstants, width);
  2348. dst_argb += dst_stride_argb;
  2349. src_y += src_stride_y;
  2350. if (y & 1) {
  2351. src_vu += src_stride_vu;
  2352. }
  2353. }
  2354. return 0;
  2355. }
  2356. // Convert NV12 to ARGB.
  2357. LIBYUV_API
  2358. int NV12ToARGB(const uint8_t* src_y,
  2359. int src_stride_y,
  2360. const uint8_t* src_uv,
  2361. int src_stride_uv,
  2362. uint8_t* dst_argb,
  2363. int dst_stride_argb,
  2364. int width,
  2365. int height) {
  2366. return NV12ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_argb,
  2367. dst_stride_argb, &kYuvI601Constants, width, height);
  2368. }
  2369. // Convert NV21 to ARGB.
  2370. LIBYUV_API
  2371. int NV21ToARGB(const uint8_t* src_y,
  2372. int src_stride_y,
  2373. const uint8_t* src_vu,
  2374. int src_stride_vu,
  2375. uint8_t* dst_argb,
  2376. int dst_stride_argb,
  2377. int width,
  2378. int height) {
  2379. return NV21ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_argb,
  2380. dst_stride_argb, &kYuvI601Constants, width, height);
  2381. }
  2382. // Convert NV12 to ABGR.
  2383. // To output ABGR instead of ARGB swap the UV and use a mirrored yuv matrix.
  2384. // To swap the UV use NV12 instead of NV21.LIBYUV_API
  2385. LIBYUV_API
  2386. int NV12ToABGR(const uint8_t* src_y,
  2387. int src_stride_y,
  2388. const uint8_t* src_uv,
  2389. int src_stride_uv,
  2390. uint8_t* dst_abgr,
  2391. int dst_stride_abgr,
  2392. int width,
  2393. int height) {
  2394. return NV21ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_abgr,
  2395. dst_stride_abgr, &kYvuI601Constants, width, height);
  2396. }
  2397. // Convert NV21 to ABGR.
  2398. LIBYUV_API
  2399. int NV21ToABGR(const uint8_t* src_y,
  2400. int src_stride_y,
  2401. const uint8_t* src_vu,
  2402. int src_stride_vu,
  2403. uint8_t* dst_abgr,
  2404. int dst_stride_abgr,
  2405. int width,
  2406. int height) {
  2407. return NV12ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_abgr,
  2408. dst_stride_abgr, &kYvuI601Constants, width, height);
  2409. }
  2410. // TODO(fbarchard): Consider SSSE3 2 step conversion.
  2411. // Convert NV12 to RGB24 with matrix.
  2412. LIBYUV_API
  2413. int NV12ToRGB24Matrix(const uint8_t* src_y,
  2414. int src_stride_y,
  2415. const uint8_t* src_uv,
  2416. int src_stride_uv,
  2417. uint8_t* dst_rgb24,
  2418. int dst_stride_rgb24,
  2419. const struct YuvConstants* yuvconstants,
  2420. int width,
  2421. int height) {
  2422. int y;
  2423. void (*NV12ToRGB24Row)(
  2424. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  2425. const struct YuvConstants* yuvconstants, int width) = NV12ToRGB24Row_C;
  2426. if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0) {
  2427. return -1;
  2428. }
  2429. // Negative height means invert the image.
  2430. if (height < 0) {
  2431. height = -height;
  2432. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  2433. dst_stride_rgb24 = -dst_stride_rgb24;
  2434. }
  2435. #if defined(HAS_NV12TORGB24ROW_NEON)
  2436. if (TestCpuFlag(kCpuHasNEON)) {
  2437. NV12ToRGB24Row = NV12ToRGB24Row_Any_NEON;
  2438. if (IS_ALIGNED(width, 8)) {
  2439. NV12ToRGB24Row = NV12ToRGB24Row_NEON;
  2440. }
  2441. }
  2442. #endif
  2443. #if defined(HAS_NV12TORGB24ROW_SSSE3)
  2444. if (TestCpuFlag(kCpuHasSSSE3)) {
  2445. NV12ToRGB24Row = NV12ToRGB24Row_Any_SSSE3;
  2446. if (IS_ALIGNED(width, 16)) {
  2447. NV12ToRGB24Row = NV12ToRGB24Row_SSSE3;
  2448. }
  2449. }
  2450. #endif
  2451. #if defined(HAS_NV12TORGB24ROW_AVX2)
  2452. if (TestCpuFlag(kCpuHasAVX2)) {
  2453. NV12ToRGB24Row = NV12ToRGB24Row_Any_AVX2;
  2454. if (IS_ALIGNED(width, 32)) {
  2455. NV12ToRGB24Row = NV12ToRGB24Row_AVX2;
  2456. }
  2457. }
  2458. #endif
  2459. #if defined(HAS_NV12TORGB24ROW_MMI)
  2460. if (TestCpuFlag(kCpuHasMMI)) {
  2461. NV12ToRGB24Row = NV12ToRGB24Row_Any_MMI;
  2462. if (IS_ALIGNED(width, 8)) {
  2463. NV12ToRGB24Row = NV12ToRGB24Row_MMI;
  2464. }
  2465. }
  2466. #endif
  2467. for (y = 0; y < height; ++y) {
  2468. NV12ToRGB24Row(src_y, src_uv, dst_rgb24, yuvconstants, width);
  2469. dst_rgb24 += dst_stride_rgb24;
  2470. src_y += src_stride_y;
  2471. if (y & 1) {
  2472. src_uv += src_stride_uv;
  2473. }
  2474. }
  2475. return 0;
  2476. }
  2477. // Convert NV21 to RGB24 with matrix.
  2478. LIBYUV_API
  2479. int NV21ToRGB24Matrix(const uint8_t* src_y,
  2480. int src_stride_y,
  2481. const uint8_t* src_vu,
  2482. int src_stride_vu,
  2483. uint8_t* dst_rgb24,
  2484. int dst_stride_rgb24,
  2485. const struct YuvConstants* yuvconstants,
  2486. int width,
  2487. int height) {
  2488. int y;
  2489. void (*NV21ToRGB24Row)(
  2490. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  2491. const struct YuvConstants* yuvconstants, int width) = NV21ToRGB24Row_C;
  2492. if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0) {
  2493. return -1;
  2494. }
  2495. // Negative height means invert the image.
  2496. if (height < 0) {
  2497. height = -height;
  2498. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  2499. dst_stride_rgb24 = -dst_stride_rgb24;
  2500. }
  2501. #if defined(HAS_NV21TORGB24ROW_NEON)
  2502. if (TestCpuFlag(kCpuHasNEON)) {
  2503. NV21ToRGB24Row = NV21ToRGB24Row_Any_NEON;
  2504. if (IS_ALIGNED(width, 8)) {
  2505. NV21ToRGB24Row = NV21ToRGB24Row_NEON;
  2506. }
  2507. }
  2508. #endif
  2509. #if defined(HAS_NV21TORGB24ROW_SSSE3)
  2510. if (TestCpuFlag(kCpuHasSSSE3)) {
  2511. NV21ToRGB24Row = NV21ToRGB24Row_Any_SSSE3;
  2512. if (IS_ALIGNED(width, 16)) {
  2513. NV21ToRGB24Row = NV21ToRGB24Row_SSSE3;
  2514. }
  2515. }
  2516. #endif
  2517. #if defined(HAS_NV21TORGB24ROW_AVX2)
  2518. if (TestCpuFlag(kCpuHasAVX2)) {
  2519. NV21ToRGB24Row = NV21ToRGB24Row_Any_AVX2;
  2520. if (IS_ALIGNED(width, 32)) {
  2521. NV21ToRGB24Row = NV21ToRGB24Row_AVX2;
  2522. }
  2523. }
  2524. #endif
  2525. #if defined(HAS_NV21TORGB24ROW_MMI)
  2526. if (TestCpuFlag(kCpuHasMMI)) {
  2527. NV21ToRGB24Row = NV21ToRGB24Row_Any_MMI;
  2528. if (IS_ALIGNED(width, 8)) {
  2529. NV21ToRGB24Row = NV21ToRGB24Row_MMI;
  2530. }
  2531. }
  2532. #endif
  2533. for (y = 0; y < height; ++y) {
  2534. NV21ToRGB24Row(src_y, src_vu, dst_rgb24, yuvconstants, width);
  2535. dst_rgb24 += dst_stride_rgb24;
  2536. src_y += src_stride_y;
  2537. if (y & 1) {
  2538. src_vu += src_stride_vu;
  2539. }
  2540. }
  2541. return 0;
  2542. }
  2543. // Convert NV12 to RGB24.
  2544. LIBYUV_API
  2545. int NV12ToRGB24(const uint8_t* src_y,
  2546. int src_stride_y,
  2547. const uint8_t* src_uv,
  2548. int src_stride_uv,
  2549. uint8_t* dst_rgb24,
  2550. int dst_stride_rgb24,
  2551. int width,
  2552. int height) {
  2553. return NV12ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  2554. dst_rgb24, dst_stride_rgb24, &kYuvI601Constants,
  2555. width, height);
  2556. }
  2557. // Convert NV21 to RGB24.
  2558. LIBYUV_API
  2559. int NV21ToRGB24(const uint8_t* src_y,
  2560. int src_stride_y,
  2561. const uint8_t* src_vu,
  2562. int src_stride_vu,
  2563. uint8_t* dst_rgb24,
  2564. int dst_stride_rgb24,
  2565. int width,
  2566. int height) {
  2567. return NV21ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu,
  2568. dst_rgb24, dst_stride_rgb24, &kYuvI601Constants,
  2569. width, height);
  2570. }
  2571. // Convert NV12 to RAW.
  2572. LIBYUV_API
  2573. int NV12ToRAW(const uint8_t* src_y,
  2574. int src_stride_y,
  2575. const uint8_t* src_uv,
  2576. int src_stride_uv,
  2577. uint8_t* dst_raw,
  2578. int dst_stride_raw,
  2579. int width,
  2580. int height) {
  2581. return NV21ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_raw,
  2582. dst_stride_raw, &kYvuI601Constants, width, height);
  2583. }
  2584. // Convert NV21 to RAW.
  2585. LIBYUV_API
  2586. int NV21ToRAW(const uint8_t* src_y,
  2587. int src_stride_y,
  2588. const uint8_t* src_vu,
  2589. int src_stride_vu,
  2590. uint8_t* dst_raw,
  2591. int dst_stride_raw,
  2592. int width,
  2593. int height) {
  2594. return NV12ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_raw,
  2595. dst_stride_raw, &kYvuI601Constants, width, height);
  2596. }
  2597. // Convert NV21 to YUV24
  2598. int NV21ToYUV24(const uint8_t* src_y,
  2599. int src_stride_y,
  2600. const uint8_t* src_vu,
  2601. int src_stride_vu,
  2602. uint8_t* dst_yuv24,
  2603. int dst_stride_yuv24,
  2604. int width,
  2605. int height) {
  2606. int y;
  2607. void (*NV21ToYUV24Row)(const uint8_t* src_y, const uint8_t* src_vu,
  2608. uint8_t* dst_yuv24, int width) = NV21ToYUV24Row_C;
  2609. if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0) {
  2610. return -1;
  2611. }
  2612. // Negative height means invert the image.
  2613. if (height < 0) {
  2614. height = -height;
  2615. dst_yuv24 = dst_yuv24 + (height - 1) * dst_stride_yuv24;
  2616. dst_stride_yuv24 = -dst_stride_yuv24;
  2617. }
  2618. #if defined(HAS_NV21TOYUV24ROW_NEON)
  2619. if (TestCpuFlag(kCpuHasNEON)) {
  2620. NV21ToYUV24Row = NV21ToYUV24Row_Any_NEON;
  2621. if (IS_ALIGNED(width, 16)) {
  2622. NV21ToYUV24Row = NV21ToYUV24Row_NEON;
  2623. }
  2624. }
  2625. #endif
  2626. #if defined(HAS_NV21TOYUV24ROW_AVX2)
  2627. if (TestCpuFlag(kCpuHasAVX2)) {
  2628. NV21ToYUV24Row = NV21ToYUV24Row_Any_AVX2;
  2629. if (IS_ALIGNED(width, 32)) {
  2630. NV21ToYUV24Row = NV21ToYUV24Row_AVX2;
  2631. }
  2632. }
  2633. #endif
  2634. for (y = 0; y < height; ++y) {
  2635. NV21ToYUV24Row(src_y, src_vu, dst_yuv24, width);
  2636. dst_yuv24 += dst_stride_yuv24;
  2637. src_y += src_stride_y;
  2638. if (y & 1) {
  2639. src_vu += src_stride_vu;
  2640. }
  2641. }
  2642. return 0;
  2643. }
  2644. // Convert YUY2 to ARGB.
  2645. LIBYUV_API
  2646. int YUY2ToARGB(const uint8_t* src_yuy2,
  2647. int src_stride_yuy2,
  2648. uint8_t* dst_argb,
  2649. int dst_stride_argb,
  2650. int width,
  2651. int height) {
  2652. int y;
  2653. void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb,
  2654. const struct YuvConstants* yuvconstants, int width) =
  2655. YUY2ToARGBRow_C;
  2656. if (!src_yuy2 || !dst_argb || width <= 0 || height == 0) {
  2657. return -1;
  2658. }
  2659. // Negative height means invert the image.
  2660. if (height < 0) {
  2661. height = -height;
  2662. src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2;
  2663. src_stride_yuy2 = -src_stride_yuy2;
  2664. }
  2665. // Coalesce rows.
  2666. if (src_stride_yuy2 == width * 2 && dst_stride_argb == width * 4) {
  2667. width *= height;
  2668. height = 1;
  2669. src_stride_yuy2 = dst_stride_argb = 0;
  2670. }
  2671. #if defined(HAS_YUY2TOARGBROW_SSSE3)
  2672. if (TestCpuFlag(kCpuHasSSSE3)) {
  2673. YUY2ToARGBRow = YUY2ToARGBRow_Any_SSSE3;
  2674. if (IS_ALIGNED(width, 16)) {
  2675. YUY2ToARGBRow = YUY2ToARGBRow_SSSE3;
  2676. }
  2677. }
  2678. #endif
  2679. #if defined(HAS_YUY2TOARGBROW_AVX2)
  2680. if (TestCpuFlag(kCpuHasAVX2)) {
  2681. YUY2ToARGBRow = YUY2ToARGBRow_Any_AVX2;
  2682. if (IS_ALIGNED(width, 32)) {
  2683. YUY2ToARGBRow = YUY2ToARGBRow_AVX2;
  2684. }
  2685. }
  2686. #endif
  2687. #if defined(HAS_YUY2TOARGBROW_NEON)
  2688. if (TestCpuFlag(kCpuHasNEON)) {
  2689. YUY2ToARGBRow = YUY2ToARGBRow_Any_NEON;
  2690. if (IS_ALIGNED(width, 8)) {
  2691. YUY2ToARGBRow = YUY2ToARGBRow_NEON;
  2692. }
  2693. }
  2694. #endif
  2695. #if defined(HAS_YUY2TOARGBROW_MMI)
  2696. if (TestCpuFlag(kCpuHasMMI)) {
  2697. YUY2ToARGBRow = YUY2ToARGBRow_Any_MMI;
  2698. if (IS_ALIGNED(width, 4)) {
  2699. YUY2ToARGBRow = YUY2ToARGBRow_MMI;
  2700. }
  2701. }
  2702. #endif
  2703. #if defined(HAS_YUY2TOARGBROW_MSA)
  2704. if (TestCpuFlag(kCpuHasMSA)) {
  2705. YUY2ToARGBRow = YUY2ToARGBRow_Any_MSA;
  2706. if (IS_ALIGNED(width, 8)) {
  2707. YUY2ToARGBRow = YUY2ToARGBRow_MSA;
  2708. }
  2709. }
  2710. #endif
  2711. for (y = 0; y < height; ++y) {
  2712. YUY2ToARGBRow(src_yuy2, dst_argb, &kYuvI601Constants, width);
  2713. src_yuy2 += src_stride_yuy2;
  2714. dst_argb += dst_stride_argb;
  2715. }
  2716. return 0;
  2717. }
  2718. // Convert UYVY to ARGB.
  2719. LIBYUV_API
  2720. int UYVYToARGB(const uint8_t* src_uyvy,
  2721. int src_stride_uyvy,
  2722. uint8_t* dst_argb,
  2723. int dst_stride_argb,
  2724. int width,
  2725. int height) {
  2726. int y;
  2727. void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb,
  2728. const struct YuvConstants* yuvconstants, int width) =
  2729. UYVYToARGBRow_C;
  2730. if (!src_uyvy || !dst_argb || width <= 0 || height == 0) {
  2731. return -1;
  2732. }
  2733. // Negative height means invert the image.
  2734. if (height < 0) {
  2735. height = -height;
  2736. src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy;
  2737. src_stride_uyvy = -src_stride_uyvy;
  2738. }
  2739. // Coalesce rows.
  2740. if (src_stride_uyvy == width * 2 && dst_stride_argb == width * 4) {
  2741. width *= height;
  2742. height = 1;
  2743. src_stride_uyvy = dst_stride_argb = 0;
  2744. }
  2745. #if defined(HAS_UYVYTOARGBROW_SSSE3)
  2746. if (TestCpuFlag(kCpuHasSSSE3)) {
  2747. UYVYToARGBRow = UYVYToARGBRow_Any_SSSE3;
  2748. if (IS_ALIGNED(width, 16)) {
  2749. UYVYToARGBRow = UYVYToARGBRow_SSSE3;
  2750. }
  2751. }
  2752. #endif
  2753. #if defined(HAS_UYVYTOARGBROW_AVX2)
  2754. if (TestCpuFlag(kCpuHasAVX2)) {
  2755. UYVYToARGBRow = UYVYToARGBRow_Any_AVX2;
  2756. if (IS_ALIGNED(width, 32)) {
  2757. UYVYToARGBRow = UYVYToARGBRow_AVX2;
  2758. }
  2759. }
  2760. #endif
  2761. #if defined(HAS_UYVYTOARGBROW_NEON)
  2762. if (TestCpuFlag(kCpuHasNEON)) {
  2763. UYVYToARGBRow = UYVYToARGBRow_Any_NEON;
  2764. if (IS_ALIGNED(width, 8)) {
  2765. UYVYToARGBRow = UYVYToARGBRow_NEON;
  2766. }
  2767. }
  2768. #endif
  2769. #if defined(HAS_UYVYTOARGBROW_MMI)
  2770. if (TestCpuFlag(kCpuHasMMI)) {
  2771. UYVYToARGBRow = UYVYToARGBRow_Any_MMI;
  2772. if (IS_ALIGNED(width, 4)) {
  2773. UYVYToARGBRow = UYVYToARGBRow_MMI;
  2774. }
  2775. }
  2776. #endif
  2777. #if defined(HAS_UYVYTOARGBROW_MSA)
  2778. if (TestCpuFlag(kCpuHasMSA)) {
  2779. UYVYToARGBRow = UYVYToARGBRow_Any_MSA;
  2780. if (IS_ALIGNED(width, 8)) {
  2781. UYVYToARGBRow = UYVYToARGBRow_MSA;
  2782. }
  2783. }
  2784. #endif
  2785. for (y = 0; y < height; ++y) {
  2786. UYVYToARGBRow(src_uyvy, dst_argb, &kYuvI601Constants, width);
  2787. src_uyvy += src_stride_uyvy;
  2788. dst_argb += dst_stride_argb;
  2789. }
  2790. return 0;
  2791. }
  2792. static void WeavePixels(const uint8_t* src_u,
  2793. const uint8_t* src_v,
  2794. int src_pixel_stride_uv,
  2795. uint8_t* dst_uv,
  2796. int width) {
  2797. int i;
  2798. for (i = 0; i < width; ++i) {
  2799. dst_uv[0] = *src_u;
  2800. dst_uv[1] = *src_v;
  2801. dst_uv += 2;
  2802. src_u += src_pixel_stride_uv;
  2803. src_v += src_pixel_stride_uv;
  2804. }
  2805. }
  2806. // Convert Android420 to ARGB with matrix.
  2807. LIBYUV_API
  2808. int Android420ToARGBMatrix(const uint8_t* src_y,
  2809. int src_stride_y,
  2810. const uint8_t* src_u,
  2811. int src_stride_u,
  2812. const uint8_t* src_v,
  2813. int src_stride_v,
  2814. int src_pixel_stride_uv,
  2815. uint8_t* dst_argb,
  2816. int dst_stride_argb,
  2817. const struct YuvConstants* yuvconstants,
  2818. int width,
  2819. int height) {
  2820. int y;
  2821. uint8_t* dst_uv;
  2822. const ptrdiff_t vu_off = src_v - src_u;
  2823. int halfwidth = (width + 1) >> 1;
  2824. int halfheight = (height + 1) >> 1;
  2825. if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {
  2826. return -1;
  2827. }
  2828. // Negative height means invert the image.
  2829. if (height < 0) {
  2830. height = -height;
  2831. halfheight = (height + 1) >> 1;
  2832. dst_argb = dst_argb + (height - 1) * dst_stride_argb;
  2833. dst_stride_argb = -dst_stride_argb;
  2834. }
  2835. // I420
  2836. if (src_pixel_stride_uv == 1) {
  2837. return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2838. src_stride_v, dst_argb, dst_stride_argb,
  2839. yuvconstants, width, height);
  2840. // NV21
  2841. }
  2842. if (src_pixel_stride_uv == 2 && vu_off == -1 &&
  2843. src_stride_u == src_stride_v) {
  2844. return NV21ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, dst_argb,
  2845. dst_stride_argb, yuvconstants, width, height);
  2846. // NV12
  2847. }
  2848. if (src_pixel_stride_uv == 2 && vu_off == 1 && src_stride_u == src_stride_v) {
  2849. return NV12ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, dst_argb,
  2850. dst_stride_argb, yuvconstants, width, height);
  2851. }
  2852. // General case fallback creates NV12
  2853. align_buffer_64(plane_uv, halfwidth * 2 * halfheight);
  2854. dst_uv = plane_uv;
  2855. for (y = 0; y < halfheight; ++y) {
  2856. WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth);
  2857. src_u += src_stride_u;
  2858. src_v += src_stride_v;
  2859. dst_uv += halfwidth * 2;
  2860. }
  2861. NV12ToARGBMatrix(src_y, src_stride_y, plane_uv, halfwidth * 2, dst_argb,
  2862. dst_stride_argb, yuvconstants, width, height);
  2863. free_aligned_buffer_64(plane_uv);
  2864. return 0;
  2865. }
  2866. // Convert Android420 to ARGB.
  2867. LIBYUV_API
  2868. int Android420ToARGB(const uint8_t* src_y,
  2869. int src_stride_y,
  2870. const uint8_t* src_u,
  2871. int src_stride_u,
  2872. const uint8_t* src_v,
  2873. int src_stride_v,
  2874. int src_pixel_stride_uv,
  2875. uint8_t* dst_argb,
  2876. int dst_stride_argb,
  2877. int width,
  2878. int height) {
  2879. return Android420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2880. src_stride_v, src_pixel_stride_uv, dst_argb,
  2881. dst_stride_argb, &kYuvI601Constants, width,
  2882. height);
  2883. }
  2884. // Convert Android420 to ABGR.
  2885. LIBYUV_API
  2886. int Android420ToABGR(const uint8_t* src_y,
  2887. int src_stride_y,
  2888. const uint8_t* src_u,
  2889. int src_stride_u,
  2890. const uint8_t* src_v,
  2891. int src_stride_v,
  2892. int src_pixel_stride_uv,
  2893. uint8_t* dst_abgr,
  2894. int dst_stride_abgr,
  2895. int width,
  2896. int height) {
  2897. return Android420ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, src_u,
  2898. src_stride_u, src_pixel_stride_uv, dst_abgr,
  2899. dst_stride_abgr, &kYvuI601Constants, width,
  2900. height);
  2901. }
  2902. // Convert I422 to RGBA with matrix.
  2903. LIBYUV_API
  2904. int I422ToRGBAMatrix(const uint8_t* src_y,
  2905. int src_stride_y,
  2906. const uint8_t* src_u,
  2907. int src_stride_u,
  2908. const uint8_t* src_v,
  2909. int src_stride_v,
  2910. uint8_t* dst_rgba,
  2911. int dst_stride_rgba,
  2912. const struct YuvConstants* yuvconstants,
  2913. int width,
  2914. int height) {
  2915. int y;
  2916. void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf,
  2917. const uint8_t* v_buf, uint8_t* rgb_buf,
  2918. const struct YuvConstants* yuvconstants, int width) =
  2919. I422ToRGBARow_C;
  2920. if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) {
  2921. return -1;
  2922. }
  2923. // Negative height means invert the image.
  2924. if (height < 0) {
  2925. height = -height;
  2926. dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba;
  2927. dst_stride_rgba = -dst_stride_rgba;
  2928. }
  2929. #if defined(HAS_I422TORGBAROW_SSSE3)
  2930. if (TestCpuFlag(kCpuHasSSSE3)) {
  2931. I422ToRGBARow = I422ToRGBARow_Any_SSSE3;
  2932. if (IS_ALIGNED(width, 8)) {
  2933. I422ToRGBARow = I422ToRGBARow_SSSE3;
  2934. }
  2935. }
  2936. #endif
  2937. #if defined(HAS_I422TORGBAROW_AVX2)
  2938. if (TestCpuFlag(kCpuHasAVX2)) {
  2939. I422ToRGBARow = I422ToRGBARow_Any_AVX2;
  2940. if (IS_ALIGNED(width, 16)) {
  2941. I422ToRGBARow = I422ToRGBARow_AVX2;
  2942. }
  2943. }
  2944. #endif
  2945. #if defined(HAS_I422TORGBAROW_NEON)
  2946. if (TestCpuFlag(kCpuHasNEON)) {
  2947. I422ToRGBARow = I422ToRGBARow_Any_NEON;
  2948. if (IS_ALIGNED(width, 8)) {
  2949. I422ToRGBARow = I422ToRGBARow_NEON;
  2950. }
  2951. }
  2952. #endif
  2953. #if defined(HAS_I422TORGBAROW_MMI)
  2954. if (TestCpuFlag(kCpuHasMMI)) {
  2955. I422ToRGBARow = I422ToRGBARow_Any_MMI;
  2956. if (IS_ALIGNED(width, 4)) {
  2957. I422ToRGBARow = I422ToRGBARow_MMI;
  2958. }
  2959. }
  2960. #endif
  2961. #if defined(HAS_I422TORGBAROW_MSA)
  2962. if (TestCpuFlag(kCpuHasMSA)) {
  2963. I422ToRGBARow = I422ToRGBARow_Any_MSA;
  2964. if (IS_ALIGNED(width, 8)) {
  2965. I422ToRGBARow = I422ToRGBARow_MSA;
  2966. }
  2967. }
  2968. #endif
  2969. for (y = 0; y < height; ++y) {
  2970. I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width);
  2971. dst_rgba += dst_stride_rgba;
  2972. src_y += src_stride_y;
  2973. src_u += src_stride_u;
  2974. src_v += src_stride_v;
  2975. }
  2976. return 0;
  2977. }
  2978. // Convert I422 to RGBA.
  2979. LIBYUV_API
  2980. int I422ToRGBA(const uint8_t* src_y,
  2981. int src_stride_y,
  2982. const uint8_t* src_u,
  2983. int src_stride_u,
  2984. const uint8_t* src_v,
  2985. int src_stride_v,
  2986. uint8_t* dst_rgba,
  2987. int dst_stride_rgba,
  2988. int width,
  2989. int height) {
  2990. return I422ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  2991. src_stride_v, dst_rgba, dst_stride_rgba,
  2992. &kYuvI601Constants, width, height);
  2993. }
  2994. // Convert I422 to BGRA.
  2995. LIBYUV_API
  2996. int I422ToBGRA(const uint8_t* src_y,
  2997. int src_stride_y,
  2998. const uint8_t* src_u,
  2999. int src_stride_u,
  3000. const uint8_t* src_v,
  3001. int src_stride_v,
  3002. uint8_t* dst_bgra,
  3003. int dst_stride_bgra,
  3004. int width,
  3005. int height) {
  3006. return I422ToRGBAMatrix(src_y, src_stride_y, src_v,
  3007. src_stride_v, // Swap U and V
  3008. src_u, src_stride_u, dst_bgra, dst_stride_bgra,
  3009. &kYvuI601Constants, // Use Yvu matrix
  3010. width, height);
  3011. }
  3012. // Convert NV12 to RGB565 with matrix.
  3013. LIBYUV_API
  3014. int NV12ToRGB565Matrix(const uint8_t* src_y,
  3015. int src_stride_y,
  3016. const uint8_t* src_uv,
  3017. int src_stride_uv,
  3018. uint8_t* dst_rgb565,
  3019. int dst_stride_rgb565,
  3020. const struct YuvConstants* yuvconstants,
  3021. int width,
  3022. int height) {
  3023. int y;
  3024. void (*NV12ToRGB565Row)(
  3025. const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf,
  3026. const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C;
  3027. if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0) {
  3028. return -1;
  3029. }
  3030. // Negative height means invert the image.
  3031. if (height < 0) {
  3032. height = -height;
  3033. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  3034. dst_stride_rgb565 = -dst_stride_rgb565;
  3035. }
  3036. #if defined(HAS_NV12TORGB565ROW_SSSE3)
  3037. if (TestCpuFlag(kCpuHasSSSE3)) {
  3038. NV12ToRGB565Row = NV12ToRGB565Row_Any_SSSE3;
  3039. if (IS_ALIGNED(width, 8)) {
  3040. NV12ToRGB565Row = NV12ToRGB565Row_SSSE3;
  3041. }
  3042. }
  3043. #endif
  3044. #if defined(HAS_NV12TORGB565ROW_AVX2)
  3045. if (TestCpuFlag(kCpuHasAVX2)) {
  3046. NV12ToRGB565Row = NV12ToRGB565Row_Any_AVX2;
  3047. if (IS_ALIGNED(width, 16)) {
  3048. NV12ToRGB565Row = NV12ToRGB565Row_AVX2;
  3049. }
  3050. }
  3051. #endif
  3052. #if defined(HAS_NV12TORGB565ROW_NEON)
  3053. if (TestCpuFlag(kCpuHasNEON)) {
  3054. NV12ToRGB565Row = NV12ToRGB565Row_Any_NEON;
  3055. if (IS_ALIGNED(width, 8)) {
  3056. NV12ToRGB565Row = NV12ToRGB565Row_NEON;
  3057. }
  3058. }
  3059. #endif
  3060. #if defined(HAS_NV12TORGB565ROW_MMI)
  3061. if (TestCpuFlag(kCpuHasMMI)) {
  3062. NV12ToRGB565Row = NV12ToRGB565Row_Any_MMI;
  3063. if (IS_ALIGNED(width, 4)) {
  3064. NV12ToRGB565Row = NV12ToRGB565Row_MMI;
  3065. }
  3066. }
  3067. #endif
  3068. #if defined(HAS_NV12TORGB565ROW_MSA)
  3069. if (TestCpuFlag(kCpuHasMSA)) {
  3070. NV12ToRGB565Row = NV12ToRGB565Row_Any_MSA;
  3071. if (IS_ALIGNED(width, 8)) {
  3072. NV12ToRGB565Row = NV12ToRGB565Row_MSA;
  3073. }
  3074. }
  3075. #endif
  3076. for (y = 0; y < height; ++y) {
  3077. NV12ToRGB565Row(src_y, src_uv, dst_rgb565, yuvconstants, width);
  3078. dst_rgb565 += dst_stride_rgb565;
  3079. src_y += src_stride_y;
  3080. if (y & 1) {
  3081. src_uv += src_stride_uv;
  3082. }
  3083. }
  3084. return 0;
  3085. }
  3086. // Convert NV12 to RGB565.
  3087. LIBYUV_API
  3088. int NV12ToRGB565(const uint8_t* src_y,
  3089. int src_stride_y,
  3090. const uint8_t* src_uv,
  3091. int src_stride_uv,
  3092. uint8_t* dst_rgb565,
  3093. int dst_stride_rgb565,
  3094. int width,
  3095. int height) {
  3096. return NV12ToRGB565Matrix(src_y, src_stride_y, src_uv, src_stride_uv,
  3097. dst_rgb565, dst_stride_rgb565, &kYuvI601Constants,
  3098. width, height);
  3099. }
  3100. // Convert I422 to RGBA with matrix.
  3101. LIBYUV_API
  3102. int I420ToRGBAMatrix(const uint8_t* src_y,
  3103. int src_stride_y,
  3104. const uint8_t* src_u,
  3105. int src_stride_u,
  3106. const uint8_t* src_v,
  3107. int src_stride_v,
  3108. uint8_t* dst_rgba,
  3109. int dst_stride_rgba,
  3110. const struct YuvConstants* yuvconstants,
  3111. int width,
  3112. int height) {
  3113. int y;
  3114. void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf,
  3115. const uint8_t* v_buf, uint8_t* rgb_buf,
  3116. const struct YuvConstants* yuvconstants, int width) =
  3117. I422ToRGBARow_C;
  3118. if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) {
  3119. return -1;
  3120. }
  3121. // Negative height means invert the image.
  3122. if (height < 0) {
  3123. height = -height;
  3124. dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba;
  3125. dst_stride_rgba = -dst_stride_rgba;
  3126. }
  3127. #if defined(HAS_I422TORGBAROW_SSSE3)
  3128. if (TestCpuFlag(kCpuHasSSSE3)) {
  3129. I422ToRGBARow = I422ToRGBARow_Any_SSSE3;
  3130. if (IS_ALIGNED(width, 8)) {
  3131. I422ToRGBARow = I422ToRGBARow_SSSE3;
  3132. }
  3133. }
  3134. #endif
  3135. #if defined(HAS_I422TORGBAROW_AVX2)
  3136. if (TestCpuFlag(kCpuHasAVX2)) {
  3137. I422ToRGBARow = I422ToRGBARow_Any_AVX2;
  3138. if (IS_ALIGNED(width, 16)) {
  3139. I422ToRGBARow = I422ToRGBARow_AVX2;
  3140. }
  3141. }
  3142. #endif
  3143. #if defined(HAS_I422TORGBAROW_NEON)
  3144. if (TestCpuFlag(kCpuHasNEON)) {
  3145. I422ToRGBARow = I422ToRGBARow_Any_NEON;
  3146. if (IS_ALIGNED(width, 8)) {
  3147. I422ToRGBARow = I422ToRGBARow_NEON;
  3148. }
  3149. }
  3150. #endif
  3151. #if defined(HAS_I422TORGBAROW_MMI)
  3152. if (TestCpuFlag(kCpuHasMMI)) {
  3153. I422ToRGBARow = I422ToRGBARow_Any_MMI;
  3154. if (IS_ALIGNED(width, 4)) {
  3155. I422ToRGBARow = I422ToRGBARow_MMI;
  3156. }
  3157. }
  3158. #endif
  3159. #if defined(HAS_I422TORGBAROW_MSA)
  3160. if (TestCpuFlag(kCpuHasMSA)) {
  3161. I422ToRGBARow = I422ToRGBARow_Any_MSA;
  3162. if (IS_ALIGNED(width, 8)) {
  3163. I422ToRGBARow = I422ToRGBARow_MSA;
  3164. }
  3165. }
  3166. #endif
  3167. for (y = 0; y < height; ++y) {
  3168. I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width);
  3169. dst_rgba += dst_stride_rgba;
  3170. src_y += src_stride_y;
  3171. if (y & 1) {
  3172. src_u += src_stride_u;
  3173. src_v += src_stride_v;
  3174. }
  3175. }
  3176. return 0;
  3177. }
  3178. // Convert I420 to RGBA.
  3179. LIBYUV_API
  3180. int I420ToRGBA(const uint8_t* src_y,
  3181. int src_stride_y,
  3182. const uint8_t* src_u,
  3183. int src_stride_u,
  3184. const uint8_t* src_v,
  3185. int src_stride_v,
  3186. uint8_t* dst_rgba,
  3187. int dst_stride_rgba,
  3188. int width,
  3189. int height) {
  3190. return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3191. src_stride_v, dst_rgba, dst_stride_rgba,
  3192. &kYuvI601Constants, width, height);
  3193. }
  3194. // Convert I420 to BGRA.
  3195. LIBYUV_API
  3196. int I420ToBGRA(const uint8_t* src_y,
  3197. int src_stride_y,
  3198. const uint8_t* src_u,
  3199. int src_stride_u,
  3200. const uint8_t* src_v,
  3201. int src_stride_v,
  3202. uint8_t* dst_bgra,
  3203. int dst_stride_bgra,
  3204. int width,
  3205. int height) {
  3206. return I420ToRGBAMatrix(src_y, src_stride_y, src_v,
  3207. src_stride_v, // Swap U and V
  3208. src_u, src_stride_u, dst_bgra, dst_stride_bgra,
  3209. &kYvuI601Constants, // Use Yvu matrix
  3210. width, height);
  3211. }
  3212. // Convert I420 to RGB24 with matrix.
  3213. LIBYUV_API
  3214. int I420ToRGB24Matrix(const uint8_t* src_y,
  3215. int src_stride_y,
  3216. const uint8_t* src_u,
  3217. int src_stride_u,
  3218. const uint8_t* src_v,
  3219. int src_stride_v,
  3220. uint8_t* dst_rgb24,
  3221. int dst_stride_rgb24,
  3222. const struct YuvConstants* yuvconstants,
  3223. int width,
  3224. int height) {
  3225. int y;
  3226. void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3227. const uint8_t* v_buf, uint8_t* rgb_buf,
  3228. const struct YuvConstants* yuvconstants, int width) =
  3229. I422ToRGB24Row_C;
  3230. if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) {
  3231. return -1;
  3232. }
  3233. // Negative height means invert the image.
  3234. if (height < 0) {
  3235. height = -height;
  3236. dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24;
  3237. dst_stride_rgb24 = -dst_stride_rgb24;
  3238. }
  3239. #if defined(HAS_I422TORGB24ROW_SSSE3)
  3240. if (TestCpuFlag(kCpuHasSSSE3)) {
  3241. I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3;
  3242. if (IS_ALIGNED(width, 16)) {
  3243. I422ToRGB24Row = I422ToRGB24Row_SSSE3;
  3244. }
  3245. }
  3246. #endif
  3247. #if defined(HAS_I422TORGB24ROW_AVX2)
  3248. if (TestCpuFlag(kCpuHasAVX2)) {
  3249. I422ToRGB24Row = I422ToRGB24Row_Any_AVX2;
  3250. if (IS_ALIGNED(width, 32)) {
  3251. I422ToRGB24Row = I422ToRGB24Row_AVX2;
  3252. }
  3253. }
  3254. #endif
  3255. #if defined(HAS_I422TORGB24ROW_NEON)
  3256. if (TestCpuFlag(kCpuHasNEON)) {
  3257. I422ToRGB24Row = I422ToRGB24Row_Any_NEON;
  3258. if (IS_ALIGNED(width, 8)) {
  3259. I422ToRGB24Row = I422ToRGB24Row_NEON;
  3260. }
  3261. }
  3262. #endif
  3263. #if defined(HAS_I422TORGB24ROW_MMI)
  3264. if (TestCpuFlag(kCpuHasMMI)) {
  3265. I422ToRGB24Row = I422ToRGB24Row_Any_MMI;
  3266. if (IS_ALIGNED(width, 4)) {
  3267. I422ToRGB24Row = I422ToRGB24Row_MMI;
  3268. }
  3269. }
  3270. #endif
  3271. #if defined(HAS_I422TORGB24ROW_MSA)
  3272. if (TestCpuFlag(kCpuHasMSA)) {
  3273. I422ToRGB24Row = I422ToRGB24Row_Any_MSA;
  3274. if (IS_ALIGNED(width, 16)) {
  3275. I422ToRGB24Row = I422ToRGB24Row_MSA;
  3276. }
  3277. }
  3278. #endif
  3279. for (y = 0; y < height; ++y) {
  3280. I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width);
  3281. dst_rgb24 += dst_stride_rgb24;
  3282. src_y += src_stride_y;
  3283. if (y & 1) {
  3284. src_u += src_stride_u;
  3285. src_v += src_stride_v;
  3286. }
  3287. }
  3288. return 0;
  3289. }
  3290. // Convert I420 to RGB24.
  3291. LIBYUV_API
  3292. int I420ToRGB24(const uint8_t* src_y,
  3293. int src_stride_y,
  3294. const uint8_t* src_u,
  3295. int src_stride_u,
  3296. const uint8_t* src_v,
  3297. int src_stride_v,
  3298. uint8_t* dst_rgb24,
  3299. int dst_stride_rgb24,
  3300. int width,
  3301. int height) {
  3302. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3303. src_stride_v, dst_rgb24, dst_stride_rgb24,
  3304. &kYuvI601Constants, width, height);
  3305. }
  3306. // Convert I420 to RAW.
  3307. LIBYUV_API
  3308. int I420ToRAW(const uint8_t* src_y,
  3309. int src_stride_y,
  3310. const uint8_t* src_u,
  3311. int src_stride_u,
  3312. const uint8_t* src_v,
  3313. int src_stride_v,
  3314. uint8_t* dst_raw,
  3315. int dst_stride_raw,
  3316. int width,
  3317. int height) {
  3318. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  3319. src_stride_v, // Swap U and V
  3320. src_u, src_stride_u, dst_raw, dst_stride_raw,
  3321. &kYvuI601Constants, // Use Yvu matrix
  3322. width, height);
  3323. }
  3324. // Convert J420 to RGB24.
  3325. LIBYUV_API
  3326. int J420ToRGB24(const uint8_t* src_y,
  3327. int src_stride_y,
  3328. const uint8_t* src_u,
  3329. int src_stride_u,
  3330. const uint8_t* src_v,
  3331. int src_stride_v,
  3332. uint8_t* dst_rgb24,
  3333. int dst_stride_rgb24,
  3334. int width,
  3335. int height) {
  3336. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3337. src_stride_v, dst_rgb24, dst_stride_rgb24,
  3338. &kYuvJPEGConstants, width, height);
  3339. }
  3340. // Convert J420 to RAW.
  3341. LIBYUV_API
  3342. int J420ToRAW(const uint8_t* src_y,
  3343. int src_stride_y,
  3344. const uint8_t* src_u,
  3345. int src_stride_u,
  3346. const uint8_t* src_v,
  3347. int src_stride_v,
  3348. uint8_t* dst_raw,
  3349. int dst_stride_raw,
  3350. int width,
  3351. int height) {
  3352. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  3353. src_stride_v, // Swap U and V
  3354. src_u, src_stride_u, dst_raw, dst_stride_raw,
  3355. &kYvuJPEGConstants, // Use Yvu matrix
  3356. width, height);
  3357. }
  3358. // Convert H420 to RGB24.
  3359. LIBYUV_API
  3360. int H420ToRGB24(const uint8_t* src_y,
  3361. int src_stride_y,
  3362. const uint8_t* src_u,
  3363. int src_stride_u,
  3364. const uint8_t* src_v,
  3365. int src_stride_v,
  3366. uint8_t* dst_rgb24,
  3367. int dst_stride_rgb24,
  3368. int width,
  3369. int height) {
  3370. return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3371. src_stride_v, dst_rgb24, dst_stride_rgb24,
  3372. &kYuvH709Constants, width, height);
  3373. }
  3374. // Convert H420 to RAW.
  3375. LIBYUV_API
  3376. int H420ToRAW(const uint8_t* src_y,
  3377. int src_stride_y,
  3378. const uint8_t* src_u,
  3379. int src_stride_u,
  3380. const uint8_t* src_v,
  3381. int src_stride_v,
  3382. uint8_t* dst_raw,
  3383. int dst_stride_raw,
  3384. int width,
  3385. int height) {
  3386. return I420ToRGB24Matrix(src_y, src_stride_y, src_v,
  3387. src_stride_v, // Swap U and V
  3388. src_u, src_stride_u, dst_raw, dst_stride_raw,
  3389. &kYvuH709Constants, // Use Yvu matrix
  3390. width, height);
  3391. }
  3392. // Convert I420 to ARGB1555.
  3393. LIBYUV_API
  3394. int I420ToARGB1555(const uint8_t* src_y,
  3395. int src_stride_y,
  3396. const uint8_t* src_u,
  3397. int src_stride_u,
  3398. const uint8_t* src_v,
  3399. int src_stride_v,
  3400. uint8_t* dst_argb1555,
  3401. int dst_stride_argb1555,
  3402. int width,
  3403. int height) {
  3404. int y;
  3405. void (*I422ToARGB1555Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3406. const uint8_t* v_buf, uint8_t* rgb_buf,
  3407. const struct YuvConstants* yuvconstants,
  3408. int width) = I422ToARGB1555Row_C;
  3409. if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 ||
  3410. height == 0) {
  3411. return -1;
  3412. }
  3413. // Negative height means invert the image.
  3414. if (height < 0) {
  3415. height = -height;
  3416. dst_argb1555 = dst_argb1555 + (height - 1) * dst_stride_argb1555;
  3417. dst_stride_argb1555 = -dst_stride_argb1555;
  3418. }
  3419. #if defined(HAS_I422TOARGB1555ROW_SSSE3)
  3420. if (TestCpuFlag(kCpuHasSSSE3)) {
  3421. I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3;
  3422. if (IS_ALIGNED(width, 8)) {
  3423. I422ToARGB1555Row = I422ToARGB1555Row_SSSE3;
  3424. }
  3425. }
  3426. #endif
  3427. #if defined(HAS_I422TOARGB1555ROW_AVX2)
  3428. if (TestCpuFlag(kCpuHasAVX2)) {
  3429. I422ToARGB1555Row = I422ToARGB1555Row_Any_AVX2;
  3430. if (IS_ALIGNED(width, 16)) {
  3431. I422ToARGB1555Row = I422ToARGB1555Row_AVX2;
  3432. }
  3433. }
  3434. #endif
  3435. #if defined(HAS_I422TOARGB1555ROW_NEON)
  3436. if (TestCpuFlag(kCpuHasNEON)) {
  3437. I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON;
  3438. if (IS_ALIGNED(width, 8)) {
  3439. I422ToARGB1555Row = I422ToARGB1555Row_NEON;
  3440. }
  3441. }
  3442. #endif
  3443. #if defined(HAS_I422TOARGB1555ROW_MMI)
  3444. if (TestCpuFlag(kCpuHasMMI)) {
  3445. I422ToARGB1555Row = I422ToARGB1555Row_Any_MMI;
  3446. if (IS_ALIGNED(width, 4)) {
  3447. I422ToARGB1555Row = I422ToARGB1555Row_MMI;
  3448. }
  3449. }
  3450. #endif
  3451. #if defined(HAS_I422TOARGB1555ROW_MSA)
  3452. if (TestCpuFlag(kCpuHasMSA)) {
  3453. I422ToARGB1555Row = I422ToARGB1555Row_Any_MSA;
  3454. if (IS_ALIGNED(width, 8)) {
  3455. I422ToARGB1555Row = I422ToARGB1555Row_MSA;
  3456. }
  3457. }
  3458. #endif
  3459. for (y = 0; y < height; ++y) {
  3460. I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, &kYuvI601Constants,
  3461. width);
  3462. dst_argb1555 += dst_stride_argb1555;
  3463. src_y += src_stride_y;
  3464. if (y & 1) {
  3465. src_u += src_stride_u;
  3466. src_v += src_stride_v;
  3467. }
  3468. }
  3469. return 0;
  3470. }
  3471. // Convert I420 to ARGB4444.
  3472. LIBYUV_API
  3473. int I420ToARGB4444(const uint8_t* src_y,
  3474. int src_stride_y,
  3475. const uint8_t* src_u,
  3476. int src_stride_u,
  3477. const uint8_t* src_v,
  3478. int src_stride_v,
  3479. uint8_t* dst_argb4444,
  3480. int dst_stride_argb4444,
  3481. int width,
  3482. int height) {
  3483. int y;
  3484. void (*I422ToARGB4444Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3485. const uint8_t* v_buf, uint8_t* rgb_buf,
  3486. const struct YuvConstants* yuvconstants,
  3487. int width) = I422ToARGB4444Row_C;
  3488. if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 ||
  3489. height == 0) {
  3490. return -1;
  3491. }
  3492. // Negative height means invert the image.
  3493. if (height < 0) {
  3494. height = -height;
  3495. dst_argb4444 = dst_argb4444 + (height - 1) * dst_stride_argb4444;
  3496. dst_stride_argb4444 = -dst_stride_argb4444;
  3497. }
  3498. #if defined(HAS_I422TOARGB4444ROW_SSSE3)
  3499. if (TestCpuFlag(kCpuHasSSSE3)) {
  3500. I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3;
  3501. if (IS_ALIGNED(width, 8)) {
  3502. I422ToARGB4444Row = I422ToARGB4444Row_SSSE3;
  3503. }
  3504. }
  3505. #endif
  3506. #if defined(HAS_I422TOARGB4444ROW_AVX2)
  3507. if (TestCpuFlag(kCpuHasAVX2)) {
  3508. I422ToARGB4444Row = I422ToARGB4444Row_Any_AVX2;
  3509. if (IS_ALIGNED(width, 16)) {
  3510. I422ToARGB4444Row = I422ToARGB4444Row_AVX2;
  3511. }
  3512. }
  3513. #endif
  3514. #if defined(HAS_I422TOARGB4444ROW_NEON)
  3515. if (TestCpuFlag(kCpuHasNEON)) {
  3516. I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON;
  3517. if (IS_ALIGNED(width, 8)) {
  3518. I422ToARGB4444Row = I422ToARGB4444Row_NEON;
  3519. }
  3520. }
  3521. #endif
  3522. #if defined(HAS_I422TOARGB4444ROW_MMI)
  3523. if (TestCpuFlag(kCpuHasMMI)) {
  3524. I422ToARGB4444Row = I422ToARGB4444Row_Any_MMI;
  3525. if (IS_ALIGNED(width, 4)) {
  3526. I422ToARGB4444Row = I422ToARGB4444Row_MMI;
  3527. }
  3528. }
  3529. #endif
  3530. #if defined(HAS_I422TOARGB4444ROW_MSA)
  3531. if (TestCpuFlag(kCpuHasMSA)) {
  3532. I422ToARGB4444Row = I422ToARGB4444Row_Any_MSA;
  3533. if (IS_ALIGNED(width, 8)) {
  3534. I422ToARGB4444Row = I422ToARGB4444Row_MSA;
  3535. }
  3536. }
  3537. #endif
  3538. for (y = 0; y < height; ++y) {
  3539. I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, &kYuvI601Constants,
  3540. width);
  3541. dst_argb4444 += dst_stride_argb4444;
  3542. src_y += src_stride_y;
  3543. if (y & 1) {
  3544. src_u += src_stride_u;
  3545. src_v += src_stride_v;
  3546. }
  3547. }
  3548. return 0;
  3549. }
  3550. // Convert I420 to RGB565 with specified color matrix.
  3551. LIBYUV_API
  3552. int I420ToRGB565Matrix(const uint8_t* src_y,
  3553. int src_stride_y,
  3554. const uint8_t* src_u,
  3555. int src_stride_u,
  3556. const uint8_t* src_v,
  3557. int src_stride_v,
  3558. uint8_t* dst_rgb565,
  3559. int dst_stride_rgb565,
  3560. const struct YuvConstants* yuvconstants,
  3561. int width,
  3562. int height) {
  3563. int y;
  3564. void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3565. const uint8_t* v_buf, uint8_t* rgb_buf,
  3566. const struct YuvConstants* yuvconstants, int width) =
  3567. I422ToRGB565Row_C;
  3568. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  3569. return -1;
  3570. }
  3571. // Negative height means invert the image.
  3572. if (height < 0) {
  3573. height = -height;
  3574. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  3575. dst_stride_rgb565 = -dst_stride_rgb565;
  3576. }
  3577. #if defined(HAS_I422TORGB565ROW_SSSE3)
  3578. if (TestCpuFlag(kCpuHasSSSE3)) {
  3579. I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3;
  3580. if (IS_ALIGNED(width, 8)) {
  3581. I422ToRGB565Row = I422ToRGB565Row_SSSE3;
  3582. }
  3583. }
  3584. #endif
  3585. #if defined(HAS_I422TORGB565ROW_AVX2)
  3586. if (TestCpuFlag(kCpuHasAVX2)) {
  3587. I422ToRGB565Row = I422ToRGB565Row_Any_AVX2;
  3588. if (IS_ALIGNED(width, 16)) {
  3589. I422ToRGB565Row = I422ToRGB565Row_AVX2;
  3590. }
  3591. }
  3592. #endif
  3593. #if defined(HAS_I422TORGB565ROW_NEON)
  3594. if (TestCpuFlag(kCpuHasNEON)) {
  3595. I422ToRGB565Row = I422ToRGB565Row_Any_NEON;
  3596. if (IS_ALIGNED(width, 8)) {
  3597. I422ToRGB565Row = I422ToRGB565Row_NEON;
  3598. }
  3599. }
  3600. #endif
  3601. #if defined(HAS_I422TORGB565ROW_MMI)
  3602. if (TestCpuFlag(kCpuHasMMI)) {
  3603. I422ToRGB565Row = I422ToRGB565Row_Any_MMI;
  3604. if (IS_ALIGNED(width, 4)) {
  3605. I422ToRGB565Row = I422ToRGB565Row_MMI;
  3606. }
  3607. }
  3608. #endif
  3609. #if defined(HAS_I422TORGB565ROW_MSA)
  3610. if (TestCpuFlag(kCpuHasMSA)) {
  3611. I422ToRGB565Row = I422ToRGB565Row_Any_MSA;
  3612. if (IS_ALIGNED(width, 8)) {
  3613. I422ToRGB565Row = I422ToRGB565Row_MSA;
  3614. }
  3615. }
  3616. #endif
  3617. for (y = 0; y < height; ++y) {
  3618. I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width);
  3619. dst_rgb565 += dst_stride_rgb565;
  3620. src_y += src_stride_y;
  3621. if (y & 1) {
  3622. src_u += src_stride_u;
  3623. src_v += src_stride_v;
  3624. }
  3625. }
  3626. return 0;
  3627. }
  3628. // Convert I420 to RGB565.
  3629. LIBYUV_API
  3630. int I420ToRGB565(const uint8_t* src_y,
  3631. int src_stride_y,
  3632. const uint8_t* src_u,
  3633. int src_stride_u,
  3634. const uint8_t* src_v,
  3635. int src_stride_v,
  3636. uint8_t* dst_rgb565,
  3637. int dst_stride_rgb565,
  3638. int width,
  3639. int height) {
  3640. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3641. src_stride_v, dst_rgb565, dst_stride_rgb565,
  3642. &kYuvI601Constants, width, height);
  3643. }
  3644. // Convert J420 to RGB565.
  3645. LIBYUV_API
  3646. int J420ToRGB565(const uint8_t* src_y,
  3647. int src_stride_y,
  3648. const uint8_t* src_u,
  3649. int src_stride_u,
  3650. const uint8_t* src_v,
  3651. int src_stride_v,
  3652. uint8_t* dst_rgb565,
  3653. int dst_stride_rgb565,
  3654. int width,
  3655. int height) {
  3656. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3657. src_stride_v, dst_rgb565, dst_stride_rgb565,
  3658. &kYuvJPEGConstants, width, height);
  3659. }
  3660. // Convert H420 to RGB565.
  3661. LIBYUV_API
  3662. int H420ToRGB565(const uint8_t* src_y,
  3663. int src_stride_y,
  3664. const uint8_t* src_u,
  3665. int src_stride_u,
  3666. const uint8_t* src_v,
  3667. int src_stride_v,
  3668. uint8_t* dst_rgb565,
  3669. int dst_stride_rgb565,
  3670. int width,
  3671. int height) {
  3672. return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3673. src_stride_v, dst_rgb565, dst_stride_rgb565,
  3674. &kYuvH709Constants, width, height);
  3675. }
  3676. // Convert I422 to RGB565.
  3677. LIBYUV_API
  3678. int I422ToRGB565(const uint8_t* src_y,
  3679. int src_stride_y,
  3680. const uint8_t* src_u,
  3681. int src_stride_u,
  3682. const uint8_t* src_v,
  3683. int src_stride_v,
  3684. uint8_t* dst_rgb565,
  3685. int dst_stride_rgb565,
  3686. int width,
  3687. int height) {
  3688. int y;
  3689. void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3690. const uint8_t* v_buf, uint8_t* rgb_buf,
  3691. const struct YuvConstants* yuvconstants, int width) =
  3692. I422ToRGB565Row_C;
  3693. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  3694. return -1;
  3695. }
  3696. // Negative height means invert the image.
  3697. if (height < 0) {
  3698. height = -height;
  3699. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  3700. dst_stride_rgb565 = -dst_stride_rgb565;
  3701. }
  3702. #if defined(HAS_I422TORGB565ROW_SSSE3)
  3703. if (TestCpuFlag(kCpuHasSSSE3)) {
  3704. I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3;
  3705. if (IS_ALIGNED(width, 8)) {
  3706. I422ToRGB565Row = I422ToRGB565Row_SSSE3;
  3707. }
  3708. }
  3709. #endif
  3710. #if defined(HAS_I422TORGB565ROW_AVX2)
  3711. if (TestCpuFlag(kCpuHasAVX2)) {
  3712. I422ToRGB565Row = I422ToRGB565Row_Any_AVX2;
  3713. if (IS_ALIGNED(width, 16)) {
  3714. I422ToRGB565Row = I422ToRGB565Row_AVX2;
  3715. }
  3716. }
  3717. #endif
  3718. #if defined(HAS_I422TORGB565ROW_NEON)
  3719. if (TestCpuFlag(kCpuHasNEON)) {
  3720. I422ToRGB565Row = I422ToRGB565Row_Any_NEON;
  3721. if (IS_ALIGNED(width, 8)) {
  3722. I422ToRGB565Row = I422ToRGB565Row_NEON;
  3723. }
  3724. }
  3725. #endif
  3726. #if defined(HAS_I422TORGB565ROW_MSA)
  3727. if (TestCpuFlag(kCpuHasMSA)) {
  3728. I422ToRGB565Row = I422ToRGB565Row_Any_MSA;
  3729. if (IS_ALIGNED(width, 8)) {
  3730. I422ToRGB565Row = I422ToRGB565Row_MSA;
  3731. }
  3732. }
  3733. #endif
  3734. for (y = 0; y < height; ++y) {
  3735. I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, &kYuvI601Constants, width);
  3736. dst_rgb565 += dst_stride_rgb565;
  3737. src_y += src_stride_y;
  3738. src_u += src_stride_u;
  3739. src_v += src_stride_v;
  3740. }
  3741. return 0;
  3742. }
  3743. // Ordered 8x8 dither for 888 to 565. Values from 0 to 7.
  3744. static const uint8_t kDither565_4x4[16] = {
  3745. 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2,
  3746. };
  3747. // Convert I420 to RGB565 with dithering.
  3748. LIBYUV_API
  3749. int I420ToRGB565Dither(const uint8_t* src_y,
  3750. int src_stride_y,
  3751. const uint8_t* src_u,
  3752. int src_stride_u,
  3753. const uint8_t* src_v,
  3754. int src_stride_v,
  3755. uint8_t* dst_rgb565,
  3756. int dst_stride_rgb565,
  3757. const uint8_t* dither4x4,
  3758. int width,
  3759. int height) {
  3760. int y;
  3761. void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
  3762. const uint8_t* v_buf, uint8_t* rgb_buf,
  3763. const struct YuvConstants* yuvconstants, int width) =
  3764. I422ToARGBRow_C;
  3765. void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb,
  3766. const uint32_t dither4, int width) =
  3767. ARGBToRGB565DitherRow_C;
  3768. if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) {
  3769. return -1;
  3770. }
  3771. // Negative height means invert the image.
  3772. if (height < 0) {
  3773. height = -height;
  3774. dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565;
  3775. dst_stride_rgb565 = -dst_stride_rgb565;
  3776. }
  3777. if (!dither4x4) {
  3778. dither4x4 = kDither565_4x4;
  3779. }
  3780. #if defined(HAS_I422TOARGBROW_SSSE3)
  3781. if (TestCpuFlag(kCpuHasSSSE3)) {
  3782. I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
  3783. if (IS_ALIGNED(width, 8)) {
  3784. I422ToARGBRow = I422ToARGBRow_SSSE3;
  3785. }
  3786. }
  3787. #endif
  3788. #if defined(HAS_I422TOARGBROW_AVX2)
  3789. if (TestCpuFlag(kCpuHasAVX2)) {
  3790. I422ToARGBRow = I422ToARGBRow_Any_AVX2;
  3791. if (IS_ALIGNED(width, 16)) {
  3792. I422ToARGBRow = I422ToARGBRow_AVX2;
  3793. }
  3794. }
  3795. #endif
  3796. #if defined(HAS_I422TOARGBROW_NEON)
  3797. if (TestCpuFlag(kCpuHasNEON)) {
  3798. I422ToARGBRow = I422ToARGBRow_Any_NEON;
  3799. if (IS_ALIGNED(width, 8)) {
  3800. I422ToARGBRow = I422ToARGBRow_NEON;
  3801. }
  3802. }
  3803. #endif
  3804. #if defined(HAS_I422TOARGBROW_MMI)
  3805. if (TestCpuFlag(kCpuHasMMI)) {
  3806. I422ToARGBRow = I422ToARGBRow_Any_MMI;
  3807. if (IS_ALIGNED(width, 4)) {
  3808. I422ToARGBRow = I422ToARGBRow_MMI;
  3809. }
  3810. }
  3811. #endif
  3812. #if defined(HAS_I422TOARGBROW_MSA)
  3813. if (TestCpuFlag(kCpuHasMSA)) {
  3814. I422ToARGBRow = I422ToARGBRow_Any_MSA;
  3815. if (IS_ALIGNED(width, 8)) {
  3816. I422ToARGBRow = I422ToARGBRow_MSA;
  3817. }
  3818. }
  3819. #endif
  3820. #if defined(HAS_ARGBTORGB565DITHERROW_SSE2)
  3821. if (TestCpuFlag(kCpuHasSSE2)) {
  3822. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2;
  3823. if (IS_ALIGNED(width, 4)) {
  3824. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2;
  3825. }
  3826. }
  3827. #endif
  3828. #if defined(HAS_ARGBTORGB565DITHERROW_AVX2)
  3829. if (TestCpuFlag(kCpuHasAVX2)) {
  3830. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2;
  3831. if (IS_ALIGNED(width, 8)) {
  3832. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2;
  3833. }
  3834. }
  3835. #endif
  3836. #if defined(HAS_ARGBTORGB565DITHERROW_NEON)
  3837. if (TestCpuFlag(kCpuHasNEON)) {
  3838. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON;
  3839. if (IS_ALIGNED(width, 8)) {
  3840. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON;
  3841. }
  3842. }
  3843. #endif
  3844. #if defined(HAS_ARGBTORGB565DITHERROW_MMI)
  3845. if (TestCpuFlag(kCpuHasMMI)) {
  3846. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MMI;
  3847. if (IS_ALIGNED(width, 4)) {
  3848. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MMI;
  3849. }
  3850. }
  3851. #endif
  3852. #if defined(HAS_ARGBTORGB565DITHERROW_MSA)
  3853. if (TestCpuFlag(kCpuHasMSA)) {
  3854. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MSA;
  3855. if (IS_ALIGNED(width, 8)) {
  3856. ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MSA;
  3857. }
  3858. }
  3859. #endif
  3860. {
  3861. // Allocate a row of argb.
  3862. align_buffer_64(row_argb, width * 4);
  3863. for (y = 0; y < height; ++y) {
  3864. I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width);
  3865. ARGBToRGB565DitherRow(row_argb, dst_rgb565,
  3866. *(const uint32_t*)(dither4x4 + ((y & 3) << 2)),
  3867. width);
  3868. dst_rgb565 += dst_stride_rgb565;
  3869. src_y += src_stride_y;
  3870. if (y & 1) {
  3871. src_u += src_stride_u;
  3872. src_v += src_stride_v;
  3873. }
  3874. }
  3875. free_aligned_buffer_64(row_argb);
  3876. }
  3877. return 0;
  3878. }
  3879. // Convert I420 to AR30 with matrix.
  3880. LIBYUV_API
  3881. int I420ToAR30Matrix(const uint8_t* src_y,
  3882. int src_stride_y,
  3883. const uint8_t* src_u,
  3884. int src_stride_u,
  3885. const uint8_t* src_v,
  3886. int src_stride_v,
  3887. uint8_t* dst_ar30,
  3888. int dst_stride_ar30,
  3889. const struct YuvConstants* yuvconstants,
  3890. int width,
  3891. int height) {
  3892. int y;
  3893. void (*I422ToAR30Row)(const uint8_t* y_buf, const uint8_t* u_buf,
  3894. const uint8_t* v_buf, uint8_t* rgb_buf,
  3895. const struct YuvConstants* yuvconstants, int width) =
  3896. I422ToAR30Row_C;
  3897. if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {
  3898. return -1;
  3899. }
  3900. // Negative height means invert the image.
  3901. if (height < 0) {
  3902. height = -height;
  3903. dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;
  3904. dst_stride_ar30 = -dst_stride_ar30;
  3905. }
  3906. #if defined(HAS_I422TOAR30ROW_SSSE3)
  3907. if (TestCpuFlag(kCpuHasSSSE3)) {
  3908. I422ToAR30Row = I422ToAR30Row_Any_SSSE3;
  3909. if (IS_ALIGNED(width, 8)) {
  3910. I422ToAR30Row = I422ToAR30Row_SSSE3;
  3911. }
  3912. }
  3913. #endif
  3914. #if defined(HAS_I422TOAR30ROW_AVX2)
  3915. if (TestCpuFlag(kCpuHasAVX2)) {
  3916. I422ToAR30Row = I422ToAR30Row_Any_AVX2;
  3917. if (IS_ALIGNED(width, 16)) {
  3918. I422ToAR30Row = I422ToAR30Row_AVX2;
  3919. }
  3920. }
  3921. #endif
  3922. for (y = 0; y < height; ++y) {
  3923. I422ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);
  3924. dst_ar30 += dst_stride_ar30;
  3925. src_y += src_stride_y;
  3926. if (y & 1) {
  3927. src_u += src_stride_u;
  3928. src_v += src_stride_v;
  3929. }
  3930. }
  3931. return 0;
  3932. }
  3933. // Convert I420 to AR30.
  3934. LIBYUV_API
  3935. int I420ToAR30(const uint8_t* src_y,
  3936. int src_stride_y,
  3937. const uint8_t* src_u,
  3938. int src_stride_u,
  3939. const uint8_t* src_v,
  3940. int src_stride_v,
  3941. uint8_t* dst_ar30,
  3942. int dst_stride_ar30,
  3943. int width,
  3944. int height) {
  3945. return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3946. src_stride_v, dst_ar30, dst_stride_ar30,
  3947. &kYuvI601Constants, width, height);
  3948. }
  3949. // Convert H420 to AR30.
  3950. LIBYUV_API
  3951. int H420ToAR30(const uint8_t* src_y,
  3952. int src_stride_y,
  3953. const uint8_t* src_u,
  3954. int src_stride_u,
  3955. const uint8_t* src_v,
  3956. int src_stride_v,
  3957. uint8_t* dst_ar30,
  3958. int dst_stride_ar30,
  3959. int width,
  3960. int height) {
  3961. return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,
  3962. src_stride_v, dst_ar30, dst_stride_ar30,
  3963. &kYvuH709Constants, width, height);
  3964. }
  3965. #ifdef __cplusplus
  3966. } // extern "C"
  3967. } // namespace libyuv
  3968. #endif