output.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741
  1. /*
  2. * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <math.h>
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/bswap.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/mem_internal.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale.h"
  35. #include "swscale_internal.h"
  36. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
  37. { 1, 3, 1, 3, 1, 3, 1, 3, },
  38. { 2, 0, 2, 0, 2, 0, 2, 0, },
  39. { 1, 3, 1, 3, 1, 3, 1, 3, },
  40. };
  41. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
  42. { 6, 2, 6, 2, 6, 2, 6, 2, },
  43. { 0, 4, 0, 4, 0, 4, 0, 4, },
  44. { 6, 2, 6, 2, 6, 2, 6, 2, },
  45. };
  46. DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
  47. { 8, 4, 11, 7, 8, 4, 11, 7, },
  48. { 2, 14, 1, 13, 2, 14, 1, 13, },
  49. { 10, 6, 9, 5, 10, 6, 9, 5, },
  50. { 0, 12, 3, 15, 0, 12, 3, 15, },
  51. { 8, 4, 11, 7, 8, 4, 11, 7, },
  52. };
  53. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
  54. { 17, 9, 23, 15, 16, 8, 22, 14, },
  55. { 5, 29, 3, 27, 4, 28, 2, 26, },
  56. { 21, 13, 19, 11, 20, 12, 18, 10, },
  57. { 0, 24, 6, 30, 1, 25, 7, 31, },
  58. { 16, 8, 22, 14, 17, 9, 23, 15, },
  59. { 4, 28, 2, 26, 5, 29, 3, 27, },
  60. { 20, 12, 18, 10, 21, 13, 19, 11, },
  61. { 1, 25, 7, 31, 0, 24, 6, 30, },
  62. { 17, 9, 23, 15, 16, 8, 22, 14, },
  63. };
  64. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
  65. { 0, 55, 14, 68, 3, 58, 17, 72, },
  66. { 37, 18, 50, 32, 40, 22, 54, 35, },
  67. { 9, 64, 5, 59, 13, 67, 8, 63, },
  68. { 46, 27, 41, 23, 49, 31, 44, 26, },
  69. { 2, 57, 16, 71, 1, 56, 15, 70, },
  70. { 39, 21, 52, 34, 38, 19, 51, 33, },
  71. { 11, 66, 7, 62, 10, 65, 6, 60, },
  72. { 48, 30, 43, 25, 47, 29, 42, 24, },
  73. { 0, 55, 14, 68, 3, 58, 17, 72, },
  74. };
  75. #if 1
  76. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  77. {117, 62, 158, 103, 113, 58, 155, 100, },
  78. { 34, 199, 21, 186, 31, 196, 17, 182, },
  79. {144, 89, 131, 76, 141, 86, 127, 72, },
  80. { 0, 165, 41, 206, 10, 175, 52, 217, },
  81. {110, 55, 151, 96, 120, 65, 162, 107, },
  82. { 28, 193, 14, 179, 38, 203, 24, 189, },
  83. {138, 83, 124, 69, 148, 93, 134, 79, },
  84. { 7, 172, 48, 213, 3, 168, 45, 210, },
  85. {117, 62, 158, 103, 113, 58, 155, 100, },
  86. };
  87. #elif 1
  88. // tries to correct a gamma of 1.5
  89. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  90. { 0, 143, 18, 200, 2, 156, 25, 215, },
  91. { 78, 28, 125, 64, 89, 36, 138, 74, },
  92. { 10, 180, 3, 161, 16, 195, 8, 175, },
  93. {109, 51, 93, 38, 121, 60, 105, 47, },
  94. { 1, 152, 23, 210, 0, 147, 20, 205, },
  95. { 85, 33, 134, 71, 81, 30, 130, 67, },
  96. { 14, 190, 6, 171, 12, 185, 5, 166, },
  97. {117, 57, 101, 44, 113, 54, 97, 41, },
  98. { 0, 143, 18, 200, 2, 156, 25, 215, },
  99. };
  100. #elif 1
  101. // tries to correct a gamma of 2.0
  102. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  103. { 0, 124, 8, 193, 0, 140, 12, 213, },
  104. { 55, 14, 104, 42, 66, 19, 119, 52, },
  105. { 3, 168, 1, 145, 6, 187, 3, 162, },
  106. { 86, 31, 70, 21, 99, 39, 82, 28, },
  107. { 0, 134, 11, 206, 0, 129, 9, 200, },
  108. { 62, 17, 114, 48, 58, 16, 109, 45, },
  109. { 5, 181, 2, 157, 4, 175, 1, 151, },
  110. { 95, 36, 78, 26, 90, 34, 74, 24, },
  111. { 0, 124, 8, 193, 0, 140, 12, 213, },
  112. };
  113. #else
  114. // tries to correct a gamma of 2.5
  115. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  116. { 0, 107, 3, 187, 0, 125, 6, 212, },
  117. { 39, 7, 86, 28, 49, 11, 102, 36, },
  118. { 1, 158, 0, 131, 3, 180, 1, 151, },
  119. { 68, 19, 52, 12, 81, 25, 64, 17, },
  120. { 0, 119, 5, 203, 0, 113, 4, 195, },
  121. { 45, 9, 96, 33, 42, 8, 91, 30, },
  122. { 2, 172, 1, 144, 2, 165, 0, 137, },
  123. { 77, 23, 60, 15, 72, 21, 56, 14, },
  124. { 0, 107, 3, 187, 0, 125, 6, 212, },
  125. };
  126. #endif
  127. #define IS_BE_LE 0
  128. #define IS_BE_BE 1
  129. /* ENDIAN_IDENTIFIER needs to be "BE" or "LE". */
  130. #define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
  131. #define output_pixel(pos, val, bias, signedness) \
  132. if (big_endian) { \
  133. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  134. } else { \
  135. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  136. }
  137. static av_always_inline void
  138. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  139. int big_endian, int output_bits)
  140. {
  141. int i;
  142. int shift = 3;
  143. av_assert0(output_bits == 16);
  144. for (i = 0; i < dstW; i++) {
  145. int val = src[i] + (1 << (shift - 1));
  146. output_pixel(&dest[i], val, 0, uint);
  147. }
  148. }
  149. static av_always_inline void
  150. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  151. const int32_t **src, uint16_t *dest, int dstW,
  152. int big_endian, int output_bits)
  153. {
  154. int i;
  155. int shift = 15;
  156. av_assert0(output_bits == 16);
  157. for (i = 0; i < dstW; i++) {
  158. int val = 1 << (shift - 1);
  159. int j;
  160. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  161. * filters (or anything with negative coeffs, the range can be slightly
  162. * wider in both directions. To account for this overflow, we subtract
  163. * a constant so it always fits in the signed range (assuming a
  164. * reasonable filterSize), and re-add that at the end. */
  165. val -= 0x40000000;
  166. for (j = 0; j < filterSize; j++)
  167. val += src[j][i] * (unsigned)filter[j];
  168. output_pixel(&dest[i], val, 0x8000, int);
  169. }
  170. }
  171. static av_always_inline void
  172. yuv2nv12cX_16_c_template(int big_endian, const uint8_t *chrDither,
  173. const int16_t *chrFilter, int chrFilterSize,
  174. const int16_t **chrUSrc, const int16_t **chrVSrc,
  175. uint8_t *dest8, int chrDstW, int output_bits)
  176. {
  177. uint16_t *dest = (uint16_t*)dest8;
  178. const int32_t **uSrc = (const int32_t **)chrUSrc;
  179. const int32_t **vSrc = (const int32_t **)chrVSrc;
  180. int shift = 15;
  181. int i, j;
  182. av_assert0(output_bits == 16);
  183. for (i = 0; i < chrDstW; i++) {
  184. int u = 1 << (shift - 1);
  185. int v = 1 << (shift - 1);
  186. /* See yuv2planeX_16_c_template for details. */
  187. u -= 0x40000000;
  188. v -= 0x40000000;
  189. for (j = 0; j < chrFilterSize; j++) {
  190. u += uSrc[j][i] * (unsigned)chrFilter[j];
  191. v += vSrc[j][i] * (unsigned)chrFilter[j];
  192. }
  193. output_pixel(&dest[2*i] , u, 0x8000, int);
  194. output_pixel(&dest[2*i+1], v, 0x8000, int);
  195. }
  196. }
  197. static av_always_inline void
  198. yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
  199. {
  200. static const int big_endian = HAVE_BIGENDIAN;
  201. static const int shift = 3;
  202. static const float float_mult = 1.0f / 65535.0f;
  203. int i, val;
  204. uint16_t val_uint;
  205. for (i = 0; i < dstW; ++i){
  206. val = src[i] + (1 << (shift - 1));
  207. output_pixel(&val_uint, val, 0, uint);
  208. dest[i] = float_mult * (float)val_uint;
  209. }
  210. }
  211. static av_always_inline void
  212. yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
  213. {
  214. static const int big_endian = HAVE_BIGENDIAN;
  215. static const int shift = 3;
  216. static const float float_mult = 1.0f / 65535.0f;
  217. int i, val;
  218. uint16_t val_uint;
  219. for (i = 0; i < dstW; ++i){
  220. val = src[i] + (1 << (shift - 1));
  221. output_pixel(&val_uint, val, 0, uint);
  222. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  223. }
  224. }
  225. static av_always_inline void
  226. yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  227. float *dest, int dstW)
  228. {
  229. static const int big_endian = HAVE_BIGENDIAN;
  230. static const int shift = 15;
  231. static const float float_mult = 1.0f / 65535.0f;
  232. int i, j, val;
  233. uint16_t val_uint;
  234. for (i = 0; i < dstW; ++i){
  235. val = (1 << (shift - 1)) - 0x40000000;
  236. for (j = 0; j < filterSize; ++j){
  237. val += src[j][i] * (unsigned)filter[j];
  238. }
  239. output_pixel(&val_uint, val, 0x8000, int);
  240. dest[i] = float_mult * (float)val_uint;
  241. }
  242. }
  243. static av_always_inline void
  244. yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  245. uint32_t *dest, int dstW)
  246. {
  247. static const int big_endian = HAVE_BIGENDIAN;
  248. static const int shift = 15;
  249. static const float float_mult = 1.0f / 65535.0f;
  250. int i, j, val;
  251. uint16_t val_uint;
  252. for (i = 0; i < dstW; ++i){
  253. val = (1 << (shift - 1)) - 0x40000000;
  254. for (j = 0; j < filterSize; ++j){
  255. val += src[j][i] * (unsigned)filter[j];
  256. }
  257. output_pixel(&val_uint, val, 0x8000, int);
  258. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  259. }
  260. }
  261. #define yuv2plane1_float(template, dest_type, BE_LE) \
  262. static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
  263. const uint8_t *dither, int offset) \
  264. { \
  265. template((const int32_t *)src, (dest_type *)dest, dstW); \
  266. }
  267. #define yuv2planeX_float(template, dest_type, BE_LE) \
  268. static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  269. const int16_t **src, uint8_t *dest, int dstW, \
  270. const uint8_t *dither, int offset) \
  271. { \
  272. template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
  273. }
  274. #if HAVE_BIGENDIAN
  275. yuv2plane1_float(yuv2plane1_float_c_template, float, BE)
  276. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
  277. yuv2planeX_float(yuv2planeX_float_c_template, float, BE)
  278. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
  279. #else
  280. yuv2plane1_float(yuv2plane1_float_c_template, float, LE)
  281. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
  282. yuv2planeX_float(yuv2planeX_float_c_template, float, LE)
  283. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
  284. #endif
  285. #undef output_pixel
  286. #define output_pixel(pos, val) \
  287. if (big_endian) { \
  288. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  289. } else { \
  290. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  291. }
  292. static av_always_inline void
  293. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  294. int big_endian, int output_bits)
  295. {
  296. int i;
  297. int shift = 15 - output_bits;
  298. for (i = 0; i < dstW; i++) {
  299. int val = src[i] + (1 << (shift - 1));
  300. output_pixel(&dest[i], val);
  301. }
  302. }
  303. static av_always_inline void
  304. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  305. const int16_t **src, uint16_t *dest, int dstW,
  306. int big_endian, int output_bits)
  307. {
  308. int i;
  309. int shift = 11 + 16 - output_bits;
  310. for (i = 0; i < dstW; i++) {
  311. int val = 1 << (shift - 1);
  312. int j;
  313. for (j = 0; j < filterSize; j++)
  314. val += src[j][i] * filter[j];
  315. output_pixel(&dest[i], val);
  316. }
  317. }
  318. #undef output_pixel
  319. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  320. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  321. uint8_t *dest, int dstW, \
  322. const uint8_t *dither, int offset)\
  323. { \
  324. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  325. (uint16_t *) dest, dstW, is_be, bits); \
  326. }\
  327. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  328. const int16_t **src, uint8_t *dest, int dstW, \
  329. const uint8_t *dither, int offset)\
  330. { \
  331. yuv2planeX_## template_size ## _c_template(filter, \
  332. filterSize, (const typeX_t **) src, \
  333. (uint16_t *) dest, dstW, is_be, bits); \
  334. }
  335. yuv2NBPS( 9, BE, 1, 10, int16_t)
  336. yuv2NBPS( 9, LE, 0, 10, int16_t)
  337. yuv2NBPS(10, BE, 1, 10, int16_t)
  338. yuv2NBPS(10, LE, 0, 10, int16_t)
  339. yuv2NBPS(12, BE, 1, 10, int16_t)
  340. yuv2NBPS(12, LE, 0, 10, int16_t)
  341. yuv2NBPS(14, BE, 1, 10, int16_t)
  342. yuv2NBPS(14, LE, 0, 10, int16_t)
  343. yuv2NBPS(16, BE, 1, 16, int32_t)
  344. yuv2NBPS(16, LE, 0, 16, int32_t)
  345. static void yuv2nv12cX_16LE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
  346. const int16_t *chrFilter, int chrFilterSize,
  347. const int16_t **chrUSrc, const int16_t **chrVSrc,
  348. uint8_t *dest8, int chrDstW)
  349. {
  350. yuv2nv12cX_16_c_template(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
  351. }
  352. static void yuv2nv12cX_16BE_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
  353. const int16_t *chrFilter, int chrFilterSize,
  354. const int16_t **chrUSrc, const int16_t **chrVSrc,
  355. uint8_t *dest8, int chrDstW)
  356. {
  357. yuv2nv12cX_16_c_template(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, dest8, chrDstW, 16);
  358. }
  359. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  360. const int16_t **src, uint8_t *dest, int dstW,
  361. const uint8_t *dither, int offset)
  362. {
  363. int i;
  364. for (i=0; i<dstW; i++) {
  365. int val = dither[(i + offset) & 7] << 12;
  366. int j;
  367. for (j=0; j<filterSize; j++)
  368. val += src[j][i] * filter[j];
  369. dest[i]= av_clip_uint8(val>>19);
  370. }
  371. }
  372. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  373. const uint8_t *dither, int offset)
  374. {
  375. int i;
  376. for (i=0; i<dstW; i++) {
  377. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  378. dest[i]= av_clip_uint8(val);
  379. }
  380. }
  381. static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
  382. const int16_t *chrFilter, int chrFilterSize,
  383. const int16_t **chrUSrc, const int16_t **chrVSrc,
  384. uint8_t *dest, int chrDstW)
  385. {
  386. int i;
  387. if (!isSwappedChroma(dstFormat))
  388. for (i=0; i<chrDstW; i++) {
  389. int u = chrDither[i & 7] << 12;
  390. int v = chrDither[(i + 3) & 7] << 12;
  391. int j;
  392. for (j=0; j<chrFilterSize; j++) {
  393. u += chrUSrc[j][i] * chrFilter[j];
  394. v += chrVSrc[j][i] * chrFilter[j];
  395. }
  396. dest[2*i]= av_clip_uint8(u>>19);
  397. dest[2*i+1]= av_clip_uint8(v>>19);
  398. }
  399. else
  400. for (i=0; i<chrDstW; i++) {
  401. int u = chrDither[i & 7] << 12;
  402. int v = chrDither[(i + 3) & 7] << 12;
  403. int j;
  404. for (j=0; j<chrFilterSize; j++) {
  405. u += chrUSrc[j][i] * chrFilter[j];
  406. v += chrVSrc[j][i] * chrFilter[j];
  407. }
  408. dest[2*i]= av_clip_uint8(v>>19);
  409. dest[2*i+1]= av_clip_uint8(u>>19);
  410. }
  411. }
  412. #define output_pixel(pos, val) \
  413. if (big_endian) { \
  414. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
  415. } else { \
  416. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
  417. }
  418. static void yuv2p01xl1_c(const int16_t *src,
  419. uint16_t *dest, int dstW,
  420. int big_endian, int output_bits)
  421. {
  422. int i;
  423. int shift = 15 - output_bits;
  424. int output_shift = 16 - output_bits;
  425. for (i = 0; i < dstW; i++) {
  426. int val = src[i] + (1 << (shift - 1));
  427. output_pixel(&dest[i], val);
  428. }
  429. }
  430. static void yuv2p01xlX_c(const int16_t *filter, int filterSize,
  431. const int16_t **src, uint16_t *dest, int dstW,
  432. int big_endian, int output_bits)
  433. {
  434. int i, j;
  435. int shift = 11 + 16 - output_bits;
  436. int output_shift = 16 - output_bits;
  437. for (i = 0; i < dstW; i++) {
  438. int val = 1 << (shift - 1);
  439. for (j = 0; j < filterSize; j++)
  440. val += src[j][i] * filter[j];
  441. output_pixel(&dest[i], val);
  442. }
  443. }
  444. static void yuv2p01xcX_c(int big_endian, const uint8_t *chrDither,
  445. const int16_t *chrFilter, int chrFilterSize,
  446. const int16_t **chrUSrc, const int16_t **chrVSrc,
  447. uint8_t *dest8, int chrDstW, int output_bits)
  448. {
  449. uint16_t *dest = (uint16_t*)dest8;
  450. int i, j;
  451. int shift = 11 + 16 - output_bits;
  452. int output_shift = 16 - output_bits;
  453. for (i = 0; i < chrDstW; i++) {
  454. int u = 1 << (shift - 1);
  455. int v = 1 << (shift - 1);
  456. for (j = 0; j < chrFilterSize; j++) {
  457. u += chrUSrc[j][i] * chrFilter[j];
  458. v += chrVSrc[j][i] * chrFilter[j];
  459. }
  460. output_pixel(&dest[2*i] , u);
  461. output_pixel(&dest[2*i+1], v);
  462. }
  463. }
  464. #undef output_pixel
  465. #define yuv2p01x_wrapper(bits) \
  466. static void yuv2p0 ## bits ## l1_LE_c(const int16_t *src, \
  467. uint8_t *dest, int dstW, \
  468. const uint8_t *dither, int offset) \
  469. { \
  470. yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 0, bits); \
  471. } \
  472. \
  473. static void yuv2p0 ## bits ## l1_BE_c(const int16_t *src, \
  474. uint8_t *dest, int dstW, \
  475. const uint8_t *dither, int offset) \
  476. { \
  477. yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 1, bits); \
  478. } \
  479. \
  480. static void yuv2p0 ## bits ## lX_LE_c(const int16_t *filter, \
  481. int filterSize, const int16_t **src, \
  482. uint8_t *dest, int dstW, \
  483. const uint8_t *dither, int offset) \
  484. { \
  485. yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0, bits); \
  486. } \
  487. \
  488. static void yuv2p0 ## bits ## lX_BE_c(const int16_t *filter, \
  489. int filterSize, const int16_t **src, \
  490. uint8_t *dest, int dstW, \
  491. const uint8_t *dither, int offset) \
  492. { \
  493. yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1, bits); \
  494. } \
  495. \
  496. static void yuv2p0 ## bits ## cX_LE_c(enum AVPixelFormat dstFormat, \
  497. const uint8_t *chrDither, \
  498. const int16_t *chrFilter, \
  499. int chrFilterSize, \
  500. const int16_t **chrUSrc, \
  501. const int16_t **chrVSrc, \
  502. uint8_t *dest8, int chrDstW) \
  503. { \
  504. yuv2p01xcX_c(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
  505. dest8, chrDstW, bits); \
  506. } \
  507. \
  508. static void yuv2p0 ## bits ## cX_BE_c(enum AVPixelFormat dstFormat, \
  509. const uint8_t *chrDither, \
  510. const int16_t *chrFilter, \
  511. int chrFilterSize, \
  512. const int16_t **chrUSrc, \
  513. const int16_t **chrVSrc, \
  514. uint8_t *dest8, int chrDstW) \
  515. { \
  516. yuv2p01xcX_c(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
  517. dest8, chrDstW, bits); \
  518. }
  519. yuv2p01x_wrapper(10)
  520. yuv2p01x_wrapper(12)
  521. #define accumulate_bit(acc, val) \
  522. acc <<= 1; \
  523. acc |= (val) >= 234
  524. #define output_pixel(pos, acc) \
  525. if (target == AV_PIX_FMT_MONOBLACK) { \
  526. pos = acc; \
  527. } else { \
  528. pos = ~acc; \
  529. }
  530. static av_always_inline void
  531. yuv2mono_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  532. const int16_t **lumSrc, int lumFilterSize,
  533. const int16_t *chrFilter, const int16_t **chrUSrc,
  534. const int16_t **chrVSrc, int chrFilterSize,
  535. const int16_t **alpSrc, uint8_t *dest, int dstW,
  536. int y, enum AVPixelFormat target)
  537. {
  538. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  539. int i;
  540. unsigned acc = 0;
  541. int err = 0;
  542. for (i = 0; i < dstW; i += 2) {
  543. int j;
  544. int Y1 = 1 << 18;
  545. int Y2 = 1 << 18;
  546. for (j = 0; j < lumFilterSize; j++) {
  547. Y1 += lumSrc[j][i] * lumFilter[j];
  548. Y2 += lumSrc[j][i+1] * lumFilter[j];
  549. }
  550. Y1 >>= 19;
  551. Y2 >>= 19;
  552. if ((Y1 | Y2) & 0x100) {
  553. Y1 = av_clip_uint8(Y1);
  554. Y2 = av_clip_uint8(Y2);
  555. }
  556. if (c->dither == SWS_DITHER_ED) {
  557. Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  558. c->dither_error[0][i] = err;
  559. acc = 2*acc + (Y1 >= 128);
  560. Y1 -= 220*(acc&1);
  561. err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
  562. c->dither_error[0][i+1] = Y1;
  563. acc = 2*acc + (err >= 128);
  564. err -= 220*(acc&1);
  565. } else {
  566. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  567. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  568. }
  569. if ((i & 7) == 6) {
  570. output_pixel(*dest++, acc);
  571. }
  572. }
  573. c->dither_error[0][i] = err;
  574. if (i & 6) {
  575. output_pixel(*dest, acc);
  576. }
  577. }
  578. static av_always_inline void
  579. yuv2mono_2_c_template(SwsInternal *c, const int16_t *buf[2],
  580. const int16_t *ubuf[2], const int16_t *vbuf[2],
  581. const int16_t *abuf[2], uint8_t *dest, int dstW,
  582. int yalpha, int uvalpha, int y,
  583. enum AVPixelFormat target)
  584. {
  585. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  586. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  587. int yalpha1 = 4096 - yalpha;
  588. int i;
  589. av_assert2(yalpha <= 4096U);
  590. if (c->dither == SWS_DITHER_ED) {
  591. int err = 0;
  592. unsigned acc = 0;
  593. for (i = 0; i < dstW; i +=2) {
  594. int Y;
  595. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  596. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  597. c->dither_error[0][i] = err;
  598. acc = 2*acc + (Y >= 128);
  599. Y -= 220*(acc&1);
  600. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  601. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  602. c->dither_error[0][i+1] = Y;
  603. acc = 2*acc + (err >= 128);
  604. err -= 220*(acc&1);
  605. if ((i & 7) == 6)
  606. output_pixel(*dest++, acc);
  607. }
  608. c->dither_error[0][i] = err;
  609. } else {
  610. for (i = 0; i < dstW; i += 8) {
  611. int Y;
  612. unsigned acc = 0;
  613. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  614. accumulate_bit(acc, Y + d128[0]);
  615. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  616. accumulate_bit(acc, Y + d128[1]);
  617. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  618. accumulate_bit(acc, Y + d128[2]);
  619. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  620. accumulate_bit(acc, Y + d128[3]);
  621. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  622. accumulate_bit(acc, Y + d128[4]);
  623. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  624. accumulate_bit(acc, Y + d128[5]);
  625. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  626. accumulate_bit(acc, Y + d128[6]);
  627. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  628. accumulate_bit(acc, Y + d128[7]);
  629. output_pixel(*dest++, acc);
  630. }
  631. }
  632. }
  633. static av_always_inline void
  634. yuv2mono_1_c_template(SwsInternal *c, const int16_t *buf0,
  635. const int16_t *ubuf[2], const int16_t *vbuf[2],
  636. const int16_t *abuf0, uint8_t *dest, int dstW,
  637. int uvalpha, int y, enum AVPixelFormat target)
  638. {
  639. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  640. int i;
  641. if (c->dither == SWS_DITHER_ED) {
  642. int err = 0;
  643. unsigned acc = 0;
  644. for (i = 0; i < dstW; i +=2) {
  645. int Y;
  646. Y = ((buf0[i + 0] + 64) >> 7);
  647. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  648. c->dither_error[0][i] = err;
  649. acc = 2*acc + (Y >= 128);
  650. Y -= 220*(acc&1);
  651. err = ((buf0[i + 1] + 64) >> 7);
  652. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  653. c->dither_error[0][i+1] = Y;
  654. acc = 2*acc + (err >= 128);
  655. err -= 220*(acc&1);
  656. if ((i & 7) == 6)
  657. output_pixel(*dest++, acc);
  658. }
  659. c->dither_error[0][i] = err;
  660. } else {
  661. for (i = 0; i < dstW; i += 8) {
  662. unsigned acc = 0;
  663. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  664. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  665. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  666. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  667. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  668. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  669. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  670. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  671. output_pixel(*dest++, acc);
  672. }
  673. }
  674. }
  675. #undef output_pixel
  676. #undef accumulate_bit
  677. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  678. static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  679. const int16_t **lumSrc, int lumFilterSize, \
  680. const int16_t *chrFilter, const int16_t **chrUSrc, \
  681. const int16_t **chrVSrc, int chrFilterSize, \
  682. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  683. int y) \
  684. { \
  685. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  686. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  687. alpSrc, dest, dstW, y, fmt); \
  688. } \
  689. \
  690. static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
  691. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  692. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  693. int yalpha, int uvalpha, int y) \
  694. { \
  695. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  696. dest, dstW, yalpha, uvalpha, y, fmt); \
  697. } \
  698. \
  699. static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
  700. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  701. const int16_t *abuf0, uint8_t *dest, int dstW, \
  702. int uvalpha, int y) \
  703. { \
  704. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  705. abuf0, dest, dstW, uvalpha, \
  706. y, fmt); \
  707. }
  708. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  709. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  710. #define output_pixels(pos, Y1, U, Y2, V) \
  711. if (target == AV_PIX_FMT_YUYV422) { \
  712. dest[pos + 0] = Y1; \
  713. dest[pos + 1] = U; \
  714. dest[pos + 2] = Y2; \
  715. dest[pos + 3] = V; \
  716. } else if (target == AV_PIX_FMT_YVYU422) { \
  717. dest[pos + 0] = Y1; \
  718. dest[pos + 1] = V; \
  719. dest[pos + 2] = Y2; \
  720. dest[pos + 3] = U; \
  721. } else { /* AV_PIX_FMT_UYVY422 */ \
  722. dest[pos + 0] = U; \
  723. dest[pos + 1] = Y1; \
  724. dest[pos + 2] = V; \
  725. dest[pos + 3] = Y2; \
  726. }
  727. static av_always_inline void
  728. yuv2422_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  729. const int16_t **lumSrc, int lumFilterSize,
  730. const int16_t *chrFilter, const int16_t **chrUSrc,
  731. const int16_t **chrVSrc, int chrFilterSize,
  732. const int16_t **alpSrc, uint8_t *dest, int dstW,
  733. int y, enum AVPixelFormat target)
  734. {
  735. int i;
  736. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  737. int j;
  738. int Y1 = 1 << 18;
  739. int Y2 = 1 << 18;
  740. int U = 1 << 18;
  741. int V = 1 << 18;
  742. for (j = 0; j < lumFilterSize; j++) {
  743. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  744. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  745. }
  746. for (j = 0; j < chrFilterSize; j++) {
  747. U += chrUSrc[j][i] * chrFilter[j];
  748. V += chrVSrc[j][i] * chrFilter[j];
  749. }
  750. Y1 >>= 19;
  751. Y2 >>= 19;
  752. U >>= 19;
  753. V >>= 19;
  754. if ((Y1 | Y2 | U | V) & 0x100) {
  755. Y1 = av_clip_uint8(Y1);
  756. Y2 = av_clip_uint8(Y2);
  757. U = av_clip_uint8(U);
  758. V = av_clip_uint8(V);
  759. }
  760. output_pixels(4*i, Y1, U, Y2, V);
  761. }
  762. }
  763. static av_always_inline void
  764. yuv2422_2_c_template(SwsInternal *c, const int16_t *buf[2],
  765. const int16_t *ubuf[2], const int16_t *vbuf[2],
  766. const int16_t *abuf[2], uint8_t *dest, int dstW,
  767. int yalpha, int uvalpha, int y,
  768. enum AVPixelFormat target)
  769. {
  770. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  771. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  772. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  773. int yalpha1 = 4096 - yalpha;
  774. int uvalpha1 = 4096 - uvalpha;
  775. int i;
  776. av_assert2(yalpha <= 4096U);
  777. av_assert2(uvalpha <= 4096U);
  778. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  779. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  780. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  781. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  782. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  783. if ((Y1 | Y2 | U | V) & 0x100) {
  784. Y1 = av_clip_uint8(Y1);
  785. Y2 = av_clip_uint8(Y2);
  786. U = av_clip_uint8(U);
  787. V = av_clip_uint8(V);
  788. }
  789. output_pixels(i * 4, Y1, U, Y2, V);
  790. }
  791. }
  792. static av_always_inline void
  793. yuv2422_1_c_template(SwsInternal *c, const int16_t *buf0,
  794. const int16_t *ubuf[2], const int16_t *vbuf[2],
  795. const int16_t *abuf0, uint8_t *dest, int dstW,
  796. int uvalpha, int y, enum AVPixelFormat target)
  797. {
  798. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  799. int i;
  800. if (uvalpha < 2048) {
  801. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  802. int Y1 = (buf0[i * 2 ]+64) >> 7;
  803. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  804. int U = (ubuf0[i] +64) >> 7;
  805. int V = (vbuf0[i] +64) >> 7;
  806. if ((Y1 | Y2 | U | V) & 0x100) {
  807. Y1 = av_clip_uint8(Y1);
  808. Y2 = av_clip_uint8(Y2);
  809. U = av_clip_uint8(U);
  810. V = av_clip_uint8(V);
  811. }
  812. output_pixels(i * 4, Y1, U, Y2, V);
  813. }
  814. } else {
  815. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  816. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  817. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  818. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  819. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  820. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  821. if ((Y1 | Y2 | U | V) & 0x100) {
  822. Y1 = av_clip_uint8(Y1);
  823. Y2 = av_clip_uint8(Y2);
  824. U = av_clip_uint8(U);
  825. V = av_clip_uint8(V);
  826. }
  827. output_pixels(i * 4, Y1, U, Y2, V);
  828. }
  829. }
  830. }
  831. #undef output_pixels
  832. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  833. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  834. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  835. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
  836. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
  837. #define output_pixel(pos, val) \
  838. if (is_be) { \
  839. AV_WB16(pos, val); \
  840. } else { \
  841. AV_WL16(pos, val); \
  842. }
  843. static av_always_inline void
  844. yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  845. const int32_t **lumSrc, int lumFilterSize,
  846. const int16_t *chrFilter, const int32_t **unused_chrUSrc,
  847. const int32_t **unused_chrVSrc, int unused_chrFilterSize,
  848. const int32_t **alpSrc, uint16_t *dest, int dstW,
  849. int y, enum AVPixelFormat target,
  850. int unused_hasAlpha, int unused_eightbytes, int is_be)
  851. {
  852. int hasAlpha = !!alpSrc;
  853. int i;
  854. for (i = 0; i < dstW; i++) {
  855. int j;
  856. int Y = -0x40000000;
  857. int A = 0xffff;
  858. for (j = 0; j < lumFilterSize; j++)
  859. Y += lumSrc[j][i] * lumFilter[j];
  860. Y >>= 15;
  861. Y += (1<<3) + 0x8000;
  862. Y = av_clip_uint16(Y);
  863. if (hasAlpha) {
  864. A = -0x40000000 + (1<<14);
  865. for (j = 0; j < lumFilterSize; j++)
  866. A += alpSrc[j][i] * lumFilter[j];
  867. A >>= 15;
  868. A += 0x8000;
  869. A = av_clip_uint16(A);
  870. }
  871. output_pixel(&dest[2 * i ], Y);
  872. output_pixel(&dest[2 * i + 1], A);
  873. }
  874. }
  875. static av_always_inline void
  876. yuv2ya16_2_c_template(SwsInternal *c, const int32_t *buf[2],
  877. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  878. const int32_t *abuf[2], uint16_t *dest, int dstW,
  879. int yalpha, int unused_uvalpha, int y,
  880. enum AVPixelFormat target, int unused_hasAlpha,
  881. int unused_eightbytes, int is_be)
  882. {
  883. int hasAlpha = abuf && abuf[0] && abuf[1];
  884. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  885. *abuf0 = hasAlpha ? abuf[0] : NULL,
  886. *abuf1 = hasAlpha ? abuf[1] : NULL;
  887. int yalpha1 = 4096 - yalpha;
  888. int i;
  889. av_assert2(yalpha <= 4096U);
  890. for (i = 0; i < dstW; i++) {
  891. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
  892. int A;
  893. Y = av_clip_uint16(Y);
  894. if (hasAlpha) {
  895. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
  896. A = av_clip_uint16(A);
  897. }
  898. output_pixel(&dest[2 * i ], Y);
  899. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  900. }
  901. }
  902. static av_always_inline void
  903. yuv2ya16_1_c_template(SwsInternal *c, const int32_t *buf0,
  904. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  905. const int32_t *abuf0, uint16_t *dest, int dstW,
  906. int unused_uvalpha, int y, enum AVPixelFormat target,
  907. int unused_hasAlpha, int unused_eightbytes, int is_be)
  908. {
  909. int hasAlpha = !!abuf0;
  910. int i;
  911. for (i = 0; i < dstW; i++) {
  912. int Y = buf0[i] >> 3;/* 19 - 16 */
  913. int A;
  914. Y = av_clip_uint16(Y);
  915. if (hasAlpha) {
  916. A = abuf0[i] >> 3;
  917. if (A & 0x100)
  918. A = av_clip_uint16(A);
  919. }
  920. output_pixel(&dest[2 * i ], Y);
  921. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  922. }
  923. }
  924. static av_always_inline void
  925. yuv2rgba64_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  926. const int32_t **lumSrc, int lumFilterSize,
  927. const int16_t *chrFilter, const int32_t **chrUSrc,
  928. const int32_t **chrVSrc, int chrFilterSize,
  929. const int32_t **alpSrc, uint16_t *dest, int dstW,
  930. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes,
  931. int is_be)
  932. {
  933. int i;
  934. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  935. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  936. int j;
  937. unsigned Y1 = -0x40000000;
  938. unsigned Y2 = -0x40000000;
  939. int U = -(128 << 23); // 19
  940. int V = -(128 << 23);
  941. int R, G, B;
  942. for (j = 0; j < lumFilterSize; j++) {
  943. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  944. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  945. }
  946. for (j = 0; j < chrFilterSize; j++) {;
  947. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  948. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  949. }
  950. if (hasAlpha) {
  951. A1 = -0x40000000;
  952. A2 = -0x40000000;
  953. for (j = 0; j < lumFilterSize; j++) {
  954. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  955. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  956. }
  957. A1 >>= 1;
  958. A1 += 0x20002000;
  959. A2 >>= 1;
  960. A2 += 0x20002000;
  961. }
  962. // 8 bits: 12+15=27; 16 bits: 12+19=31
  963. Y1 = (int)Y1 >> 14; // 10
  964. Y1 += 0x10000;
  965. Y2 = (int)Y2 >> 14;
  966. Y2 += 0x10000;
  967. U >>= 14;
  968. V >>= 14;
  969. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  970. Y1 -= c->yuv2rgb_y_offset;
  971. Y2 -= c->yuv2rgb_y_offset;
  972. Y1 *= c->yuv2rgb_y_coeff;
  973. Y2 *= c->yuv2rgb_y_coeff;
  974. Y1 += (1 << 13) - (1 << 29); // 21
  975. Y2 += (1 << 13) - (1 << 29);
  976. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  977. R = V * c->yuv2rgb_v2r_coeff;
  978. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  979. B = U * c->yuv2rgb_u2b_coeff;
  980. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  981. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  982. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  983. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  984. if (eightbytes) {
  985. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  986. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  987. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  988. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  989. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  990. dest += 8;
  991. } else {
  992. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  993. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  994. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  995. dest += 6;
  996. }
  997. }
  998. }
  999. static av_always_inline void
  1000. yuv2rgba64_2_c_template(SwsInternal *c, const int32_t *buf[2],
  1001. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1002. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1003. int yalpha, int uvalpha, int y,
  1004. enum AVPixelFormat target, int hasAlpha, int eightbytes,
  1005. int is_be)
  1006. {
  1007. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1008. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1009. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1010. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1011. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1012. int yalpha1 = 4096 - yalpha;
  1013. int uvalpha1 = 4096 - uvalpha;
  1014. int i;
  1015. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  1016. av_assert2(yalpha <= 4096U);
  1017. av_assert2(uvalpha <= 4096U);
  1018. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1019. unsigned Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  1020. unsigned Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  1021. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1022. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1023. int R, G, B;
  1024. Y1 -= c->yuv2rgb_y_offset;
  1025. Y2 -= c->yuv2rgb_y_offset;
  1026. Y1 *= c->yuv2rgb_y_coeff;
  1027. Y2 *= c->yuv2rgb_y_coeff;
  1028. Y1 += (1 << 13) - (1 << 29);
  1029. Y2 += (1 << 13) - (1 << 29);
  1030. R = V * c->yuv2rgb_v2r_coeff;
  1031. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1032. B = U * c->yuv2rgb_u2b_coeff;
  1033. if (hasAlpha) {
  1034. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  1035. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  1036. A1 += 1 << 13;
  1037. A2 += 1 << 13;
  1038. }
  1039. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1040. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1041. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1042. if (eightbytes) {
  1043. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1044. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1045. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1046. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1047. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1048. dest += 8;
  1049. } else {
  1050. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1051. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1052. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1053. dest += 6;
  1054. }
  1055. }
  1056. }
  1057. static av_always_inline void
  1058. yuv2rgba64_1_c_template(SwsInternal *c, const int32_t *buf0,
  1059. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1060. const int32_t *abuf0, uint16_t *dest, int dstW,
  1061. int uvalpha, int y, enum AVPixelFormat target,
  1062. int hasAlpha, int eightbytes, int is_be)
  1063. {
  1064. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1065. int i;
  1066. int A1 = 0xffff<<14, A2= 0xffff<<14;
  1067. if (uvalpha < 2048) {
  1068. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1069. SUINT Y1 = (buf0[i * 2] ) >> 2;
  1070. SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
  1071. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1072. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1073. int R, G, B;
  1074. Y1 -= c->yuv2rgb_y_offset;
  1075. Y2 -= c->yuv2rgb_y_offset;
  1076. Y1 *= c->yuv2rgb_y_coeff;
  1077. Y2 *= c->yuv2rgb_y_coeff;
  1078. Y1 += (1 << 13) - (1 << 29);
  1079. Y2 += (1 << 13) - (1 << 29);
  1080. if (hasAlpha) {
  1081. A1 = abuf0[i * 2 ] * (1 << 11);
  1082. A2 = abuf0[i * 2 + 1] * (1 << 11);
  1083. A1 += 1 << 13;
  1084. A2 += 1 << 13;
  1085. }
  1086. R = V * c->yuv2rgb_v2r_coeff;
  1087. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1088. B = U * c->yuv2rgb_u2b_coeff;
  1089. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1090. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1091. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1092. if (eightbytes) {
  1093. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1094. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1095. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1096. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1097. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1098. dest += 8;
  1099. } else {
  1100. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1101. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1102. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1103. dest += 6;
  1104. }
  1105. }
  1106. } else {
  1107. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1108. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  1109. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1110. SUINT Y1 = (buf0[i * 2] ) >> 2;
  1111. SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
  1112. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1113. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1114. int R, G, B;
  1115. Y1 -= c->yuv2rgb_y_offset;
  1116. Y2 -= c->yuv2rgb_y_offset;
  1117. Y1 *= c->yuv2rgb_y_coeff;
  1118. Y2 *= c->yuv2rgb_y_coeff;
  1119. Y1 += (1 << 13) - (1 << 29);
  1120. Y2 += (1 << 13) - (1 << 29);
  1121. if (hasAlpha) {
  1122. A1 = abuf0[i * 2 ] * (1 << 11);
  1123. A2 = abuf0[i * 2 + 1] * (1 << 11);
  1124. A1 += 1 << 13;
  1125. A2 += 1 << 13;
  1126. }
  1127. R = V * c->yuv2rgb_v2r_coeff;
  1128. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1129. B = U * c->yuv2rgb_u2b_coeff;
  1130. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1131. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1132. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1133. if (eightbytes) {
  1134. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1135. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1136. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1137. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1138. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1139. dest += 8;
  1140. } else {
  1141. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1142. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1143. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1144. dest += 6;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. static av_always_inline void
  1150. yuv2rgba64_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1151. const int32_t **lumSrc, int lumFilterSize,
  1152. const int16_t *chrFilter, const int32_t **chrUSrc,
  1153. const int32_t **chrVSrc, int chrFilterSize,
  1154. const int32_t **alpSrc, uint16_t *dest, int dstW,
  1155. int y, enum AVPixelFormat target, int hasAlpha,
  1156. int eightbytes, int is_be)
  1157. {
  1158. int i;
  1159. int A = 0xffff<<14;
  1160. for (i = 0; i < dstW; i++) {
  1161. int j;
  1162. int Y = -0x40000000;
  1163. int U = -(128 << 23); // 19
  1164. int V = -(128 << 23);
  1165. int R, G, B;
  1166. for (j = 0; j < lumFilterSize; j++) {
  1167. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1168. }
  1169. for (j = 0; j < chrFilterSize; j++) {;
  1170. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1171. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1172. }
  1173. if (hasAlpha) {
  1174. A = -0x40000000;
  1175. for (j = 0; j < lumFilterSize; j++) {
  1176. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1177. }
  1178. A >>= 1;
  1179. A += 0x20002000;
  1180. }
  1181. // 8bit: 12+15=27; 16-bit: 12+19=31
  1182. Y >>= 14; // 10
  1183. Y += 0x10000;
  1184. U >>= 14;
  1185. V >>= 14;
  1186. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  1187. Y -= c->yuv2rgb_y_offset;
  1188. Y *= c->yuv2rgb_y_coeff;
  1189. Y += (1 << 13) - (1<<29); // 21
  1190. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  1191. R = V * c->yuv2rgb_v2r_coeff;
  1192. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1193. B = U * c->yuv2rgb_u2b_coeff;
  1194. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  1195. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15), 16));
  1196. output_pixel(&dest[1], av_clip_uintp2((( G + Y)>>14) + (1<<15), 16));
  1197. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15), 16));
  1198. if (eightbytes) {
  1199. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1200. dest += 4;
  1201. } else {
  1202. dest += 3;
  1203. }
  1204. }
  1205. }
  1206. static av_always_inline void
  1207. yuv2rgba64_full_2_c_template(SwsInternal *c, const int32_t *buf[2],
  1208. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1209. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1210. int yalpha, int uvalpha, int y,
  1211. enum AVPixelFormat target, int hasAlpha, int eightbytes,
  1212. int is_be)
  1213. {
  1214. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1215. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1216. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1217. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1218. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1219. int yalpha1 = 4096 - yalpha;
  1220. int uvalpha1 = 4096 - uvalpha;
  1221. int i;
  1222. int A = 0xffff<<14;
  1223. av_assert2(yalpha <= 4096U);
  1224. av_assert2(uvalpha <= 4096U);
  1225. for (i = 0; i < dstW; i++) {
  1226. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  1227. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1228. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1229. int R, G, B;
  1230. Y -= c->yuv2rgb_y_offset;
  1231. Y *= c->yuv2rgb_y_coeff;
  1232. Y += (1 << 13) - (1 << 29);
  1233. R = V * c->yuv2rgb_v2r_coeff;
  1234. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1235. B = U * c->yuv2rgb_u2b_coeff;
  1236. if (hasAlpha) {
  1237. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  1238. A += 1 << 13;
  1239. }
  1240. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
  1241. output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));
  1242. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
  1243. if (eightbytes) {
  1244. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1245. dest += 4;
  1246. } else {
  1247. dest += 3;
  1248. }
  1249. }
  1250. }
  1251. static av_always_inline void
  1252. yuv2rgba64_full_1_c_template(SwsInternal *c, const int32_t *buf0,
  1253. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1254. const int32_t *abuf0, uint16_t *dest, int dstW,
  1255. int uvalpha, int y, enum AVPixelFormat target,
  1256. int hasAlpha, int eightbytes, int is_be)
  1257. {
  1258. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1259. int i;
  1260. int A = 0xffff<<14;
  1261. if (uvalpha < 2048) {
  1262. for (i = 0; i < dstW; i++) {
  1263. SUINT Y = (buf0[i]) >> 2;
  1264. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1265. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1266. int R, G, B;
  1267. Y -= c->yuv2rgb_y_offset;
  1268. Y *= c->yuv2rgb_y_coeff;
  1269. Y += (1 << 13) - (1 << 29);
  1270. if (hasAlpha) {
  1271. A = abuf0[i] * (1 << 11);
  1272. A += 1 << 13;
  1273. }
  1274. R = V * c->yuv2rgb_v2r_coeff;
  1275. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1276. B = U * c->yuv2rgb_u2b_coeff;
  1277. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1278. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1279. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1280. if (eightbytes) {
  1281. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1282. dest += 4;
  1283. } else {
  1284. dest += 3;
  1285. }
  1286. }
  1287. } else {
  1288. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1289. int A = 0xffff<<14;
  1290. for (i = 0; i < dstW; i++) {
  1291. SUINT Y = (buf0[i] ) >> 2;
  1292. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1293. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1294. int R, G, B;
  1295. Y -= c->yuv2rgb_y_offset;
  1296. Y *= c->yuv2rgb_y_coeff;
  1297. Y += (1 << 13) - (1 << 29);
  1298. if (hasAlpha) {
  1299. A = abuf0[i] * (1 << 11);
  1300. A += 1 << 13;
  1301. }
  1302. R = V * c->yuv2rgb_v2r_coeff;
  1303. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1304. B = U * c->yuv2rgb_u2b_coeff;
  1305. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1306. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1307. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1308. if (eightbytes) {
  1309. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1310. dest += 4;
  1311. } else {
  1312. dest += 3;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. #undef output_pixel
  1318. #undef r_b
  1319. #undef b_r
  1320. #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
  1321. static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  1322. const int16_t **_lumSrc, int lumFilterSize, \
  1323. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1324. const int16_t **_chrVSrc, int chrFilterSize, \
  1325. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1326. int y) \
  1327. { \
  1328. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1329. **chrUSrc = (const int32_t **) _chrUSrc, \
  1330. **chrVSrc = (const int32_t **) _chrVSrc, \
  1331. **alpSrc = (const int32_t **) _alpSrc; \
  1332. uint16_t *dest = (uint16_t *) _dest; \
  1333. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1334. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1335. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
  1336. } \
  1337. \
  1338. static void name ## ext ## _2_c(SwsInternal *c, const int16_t *_buf[2], \
  1339. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1340. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1341. int yalpha, int uvalpha, int y) \
  1342. { \
  1343. const int32_t **buf = (const int32_t **) _buf, \
  1344. **ubuf = (const int32_t **) _ubuf, \
  1345. **vbuf = (const int32_t **) _vbuf, \
  1346. **abuf = (const int32_t **) _abuf; \
  1347. uint16_t *dest = (uint16_t *) _dest; \
  1348. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1349. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1350. } \
  1351. \
  1352. static void name ## ext ## _1_c(SwsInternal *c, const int16_t *_buf0, \
  1353. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1354. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1355. int uvalpha, int y) \
  1356. { \
  1357. const int32_t *buf0 = (const int32_t *) _buf0, \
  1358. **ubuf = (const int32_t **) _ubuf, \
  1359. **vbuf = (const int32_t **) _vbuf, \
  1360. *abuf0 = (const int32_t *) _abuf0; \
  1361. uint16_t *dest = (uint16_t *) _dest; \
  1362. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1363. dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1364. }
  1365. #define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
  1366. YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
  1367. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48, BE, 0, 0)
  1368. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48, LE, 0, 0)
  1369. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48, BE, 0, 0)
  1370. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48, LE, 0, 0)
  1371. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1372. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1373. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1374. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1375. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1376. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1377. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1378. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1379. YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
  1380. YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
  1381. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
  1382. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
  1383. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48, BE, 0, 0)
  1384. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48, LE, 0, 0)
  1385. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1386. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1387. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1388. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1389. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1390. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1391. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1392. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1393. /*
  1394. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1395. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1396. * things like endianness conversion and shifting. The caller takes care of
  1397. * setting the correct offset in these tables from the chroma (U/V) values.
  1398. * This function then uses the luminance (Y1/Y2) values to write out the
  1399. * correct RGB values into the destination buffer.
  1400. */
  1401. static av_always_inline void
  1402. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1403. unsigned A1, unsigned A2,
  1404. const void *_r, const void *_g, const void *_b, int y,
  1405. enum AVPixelFormat target, int hasAlpha)
  1406. {
  1407. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1408. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1409. uint32_t *dest = (uint32_t *) _dest;
  1410. const uint32_t *r = (const uint32_t *) _r;
  1411. const uint32_t *g = (const uint32_t *) _g;
  1412. const uint32_t *b = (const uint32_t *) _b;
  1413. #if CONFIG_SMALL
  1414. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1415. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1416. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1417. #else
  1418. if (hasAlpha) {
  1419. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1420. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1421. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1422. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1423. } else {
  1424. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1425. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1426. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1427. #endif
  1428. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1429. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1430. }
  1431. #endif
  1432. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1433. uint8_t *dest = (uint8_t *) _dest;
  1434. const uint8_t *r = (const uint8_t *) _r;
  1435. const uint8_t *g = (const uint8_t *) _g;
  1436. const uint8_t *b = (const uint8_t *) _b;
  1437. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1438. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1439. dest[i * 6 + 0] = r_b[Y1];
  1440. dest[i * 6 + 1] = g[Y1];
  1441. dest[i * 6 + 2] = b_r[Y1];
  1442. dest[i * 6 + 3] = r_b[Y2];
  1443. dest[i * 6 + 4] = g[Y2];
  1444. dest[i * 6 + 5] = b_r[Y2];
  1445. #undef r_b
  1446. #undef b_r
  1447. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1448. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1449. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1450. uint16_t *dest = (uint16_t *) _dest;
  1451. const uint16_t *r = (const uint16_t *) _r;
  1452. const uint16_t *g = (const uint16_t *) _g;
  1453. const uint16_t *b = (const uint16_t *) _b;
  1454. int dr1, dg1, db1, dr2, dg2, db2;
  1455. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1456. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1457. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1458. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1459. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1460. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1461. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1462. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1463. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1464. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1465. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1466. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1467. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1468. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1469. } else {
  1470. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1471. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1472. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1473. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1474. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1475. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1476. }
  1477. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1478. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1479. } else if (target == AV_PIX_FMT_X2RGB10 || target == AV_PIX_FMT_X2BGR10) {
  1480. uint32_t *dest = (uint32_t *) _dest;
  1481. const uint32_t *r = (const uint32_t *) _r;
  1482. const uint32_t *g = (const uint32_t *) _g;
  1483. const uint32_t *b = (const uint32_t *) _b;
  1484. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1485. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1486. } else /* 8/4 bits */ {
  1487. uint8_t *dest = (uint8_t *) _dest;
  1488. const uint8_t *r = (const uint8_t *) _r;
  1489. const uint8_t *g = (const uint8_t *) _g;
  1490. const uint8_t *b = (const uint8_t *) _b;
  1491. int dr1, dg1, db1, dr2, dg2, db2;
  1492. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1493. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1494. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1495. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1496. db1 = d64[(i * 2 + 0) & 7];
  1497. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1498. db2 = d64[(i * 2 + 1) & 7];
  1499. } else {
  1500. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1501. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1502. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1503. dg1 = d64[(i * 2 + 0) & 7];
  1504. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1505. dg2 = d64[(i * 2 + 1) & 7];
  1506. }
  1507. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1508. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1509. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1510. } else {
  1511. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1512. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1513. }
  1514. }
  1515. }
  1516. static av_always_inline void
  1517. yuv2rgb_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1518. const int16_t **lumSrc, int lumFilterSize,
  1519. const int16_t *chrFilter, const int16_t **chrUSrc,
  1520. const int16_t **chrVSrc, int chrFilterSize,
  1521. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1522. int y, enum AVPixelFormat target, int hasAlpha)
  1523. {
  1524. int i;
  1525. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1526. int j, A1, A2;
  1527. int Y1 = 1 << 18;
  1528. int Y2 = 1 << 18;
  1529. int U = 1 << 18;
  1530. int V = 1 << 18;
  1531. const void *r, *g, *b;
  1532. for (j = 0; j < lumFilterSize; j++) {
  1533. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1534. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1535. }
  1536. for (j = 0; j < chrFilterSize; j++) {
  1537. U += chrUSrc[j][i] * chrFilter[j];
  1538. V += chrVSrc[j][i] * chrFilter[j];
  1539. }
  1540. Y1 >>= 19;
  1541. Y2 >>= 19;
  1542. U >>= 19;
  1543. V >>= 19;
  1544. if (hasAlpha) {
  1545. A1 = 1 << 18;
  1546. A2 = 1 << 18;
  1547. for (j = 0; j < lumFilterSize; j++) {
  1548. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1549. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1550. }
  1551. A1 >>= 19;
  1552. A2 >>= 19;
  1553. if ((A1 | A2) & 0x100) {
  1554. A1 = av_clip_uint8(A1);
  1555. A2 = av_clip_uint8(A2);
  1556. }
  1557. }
  1558. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1559. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1560. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1561. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1562. r, g, b, y, target, hasAlpha);
  1563. }
  1564. }
  1565. static av_always_inline void
  1566. yuv2rgb_2_c_template(SwsInternal *c, const int16_t *buf[2],
  1567. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1568. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1569. int yalpha, int uvalpha, int y,
  1570. enum AVPixelFormat target, int hasAlpha)
  1571. {
  1572. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1573. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1574. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1575. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1576. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1577. int yalpha1 = 4096 - yalpha;
  1578. int uvalpha1 = 4096 - uvalpha;
  1579. int i;
  1580. av_assert2(yalpha <= 4096U);
  1581. av_assert2(uvalpha <= 4096U);
  1582. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1583. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1584. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1585. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1586. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1587. int A1, A2;
  1588. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1589. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1590. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1591. if (hasAlpha) {
  1592. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1593. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1594. A1 = av_clip_uint8(A1);
  1595. A2 = av_clip_uint8(A2);
  1596. }
  1597. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1598. r, g, b, y, target, hasAlpha);
  1599. }
  1600. }
  1601. static av_always_inline void
  1602. yuv2rgb_1_c_template(SwsInternal *c, const int16_t *buf0,
  1603. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1604. const int16_t *abuf0, uint8_t *dest, int dstW,
  1605. int uvalpha, int y, enum AVPixelFormat target,
  1606. int hasAlpha)
  1607. {
  1608. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1609. int i;
  1610. if (uvalpha < 2048) {
  1611. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1612. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1613. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1614. int U = (ubuf0[i] + 64) >> 7;
  1615. int V = (vbuf0[i] + 64) >> 7;
  1616. int A1, A2;
  1617. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1618. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1619. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1620. if (hasAlpha) {
  1621. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1622. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1623. A1 = av_clip_uint8(A1);
  1624. A2 = av_clip_uint8(A2);
  1625. }
  1626. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1627. r, g, b, y, target, hasAlpha);
  1628. }
  1629. } else {
  1630. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1631. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1632. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1633. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1634. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1635. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1636. int A1, A2;
  1637. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1638. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1639. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1640. if (hasAlpha) {
  1641. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1642. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1643. A1 = av_clip_uint8(A1);
  1644. A2 = av_clip_uint8(A2);
  1645. }
  1646. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1647. r, g, b, y, target, hasAlpha);
  1648. }
  1649. }
  1650. }
  1651. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1652. static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  1653. const int16_t **lumSrc, int lumFilterSize, \
  1654. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1655. const int16_t **chrVSrc, int chrFilterSize, \
  1656. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1657. int y) \
  1658. { \
  1659. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1660. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1661. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1662. }
  1663. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1664. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1665. static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
  1666. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1667. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1668. int yalpha, int uvalpha, int y) \
  1669. { \
  1670. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1671. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1672. }
  1673. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1674. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1675. static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
  1676. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1677. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1678. int uvalpha, int y) \
  1679. { \
  1680. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1681. dstW, uvalpha, y, fmt, hasAlpha); \
  1682. }
  1683. #if CONFIG_SMALL
  1684. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1685. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1686. #else
  1687. #if CONFIG_SWSCALE_ALPHA
  1688. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1689. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1690. #endif
  1691. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1692. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1693. #endif
  1694. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1695. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1696. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1697. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1698. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1699. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1700. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1701. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1702. YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
  1703. YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0)
  1704. static av_always_inline void yuv2rgb_write_full(SwsInternal *c,
  1705. uint8_t *dest, int i, int Y, int A, int U, int V,
  1706. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1707. {
  1708. int R, G, B;
  1709. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1710. Y -= c->yuv2rgb_y_offset;
  1711. Y *= c->yuv2rgb_y_coeff;
  1712. Y += 1 << 21;
  1713. R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
  1714. G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
  1715. B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff;
  1716. if ((R | G | B) & 0xC0000000) {
  1717. R = av_clip_uintp2(R, 30);
  1718. G = av_clip_uintp2(G, 30);
  1719. B = av_clip_uintp2(B, 30);
  1720. }
  1721. switch(target) {
  1722. case AV_PIX_FMT_ARGB:
  1723. dest[0] = hasAlpha ? A : 255;
  1724. dest[1] = R >> 22;
  1725. dest[2] = G >> 22;
  1726. dest[3] = B >> 22;
  1727. break;
  1728. case AV_PIX_FMT_RGB24:
  1729. dest[0] = R >> 22;
  1730. dest[1] = G >> 22;
  1731. dest[2] = B >> 22;
  1732. break;
  1733. case AV_PIX_FMT_RGBA:
  1734. dest[0] = R >> 22;
  1735. dest[1] = G >> 22;
  1736. dest[2] = B >> 22;
  1737. dest[3] = hasAlpha ? A : 255;
  1738. break;
  1739. case AV_PIX_FMT_ABGR:
  1740. dest[0] = hasAlpha ? A : 255;
  1741. dest[1] = B >> 22;
  1742. dest[2] = G >> 22;
  1743. dest[3] = R >> 22;
  1744. break;
  1745. case AV_PIX_FMT_BGR24:
  1746. dest[0] = B >> 22;
  1747. dest[1] = G >> 22;
  1748. dest[2] = R >> 22;
  1749. break;
  1750. case AV_PIX_FMT_BGRA:
  1751. dest[0] = B >> 22;
  1752. dest[1] = G >> 22;
  1753. dest[2] = R >> 22;
  1754. dest[3] = hasAlpha ? A : 255;
  1755. break;
  1756. case AV_PIX_FMT_X2RGB10LE:
  1757. R >>= 20;
  1758. G >>= 20;
  1759. B >>= 20;
  1760. AV_WL32(dest, (3U << 30) + (R << 20) + (G << 10) + B);
  1761. break;
  1762. case AV_PIX_FMT_X2BGR10LE:
  1763. R >>= 20;
  1764. G >>= 20;
  1765. B >>= 20;
  1766. AV_WL32(dest, (3U << 30) + (B << 20) + (G << 10) + R);
  1767. break;
  1768. case AV_PIX_FMT_BGR4_BYTE:
  1769. case AV_PIX_FMT_RGB4_BYTE:
  1770. case AV_PIX_FMT_BGR8:
  1771. case AV_PIX_FMT_RGB8:
  1772. {
  1773. int r,g,b;
  1774. switch (c->dither) {
  1775. case SWS_DITHER_NONE:
  1776. if (isrgb8) {
  1777. r = av_clip_uintp2(R >> 27, 3);
  1778. g = av_clip_uintp2(G >> 27, 3);
  1779. b = av_clip_uintp2(B >> 28, 2);
  1780. } else {
  1781. r = av_clip_uintp2(R >> 29, 1);
  1782. g = av_clip_uintp2(G >> 28, 2);
  1783. b = av_clip_uintp2(B >> 29, 1);
  1784. }
  1785. break;
  1786. default:
  1787. case SWS_DITHER_AUTO:
  1788. case SWS_DITHER_ED:
  1789. R >>= 22;
  1790. G >>= 22;
  1791. B >>= 22;
  1792. R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
  1793. G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
  1794. B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
  1795. c->dither_error[0][i] = err[0];
  1796. c->dither_error[1][i] = err[1];
  1797. c->dither_error[2][i] = err[2];
  1798. r = R >> (isrgb8 ? 5 : 7);
  1799. g = G >> (isrgb8 ? 5 : 6);
  1800. b = B >> (isrgb8 ? 6 : 7);
  1801. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1802. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1803. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1804. err[0] = R - r*(isrgb8 ? 36 : 255);
  1805. err[1] = G - g*(isrgb8 ? 36 : 85);
  1806. err[2] = B - b*(isrgb8 ? 85 : 255);
  1807. break;
  1808. case SWS_DITHER_A_DITHER:
  1809. if (isrgb8) {
  1810. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1811. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1812. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1813. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1814. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1815. r = av_clip_uintp2(r, 3);
  1816. g = av_clip_uintp2(g, 3);
  1817. b = av_clip_uintp2(b, 2);
  1818. } else {
  1819. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1820. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1821. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1822. r = av_clip_uintp2(r, 1);
  1823. g = av_clip_uintp2(g, 2);
  1824. b = av_clip_uintp2(b, 1);
  1825. }
  1826. break;
  1827. case SWS_DITHER_X_DITHER:
  1828. if (isrgb8) {
  1829. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1830. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1831. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1832. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1833. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1834. r = av_clip_uintp2(r, 3);
  1835. g = av_clip_uintp2(g, 3);
  1836. b = av_clip_uintp2(b, 2);
  1837. } else {
  1838. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1839. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1840. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1841. r = av_clip_uintp2(r, 1);
  1842. g = av_clip_uintp2(g, 2);
  1843. b = av_clip_uintp2(b, 1);
  1844. }
  1845. break;
  1846. }
  1847. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1848. dest[0] = r + 2*g + 8*b;
  1849. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1850. dest[0] = b + 2*g + 8*r;
  1851. } else if(target == AV_PIX_FMT_BGR8) {
  1852. dest[0] = r + 8*g + 64*b;
  1853. } else if(target == AV_PIX_FMT_RGB8) {
  1854. dest[0] = b + 4*g + 32*r;
  1855. } else
  1856. av_assert2(0);
  1857. break;}
  1858. }
  1859. }
  1860. static av_always_inline void
  1861. yuv2rgb_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1862. const int16_t **lumSrc, int lumFilterSize,
  1863. const int16_t *chrFilter, const int16_t **chrUSrc,
  1864. const int16_t **chrVSrc, int chrFilterSize,
  1865. const int16_t **alpSrc, uint8_t *dest,
  1866. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1867. {
  1868. int i;
  1869. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1870. int err[4] = {0};
  1871. int A = 0; //init to silence warning
  1872. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1873. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1874. step = 1;
  1875. for (i = 0; i < dstW; i++) {
  1876. int j;
  1877. int Y = 1<<9;
  1878. int U = (1<<9)-(128 << 19);
  1879. int V = (1<<9)-(128 << 19);
  1880. for (j = 0; j < lumFilterSize; j++) {
  1881. Y += lumSrc[j][i] * lumFilter[j];
  1882. }
  1883. for (j = 0; j < chrFilterSize; j++) {
  1884. U += chrUSrc[j][i] * chrFilter[j];
  1885. V += chrVSrc[j][i] * chrFilter[j];
  1886. }
  1887. Y >>= 10;
  1888. U >>= 10;
  1889. V >>= 10;
  1890. if (hasAlpha) {
  1891. A = 1 << 18;
  1892. for (j = 0; j < lumFilterSize; j++) {
  1893. A += alpSrc[j][i] * lumFilter[j];
  1894. }
  1895. A >>= 19;
  1896. if (A & 0x100)
  1897. A = av_clip_uint8(A);
  1898. }
  1899. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1900. dest += step;
  1901. }
  1902. c->dither_error[0][i] = err[0];
  1903. c->dither_error[1][i] = err[1];
  1904. c->dither_error[2][i] = err[2];
  1905. }
  1906. static av_always_inline void
  1907. yuv2rgb_full_2_c_template(SwsInternal *c, const int16_t *buf[2],
  1908. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1909. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1910. int yalpha, int uvalpha, int y,
  1911. enum AVPixelFormat target, int hasAlpha)
  1912. {
  1913. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1914. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1915. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1916. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1917. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1918. int yalpha1 = 4096 - yalpha;
  1919. int uvalpha1 = 4096 - uvalpha;
  1920. int i;
  1921. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1922. int err[4] = {0};
  1923. int A = 0; // init to silcene warning
  1924. av_assert2(yalpha <= 4096U);
  1925. av_assert2(uvalpha <= 4096U);
  1926. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1927. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1928. step = 1;
  1929. for (i = 0; i < dstW; i++) {
  1930. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1931. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1932. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1933. if (hasAlpha) {
  1934. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1935. if (A & 0x100)
  1936. A = av_clip_uint8(A);
  1937. }
  1938. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1939. dest += step;
  1940. }
  1941. c->dither_error[0][i] = err[0];
  1942. c->dither_error[1][i] = err[1];
  1943. c->dither_error[2][i] = err[2];
  1944. }
  1945. static av_always_inline void
  1946. yuv2rgb_full_1_c_template(SwsInternal *c, const int16_t *buf0,
  1947. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1948. const int16_t *abuf0, uint8_t *dest, int dstW,
  1949. int uvalpha, int y, enum AVPixelFormat target,
  1950. int hasAlpha)
  1951. {
  1952. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1953. int i;
  1954. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1955. int err[4] = {0};
  1956. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1957. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1958. step = 1;
  1959. if (uvalpha < 2048) {
  1960. int A = 0; //init to silence warning
  1961. for (i = 0; i < dstW; i++) {
  1962. int Y = buf0[i] * 4;
  1963. int U = (ubuf0[i] - (128<<7)) * 4;
  1964. int V = (vbuf0[i] - (128<<7)) * 4;
  1965. if (hasAlpha) {
  1966. A = (abuf0[i] + 64) >> 7;
  1967. if (A & 0x100)
  1968. A = av_clip_uint8(A);
  1969. }
  1970. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1971. dest += step;
  1972. }
  1973. } else {
  1974. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1975. int A = 0; //init to silence warning
  1976. for (i = 0; i < dstW; i++) {
  1977. int Y = buf0[i] * 4;
  1978. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) * 2;
  1979. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) * 2;
  1980. if (hasAlpha) {
  1981. A = (abuf0[i] + 64) >> 7;
  1982. if (A & 0x100)
  1983. A = av_clip_uint8(A);
  1984. }
  1985. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1986. dest += step;
  1987. }
  1988. }
  1989. c->dither_error[0][i] = err[0];
  1990. c->dither_error[1][i] = err[1];
  1991. c->dither_error[2][i] = err[2];
  1992. }
  1993. #if CONFIG_SMALL
  1994. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1995. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1996. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1997. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1998. #else
  1999. #if CONFIG_SWSCALE_ALPHA
  2000. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  2001. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  2002. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  2003. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  2004. #endif
  2005. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  2006. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  2007. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  2008. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  2009. #endif
  2010. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  2011. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  2012. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  2013. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  2014. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  2015. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  2016. YUV2RGBWRAPPER(yuv2, rgb_full, x2rgb10_full, AV_PIX_FMT_X2RGB10LE, 0)
  2017. YUV2RGBWRAPPER(yuv2, rgb_full, x2bgr10_full, AV_PIX_FMT_X2BGR10LE, 0)
  2018. static void
  2019. yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2020. const int16_t **lumSrc, int lumFilterSize,
  2021. const int16_t *chrFilter, const int16_t **chrUSrc,
  2022. const int16_t **chrVSrc, int chrFilterSize,
  2023. const int16_t **alpSrc, uint8_t **dest,
  2024. int dstW, int y)
  2025. {
  2026. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2027. int i;
  2028. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  2029. uint16_t **dest16 = (uint16_t**)dest;
  2030. int SH = 22 + 8 - desc->comp[0].depth;
  2031. int A = 0; // init to silence warning
  2032. for (i = 0; i < dstW; i++) {
  2033. int j;
  2034. int Y = 1 << 9;
  2035. int U = (1 << 9) - (128 << 19);
  2036. int V = (1 << 9) - (128 << 19);
  2037. int R, G, B;
  2038. for (j = 0; j < lumFilterSize; j++)
  2039. Y += lumSrc[j][i] * lumFilter[j];
  2040. for (j = 0; j < chrFilterSize; j++) {
  2041. U += chrUSrc[j][i] * chrFilter[j];
  2042. V += chrVSrc[j][i] * chrFilter[j];
  2043. }
  2044. Y >>= 10;
  2045. U >>= 10;
  2046. V >>= 10;
  2047. if (hasAlpha) {
  2048. A = 1 << 18;
  2049. for (j = 0; j < lumFilterSize; j++)
  2050. A += alpSrc[j][i] * lumFilter[j];
  2051. if (A & 0xF8000000)
  2052. A = av_clip_uintp2(A, 27);
  2053. }
  2054. Y -= c->yuv2rgb_y_offset;
  2055. Y *= c->yuv2rgb_y_coeff;
  2056. Y += 1 << (SH-1);
  2057. R = Y + V * c->yuv2rgb_v2r_coeff;
  2058. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2059. B = Y + U * c->yuv2rgb_u2b_coeff;
  2060. if ((R | G | B) & 0xC0000000) {
  2061. R = av_clip_uintp2(R, 30);
  2062. G = av_clip_uintp2(G, 30);
  2063. B = av_clip_uintp2(B, 30);
  2064. }
  2065. if (SH != 22) {
  2066. dest16[0][i] = G >> SH;
  2067. dest16[1][i] = B >> SH;
  2068. dest16[2][i] = R >> SH;
  2069. if (hasAlpha)
  2070. dest16[3][i] = A >> (SH - 3);
  2071. } else {
  2072. dest[0][i] = G >> 22;
  2073. dest[1][i] = B >> 22;
  2074. dest[2][i] = R >> 22;
  2075. if (hasAlpha)
  2076. dest[3][i] = A >> 19;
  2077. }
  2078. }
  2079. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2080. for (i = 0; i < dstW; i++) {
  2081. dest16[0][i] = av_bswap16(dest16[0][i]);
  2082. dest16[1][i] = av_bswap16(dest16[1][i]);
  2083. dest16[2][i] = av_bswap16(dest16[2][i]);
  2084. if (hasAlpha)
  2085. dest16[3][i] = av_bswap16(dest16[3][i]);
  2086. }
  2087. }
  2088. }
  2089. static void
  2090. yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2091. const int16_t **lumSrcx, int lumFilterSize,
  2092. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2093. const int16_t **chrVSrcx, int chrFilterSize,
  2094. const int16_t **alpSrcx, uint8_t **dest,
  2095. int dstW, int y)
  2096. {
  2097. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2098. int i;
  2099. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2100. uint16_t **dest16 = (uint16_t**)dest;
  2101. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2102. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2103. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2104. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2105. for (i = 0; i < dstW; i++) {
  2106. int j;
  2107. int Y = -0x40000000;
  2108. int U = -(128 << 23);
  2109. int V = -(128 << 23);
  2110. int R, G, B, A;
  2111. for (j = 0; j < lumFilterSize; j++)
  2112. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2113. for (j = 0; j < chrFilterSize; j++) {
  2114. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2115. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2116. }
  2117. Y >>= 14;
  2118. Y += 0x10000;
  2119. U >>= 14;
  2120. V >>= 14;
  2121. if (hasAlpha) {
  2122. A = -0x40000000;
  2123. for (j = 0; j < lumFilterSize; j++)
  2124. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2125. A >>= 1;
  2126. A += 0x20002000;
  2127. }
  2128. Y -= c->yuv2rgb_y_offset;
  2129. Y *= c->yuv2rgb_y_coeff;
  2130. Y += (1 << 13) - (1 << 29);
  2131. R = V * c->yuv2rgb_v2r_coeff;
  2132. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2133. B = U * c->yuv2rgb_u2b_coeff;
  2134. dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2135. dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2136. dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2137. if (hasAlpha)
  2138. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  2139. }
  2140. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2141. for (i = 0; i < dstW; i++) {
  2142. dest16[0][i] = av_bswap16(dest16[0][i]);
  2143. dest16[1][i] = av_bswap16(dest16[1][i]);
  2144. dest16[2][i] = av_bswap16(dest16[2][i]);
  2145. if (hasAlpha)
  2146. dest16[3][i] = av_bswap16(dest16[3][i]);
  2147. }
  2148. }
  2149. }
  2150. static void
  2151. yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2152. const int16_t **lumSrcx, int lumFilterSize,
  2153. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2154. const int16_t **chrVSrcx, int chrFilterSize,
  2155. const int16_t **alpSrcx, uint8_t **dest,
  2156. int dstW, int y)
  2157. {
  2158. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2159. int i;
  2160. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2161. uint32_t **dest32 = (uint32_t**)dest;
  2162. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2163. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2164. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2165. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2166. static const float float_mult = 1.0f / 65535.0f;
  2167. for (i = 0; i < dstW; i++) {
  2168. int j;
  2169. int Y = -0x40000000;
  2170. int U = -(128 << 23);
  2171. int V = -(128 << 23);
  2172. int R, G, B, A;
  2173. for (j = 0; j < lumFilterSize; j++)
  2174. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2175. for (j = 0; j < chrFilterSize; j++) {
  2176. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2177. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2178. }
  2179. Y >>= 14;
  2180. Y += 0x10000;
  2181. U >>= 14;
  2182. V >>= 14;
  2183. if (hasAlpha) {
  2184. A = -0x40000000;
  2185. for (j = 0; j < lumFilterSize; j++)
  2186. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2187. A >>= 1;
  2188. A += 0x20002000;
  2189. }
  2190. Y -= c->yuv2rgb_y_offset;
  2191. Y *= c->yuv2rgb_y_coeff;
  2192. Y += (1 << 13) - (1 << 29);
  2193. R = V * c->yuv2rgb_v2r_coeff;
  2194. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2195. B = U * c->yuv2rgb_u2b_coeff;
  2196. R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2197. G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2198. B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2199. dest32[0][i] = av_float2int(float_mult * (float)G);
  2200. dest32[1][i] = av_float2int(float_mult * (float)B);
  2201. dest32[2][i] = av_float2int(float_mult * (float)R);
  2202. if (hasAlpha)
  2203. dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
  2204. }
  2205. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2206. for (i = 0; i < dstW; i++) {
  2207. dest32[0][i] = av_bswap32(dest32[0][i]);
  2208. dest32[1][i] = av_bswap32(dest32[1][i]);
  2209. dest32[2][i] = av_bswap32(dest32[2][i]);
  2210. if (hasAlpha)
  2211. dest32[3][i] = av_bswap32(dest32[3][i]);
  2212. }
  2213. }
  2214. }
  2215. static void
  2216. yuv2ya8_1_c(SwsInternal *c, const int16_t *buf0,
  2217. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2218. const int16_t *abuf0, uint8_t *dest, int dstW,
  2219. int uvalpha, int y)
  2220. {
  2221. int hasAlpha = !!abuf0;
  2222. int i;
  2223. for (i = 0; i < dstW; i++) {
  2224. int Y = (buf0[i] + 64) >> 7;
  2225. int A;
  2226. Y = av_clip_uint8(Y);
  2227. if (hasAlpha) {
  2228. A = (abuf0[i] + 64) >> 7;
  2229. if (A & 0x100)
  2230. A = av_clip_uint8(A);
  2231. }
  2232. dest[i * 2 ] = Y;
  2233. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2234. }
  2235. }
  2236. static void
  2237. yuv2ya8_2_c(SwsInternal *c, const int16_t *buf[2],
  2238. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2239. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2240. int yalpha, int uvalpha, int y)
  2241. {
  2242. int hasAlpha = abuf && abuf[0] && abuf[1];
  2243. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2244. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2245. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2246. int yalpha1 = 4096 - yalpha;
  2247. int i;
  2248. av_assert2(yalpha <= 4096U);
  2249. for (i = 0; i < dstW; i++) {
  2250. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2251. int A;
  2252. Y = av_clip_uint8(Y);
  2253. if (hasAlpha) {
  2254. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2255. A = av_clip_uint8(A);
  2256. }
  2257. dest[i * 2 ] = Y;
  2258. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2259. }
  2260. }
  2261. static void
  2262. yuv2ya8_X_c(SwsInternal *c, const int16_t *lumFilter,
  2263. const int16_t **lumSrc, int lumFilterSize,
  2264. const int16_t *chrFilter, const int16_t **chrUSrc,
  2265. const int16_t **chrVSrc, int chrFilterSize,
  2266. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2267. {
  2268. int hasAlpha = !!alpSrc;
  2269. int i;
  2270. for (i = 0; i < dstW; i++) {
  2271. int j;
  2272. int Y = 1 << 18, A = 1 << 18;
  2273. for (j = 0; j < lumFilterSize; j++)
  2274. Y += lumSrc[j][i] * lumFilter[j];
  2275. Y >>= 19;
  2276. if (Y & 0x100)
  2277. Y = av_clip_uint8(Y);
  2278. if (hasAlpha) {
  2279. for (j = 0; j < lumFilterSize; j++)
  2280. A += alpSrc[j][i] * lumFilter[j];
  2281. A >>= 19;
  2282. if (A & 0x100)
  2283. A = av_clip_uint8(A);
  2284. }
  2285. dest[2 * i ] = Y;
  2286. dest[2 * i + 1] = hasAlpha ? A : 255;
  2287. }
  2288. }
  2289. #define output_pixels(pos, val) \
  2290. if (is_be) { \
  2291. AV_WB16(pos, val); \
  2292. } else { \
  2293. AV_WL16(pos, val); \
  2294. }
  2295. static av_always_inline void
  2296. yuv2ayuv64_X_c(SwsInternal *c, const int16_t *lumFilter,
  2297. const int16_t **_lumSrc, int lumFilterSize,
  2298. const int16_t *chrFilter, const int16_t **_chrUSrc,
  2299. const int16_t **_chrVSrc, int chrFilterSize,
  2300. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y,
  2301. int A_offset, int Y_offset, int U_offset, int V_offset, int is_be)
  2302. {
  2303. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  2304. **chrUSrc = (const int32_t **) _chrUSrc,
  2305. **chrVSrc = (const int32_t **) _chrVSrc,
  2306. **alpSrc = (const int32_t **) _alpSrc;
  2307. int hasAlpha = !!alpSrc;
  2308. int i;
  2309. for (i = 0; i < dstW; i++) {
  2310. int Y = 1 << 14, U = 1 << 14;
  2311. int V = 1 << 14, A = 1 << 14;
  2312. int j;
  2313. Y -= 0x40000000;
  2314. U -= 0x40000000;
  2315. V -= 0x40000000;
  2316. A -= 0x40000000;
  2317. for (j = 0; j < lumFilterSize; j++)
  2318. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2319. for (j = 0; j < chrFilterSize; j++)
  2320. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2321. for (j = 0; j < chrFilterSize; j++)
  2322. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2323. if (hasAlpha)
  2324. for (j = 0; j < lumFilterSize; j++)
  2325. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2326. Y = 0x8000 + av_clip_int16(Y >> 15);
  2327. U = 0x8000 + av_clip_int16(U >> 15);
  2328. V = 0x8000 + av_clip_int16(V >> 15);
  2329. if (hasAlpha)
  2330. A = 0x8000 + av_clip_int16(A >> 15);
  2331. output_pixels(dest + 8 * i + A_offset, hasAlpha ? A : 65535);
  2332. output_pixels(dest + 8 * i + Y_offset, Y);
  2333. output_pixels(dest + 8 * i + U_offset, U);
  2334. output_pixels(dest + 8 * i + V_offset, V);
  2335. }
  2336. }
  2337. #define YUV2AYUV64(pixfmt, BE_LE, A, Y, U, V, is_be) \
  2338. static void \
  2339. yuv2 ## pixfmt ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2340. const int16_t **lumSrc, int lumFilterSize, \
  2341. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2342. const int16_t **chrVSrc, int chrFilterSize, \
  2343. const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
  2344. { \
  2345. yuv2ayuv64_X_c(c, lumFilter, lumSrc, lumFilterSize, \
  2346. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2347. alpSrc, dest, dstW, y, A, Y, U, V, is_be); \
  2348. }
  2349. YUV2AYUV64(ayuv64, le, 0, 2, 4, 6, 0)
  2350. YUV2AYUV64(ayuv64, be, 0, 2, 4, 6, 1)
  2351. YUV2AYUV64(xv48, le, 6, 2, 0, 4, 0)
  2352. YUV2AYUV64(xv48, be, 6, 2, 0, 4, 1)
  2353. #undef output_pixels
  2354. static av_always_inline void
  2355. yuv2v30_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  2356. const int16_t **lumSrc, int lumFilterSize,
  2357. const int16_t *chrFilter, const int16_t **chrUSrc,
  2358. const int16_t **chrVSrc, int chrFilterSize,
  2359. const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
  2360. int shift)
  2361. {
  2362. int i;
  2363. for (i = 0; i < dstW; i++) {
  2364. int Y = 1 << 16, U = 1 << 16, V = 1 << 16, A = 0x3;
  2365. int j;
  2366. for (j = 0; j < lumFilterSize; j++)
  2367. Y += lumSrc[j][i] * lumFilter[j];
  2368. for (j = 0; j < chrFilterSize; j++) {
  2369. U += chrUSrc[j][i] * chrFilter[j];
  2370. V += chrVSrc[j][i] * chrFilter[j];
  2371. }
  2372. Y = av_clip_uintp2(Y >> 17, 10);
  2373. U = av_clip_uintp2(U >> 17, 10);
  2374. V = av_clip_uintp2(V >> 17, 10);
  2375. AV_WL32(dest + 4 * i, U << (shift + 0) |
  2376. Y << (shift + 10) |
  2377. (unsigned)V << (shift + 20) |
  2378. (unsigned)A << (shift ? 0 : 30 /* xv30le = 30, v30xle = 0 */));
  2379. }
  2380. }
  2381. #define V30LE_WRAPPER(name, shift) \
  2382. static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  2383. const int16_t **lumSrc, int lumFilterSize, \
  2384. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2385. const int16_t **chrVSrc, int chrFilterSize, \
  2386. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  2387. int y) \
  2388. { \
  2389. yuv2v30_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  2390. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2391. alpSrc, dest, dstW, y, shift); \
  2392. }
  2393. V30LE_WRAPPER(xv30le, 0)
  2394. V30LE_WRAPPER(v30xle, 2)
  2395. #define output_pixels(pos, val, shift, bits, output_shift) \
  2396. if (is_be) { \
  2397. AV_WB16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
  2398. } else { \
  2399. AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
  2400. }
  2401. static void
  2402. yuv2xv36_X_c(SwsInternal *c, const int16_t *lumFilter,
  2403. const int16_t **lumSrc, int lumFilterSize,
  2404. const int16_t *chrFilter, const int16_t **chrUSrc,
  2405. const int16_t **chrVSrc, int chrFilterSize,
  2406. const int16_t **alpSrc, uint8_t *dest, int dstW, int y, int is_be)
  2407. {
  2408. int i;
  2409. for (i = 0; i < dstW; i++) {
  2410. int Y = 1 << 14, U = 1 << 14, V = 1 << 14, A = 65535;
  2411. int j;
  2412. for (j = 0; j < lumFilterSize; j++)
  2413. Y += lumSrc[j][i] * lumFilter[j];
  2414. for (j = 0; j < chrFilterSize; j++) {
  2415. U += chrUSrc[j][i] * chrFilter[j];
  2416. V += chrVSrc[j][i] * chrFilter[j];
  2417. }
  2418. output_pixels(dest + 8 * i + 2, Y, 15, 12, 4)
  2419. output_pixels(dest + 8 * i + 0, U, 15, 12, 4)
  2420. output_pixels(dest + 8 * i + 4, V, 15, 12, 4)
  2421. output_pixels(dest + 8 * i + 6, A, 0, 12, 4);
  2422. }
  2423. }
  2424. #undef output_pixels
  2425. #define YUV2XV36(BE_LE, is_be) \
  2426. static void \
  2427. yuv2xv36 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2428. const int16_t **lumSrc, int lumFilterSize, \
  2429. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2430. const int16_t **chrVSrc, int chrFilterSize, \
  2431. const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
  2432. { \
  2433. yuv2xv36_X_c(c, lumFilter, lumSrc, lumFilterSize, \
  2434. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2435. alpSrc, dest, dstW, y, is_be); \
  2436. }
  2437. YUV2XV36(le, 0)
  2438. YUV2XV36(be, 1)
  2439. #define output_pixels(pos, A, Y, U, V) \
  2440. if (target == AV_PIX_FMT_AYUV) { \
  2441. dest[pos + 0] = A; \
  2442. dest[pos + 1] = Y; \
  2443. dest[pos + 2] = U; \
  2444. dest[pos + 3] = V; \
  2445. } else if (target == AV_PIX_FMT_UYVA) { \
  2446. dest[pos + 0] = U; \
  2447. dest[pos + 1] = Y; \
  2448. dest[pos + 2] = V; \
  2449. dest[pos + 3] = A; \
  2450. } else { /* AV_PIX_FMT_VUYA || AV_PIX_FMT_VUYX */ \
  2451. dest[pos + 0] = V; \
  2452. dest[pos + 1] = U; \
  2453. dest[pos + 2] = Y; \
  2454. dest[pos + 3] = A; \
  2455. }
  2456. static av_always_inline void
  2457. yuv2ayuv_1_c_template(SwsInternal *c, const int16_t *buf0,
  2458. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2459. const int16_t *abuf0, uint8_t *dest, int dstW,
  2460. int uvalpha, int y, enum AVPixelFormat target)
  2461. {
  2462. int hasAlpha = !!abuf0;
  2463. int i;
  2464. if (uvalpha < 2048) {
  2465. for (i = 0; i < dstW; i++) {
  2466. int Y = (buf0[i] + 64) >> 7;
  2467. int U = (ubuf[0][i] + 64) >> 7;
  2468. int V = (vbuf[0][i] + 64) >> 7;
  2469. int A = 255;
  2470. if (Y & 0x100)
  2471. Y = av_clip_uint8(Y);
  2472. if (U & 0x100)
  2473. U = av_clip_uint8(U);
  2474. if (V & 0x100)
  2475. V = av_clip_uint8(V);
  2476. if (hasAlpha) {
  2477. A = (abuf0[i] + 64) >> 7;
  2478. if (A & 0x100)
  2479. A = av_clip_uint8(A);
  2480. }
  2481. output_pixels(i * 4, A, Y, U, V)
  2482. }
  2483. } else {
  2484. for (i = 0; i < dstW; i++) {
  2485. int Y = (buf0[i] + 64) >> 7;
  2486. int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
  2487. int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
  2488. int A = 255;
  2489. if (Y & 0x100)
  2490. Y = av_clip_uint8(Y);
  2491. if (U & 0x100)
  2492. U = av_clip_uint8(U);
  2493. if (V & 0x100)
  2494. V = av_clip_uint8(V);
  2495. if (hasAlpha) {
  2496. A = (abuf0[i] + 64) >> 7;
  2497. if (A & 0x100)
  2498. A = av_clip_uint8(A);
  2499. }
  2500. output_pixels(i * 4, A, Y, U, V)
  2501. }
  2502. }
  2503. }
  2504. static av_always_inline void
  2505. yuv2ayuv_2_c_template(SwsInternal *c, const int16_t *buf[2],
  2506. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2507. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2508. int yalpha, int uvalpha, int y,
  2509. enum AVPixelFormat target)
  2510. {
  2511. int hasAlpha = abuf && abuf[0] && abuf[1];
  2512. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2513. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  2514. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  2515. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2516. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2517. int yalpha1 = 4096 - yalpha;
  2518. int uvalpha1 = 4096 - uvalpha;
  2519. int i;
  2520. av_assert2(yalpha <= 4096U);
  2521. av_assert2(uvalpha <= 4096U);
  2522. for (i = 0; i < dstW; i++) {
  2523. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2524. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  2525. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  2526. int A = 255;
  2527. if (Y & 0x100)
  2528. Y = av_clip_uint8(Y);
  2529. if (U & 0x100)
  2530. U = av_clip_uint8(U);
  2531. if (V & 0x100)
  2532. V = av_clip_uint8(V);
  2533. if (hasAlpha) {
  2534. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2535. A = av_clip_uint8(A);
  2536. }
  2537. output_pixels(i * 4, A, Y, U, V)
  2538. }
  2539. }
  2540. static av_always_inline void
  2541. yuv2ayuv_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  2542. const int16_t **lumSrc, int lumFilterSize,
  2543. const int16_t *chrFilter, const int16_t **chrUSrc,
  2544. const int16_t **chrVSrc, int chrFilterSize,
  2545. const int16_t **alpSrc, uint8_t *dest, int dstW,
  2546. int y, enum AVPixelFormat target)
  2547. {
  2548. int i;
  2549. for (i = 0; i < dstW; i++) {
  2550. int j;
  2551. int Y = 1 << 18, U = 1 << 18;
  2552. int V = 1 << 18, A = 255;
  2553. for (j = 0; j < lumFilterSize; j++)
  2554. Y += lumSrc[j][i] * lumFilter[j];
  2555. for (j = 0; j < chrFilterSize; j++)
  2556. U += chrUSrc[j][i] * chrFilter[j];
  2557. for (j = 0; j < chrFilterSize; j++)
  2558. V += chrVSrc[j][i] * chrFilter[j];
  2559. Y >>= 19;
  2560. U >>= 19;
  2561. V >>= 19;
  2562. if (Y & 0x100)
  2563. Y = av_clip_uint8(Y);
  2564. if (U & 0x100)
  2565. U = av_clip_uint8(U);
  2566. if (V & 0x100)
  2567. V = av_clip_uint8(V);
  2568. if (alpSrc) {
  2569. A = 1 << 18;
  2570. for (j = 0; j < lumFilterSize; j++)
  2571. A += alpSrc[j][i] * lumFilter[j];
  2572. A >>= 19;
  2573. if (A & 0x100)
  2574. A = av_clip_uint8(A);
  2575. }
  2576. output_pixels(i * 4, A, Y, U, V)
  2577. }
  2578. }
  2579. #undef output_pixels
  2580. #define AYUVPACKEDWRAPPER(name, fmt) \
  2581. static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  2582. const int16_t **lumSrc, int lumFilterSize, \
  2583. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2584. const int16_t **chrVSrc, int chrFilterSize, \
  2585. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  2586. int y) \
  2587. { \
  2588. yuv2ayuv_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  2589. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2590. alpSrc, dest, dstW, y, fmt); \
  2591. } \
  2592. \
  2593. static void yuv2 ## name ## _2_c(SwsInternal *c, const int16_t *buf[2], \
  2594. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  2595. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  2596. int yalpha, int uvalpha, int y) \
  2597. { \
  2598. yuv2ayuv_2_c_template(c, buf, ubuf, vbuf, abuf, \
  2599. dest, dstW, yalpha, uvalpha, y, fmt); \
  2600. } \
  2601. \
  2602. static void yuv2 ## name ## _1_c(SwsInternal *c, const int16_t *buf0, \
  2603. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  2604. const int16_t *abuf0, uint8_t *dest, int dstW, \
  2605. int uvalpha, int y) \
  2606. { \
  2607. yuv2ayuv_1_c_template(c, buf0, ubuf, vbuf, \
  2608. abuf0, dest, dstW, uvalpha, \
  2609. y, fmt); \
  2610. }
  2611. AYUVPACKEDWRAPPER(vuyX, AV_PIX_FMT_VUYX)
  2612. AYUVPACKEDWRAPPER(ayuv, AV_PIX_FMT_AYUV)
  2613. AYUVPACKEDWRAPPER(uyva, AV_PIX_FMT_UYVA)
  2614. #define output_pixel(pos, val, bits) \
  2615. AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
  2616. #define yuv2y2xx_wrapper(bits) \
  2617. static void \
  2618. yuv2y2 ## bits ## le_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2619. const int16_t **lumSrc, int lumFilterSize, \
  2620. const int16_t *chrFilter, \
  2621. const int16_t **chrUSrc, \
  2622. const int16_t **chrVSrc, int chrFilterSize, \
  2623. const int16_t **alpSrc, \
  2624. uint8_t *dest, int dstW, int y) \
  2625. { \
  2626. int i, j; \
  2627. int shift = 11 + 16 - bits; \
  2628. int output_shift = 16 - bits; \
  2629. for (i = 0; i < ((dstW + 1) >> 1); i++) { \
  2630. int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1); \
  2631. int U = 1 << (shift - 1), V = 1 << (shift - 1); \
  2632. \
  2633. for (j = 0; j < lumFilterSize; j++) { \
  2634. Y1 += lumSrc[j][i * 2] * lumFilter[j]; \
  2635. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; \
  2636. } \
  2637. \
  2638. for (j = 0; j < chrFilterSize; j++) { \
  2639. U += chrUSrc[j][i] * chrFilter[j]; \
  2640. V += chrVSrc[j][i] * chrFilter[j]; \
  2641. } \
  2642. \
  2643. output_pixel(dest + 8 * i + 0, Y1, bits); \
  2644. output_pixel(dest + 8 * i + 2, U, bits); \
  2645. output_pixel(dest + 8 * i + 4, Y2, bits); \
  2646. output_pixel(dest + 8 * i + 6, V, bits); \
  2647. } \
  2648. }
  2649. yuv2y2xx_wrapper(10)
  2650. yuv2y2xx_wrapper(12)
  2651. static void
  2652. yuv2y216le_X_c(SwsInternal *c, const int16_t *lumFilter,
  2653. const int16_t **_lumSrc, int lumFilterSize,
  2654. const int16_t *chrFilter,
  2655. const int16_t **_chrUSrc,
  2656. const int16_t **_chrVSrc, int chrFilterSize,
  2657. const int16_t **_alpSrc,
  2658. uint8_t *dest, int dstW, int y)
  2659. {
  2660. const int32_t **lumSrc = (const int32_t **)_lumSrc;
  2661. const int32_t **chrUSrc = (const int32_t **)_chrUSrc;
  2662. const int32_t **chrVSrc = (const int32_t **)_chrVSrc;
  2663. int shift = 15;
  2664. for (int i = 0; i < ((dstW + 1) >> 1); i++) {
  2665. int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1);
  2666. int U = 1 << (shift - 1), V = 1 << (shift - 1);
  2667. /* See yuv2planeX_16_c_template for details. */
  2668. Y1 -= 0x40000000;
  2669. U -= 0x40000000;
  2670. Y2 -= 0x40000000;
  2671. V -= 0x40000000;
  2672. for (int j = 0; j < lumFilterSize; j++) {
  2673. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  2674. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  2675. }
  2676. for (int j = 0; j < chrFilterSize; j++) {
  2677. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2678. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2679. }
  2680. AV_WL16(dest + 8 * i + 0, 0x8000 + av_clip_int16(Y1 >> shift));
  2681. AV_WL16(dest + 8 * i + 2, 0x8000 + av_clip_int16(U >> shift));
  2682. AV_WL16(dest + 8 * i + 4, 0x8000 + av_clip_int16(Y2 >> shift));
  2683. AV_WL16(dest + 8 * i + 6, 0x8000 + av_clip_int16(V >> shift));
  2684. }
  2685. }
  2686. static void
  2687. yuv2vyu444_1_c(SwsInternal *c, const int16_t *buf0,
  2688. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2689. const int16_t *abuf0, uint8_t *dest, int dstW,
  2690. int uvalpha, int y)
  2691. {
  2692. int i;
  2693. if (uvalpha < 2048) {
  2694. for (i = 0; i < dstW; i++) {
  2695. int Y = (buf0[i] + 64) >> 7;
  2696. int U = (ubuf[0][i] + 64) >> 7;
  2697. int V = (vbuf[0][i] + 64) >> 7;
  2698. if (Y & 0x100)
  2699. Y = av_clip_uint8(Y);
  2700. if (U & 0x100)
  2701. U = av_clip_uint8(U);
  2702. if (V & 0x100)
  2703. V = av_clip_uint8(V);
  2704. dest[3 * i ] = V;
  2705. dest[3 * i + 1] = Y;
  2706. dest[3 * i + 2] = U;
  2707. }
  2708. } else {
  2709. for (i = 0; i < dstW; i++) {
  2710. int Y = (buf0[i] + 64) >> 7;
  2711. int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
  2712. int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
  2713. if (Y & 0x100)
  2714. Y = av_clip_uint8(Y);
  2715. if (U & 0x100)
  2716. U = av_clip_uint8(U);
  2717. if (V & 0x100)
  2718. V = av_clip_uint8(V);
  2719. dest[3 * i ] = V;
  2720. dest[3 * i + 1] = Y;
  2721. dest[3 * i + 2] = U;
  2722. }
  2723. }
  2724. }
  2725. static void
  2726. yuv2vyu444_2_c(SwsInternal *c, const int16_t *buf[2],
  2727. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2728. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2729. int yalpha, int uvalpha, int y)
  2730. {
  2731. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2732. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  2733. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  2734. int yalpha1 = 4096 - yalpha;
  2735. int uvalpha1 = 4096 - uvalpha;
  2736. int i;
  2737. av_assert2(yalpha <= 4096U);
  2738. av_assert2(uvalpha <= 4096U);
  2739. for (i = 0; i < dstW; i++) {
  2740. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2741. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  2742. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  2743. if (Y & 0x100)
  2744. Y = av_clip_uint8(Y);
  2745. if (U & 0x100)
  2746. U = av_clip_uint8(U);
  2747. if (V & 0x100)
  2748. V = av_clip_uint8(V);
  2749. dest[3 * i ] = V;
  2750. dest[3 * i + 1] = Y;
  2751. dest[3 * i + 2] = U;
  2752. }
  2753. }
  2754. static void
  2755. yuv2vyu444_X_c(SwsInternal *c, const int16_t *lumFilter,
  2756. const int16_t **lumSrc, int lumFilterSize,
  2757. const int16_t *chrFilter, const int16_t **chrUSrc,
  2758. const int16_t **chrVSrc, int chrFilterSize,
  2759. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2760. {
  2761. int i;
  2762. for (i = 0; i < dstW; i++) {
  2763. int j;
  2764. int Y = 1 << 18, U = 1 << 18;
  2765. int V = 1 << 18;
  2766. for (j = 0; j < lumFilterSize; j++)
  2767. Y += lumSrc[j][i] * lumFilter[j];
  2768. for (j = 0; j < chrFilterSize; j++)
  2769. U += chrUSrc[j][i] * chrFilter[j];
  2770. for (j = 0; j < chrFilterSize; j++)
  2771. V += chrVSrc[j][i] * chrFilter[j];
  2772. Y >>= 19;
  2773. U >>= 19;
  2774. V >>= 19;
  2775. if (Y & 0x100)
  2776. Y = av_clip_uint8(Y);
  2777. if (U & 0x100)
  2778. U = av_clip_uint8(U);
  2779. if (V & 0x100)
  2780. V = av_clip_uint8(V);
  2781. dest[3 * i ] = V;
  2782. dest[3 * i + 1] = Y;
  2783. dest[3 * i + 2] = U;
  2784. }
  2785. }
  2786. #undef output_pixel
  2787. av_cold void ff_sws_init_output_funcs(SwsInternal *c,
  2788. yuv2planar1_fn *yuv2plane1,
  2789. yuv2planarX_fn *yuv2planeX,
  2790. yuv2interleavedX_fn *yuv2nv12cX,
  2791. yuv2packed1_fn *yuv2packed1,
  2792. yuv2packed2_fn *yuv2packed2,
  2793. yuv2packedX_fn *yuv2packedX,
  2794. yuv2anyX_fn *yuv2anyX)
  2795. {
  2796. enum AVPixelFormat dstFormat = c->dstFormat;
  2797. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  2798. if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) {
  2799. if (desc->comp[0].depth == 10) {
  2800. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  2801. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  2802. *yuv2nv12cX = isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
  2803. } else if (desc->comp[0].depth == 12) {
  2804. *yuv2plane1 = isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
  2805. *yuv2planeX = isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
  2806. *yuv2nv12cX = isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
  2807. } else
  2808. av_assert0(0);
  2809. } else if (is16BPS(dstFormat)) {
  2810. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2811. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2812. if (isSemiPlanarYUV(dstFormat)) {
  2813. *yuv2nv12cX = isBE(dstFormat) ? yuv2nv12cX_16BE_c : yuv2nv12cX_16LE_c;
  2814. }
  2815. } else if (isNBPS(dstFormat)) {
  2816. if (desc->comp[0].depth == 9) {
  2817. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2818. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2819. } else if (desc->comp[0].depth == 10) {
  2820. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2821. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2822. } else if (desc->comp[0].depth == 12) {
  2823. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2824. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2825. } else if (desc->comp[0].depth == 14) {
  2826. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2827. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2828. } else
  2829. av_assert0(0);
  2830. } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
  2831. *yuv2planeX = yuv2planeX_floatBE_c;
  2832. *yuv2plane1 = yuv2plane1_floatBE_c;
  2833. } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
  2834. *yuv2planeX = yuv2planeX_floatLE_c;
  2835. *yuv2plane1 = yuv2plane1_floatLE_c;
  2836. } else {
  2837. *yuv2plane1 = yuv2plane1_8_c;
  2838. *yuv2planeX = yuv2planeX_8_c;
  2839. if (isSemiPlanarYUV(dstFormat))
  2840. *yuv2nv12cX = yuv2nv12cX_c;
  2841. }
  2842. if(c->flags & SWS_FULL_CHR_H_INT) {
  2843. switch (dstFormat) {
  2844. case AV_PIX_FMT_RGBA:
  2845. #if CONFIG_SMALL
  2846. *yuv2packedX = yuv2rgba32_full_X_c;
  2847. *yuv2packed2 = yuv2rgba32_full_2_c;
  2848. *yuv2packed1 = yuv2rgba32_full_1_c;
  2849. #else
  2850. #if CONFIG_SWSCALE_ALPHA
  2851. if (c->needAlpha) {
  2852. *yuv2packedX = yuv2rgba32_full_X_c;
  2853. *yuv2packed2 = yuv2rgba32_full_2_c;
  2854. *yuv2packed1 = yuv2rgba32_full_1_c;
  2855. } else
  2856. #endif /* CONFIG_SWSCALE_ALPHA */
  2857. {
  2858. *yuv2packedX = yuv2rgbx32_full_X_c;
  2859. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2860. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2861. }
  2862. #endif /* !CONFIG_SMALL */
  2863. break;
  2864. case AV_PIX_FMT_ARGB:
  2865. #if CONFIG_SMALL
  2866. *yuv2packedX = yuv2argb32_full_X_c;
  2867. *yuv2packed2 = yuv2argb32_full_2_c;
  2868. *yuv2packed1 = yuv2argb32_full_1_c;
  2869. #else
  2870. #if CONFIG_SWSCALE_ALPHA
  2871. if (c->needAlpha) {
  2872. *yuv2packedX = yuv2argb32_full_X_c;
  2873. *yuv2packed2 = yuv2argb32_full_2_c;
  2874. *yuv2packed1 = yuv2argb32_full_1_c;
  2875. } else
  2876. #endif /* CONFIG_SWSCALE_ALPHA */
  2877. {
  2878. *yuv2packedX = yuv2xrgb32_full_X_c;
  2879. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2880. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2881. }
  2882. #endif /* !CONFIG_SMALL */
  2883. break;
  2884. case AV_PIX_FMT_BGRA:
  2885. #if CONFIG_SMALL
  2886. *yuv2packedX = yuv2bgra32_full_X_c;
  2887. *yuv2packed2 = yuv2bgra32_full_2_c;
  2888. *yuv2packed1 = yuv2bgra32_full_1_c;
  2889. #else
  2890. #if CONFIG_SWSCALE_ALPHA
  2891. if (c->needAlpha) {
  2892. *yuv2packedX = yuv2bgra32_full_X_c;
  2893. *yuv2packed2 = yuv2bgra32_full_2_c;
  2894. *yuv2packed1 = yuv2bgra32_full_1_c;
  2895. } else
  2896. #endif /* CONFIG_SWSCALE_ALPHA */
  2897. {
  2898. *yuv2packedX = yuv2bgrx32_full_X_c;
  2899. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2900. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2901. }
  2902. #endif /* !CONFIG_SMALL */
  2903. break;
  2904. case AV_PIX_FMT_ABGR:
  2905. #if CONFIG_SMALL
  2906. *yuv2packedX = yuv2abgr32_full_X_c;
  2907. *yuv2packed2 = yuv2abgr32_full_2_c;
  2908. *yuv2packed1 = yuv2abgr32_full_1_c;
  2909. #else
  2910. #if CONFIG_SWSCALE_ALPHA
  2911. if (c->needAlpha) {
  2912. *yuv2packedX = yuv2abgr32_full_X_c;
  2913. *yuv2packed2 = yuv2abgr32_full_2_c;
  2914. *yuv2packed1 = yuv2abgr32_full_1_c;
  2915. } else
  2916. #endif /* CONFIG_SWSCALE_ALPHA */
  2917. {
  2918. *yuv2packedX = yuv2xbgr32_full_X_c;
  2919. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2920. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2921. }
  2922. #endif /* !CONFIG_SMALL */
  2923. break;
  2924. case AV_PIX_FMT_RGBA64LE:
  2925. #if CONFIG_SWSCALE_ALPHA
  2926. if (c->needAlpha) {
  2927. *yuv2packedX = yuv2rgba64le_full_X_c;
  2928. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2929. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2930. } else
  2931. #endif /* CONFIG_SWSCALE_ALPHA */
  2932. {
  2933. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2934. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2935. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2936. }
  2937. break;
  2938. case AV_PIX_FMT_RGBA64BE:
  2939. #if CONFIG_SWSCALE_ALPHA
  2940. if (c->needAlpha) {
  2941. *yuv2packedX = yuv2rgba64be_full_X_c;
  2942. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2943. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2944. } else
  2945. #endif /* CONFIG_SWSCALE_ALPHA */
  2946. {
  2947. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2948. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2949. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2950. }
  2951. break;
  2952. case AV_PIX_FMT_BGRA64LE:
  2953. #if CONFIG_SWSCALE_ALPHA
  2954. if (c->needAlpha) {
  2955. *yuv2packedX = yuv2bgra64le_full_X_c;
  2956. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2957. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2958. } else
  2959. #endif /* CONFIG_SWSCALE_ALPHA */
  2960. {
  2961. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2962. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2963. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2964. }
  2965. break;
  2966. case AV_PIX_FMT_BGRA64BE:
  2967. #if CONFIG_SWSCALE_ALPHA
  2968. if (c->needAlpha) {
  2969. *yuv2packedX = yuv2bgra64be_full_X_c;
  2970. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2971. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2972. } else
  2973. #endif /* CONFIG_SWSCALE_ALPHA */
  2974. {
  2975. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2976. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2977. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2978. }
  2979. break;
  2980. case AV_PIX_FMT_RGB24:
  2981. *yuv2packedX = yuv2rgb24_full_X_c;
  2982. *yuv2packed2 = yuv2rgb24_full_2_c;
  2983. *yuv2packed1 = yuv2rgb24_full_1_c;
  2984. break;
  2985. case AV_PIX_FMT_BGR24:
  2986. *yuv2packedX = yuv2bgr24_full_X_c;
  2987. *yuv2packed2 = yuv2bgr24_full_2_c;
  2988. *yuv2packed1 = yuv2bgr24_full_1_c;
  2989. break;
  2990. case AV_PIX_FMT_RGB48LE:
  2991. *yuv2packedX = yuv2rgb48le_full_X_c;
  2992. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2993. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2994. break;
  2995. case AV_PIX_FMT_BGR48LE:
  2996. *yuv2packedX = yuv2bgr48le_full_X_c;
  2997. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2998. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2999. break;
  3000. case AV_PIX_FMT_RGB48BE:
  3001. *yuv2packedX = yuv2rgb48be_full_X_c;
  3002. *yuv2packed2 = yuv2rgb48be_full_2_c;
  3003. *yuv2packed1 = yuv2rgb48be_full_1_c;
  3004. break;
  3005. case AV_PIX_FMT_BGR48BE:
  3006. *yuv2packedX = yuv2bgr48be_full_X_c;
  3007. *yuv2packed2 = yuv2bgr48be_full_2_c;
  3008. *yuv2packed1 = yuv2bgr48be_full_1_c;
  3009. break;
  3010. case AV_PIX_FMT_BGR4_BYTE:
  3011. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  3012. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  3013. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  3014. break;
  3015. case AV_PIX_FMT_RGB4_BYTE:
  3016. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  3017. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  3018. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  3019. break;
  3020. case AV_PIX_FMT_BGR8:
  3021. *yuv2packedX = yuv2bgr8_full_X_c;
  3022. *yuv2packed2 = yuv2bgr8_full_2_c;
  3023. *yuv2packed1 = yuv2bgr8_full_1_c;
  3024. break;
  3025. case AV_PIX_FMT_RGB8:
  3026. *yuv2packedX = yuv2rgb8_full_X_c;
  3027. *yuv2packed2 = yuv2rgb8_full_2_c;
  3028. *yuv2packed1 = yuv2rgb8_full_1_c;
  3029. break;
  3030. case AV_PIX_FMT_X2RGB10LE:
  3031. *yuv2packedX = yuv2x2rgb10_full_X_c;
  3032. *yuv2packed2 = yuv2x2rgb10_full_2_c;
  3033. *yuv2packed1 = yuv2x2rgb10_full_1_c;
  3034. break;
  3035. case AV_PIX_FMT_X2BGR10LE:
  3036. *yuv2packedX = yuv2x2bgr10_full_X_c;
  3037. *yuv2packed2 = yuv2x2bgr10_full_2_c;
  3038. *yuv2packed1 = yuv2x2bgr10_full_1_c;
  3039. break;
  3040. case AV_PIX_FMT_GBRP:
  3041. case AV_PIX_FMT_GBRP9BE:
  3042. case AV_PIX_FMT_GBRP9LE:
  3043. case AV_PIX_FMT_GBRP10BE:
  3044. case AV_PIX_FMT_GBRP10LE:
  3045. case AV_PIX_FMT_GBRP12BE:
  3046. case AV_PIX_FMT_GBRP12LE:
  3047. case AV_PIX_FMT_GBRP14BE:
  3048. case AV_PIX_FMT_GBRP14LE:
  3049. case AV_PIX_FMT_GBRAP:
  3050. case AV_PIX_FMT_GBRAP10BE:
  3051. case AV_PIX_FMT_GBRAP10LE:
  3052. case AV_PIX_FMT_GBRAP12BE:
  3053. case AV_PIX_FMT_GBRAP12LE:
  3054. case AV_PIX_FMT_GBRAP14BE:
  3055. case AV_PIX_FMT_GBRAP14LE:
  3056. *yuv2anyX = yuv2gbrp_full_X_c;
  3057. break;
  3058. case AV_PIX_FMT_GBRP16BE:
  3059. case AV_PIX_FMT_GBRP16LE:
  3060. case AV_PIX_FMT_GBRAP16BE:
  3061. case AV_PIX_FMT_GBRAP16LE:
  3062. *yuv2anyX = yuv2gbrp16_full_X_c;
  3063. break;
  3064. case AV_PIX_FMT_GBRPF32BE:
  3065. case AV_PIX_FMT_GBRPF32LE:
  3066. case AV_PIX_FMT_GBRAPF32BE:
  3067. case AV_PIX_FMT_GBRAPF32LE:
  3068. *yuv2anyX = yuv2gbrpf32_full_X_c;
  3069. break;
  3070. }
  3071. if (!*yuv2packedX && !*yuv2anyX)
  3072. goto YUV_PACKED;
  3073. } else {
  3074. YUV_PACKED:
  3075. switch (dstFormat) {
  3076. case AV_PIX_FMT_RGBA64LE:
  3077. #if CONFIG_SWSCALE_ALPHA
  3078. if (c->needAlpha) {
  3079. *yuv2packed1 = yuv2rgba64le_1_c;
  3080. *yuv2packed2 = yuv2rgba64le_2_c;
  3081. *yuv2packedX = yuv2rgba64le_X_c;
  3082. } else
  3083. #endif /* CONFIG_SWSCALE_ALPHA */
  3084. {
  3085. *yuv2packed1 = yuv2rgbx64le_1_c;
  3086. *yuv2packed2 = yuv2rgbx64le_2_c;
  3087. *yuv2packedX = yuv2rgbx64le_X_c;
  3088. }
  3089. break;
  3090. case AV_PIX_FMT_RGBA64BE:
  3091. #if CONFIG_SWSCALE_ALPHA
  3092. if (c->needAlpha) {
  3093. *yuv2packed1 = yuv2rgba64be_1_c;
  3094. *yuv2packed2 = yuv2rgba64be_2_c;
  3095. *yuv2packedX = yuv2rgba64be_X_c;
  3096. } else
  3097. #endif /* CONFIG_SWSCALE_ALPHA */
  3098. {
  3099. *yuv2packed1 = yuv2rgbx64be_1_c;
  3100. *yuv2packed2 = yuv2rgbx64be_2_c;
  3101. *yuv2packedX = yuv2rgbx64be_X_c;
  3102. }
  3103. break;
  3104. case AV_PIX_FMT_BGRA64LE:
  3105. #if CONFIG_SWSCALE_ALPHA
  3106. if (c->needAlpha) {
  3107. *yuv2packed1 = yuv2bgra64le_1_c;
  3108. *yuv2packed2 = yuv2bgra64le_2_c;
  3109. *yuv2packedX = yuv2bgra64le_X_c;
  3110. } else
  3111. #endif /* CONFIG_SWSCALE_ALPHA */
  3112. {
  3113. *yuv2packed1 = yuv2bgrx64le_1_c;
  3114. *yuv2packed2 = yuv2bgrx64le_2_c;
  3115. *yuv2packedX = yuv2bgrx64le_X_c;
  3116. }
  3117. break;
  3118. case AV_PIX_FMT_BGRA64BE:
  3119. #if CONFIG_SWSCALE_ALPHA
  3120. if (c->needAlpha) {
  3121. *yuv2packed1 = yuv2bgra64be_1_c;
  3122. *yuv2packed2 = yuv2bgra64be_2_c;
  3123. *yuv2packedX = yuv2bgra64be_X_c;
  3124. } else
  3125. #endif /* CONFIG_SWSCALE_ALPHA */
  3126. {
  3127. *yuv2packed1 = yuv2bgrx64be_1_c;
  3128. *yuv2packed2 = yuv2bgrx64be_2_c;
  3129. *yuv2packedX = yuv2bgrx64be_X_c;
  3130. }
  3131. break;
  3132. case AV_PIX_FMT_RGB48LE:
  3133. *yuv2packed1 = yuv2rgb48le_1_c;
  3134. *yuv2packed2 = yuv2rgb48le_2_c;
  3135. *yuv2packedX = yuv2rgb48le_X_c;
  3136. break;
  3137. case AV_PIX_FMT_RGB48BE:
  3138. *yuv2packed1 = yuv2rgb48be_1_c;
  3139. *yuv2packed2 = yuv2rgb48be_2_c;
  3140. *yuv2packedX = yuv2rgb48be_X_c;
  3141. break;
  3142. case AV_PIX_FMT_BGR48LE:
  3143. *yuv2packed1 = yuv2bgr48le_1_c;
  3144. *yuv2packed2 = yuv2bgr48le_2_c;
  3145. *yuv2packedX = yuv2bgr48le_X_c;
  3146. break;
  3147. case AV_PIX_FMT_BGR48BE:
  3148. *yuv2packed1 = yuv2bgr48be_1_c;
  3149. *yuv2packed2 = yuv2bgr48be_2_c;
  3150. *yuv2packedX = yuv2bgr48be_X_c;
  3151. break;
  3152. case AV_PIX_FMT_RGB32:
  3153. case AV_PIX_FMT_BGR32:
  3154. #if CONFIG_SMALL
  3155. *yuv2packed1 = yuv2rgb32_1_c;
  3156. *yuv2packed2 = yuv2rgb32_2_c;
  3157. *yuv2packedX = yuv2rgb32_X_c;
  3158. #else
  3159. #if CONFIG_SWSCALE_ALPHA
  3160. if (c->needAlpha) {
  3161. *yuv2packed1 = yuv2rgba32_1_c;
  3162. *yuv2packed2 = yuv2rgba32_2_c;
  3163. *yuv2packedX = yuv2rgba32_X_c;
  3164. } else
  3165. #endif /* CONFIG_SWSCALE_ALPHA */
  3166. {
  3167. *yuv2packed1 = yuv2rgbx32_1_c;
  3168. *yuv2packed2 = yuv2rgbx32_2_c;
  3169. *yuv2packedX = yuv2rgbx32_X_c;
  3170. }
  3171. #endif /* !CONFIG_SMALL */
  3172. break;
  3173. case AV_PIX_FMT_RGB32_1:
  3174. case AV_PIX_FMT_BGR32_1:
  3175. #if CONFIG_SMALL
  3176. *yuv2packed1 = yuv2rgb32_1_1_c;
  3177. *yuv2packed2 = yuv2rgb32_1_2_c;
  3178. *yuv2packedX = yuv2rgb32_1_X_c;
  3179. #else
  3180. #if CONFIG_SWSCALE_ALPHA
  3181. if (c->needAlpha) {
  3182. *yuv2packed1 = yuv2rgba32_1_1_c;
  3183. *yuv2packed2 = yuv2rgba32_1_2_c;
  3184. *yuv2packedX = yuv2rgba32_1_X_c;
  3185. } else
  3186. #endif /* CONFIG_SWSCALE_ALPHA */
  3187. {
  3188. *yuv2packed1 = yuv2rgbx32_1_1_c;
  3189. *yuv2packed2 = yuv2rgbx32_1_2_c;
  3190. *yuv2packedX = yuv2rgbx32_1_X_c;
  3191. }
  3192. #endif /* !CONFIG_SMALL */
  3193. break;
  3194. case AV_PIX_FMT_RGB24:
  3195. *yuv2packed1 = yuv2rgb24_1_c;
  3196. *yuv2packed2 = yuv2rgb24_2_c;
  3197. *yuv2packedX = yuv2rgb24_X_c;
  3198. break;
  3199. case AV_PIX_FMT_BGR24:
  3200. *yuv2packed1 = yuv2bgr24_1_c;
  3201. *yuv2packed2 = yuv2bgr24_2_c;
  3202. *yuv2packedX = yuv2bgr24_X_c;
  3203. break;
  3204. case AV_PIX_FMT_RGB565LE:
  3205. case AV_PIX_FMT_RGB565BE:
  3206. case AV_PIX_FMT_BGR565LE:
  3207. case AV_PIX_FMT_BGR565BE:
  3208. *yuv2packed1 = yuv2rgb16_1_c;
  3209. *yuv2packed2 = yuv2rgb16_2_c;
  3210. *yuv2packedX = yuv2rgb16_X_c;
  3211. break;
  3212. case AV_PIX_FMT_RGB555LE:
  3213. case AV_PIX_FMT_RGB555BE:
  3214. case AV_PIX_FMT_BGR555LE:
  3215. case AV_PIX_FMT_BGR555BE:
  3216. *yuv2packed1 = yuv2rgb15_1_c;
  3217. *yuv2packed2 = yuv2rgb15_2_c;
  3218. *yuv2packedX = yuv2rgb15_X_c;
  3219. break;
  3220. case AV_PIX_FMT_RGB444LE:
  3221. case AV_PIX_FMT_RGB444BE:
  3222. case AV_PIX_FMT_BGR444LE:
  3223. case AV_PIX_FMT_BGR444BE:
  3224. *yuv2packed1 = yuv2rgb12_1_c;
  3225. *yuv2packed2 = yuv2rgb12_2_c;
  3226. *yuv2packedX = yuv2rgb12_X_c;
  3227. break;
  3228. case AV_PIX_FMT_RGB8:
  3229. case AV_PIX_FMT_BGR8:
  3230. *yuv2packed1 = yuv2rgb8_1_c;
  3231. *yuv2packed2 = yuv2rgb8_2_c;
  3232. *yuv2packedX = yuv2rgb8_X_c;
  3233. break;
  3234. case AV_PIX_FMT_RGB4:
  3235. case AV_PIX_FMT_BGR4:
  3236. *yuv2packed1 = yuv2rgb4_1_c;
  3237. *yuv2packed2 = yuv2rgb4_2_c;
  3238. *yuv2packedX = yuv2rgb4_X_c;
  3239. break;
  3240. case AV_PIX_FMT_RGB4_BYTE:
  3241. case AV_PIX_FMT_BGR4_BYTE:
  3242. *yuv2packed1 = yuv2rgb4b_1_c;
  3243. *yuv2packed2 = yuv2rgb4b_2_c;
  3244. *yuv2packedX = yuv2rgb4b_X_c;
  3245. break;
  3246. case AV_PIX_FMT_X2RGB10LE:
  3247. case AV_PIX_FMT_X2RGB10BE:
  3248. *yuv2packed1 = yuv2x2rgb10_1_c;
  3249. *yuv2packed2 = yuv2x2rgb10_2_c;
  3250. *yuv2packedX = yuv2x2rgb10_X_c;
  3251. break;
  3252. case AV_PIX_FMT_X2BGR10LE:
  3253. case AV_PIX_FMT_X2BGR10BE:
  3254. *yuv2packed1 = yuv2x2bgr10_1_c;
  3255. *yuv2packed2 = yuv2x2bgr10_2_c;
  3256. *yuv2packedX = yuv2x2bgr10_X_c;
  3257. break;
  3258. }
  3259. }
  3260. switch (dstFormat) {
  3261. case AV_PIX_FMT_MONOWHITE:
  3262. *yuv2packed1 = yuv2monowhite_1_c;
  3263. *yuv2packed2 = yuv2monowhite_2_c;
  3264. *yuv2packedX = yuv2monowhite_X_c;
  3265. break;
  3266. case AV_PIX_FMT_MONOBLACK:
  3267. *yuv2packed1 = yuv2monoblack_1_c;
  3268. *yuv2packed2 = yuv2monoblack_2_c;
  3269. *yuv2packedX = yuv2monoblack_X_c;
  3270. break;
  3271. case AV_PIX_FMT_YUYV422:
  3272. *yuv2packed1 = yuv2yuyv422_1_c;
  3273. *yuv2packed2 = yuv2yuyv422_2_c;
  3274. *yuv2packedX = yuv2yuyv422_X_c;
  3275. break;
  3276. case AV_PIX_FMT_YVYU422:
  3277. *yuv2packed1 = yuv2yvyu422_1_c;
  3278. *yuv2packed2 = yuv2yvyu422_2_c;
  3279. *yuv2packedX = yuv2yvyu422_X_c;
  3280. break;
  3281. case AV_PIX_FMT_UYVY422:
  3282. *yuv2packed1 = yuv2uyvy422_1_c;
  3283. *yuv2packed2 = yuv2uyvy422_2_c;
  3284. *yuv2packedX = yuv2uyvy422_X_c;
  3285. break;
  3286. case AV_PIX_FMT_VYU444:
  3287. *yuv2packed1 = yuv2vyu444_1_c;
  3288. *yuv2packed2 = yuv2vyu444_2_c;
  3289. *yuv2packedX = yuv2vyu444_X_c;
  3290. break;
  3291. case AV_PIX_FMT_YA8:
  3292. *yuv2packed1 = yuv2ya8_1_c;
  3293. *yuv2packed2 = yuv2ya8_2_c;
  3294. *yuv2packedX = yuv2ya8_X_c;
  3295. break;
  3296. case AV_PIX_FMT_YA16LE:
  3297. *yuv2packed1 = yuv2ya16le_1_c;
  3298. *yuv2packed2 = yuv2ya16le_2_c;
  3299. *yuv2packedX = yuv2ya16le_X_c;
  3300. break;
  3301. case AV_PIX_FMT_YA16BE:
  3302. *yuv2packed1 = yuv2ya16be_1_c;
  3303. *yuv2packed2 = yuv2ya16be_2_c;
  3304. *yuv2packedX = yuv2ya16be_X_c;
  3305. break;
  3306. case AV_PIX_FMT_V30XLE:
  3307. *yuv2packedX = yuv2v30xle_X_c;
  3308. break;
  3309. case AV_PIX_FMT_AYUV64LE:
  3310. *yuv2packedX = yuv2ayuv64le_X_c;
  3311. break;
  3312. case AV_PIX_FMT_AYUV64BE:
  3313. *yuv2packedX = yuv2ayuv64be_X_c;
  3314. break;
  3315. case AV_PIX_FMT_AYUV:
  3316. *yuv2packed1 = yuv2ayuv_1_c;
  3317. *yuv2packed2 = yuv2ayuv_2_c;
  3318. *yuv2packedX = yuv2ayuv_X_c;
  3319. break;
  3320. case AV_PIX_FMT_VUYA:
  3321. case AV_PIX_FMT_VUYX:
  3322. *yuv2packed1 = yuv2vuyX_1_c;
  3323. *yuv2packed2 = yuv2vuyX_2_c;
  3324. *yuv2packedX = yuv2vuyX_X_c;
  3325. break;
  3326. case AV_PIX_FMT_UYVA:
  3327. *yuv2packed1 = yuv2uyva_1_c;
  3328. *yuv2packed2 = yuv2uyva_2_c;
  3329. *yuv2packedX = yuv2uyva_X_c;
  3330. break;
  3331. case AV_PIX_FMT_XV30LE:
  3332. *yuv2packedX = yuv2xv30le_X_c;
  3333. break;
  3334. case AV_PIX_FMT_XV36LE:
  3335. *yuv2packedX = yuv2xv36le_X_c;
  3336. break;
  3337. case AV_PIX_FMT_XV36BE:
  3338. *yuv2packedX = yuv2xv36be_X_c;
  3339. break;
  3340. case AV_PIX_FMT_XV48LE:
  3341. *yuv2packedX = yuv2xv48le_X_c;
  3342. break;
  3343. case AV_PIX_FMT_XV48BE:
  3344. *yuv2packedX = yuv2xv48be_X_c;
  3345. break;
  3346. case AV_PIX_FMT_Y210LE:
  3347. *yuv2packedX = yuv2y210le_X_c;
  3348. break;
  3349. case AV_PIX_FMT_Y212LE:
  3350. *yuv2packedX = yuv2y212le_X_c;
  3351. break;
  3352. case AV_PIX_FMT_Y216LE:
  3353. *yuv2packedX = yuv2y216le_X_c;
  3354. break;
  3355. }
  3356. }