output.c 136 KB

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