output.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319
  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(SwsContext *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(SwsContext *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. int 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, acc = 0;
  612. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  613. accumulate_bit(acc, Y + d128[0]);
  614. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  615. accumulate_bit(acc, Y + d128[1]);
  616. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  617. accumulate_bit(acc, Y + d128[2]);
  618. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  619. accumulate_bit(acc, Y + d128[3]);
  620. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  621. accumulate_bit(acc, Y + d128[4]);
  622. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  623. accumulate_bit(acc, Y + d128[5]);
  624. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  625. accumulate_bit(acc, Y + d128[6]);
  626. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  627. accumulate_bit(acc, Y + d128[7]);
  628. output_pixel(*dest++, acc);
  629. }
  630. }
  631. }
  632. static av_always_inline void
  633. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  634. const int16_t *ubuf[2], const int16_t *vbuf[2],
  635. const int16_t *abuf0, uint8_t *dest, int dstW,
  636. int uvalpha, int y, enum AVPixelFormat target)
  637. {
  638. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  639. int i;
  640. if (c->dither == SWS_DITHER_ED) {
  641. int err = 0;
  642. int acc = 0;
  643. for (i = 0; i < dstW; i +=2) {
  644. int Y;
  645. Y = ((buf0[i + 0] + 64) >> 7);
  646. 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;
  647. c->dither_error[0][i] = err;
  648. acc = 2*acc + (Y >= 128);
  649. Y -= 220*(acc&1);
  650. err = ((buf0[i + 1] + 64) >> 7);
  651. 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;
  652. c->dither_error[0][i+1] = Y;
  653. acc = 2*acc + (err >= 128);
  654. err -= 220*(acc&1);
  655. if ((i & 7) == 6)
  656. output_pixel(*dest++, acc);
  657. }
  658. c->dither_error[0][i] = err;
  659. } else {
  660. for (i = 0; i < dstW; i += 8) {
  661. int acc = 0;
  662. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  663. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  664. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  665. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  666. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  667. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  668. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  669. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  670. output_pixel(*dest++, acc);
  671. }
  672. }
  673. }
  674. #undef output_pixel
  675. #undef accumulate_bit
  676. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  677. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  678. const int16_t **lumSrc, int lumFilterSize, \
  679. const int16_t *chrFilter, const int16_t **chrUSrc, \
  680. const int16_t **chrVSrc, int chrFilterSize, \
  681. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  682. int y) \
  683. { \
  684. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  685. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  686. alpSrc, dest, dstW, y, fmt); \
  687. } \
  688. \
  689. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  690. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  691. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  692. int yalpha, int uvalpha, int y) \
  693. { \
  694. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  695. dest, dstW, yalpha, uvalpha, y, fmt); \
  696. } \
  697. \
  698. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  699. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  700. const int16_t *abuf0, uint8_t *dest, int dstW, \
  701. int uvalpha, int y) \
  702. { \
  703. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  704. abuf0, dest, dstW, uvalpha, \
  705. y, fmt); \
  706. }
  707. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  708. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  709. #define output_pixels(pos, Y1, U, Y2, V) \
  710. if (target == AV_PIX_FMT_YUYV422) { \
  711. dest[pos + 0] = Y1; \
  712. dest[pos + 1] = U; \
  713. dest[pos + 2] = Y2; \
  714. dest[pos + 3] = V; \
  715. } else if (target == AV_PIX_FMT_YVYU422) { \
  716. dest[pos + 0] = Y1; \
  717. dest[pos + 1] = V; \
  718. dest[pos + 2] = Y2; \
  719. dest[pos + 3] = U; \
  720. } else { /* AV_PIX_FMT_UYVY422 */ \
  721. dest[pos + 0] = U; \
  722. dest[pos + 1] = Y1; \
  723. dest[pos + 2] = V; \
  724. dest[pos + 3] = Y2; \
  725. }
  726. static av_always_inline void
  727. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  728. const int16_t **lumSrc, int lumFilterSize,
  729. const int16_t *chrFilter, const int16_t **chrUSrc,
  730. const int16_t **chrVSrc, int chrFilterSize,
  731. const int16_t **alpSrc, uint8_t *dest, int dstW,
  732. int y, enum AVPixelFormat target)
  733. {
  734. int i;
  735. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  736. int j;
  737. int Y1 = 1 << 18;
  738. int Y2 = 1 << 18;
  739. int U = 1 << 18;
  740. int V = 1 << 18;
  741. for (j = 0; j < lumFilterSize; j++) {
  742. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  743. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  744. }
  745. for (j = 0; j < chrFilterSize; j++) {
  746. U += chrUSrc[j][i] * chrFilter[j];
  747. V += chrVSrc[j][i] * chrFilter[j];
  748. }
  749. Y1 >>= 19;
  750. Y2 >>= 19;
  751. U >>= 19;
  752. V >>= 19;
  753. if ((Y1 | Y2 | U | V) & 0x100) {
  754. Y1 = av_clip_uint8(Y1);
  755. Y2 = av_clip_uint8(Y2);
  756. U = av_clip_uint8(U);
  757. V = av_clip_uint8(V);
  758. }
  759. output_pixels(4*i, Y1, U, Y2, V);
  760. }
  761. }
  762. static av_always_inline void
  763. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  764. const int16_t *ubuf[2], const int16_t *vbuf[2],
  765. const int16_t *abuf[2], uint8_t *dest, int dstW,
  766. int yalpha, int uvalpha, int y,
  767. enum AVPixelFormat target)
  768. {
  769. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  770. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  771. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  772. int yalpha1 = 4096 - yalpha;
  773. int uvalpha1 = 4096 - uvalpha;
  774. int i;
  775. av_assert2(yalpha <= 4096U);
  776. av_assert2(uvalpha <= 4096U);
  777. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  778. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  779. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  780. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  781. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  782. if ((Y1 | Y2 | U | V) & 0x100) {
  783. Y1 = av_clip_uint8(Y1);
  784. Y2 = av_clip_uint8(Y2);
  785. U = av_clip_uint8(U);
  786. V = av_clip_uint8(V);
  787. }
  788. output_pixels(i * 4, Y1, U, Y2, V);
  789. }
  790. }
  791. static av_always_inline void
  792. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  793. const int16_t *ubuf[2], const int16_t *vbuf[2],
  794. const int16_t *abuf0, uint8_t *dest, int dstW,
  795. int uvalpha, int y, enum AVPixelFormat target)
  796. {
  797. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  798. int i;
  799. if (uvalpha < 2048) {
  800. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  801. int Y1 = (buf0[i * 2 ]+64) >> 7;
  802. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  803. int U = (ubuf0[i] +64) >> 7;
  804. int V = (vbuf0[i] +64) >> 7;
  805. if ((Y1 | Y2 | U | V) & 0x100) {
  806. Y1 = av_clip_uint8(Y1);
  807. Y2 = av_clip_uint8(Y2);
  808. U = av_clip_uint8(U);
  809. V = av_clip_uint8(V);
  810. }
  811. output_pixels(i * 4, Y1, U, Y2, V);
  812. }
  813. } else {
  814. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  815. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  816. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  817. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  818. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  819. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  820. if ((Y1 | Y2 | U | V) & 0x100) {
  821. Y1 = av_clip_uint8(Y1);
  822. Y2 = av_clip_uint8(Y2);
  823. U = av_clip_uint8(U);
  824. V = av_clip_uint8(V);
  825. }
  826. output_pixels(i * 4, Y1, U, Y2, V);
  827. }
  828. }
  829. }
  830. #undef output_pixels
  831. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  832. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  833. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  834. #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)
  835. #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)
  836. #define output_pixel(pos, val) \
  837. if (is_be) { \
  838. AV_WB16(pos, val); \
  839. } else { \
  840. AV_WL16(pos, val); \
  841. }
  842. static av_always_inline void
  843. yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
  844. const int32_t **lumSrc, int lumFilterSize,
  845. const int16_t *chrFilter, const int32_t **unused_chrUSrc,
  846. const int32_t **unused_chrVSrc, int unused_chrFilterSize,
  847. const int32_t **alpSrc, uint16_t *dest, int dstW,
  848. int y, enum AVPixelFormat target,
  849. int unused_hasAlpha, int unused_eightbytes, int is_be)
  850. {
  851. int hasAlpha = !!alpSrc;
  852. int i;
  853. for (i = 0; i < dstW; i++) {
  854. int j;
  855. int Y = -0x40000000;
  856. int A = 0xffff;
  857. for (j = 0; j < lumFilterSize; j++)
  858. Y += lumSrc[j][i] * lumFilter[j];
  859. Y >>= 15;
  860. Y += (1<<3) + 0x8000;
  861. Y = av_clip_uint16(Y);
  862. if (hasAlpha) {
  863. A = -0x40000000 + (1<<14);
  864. for (j = 0; j < lumFilterSize; j++)
  865. A += alpSrc[j][i] * lumFilter[j];
  866. A >>= 15;
  867. A += 0x8000;
  868. A = av_clip_uint16(A);
  869. }
  870. output_pixel(&dest[2 * i ], Y);
  871. output_pixel(&dest[2 * i + 1], A);
  872. }
  873. }
  874. static av_always_inline void
  875. yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2],
  876. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  877. const int32_t *abuf[2], uint16_t *dest, int dstW,
  878. int yalpha, int unused_uvalpha, int y,
  879. enum AVPixelFormat target, int unused_hasAlpha,
  880. int unused_eightbytes, int is_be)
  881. {
  882. int hasAlpha = abuf && abuf[0] && abuf[1];
  883. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  884. *abuf0 = hasAlpha ? abuf[0] : NULL,
  885. *abuf1 = hasAlpha ? abuf[1] : NULL;
  886. int yalpha1 = 4096 - yalpha;
  887. int i;
  888. av_assert2(yalpha <= 4096U);
  889. for (i = 0; i < dstW; i++) {
  890. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
  891. int A;
  892. Y = av_clip_uint16(Y);
  893. if (hasAlpha) {
  894. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
  895. A = av_clip_uint16(A);
  896. }
  897. output_pixel(&dest[2 * i ], Y);
  898. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  899. }
  900. }
  901. static av_always_inline void
  902. yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0,
  903. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  904. const int32_t *abuf0, uint16_t *dest, int dstW,
  905. int unused_uvalpha, int y, enum AVPixelFormat target,
  906. int unused_hasAlpha, int unused_eightbytes, int is_be)
  907. {
  908. int hasAlpha = !!abuf0;
  909. int i;
  910. for (i = 0; i < dstW; i++) {
  911. int Y = buf0[i] >> 3;/* 19 - 16 */
  912. int A;
  913. Y = av_clip_uint16(Y);
  914. if (hasAlpha) {
  915. A = abuf0[i] >> 3;
  916. if (A & 0x100)
  917. A = av_clip_uint16(A);
  918. }
  919. output_pixel(&dest[2 * i ], Y);
  920. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  921. }
  922. }
  923. static av_always_inline void
  924. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  925. const int32_t **lumSrc, int lumFilterSize,
  926. const int16_t *chrFilter, const int32_t **chrUSrc,
  927. const int32_t **chrVSrc, int chrFilterSize,
  928. const int32_t **alpSrc, uint16_t *dest, int dstW,
  929. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes,
  930. int is_be)
  931. {
  932. int i;
  933. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  934. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  935. int j;
  936. int Y1 = -0x40000000;
  937. int Y2 = -0x40000000;
  938. int U = -(128 << 23); // 19
  939. int V = -(128 << 23);
  940. int R, G, B;
  941. for (j = 0; j < lumFilterSize; j++) {
  942. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  943. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  944. }
  945. for (j = 0; j < chrFilterSize; j++) {;
  946. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  947. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  948. }
  949. if (hasAlpha) {
  950. A1 = -0x40000000;
  951. A2 = -0x40000000;
  952. for (j = 0; j < lumFilterSize; j++) {
  953. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  954. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  955. }
  956. A1 >>= 1;
  957. A1 += 0x20002000;
  958. A2 >>= 1;
  959. A2 += 0x20002000;
  960. }
  961. // 8 bits: 12+15=27; 16 bits: 12+19=31
  962. Y1 >>= 14; // 10
  963. Y1 += 0x10000;
  964. Y2 >>= 14;
  965. Y2 += 0x10000;
  966. U >>= 14;
  967. V >>= 14;
  968. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  969. Y1 -= c->yuv2rgb_y_offset;
  970. Y2 -= c->yuv2rgb_y_offset;
  971. Y1 *= c->yuv2rgb_y_coeff;
  972. Y2 *= c->yuv2rgb_y_coeff;
  973. Y1 += (1 << 13) - (1 << 29); // 21
  974. Y2 += (1 << 13) - (1 << 29);
  975. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  976. R = V * c->yuv2rgb_v2r_coeff;
  977. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  978. B = U * c->yuv2rgb_u2b_coeff;
  979. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  980. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
  981. output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16));
  982. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
  983. if (eightbytes) {
  984. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  985. output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
  986. output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16));
  987. output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
  988. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  989. dest += 8;
  990. } else {
  991. output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
  992. output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16));
  993. output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
  994. dest += 6;
  995. }
  996. }
  997. }
  998. static av_always_inline void
  999. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  1000. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1001. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1002. int yalpha, int uvalpha, int y,
  1003. enum AVPixelFormat target, int hasAlpha, int eightbytes,
  1004. int is_be)
  1005. {
  1006. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1007. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1008. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1009. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1010. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1011. int yalpha1 = 4096 - yalpha;
  1012. int uvalpha1 = 4096 - uvalpha;
  1013. int i;
  1014. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  1015. av_assert2(yalpha <= 4096U);
  1016. av_assert2(uvalpha <= 4096U);
  1017. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1018. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  1019. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  1020. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1021. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1022. int R, G, B;
  1023. Y1 -= c->yuv2rgb_y_offset;
  1024. Y2 -= c->yuv2rgb_y_offset;
  1025. Y1 *= c->yuv2rgb_y_coeff;
  1026. Y2 *= c->yuv2rgb_y_coeff;
  1027. Y1 += (1 << 13) - (1 << 29);
  1028. Y2 += (1 << 13) - (1 << 29);
  1029. R = V * c->yuv2rgb_v2r_coeff;
  1030. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1031. B = U * c->yuv2rgb_u2b_coeff;
  1032. if (hasAlpha) {
  1033. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  1034. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  1035. A1 += 1 << 13;
  1036. A2 += 1 << 13;
  1037. }
  1038. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16));
  1039. output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16));
  1040. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16));
  1041. if (eightbytes) {
  1042. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1043. output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
  1044. output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16));
  1045. output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
  1046. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1047. dest += 8;
  1048. } else {
  1049. output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16));
  1050. output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16));
  1051. output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16));
  1052. dest += 6;
  1053. }
  1054. }
  1055. }
  1056. static av_always_inline void
  1057. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  1058. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1059. const int32_t *abuf0, uint16_t *dest, int dstW,
  1060. int uvalpha, int y, enum AVPixelFormat target,
  1061. int hasAlpha, int eightbytes, int is_be)
  1062. {
  1063. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1064. int i;
  1065. int A1 = 0xffff<<14, A2= 0xffff<<14;
  1066. if (uvalpha < 2048) {
  1067. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1068. SUINT Y1 = (buf0[i * 2] ) >> 2;
  1069. SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
  1070. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1071. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1072. int R, G, B;
  1073. Y1 -= c->yuv2rgb_y_offset;
  1074. Y2 -= c->yuv2rgb_y_offset;
  1075. Y1 *= c->yuv2rgb_y_coeff;
  1076. Y2 *= c->yuv2rgb_y_coeff;
  1077. Y1 += (1 << 13) - (1 << 29);
  1078. Y2 += (1 << 13) - (1 << 29);
  1079. if (hasAlpha) {
  1080. A1 = abuf0[i * 2 ] * (1 << 11);
  1081. A2 = abuf0[i * 2 + 1] * (1 << 11);
  1082. A1 += 1 << 13;
  1083. A2 += 1 << 13;
  1084. }
  1085. R = V * c->yuv2rgb_v2r_coeff;
  1086. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1087. B = U * c->yuv2rgb_u2b_coeff;
  1088. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1089. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1090. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1091. if (eightbytes) {
  1092. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1093. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1094. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1095. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1096. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1097. dest += 8;
  1098. } else {
  1099. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1100. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1101. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1102. dest += 6;
  1103. }
  1104. }
  1105. } else {
  1106. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1107. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  1108. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1109. SUINT Y1 = (buf0[i * 2] ) >> 2;
  1110. SUINT Y2 = (buf0[i * 2 + 1]) >> 2;
  1111. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1112. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1113. int R, G, B;
  1114. Y1 -= c->yuv2rgb_y_offset;
  1115. Y2 -= c->yuv2rgb_y_offset;
  1116. Y1 *= c->yuv2rgb_y_coeff;
  1117. Y2 *= c->yuv2rgb_y_coeff;
  1118. Y1 += (1 << 13) - (1 << 29);
  1119. Y2 += (1 << 13) - (1 << 29);
  1120. if (hasAlpha) {
  1121. A1 = abuf0[i * 2 ] * (1 << 11);
  1122. A2 = abuf0[i * 2 + 1] * (1 << 11);
  1123. A1 += 1 << 13;
  1124. A2 += 1 << 13;
  1125. }
  1126. R = V * c->yuv2rgb_v2r_coeff;
  1127. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1128. B = U * c->yuv2rgb_u2b_coeff;
  1129. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16));
  1130. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16));
  1131. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16));
  1132. if (eightbytes) {
  1133. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1134. output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1135. output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1136. output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1137. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1138. dest += 8;
  1139. } else {
  1140. output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16));
  1141. output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16));
  1142. output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16));
  1143. dest += 6;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. static av_always_inline void
  1149. yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1150. const int32_t **lumSrc, int lumFilterSize,
  1151. const int16_t *chrFilter, const int32_t **chrUSrc,
  1152. const int32_t **chrVSrc, int chrFilterSize,
  1153. const int32_t **alpSrc, uint16_t *dest, int dstW,
  1154. int y, enum AVPixelFormat target, int hasAlpha,
  1155. int eightbytes, int is_be)
  1156. {
  1157. int i;
  1158. int A = 0xffff<<14;
  1159. for (i = 0; i < dstW; i++) {
  1160. int j;
  1161. int Y = -0x40000000;
  1162. int U = -(128 << 23); // 19
  1163. int V = -(128 << 23);
  1164. int R, G, B;
  1165. for (j = 0; j < lumFilterSize; j++) {
  1166. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1167. }
  1168. for (j = 0; j < chrFilterSize; j++) {;
  1169. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1170. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1171. }
  1172. if (hasAlpha) {
  1173. A = -0x40000000;
  1174. for (j = 0; j < lumFilterSize; j++) {
  1175. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1176. }
  1177. A >>= 1;
  1178. A += 0x20002000;
  1179. }
  1180. // 8bit: 12+15=27; 16-bit: 12+19=31
  1181. Y >>= 14; // 10
  1182. Y += 0x10000;
  1183. U >>= 14;
  1184. V >>= 14;
  1185. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  1186. Y -= c->yuv2rgb_y_offset;
  1187. Y *= c->yuv2rgb_y_coeff;
  1188. Y += (1 << 13) - (1<<29); // 21
  1189. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  1190. R = V * c->yuv2rgb_v2r_coeff;
  1191. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1192. B = U * c->yuv2rgb_u2b_coeff;
  1193. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  1194. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y)>>14) + (1<<15), 16));
  1195. output_pixel(&dest[1], av_clip_uintp2((( G + Y)>>14) + (1<<15), 16));
  1196. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y)>>14) + (1<<15), 16));
  1197. if (eightbytes) {
  1198. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1199. dest += 4;
  1200. } else {
  1201. dest += 3;
  1202. }
  1203. }
  1204. }
  1205. static av_always_inline void
  1206. yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
  1207. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1208. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1209. int yalpha, int uvalpha, int y,
  1210. enum AVPixelFormat target, int hasAlpha, int eightbytes,
  1211. int is_be)
  1212. {
  1213. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1214. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1215. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1216. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1217. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1218. int yalpha1 = 4096 - yalpha;
  1219. int uvalpha1 = 4096 - uvalpha;
  1220. int i;
  1221. int A = 0xffff<<14;
  1222. av_assert2(yalpha <= 4096U);
  1223. av_assert2(uvalpha <= 4096U);
  1224. for (i = 0; i < dstW; i++) {
  1225. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  1226. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1227. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1228. int R, G, B;
  1229. Y -= c->yuv2rgb_y_offset;
  1230. Y *= c->yuv2rgb_y_coeff;
  1231. Y += (1 << 13) - (1 << 29);
  1232. R = V * c->yuv2rgb_v2r_coeff;
  1233. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1234. B = U * c->yuv2rgb_u2b_coeff;
  1235. if (hasAlpha) {
  1236. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  1237. A += 1 << 13;
  1238. }
  1239. output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));
  1240. output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));
  1241. output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));
  1242. if (eightbytes) {
  1243. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1244. dest += 4;
  1245. } else {
  1246. dest += 3;
  1247. }
  1248. }
  1249. }
  1250. static av_always_inline void
  1251. yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
  1252. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1253. const int32_t *abuf0, uint16_t *dest, int dstW,
  1254. int uvalpha, int y, enum AVPixelFormat target,
  1255. int hasAlpha, int eightbytes, int is_be)
  1256. {
  1257. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1258. int i;
  1259. int A = 0xffff<<14;
  1260. if (uvalpha < 2048) {
  1261. for (i = 0; i < dstW; i++) {
  1262. SUINT Y = (buf0[i]) >> 2;
  1263. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1264. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1265. int R, G, B;
  1266. Y -= c->yuv2rgb_y_offset;
  1267. Y *= c->yuv2rgb_y_coeff;
  1268. Y += (1 << 13) - (1 << 29);
  1269. if (hasAlpha) {
  1270. A = abuf0[i] * (1 << 11);
  1271. A += 1 << 13;
  1272. }
  1273. R = V * c->yuv2rgb_v2r_coeff;
  1274. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1275. B = U * c->yuv2rgb_u2b_coeff;
  1276. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1277. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1278. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1279. if (eightbytes) {
  1280. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1281. dest += 4;
  1282. } else {
  1283. dest += 3;
  1284. }
  1285. }
  1286. } else {
  1287. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1288. int A = 0xffff<<14;
  1289. for (i = 0; i < dstW; i++) {
  1290. SUINT Y = (buf0[i] ) >> 2;
  1291. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1292. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1293. int R, G, B;
  1294. Y -= c->yuv2rgb_y_offset;
  1295. Y *= c->yuv2rgb_y_coeff;
  1296. Y += (1 << 13) - (1 << 29);
  1297. if (hasAlpha) {
  1298. A = abuf0[i] * (1 << 11);
  1299. A += 1 << 13;
  1300. }
  1301. R = V * c->yuv2rgb_v2r_coeff;
  1302. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1303. B = U * c->yuv2rgb_u2b_coeff;
  1304. output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
  1305. output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
  1306. output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
  1307. if (eightbytes) {
  1308. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1309. dest += 4;
  1310. } else {
  1311. dest += 3;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. #undef output_pixel
  1317. #undef r_b
  1318. #undef b_r
  1319. #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
  1320. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1321. const int16_t **_lumSrc, int lumFilterSize, \
  1322. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1323. const int16_t **_chrVSrc, int chrFilterSize, \
  1324. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1325. int y) \
  1326. { \
  1327. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1328. **chrUSrc = (const int32_t **) _chrUSrc, \
  1329. **chrVSrc = (const int32_t **) _chrVSrc, \
  1330. **alpSrc = (const int32_t **) _alpSrc; \
  1331. uint16_t *dest = (uint16_t *) _dest; \
  1332. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1333. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1334. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
  1335. } \
  1336. \
  1337. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  1338. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1339. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1340. int yalpha, int uvalpha, int y) \
  1341. { \
  1342. const int32_t **buf = (const int32_t **) _buf, \
  1343. **ubuf = (const int32_t **) _ubuf, \
  1344. **vbuf = (const int32_t **) _vbuf, \
  1345. **abuf = (const int32_t **) _abuf; \
  1346. uint16_t *dest = (uint16_t *) _dest; \
  1347. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1348. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1349. } \
  1350. \
  1351. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  1352. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1353. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1354. int uvalpha, int y) \
  1355. { \
  1356. const int32_t *buf0 = (const int32_t *) _buf0, \
  1357. **ubuf = (const int32_t **) _ubuf, \
  1358. **vbuf = (const int32_t **) _vbuf, \
  1359. *abuf0 = (const int32_t *) _abuf0; \
  1360. uint16_t *dest = (uint16_t *) _dest; \
  1361. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1362. dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
  1363. }
  1364. #define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
  1365. YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
  1366. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48, BE, 0, 0)
  1367. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48, LE, 0, 0)
  1368. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48, BE, 0, 0)
  1369. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48, LE, 0, 0)
  1370. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1371. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1372. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1373. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1374. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1375. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1376. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1377. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1378. YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
  1379. YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
  1380. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
  1381. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
  1382. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48, BE, 0, 0)
  1383. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48, LE, 0, 0)
  1384. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64, BE, 1, 1)
  1385. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64, LE, 1, 1)
  1386. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64, BE, 0, 1)
  1387. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64, LE, 0, 1)
  1388. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64, BE, 1, 1)
  1389. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64, LE, 1, 1)
  1390. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64, BE, 0, 1)
  1391. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64, LE, 0, 1)
  1392. /*
  1393. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1394. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1395. * things like endianness conversion and shifting. The caller takes care of
  1396. * setting the correct offset in these tables from the chroma (U/V) values.
  1397. * This function then uses the luminance (Y1/Y2) values to write out the
  1398. * correct RGB values into the destination buffer.
  1399. */
  1400. static av_always_inline void
  1401. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1402. unsigned A1, unsigned A2,
  1403. const void *_r, const void *_g, const void *_b, int y,
  1404. enum AVPixelFormat target, int hasAlpha)
  1405. {
  1406. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1407. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1408. uint32_t *dest = (uint32_t *) _dest;
  1409. const uint32_t *r = (const uint32_t *) _r;
  1410. const uint32_t *g = (const uint32_t *) _g;
  1411. const uint32_t *b = (const uint32_t *) _b;
  1412. #if CONFIG_SMALL
  1413. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1414. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1415. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1416. #else
  1417. if (hasAlpha) {
  1418. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1419. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1420. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1421. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1422. } else {
  1423. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1424. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1425. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1426. #endif
  1427. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1428. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1429. }
  1430. #endif
  1431. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1432. uint8_t *dest = (uint8_t *) _dest;
  1433. const uint8_t *r = (const uint8_t *) _r;
  1434. const uint8_t *g = (const uint8_t *) _g;
  1435. const uint8_t *b = (const uint8_t *) _b;
  1436. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1437. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1438. dest[i * 6 + 0] = r_b[Y1];
  1439. dest[i * 6 + 1] = g[Y1];
  1440. dest[i * 6 + 2] = b_r[Y1];
  1441. dest[i * 6 + 3] = r_b[Y2];
  1442. dest[i * 6 + 4] = g[Y2];
  1443. dest[i * 6 + 5] = b_r[Y2];
  1444. #undef r_b
  1445. #undef b_r
  1446. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1447. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1448. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1449. uint16_t *dest = (uint16_t *) _dest;
  1450. const uint16_t *r = (const uint16_t *) _r;
  1451. const uint16_t *g = (const uint16_t *) _g;
  1452. const uint16_t *b = (const uint16_t *) _b;
  1453. int dr1, dg1, db1, dr2, dg2, db2;
  1454. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1455. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1456. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1457. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1458. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1459. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1460. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1461. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1462. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1463. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1464. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1465. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1466. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1467. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1468. } else {
  1469. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1470. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1471. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1472. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1473. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1474. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1475. }
  1476. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1477. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1478. } else if (target == AV_PIX_FMT_X2RGB10 || target == AV_PIX_FMT_X2BGR10) {
  1479. uint32_t *dest = (uint32_t *) _dest;
  1480. const uint32_t *r = (const uint32_t *) _r;
  1481. const uint32_t *g = (const uint32_t *) _g;
  1482. const uint32_t *b = (const uint32_t *) _b;
  1483. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1484. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1485. } else /* 8/4 bits */ {
  1486. uint8_t *dest = (uint8_t *) _dest;
  1487. const uint8_t *r = (const uint8_t *) _r;
  1488. const uint8_t *g = (const uint8_t *) _g;
  1489. const uint8_t *b = (const uint8_t *) _b;
  1490. int dr1, dg1, db1, dr2, dg2, db2;
  1491. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1492. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1493. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1494. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1495. db1 = d64[(i * 2 + 0) & 7];
  1496. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1497. db2 = d64[(i * 2 + 1) & 7];
  1498. } else {
  1499. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1500. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1501. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1502. dg1 = d64[(i * 2 + 0) & 7];
  1503. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1504. dg2 = d64[(i * 2 + 1) & 7];
  1505. }
  1506. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1507. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1508. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1509. } else {
  1510. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1511. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1512. }
  1513. }
  1514. }
  1515. static av_always_inline void
  1516. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1517. const int16_t **lumSrc, int lumFilterSize,
  1518. const int16_t *chrFilter, const int16_t **chrUSrc,
  1519. const int16_t **chrVSrc, int chrFilterSize,
  1520. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1521. int y, enum AVPixelFormat target, int hasAlpha)
  1522. {
  1523. int i;
  1524. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1525. int j, A1, A2;
  1526. int Y1 = 1 << 18;
  1527. int Y2 = 1 << 18;
  1528. int U = 1 << 18;
  1529. int V = 1 << 18;
  1530. const void *r, *g, *b;
  1531. for (j = 0; j < lumFilterSize; j++) {
  1532. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1533. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1534. }
  1535. for (j = 0; j < chrFilterSize; j++) {
  1536. U += chrUSrc[j][i] * chrFilter[j];
  1537. V += chrVSrc[j][i] * chrFilter[j];
  1538. }
  1539. Y1 >>= 19;
  1540. Y2 >>= 19;
  1541. U >>= 19;
  1542. V >>= 19;
  1543. if (hasAlpha) {
  1544. A1 = 1 << 18;
  1545. A2 = 1 << 18;
  1546. for (j = 0; j < lumFilterSize; j++) {
  1547. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1548. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1549. }
  1550. A1 >>= 19;
  1551. A2 >>= 19;
  1552. if ((A1 | A2) & 0x100) {
  1553. A1 = av_clip_uint8(A1);
  1554. A2 = av_clip_uint8(A2);
  1555. }
  1556. }
  1557. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1558. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1559. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1560. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1561. r, g, b, y, target, hasAlpha);
  1562. }
  1563. }
  1564. static av_always_inline void
  1565. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1566. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1567. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1568. int yalpha, int uvalpha, int y,
  1569. enum AVPixelFormat target, int hasAlpha)
  1570. {
  1571. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1572. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1573. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1574. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1575. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1576. int yalpha1 = 4096 - yalpha;
  1577. int uvalpha1 = 4096 - uvalpha;
  1578. int i;
  1579. av_assert2(yalpha <= 4096U);
  1580. av_assert2(uvalpha <= 4096U);
  1581. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1582. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1583. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1584. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1585. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1586. int A1, A2;
  1587. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1588. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1589. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1590. if (hasAlpha) {
  1591. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1592. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1593. A1 = av_clip_uint8(A1);
  1594. A2 = av_clip_uint8(A2);
  1595. }
  1596. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1597. r, g, b, y, target, hasAlpha);
  1598. }
  1599. }
  1600. static av_always_inline void
  1601. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1602. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1603. const int16_t *abuf0, uint8_t *dest, int dstW,
  1604. int uvalpha, int y, enum AVPixelFormat target,
  1605. int hasAlpha)
  1606. {
  1607. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1608. int i;
  1609. if (uvalpha < 2048) {
  1610. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1611. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1612. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1613. int U = (ubuf0[i] + 64) >> 7;
  1614. int V = (vbuf0[i] + 64) >> 7;
  1615. int A1, A2;
  1616. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1617. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1618. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1619. if (hasAlpha) {
  1620. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1621. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1622. A1 = av_clip_uint8(A1);
  1623. A2 = av_clip_uint8(A2);
  1624. }
  1625. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1626. r, g, b, y, target, hasAlpha);
  1627. }
  1628. } else {
  1629. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1630. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1631. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1632. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1633. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1634. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1635. int A1, A2;
  1636. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1637. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1638. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1639. if (hasAlpha) {
  1640. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1641. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1642. A1 = av_clip_uint8(A1);
  1643. A2 = av_clip_uint8(A2);
  1644. }
  1645. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1646. r, g, b, y, target, hasAlpha);
  1647. }
  1648. }
  1649. }
  1650. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1651. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1652. const int16_t **lumSrc, int lumFilterSize, \
  1653. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1654. const int16_t **chrVSrc, int chrFilterSize, \
  1655. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1656. int y) \
  1657. { \
  1658. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1659. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1660. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1661. }
  1662. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1663. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1664. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1665. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1666. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1667. int yalpha, int uvalpha, int y) \
  1668. { \
  1669. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1670. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1671. }
  1672. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1673. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1674. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1675. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1676. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1677. int uvalpha, int y) \
  1678. { \
  1679. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1680. dstW, uvalpha, y, fmt, hasAlpha); \
  1681. }
  1682. #if CONFIG_SMALL
  1683. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1684. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1685. #else
  1686. #if CONFIG_SWSCALE_ALPHA
  1687. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1688. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1689. #endif
  1690. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1691. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1692. #endif
  1693. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1694. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1695. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1696. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1697. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1698. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1699. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1700. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1701. YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0)
  1702. YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0)
  1703. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1704. uint8_t *dest, int i, int Y, int A, int U, int V,
  1705. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1706. {
  1707. int R, G, B;
  1708. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1709. Y -= c->yuv2rgb_y_offset;
  1710. Y *= c->yuv2rgb_y_coeff;
  1711. Y += 1 << 21;
  1712. R = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2r_coeff;
  1713. G = (unsigned)Y + V*(unsigned)c->yuv2rgb_v2g_coeff + U*(unsigned)c->yuv2rgb_u2g_coeff;
  1714. B = (unsigned)Y + U*(unsigned)c->yuv2rgb_u2b_coeff;
  1715. if ((R | G | B) & 0xC0000000) {
  1716. R = av_clip_uintp2(R, 30);
  1717. G = av_clip_uintp2(G, 30);
  1718. B = av_clip_uintp2(B, 30);
  1719. }
  1720. switch(target) {
  1721. case AV_PIX_FMT_ARGB:
  1722. dest[0] = hasAlpha ? A : 255;
  1723. dest[1] = R >> 22;
  1724. dest[2] = G >> 22;
  1725. dest[3] = B >> 22;
  1726. break;
  1727. case AV_PIX_FMT_RGB24:
  1728. dest[0] = R >> 22;
  1729. dest[1] = G >> 22;
  1730. dest[2] = B >> 22;
  1731. break;
  1732. case AV_PIX_FMT_RGBA:
  1733. dest[0] = R >> 22;
  1734. dest[1] = G >> 22;
  1735. dest[2] = B >> 22;
  1736. dest[3] = hasAlpha ? A : 255;
  1737. break;
  1738. case AV_PIX_FMT_ABGR:
  1739. dest[0] = hasAlpha ? A : 255;
  1740. dest[1] = B >> 22;
  1741. dest[2] = G >> 22;
  1742. dest[3] = R >> 22;
  1743. break;
  1744. case AV_PIX_FMT_BGR24:
  1745. dest[0] = B >> 22;
  1746. dest[1] = G >> 22;
  1747. dest[2] = R >> 22;
  1748. break;
  1749. case AV_PIX_FMT_BGRA:
  1750. dest[0] = B >> 22;
  1751. dest[1] = G >> 22;
  1752. dest[2] = R >> 22;
  1753. dest[3] = hasAlpha ? A : 255;
  1754. break;
  1755. case AV_PIX_FMT_BGR4_BYTE:
  1756. case AV_PIX_FMT_RGB4_BYTE:
  1757. case AV_PIX_FMT_BGR8:
  1758. case AV_PIX_FMT_RGB8:
  1759. {
  1760. int r,g,b;
  1761. switch (c->dither) {
  1762. case SWS_DITHER_NONE:
  1763. if (isrgb8) {
  1764. r = av_clip_uintp2(R >> 27, 3);
  1765. g = av_clip_uintp2(G >> 27, 3);
  1766. b = av_clip_uintp2(B >> 28, 2);
  1767. } else {
  1768. r = av_clip_uintp2(R >> 29, 1);
  1769. g = av_clip_uintp2(G >> 28, 2);
  1770. b = av_clip_uintp2(B >> 29, 1);
  1771. }
  1772. break;
  1773. default:
  1774. case SWS_DITHER_AUTO:
  1775. case SWS_DITHER_ED:
  1776. R >>= 22;
  1777. G >>= 22;
  1778. B >>= 22;
  1779. 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;
  1780. 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;
  1781. 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;
  1782. c->dither_error[0][i] = err[0];
  1783. c->dither_error[1][i] = err[1];
  1784. c->dither_error[2][i] = err[2];
  1785. r = R >> (isrgb8 ? 5 : 7);
  1786. g = G >> (isrgb8 ? 5 : 6);
  1787. b = B >> (isrgb8 ? 6 : 7);
  1788. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1789. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1790. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1791. err[0] = R - r*(isrgb8 ? 36 : 255);
  1792. err[1] = G - g*(isrgb8 ? 36 : 85);
  1793. err[2] = B - b*(isrgb8 ? 85 : 255);
  1794. break;
  1795. case SWS_DITHER_A_DITHER:
  1796. if (isrgb8) {
  1797. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1798. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1799. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1800. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1801. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1802. r = av_clip_uintp2(r, 3);
  1803. g = av_clip_uintp2(g, 3);
  1804. b = av_clip_uintp2(b, 2);
  1805. } else {
  1806. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1807. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1808. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1809. r = av_clip_uintp2(r, 1);
  1810. g = av_clip_uintp2(g, 2);
  1811. b = av_clip_uintp2(b, 1);
  1812. }
  1813. break;
  1814. case SWS_DITHER_X_DITHER:
  1815. if (isrgb8) {
  1816. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1817. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1818. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1819. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1820. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1821. r = av_clip_uintp2(r, 3);
  1822. g = av_clip_uintp2(g, 3);
  1823. b = av_clip_uintp2(b, 2);
  1824. } else {
  1825. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1826. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1827. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1828. r = av_clip_uintp2(r, 1);
  1829. g = av_clip_uintp2(g, 2);
  1830. b = av_clip_uintp2(b, 1);
  1831. }
  1832. break;
  1833. }
  1834. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1835. dest[0] = r + 2*g + 8*b;
  1836. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1837. dest[0] = b + 2*g + 8*r;
  1838. } else if(target == AV_PIX_FMT_BGR8) {
  1839. dest[0] = r + 8*g + 64*b;
  1840. } else if(target == AV_PIX_FMT_RGB8) {
  1841. dest[0] = b + 4*g + 32*r;
  1842. } else
  1843. av_assert2(0);
  1844. break;}
  1845. }
  1846. }
  1847. static av_always_inline void
  1848. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1849. const int16_t **lumSrc, int lumFilterSize,
  1850. const int16_t *chrFilter, const int16_t **chrUSrc,
  1851. const int16_t **chrVSrc, int chrFilterSize,
  1852. const int16_t **alpSrc, uint8_t *dest,
  1853. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1854. {
  1855. int i;
  1856. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1857. int err[4] = {0};
  1858. int A = 0; //init to silence warning
  1859. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1860. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1861. step = 1;
  1862. for (i = 0; i < dstW; i++) {
  1863. int j;
  1864. int Y = 1<<9;
  1865. int U = (1<<9)-(128 << 19);
  1866. int V = (1<<9)-(128 << 19);
  1867. for (j = 0; j < lumFilterSize; j++) {
  1868. Y += lumSrc[j][i] * lumFilter[j];
  1869. }
  1870. for (j = 0; j < chrFilterSize; j++) {
  1871. U += chrUSrc[j][i] * chrFilter[j];
  1872. V += chrVSrc[j][i] * chrFilter[j];
  1873. }
  1874. Y >>= 10;
  1875. U >>= 10;
  1876. V >>= 10;
  1877. if (hasAlpha) {
  1878. A = 1 << 18;
  1879. for (j = 0; j < lumFilterSize; j++) {
  1880. A += alpSrc[j][i] * lumFilter[j];
  1881. }
  1882. A >>= 19;
  1883. if (A & 0x100)
  1884. A = av_clip_uint8(A);
  1885. }
  1886. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1887. dest += step;
  1888. }
  1889. c->dither_error[0][i] = err[0];
  1890. c->dither_error[1][i] = err[1];
  1891. c->dither_error[2][i] = err[2];
  1892. }
  1893. static av_always_inline void
  1894. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1895. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1896. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1897. int yalpha, int uvalpha, int y,
  1898. enum AVPixelFormat target, int hasAlpha)
  1899. {
  1900. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1901. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1902. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1903. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1904. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1905. int yalpha1 = 4096 - yalpha;
  1906. int uvalpha1 = 4096 - uvalpha;
  1907. int i;
  1908. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1909. int err[4] = {0};
  1910. int A = 0; // init to silcene warning
  1911. av_assert2(yalpha <= 4096U);
  1912. av_assert2(uvalpha <= 4096U);
  1913. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1914. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1915. step = 1;
  1916. for (i = 0; i < dstW; i++) {
  1917. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1918. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1919. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1920. if (hasAlpha) {
  1921. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1922. if (A & 0x100)
  1923. A = av_clip_uint8(A);
  1924. }
  1925. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1926. dest += step;
  1927. }
  1928. c->dither_error[0][i] = err[0];
  1929. c->dither_error[1][i] = err[1];
  1930. c->dither_error[2][i] = err[2];
  1931. }
  1932. static av_always_inline void
  1933. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1934. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1935. const int16_t *abuf0, uint8_t *dest, int dstW,
  1936. int uvalpha, int y, enum AVPixelFormat target,
  1937. int hasAlpha)
  1938. {
  1939. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1940. int i;
  1941. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1942. int err[4] = {0};
  1943. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1944. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1945. step = 1;
  1946. if (uvalpha < 2048) {
  1947. int A = 0; //init to silence warning
  1948. for (i = 0; i < dstW; i++) {
  1949. int Y = buf0[i] * 4;
  1950. int U = (ubuf0[i] - (128<<7)) * 4;
  1951. int V = (vbuf0[i] - (128<<7)) * 4;
  1952. if (hasAlpha) {
  1953. A = (abuf0[i] + 64) >> 7;
  1954. if (A & 0x100)
  1955. A = av_clip_uint8(A);
  1956. }
  1957. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1958. dest += step;
  1959. }
  1960. } else {
  1961. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1962. int A = 0; //init to silence warning
  1963. for (i = 0; i < dstW; i++) {
  1964. int Y = buf0[i] * 4;
  1965. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) * 2;
  1966. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) * 2;
  1967. if (hasAlpha) {
  1968. A = (abuf0[i] + 64) >> 7;
  1969. if (A & 0x100)
  1970. A = av_clip_uint8(A);
  1971. }
  1972. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1973. dest += step;
  1974. }
  1975. }
  1976. c->dither_error[0][i] = err[0];
  1977. c->dither_error[1][i] = err[1];
  1978. c->dither_error[2][i] = err[2];
  1979. }
  1980. #if CONFIG_SMALL
  1981. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1982. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1983. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1984. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1985. #else
  1986. #if CONFIG_SWSCALE_ALPHA
  1987. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1988. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1989. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1990. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1991. #endif
  1992. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1993. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1994. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1995. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1996. #endif
  1997. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1998. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1999. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  2000. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  2001. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  2002. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  2003. static void
  2004. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  2005. const int16_t **lumSrc, int lumFilterSize,
  2006. const int16_t *chrFilter, const int16_t **chrUSrc,
  2007. const int16_t **chrVSrc, int chrFilterSize,
  2008. const int16_t **alpSrc, uint8_t **dest,
  2009. int dstW, int y)
  2010. {
  2011. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2012. int i;
  2013. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  2014. uint16_t **dest16 = (uint16_t**)dest;
  2015. int SH = 22 + 8 - desc->comp[0].depth;
  2016. int A = 0; // init to silence warning
  2017. for (i = 0; i < dstW; i++) {
  2018. int j;
  2019. int Y = 1 << 9;
  2020. int U = (1 << 9) - (128 << 19);
  2021. int V = (1 << 9) - (128 << 19);
  2022. int R, G, B;
  2023. for (j = 0; j < lumFilterSize; j++)
  2024. Y += lumSrc[j][i] * lumFilter[j];
  2025. for (j = 0; j < chrFilterSize; j++) {
  2026. U += chrUSrc[j][i] * chrFilter[j];
  2027. V += chrVSrc[j][i] * chrFilter[j];
  2028. }
  2029. Y >>= 10;
  2030. U >>= 10;
  2031. V >>= 10;
  2032. if (hasAlpha) {
  2033. A = 1 << 18;
  2034. for (j = 0; j < lumFilterSize; j++)
  2035. A += alpSrc[j][i] * lumFilter[j];
  2036. if (A & 0xF8000000)
  2037. A = av_clip_uintp2(A, 27);
  2038. }
  2039. Y -= c->yuv2rgb_y_offset;
  2040. Y *= c->yuv2rgb_y_coeff;
  2041. Y += 1 << (SH-1);
  2042. R = Y + V * c->yuv2rgb_v2r_coeff;
  2043. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2044. B = Y + U * c->yuv2rgb_u2b_coeff;
  2045. if ((R | G | B) & 0xC0000000) {
  2046. R = av_clip_uintp2(R, 30);
  2047. G = av_clip_uintp2(G, 30);
  2048. B = av_clip_uintp2(B, 30);
  2049. }
  2050. if (SH != 22) {
  2051. dest16[0][i] = G >> SH;
  2052. dest16[1][i] = B >> SH;
  2053. dest16[2][i] = R >> SH;
  2054. if (hasAlpha)
  2055. dest16[3][i] = A >> (SH - 3);
  2056. } else {
  2057. dest[0][i] = G >> 22;
  2058. dest[1][i] = B >> 22;
  2059. dest[2][i] = R >> 22;
  2060. if (hasAlpha)
  2061. dest[3][i] = A >> 19;
  2062. }
  2063. }
  2064. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2065. for (i = 0; i < dstW; i++) {
  2066. dest16[0][i] = av_bswap16(dest16[0][i]);
  2067. dest16[1][i] = av_bswap16(dest16[1][i]);
  2068. dest16[2][i] = av_bswap16(dest16[2][i]);
  2069. if (hasAlpha)
  2070. dest16[3][i] = av_bswap16(dest16[3][i]);
  2071. }
  2072. }
  2073. }
  2074. static void
  2075. yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
  2076. const int16_t **lumSrcx, int lumFilterSize,
  2077. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2078. const int16_t **chrVSrcx, int chrFilterSize,
  2079. const int16_t **alpSrcx, uint8_t **dest,
  2080. int dstW, int y)
  2081. {
  2082. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2083. int i;
  2084. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2085. uint16_t **dest16 = (uint16_t**)dest;
  2086. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2087. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2088. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2089. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2090. for (i = 0; i < dstW; i++) {
  2091. int j;
  2092. int Y = -0x40000000;
  2093. int U = -(128 << 23);
  2094. int V = -(128 << 23);
  2095. int R, G, B, A;
  2096. for (j = 0; j < lumFilterSize; j++)
  2097. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2098. for (j = 0; j < chrFilterSize; j++) {
  2099. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2100. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2101. }
  2102. Y >>= 14;
  2103. Y += 0x10000;
  2104. U >>= 14;
  2105. V >>= 14;
  2106. if (hasAlpha) {
  2107. A = -0x40000000;
  2108. for (j = 0; j < lumFilterSize; j++)
  2109. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2110. A >>= 1;
  2111. A += 0x20002000;
  2112. }
  2113. Y -= c->yuv2rgb_y_offset;
  2114. Y *= c->yuv2rgb_y_coeff;
  2115. Y += (1 << 13) - (1 << 29);
  2116. R = V * c->yuv2rgb_v2r_coeff;
  2117. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2118. B = U * c->yuv2rgb_u2b_coeff;
  2119. dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2120. dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2121. dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2122. if (hasAlpha)
  2123. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  2124. }
  2125. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2126. for (i = 0; i < dstW; i++) {
  2127. dest16[0][i] = av_bswap16(dest16[0][i]);
  2128. dest16[1][i] = av_bswap16(dest16[1][i]);
  2129. dest16[2][i] = av_bswap16(dest16[2][i]);
  2130. if (hasAlpha)
  2131. dest16[3][i] = av_bswap16(dest16[3][i]);
  2132. }
  2133. }
  2134. }
  2135. static void
  2136. yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
  2137. const int16_t **lumSrcx, int lumFilterSize,
  2138. const int16_t *chrFilter, const int16_t **chrUSrcx,
  2139. const int16_t **chrVSrcx, int chrFilterSize,
  2140. const int16_t **alpSrcx, uint8_t **dest,
  2141. int dstW, int y)
  2142. {
  2143. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  2144. int i;
  2145. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  2146. uint32_t **dest32 = (uint32_t**)dest;
  2147. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  2148. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2149. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2150. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2151. static const float float_mult = 1.0f / 65535.0f;
  2152. for (i = 0; i < dstW; i++) {
  2153. int j;
  2154. int Y = -0x40000000;
  2155. int U = -(128 << 23);
  2156. int V = -(128 << 23);
  2157. int R, G, B, A;
  2158. for (j = 0; j < lumFilterSize; j++)
  2159. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2160. for (j = 0; j < chrFilterSize; j++) {
  2161. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2162. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2163. }
  2164. Y >>= 14;
  2165. Y += 0x10000;
  2166. U >>= 14;
  2167. V >>= 14;
  2168. if (hasAlpha) {
  2169. A = -0x40000000;
  2170. for (j = 0; j < lumFilterSize; j++)
  2171. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2172. A >>= 1;
  2173. A += 0x20002000;
  2174. }
  2175. Y -= c->yuv2rgb_y_offset;
  2176. Y *= c->yuv2rgb_y_coeff;
  2177. Y += (1 << 13) - (1 << 29);
  2178. R = V * c->yuv2rgb_v2r_coeff;
  2179. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2180. B = U * c->yuv2rgb_u2b_coeff;
  2181. R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
  2182. G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
  2183. B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
  2184. dest32[0][i] = av_float2int(float_mult * (float)G);
  2185. dest32[1][i] = av_float2int(float_mult * (float)B);
  2186. dest32[2][i] = av_float2int(float_mult * (float)R);
  2187. if (hasAlpha)
  2188. dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
  2189. }
  2190. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2191. for (i = 0; i < dstW; i++) {
  2192. dest32[0][i] = av_bswap32(dest32[0][i]);
  2193. dest32[1][i] = av_bswap32(dest32[1][i]);
  2194. dest32[2][i] = av_bswap32(dest32[2][i]);
  2195. if (hasAlpha)
  2196. dest32[3][i] = av_bswap32(dest32[3][i]);
  2197. }
  2198. }
  2199. }
  2200. static void
  2201. yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
  2202. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2203. const int16_t *abuf0, uint8_t *dest, int dstW,
  2204. int uvalpha, int y)
  2205. {
  2206. int hasAlpha = !!abuf0;
  2207. int i;
  2208. for (i = 0; i < dstW; i++) {
  2209. int Y = (buf0[i] + 64) >> 7;
  2210. int A;
  2211. Y = av_clip_uint8(Y);
  2212. if (hasAlpha) {
  2213. A = (abuf0[i] + 64) >> 7;
  2214. if (A & 0x100)
  2215. A = av_clip_uint8(A);
  2216. }
  2217. dest[i * 2 ] = Y;
  2218. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2219. }
  2220. }
  2221. static void
  2222. yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
  2223. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2224. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2225. int yalpha, int uvalpha, int y)
  2226. {
  2227. int hasAlpha = abuf && abuf[0] && abuf[1];
  2228. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2229. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2230. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2231. int yalpha1 = 4096 - yalpha;
  2232. int i;
  2233. av_assert2(yalpha <= 4096U);
  2234. for (i = 0; i < dstW; i++) {
  2235. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2236. int A;
  2237. Y = av_clip_uint8(Y);
  2238. if (hasAlpha) {
  2239. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2240. A = av_clip_uint8(A);
  2241. }
  2242. dest[i * 2 ] = Y;
  2243. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2244. }
  2245. }
  2246. static void
  2247. yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
  2248. const int16_t **lumSrc, int lumFilterSize,
  2249. const int16_t *chrFilter, const int16_t **chrUSrc,
  2250. const int16_t **chrVSrc, int chrFilterSize,
  2251. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2252. {
  2253. int hasAlpha = !!alpSrc;
  2254. int i;
  2255. for (i = 0; i < dstW; i++) {
  2256. int j;
  2257. int Y = 1 << 18, A = 1 << 18;
  2258. for (j = 0; j < lumFilterSize; j++)
  2259. Y += lumSrc[j][i] * lumFilter[j];
  2260. Y >>= 19;
  2261. if (Y & 0x100)
  2262. Y = av_clip_uint8(Y);
  2263. if (hasAlpha) {
  2264. for (j = 0; j < lumFilterSize; j++)
  2265. A += alpSrc[j][i] * lumFilter[j];
  2266. A >>= 19;
  2267. if (A & 0x100)
  2268. A = av_clip_uint8(A);
  2269. }
  2270. dest[2 * i ] = Y;
  2271. dest[2 * i + 1] = hasAlpha ? A : 255;
  2272. }
  2273. }
  2274. static void
  2275. yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
  2276. const int16_t **_lumSrc, int lumFilterSize,
  2277. const int16_t *chrFilter, const int16_t **_chrUSrc,
  2278. const int16_t **_chrVSrc, int chrFilterSize,
  2279. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
  2280. {
  2281. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  2282. **chrUSrc = (const int32_t **) _chrUSrc,
  2283. **chrVSrc = (const int32_t **) _chrVSrc,
  2284. **alpSrc = (const int32_t **) _alpSrc;
  2285. int hasAlpha = !!alpSrc;
  2286. int i;
  2287. for (i = 0; i < dstW; i++) {
  2288. int Y = 1 << 14, U = 1 << 14;
  2289. int V = 1 << 14, A = 1 << 14;
  2290. int j;
  2291. Y -= 0x40000000;
  2292. U -= 0x40000000;
  2293. V -= 0x40000000;
  2294. A -= 0x40000000;
  2295. for (j = 0; j < lumFilterSize; j++)
  2296. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2297. for (j = 0; j < chrFilterSize; j++)
  2298. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2299. for (j = 0; j < chrFilterSize; j++)
  2300. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2301. if (hasAlpha)
  2302. for (j = 0; j < lumFilterSize; j++)
  2303. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2304. Y = 0x8000 + av_clip_int16(Y >> 15);
  2305. U = 0x8000 + av_clip_int16(U >> 15);
  2306. V = 0x8000 + av_clip_int16(V >> 15);
  2307. A = 0x8000 + av_clip_int16(A >> 15);
  2308. AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
  2309. AV_WL16(dest + 8 * i + 2, Y);
  2310. AV_WL16(dest + 8 * i + 4, U);
  2311. AV_WL16(dest + 8 * i + 6, V);
  2312. }
  2313. }
  2314. static void
  2315. yuv2xv30le_X_c(SwsContext *c, const int16_t *lumFilter,
  2316. const int16_t **lumSrc, int lumFilterSize,
  2317. const int16_t *chrFilter, const int16_t **chrUSrc,
  2318. const int16_t **chrVSrc, int chrFilterSize,
  2319. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2320. {
  2321. int i;
  2322. for (i = 0; i < dstW; i++) {
  2323. int Y = 1 << 16, U = 1 << 16, V = 1 << 16;
  2324. int j;
  2325. for (j = 0; j < lumFilterSize; j++)
  2326. Y += lumSrc[j][i] * lumFilter[j];
  2327. for (j = 0; j < chrFilterSize; j++) {
  2328. U += chrUSrc[j][i] * chrFilter[j];
  2329. V += chrVSrc[j][i] * chrFilter[j];
  2330. }
  2331. Y = av_clip_uintp2(Y >> 17, 10);
  2332. U = av_clip_uintp2(U >> 17, 10);
  2333. V = av_clip_uintp2(V >> 17, 10);
  2334. AV_WL32(dest + 4 * i, U | Y << 10 | V << 20);
  2335. }
  2336. }
  2337. static void
  2338. yuv2xv36le_X_c(SwsContext *c, const int16_t *lumFilter,
  2339. const int16_t **lumSrc, int lumFilterSize,
  2340. const int16_t *chrFilter, const int16_t **chrUSrc,
  2341. const int16_t **chrVSrc, int chrFilterSize,
  2342. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2343. {
  2344. int i;
  2345. for (i = 0; i < dstW; i++) {
  2346. int Y = 1 << 14, U = 1 << 14, V = 1 << 14;
  2347. int j;
  2348. for (j = 0; j < lumFilterSize; j++)
  2349. Y += lumSrc[j][i] * lumFilter[j];
  2350. for (j = 0; j < chrFilterSize; j++) {
  2351. U += chrUSrc[j][i] * chrFilter[j];
  2352. V += chrVSrc[j][i] * chrFilter[j];
  2353. }
  2354. AV_WL16(dest + 8 * i + 2, av_clip_uintp2(Y >> 15, 12) << 4);
  2355. AV_WL16(dest + 8 * i + 0, av_clip_uintp2(U >> 15, 12) << 4);
  2356. AV_WL16(dest + 8 * i + 4, av_clip_uintp2(V >> 15, 12) << 4);
  2357. }
  2358. }
  2359. static void
  2360. yuv2vuyX_X_c(SwsContext *c, const int16_t *lumFilter,
  2361. const int16_t **lumSrc, int lumFilterSize,
  2362. const int16_t *chrFilter, const int16_t **chrUSrc,
  2363. const int16_t **chrVSrc, int chrFilterSize,
  2364. const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
  2365. int destHasAlpha)
  2366. {
  2367. int hasAlpha = destHasAlpha && (!!alpSrc);
  2368. int i;
  2369. for (i = 0; i < dstW; i++) {
  2370. int j;
  2371. int Y = 1 << 18, U = 1 << 18;
  2372. int V = 1 << 18, A = 255;
  2373. for (j = 0; j < lumFilterSize; j++)
  2374. Y += lumSrc[j][i] * lumFilter[j];
  2375. for (j = 0; j < chrFilterSize; j++)
  2376. U += chrUSrc[j][i] * chrFilter[j];
  2377. for (j = 0; j < chrFilterSize; j++)
  2378. V += chrVSrc[j][i] * chrFilter[j];
  2379. Y >>= 19;
  2380. U >>= 19;
  2381. V >>= 19;
  2382. if (Y & 0x100)
  2383. Y = av_clip_uint8(Y);
  2384. if (U & 0x100)
  2385. U = av_clip_uint8(U);
  2386. if (V & 0x100)
  2387. V = av_clip_uint8(V);
  2388. if (hasAlpha) {
  2389. A = 1 << 18;
  2390. for (j = 0; j < lumFilterSize; j++)
  2391. A += alpSrc[j][i] * lumFilter[j];
  2392. A >>= 19;
  2393. if (A & 0x100)
  2394. A = av_clip_uint8(A);
  2395. }
  2396. dest[4 * i ] = V;
  2397. dest[4 * i + 1] = U;
  2398. dest[4 * i + 2] = Y;
  2399. if (destHasAlpha)
  2400. dest[4 * i + 3] = A;
  2401. }
  2402. }
  2403. static void
  2404. yuv2vuya_X_c(SwsContext *c, const int16_t *lumFilter,
  2405. const int16_t **lumSrc, int lumFilterSize,
  2406. const int16_t *chrFilter, const int16_t **chrUSrc,
  2407. const int16_t **chrVSrc, int chrFilterSize,
  2408. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2409. {
  2410. yuv2vuyX_X_c(c, lumFilter, lumSrc, lumFilterSize, chrFilter,
  2411. chrUSrc, chrVSrc, chrFilterSize, alpSrc, dest, dstW, y, 1);
  2412. }
  2413. static void
  2414. yuv2vuyx_X_c(SwsContext *c, const int16_t *lumFilter,
  2415. const int16_t **lumSrc, int lumFilterSize,
  2416. const int16_t *chrFilter, const int16_t **chrUSrc,
  2417. const int16_t **chrVSrc, int chrFilterSize,
  2418. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2419. {
  2420. yuv2vuyX_X_c(c, lumFilter, lumSrc, lumFilterSize, chrFilter,
  2421. chrUSrc, chrVSrc, chrFilterSize, alpSrc, dest, dstW, y, 0);
  2422. }
  2423. #define output_pixel(pos, val, bits) \
  2424. AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
  2425. #define yuv2y2xx_wrapper(bits) \
  2426. static void \
  2427. yuv2y2 ## bits ## le_X_c(SwsContext *c, const int16_t *lumFilter, \
  2428. const int16_t **lumSrc, int lumFilterSize, \
  2429. const int16_t *chrFilter, \
  2430. const int16_t **chrUSrc, \
  2431. const int16_t **chrVSrc, int chrFilterSize, \
  2432. const int16_t **alpSrc, \
  2433. uint8_t *dest, int dstW, int y) \
  2434. { \
  2435. int i, j; \
  2436. int shift = 11 + 16 - bits; \
  2437. int output_shift = 16 - bits; \
  2438. for (i = 0; i < ((dstW + 1) >> 1); i++) { \
  2439. int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1); \
  2440. int U = 1 << (shift - 1), V = 1 << (shift - 1); \
  2441. \
  2442. for (j = 0; j < lumFilterSize; j++) { \
  2443. Y1 += lumSrc[j][i * 2] * lumFilter[j]; \
  2444. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; \
  2445. } \
  2446. \
  2447. for (j = 0; j < chrFilterSize; j++) { \
  2448. U += chrUSrc[j][i] * chrFilter[j]; \
  2449. V += chrVSrc[j][i] * chrFilter[j]; \
  2450. } \
  2451. \
  2452. output_pixel(dest + 8 * i + 0, Y1, bits); \
  2453. output_pixel(dest + 8 * i + 2, U, bits); \
  2454. output_pixel(dest + 8 * i + 4, Y2, bits); \
  2455. output_pixel(dest + 8 * i + 6, V, bits); \
  2456. } \
  2457. }
  2458. yuv2y2xx_wrapper(10)
  2459. yuv2y2xx_wrapper(12)
  2460. #undef output_pixel
  2461. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  2462. yuv2planar1_fn *yuv2plane1,
  2463. yuv2planarX_fn *yuv2planeX,
  2464. yuv2interleavedX_fn *yuv2nv12cX,
  2465. yuv2packed1_fn *yuv2packed1,
  2466. yuv2packed2_fn *yuv2packed2,
  2467. yuv2packedX_fn *yuv2packedX,
  2468. yuv2anyX_fn *yuv2anyX)
  2469. {
  2470. enum AVPixelFormat dstFormat = c->dstFormat;
  2471. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  2472. if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) {
  2473. if (desc->comp[0].depth == 10) {
  2474. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  2475. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  2476. *yuv2nv12cX = isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
  2477. } else if (desc->comp[0].depth == 12) {
  2478. *yuv2plane1 = isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
  2479. *yuv2planeX = isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
  2480. *yuv2nv12cX = isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
  2481. } else
  2482. av_assert0(0);
  2483. } else if (is16BPS(dstFormat)) {
  2484. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2485. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2486. if (isSemiPlanarYUV(dstFormat)) {
  2487. *yuv2nv12cX = isBE(dstFormat) ? yuv2nv12cX_16BE_c : yuv2nv12cX_16LE_c;
  2488. }
  2489. } else if (isNBPS(dstFormat)) {
  2490. if (desc->comp[0].depth == 9) {
  2491. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2492. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2493. } else if (desc->comp[0].depth == 10) {
  2494. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2495. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2496. } else if (desc->comp[0].depth == 12) {
  2497. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2498. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2499. } else if (desc->comp[0].depth == 14) {
  2500. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2501. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2502. } else
  2503. av_assert0(0);
  2504. } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
  2505. *yuv2planeX = yuv2planeX_floatBE_c;
  2506. *yuv2plane1 = yuv2plane1_floatBE_c;
  2507. } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
  2508. *yuv2planeX = yuv2planeX_floatLE_c;
  2509. *yuv2plane1 = yuv2plane1_floatLE_c;
  2510. } else {
  2511. *yuv2plane1 = yuv2plane1_8_c;
  2512. *yuv2planeX = yuv2planeX_8_c;
  2513. if (isSemiPlanarYUV(dstFormat))
  2514. *yuv2nv12cX = yuv2nv12cX_c;
  2515. }
  2516. if(c->flags & SWS_FULL_CHR_H_INT) {
  2517. switch (dstFormat) {
  2518. case AV_PIX_FMT_RGBA:
  2519. #if CONFIG_SMALL
  2520. *yuv2packedX = yuv2rgba32_full_X_c;
  2521. *yuv2packed2 = yuv2rgba32_full_2_c;
  2522. *yuv2packed1 = yuv2rgba32_full_1_c;
  2523. #else
  2524. #if CONFIG_SWSCALE_ALPHA
  2525. if (c->needAlpha) {
  2526. *yuv2packedX = yuv2rgba32_full_X_c;
  2527. *yuv2packed2 = yuv2rgba32_full_2_c;
  2528. *yuv2packed1 = yuv2rgba32_full_1_c;
  2529. } else
  2530. #endif /* CONFIG_SWSCALE_ALPHA */
  2531. {
  2532. *yuv2packedX = yuv2rgbx32_full_X_c;
  2533. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2534. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2535. }
  2536. #endif /* !CONFIG_SMALL */
  2537. break;
  2538. case AV_PIX_FMT_ARGB:
  2539. #if CONFIG_SMALL
  2540. *yuv2packedX = yuv2argb32_full_X_c;
  2541. *yuv2packed2 = yuv2argb32_full_2_c;
  2542. *yuv2packed1 = yuv2argb32_full_1_c;
  2543. #else
  2544. #if CONFIG_SWSCALE_ALPHA
  2545. if (c->needAlpha) {
  2546. *yuv2packedX = yuv2argb32_full_X_c;
  2547. *yuv2packed2 = yuv2argb32_full_2_c;
  2548. *yuv2packed1 = yuv2argb32_full_1_c;
  2549. } else
  2550. #endif /* CONFIG_SWSCALE_ALPHA */
  2551. {
  2552. *yuv2packedX = yuv2xrgb32_full_X_c;
  2553. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2554. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2555. }
  2556. #endif /* !CONFIG_SMALL */
  2557. break;
  2558. case AV_PIX_FMT_BGRA:
  2559. #if CONFIG_SMALL
  2560. *yuv2packedX = yuv2bgra32_full_X_c;
  2561. *yuv2packed2 = yuv2bgra32_full_2_c;
  2562. *yuv2packed1 = yuv2bgra32_full_1_c;
  2563. #else
  2564. #if CONFIG_SWSCALE_ALPHA
  2565. if (c->needAlpha) {
  2566. *yuv2packedX = yuv2bgra32_full_X_c;
  2567. *yuv2packed2 = yuv2bgra32_full_2_c;
  2568. *yuv2packed1 = yuv2bgra32_full_1_c;
  2569. } else
  2570. #endif /* CONFIG_SWSCALE_ALPHA */
  2571. {
  2572. *yuv2packedX = yuv2bgrx32_full_X_c;
  2573. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2574. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2575. }
  2576. #endif /* !CONFIG_SMALL */
  2577. break;
  2578. case AV_PIX_FMT_ABGR:
  2579. #if CONFIG_SMALL
  2580. *yuv2packedX = yuv2abgr32_full_X_c;
  2581. *yuv2packed2 = yuv2abgr32_full_2_c;
  2582. *yuv2packed1 = yuv2abgr32_full_1_c;
  2583. #else
  2584. #if CONFIG_SWSCALE_ALPHA
  2585. if (c->needAlpha) {
  2586. *yuv2packedX = yuv2abgr32_full_X_c;
  2587. *yuv2packed2 = yuv2abgr32_full_2_c;
  2588. *yuv2packed1 = yuv2abgr32_full_1_c;
  2589. } else
  2590. #endif /* CONFIG_SWSCALE_ALPHA */
  2591. {
  2592. *yuv2packedX = yuv2xbgr32_full_X_c;
  2593. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2594. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2595. }
  2596. #endif /* !CONFIG_SMALL */
  2597. break;
  2598. case AV_PIX_FMT_RGBA64LE:
  2599. #if CONFIG_SWSCALE_ALPHA
  2600. if (c->needAlpha) {
  2601. *yuv2packedX = yuv2rgba64le_full_X_c;
  2602. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2603. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2604. } else
  2605. #endif /* CONFIG_SWSCALE_ALPHA */
  2606. {
  2607. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2608. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2609. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2610. }
  2611. break;
  2612. case AV_PIX_FMT_RGBA64BE:
  2613. #if CONFIG_SWSCALE_ALPHA
  2614. if (c->needAlpha) {
  2615. *yuv2packedX = yuv2rgba64be_full_X_c;
  2616. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2617. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2618. } else
  2619. #endif /* CONFIG_SWSCALE_ALPHA */
  2620. {
  2621. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2622. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2623. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2624. }
  2625. break;
  2626. case AV_PIX_FMT_BGRA64LE:
  2627. #if CONFIG_SWSCALE_ALPHA
  2628. if (c->needAlpha) {
  2629. *yuv2packedX = yuv2bgra64le_full_X_c;
  2630. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2631. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2632. } else
  2633. #endif /* CONFIG_SWSCALE_ALPHA */
  2634. {
  2635. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2636. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2637. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2638. }
  2639. break;
  2640. case AV_PIX_FMT_BGRA64BE:
  2641. #if CONFIG_SWSCALE_ALPHA
  2642. if (c->needAlpha) {
  2643. *yuv2packedX = yuv2bgra64be_full_X_c;
  2644. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2645. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2646. } else
  2647. #endif /* CONFIG_SWSCALE_ALPHA */
  2648. {
  2649. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2650. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2651. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2652. }
  2653. break;
  2654. case AV_PIX_FMT_RGB24:
  2655. *yuv2packedX = yuv2rgb24_full_X_c;
  2656. *yuv2packed2 = yuv2rgb24_full_2_c;
  2657. *yuv2packed1 = yuv2rgb24_full_1_c;
  2658. break;
  2659. case AV_PIX_FMT_BGR24:
  2660. *yuv2packedX = yuv2bgr24_full_X_c;
  2661. *yuv2packed2 = yuv2bgr24_full_2_c;
  2662. *yuv2packed1 = yuv2bgr24_full_1_c;
  2663. break;
  2664. case AV_PIX_FMT_RGB48LE:
  2665. *yuv2packedX = yuv2rgb48le_full_X_c;
  2666. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2667. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2668. break;
  2669. case AV_PIX_FMT_BGR48LE:
  2670. *yuv2packedX = yuv2bgr48le_full_X_c;
  2671. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2672. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2673. break;
  2674. case AV_PIX_FMT_RGB48BE:
  2675. *yuv2packedX = yuv2rgb48be_full_X_c;
  2676. *yuv2packed2 = yuv2rgb48be_full_2_c;
  2677. *yuv2packed1 = yuv2rgb48be_full_1_c;
  2678. break;
  2679. case AV_PIX_FMT_BGR48BE:
  2680. *yuv2packedX = yuv2bgr48be_full_X_c;
  2681. *yuv2packed2 = yuv2bgr48be_full_2_c;
  2682. *yuv2packed1 = yuv2bgr48be_full_1_c;
  2683. break;
  2684. case AV_PIX_FMT_BGR4_BYTE:
  2685. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  2686. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  2687. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  2688. break;
  2689. case AV_PIX_FMT_RGB4_BYTE:
  2690. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  2691. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  2692. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  2693. break;
  2694. case AV_PIX_FMT_BGR8:
  2695. *yuv2packedX = yuv2bgr8_full_X_c;
  2696. *yuv2packed2 = yuv2bgr8_full_2_c;
  2697. *yuv2packed1 = yuv2bgr8_full_1_c;
  2698. break;
  2699. case AV_PIX_FMT_RGB8:
  2700. *yuv2packedX = yuv2rgb8_full_X_c;
  2701. *yuv2packed2 = yuv2rgb8_full_2_c;
  2702. *yuv2packed1 = yuv2rgb8_full_1_c;
  2703. break;
  2704. case AV_PIX_FMT_GBRP:
  2705. case AV_PIX_FMT_GBRP9BE:
  2706. case AV_PIX_FMT_GBRP9LE:
  2707. case AV_PIX_FMT_GBRP10BE:
  2708. case AV_PIX_FMT_GBRP10LE:
  2709. case AV_PIX_FMT_GBRP12BE:
  2710. case AV_PIX_FMT_GBRP12LE:
  2711. case AV_PIX_FMT_GBRP14BE:
  2712. case AV_PIX_FMT_GBRP14LE:
  2713. case AV_PIX_FMT_GBRAP:
  2714. case AV_PIX_FMT_GBRAP10BE:
  2715. case AV_PIX_FMT_GBRAP10LE:
  2716. case AV_PIX_FMT_GBRAP12BE:
  2717. case AV_PIX_FMT_GBRAP12LE:
  2718. case AV_PIX_FMT_GBRAP14BE:
  2719. case AV_PIX_FMT_GBRAP14LE:
  2720. *yuv2anyX = yuv2gbrp_full_X_c;
  2721. break;
  2722. case AV_PIX_FMT_GBRP16BE:
  2723. case AV_PIX_FMT_GBRP16LE:
  2724. case AV_PIX_FMT_GBRAP16BE:
  2725. case AV_PIX_FMT_GBRAP16LE:
  2726. *yuv2anyX = yuv2gbrp16_full_X_c;
  2727. break;
  2728. case AV_PIX_FMT_GBRPF32BE:
  2729. case AV_PIX_FMT_GBRPF32LE:
  2730. case AV_PIX_FMT_GBRAPF32BE:
  2731. case AV_PIX_FMT_GBRAPF32LE:
  2732. *yuv2anyX = yuv2gbrpf32_full_X_c;
  2733. break;
  2734. }
  2735. if (!*yuv2packedX && !*yuv2anyX)
  2736. goto YUV_PACKED;
  2737. } else {
  2738. YUV_PACKED:
  2739. switch (dstFormat) {
  2740. case AV_PIX_FMT_RGBA64LE:
  2741. #if CONFIG_SWSCALE_ALPHA
  2742. if (c->needAlpha) {
  2743. *yuv2packed1 = yuv2rgba64le_1_c;
  2744. *yuv2packed2 = yuv2rgba64le_2_c;
  2745. *yuv2packedX = yuv2rgba64le_X_c;
  2746. } else
  2747. #endif /* CONFIG_SWSCALE_ALPHA */
  2748. {
  2749. *yuv2packed1 = yuv2rgbx64le_1_c;
  2750. *yuv2packed2 = yuv2rgbx64le_2_c;
  2751. *yuv2packedX = yuv2rgbx64le_X_c;
  2752. }
  2753. break;
  2754. case AV_PIX_FMT_RGBA64BE:
  2755. #if CONFIG_SWSCALE_ALPHA
  2756. if (c->needAlpha) {
  2757. *yuv2packed1 = yuv2rgba64be_1_c;
  2758. *yuv2packed2 = yuv2rgba64be_2_c;
  2759. *yuv2packedX = yuv2rgba64be_X_c;
  2760. } else
  2761. #endif /* CONFIG_SWSCALE_ALPHA */
  2762. {
  2763. *yuv2packed1 = yuv2rgbx64be_1_c;
  2764. *yuv2packed2 = yuv2rgbx64be_2_c;
  2765. *yuv2packedX = yuv2rgbx64be_X_c;
  2766. }
  2767. break;
  2768. case AV_PIX_FMT_BGRA64LE:
  2769. #if CONFIG_SWSCALE_ALPHA
  2770. if (c->needAlpha) {
  2771. *yuv2packed1 = yuv2bgra64le_1_c;
  2772. *yuv2packed2 = yuv2bgra64le_2_c;
  2773. *yuv2packedX = yuv2bgra64le_X_c;
  2774. } else
  2775. #endif /* CONFIG_SWSCALE_ALPHA */
  2776. {
  2777. *yuv2packed1 = yuv2bgrx64le_1_c;
  2778. *yuv2packed2 = yuv2bgrx64le_2_c;
  2779. *yuv2packedX = yuv2bgrx64le_X_c;
  2780. }
  2781. break;
  2782. case AV_PIX_FMT_BGRA64BE:
  2783. #if CONFIG_SWSCALE_ALPHA
  2784. if (c->needAlpha) {
  2785. *yuv2packed1 = yuv2bgra64be_1_c;
  2786. *yuv2packed2 = yuv2bgra64be_2_c;
  2787. *yuv2packedX = yuv2bgra64be_X_c;
  2788. } else
  2789. #endif /* CONFIG_SWSCALE_ALPHA */
  2790. {
  2791. *yuv2packed1 = yuv2bgrx64be_1_c;
  2792. *yuv2packed2 = yuv2bgrx64be_2_c;
  2793. *yuv2packedX = yuv2bgrx64be_X_c;
  2794. }
  2795. break;
  2796. case AV_PIX_FMT_RGB48LE:
  2797. *yuv2packed1 = yuv2rgb48le_1_c;
  2798. *yuv2packed2 = yuv2rgb48le_2_c;
  2799. *yuv2packedX = yuv2rgb48le_X_c;
  2800. break;
  2801. case AV_PIX_FMT_RGB48BE:
  2802. *yuv2packed1 = yuv2rgb48be_1_c;
  2803. *yuv2packed2 = yuv2rgb48be_2_c;
  2804. *yuv2packedX = yuv2rgb48be_X_c;
  2805. break;
  2806. case AV_PIX_FMT_BGR48LE:
  2807. *yuv2packed1 = yuv2bgr48le_1_c;
  2808. *yuv2packed2 = yuv2bgr48le_2_c;
  2809. *yuv2packedX = yuv2bgr48le_X_c;
  2810. break;
  2811. case AV_PIX_FMT_BGR48BE:
  2812. *yuv2packed1 = yuv2bgr48be_1_c;
  2813. *yuv2packed2 = yuv2bgr48be_2_c;
  2814. *yuv2packedX = yuv2bgr48be_X_c;
  2815. break;
  2816. case AV_PIX_FMT_RGB32:
  2817. case AV_PIX_FMT_BGR32:
  2818. #if CONFIG_SMALL
  2819. *yuv2packed1 = yuv2rgb32_1_c;
  2820. *yuv2packed2 = yuv2rgb32_2_c;
  2821. *yuv2packedX = yuv2rgb32_X_c;
  2822. #else
  2823. #if CONFIG_SWSCALE_ALPHA
  2824. if (c->needAlpha) {
  2825. *yuv2packed1 = yuv2rgba32_1_c;
  2826. *yuv2packed2 = yuv2rgba32_2_c;
  2827. *yuv2packedX = yuv2rgba32_X_c;
  2828. } else
  2829. #endif /* CONFIG_SWSCALE_ALPHA */
  2830. {
  2831. *yuv2packed1 = yuv2rgbx32_1_c;
  2832. *yuv2packed2 = yuv2rgbx32_2_c;
  2833. *yuv2packedX = yuv2rgbx32_X_c;
  2834. }
  2835. #endif /* !CONFIG_SMALL */
  2836. break;
  2837. case AV_PIX_FMT_RGB32_1:
  2838. case AV_PIX_FMT_BGR32_1:
  2839. #if CONFIG_SMALL
  2840. *yuv2packed1 = yuv2rgb32_1_1_c;
  2841. *yuv2packed2 = yuv2rgb32_1_2_c;
  2842. *yuv2packedX = yuv2rgb32_1_X_c;
  2843. #else
  2844. #if CONFIG_SWSCALE_ALPHA
  2845. if (c->needAlpha) {
  2846. *yuv2packed1 = yuv2rgba32_1_1_c;
  2847. *yuv2packed2 = yuv2rgba32_1_2_c;
  2848. *yuv2packedX = yuv2rgba32_1_X_c;
  2849. } else
  2850. #endif /* CONFIG_SWSCALE_ALPHA */
  2851. {
  2852. *yuv2packed1 = yuv2rgbx32_1_1_c;
  2853. *yuv2packed2 = yuv2rgbx32_1_2_c;
  2854. *yuv2packedX = yuv2rgbx32_1_X_c;
  2855. }
  2856. #endif /* !CONFIG_SMALL */
  2857. break;
  2858. case AV_PIX_FMT_RGB24:
  2859. *yuv2packed1 = yuv2rgb24_1_c;
  2860. *yuv2packed2 = yuv2rgb24_2_c;
  2861. *yuv2packedX = yuv2rgb24_X_c;
  2862. break;
  2863. case AV_PIX_FMT_BGR24:
  2864. *yuv2packed1 = yuv2bgr24_1_c;
  2865. *yuv2packed2 = yuv2bgr24_2_c;
  2866. *yuv2packedX = yuv2bgr24_X_c;
  2867. break;
  2868. case AV_PIX_FMT_RGB565LE:
  2869. case AV_PIX_FMT_RGB565BE:
  2870. case AV_PIX_FMT_BGR565LE:
  2871. case AV_PIX_FMT_BGR565BE:
  2872. *yuv2packed1 = yuv2rgb16_1_c;
  2873. *yuv2packed2 = yuv2rgb16_2_c;
  2874. *yuv2packedX = yuv2rgb16_X_c;
  2875. break;
  2876. case AV_PIX_FMT_RGB555LE:
  2877. case AV_PIX_FMT_RGB555BE:
  2878. case AV_PIX_FMT_BGR555LE:
  2879. case AV_PIX_FMT_BGR555BE:
  2880. *yuv2packed1 = yuv2rgb15_1_c;
  2881. *yuv2packed2 = yuv2rgb15_2_c;
  2882. *yuv2packedX = yuv2rgb15_X_c;
  2883. break;
  2884. case AV_PIX_FMT_RGB444LE:
  2885. case AV_PIX_FMT_RGB444BE:
  2886. case AV_PIX_FMT_BGR444LE:
  2887. case AV_PIX_FMT_BGR444BE:
  2888. *yuv2packed1 = yuv2rgb12_1_c;
  2889. *yuv2packed2 = yuv2rgb12_2_c;
  2890. *yuv2packedX = yuv2rgb12_X_c;
  2891. break;
  2892. case AV_PIX_FMT_RGB8:
  2893. case AV_PIX_FMT_BGR8:
  2894. *yuv2packed1 = yuv2rgb8_1_c;
  2895. *yuv2packed2 = yuv2rgb8_2_c;
  2896. *yuv2packedX = yuv2rgb8_X_c;
  2897. break;
  2898. case AV_PIX_FMT_RGB4:
  2899. case AV_PIX_FMT_BGR4:
  2900. *yuv2packed1 = yuv2rgb4_1_c;
  2901. *yuv2packed2 = yuv2rgb4_2_c;
  2902. *yuv2packedX = yuv2rgb4_X_c;
  2903. break;
  2904. case AV_PIX_FMT_RGB4_BYTE:
  2905. case AV_PIX_FMT_BGR4_BYTE:
  2906. *yuv2packed1 = yuv2rgb4b_1_c;
  2907. *yuv2packed2 = yuv2rgb4b_2_c;
  2908. *yuv2packedX = yuv2rgb4b_X_c;
  2909. break;
  2910. case AV_PIX_FMT_X2RGB10LE:
  2911. case AV_PIX_FMT_X2RGB10BE:
  2912. *yuv2packed1 = yuv2x2rgb10_1_c;
  2913. *yuv2packed2 = yuv2x2rgb10_2_c;
  2914. *yuv2packedX = yuv2x2rgb10_X_c;
  2915. break;
  2916. case AV_PIX_FMT_X2BGR10LE:
  2917. case AV_PIX_FMT_X2BGR10BE:
  2918. *yuv2packed1 = yuv2x2bgr10_1_c;
  2919. *yuv2packed2 = yuv2x2bgr10_2_c;
  2920. *yuv2packedX = yuv2x2bgr10_X_c;
  2921. break;
  2922. }
  2923. }
  2924. switch (dstFormat) {
  2925. case AV_PIX_FMT_MONOWHITE:
  2926. *yuv2packed1 = yuv2monowhite_1_c;
  2927. *yuv2packed2 = yuv2monowhite_2_c;
  2928. *yuv2packedX = yuv2monowhite_X_c;
  2929. break;
  2930. case AV_PIX_FMT_MONOBLACK:
  2931. *yuv2packed1 = yuv2monoblack_1_c;
  2932. *yuv2packed2 = yuv2monoblack_2_c;
  2933. *yuv2packedX = yuv2monoblack_X_c;
  2934. break;
  2935. case AV_PIX_FMT_YUYV422:
  2936. *yuv2packed1 = yuv2yuyv422_1_c;
  2937. *yuv2packed2 = yuv2yuyv422_2_c;
  2938. *yuv2packedX = yuv2yuyv422_X_c;
  2939. break;
  2940. case AV_PIX_FMT_YVYU422:
  2941. *yuv2packed1 = yuv2yvyu422_1_c;
  2942. *yuv2packed2 = yuv2yvyu422_2_c;
  2943. *yuv2packedX = yuv2yvyu422_X_c;
  2944. break;
  2945. case AV_PIX_FMT_UYVY422:
  2946. *yuv2packed1 = yuv2uyvy422_1_c;
  2947. *yuv2packed2 = yuv2uyvy422_2_c;
  2948. *yuv2packedX = yuv2uyvy422_X_c;
  2949. break;
  2950. case AV_PIX_FMT_YA8:
  2951. *yuv2packed1 = yuv2ya8_1_c;
  2952. *yuv2packed2 = yuv2ya8_2_c;
  2953. *yuv2packedX = yuv2ya8_X_c;
  2954. break;
  2955. case AV_PIX_FMT_YA16LE:
  2956. *yuv2packed1 = yuv2ya16le_1_c;
  2957. *yuv2packed2 = yuv2ya16le_2_c;
  2958. *yuv2packedX = yuv2ya16le_X_c;
  2959. break;
  2960. case AV_PIX_FMT_YA16BE:
  2961. *yuv2packed1 = yuv2ya16be_1_c;
  2962. *yuv2packed2 = yuv2ya16be_2_c;
  2963. *yuv2packedX = yuv2ya16be_X_c;
  2964. break;
  2965. case AV_PIX_FMT_AYUV64LE:
  2966. *yuv2packedX = yuv2ayuv64le_X_c;
  2967. break;
  2968. case AV_PIX_FMT_VUYA:
  2969. *yuv2packedX = yuv2vuya_X_c;
  2970. break;
  2971. case AV_PIX_FMT_VUYX:
  2972. *yuv2packedX = yuv2vuyx_X_c;
  2973. break;
  2974. case AV_PIX_FMT_XV30LE:
  2975. *yuv2packedX = yuv2xv30le_X_c;
  2976. break;
  2977. case AV_PIX_FMT_XV36LE:
  2978. *yuv2packedX = yuv2xv36le_X_c;
  2979. break;
  2980. case AV_PIX_FMT_Y210LE:
  2981. *yuv2packedX = yuv2y210le_X_c;
  2982. break;
  2983. case AV_PIX_FMT_Y212LE:
  2984. *yuv2packedX = yuv2y212le_X_c;
  2985. break;
  2986. }
  2987. }