output.c 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753
  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->opts.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->opts.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->opts.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 == 0) {
  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. int uvalpha1 = 4096 - uvalpha;
  1110. av_assert2(uvalpha <= 4096U);
  1111. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1112. SUINT Y1 = (buf0[i * 2] ) >> 2;
  1113. SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
  1114. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1115. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1116. int R, G, B;
  1117. Y1 -= c->yuv2rgb_y_offset;
  1118. Y2 -= c->yuv2rgb_y_offset;
  1119. Y1 *= c->yuv2rgb_y_coeff;
  1120. Y2 *= c->yuv2rgb_y_coeff;
  1121. Y1 += (1 << 13) - (1 << 29);
  1122. Y2 += (1 << 13) - (1 << 29);
  1123. if (hasAlpha) {
  1124. A1 = abuf0[i * 2 ] * (1 << 11);
  1125. A2 = abuf0[i * 2 + 1] * (1 << 11);
  1126. A1 += 1 << 13;
  1127. A2 += 1 << 13;
  1128. }
  1129. R = V * c->yuv2rgb_v2r_coeff;
  1130. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1131. B = U * c->yuv2rgb_u2b_coeff;
  1132. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1133. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1134. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1135. if (eightbytes) {
  1136. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1137. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1138. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1139. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1140. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1141. dest += 8;
  1142. } else {
  1143. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1144. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1145. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1146. dest += 6;
  1147. }
  1148. }
  1149. }
  1150. }
  1151. static av_always_inline void
  1152. yuv2rgba64_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1153. const int32_t **lumSrc, int lumFilterSize,
  1154. const int16_t *chrFilter, const int32_t **chrUSrc,
  1155. const int32_t **chrVSrc, int chrFilterSize,
  1156. const int32_t **alpSrc, uint16_t *dest, int dstW,
  1157. int y, enum AVPixelFormat target, int hasAlpha,
  1158. int eightbytes, int is_be)
  1159. {
  1160. int i;
  1161. int A = 0xffff<<14;
  1162. for (i = 0; i < dstW; i++) {
  1163. int j;
  1164. int Y = -0x40000000;
  1165. int U = -(128 << 23); // 19
  1166. int V = -(128 << 23);
  1167. int R, G, B;
  1168. for (j = 0; j < lumFilterSize; j++) {
  1169. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1170. }
  1171. for (j = 0; j < chrFilterSize; j++) {;
  1172. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1173. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1174. }
  1175. if (hasAlpha) {
  1176. A = -0x40000000;
  1177. for (j = 0; j < lumFilterSize; j++) {
  1178. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1179. }
  1180. A >>= 1;
  1181. A += 0x20002000;
  1182. }
  1183. // 8bit: 12+15=27; 16-bit: 12+19=31
  1184. Y >>= 14; // 10
  1185. Y += 0x10000;
  1186. U >>= 14;
  1187. V >>= 14;
  1188. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  1189. Y -= c->yuv2rgb_y_offset;
  1190. Y *= c->yuv2rgb_y_coeff;
  1191. Y += (1 << 13) - (1<<29); // 21
  1192. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  1193. R = V * c->yuv2rgb_v2r_coeff;
  1194. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1195. B = U * c->yuv2rgb_u2b_coeff;
  1196. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  1197. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + (unsigned)Y)>>14) + (1<<15), 16));
  1198. output_pixel(&dest[1], av_clip_uintp2(((int)( G + (unsigned)Y)>>14) + (1<<15), 16));
  1199. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + (unsigned)Y)>>14) + (1<<15), 16));
  1200. if (eightbytes) {
  1201. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1202. dest += 4;
  1203. } else {
  1204. dest += 3;
  1205. }
  1206. }
  1207. }
  1208. static av_always_inline void
  1209. yuv2rgba64_full_2_c_template(SwsInternal *c, const int32_t *buf[2],
  1210. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1211. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1212. int yalpha, int uvalpha, int y,
  1213. enum AVPixelFormat target, int hasAlpha, int eightbytes,
  1214. int is_be)
  1215. {
  1216. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1217. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1218. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1219. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1220. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1221. int yalpha1 = 4096 - yalpha;
  1222. int uvalpha1 = 4096 - uvalpha;
  1223. int i;
  1224. int A = 0xffff<<14;
  1225. av_assert2(yalpha <= 4096U);
  1226. av_assert2(uvalpha <= 4096U);
  1227. for (i = 0; i < dstW; i++) {
  1228. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  1229. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1230. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1231. int R, G, B;
  1232. Y -= c->yuv2rgb_y_offset;
  1233. Y *= c->yuv2rgb_y_coeff;
  1234. Y += (1 << 13) - (1 << 29);
  1235. R = V * c->yuv2rgb_v2r_coeff;
  1236. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1237. B = U * c->yuv2rgb_u2b_coeff;
  1238. if (hasAlpha) {
  1239. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  1240. A += 1 << 13;
  1241. }
  1242. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
  1243. output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));
  1244. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
  1245. if (eightbytes) {
  1246. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1247. dest += 4;
  1248. } else {
  1249. dest += 3;
  1250. }
  1251. }
  1252. }
  1253. static av_always_inline void
  1254. yuv2rgba64_full_1_c_template(SwsInternal *c, const int32_t *buf0,
  1255. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1256. const int32_t *abuf0, uint16_t *dest, int dstW,
  1257. int uvalpha, int y, enum AVPixelFormat target,
  1258. int hasAlpha, int eightbytes, int is_be)
  1259. {
  1260. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1261. int i;
  1262. int A = 0xffff<<14;
  1263. if (uvalpha == 0) {
  1264. for (i = 0; i < dstW; i++) {
  1265. SUINT Y = (buf0[i]) >> 2;
  1266. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1267. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1268. int R, G, B;
  1269. Y -= c->yuv2rgb_y_offset;
  1270. Y *= c->yuv2rgb_y_coeff;
  1271. Y += (1 << 13) - (1 << 29);
  1272. if (hasAlpha) {
  1273. A = abuf0[i] * (1 << 11);
  1274. A += 1 << 13;
  1275. }
  1276. R = V * c->yuv2rgb_v2r_coeff;
  1277. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1278. B = U * c->yuv2rgb_u2b_coeff;
  1279. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1280. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1281. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1282. if (eightbytes) {
  1283. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1284. dest += 4;
  1285. } else {
  1286. dest += 3;
  1287. }
  1288. }
  1289. } else {
  1290. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1291. int uvalpha1 = 4096 - uvalpha;
  1292. int A = 0xffff<<14;
  1293. av_assert2(uvalpha <= 4096U);
  1294. for (i = 0; i < dstW; i++) {
  1295. SUINT Y = (buf0[i] ) >> 2;
  1296. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1297. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1298. int R, G, B;
  1299. Y -= c->yuv2rgb_y_offset;
  1300. Y *= c->yuv2rgb_y_coeff;
  1301. Y += (1 << 13) - (1 << 29);
  1302. if (hasAlpha) {
  1303. A = abuf0[i] * (1 << 11);
  1304. A += 1 << 13;
  1305. }
  1306. R = V * c->yuv2rgb_v2r_coeff;
  1307. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1308. B = U * c->yuv2rgb_u2b_coeff;
  1309. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1310. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1311. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1312. if (eightbytes) {
  1313. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1314. dest += 4;
  1315. } else {
  1316. dest += 3;
  1317. }
  1318. }
  1319. }
  1320. }
  1321. #undef output_pixel
  1322. #undef r_b
  1323. #undef b_r
  1324. #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
  1325. static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  1326. const int16_t **_lumSrc, int lumFilterSize, \
  1327. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1328. const int16_t **_chrVSrc, int chrFilterSize, \
  1329. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1330. int y) \
  1331. { \
  1332. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1333. **chrUSrc = (const int32_t **) _chrUSrc, \
  1334. **chrVSrc = (const int32_t **) _chrVSrc, \
  1335. **alpSrc = (const int32_t **) _alpSrc; \
  1336. uint16_t *dest = (uint16_t *) _dest; \
  1337. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1338. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1339. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
  1340. } \
  1341. \
  1342. static void name ## ext ## _2_c(SwsInternal *c, const int16_t *_buf[2], \
  1343. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1344. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1345. int yalpha, int uvalpha, int y) \
  1346. { \
  1347. const int32_t **buf = (const int32_t **) _buf, \
  1348. **ubuf = (const int32_t **) _ubuf, \
  1349. **vbuf = (const int32_t **) _vbuf, \
  1350. **abuf = (const int32_t **) _abuf; \
  1351. uint16_t *dest = (uint16_t *) _dest; \
  1352. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1353. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1354. } \
  1355. \
  1356. static void name ## ext ## _1_c(SwsInternal *c, const int16_t *_buf0, \
  1357. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1358. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1359. int uvalpha, int y) \
  1360. { \
  1361. const int32_t *buf0 = (const int32_t *) _buf0, \
  1362. **ubuf = (const int32_t **) _ubuf, \
  1363. **vbuf = (const int32_t **) _vbuf, \
  1364. *abuf0 = (const int32_t *) _abuf0; \
  1365. uint16_t *dest = (uint16_t *) _dest; \
  1366. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1367. dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1368. }
  1369. #define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
  1370. YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
  1371. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48, BE, 0, 0)
  1372. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48, LE, 0, 0)
  1373. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48, BE, 0, 0)
  1374. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48, LE, 0, 0)
  1375. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1376. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1377. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1378. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1379. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1380. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1381. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1382. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1383. YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
  1384. YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
  1385. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
  1386. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
  1387. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48, BE, 0, 0)
  1388. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48, LE, 0, 0)
  1389. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1390. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1391. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1392. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1393. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1394. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1395. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1396. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1397. /*
  1398. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1399. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1400. * things like endianness conversion and shifting. The caller takes care of
  1401. * setting the correct offset in these tables from the chroma (U/V) values.
  1402. * This function then uses the luminance (Y1/Y2) values to write out the
  1403. * correct RGB values into the destination buffer.
  1404. */
  1405. static av_always_inline void
  1406. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1407. unsigned A1, unsigned A2,
  1408. const void *_r, const void *_g, const void *_b, int y,
  1409. enum AVPixelFormat target, int hasAlpha)
  1410. {
  1411. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1412. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1413. uint32_t *dest = (uint32_t *) _dest;
  1414. const uint32_t *r = (const uint32_t *) _r;
  1415. const uint32_t *g = (const uint32_t *) _g;
  1416. const uint32_t *b = (const uint32_t *) _b;
  1417. #if CONFIG_SMALL
  1418. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1419. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1420. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1421. #else
  1422. if (hasAlpha) {
  1423. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1424. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1425. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1426. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1427. } else {
  1428. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1429. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1430. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1431. #endif
  1432. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1433. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1434. }
  1435. #endif
  1436. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1437. uint8_t *dest = (uint8_t *) _dest;
  1438. const uint8_t *r = (const uint8_t *) _r;
  1439. const uint8_t *g = (const uint8_t *) _g;
  1440. const uint8_t *b = (const uint8_t *) _b;
  1441. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1442. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1443. dest[i * 6 + 0] = r_b[Y1];
  1444. dest[i * 6 + 1] = g[Y1];
  1445. dest[i * 6 + 2] = b_r[Y1];
  1446. dest[i * 6 + 3] = r_b[Y2];
  1447. dest[i * 6 + 4] = g[Y2];
  1448. dest[i * 6 + 5] = b_r[Y2];
  1449. #undef r_b
  1450. #undef b_r
  1451. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1452. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1453. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1454. uint16_t *dest = (uint16_t *) _dest;
  1455. const uint16_t *r = (const uint16_t *) _r;
  1456. const uint16_t *g = (const uint16_t *) _g;
  1457. const uint16_t *b = (const uint16_t *) _b;
  1458. int dr1, dg1, db1, dr2, dg2, db2;
  1459. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1460. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1461. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1462. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1463. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1464. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1465. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1466. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1467. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1468. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1469. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1470. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1471. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1472. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1473. } else {
  1474. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1475. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1476. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1477. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1478. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1479. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1480. }
  1481. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1482. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1483. } else if (target == AV_PIX_FMT_X2RGB10 || target == AV_PIX_FMT_X2BGR10) {
  1484. uint32_t *dest = (uint32_t *) _dest;
  1485. const uint32_t *r = (const uint32_t *) _r;
  1486. const uint32_t *g = (const uint32_t *) _g;
  1487. const uint32_t *b = (const uint32_t *) _b;
  1488. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1489. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1490. } else /* 8/4 bits */ {
  1491. uint8_t *dest = (uint8_t *) _dest;
  1492. const uint8_t *r = (const uint8_t *) _r;
  1493. const uint8_t *g = (const uint8_t *) _g;
  1494. const uint8_t *b = (const uint8_t *) _b;
  1495. int dr1, dg1, db1, dr2, dg2, db2;
  1496. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1497. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1498. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1499. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1500. db1 = d64[(i * 2 + 0) & 7];
  1501. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1502. db2 = d64[(i * 2 + 1) & 7];
  1503. } else {
  1504. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1505. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1506. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1507. dg1 = d64[(i * 2 + 0) & 7];
  1508. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1509. dg2 = d64[(i * 2 + 1) & 7];
  1510. }
  1511. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1512. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1513. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1514. } else {
  1515. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1516. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1517. }
  1518. }
  1519. }
  1520. static av_always_inline void
  1521. yuv2rgb_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1522. const int16_t **lumSrc, int lumFilterSize,
  1523. const int16_t *chrFilter, const int16_t **chrUSrc,
  1524. const int16_t **chrVSrc, int chrFilterSize,
  1525. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1526. int y, enum AVPixelFormat target, int hasAlpha)
  1527. {
  1528. int i;
  1529. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1530. int j, A1, A2;
  1531. int Y1 = 1 << 18;
  1532. int Y2 = 1 << 18;
  1533. int U = 1 << 18;
  1534. int V = 1 << 18;
  1535. const void *r, *g, *b;
  1536. for (j = 0; j < lumFilterSize; j++) {
  1537. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1538. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1539. }
  1540. for (j = 0; j < chrFilterSize; j++) {
  1541. U += chrUSrc[j][i] * chrFilter[j];
  1542. V += chrVSrc[j][i] * chrFilter[j];
  1543. }
  1544. Y1 >>= 19;
  1545. Y2 >>= 19;
  1546. U >>= 19;
  1547. V >>= 19;
  1548. if (hasAlpha) {
  1549. A1 = 1 << 18;
  1550. A2 = 1 << 18;
  1551. for (j = 0; j < lumFilterSize; j++) {
  1552. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1553. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1554. }
  1555. A1 >>= 19;
  1556. A2 >>= 19;
  1557. if ((A1 | A2) & 0x100) {
  1558. A1 = av_clip_uint8(A1);
  1559. A2 = av_clip_uint8(A2);
  1560. }
  1561. }
  1562. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1563. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1564. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1565. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1566. r, g, b, y, target, hasAlpha);
  1567. }
  1568. }
  1569. static av_always_inline void
  1570. yuv2rgb_2_c_template(SwsInternal *c, const int16_t *buf[2],
  1571. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1572. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1573. int yalpha, int uvalpha, int y,
  1574. enum AVPixelFormat target, int hasAlpha)
  1575. {
  1576. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1577. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1578. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1579. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1580. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1581. int yalpha1 = 4096 - yalpha;
  1582. int uvalpha1 = 4096 - uvalpha;
  1583. int i;
  1584. av_assert2(yalpha <= 4096U);
  1585. av_assert2(uvalpha <= 4096U);
  1586. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1587. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1588. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1589. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1590. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1591. int A1, A2;
  1592. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1593. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1594. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1595. if (hasAlpha) {
  1596. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1597. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1598. A1 = av_clip_uint8(A1);
  1599. A2 = av_clip_uint8(A2);
  1600. }
  1601. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1602. r, g, b, y, target, hasAlpha);
  1603. }
  1604. }
  1605. static av_always_inline void
  1606. yuv2rgb_1_c_template(SwsInternal *c, const int16_t *buf0,
  1607. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1608. const int16_t *abuf0, uint8_t *dest, int dstW,
  1609. int uvalpha, int y, enum AVPixelFormat target,
  1610. int hasAlpha)
  1611. {
  1612. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1613. int i;
  1614. if (uvalpha == 0) {
  1615. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1616. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1617. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1618. int U = (ubuf0[i] + 64) >> 7;
  1619. int V = (vbuf0[i] + 64) >> 7;
  1620. int A1, A2;
  1621. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1622. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1623. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1624. if (hasAlpha) {
  1625. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1626. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1627. A1 = av_clip_uint8(A1);
  1628. A2 = av_clip_uint8(A2);
  1629. }
  1630. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1631. r, g, b, y, target, hasAlpha);
  1632. }
  1633. } else {
  1634. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1635. int uvalpha1 = 4096 - uvalpha;
  1636. av_assert2(uvalpha <= 4096U);
  1637. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1638. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1639. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1640. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (128 << 11)) >> 19;
  1641. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (128 << 11)) >> 19;
  1642. int A1, A2;
  1643. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1644. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1645. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1646. if (hasAlpha) {
  1647. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1648. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1649. A1 = av_clip_uint8(A1);
  1650. A2 = av_clip_uint8(A2);
  1651. }
  1652. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1653. r, g, b, y, target, hasAlpha);
  1654. }
  1655. }
  1656. }
  1657. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1658. static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  1659. const int16_t **lumSrc, int lumFilterSize, \
  1660. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1661. const int16_t **chrVSrc, int chrFilterSize, \
  1662. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1663. int y) \
  1664. { \
  1665. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1666. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1667. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1668. }
  1669. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1670. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1671. static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \
  1672. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1673. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1674. int yalpha, int uvalpha, int y) \
  1675. { \
  1676. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1677. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1678. }
  1679. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1680. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1681. static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \
  1682. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1683. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1684. int uvalpha, int y) \
  1685. { \
  1686. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1687. dstW, uvalpha, y, fmt, hasAlpha); \
  1688. }
  1689. #if CONFIG_SMALL
  1690. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1691. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1692. #else
  1693. #if CONFIG_SWSCALE_ALPHA
  1694. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1695. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1696. #endif
  1697. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1698. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1699. #endif
  1700. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1701. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1702. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1703. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1704. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1705. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1706. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1707. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1708. YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
  1709. YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0)
  1710. static av_always_inline void yuv2rgb_write_full(SwsInternal *c,
  1711. uint8_t *dest, int i, int Y, int A, int U, int V,
  1712. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1713. {
  1714. int R, G, B;
  1715. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1716. Y -= c->yuv2rgb_y_offset;
  1717. Y *= c->yuv2rgb_y_coeff;
  1718. Y += 1 << 21;
  1719. R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
  1720. G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
  1721. B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff;
  1722. if ((R | G | B) & 0xC0000000) {
  1723. R = av_clip_uintp2(R, 30);
  1724. G = av_clip_uintp2(G, 30);
  1725. B = av_clip_uintp2(B, 30);
  1726. }
  1727. switch(target) {
  1728. case AV_PIX_FMT_ARGB:
  1729. dest[0] = hasAlpha ? A : 255;
  1730. dest[1] = R >> 22;
  1731. dest[2] = G >> 22;
  1732. dest[3] = B >> 22;
  1733. break;
  1734. case AV_PIX_FMT_RGB24:
  1735. dest[0] = R >> 22;
  1736. dest[1] = G >> 22;
  1737. dest[2] = B >> 22;
  1738. break;
  1739. case AV_PIX_FMT_RGBA:
  1740. dest[0] = R >> 22;
  1741. dest[1] = G >> 22;
  1742. dest[2] = B >> 22;
  1743. dest[3] = hasAlpha ? A : 255;
  1744. break;
  1745. case AV_PIX_FMT_ABGR:
  1746. dest[0] = hasAlpha ? A : 255;
  1747. dest[1] = B >> 22;
  1748. dest[2] = G >> 22;
  1749. dest[3] = R >> 22;
  1750. break;
  1751. case AV_PIX_FMT_BGR24:
  1752. dest[0] = B >> 22;
  1753. dest[1] = G >> 22;
  1754. dest[2] = R >> 22;
  1755. break;
  1756. case AV_PIX_FMT_BGRA:
  1757. dest[0] = B >> 22;
  1758. dest[1] = G >> 22;
  1759. dest[2] = R >> 22;
  1760. dest[3] = hasAlpha ? A : 255;
  1761. break;
  1762. case AV_PIX_FMT_X2RGB10LE:
  1763. R >>= 20;
  1764. G >>= 20;
  1765. B >>= 20;
  1766. AV_WL32(dest, (3U << 30) + (R << 20) + (G << 10) + B);
  1767. break;
  1768. case AV_PIX_FMT_X2BGR10LE:
  1769. R >>= 20;
  1770. G >>= 20;
  1771. B >>= 20;
  1772. AV_WL32(dest, (3U << 30) + (B << 20) + (G << 10) + R);
  1773. break;
  1774. case AV_PIX_FMT_BGR4_BYTE:
  1775. case AV_PIX_FMT_RGB4_BYTE:
  1776. case AV_PIX_FMT_BGR8:
  1777. case AV_PIX_FMT_RGB8:
  1778. {
  1779. int r,g,b;
  1780. switch (c->opts.dither) {
  1781. case SWS_DITHER_NONE:
  1782. if (isrgb8) {
  1783. r = av_clip_uintp2(R >> 27, 3);
  1784. g = av_clip_uintp2(G >> 27, 3);
  1785. b = av_clip_uintp2(B >> 28, 2);
  1786. } else {
  1787. r = av_clip_uintp2(R >> 29, 1);
  1788. g = av_clip_uintp2(G >> 28, 2);
  1789. b = av_clip_uintp2(B >> 29, 1);
  1790. }
  1791. break;
  1792. default:
  1793. case SWS_DITHER_AUTO:
  1794. case SWS_DITHER_ED:
  1795. R >>= 22;
  1796. G >>= 22;
  1797. B >>= 22;
  1798. 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;
  1799. 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;
  1800. 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;
  1801. c->dither_error[0][i] = err[0];
  1802. c->dither_error[1][i] = err[1];
  1803. c->dither_error[2][i] = err[2];
  1804. r = R >> (isrgb8 ? 5 : 7);
  1805. g = G >> (isrgb8 ? 5 : 6);
  1806. b = B >> (isrgb8 ? 6 : 7);
  1807. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1808. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1809. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1810. err[0] = R - r*(isrgb8 ? 36 : 255);
  1811. err[1] = G - g*(isrgb8 ? 36 : 85);
  1812. err[2] = B - b*(isrgb8 ? 85 : 255);
  1813. break;
  1814. case SWS_DITHER_A_DITHER:
  1815. if (isrgb8) {
  1816. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1817. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1818. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1819. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1820. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1821. r = av_clip_uintp2(r, 3);
  1822. g = av_clip_uintp2(g, 3);
  1823. b = av_clip_uintp2(b, 2);
  1824. } else {
  1825. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1826. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1827. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1828. r = av_clip_uintp2(r, 1);
  1829. g = av_clip_uintp2(g, 2);
  1830. b = av_clip_uintp2(b, 1);
  1831. }
  1832. break;
  1833. case SWS_DITHER_X_DITHER:
  1834. if (isrgb8) {
  1835. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1836. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1837. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1838. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1839. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1840. r = av_clip_uintp2(r, 3);
  1841. g = av_clip_uintp2(g, 3);
  1842. b = av_clip_uintp2(b, 2);
  1843. } else {
  1844. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1845. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1846. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1847. r = av_clip_uintp2(r, 1);
  1848. g = av_clip_uintp2(g, 2);
  1849. b = av_clip_uintp2(b, 1);
  1850. }
  1851. break;
  1852. }
  1853. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1854. dest[0] = r + 2*g + 8*b;
  1855. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1856. dest[0] = b + 2*g + 8*r;
  1857. } else if(target == AV_PIX_FMT_BGR8) {
  1858. dest[0] = r + 8*g + 64*b;
  1859. } else if(target == AV_PIX_FMT_RGB8) {
  1860. dest[0] = b + 4*g + 32*r;
  1861. } else
  1862. av_assert2(0);
  1863. break;}
  1864. }
  1865. }
  1866. static av_always_inline void
  1867. yuv2rgb_full_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  1868. const int16_t **lumSrc, int lumFilterSize,
  1869. const int16_t *chrFilter, const int16_t **chrUSrc,
  1870. const int16_t **chrVSrc, int chrFilterSize,
  1871. const int16_t **alpSrc, uint8_t *dest,
  1872. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1873. {
  1874. int i;
  1875. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1876. int err[4] = {0};
  1877. int A = 0; //init to silence warning
  1878. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1879. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1880. step = 1;
  1881. for (i = 0; i < dstW; i++) {
  1882. int j;
  1883. int Y = 1<<9;
  1884. int U = (1<<9)-(128 << 19);
  1885. int V = (1<<9)-(128 << 19);
  1886. for (j = 0; j < lumFilterSize; j++) {
  1887. Y += lumSrc[j][i] * lumFilter[j];
  1888. }
  1889. for (j = 0; j < chrFilterSize; j++) {
  1890. U += chrUSrc[j][i] * chrFilter[j];
  1891. V += chrVSrc[j][i] * chrFilter[j];
  1892. }
  1893. Y >>= 10;
  1894. U >>= 10;
  1895. V >>= 10;
  1896. if (hasAlpha) {
  1897. A = 1 << 18;
  1898. for (j = 0; j < lumFilterSize; j++) {
  1899. A += alpSrc[j][i] * lumFilter[j];
  1900. }
  1901. A >>= 19;
  1902. if (A & 0x100)
  1903. A = av_clip_uint8(A);
  1904. }
  1905. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1906. dest += step;
  1907. }
  1908. c->dither_error[0][i] = err[0];
  1909. c->dither_error[1][i] = err[1];
  1910. c->dither_error[2][i] = err[2];
  1911. }
  1912. static av_always_inline void
  1913. yuv2rgb_full_2_c_template(SwsInternal *c, const int16_t *buf[2],
  1914. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1915. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1916. int yalpha, int uvalpha, int y,
  1917. enum AVPixelFormat target, int hasAlpha)
  1918. {
  1919. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1920. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1921. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1922. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1923. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1924. int yalpha1 = 4096 - yalpha;
  1925. int uvalpha1 = 4096 - uvalpha;
  1926. int i;
  1927. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1928. int err[4] = {0};
  1929. int A = 0; // init to silcene warning
  1930. av_assert2(yalpha <= 4096U);
  1931. av_assert2(uvalpha <= 4096U);
  1932. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1933. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1934. step = 1;
  1935. for (i = 0; i < dstW; i++) {
  1936. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1937. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1938. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1939. if (hasAlpha) {
  1940. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1941. if (A & 0x100)
  1942. A = av_clip_uint8(A);
  1943. }
  1944. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1945. dest += step;
  1946. }
  1947. c->dither_error[0][i] = err[0];
  1948. c->dither_error[1][i] = err[1];
  1949. c->dither_error[2][i] = err[2];
  1950. }
  1951. static av_always_inline void
  1952. yuv2rgb_full_1_c_template(SwsInternal *c, const int16_t *buf0,
  1953. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1954. const int16_t *abuf0, uint8_t *dest, int dstW,
  1955. int uvalpha, int y, enum AVPixelFormat target,
  1956. int hasAlpha)
  1957. {
  1958. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1959. int i;
  1960. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1961. int err[4] = {0};
  1962. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1963. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1964. step = 1;
  1965. if (uvalpha == 0) {
  1966. int A = 0; //init to silence warning
  1967. for (i = 0; i < dstW; i++) {
  1968. int Y = buf0[i] * 4;
  1969. int U = (ubuf0[i] - (128<<7)) * 4;
  1970. int V = (vbuf0[i] - (128<<7)) * 4;
  1971. if (hasAlpha) {
  1972. A = (abuf0[i] + 64) >> 7;
  1973. if (A & 0x100)
  1974. A = av_clip_uint8(A);
  1975. }
  1976. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1977. dest += step;
  1978. }
  1979. } else {
  1980. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1981. int A = 0; //init to silence warning
  1982. int uvalpha1 = 4096 - uvalpha;
  1983. av_assert2(uvalpha <= 4096U);
  1984. for (i = 0; i < dstW; i++) {
  1985. int Y = buf0[i] * 4;
  1986. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 19)) >> 10;
  1987. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 19)) >> 10;
  1988. if (hasAlpha) {
  1989. A = (abuf0[i] + 64) >> 7;
  1990. if (A & 0x100)
  1991. A = av_clip_uint8(A);
  1992. }
  1993. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1994. dest += step;
  1995. }
  1996. }
  1997. c->dither_error[0][i] = err[0];
  1998. c->dither_error[1][i] = err[1];
  1999. c->dither_error[2][i] = err[2];
  2000. }
  2001. #if CONFIG_SMALL
  2002. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  2003. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  2004. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  2005. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  2006. #else
  2007. #if CONFIG_SWSCALE_ALPHA
  2008. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  2009. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  2010. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  2011. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  2012. #endif
  2013. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  2014. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  2015. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  2016. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  2017. #endif
  2018. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  2019. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  2020. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  2021. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  2022. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  2023. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  2024. YUV2RGBWRAPPER(yuv2, rgb_full, x2rgb10_full, AV_PIX_FMT_X2RGB10LE, 0)
  2025. YUV2RGBWRAPPER(yuv2, rgb_full, x2bgr10_full, AV_PIX_FMT_X2BGR10LE, 0)
  2026. static void
  2027. yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2028. const int16_t **lumSrc, int lumFilterSize,
  2029. const int16_t *chrFilter, const int16_t **chrUSrc,
  2030. const int16_t **chrVSrc, int chrFilterSize,
  2031. const int16_t **alpSrc, uint8_t **dest,
  2032. int dstW, int y)
  2033. {
  2034. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
  2035. int i;
  2036. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  2037. uint16_t **dest16 = (uint16_t**)dest;
  2038. int SH = 22 + 8 - desc->comp[0].depth;
  2039. int A = 0; // init to silence warning
  2040. for (i = 0; i < dstW; i++) {
  2041. int j;
  2042. int Y = 1 << 9;
  2043. int U = (1 << 9) - (128 << 19);
  2044. int V = (1 << 9) - (128 << 19);
  2045. int R, G, B;
  2046. for (j = 0; j < lumFilterSize; j++)
  2047. Y += lumSrc[j][i] * lumFilter[j];
  2048. for (j = 0; j < chrFilterSize; j++) {
  2049. U += chrUSrc[j][i] * chrFilter[j];
  2050. V += chrVSrc[j][i] * chrFilter[j];
  2051. }
  2052. Y >>= 10;
  2053. U >>= 10;
  2054. V >>= 10;
  2055. if (hasAlpha) {
  2056. A = 1 << 18;
  2057. for (j = 0; j < lumFilterSize; j++)
  2058. A += alpSrc[j][i] * lumFilter[j];
  2059. if (A & 0xF8000000)
  2060. A = av_clip_uintp2(A, 27);
  2061. }
  2062. Y -= c->yuv2rgb_y_offset;
  2063. Y *= c->yuv2rgb_y_coeff;
  2064. Y += 1 << (SH-1);
  2065. R = Y + V * c->yuv2rgb_v2r_coeff;
  2066. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2067. B = Y + U * c->yuv2rgb_u2b_coeff;
  2068. if ((R | G | B) & 0xC0000000) {
  2069. R = av_clip_uintp2(R, 30);
  2070. G = av_clip_uintp2(G, 30);
  2071. B = av_clip_uintp2(B, 30);
  2072. }
  2073. if (SH != 22) {
  2074. dest16[0][i] = G >> SH;
  2075. dest16[1][i] = B >> SH;
  2076. dest16[2][i] = R >> SH;
  2077. if (hasAlpha)
  2078. dest16[3][i] = A >> (SH - 3);
  2079. } else {
  2080. dest[0][i] = G >> 22;
  2081. dest[1][i] = B >> 22;
  2082. dest[2][i] = R >> 22;
  2083. if (hasAlpha)
  2084. dest[3][i] = A >> 19;
  2085. }
  2086. }
  2087. if (SH != 22 && (!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
  2088. for (i = 0; i < dstW; i++) {
  2089. dest16[0][i] = av_bswap16(dest16[0][i]);
  2090. dest16[1][i] = av_bswap16(dest16[1][i]);
  2091. dest16[2][i] = av_bswap16(dest16[2][i]);
  2092. if (hasAlpha)
  2093. dest16[3][i] = av_bswap16(dest16[3][i]);
  2094. }
  2095. }
  2096. }
  2097. static void
  2098. yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2099. const int16_t **lumSrcx, int lumFilterSize,
  2100. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2101. const int16_t **chrVSrcx, int chrFilterSize,
  2102. const int16_t **alpSrcx, uint8_t **dest,
  2103. int dstW, int y)
  2104. {
  2105. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
  2106. int i;
  2107. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2108. uint16_t **dest16 = (uint16_t**)dest;
  2109. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2110. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2111. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2112. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2113. for (i = 0; i < dstW; i++) {
  2114. int j;
  2115. int Y = -0x40000000;
  2116. int U = -(128 << 23);
  2117. int V = -(128 << 23);
  2118. int R, G, B, A;
  2119. for (j = 0; j < lumFilterSize; j++)
  2120. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2121. for (j = 0; j < chrFilterSize; j++) {
  2122. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2123. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2124. }
  2125. Y >>= 14;
  2126. Y += 0x10000;
  2127. U >>= 14;
  2128. V >>= 14;
  2129. if (hasAlpha) {
  2130. A = -0x40000000;
  2131. for (j = 0; j < lumFilterSize; j++)
  2132. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2133. A >>= 1;
  2134. A += 0x20002000;
  2135. }
  2136. Y -= c->yuv2rgb_y_offset;
  2137. Y *= c->yuv2rgb_y_coeff;
  2138. Y += (1 << 13) - (1 << 29);
  2139. R = V * c->yuv2rgb_v2r_coeff;
  2140. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2141. B = U * c->yuv2rgb_u2b_coeff;
  2142. dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2143. dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2144. dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2145. if (hasAlpha)
  2146. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  2147. }
  2148. if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
  2149. for (i = 0; i < dstW; i++) {
  2150. dest16[0][i] = av_bswap16(dest16[0][i]);
  2151. dest16[1][i] = av_bswap16(dest16[1][i]);
  2152. dest16[2][i] = av_bswap16(dest16[2][i]);
  2153. if (hasAlpha)
  2154. dest16[3][i] = av_bswap16(dest16[3][i]);
  2155. }
  2156. }
  2157. }
  2158. static void
  2159. yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter,
  2160. const int16_t **lumSrcx, int lumFilterSize,
  2161. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2162. const int16_t **chrVSrcx, int chrFilterSize,
  2163. const int16_t **alpSrcx, uint8_t **dest,
  2164. int dstW, int y)
  2165. {
  2166. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
  2167. int i;
  2168. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2169. uint32_t **dest32 = (uint32_t**)dest;
  2170. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2171. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2172. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2173. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2174. static const float float_mult = 1.0f / 65535.0f;
  2175. for (i = 0; i < dstW; i++) {
  2176. int j;
  2177. int Y = -0x40000000;
  2178. int U = -(128 << 23);
  2179. int V = -(128 << 23);
  2180. int R, G, B, A;
  2181. for (j = 0; j < lumFilterSize; j++)
  2182. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2183. for (j = 0; j < chrFilterSize; j++) {
  2184. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2185. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2186. }
  2187. Y >>= 14;
  2188. Y += 0x10000;
  2189. U >>= 14;
  2190. V >>= 14;
  2191. if (hasAlpha) {
  2192. A = -0x40000000;
  2193. for (j = 0; j < lumFilterSize; j++)
  2194. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2195. A >>= 1;
  2196. A += 0x20002000;
  2197. }
  2198. Y -= c->yuv2rgb_y_offset;
  2199. Y *= c->yuv2rgb_y_coeff;
  2200. Y += (1 << 13) - (1 << 29);
  2201. R = V * c->yuv2rgb_v2r_coeff;
  2202. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2203. B = U * c->yuv2rgb_u2b_coeff;
  2204. R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2205. G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2206. B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2207. dest32[0][i] = av_float2int(float_mult * (float)G);
  2208. dest32[1][i] = av_float2int(float_mult * (float)B);
  2209. dest32[2][i] = av_float2int(float_mult * (float)R);
  2210. if (hasAlpha)
  2211. dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
  2212. }
  2213. if ((!isBE(c->opts.dst_format)) != (!HAVE_BIGENDIAN)) {
  2214. for (i = 0; i < dstW; i++) {
  2215. dest32[0][i] = av_bswap32(dest32[0][i]);
  2216. dest32[1][i] = av_bswap32(dest32[1][i]);
  2217. dest32[2][i] = av_bswap32(dest32[2][i]);
  2218. if (hasAlpha)
  2219. dest32[3][i] = av_bswap32(dest32[3][i]);
  2220. }
  2221. }
  2222. }
  2223. static void
  2224. yuv2ya8_1_c(SwsInternal *c, const int16_t *buf0,
  2225. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2226. const int16_t *abuf0, uint8_t *dest, int dstW,
  2227. int uvalpha, int y)
  2228. {
  2229. int hasAlpha = !!abuf0;
  2230. int i;
  2231. for (i = 0; i < dstW; i++) {
  2232. int Y = (buf0[i] + 64) >> 7;
  2233. int A;
  2234. Y = av_clip_uint8(Y);
  2235. if (hasAlpha) {
  2236. A = (abuf0[i] + 64) >> 7;
  2237. if (A & 0x100)
  2238. A = av_clip_uint8(A);
  2239. }
  2240. dest[i * 2 ] = Y;
  2241. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2242. }
  2243. }
  2244. static void
  2245. yuv2ya8_2_c(SwsInternal *c, const int16_t *buf[2],
  2246. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2247. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2248. int yalpha, int uvalpha, int y)
  2249. {
  2250. int hasAlpha = abuf && abuf[0] && abuf[1];
  2251. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2252. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2253. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2254. int yalpha1 = 4096 - yalpha;
  2255. int i;
  2256. av_assert2(yalpha <= 4096U);
  2257. for (i = 0; i < dstW; i++) {
  2258. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2259. int A;
  2260. Y = av_clip_uint8(Y);
  2261. if (hasAlpha) {
  2262. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2263. A = av_clip_uint8(A);
  2264. }
  2265. dest[i * 2 ] = Y;
  2266. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2267. }
  2268. }
  2269. static void
  2270. yuv2ya8_X_c(SwsInternal *c, const int16_t *lumFilter,
  2271. const int16_t **lumSrc, int lumFilterSize,
  2272. const int16_t *chrFilter, const int16_t **chrUSrc,
  2273. const int16_t **chrVSrc, int chrFilterSize,
  2274. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2275. {
  2276. int hasAlpha = !!alpSrc;
  2277. int i;
  2278. for (i = 0; i < dstW; i++) {
  2279. int j;
  2280. int Y = 1 << 18, A = 1 << 18;
  2281. for (j = 0; j < lumFilterSize; j++)
  2282. Y += lumSrc[j][i] * lumFilter[j];
  2283. Y >>= 19;
  2284. if (Y & 0x100)
  2285. Y = av_clip_uint8(Y);
  2286. if (hasAlpha) {
  2287. for (j = 0; j < lumFilterSize; j++)
  2288. A += alpSrc[j][i] * lumFilter[j];
  2289. A >>= 19;
  2290. if (A & 0x100)
  2291. A = av_clip_uint8(A);
  2292. }
  2293. dest[2 * i ] = Y;
  2294. dest[2 * i + 1] = hasAlpha ? A : 255;
  2295. }
  2296. }
  2297. #define output_pixels(pos, val) \
  2298. if (is_be) { \
  2299. AV_WB16(pos, val); \
  2300. } else { \
  2301. AV_WL16(pos, val); \
  2302. }
  2303. static av_always_inline void
  2304. yuv2ayuv64_X_c(SwsInternal *c, const int16_t *lumFilter,
  2305. const int16_t **_lumSrc, int lumFilterSize,
  2306. const int16_t *chrFilter, const int16_t **_chrUSrc,
  2307. const int16_t **_chrVSrc, int chrFilterSize,
  2308. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y,
  2309. int A_offset, int Y_offset, int U_offset, int V_offset, int is_be)
  2310. {
  2311. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  2312. **chrUSrc = (const int32_t **) _chrUSrc,
  2313. **chrVSrc = (const int32_t **) _chrVSrc,
  2314. **alpSrc = (const int32_t **) _alpSrc;
  2315. int hasAlpha = !!alpSrc;
  2316. int i;
  2317. for (i = 0; i < dstW; i++) {
  2318. int Y = 1 << 14, U = 1 << 14;
  2319. int V = 1 << 14, A = 1 << 14;
  2320. int j;
  2321. Y -= 0x40000000;
  2322. U -= 0x40000000;
  2323. V -= 0x40000000;
  2324. A -= 0x40000000;
  2325. for (j = 0; j < lumFilterSize; j++)
  2326. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2327. for (j = 0; j < chrFilterSize; j++)
  2328. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2329. for (j = 0; j < chrFilterSize; j++)
  2330. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2331. if (hasAlpha)
  2332. for (j = 0; j < lumFilterSize; j++)
  2333. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2334. Y = 0x8000 + av_clip_int16(Y >> 15);
  2335. U = 0x8000 + av_clip_int16(U >> 15);
  2336. V = 0x8000 + av_clip_int16(V >> 15);
  2337. if (hasAlpha)
  2338. A = 0x8000 + av_clip_int16(A >> 15);
  2339. output_pixels(dest + 8 * i + A_offset, hasAlpha ? A : 65535);
  2340. output_pixels(dest + 8 * i + Y_offset, Y);
  2341. output_pixels(dest + 8 * i + U_offset, U);
  2342. output_pixels(dest + 8 * i + V_offset, V);
  2343. }
  2344. }
  2345. #define YUV2AYUV64(pixfmt, BE_LE, A, Y, U, V, is_be) \
  2346. static void \
  2347. yuv2 ## pixfmt ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2348. const int16_t **lumSrc, int lumFilterSize, \
  2349. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2350. const int16_t **chrVSrc, int chrFilterSize, \
  2351. const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
  2352. { \
  2353. yuv2ayuv64_X_c(c, lumFilter, lumSrc, lumFilterSize, \
  2354. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2355. alpSrc, dest, dstW, y, A, Y, U, V, is_be); \
  2356. }
  2357. YUV2AYUV64(ayuv64, le, 0, 2, 4, 6, 0)
  2358. YUV2AYUV64(ayuv64, be, 0, 2, 4, 6, 1)
  2359. YUV2AYUV64(xv48, le, 6, 2, 0, 4, 0)
  2360. YUV2AYUV64(xv48, be, 6, 2, 0, 4, 1)
  2361. #undef output_pixels
  2362. static av_always_inline void
  2363. yuv2v30_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  2364. const int16_t **lumSrc, int lumFilterSize,
  2365. const int16_t *chrFilter, const int16_t **chrUSrc,
  2366. const int16_t **chrVSrc, int chrFilterSize,
  2367. const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
  2368. int shift)
  2369. {
  2370. int i;
  2371. for (i = 0; i < dstW; i++) {
  2372. int Y = 1 << 16, U = 1 << 16, V = 1 << 16, A = 0x3;
  2373. int j;
  2374. for (j = 0; j < lumFilterSize; j++)
  2375. Y += lumSrc[j][i] * lumFilter[j];
  2376. for (j = 0; j < chrFilterSize; j++) {
  2377. U += chrUSrc[j][i] * chrFilter[j];
  2378. V += chrVSrc[j][i] * chrFilter[j];
  2379. }
  2380. Y = av_clip_uintp2(Y >> 17, 10);
  2381. U = av_clip_uintp2(U >> 17, 10);
  2382. V = av_clip_uintp2(V >> 17, 10);
  2383. AV_WL32(dest + 4 * i, U << (shift + 0) |
  2384. Y << (shift + 10) |
  2385. (unsigned)V << (shift + 20) |
  2386. (unsigned)A << (shift ? 0 : 30 /* xv30le = 30, v30xle = 0 */));
  2387. }
  2388. }
  2389. #define V30LE_WRAPPER(name, shift) \
  2390. static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  2391. const int16_t **lumSrc, int lumFilterSize, \
  2392. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2393. const int16_t **chrVSrc, int chrFilterSize, \
  2394. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  2395. int y) \
  2396. { \
  2397. yuv2v30_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  2398. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2399. alpSrc, dest, dstW, y, shift); \
  2400. }
  2401. V30LE_WRAPPER(xv30le, 0)
  2402. V30LE_WRAPPER(v30xle, 2)
  2403. #define output_pixels(pos, val, shift, bits, output_shift) \
  2404. if (is_be) { \
  2405. AV_WB16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
  2406. } else { \
  2407. AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift); \
  2408. }
  2409. static void
  2410. yuv2xv36_X_c(SwsInternal *c, const int16_t *lumFilter,
  2411. const int16_t **lumSrc, int lumFilterSize,
  2412. const int16_t *chrFilter, const int16_t **chrUSrc,
  2413. const int16_t **chrVSrc, int chrFilterSize,
  2414. const int16_t **alpSrc, uint8_t *dest, int dstW, int y, int is_be)
  2415. {
  2416. int i;
  2417. for (i = 0; i < dstW; i++) {
  2418. int Y = 1 << 14, U = 1 << 14, V = 1 << 14, A = 65535;
  2419. int j;
  2420. for (j = 0; j < lumFilterSize; j++)
  2421. Y += lumSrc[j][i] * lumFilter[j];
  2422. for (j = 0; j < chrFilterSize; j++) {
  2423. U += chrUSrc[j][i] * chrFilter[j];
  2424. V += chrVSrc[j][i] * chrFilter[j];
  2425. }
  2426. output_pixels(dest + 8 * i + 2, Y, 15, 12, 4)
  2427. output_pixels(dest + 8 * i + 0, U, 15, 12, 4)
  2428. output_pixels(dest + 8 * i + 4, V, 15, 12, 4)
  2429. output_pixels(dest + 8 * i + 6, A, 0, 12, 4);
  2430. }
  2431. }
  2432. #undef output_pixels
  2433. #define YUV2XV36(BE_LE, is_be) \
  2434. static void \
  2435. yuv2xv36 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2436. const int16_t **lumSrc, int lumFilterSize, \
  2437. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2438. const int16_t **chrVSrc, int chrFilterSize, \
  2439. const int16_t **alpSrc, uint8_t *dest, int dstW, int y) \
  2440. { \
  2441. yuv2xv36_X_c(c, lumFilter, lumSrc, lumFilterSize, \
  2442. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2443. alpSrc, dest, dstW, y, is_be); \
  2444. }
  2445. YUV2XV36(le, 0)
  2446. YUV2XV36(be, 1)
  2447. #define output_pixels(pos, A, Y, U, V) \
  2448. if (target == AV_PIX_FMT_AYUV) { \
  2449. dest[pos + 0] = A; \
  2450. dest[pos + 1] = Y; \
  2451. dest[pos + 2] = U; \
  2452. dest[pos + 3] = V; \
  2453. } else if (target == AV_PIX_FMT_UYVA) { \
  2454. dest[pos + 0] = U; \
  2455. dest[pos + 1] = Y; \
  2456. dest[pos + 2] = V; \
  2457. dest[pos + 3] = A; \
  2458. } else { /* AV_PIX_FMT_VUYA || AV_PIX_FMT_VUYX */ \
  2459. dest[pos + 0] = V; \
  2460. dest[pos + 1] = U; \
  2461. dest[pos + 2] = Y; \
  2462. dest[pos + 3] = A; \
  2463. }
  2464. static av_always_inline void
  2465. yuv2ayuv_1_c_template(SwsInternal *c, const int16_t *buf0,
  2466. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2467. const int16_t *abuf0, uint8_t *dest, int dstW,
  2468. int uvalpha, int y, enum AVPixelFormat target)
  2469. {
  2470. int hasAlpha = !!abuf0;
  2471. int i;
  2472. if (uvalpha < 2048) {
  2473. for (i = 0; i < dstW; i++) {
  2474. int Y = (buf0[i] + 64) >> 7;
  2475. int U = (ubuf[0][i] + 64) >> 7;
  2476. int V = (vbuf[0][i] + 64) >> 7;
  2477. int A = 255;
  2478. if (Y & 0x100)
  2479. Y = av_clip_uint8(Y);
  2480. if (U & 0x100)
  2481. U = av_clip_uint8(U);
  2482. if (V & 0x100)
  2483. V = av_clip_uint8(V);
  2484. if (hasAlpha) {
  2485. A = (abuf0[i] + 64) >> 7;
  2486. if (A & 0x100)
  2487. A = av_clip_uint8(A);
  2488. }
  2489. output_pixels(i * 4, A, Y, U, V)
  2490. }
  2491. } else {
  2492. for (i = 0; i < dstW; i++) {
  2493. int Y = (buf0[i] + 64) >> 7;
  2494. int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
  2495. int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
  2496. int A = 255;
  2497. if (Y & 0x100)
  2498. Y = av_clip_uint8(Y);
  2499. if (U & 0x100)
  2500. U = av_clip_uint8(U);
  2501. if (V & 0x100)
  2502. V = av_clip_uint8(V);
  2503. if (hasAlpha) {
  2504. A = (abuf0[i] + 64) >> 7;
  2505. if (A & 0x100)
  2506. A = av_clip_uint8(A);
  2507. }
  2508. output_pixels(i * 4, A, Y, U, V)
  2509. }
  2510. }
  2511. }
  2512. static av_always_inline void
  2513. yuv2ayuv_2_c_template(SwsInternal *c, const int16_t *buf[2],
  2514. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2515. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2516. int yalpha, int uvalpha, int y,
  2517. enum AVPixelFormat target)
  2518. {
  2519. int hasAlpha = abuf && abuf[0] && abuf[1];
  2520. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2521. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  2522. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  2523. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2524. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2525. int yalpha1 = 4096 - yalpha;
  2526. int uvalpha1 = 4096 - uvalpha;
  2527. int i;
  2528. av_assert2(yalpha <= 4096U);
  2529. av_assert2(uvalpha <= 4096U);
  2530. for (i = 0; i < dstW; i++) {
  2531. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2532. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  2533. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  2534. int A = 255;
  2535. if (Y & 0x100)
  2536. Y = av_clip_uint8(Y);
  2537. if (U & 0x100)
  2538. U = av_clip_uint8(U);
  2539. if (V & 0x100)
  2540. V = av_clip_uint8(V);
  2541. if (hasAlpha) {
  2542. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2543. A = av_clip_uint8(A);
  2544. }
  2545. output_pixels(i * 4, A, Y, U, V)
  2546. }
  2547. }
  2548. static av_always_inline void
  2549. yuv2ayuv_X_c_template(SwsInternal *c, const int16_t *lumFilter,
  2550. const int16_t **lumSrc, int lumFilterSize,
  2551. const int16_t *chrFilter, const int16_t **chrUSrc,
  2552. const int16_t **chrVSrc, int chrFilterSize,
  2553. const int16_t **alpSrc, uint8_t *dest, int dstW,
  2554. int y, enum AVPixelFormat target)
  2555. {
  2556. int i;
  2557. for (i = 0; i < dstW; i++) {
  2558. int j;
  2559. int Y = 1 << 18, U = 1 << 18;
  2560. int V = 1 << 18, A = 255;
  2561. for (j = 0; j < lumFilterSize; j++)
  2562. Y += lumSrc[j][i] * lumFilter[j];
  2563. for (j = 0; j < chrFilterSize; j++)
  2564. U += chrUSrc[j][i] * chrFilter[j];
  2565. for (j = 0; j < chrFilterSize; j++)
  2566. V += chrVSrc[j][i] * chrFilter[j];
  2567. Y >>= 19;
  2568. U >>= 19;
  2569. V >>= 19;
  2570. if (Y & 0x100)
  2571. Y = av_clip_uint8(Y);
  2572. if (U & 0x100)
  2573. U = av_clip_uint8(U);
  2574. if (V & 0x100)
  2575. V = av_clip_uint8(V);
  2576. if (alpSrc) {
  2577. A = 1 << 18;
  2578. for (j = 0; j < lumFilterSize; j++)
  2579. A += alpSrc[j][i] * lumFilter[j];
  2580. A >>= 19;
  2581. if (A & 0x100)
  2582. A = av_clip_uint8(A);
  2583. }
  2584. output_pixels(i * 4, A, Y, U, V)
  2585. }
  2586. }
  2587. #undef output_pixels
  2588. #define AYUVPACKEDWRAPPER(name, fmt) \
  2589. static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \
  2590. const int16_t **lumSrc, int lumFilterSize, \
  2591. const int16_t *chrFilter, const int16_t **chrUSrc, \
  2592. const int16_t **chrVSrc, int chrFilterSize, \
  2593. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  2594. int y) \
  2595. { \
  2596. yuv2ayuv_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  2597. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  2598. alpSrc, dest, dstW, y, fmt); \
  2599. } \
  2600. \
  2601. static void yuv2 ## name ## _2_c(SwsInternal *c, const int16_t *buf[2], \
  2602. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  2603. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  2604. int yalpha, int uvalpha, int y) \
  2605. { \
  2606. yuv2ayuv_2_c_template(c, buf, ubuf, vbuf, abuf, \
  2607. dest, dstW, yalpha, uvalpha, y, fmt); \
  2608. } \
  2609. \
  2610. static void yuv2 ## name ## _1_c(SwsInternal *c, const int16_t *buf0, \
  2611. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  2612. const int16_t *abuf0, uint8_t *dest, int dstW, \
  2613. int uvalpha, int y) \
  2614. { \
  2615. yuv2ayuv_1_c_template(c, buf0, ubuf, vbuf, \
  2616. abuf0, dest, dstW, uvalpha, \
  2617. y, fmt); \
  2618. }
  2619. AYUVPACKEDWRAPPER(vuyX, AV_PIX_FMT_VUYX)
  2620. AYUVPACKEDWRAPPER(ayuv, AV_PIX_FMT_AYUV)
  2621. AYUVPACKEDWRAPPER(uyva, AV_PIX_FMT_UYVA)
  2622. #define output_pixel(pos, val, bits) \
  2623. AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
  2624. #define yuv2y2xx_wrapper(bits) \
  2625. static void \
  2626. yuv2y2 ## bits ## le_X_c(SwsInternal *c, const int16_t *lumFilter, \
  2627. const int16_t **lumSrc, int lumFilterSize, \
  2628. const int16_t *chrFilter, \
  2629. const int16_t **chrUSrc, \
  2630. const int16_t **chrVSrc, int chrFilterSize, \
  2631. const int16_t **alpSrc, \
  2632. uint8_t *dest, int dstW, int y) \
  2633. { \
  2634. int i, j; \
  2635. int shift = 11 + 16 - bits; \
  2636. int output_shift = 16 - bits; \
  2637. for (i = 0; i < ((dstW + 1) >> 1); i++) { \
  2638. int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1); \
  2639. int U = 1 << (shift - 1), V = 1 << (shift - 1); \
  2640. \
  2641. for (j = 0; j < lumFilterSize; j++) { \
  2642. Y1 += lumSrc[j][i * 2] * lumFilter[j]; \
  2643. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; \
  2644. } \
  2645. \
  2646. for (j = 0; j < chrFilterSize; j++) { \
  2647. U += chrUSrc[j][i] * chrFilter[j]; \
  2648. V += chrVSrc[j][i] * chrFilter[j]; \
  2649. } \
  2650. \
  2651. output_pixel(dest + 8 * i + 0, Y1, bits); \
  2652. output_pixel(dest + 8 * i + 2, U, bits); \
  2653. output_pixel(dest + 8 * i + 4, Y2, bits); \
  2654. output_pixel(dest + 8 * i + 6, V, bits); \
  2655. } \
  2656. }
  2657. yuv2y2xx_wrapper(10)
  2658. yuv2y2xx_wrapper(12)
  2659. static void
  2660. yuv2y216le_X_c(SwsInternal *c, const int16_t *lumFilter,
  2661. const int16_t **_lumSrc, int lumFilterSize,
  2662. const int16_t *chrFilter,
  2663. const int16_t **_chrUSrc,
  2664. const int16_t **_chrVSrc, int chrFilterSize,
  2665. const int16_t **_alpSrc,
  2666. uint8_t *dest, int dstW, int y)
  2667. {
  2668. const int32_t **lumSrc = (const int32_t **)_lumSrc;
  2669. const int32_t **chrUSrc = (const int32_t **)_chrUSrc;
  2670. const int32_t **chrVSrc = (const int32_t **)_chrVSrc;
  2671. int shift = 15;
  2672. for (int i = 0; i < ((dstW + 1) >> 1); i++) {
  2673. int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1);
  2674. int U = 1 << (shift - 1), V = 1 << (shift - 1);
  2675. /* See yuv2planeX_16_c_template for details. */
  2676. Y1 -= 0x40000000;
  2677. U -= 0x40000000;
  2678. Y2 -= 0x40000000;
  2679. V -= 0x40000000;
  2680. for (int j = 0; j < lumFilterSize; j++) {
  2681. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  2682. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  2683. }
  2684. for (int j = 0; j < chrFilterSize; j++) {
  2685. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2686. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2687. }
  2688. AV_WL16(dest + 8 * i + 0, 0x8000 + av_clip_int16(Y1 >> shift));
  2689. AV_WL16(dest + 8 * i + 2, 0x8000 + av_clip_int16(U >> shift));
  2690. AV_WL16(dest + 8 * i + 4, 0x8000 + av_clip_int16(Y2 >> shift));
  2691. AV_WL16(dest + 8 * i + 6, 0x8000 + av_clip_int16(V >> shift));
  2692. }
  2693. }
  2694. static void
  2695. yuv2vyu444_1_c(SwsInternal *c, const int16_t *buf0,
  2696. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2697. const int16_t *abuf0, uint8_t *dest, int dstW,
  2698. int uvalpha, int y)
  2699. {
  2700. int i;
  2701. if (uvalpha < 2048) {
  2702. for (i = 0; i < dstW; i++) {
  2703. int Y = (buf0[i] + 64) >> 7;
  2704. int U = (ubuf[0][i] + 64) >> 7;
  2705. int V = (vbuf[0][i] + 64) >> 7;
  2706. if (Y & 0x100)
  2707. Y = av_clip_uint8(Y);
  2708. if (U & 0x100)
  2709. U = av_clip_uint8(U);
  2710. if (V & 0x100)
  2711. V = av_clip_uint8(V);
  2712. dest[3 * i ] = V;
  2713. dest[3 * i + 1] = Y;
  2714. dest[3 * i + 2] = U;
  2715. }
  2716. } else {
  2717. for (i = 0; i < dstW; i++) {
  2718. int Y = (buf0[i] + 64) >> 7;
  2719. int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
  2720. int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
  2721. if (Y & 0x100)
  2722. Y = av_clip_uint8(Y);
  2723. if (U & 0x100)
  2724. U = av_clip_uint8(U);
  2725. if (V & 0x100)
  2726. V = av_clip_uint8(V);
  2727. dest[3 * i ] = V;
  2728. dest[3 * i + 1] = Y;
  2729. dest[3 * i + 2] = U;
  2730. }
  2731. }
  2732. }
  2733. static void
  2734. yuv2vyu444_2_c(SwsInternal *c, const int16_t *buf[2],
  2735. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2736. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2737. int yalpha, int uvalpha, int y)
  2738. {
  2739. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2740. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  2741. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  2742. int yalpha1 = 4096 - yalpha;
  2743. int uvalpha1 = 4096 - uvalpha;
  2744. int i;
  2745. av_assert2(yalpha <= 4096U);
  2746. av_assert2(uvalpha <= 4096U);
  2747. for (i = 0; i < dstW; i++) {
  2748. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2749. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  2750. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  2751. if (Y & 0x100)
  2752. Y = av_clip_uint8(Y);
  2753. if (U & 0x100)
  2754. U = av_clip_uint8(U);
  2755. if (V & 0x100)
  2756. V = av_clip_uint8(V);
  2757. dest[3 * i ] = V;
  2758. dest[3 * i + 1] = Y;
  2759. dest[3 * i + 2] = U;
  2760. }
  2761. }
  2762. static void
  2763. yuv2vyu444_X_c(SwsInternal *c, const int16_t *lumFilter,
  2764. const int16_t **lumSrc, int lumFilterSize,
  2765. const int16_t *chrFilter, const int16_t **chrUSrc,
  2766. const int16_t **chrVSrc, int chrFilterSize,
  2767. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2768. {
  2769. int i;
  2770. for (i = 0; i < dstW; i++) {
  2771. int j;
  2772. int Y = 1 << 18, U = 1 << 18;
  2773. int V = 1 << 18;
  2774. for (j = 0; j < lumFilterSize; j++)
  2775. Y += lumSrc[j][i] * lumFilter[j];
  2776. for (j = 0; j < chrFilterSize; j++)
  2777. U += chrUSrc[j][i] * chrFilter[j];
  2778. for (j = 0; j < chrFilterSize; j++)
  2779. V += chrVSrc[j][i] * chrFilter[j];
  2780. Y >>= 19;
  2781. U >>= 19;
  2782. V >>= 19;
  2783. if (Y & 0x100)
  2784. Y = av_clip_uint8(Y);
  2785. if (U & 0x100)
  2786. U = av_clip_uint8(U);
  2787. if (V & 0x100)
  2788. V = av_clip_uint8(V);
  2789. dest[3 * i ] = V;
  2790. dest[3 * i + 1] = Y;
  2791. dest[3 * i + 2] = U;
  2792. }
  2793. }
  2794. #undef output_pixel
  2795. av_cold void ff_sws_init_output_funcs(SwsInternal *c,
  2796. yuv2planar1_fn *yuv2plane1,
  2797. yuv2planarX_fn *yuv2planeX,
  2798. yuv2interleavedX_fn *yuv2nv12cX,
  2799. yuv2packed1_fn *yuv2packed1,
  2800. yuv2packed2_fn *yuv2packed2,
  2801. yuv2packedX_fn *yuv2packedX,
  2802. yuv2anyX_fn *yuv2anyX)
  2803. {
  2804. enum AVPixelFormat dstFormat = c->opts.dst_format;
  2805. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  2806. if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) {
  2807. if (desc->comp[0].depth == 10) {
  2808. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  2809. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  2810. *yuv2nv12cX = isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
  2811. } else if (desc->comp[0].depth == 12) {
  2812. *yuv2plane1 = isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
  2813. *yuv2planeX = isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
  2814. *yuv2nv12cX = isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
  2815. } else
  2816. av_assert0(0);
  2817. } else if (is16BPS(dstFormat)) {
  2818. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2819. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2820. if (isSemiPlanarYUV(dstFormat)) {
  2821. *yuv2nv12cX = isBE(dstFormat) ? yuv2nv12cX_16BE_c : yuv2nv12cX_16LE_c;
  2822. }
  2823. } else if (isNBPS(dstFormat)) {
  2824. if (desc->comp[0].depth == 9) {
  2825. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2826. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2827. } else if (desc->comp[0].depth == 10) {
  2828. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2829. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2830. } else if (desc->comp[0].depth == 12) {
  2831. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2832. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2833. } else if (desc->comp[0].depth == 14) {
  2834. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2835. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2836. } else
  2837. av_assert0(0);
  2838. } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
  2839. *yuv2planeX = yuv2planeX_floatBE_c;
  2840. *yuv2plane1 = yuv2plane1_floatBE_c;
  2841. } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
  2842. *yuv2planeX = yuv2planeX_floatLE_c;
  2843. *yuv2plane1 = yuv2plane1_floatLE_c;
  2844. } else {
  2845. *yuv2plane1 = yuv2plane1_8_c;
  2846. *yuv2planeX = yuv2planeX_8_c;
  2847. if (isSemiPlanarYUV(dstFormat))
  2848. *yuv2nv12cX = yuv2nv12cX_c;
  2849. }
  2850. if(c->opts.flags & SWS_FULL_CHR_H_INT) {
  2851. switch (dstFormat) {
  2852. case AV_PIX_FMT_RGBA:
  2853. #if CONFIG_SMALL
  2854. *yuv2packedX = yuv2rgba32_full_X_c;
  2855. *yuv2packed2 = yuv2rgba32_full_2_c;
  2856. *yuv2packed1 = yuv2rgba32_full_1_c;
  2857. #else
  2858. #if CONFIG_SWSCALE_ALPHA
  2859. if (c->needAlpha) {
  2860. *yuv2packedX = yuv2rgba32_full_X_c;
  2861. *yuv2packed2 = yuv2rgba32_full_2_c;
  2862. *yuv2packed1 = yuv2rgba32_full_1_c;
  2863. } else
  2864. #endif /* CONFIG_SWSCALE_ALPHA */
  2865. {
  2866. *yuv2packedX = yuv2rgbx32_full_X_c;
  2867. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2868. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2869. }
  2870. #endif /* !CONFIG_SMALL */
  2871. break;
  2872. case AV_PIX_FMT_ARGB:
  2873. #if CONFIG_SMALL
  2874. *yuv2packedX = yuv2argb32_full_X_c;
  2875. *yuv2packed2 = yuv2argb32_full_2_c;
  2876. *yuv2packed1 = yuv2argb32_full_1_c;
  2877. #else
  2878. #if CONFIG_SWSCALE_ALPHA
  2879. if (c->needAlpha) {
  2880. *yuv2packedX = yuv2argb32_full_X_c;
  2881. *yuv2packed2 = yuv2argb32_full_2_c;
  2882. *yuv2packed1 = yuv2argb32_full_1_c;
  2883. } else
  2884. #endif /* CONFIG_SWSCALE_ALPHA */
  2885. {
  2886. *yuv2packedX = yuv2xrgb32_full_X_c;
  2887. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2888. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2889. }
  2890. #endif /* !CONFIG_SMALL */
  2891. break;
  2892. case AV_PIX_FMT_BGRA:
  2893. #if CONFIG_SMALL
  2894. *yuv2packedX = yuv2bgra32_full_X_c;
  2895. *yuv2packed2 = yuv2bgra32_full_2_c;
  2896. *yuv2packed1 = yuv2bgra32_full_1_c;
  2897. #else
  2898. #if CONFIG_SWSCALE_ALPHA
  2899. if (c->needAlpha) {
  2900. *yuv2packedX = yuv2bgra32_full_X_c;
  2901. *yuv2packed2 = yuv2bgra32_full_2_c;
  2902. *yuv2packed1 = yuv2bgra32_full_1_c;
  2903. } else
  2904. #endif /* CONFIG_SWSCALE_ALPHA */
  2905. {
  2906. *yuv2packedX = yuv2bgrx32_full_X_c;
  2907. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2908. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2909. }
  2910. #endif /* !CONFIG_SMALL */
  2911. break;
  2912. case AV_PIX_FMT_ABGR:
  2913. #if CONFIG_SMALL
  2914. *yuv2packedX = yuv2abgr32_full_X_c;
  2915. *yuv2packed2 = yuv2abgr32_full_2_c;
  2916. *yuv2packed1 = yuv2abgr32_full_1_c;
  2917. #else
  2918. #if CONFIG_SWSCALE_ALPHA
  2919. if (c->needAlpha) {
  2920. *yuv2packedX = yuv2abgr32_full_X_c;
  2921. *yuv2packed2 = yuv2abgr32_full_2_c;
  2922. *yuv2packed1 = yuv2abgr32_full_1_c;
  2923. } else
  2924. #endif /* CONFIG_SWSCALE_ALPHA */
  2925. {
  2926. *yuv2packedX = yuv2xbgr32_full_X_c;
  2927. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2928. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2929. }
  2930. #endif /* !CONFIG_SMALL */
  2931. break;
  2932. case AV_PIX_FMT_RGBA64LE:
  2933. #if CONFIG_SWSCALE_ALPHA
  2934. if (c->needAlpha) {
  2935. *yuv2packedX = yuv2rgba64le_full_X_c;
  2936. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2937. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2938. } else
  2939. #endif /* CONFIG_SWSCALE_ALPHA */
  2940. {
  2941. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2942. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2943. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2944. }
  2945. break;
  2946. case AV_PIX_FMT_RGBA64BE:
  2947. #if CONFIG_SWSCALE_ALPHA
  2948. if (c->needAlpha) {
  2949. *yuv2packedX = yuv2rgba64be_full_X_c;
  2950. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2951. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2952. } else
  2953. #endif /* CONFIG_SWSCALE_ALPHA */
  2954. {
  2955. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2956. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2957. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2958. }
  2959. break;
  2960. case AV_PIX_FMT_BGRA64LE:
  2961. #if CONFIG_SWSCALE_ALPHA
  2962. if (c->needAlpha) {
  2963. *yuv2packedX = yuv2bgra64le_full_X_c;
  2964. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2965. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2966. } else
  2967. #endif /* CONFIG_SWSCALE_ALPHA */
  2968. {
  2969. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2970. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2971. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2972. }
  2973. break;
  2974. case AV_PIX_FMT_BGRA64BE:
  2975. #if CONFIG_SWSCALE_ALPHA
  2976. if (c->needAlpha) {
  2977. *yuv2packedX = yuv2bgra64be_full_X_c;
  2978. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2979. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2980. } else
  2981. #endif /* CONFIG_SWSCALE_ALPHA */
  2982. {
  2983. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2984. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2985. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2986. }
  2987. break;
  2988. case AV_PIX_FMT_RGB24:
  2989. *yuv2packedX = yuv2rgb24_full_X_c;
  2990. *yuv2packed2 = yuv2rgb24_full_2_c;
  2991. *yuv2packed1 = yuv2rgb24_full_1_c;
  2992. break;
  2993. case AV_PIX_FMT_BGR24:
  2994. *yuv2packedX = yuv2bgr24_full_X_c;
  2995. *yuv2packed2 = yuv2bgr24_full_2_c;
  2996. *yuv2packed1 = yuv2bgr24_full_1_c;
  2997. break;
  2998. case AV_PIX_FMT_RGB48LE:
  2999. *yuv2packedX = yuv2rgb48le_full_X_c;
  3000. *yuv2packed2 = yuv2rgb48le_full_2_c;
  3001. *yuv2packed1 = yuv2rgb48le_full_1_c;
  3002. break;
  3003. case AV_PIX_FMT_BGR48LE:
  3004. *yuv2packedX = yuv2bgr48le_full_X_c;
  3005. *yuv2packed2 = yuv2bgr48le_full_2_c;
  3006. *yuv2packed1 = yuv2bgr48le_full_1_c;
  3007. break;
  3008. case AV_PIX_FMT_RGB48BE:
  3009. *yuv2packedX = yuv2rgb48be_full_X_c;
  3010. *yuv2packed2 = yuv2rgb48be_full_2_c;
  3011. *yuv2packed1 = yuv2rgb48be_full_1_c;
  3012. break;
  3013. case AV_PIX_FMT_BGR48BE:
  3014. *yuv2packedX = yuv2bgr48be_full_X_c;
  3015. *yuv2packed2 = yuv2bgr48be_full_2_c;
  3016. *yuv2packed1 = yuv2bgr48be_full_1_c;
  3017. break;
  3018. case AV_PIX_FMT_BGR4_BYTE:
  3019. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  3020. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  3021. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  3022. break;
  3023. case AV_PIX_FMT_RGB4_BYTE:
  3024. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  3025. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  3026. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  3027. break;
  3028. case AV_PIX_FMT_BGR8:
  3029. *yuv2packedX = yuv2bgr8_full_X_c;
  3030. *yuv2packed2 = yuv2bgr8_full_2_c;
  3031. *yuv2packed1 = yuv2bgr8_full_1_c;
  3032. break;
  3033. case AV_PIX_FMT_RGB8:
  3034. *yuv2packedX = yuv2rgb8_full_X_c;
  3035. *yuv2packed2 = yuv2rgb8_full_2_c;
  3036. *yuv2packed1 = yuv2rgb8_full_1_c;
  3037. break;
  3038. case AV_PIX_FMT_X2RGB10LE:
  3039. *yuv2packedX = yuv2x2rgb10_full_X_c;
  3040. *yuv2packed2 = yuv2x2rgb10_full_2_c;
  3041. *yuv2packed1 = yuv2x2rgb10_full_1_c;
  3042. break;
  3043. case AV_PIX_FMT_X2BGR10LE:
  3044. *yuv2packedX = yuv2x2bgr10_full_X_c;
  3045. *yuv2packed2 = yuv2x2bgr10_full_2_c;
  3046. *yuv2packed1 = yuv2x2bgr10_full_1_c;
  3047. break;
  3048. case AV_PIX_FMT_GBRP:
  3049. case AV_PIX_FMT_GBRP9BE:
  3050. case AV_PIX_FMT_GBRP9LE:
  3051. case AV_PIX_FMT_GBRP10BE:
  3052. case AV_PIX_FMT_GBRP10LE:
  3053. case AV_PIX_FMT_GBRP12BE:
  3054. case AV_PIX_FMT_GBRP12LE:
  3055. case AV_PIX_FMT_GBRP14BE:
  3056. case AV_PIX_FMT_GBRP14LE:
  3057. case AV_PIX_FMT_GBRAP:
  3058. case AV_PIX_FMT_GBRAP10BE:
  3059. case AV_PIX_FMT_GBRAP10LE:
  3060. case AV_PIX_FMT_GBRAP12BE:
  3061. case AV_PIX_FMT_GBRAP12LE:
  3062. case AV_PIX_FMT_GBRAP14BE:
  3063. case AV_PIX_FMT_GBRAP14LE:
  3064. *yuv2anyX = yuv2gbrp_full_X_c;
  3065. break;
  3066. case AV_PIX_FMT_GBRP16BE:
  3067. case AV_PIX_FMT_GBRP16LE:
  3068. case AV_PIX_FMT_GBRAP16BE:
  3069. case AV_PIX_FMT_GBRAP16LE:
  3070. *yuv2anyX = yuv2gbrp16_full_X_c;
  3071. break;
  3072. case AV_PIX_FMT_GBRPF32BE:
  3073. case AV_PIX_FMT_GBRPF32LE:
  3074. case AV_PIX_FMT_GBRAPF32BE:
  3075. case AV_PIX_FMT_GBRAPF32LE:
  3076. *yuv2anyX = yuv2gbrpf32_full_X_c;
  3077. break;
  3078. }
  3079. if (!*yuv2packedX && !*yuv2anyX)
  3080. goto YUV_PACKED;
  3081. } else {
  3082. YUV_PACKED:
  3083. switch (dstFormat) {
  3084. case AV_PIX_FMT_RGBA64LE:
  3085. #if CONFIG_SWSCALE_ALPHA
  3086. if (c->needAlpha) {
  3087. *yuv2packed1 = yuv2rgba64le_1_c;
  3088. *yuv2packed2 = yuv2rgba64le_2_c;
  3089. *yuv2packedX = yuv2rgba64le_X_c;
  3090. } else
  3091. #endif /* CONFIG_SWSCALE_ALPHA */
  3092. {
  3093. *yuv2packed1 = yuv2rgbx64le_1_c;
  3094. *yuv2packed2 = yuv2rgbx64le_2_c;
  3095. *yuv2packedX = yuv2rgbx64le_X_c;
  3096. }
  3097. break;
  3098. case AV_PIX_FMT_RGBA64BE:
  3099. #if CONFIG_SWSCALE_ALPHA
  3100. if (c->needAlpha) {
  3101. *yuv2packed1 = yuv2rgba64be_1_c;
  3102. *yuv2packed2 = yuv2rgba64be_2_c;
  3103. *yuv2packedX = yuv2rgba64be_X_c;
  3104. } else
  3105. #endif /* CONFIG_SWSCALE_ALPHA */
  3106. {
  3107. *yuv2packed1 = yuv2rgbx64be_1_c;
  3108. *yuv2packed2 = yuv2rgbx64be_2_c;
  3109. *yuv2packedX = yuv2rgbx64be_X_c;
  3110. }
  3111. break;
  3112. case AV_PIX_FMT_BGRA64LE:
  3113. #if CONFIG_SWSCALE_ALPHA
  3114. if (c->needAlpha) {
  3115. *yuv2packed1 = yuv2bgra64le_1_c;
  3116. *yuv2packed2 = yuv2bgra64le_2_c;
  3117. *yuv2packedX = yuv2bgra64le_X_c;
  3118. } else
  3119. #endif /* CONFIG_SWSCALE_ALPHA */
  3120. {
  3121. *yuv2packed1 = yuv2bgrx64le_1_c;
  3122. *yuv2packed2 = yuv2bgrx64le_2_c;
  3123. *yuv2packedX = yuv2bgrx64le_X_c;
  3124. }
  3125. break;
  3126. case AV_PIX_FMT_BGRA64BE:
  3127. #if CONFIG_SWSCALE_ALPHA
  3128. if (c->needAlpha) {
  3129. *yuv2packed1 = yuv2bgra64be_1_c;
  3130. *yuv2packed2 = yuv2bgra64be_2_c;
  3131. *yuv2packedX = yuv2bgra64be_X_c;
  3132. } else
  3133. #endif /* CONFIG_SWSCALE_ALPHA */
  3134. {
  3135. *yuv2packed1 = yuv2bgrx64be_1_c;
  3136. *yuv2packed2 = yuv2bgrx64be_2_c;
  3137. *yuv2packedX = yuv2bgrx64be_X_c;
  3138. }
  3139. break;
  3140. case AV_PIX_FMT_RGB48LE:
  3141. *yuv2packed1 = yuv2rgb48le_1_c;
  3142. *yuv2packed2 = yuv2rgb48le_2_c;
  3143. *yuv2packedX = yuv2rgb48le_X_c;
  3144. break;
  3145. case AV_PIX_FMT_RGB48BE:
  3146. *yuv2packed1 = yuv2rgb48be_1_c;
  3147. *yuv2packed2 = yuv2rgb48be_2_c;
  3148. *yuv2packedX = yuv2rgb48be_X_c;
  3149. break;
  3150. case AV_PIX_FMT_BGR48LE:
  3151. *yuv2packed1 = yuv2bgr48le_1_c;
  3152. *yuv2packed2 = yuv2bgr48le_2_c;
  3153. *yuv2packedX = yuv2bgr48le_X_c;
  3154. break;
  3155. case AV_PIX_FMT_BGR48BE:
  3156. *yuv2packed1 = yuv2bgr48be_1_c;
  3157. *yuv2packed2 = yuv2bgr48be_2_c;
  3158. *yuv2packedX = yuv2bgr48be_X_c;
  3159. break;
  3160. case AV_PIX_FMT_RGB32:
  3161. case AV_PIX_FMT_BGR32:
  3162. #if CONFIG_SMALL
  3163. *yuv2packed1 = yuv2rgb32_1_c;
  3164. *yuv2packed2 = yuv2rgb32_2_c;
  3165. *yuv2packedX = yuv2rgb32_X_c;
  3166. #else
  3167. #if CONFIG_SWSCALE_ALPHA
  3168. if (c->needAlpha) {
  3169. *yuv2packed1 = yuv2rgba32_1_c;
  3170. *yuv2packed2 = yuv2rgba32_2_c;
  3171. *yuv2packedX = yuv2rgba32_X_c;
  3172. } else
  3173. #endif /* CONFIG_SWSCALE_ALPHA */
  3174. {
  3175. *yuv2packed1 = yuv2rgbx32_1_c;
  3176. *yuv2packed2 = yuv2rgbx32_2_c;
  3177. *yuv2packedX = yuv2rgbx32_X_c;
  3178. }
  3179. #endif /* !CONFIG_SMALL */
  3180. break;
  3181. case AV_PIX_FMT_RGB32_1:
  3182. case AV_PIX_FMT_BGR32_1:
  3183. #if CONFIG_SMALL
  3184. *yuv2packed1 = yuv2rgb32_1_1_c;
  3185. *yuv2packed2 = yuv2rgb32_1_2_c;
  3186. *yuv2packedX = yuv2rgb32_1_X_c;
  3187. #else
  3188. #if CONFIG_SWSCALE_ALPHA
  3189. if (c->needAlpha) {
  3190. *yuv2packed1 = yuv2rgba32_1_1_c;
  3191. *yuv2packed2 = yuv2rgba32_1_2_c;
  3192. *yuv2packedX = yuv2rgba32_1_X_c;
  3193. } else
  3194. #endif /* CONFIG_SWSCALE_ALPHA */
  3195. {
  3196. *yuv2packed1 = yuv2rgbx32_1_1_c;
  3197. *yuv2packed2 = yuv2rgbx32_1_2_c;
  3198. *yuv2packedX = yuv2rgbx32_1_X_c;
  3199. }
  3200. #endif /* !CONFIG_SMALL */
  3201. break;
  3202. case AV_PIX_FMT_RGB24:
  3203. *yuv2packed1 = yuv2rgb24_1_c;
  3204. *yuv2packed2 = yuv2rgb24_2_c;
  3205. *yuv2packedX = yuv2rgb24_X_c;
  3206. break;
  3207. case AV_PIX_FMT_BGR24:
  3208. *yuv2packed1 = yuv2bgr24_1_c;
  3209. *yuv2packed2 = yuv2bgr24_2_c;
  3210. *yuv2packedX = yuv2bgr24_X_c;
  3211. break;
  3212. case AV_PIX_FMT_RGB565LE:
  3213. case AV_PIX_FMT_RGB565BE:
  3214. case AV_PIX_FMT_BGR565LE:
  3215. case AV_PIX_FMT_BGR565BE:
  3216. *yuv2packed1 = yuv2rgb16_1_c;
  3217. *yuv2packed2 = yuv2rgb16_2_c;
  3218. *yuv2packedX = yuv2rgb16_X_c;
  3219. break;
  3220. case AV_PIX_FMT_RGB555LE:
  3221. case AV_PIX_FMT_RGB555BE:
  3222. case AV_PIX_FMT_BGR555LE:
  3223. case AV_PIX_FMT_BGR555BE:
  3224. *yuv2packed1 = yuv2rgb15_1_c;
  3225. *yuv2packed2 = yuv2rgb15_2_c;
  3226. *yuv2packedX = yuv2rgb15_X_c;
  3227. break;
  3228. case AV_PIX_FMT_RGB444LE:
  3229. case AV_PIX_FMT_RGB444BE:
  3230. case AV_PIX_FMT_BGR444LE:
  3231. case AV_PIX_FMT_BGR444BE:
  3232. *yuv2packed1 = yuv2rgb12_1_c;
  3233. *yuv2packed2 = yuv2rgb12_2_c;
  3234. *yuv2packedX = yuv2rgb12_X_c;
  3235. break;
  3236. case AV_PIX_FMT_RGB8:
  3237. case AV_PIX_FMT_BGR8:
  3238. *yuv2packed1 = yuv2rgb8_1_c;
  3239. *yuv2packed2 = yuv2rgb8_2_c;
  3240. *yuv2packedX = yuv2rgb8_X_c;
  3241. break;
  3242. case AV_PIX_FMT_RGB4:
  3243. case AV_PIX_FMT_BGR4:
  3244. *yuv2packed1 = yuv2rgb4_1_c;
  3245. *yuv2packed2 = yuv2rgb4_2_c;
  3246. *yuv2packedX = yuv2rgb4_X_c;
  3247. break;
  3248. case AV_PIX_FMT_RGB4_BYTE:
  3249. case AV_PIX_FMT_BGR4_BYTE:
  3250. *yuv2packed1 = yuv2rgb4b_1_c;
  3251. *yuv2packed2 = yuv2rgb4b_2_c;
  3252. *yuv2packedX = yuv2rgb4b_X_c;
  3253. break;
  3254. case AV_PIX_FMT_X2RGB10LE:
  3255. case AV_PIX_FMT_X2RGB10BE:
  3256. *yuv2packed1 = yuv2x2rgb10_1_c;
  3257. *yuv2packed2 = yuv2x2rgb10_2_c;
  3258. *yuv2packedX = yuv2x2rgb10_X_c;
  3259. break;
  3260. case AV_PIX_FMT_X2BGR10LE:
  3261. case AV_PIX_FMT_X2BGR10BE:
  3262. *yuv2packed1 = yuv2x2bgr10_1_c;
  3263. *yuv2packed2 = yuv2x2bgr10_2_c;
  3264. *yuv2packedX = yuv2x2bgr10_X_c;
  3265. break;
  3266. }
  3267. }
  3268. switch (dstFormat) {
  3269. case AV_PIX_FMT_MONOWHITE:
  3270. *yuv2packed1 = yuv2monowhite_1_c;
  3271. *yuv2packed2 = yuv2monowhite_2_c;
  3272. *yuv2packedX = yuv2monowhite_X_c;
  3273. break;
  3274. case AV_PIX_FMT_MONOBLACK:
  3275. *yuv2packed1 = yuv2monoblack_1_c;
  3276. *yuv2packed2 = yuv2monoblack_2_c;
  3277. *yuv2packedX = yuv2monoblack_X_c;
  3278. break;
  3279. case AV_PIX_FMT_YUYV422:
  3280. *yuv2packed1 = yuv2yuyv422_1_c;
  3281. *yuv2packed2 = yuv2yuyv422_2_c;
  3282. *yuv2packedX = yuv2yuyv422_X_c;
  3283. break;
  3284. case AV_PIX_FMT_YVYU422:
  3285. *yuv2packed1 = yuv2yvyu422_1_c;
  3286. *yuv2packed2 = yuv2yvyu422_2_c;
  3287. *yuv2packedX = yuv2yvyu422_X_c;
  3288. break;
  3289. case AV_PIX_FMT_UYVY422:
  3290. *yuv2packed1 = yuv2uyvy422_1_c;
  3291. *yuv2packed2 = yuv2uyvy422_2_c;
  3292. *yuv2packedX = yuv2uyvy422_X_c;
  3293. break;
  3294. case AV_PIX_FMT_VYU444:
  3295. *yuv2packed1 = yuv2vyu444_1_c;
  3296. *yuv2packed2 = yuv2vyu444_2_c;
  3297. *yuv2packedX = yuv2vyu444_X_c;
  3298. break;
  3299. case AV_PIX_FMT_YA8:
  3300. *yuv2packed1 = yuv2ya8_1_c;
  3301. *yuv2packed2 = yuv2ya8_2_c;
  3302. *yuv2packedX = yuv2ya8_X_c;
  3303. break;
  3304. case AV_PIX_FMT_YA16LE:
  3305. *yuv2packed1 = yuv2ya16le_1_c;
  3306. *yuv2packed2 = yuv2ya16le_2_c;
  3307. *yuv2packedX = yuv2ya16le_X_c;
  3308. break;
  3309. case AV_PIX_FMT_YA16BE:
  3310. *yuv2packed1 = yuv2ya16be_1_c;
  3311. *yuv2packed2 = yuv2ya16be_2_c;
  3312. *yuv2packedX = yuv2ya16be_X_c;
  3313. break;
  3314. case AV_PIX_FMT_V30XLE:
  3315. *yuv2packedX = yuv2v30xle_X_c;
  3316. break;
  3317. case AV_PIX_FMT_AYUV64LE:
  3318. *yuv2packedX = yuv2ayuv64le_X_c;
  3319. break;
  3320. case AV_PIX_FMT_AYUV64BE:
  3321. *yuv2packedX = yuv2ayuv64be_X_c;
  3322. break;
  3323. case AV_PIX_FMT_AYUV:
  3324. *yuv2packed1 = yuv2ayuv_1_c;
  3325. *yuv2packed2 = yuv2ayuv_2_c;
  3326. *yuv2packedX = yuv2ayuv_X_c;
  3327. break;
  3328. case AV_PIX_FMT_VUYA:
  3329. case AV_PIX_FMT_VUYX:
  3330. *yuv2packed1 = yuv2vuyX_1_c;
  3331. *yuv2packed2 = yuv2vuyX_2_c;
  3332. *yuv2packedX = yuv2vuyX_X_c;
  3333. break;
  3334. case AV_PIX_FMT_UYVA:
  3335. *yuv2packed1 = yuv2uyva_1_c;
  3336. *yuv2packed2 = yuv2uyva_2_c;
  3337. *yuv2packedX = yuv2uyva_X_c;
  3338. break;
  3339. case AV_PIX_FMT_XV30LE:
  3340. *yuv2packedX = yuv2xv30le_X_c;
  3341. break;
  3342. case AV_PIX_FMT_XV36LE:
  3343. *yuv2packedX = yuv2xv36le_X_c;
  3344. break;
  3345. case AV_PIX_FMT_XV36BE:
  3346. *yuv2packedX = yuv2xv36be_X_c;
  3347. break;
  3348. case AV_PIX_FMT_XV48LE:
  3349. *yuv2packedX = yuv2xv48le_X_c;
  3350. break;
  3351. case AV_PIX_FMT_XV48BE:
  3352. *yuv2packedX = yuv2xv48be_X_c;
  3353. break;
  3354. case AV_PIX_FMT_Y210LE:
  3355. *yuv2packedX = yuv2y210le_X_c;
  3356. break;
  3357. case AV_PIX_FMT_Y212LE:
  3358. *yuv2packedX = yuv2y212le_X_c;
  3359. break;
  3360. case AV_PIX_FMT_Y216LE:
  3361. *yuv2packedX = yuv2y216le_X_c;
  3362. break;
  3363. }
  3364. }