output.c 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706
  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/cpu.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/mathematics.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 output_pixel(pos, val, bias, signedness) \
  128. if (big_endian) { \
  129. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  130. } else { \
  131. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  132. }
  133. static av_always_inline void
  134. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  135. int big_endian, int output_bits)
  136. {
  137. int i;
  138. int shift = 3;
  139. av_assert0(output_bits == 16);
  140. for (i = 0; i < dstW; i++) {
  141. int val = src[i] + (1 << (shift - 1));
  142. output_pixel(&dest[i], val, 0, uint);
  143. }
  144. }
  145. static av_always_inline void
  146. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  147. const int32_t **src, uint16_t *dest, int dstW,
  148. int big_endian, int output_bits)
  149. {
  150. int i;
  151. int shift = 15;
  152. av_assert0(output_bits == 16);
  153. for (i = 0; i < dstW; i++) {
  154. int val = 1 << (shift - 1);
  155. int j;
  156. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  157. * filters (or anything with negative coeffs, the range can be slightly
  158. * wider in both directions. To account for this overflow, we subtract
  159. * a constant so it always fits in the signed range (assuming a
  160. * reasonable filterSize), and re-add that at the end. */
  161. val -= 0x40000000;
  162. for (j = 0; j < filterSize; j++)
  163. val += src[j][i] * (unsigned)filter[j];
  164. output_pixel(&dest[i], val, 0x8000, int);
  165. }
  166. }
  167. #undef output_pixel
  168. #define output_pixel(pos, val) \
  169. if (big_endian) { \
  170. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  171. } else { \
  172. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  173. }
  174. static av_always_inline void
  175. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  176. int big_endian, int output_bits)
  177. {
  178. int i;
  179. int shift = 15 - output_bits;
  180. for (i = 0; i < dstW; i++) {
  181. int val = src[i] + (1 << (shift - 1));
  182. output_pixel(&dest[i], val);
  183. }
  184. }
  185. static av_always_inline void
  186. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  187. const int16_t **src, uint16_t *dest, int dstW,
  188. int big_endian, int output_bits)
  189. {
  190. int i;
  191. int shift = 11 + 16 - output_bits;
  192. for (i = 0; i < dstW; i++) {
  193. int val = 1 << (shift - 1);
  194. int j;
  195. for (j = 0; j < filterSize; j++)
  196. val += src[j][i] * filter[j];
  197. output_pixel(&dest[i], val);
  198. }
  199. }
  200. #undef output_pixel
  201. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  202. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  203. uint8_t *dest, int dstW, \
  204. const uint8_t *dither, int offset)\
  205. { \
  206. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  207. (uint16_t *) dest, dstW, is_be, bits); \
  208. }\
  209. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  210. const int16_t **src, uint8_t *dest, int dstW, \
  211. const uint8_t *dither, int offset)\
  212. { \
  213. yuv2planeX_## template_size ## _c_template(filter, \
  214. filterSize, (const typeX_t **) src, \
  215. (uint16_t *) dest, dstW, is_be, bits); \
  216. }
  217. yuv2NBPS( 9, BE, 1, 10, int16_t)
  218. yuv2NBPS( 9, LE, 0, 10, int16_t)
  219. yuv2NBPS(10, BE, 1, 10, int16_t)
  220. yuv2NBPS(10, LE, 0, 10, int16_t)
  221. yuv2NBPS(12, BE, 1, 10, int16_t)
  222. yuv2NBPS(12, LE, 0, 10, int16_t)
  223. yuv2NBPS(14, BE, 1, 10, int16_t)
  224. yuv2NBPS(14, LE, 0, 10, int16_t)
  225. yuv2NBPS(16, BE, 1, 16, int32_t)
  226. yuv2NBPS(16, LE, 0, 16, int32_t)
  227. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  228. const int16_t **src, uint8_t *dest, int dstW,
  229. const uint8_t *dither, int offset)
  230. {
  231. int i;
  232. for (i=0; i<dstW; i++) {
  233. int val = dither[(i + offset) & 7] << 12;
  234. int j;
  235. for (j=0; j<filterSize; j++)
  236. val += src[j][i] * filter[j];
  237. dest[i]= av_clip_uint8(val>>19);
  238. }
  239. }
  240. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  241. const uint8_t *dither, int offset)
  242. {
  243. int i;
  244. for (i=0; i<dstW; i++) {
  245. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  246. dest[i]= av_clip_uint8(val);
  247. }
  248. }
  249. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  250. const int16_t **chrUSrc, const int16_t **chrVSrc,
  251. uint8_t *dest, int chrDstW)
  252. {
  253. enum AVPixelFormat dstFormat = c->dstFormat;
  254. const uint8_t *chrDither = c->chrDither8;
  255. int i;
  256. if (dstFormat == AV_PIX_FMT_NV12)
  257. for (i=0; i<chrDstW; i++) {
  258. int u = chrDither[i & 7] << 12;
  259. int v = chrDither[(i + 3) & 7] << 12;
  260. int j;
  261. for (j=0; j<chrFilterSize; j++) {
  262. u += chrUSrc[j][i] * chrFilter[j];
  263. v += chrVSrc[j][i] * chrFilter[j];
  264. }
  265. dest[2*i]= av_clip_uint8(u>>19);
  266. dest[2*i+1]= av_clip_uint8(v>>19);
  267. }
  268. else
  269. for (i=0; i<chrDstW; i++) {
  270. int u = chrDither[i & 7] << 12;
  271. int v = chrDither[(i + 3) & 7] << 12;
  272. int j;
  273. for (j=0; j<chrFilterSize; j++) {
  274. u += chrUSrc[j][i] * chrFilter[j];
  275. v += chrVSrc[j][i] * chrFilter[j];
  276. }
  277. dest[2*i]= av_clip_uint8(v>>19);
  278. dest[2*i+1]= av_clip_uint8(u>>19);
  279. }
  280. }
  281. #define output_pixel(pos, val) \
  282. if (big_endian) { \
  283. AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  284. } else { \
  285. AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  286. }
  287. static void yuv2p010l1_c(const int16_t *src,
  288. uint16_t *dest, int dstW,
  289. int big_endian)
  290. {
  291. int i;
  292. int shift = 5;
  293. for (i = 0; i < dstW; i++) {
  294. int val = src[i] + (1 << (shift - 1));
  295. output_pixel(&dest[i], val);
  296. }
  297. }
  298. static void yuv2p010lX_c(const int16_t *filter, int filterSize,
  299. const int16_t **src, uint16_t *dest, int dstW,
  300. int big_endian)
  301. {
  302. int i, j;
  303. int shift = 17;
  304. for (i = 0; i < dstW; i++) {
  305. int val = 1 << (shift - 1);
  306. for (j = 0; j < filterSize; j++)
  307. val += src[j][i] * filter[j];
  308. output_pixel(&dest[i], val);
  309. }
  310. }
  311. static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  312. const int16_t **chrUSrc, const int16_t **chrVSrc,
  313. uint8_t *dest8, int chrDstW)
  314. {
  315. uint16_t *dest = (uint16_t*)dest8;
  316. int shift = 17;
  317. int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
  318. int i, j;
  319. for (i = 0; i < chrDstW; i++) {
  320. int u = 1 << (shift - 1);
  321. int v = 1 << (shift - 1);
  322. for (j = 0; j < chrFilterSize; j++) {
  323. u += chrUSrc[j][i] * chrFilter[j];
  324. v += chrVSrc[j][i] * chrFilter[j];
  325. }
  326. output_pixel(&dest[2*i] , u);
  327. output_pixel(&dest[2*i+1], v);
  328. }
  329. }
  330. static void yuv2p010l1_LE_c(const int16_t *src,
  331. uint8_t *dest, int dstW,
  332. const uint8_t *dither, int offset)
  333. {
  334. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
  335. }
  336. static void yuv2p010l1_BE_c(const int16_t *src,
  337. uint8_t *dest, int dstW,
  338. const uint8_t *dither, int offset)
  339. {
  340. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
  341. }
  342. static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
  343. const int16_t **src, uint8_t *dest, int dstW,
  344. const uint8_t *dither, int offset)
  345. {
  346. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
  347. }
  348. static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
  349. const int16_t **src, uint8_t *dest, int dstW,
  350. const uint8_t *dither, int offset)
  351. {
  352. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
  353. }
  354. #undef output_pixel
  355. #define accumulate_bit(acc, val) \
  356. acc <<= 1; \
  357. acc |= (val) >= 234
  358. #define output_pixel(pos, acc) \
  359. if (target == AV_PIX_FMT_MONOBLACK) { \
  360. pos = acc; \
  361. } else { \
  362. pos = ~acc; \
  363. }
  364. static av_always_inline void
  365. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  366. const int16_t **lumSrc, int lumFilterSize,
  367. const int16_t *chrFilter, const int16_t **chrUSrc,
  368. const int16_t **chrVSrc, int chrFilterSize,
  369. const int16_t **alpSrc, uint8_t *dest, int dstW,
  370. int y, enum AVPixelFormat target)
  371. {
  372. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  373. int i;
  374. unsigned acc = 0;
  375. int err = 0;
  376. for (i = 0; i < dstW; i += 2) {
  377. int j;
  378. int Y1 = 1 << 18;
  379. int Y2 = 1 << 18;
  380. for (j = 0; j < lumFilterSize; j++) {
  381. Y1 += lumSrc[j][i] * lumFilter[j];
  382. Y2 += lumSrc[j][i+1] * lumFilter[j];
  383. }
  384. Y1 >>= 19;
  385. Y2 >>= 19;
  386. if ((Y1 | Y2) & 0x100) {
  387. Y1 = av_clip_uint8(Y1);
  388. Y2 = av_clip_uint8(Y2);
  389. }
  390. if (c->dither == SWS_DITHER_ED) {
  391. 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;
  392. c->dither_error[0][i] = err;
  393. acc = 2*acc + (Y1 >= 128);
  394. Y1 -= 220*(acc&1);
  395. 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);
  396. c->dither_error[0][i+1] = Y1;
  397. acc = 2*acc + (err >= 128);
  398. err -= 220*(acc&1);
  399. } else {
  400. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  401. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  402. }
  403. if ((i & 7) == 6) {
  404. output_pixel(*dest++, acc);
  405. }
  406. }
  407. c->dither_error[0][i] = err;
  408. if (i & 6) {
  409. output_pixel(*dest, acc);
  410. }
  411. }
  412. static av_always_inline void
  413. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  414. const int16_t *ubuf[2], const int16_t *vbuf[2],
  415. const int16_t *abuf[2], uint8_t *dest, int dstW,
  416. int yalpha, int uvalpha, int y,
  417. enum AVPixelFormat target)
  418. {
  419. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  420. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  421. int yalpha1 = 4096 - yalpha;
  422. int i;
  423. av_assert2(yalpha <= 4096U);
  424. if (c->dither == SWS_DITHER_ED) {
  425. int err = 0;
  426. int acc = 0;
  427. for (i = 0; i < dstW; i +=2) {
  428. int Y;
  429. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  430. 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;
  431. c->dither_error[0][i] = err;
  432. acc = 2*acc + (Y >= 128);
  433. Y -= 220*(acc&1);
  434. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  435. 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;
  436. c->dither_error[0][i+1] = Y;
  437. acc = 2*acc + (err >= 128);
  438. err -= 220*(acc&1);
  439. if ((i & 7) == 6)
  440. output_pixel(*dest++, acc);
  441. }
  442. c->dither_error[0][i] = err;
  443. } else {
  444. for (i = 0; i < dstW; i += 8) {
  445. int Y, acc = 0;
  446. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  447. accumulate_bit(acc, Y + d128[0]);
  448. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  449. accumulate_bit(acc, Y + d128[1]);
  450. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  451. accumulate_bit(acc, Y + d128[2]);
  452. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  453. accumulate_bit(acc, Y + d128[3]);
  454. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  455. accumulate_bit(acc, Y + d128[4]);
  456. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  457. accumulate_bit(acc, Y + d128[5]);
  458. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  459. accumulate_bit(acc, Y + d128[6]);
  460. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  461. accumulate_bit(acc, Y + d128[7]);
  462. output_pixel(*dest++, acc);
  463. }
  464. }
  465. }
  466. static av_always_inline void
  467. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  468. const int16_t *ubuf[2], const int16_t *vbuf[2],
  469. const int16_t *abuf0, uint8_t *dest, int dstW,
  470. int uvalpha, int y, enum AVPixelFormat target)
  471. {
  472. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  473. int i;
  474. if (c->dither == SWS_DITHER_ED) {
  475. int err = 0;
  476. int acc = 0;
  477. for (i = 0; i < dstW; i +=2) {
  478. int Y;
  479. Y = ((buf0[i + 0] + 64) >> 7);
  480. 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;
  481. c->dither_error[0][i] = err;
  482. acc = 2*acc + (Y >= 128);
  483. Y -= 220*(acc&1);
  484. err = ((buf0[i + 1] + 64) >> 7);
  485. 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;
  486. c->dither_error[0][i+1] = Y;
  487. acc = 2*acc + (err >= 128);
  488. err -= 220*(acc&1);
  489. if ((i & 7) == 6)
  490. output_pixel(*dest++, acc);
  491. }
  492. c->dither_error[0][i] = err;
  493. } else {
  494. for (i = 0; i < dstW; i += 8) {
  495. int acc = 0;
  496. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  497. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  498. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  499. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  500. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  501. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  502. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  503. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  504. output_pixel(*dest++, acc);
  505. }
  506. }
  507. }
  508. #undef output_pixel
  509. #undef accumulate_bit
  510. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  511. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  512. const int16_t **lumSrc, int lumFilterSize, \
  513. const int16_t *chrFilter, const int16_t **chrUSrc, \
  514. const int16_t **chrVSrc, int chrFilterSize, \
  515. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  516. int y) \
  517. { \
  518. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  519. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  520. alpSrc, dest, dstW, y, fmt); \
  521. } \
  522. \
  523. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  524. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  525. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  526. int yalpha, int uvalpha, int y) \
  527. { \
  528. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  529. dest, dstW, yalpha, uvalpha, y, fmt); \
  530. } \
  531. \
  532. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  533. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  534. const int16_t *abuf0, uint8_t *dest, int dstW, \
  535. int uvalpha, int y) \
  536. { \
  537. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  538. abuf0, dest, dstW, uvalpha, \
  539. y, fmt); \
  540. }
  541. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  542. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  543. #define output_pixels(pos, Y1, U, Y2, V) \
  544. if (target == AV_PIX_FMT_YUYV422) { \
  545. dest[pos + 0] = Y1; \
  546. dest[pos + 1] = U; \
  547. dest[pos + 2] = Y2; \
  548. dest[pos + 3] = V; \
  549. } else if (target == AV_PIX_FMT_YVYU422) { \
  550. dest[pos + 0] = Y1; \
  551. dest[pos + 1] = V; \
  552. dest[pos + 2] = Y2; \
  553. dest[pos + 3] = U; \
  554. } else { /* AV_PIX_FMT_UYVY422 */ \
  555. dest[pos + 0] = U; \
  556. dest[pos + 1] = Y1; \
  557. dest[pos + 2] = V; \
  558. dest[pos + 3] = Y2; \
  559. }
  560. static av_always_inline void
  561. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  562. const int16_t **lumSrc, int lumFilterSize,
  563. const int16_t *chrFilter, const int16_t **chrUSrc,
  564. const int16_t **chrVSrc, int chrFilterSize,
  565. const int16_t **alpSrc, uint8_t *dest, int dstW,
  566. int y, enum AVPixelFormat target)
  567. {
  568. int i;
  569. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  570. int j;
  571. int Y1 = 1 << 18;
  572. int Y2 = 1 << 18;
  573. int U = 1 << 18;
  574. int V = 1 << 18;
  575. for (j = 0; j < lumFilterSize; j++) {
  576. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  577. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  578. }
  579. for (j = 0; j < chrFilterSize; j++) {
  580. U += chrUSrc[j][i] * chrFilter[j];
  581. V += chrVSrc[j][i] * chrFilter[j];
  582. }
  583. Y1 >>= 19;
  584. Y2 >>= 19;
  585. U >>= 19;
  586. V >>= 19;
  587. if ((Y1 | Y2 | U | V) & 0x100) {
  588. Y1 = av_clip_uint8(Y1);
  589. Y2 = av_clip_uint8(Y2);
  590. U = av_clip_uint8(U);
  591. V = av_clip_uint8(V);
  592. }
  593. output_pixels(4*i, Y1, U, Y2, V);
  594. }
  595. }
  596. static av_always_inline void
  597. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  598. const int16_t *ubuf[2], const int16_t *vbuf[2],
  599. const int16_t *abuf[2], uint8_t *dest, int dstW,
  600. int yalpha, int uvalpha, int y,
  601. enum AVPixelFormat target)
  602. {
  603. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  604. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  605. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  606. int yalpha1 = 4096 - yalpha;
  607. int uvalpha1 = 4096 - uvalpha;
  608. int i;
  609. av_assert2(yalpha <= 4096U);
  610. av_assert2(uvalpha <= 4096U);
  611. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  612. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  613. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  614. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  615. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  616. if ((Y1 | Y2 | U | V) & 0x100) {
  617. Y1 = av_clip_uint8(Y1);
  618. Y2 = av_clip_uint8(Y2);
  619. U = av_clip_uint8(U);
  620. V = av_clip_uint8(V);
  621. }
  622. output_pixels(i * 4, Y1, U, Y2, V);
  623. }
  624. }
  625. static av_always_inline void
  626. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  627. const int16_t *ubuf[2], const int16_t *vbuf[2],
  628. const int16_t *abuf0, uint8_t *dest, int dstW,
  629. int uvalpha, int y, enum AVPixelFormat target)
  630. {
  631. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  632. int i;
  633. if (uvalpha < 2048) {
  634. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  635. int Y1 = (buf0[i * 2 ]+64) >> 7;
  636. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  637. int U = (ubuf0[i] +64) >> 7;
  638. int V = (vbuf0[i] +64) >> 7;
  639. if ((Y1 | Y2 | U | V) & 0x100) {
  640. Y1 = av_clip_uint8(Y1);
  641. Y2 = av_clip_uint8(Y2);
  642. U = av_clip_uint8(U);
  643. V = av_clip_uint8(V);
  644. }
  645. Y1 = av_clip_uint8(Y1);
  646. Y2 = av_clip_uint8(Y2);
  647. U = av_clip_uint8(U);
  648. V = av_clip_uint8(V);
  649. output_pixels(i * 4, Y1, U, Y2, V);
  650. }
  651. } else {
  652. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  653. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  654. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  655. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  656. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  657. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  658. if ((Y1 | Y2 | U | V) & 0x100) {
  659. Y1 = av_clip_uint8(Y1);
  660. Y2 = av_clip_uint8(Y2);
  661. U = av_clip_uint8(U);
  662. V = av_clip_uint8(V);
  663. }
  664. Y1 = av_clip_uint8(Y1);
  665. Y2 = av_clip_uint8(Y2);
  666. U = av_clip_uint8(U);
  667. V = av_clip_uint8(V);
  668. output_pixels(i * 4, Y1, U, Y2, V);
  669. }
  670. }
  671. }
  672. #undef output_pixels
  673. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  674. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  675. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  676. #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)
  677. #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)
  678. #define output_pixel(pos, val) \
  679. if (isBE(target)) { \
  680. AV_WB16(pos, val); \
  681. } else { \
  682. AV_WL16(pos, val); \
  683. }
  684. static av_always_inline void
  685. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  686. const int32_t **lumSrc, int lumFilterSize,
  687. const int16_t *chrFilter, const int32_t **chrUSrc,
  688. const int32_t **chrVSrc, int chrFilterSize,
  689. const int32_t **alpSrc, uint16_t *dest, int dstW,
  690. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  691. {
  692. int i;
  693. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  694. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  695. int j;
  696. int Y1 = -0x40000000;
  697. int Y2 = -0x40000000;
  698. int U = -(128 << 23); // 19
  699. int V = -(128 << 23);
  700. int R, G, B;
  701. for (j = 0; j < lumFilterSize; j++) {
  702. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  703. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  704. }
  705. for (j = 0; j < chrFilterSize; j++) {;
  706. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  707. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  708. }
  709. if (hasAlpha) {
  710. A1 = -0x40000000;
  711. A2 = -0x40000000;
  712. for (j = 0; j < lumFilterSize; j++) {
  713. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  714. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  715. }
  716. A1 >>= 1;
  717. A1 += 0x20002000;
  718. A2 >>= 1;
  719. A2 += 0x20002000;
  720. }
  721. // 8 bits: 12+15=27; 16 bits: 12+19=31
  722. Y1 >>= 14; // 10
  723. Y1 += 0x10000;
  724. Y2 >>= 14;
  725. Y2 += 0x10000;
  726. U >>= 14;
  727. V >>= 14;
  728. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  729. Y1 -= c->yuv2rgb_y_offset;
  730. Y2 -= c->yuv2rgb_y_offset;
  731. Y1 *= c->yuv2rgb_y_coeff;
  732. Y2 *= c->yuv2rgb_y_coeff;
  733. Y1 += 1 << 13; // 21
  734. Y2 += 1 << 13;
  735. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  736. R = V * c->yuv2rgb_v2r_coeff;
  737. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  738. B = U * c->yuv2rgb_u2b_coeff;
  739. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  740. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  741. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  742. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  743. if (eightbytes) {
  744. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  745. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  746. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  747. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  748. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  749. dest += 8;
  750. } else {
  751. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  752. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  753. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  754. dest += 6;
  755. }
  756. }
  757. }
  758. static av_always_inline void
  759. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  760. const int32_t *ubuf[2], const int32_t *vbuf[2],
  761. const int32_t *abuf[2], uint16_t *dest, int dstW,
  762. int yalpha, int uvalpha, int y,
  763. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  764. {
  765. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  766. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  767. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  768. *abuf0 = hasAlpha ? abuf[0] : NULL,
  769. *abuf1 = hasAlpha ? abuf[1] : NULL;
  770. int yalpha1 = 4096 - yalpha;
  771. int uvalpha1 = 4096 - uvalpha;
  772. int i;
  773. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  774. av_assert2(yalpha <= 4096U);
  775. av_assert2(uvalpha <= 4096U);
  776. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  777. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  778. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  779. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  780. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  781. int R, G, B;
  782. Y1 -= c->yuv2rgb_y_offset;
  783. Y2 -= c->yuv2rgb_y_offset;
  784. Y1 *= c->yuv2rgb_y_coeff;
  785. Y2 *= c->yuv2rgb_y_coeff;
  786. Y1 += 1 << 13;
  787. Y2 += 1 << 13;
  788. R = V * c->yuv2rgb_v2r_coeff;
  789. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  790. B = U * c->yuv2rgb_u2b_coeff;
  791. if (hasAlpha) {
  792. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  793. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  794. A1 += 1 << 13;
  795. A2 += 1 << 13;
  796. }
  797. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  798. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  799. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  800. if (eightbytes) {
  801. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  802. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  803. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  804. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  805. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  806. dest += 8;
  807. } else {
  808. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  809. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  810. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  811. dest += 6;
  812. }
  813. }
  814. }
  815. static av_always_inline void
  816. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  817. const int32_t *ubuf[2], const int32_t *vbuf[2],
  818. const int32_t *abuf0, uint16_t *dest, int dstW,
  819. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  820. {
  821. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  822. int i;
  823. int A1 = 0xffff<<14, A2= 0xffff<<14;
  824. if (uvalpha < 2048) {
  825. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  826. int Y1 = (buf0[i * 2] ) >> 2;
  827. int Y2 = (buf0[i * 2 + 1]) >> 2;
  828. int U = (ubuf0[i] - (128 << 11)) >> 2;
  829. int V = (vbuf0[i] - (128 << 11)) >> 2;
  830. int R, G, B;
  831. Y1 -= c->yuv2rgb_y_offset;
  832. Y2 -= c->yuv2rgb_y_offset;
  833. Y1 *= c->yuv2rgb_y_coeff;
  834. Y2 *= c->yuv2rgb_y_coeff;
  835. Y1 += 1 << 13;
  836. Y2 += 1 << 13;
  837. if (hasAlpha) {
  838. A1 = abuf0[i * 2 ] << 11;
  839. A2 = abuf0[i * 2 + 1] << 11;
  840. A1 += 1 << 13;
  841. A2 += 1 << 13;
  842. }
  843. R = V * c->yuv2rgb_v2r_coeff;
  844. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  845. B = U * c->yuv2rgb_u2b_coeff;
  846. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  847. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  848. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  849. if (eightbytes) {
  850. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  851. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  852. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  853. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  854. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  855. dest += 8;
  856. } else {
  857. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  858. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  859. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  860. dest += 6;
  861. }
  862. }
  863. } else {
  864. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  865. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  866. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  867. int Y1 = (buf0[i * 2] ) >> 2;
  868. int Y2 = (buf0[i * 2 + 1]) >> 2;
  869. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  870. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  871. int R, G, B;
  872. Y1 -= c->yuv2rgb_y_offset;
  873. Y2 -= c->yuv2rgb_y_offset;
  874. Y1 *= c->yuv2rgb_y_coeff;
  875. Y2 *= c->yuv2rgb_y_coeff;
  876. Y1 += 1 << 13;
  877. Y2 += 1 << 13;
  878. if (hasAlpha) {
  879. A1 = abuf0[i * 2 ] << 11;
  880. A2 = abuf0[i * 2 + 1] << 11;
  881. A1 += 1 << 13;
  882. A2 += 1 << 13;
  883. }
  884. R = V * c->yuv2rgb_v2r_coeff;
  885. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  886. B = U * c->yuv2rgb_u2b_coeff;
  887. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  888. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  889. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  890. if (eightbytes) {
  891. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  892. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  893. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  894. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  895. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  896. dest += 8;
  897. } else {
  898. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  899. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  900. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  901. dest += 6;
  902. }
  903. }
  904. }
  905. }
  906. static av_always_inline void
  907. yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  908. const int32_t **lumSrc, int lumFilterSize,
  909. const int16_t *chrFilter, const int32_t **chrUSrc,
  910. const int32_t **chrVSrc, int chrFilterSize,
  911. const int32_t **alpSrc, uint16_t *dest, int dstW,
  912. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  913. {
  914. int i;
  915. int A = 0xffff<<14;
  916. for (i = 0; i < dstW; i++) {
  917. int j;
  918. int Y = -0x40000000;
  919. int U = -(128 << 23); // 19
  920. int V = -(128 << 23);
  921. int R, G, B;
  922. for (j = 0; j < lumFilterSize; j++) {
  923. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  924. }
  925. for (j = 0; j < chrFilterSize; j++) {;
  926. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  927. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  928. }
  929. if (hasAlpha) {
  930. A = -0x40000000;
  931. for (j = 0; j < lumFilterSize; j++) {
  932. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  933. }
  934. A >>= 1;
  935. A += 0x20002000;
  936. }
  937. // 8bit: 12+15=27; 16-bit: 12+19=31
  938. Y >>= 14; // 10
  939. Y += 0x10000;
  940. U >>= 14;
  941. V >>= 14;
  942. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  943. Y -= c->yuv2rgb_y_offset;
  944. Y *= c->yuv2rgb_y_coeff;
  945. Y += 1 << 13; // 21
  946. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  947. R = V * c->yuv2rgb_v2r_coeff;
  948. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  949. B = U * c->yuv2rgb_u2b_coeff;
  950. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  951. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  952. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  953. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  954. if (eightbytes) {
  955. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  956. dest += 4;
  957. } else {
  958. dest += 3;
  959. }
  960. }
  961. }
  962. static av_always_inline void
  963. yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
  964. const int32_t *ubuf[2], const int32_t *vbuf[2],
  965. const int32_t *abuf[2], uint16_t *dest, int dstW,
  966. int yalpha, int uvalpha, int y,
  967. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  968. {
  969. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  970. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  971. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  972. *abuf0 = hasAlpha ? abuf[0] : NULL,
  973. *abuf1 = hasAlpha ? abuf[1] : NULL;
  974. int yalpha1 = 4096 - yalpha;
  975. int uvalpha1 = 4096 - uvalpha;
  976. int i;
  977. int A = 0xffff<<14;
  978. av_assert2(yalpha <= 4096U);
  979. av_assert2(uvalpha <= 4096U);
  980. for (i = 0; i < dstW; i++) {
  981. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  982. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  983. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  984. int R, G, B;
  985. Y -= c->yuv2rgb_y_offset;
  986. Y *= c->yuv2rgb_y_coeff;
  987. Y += 1 << 13;
  988. R = V * c->yuv2rgb_v2r_coeff;
  989. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  990. B = U * c->yuv2rgb_u2b_coeff;
  991. if (hasAlpha) {
  992. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  993. A += 1 << 13;
  994. }
  995. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  996. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  997. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  998. if (eightbytes) {
  999. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1000. dest += 4;
  1001. } else {
  1002. dest += 3;
  1003. }
  1004. }
  1005. }
  1006. static av_always_inline void
  1007. yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
  1008. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1009. const int32_t *abuf0, uint16_t *dest, int dstW,
  1010. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1011. {
  1012. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1013. int i;
  1014. int A = 0xffff<<14;
  1015. if (uvalpha < 2048) {
  1016. for (i = 0; i < dstW; i++) {
  1017. int Y = (buf0[i]) >> 2;
  1018. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1019. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1020. int R, G, B;
  1021. Y -= c->yuv2rgb_y_offset;
  1022. Y *= c->yuv2rgb_y_coeff;
  1023. Y += 1 << 13;
  1024. if (hasAlpha) {
  1025. A = abuf0[i] << 11;
  1026. A += 1 << 13;
  1027. }
  1028. R = V * c->yuv2rgb_v2r_coeff;
  1029. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1030. B = U * c->yuv2rgb_u2b_coeff;
  1031. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1032. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1033. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1034. if (eightbytes) {
  1035. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1036. dest += 4;
  1037. } else {
  1038. dest += 3;
  1039. }
  1040. }
  1041. } else {
  1042. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1043. int A = 0xffff<<14;
  1044. for (i = 0; i < dstW; i++) {
  1045. int Y = (buf0[i] ) >> 2;
  1046. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1047. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1048. int R, G, B;
  1049. Y -= c->yuv2rgb_y_offset;
  1050. Y *= c->yuv2rgb_y_coeff;
  1051. Y += 1 << 13;
  1052. if (hasAlpha) {
  1053. A = abuf0[i] << 11;
  1054. A += 1 << 13;
  1055. }
  1056. R = V * c->yuv2rgb_v2r_coeff;
  1057. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1058. B = U * c->yuv2rgb_u2b_coeff;
  1059. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1060. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1061. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1062. if (eightbytes) {
  1063. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1064. dest += 4;
  1065. } else {
  1066. dest += 3;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. #undef output_pixel
  1072. #undef r_b
  1073. #undef b_r
  1074. #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
  1075. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1076. const int16_t **_lumSrc, int lumFilterSize, \
  1077. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1078. const int16_t **_chrVSrc, int chrFilterSize, \
  1079. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1080. int y) \
  1081. { \
  1082. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1083. **chrUSrc = (const int32_t **) _chrUSrc, \
  1084. **chrVSrc = (const int32_t **) _chrVSrc, \
  1085. **alpSrc = (const int32_t **) _alpSrc; \
  1086. uint16_t *dest = (uint16_t *) _dest; \
  1087. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1088. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1089. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
  1090. } \
  1091. \
  1092. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  1093. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1094. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1095. int yalpha, int uvalpha, int y) \
  1096. { \
  1097. const int32_t **buf = (const int32_t **) _buf, \
  1098. **ubuf = (const int32_t **) _ubuf, \
  1099. **vbuf = (const int32_t **) _vbuf, \
  1100. **abuf = (const int32_t **) _abuf; \
  1101. uint16_t *dest = (uint16_t *) _dest; \
  1102. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1103. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1104. } \
  1105. \
  1106. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  1107. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1108. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1109. int uvalpha, int y) \
  1110. { \
  1111. const int32_t *buf0 = (const int32_t *) _buf0, \
  1112. **ubuf = (const int32_t **) _ubuf, \
  1113. **vbuf = (const int32_t **) _vbuf, \
  1114. *abuf0 = (const int32_t *) _abuf0; \
  1115. uint16_t *dest = (uint16_t *) _dest; \
  1116. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1117. dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1118. }
  1119. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
  1120. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
  1121. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
  1122. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
  1123. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
  1124. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
  1125. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
  1126. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
  1127. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
  1128. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
  1129. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
  1130. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
  1131. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
  1132. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
  1133. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
  1134. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
  1135. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
  1136. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
  1137. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
  1138. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
  1139. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
  1140. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
  1141. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
  1142. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
  1143. /*
  1144. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1145. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1146. * things like endianness conversion and shifting. The caller takes care of
  1147. * setting the correct offset in these tables from the chroma (U/V) values.
  1148. * This function then uses the luminance (Y1/Y2) values to write out the
  1149. * correct RGB values into the destination buffer.
  1150. */
  1151. static av_always_inline void
  1152. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1153. unsigned A1, unsigned A2,
  1154. const void *_r, const void *_g, const void *_b, int y,
  1155. enum AVPixelFormat target, int hasAlpha)
  1156. {
  1157. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1158. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1159. uint32_t *dest = (uint32_t *) _dest;
  1160. const uint32_t *r = (const uint32_t *) _r;
  1161. const uint32_t *g = (const uint32_t *) _g;
  1162. const uint32_t *b = (const uint32_t *) _b;
  1163. #if CONFIG_SMALL
  1164. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1165. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1166. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1167. #else
  1168. if (hasAlpha) {
  1169. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1170. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1171. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1172. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1173. } else {
  1174. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1175. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1176. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1177. #endif
  1178. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1179. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1180. }
  1181. #endif
  1182. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1183. uint8_t *dest = (uint8_t *) _dest;
  1184. const uint8_t *r = (const uint8_t *) _r;
  1185. const uint8_t *g = (const uint8_t *) _g;
  1186. const uint8_t *b = (const uint8_t *) _b;
  1187. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1188. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1189. dest[i * 6 + 0] = r_b[Y1];
  1190. dest[i * 6 + 1] = g[Y1];
  1191. dest[i * 6 + 2] = b_r[Y1];
  1192. dest[i * 6 + 3] = r_b[Y2];
  1193. dest[i * 6 + 4] = g[Y2];
  1194. dest[i * 6 + 5] = b_r[Y2];
  1195. #undef r_b
  1196. #undef b_r
  1197. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1198. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1199. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1200. uint16_t *dest = (uint16_t *) _dest;
  1201. const uint16_t *r = (const uint16_t *) _r;
  1202. const uint16_t *g = (const uint16_t *) _g;
  1203. const uint16_t *b = (const uint16_t *) _b;
  1204. int dr1, dg1, db1, dr2, dg2, db2;
  1205. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1206. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1207. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1208. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1209. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1210. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1211. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1212. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1213. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1214. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1215. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1216. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1217. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1218. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1219. } else {
  1220. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1221. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1222. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1223. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1224. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1225. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1226. }
  1227. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1228. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1229. } else /* 8/4 bits */ {
  1230. uint8_t *dest = (uint8_t *) _dest;
  1231. const uint8_t *r = (const uint8_t *) _r;
  1232. const uint8_t *g = (const uint8_t *) _g;
  1233. const uint8_t *b = (const uint8_t *) _b;
  1234. int dr1, dg1, db1, dr2, dg2, db2;
  1235. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1236. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1237. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1238. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1239. db1 = d64[(i * 2 + 0) & 7];
  1240. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1241. db2 = d64[(i * 2 + 1) & 7];
  1242. } else {
  1243. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1244. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1245. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1246. dg1 = d64[(i * 2 + 0) & 7];
  1247. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1248. dg2 = d64[(i * 2 + 1) & 7];
  1249. }
  1250. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1251. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1252. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1253. } else {
  1254. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1255. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1256. }
  1257. }
  1258. }
  1259. static av_always_inline void
  1260. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1261. const int16_t **lumSrc, int lumFilterSize,
  1262. const int16_t *chrFilter, const int16_t **chrUSrc,
  1263. const int16_t **chrVSrc, int chrFilterSize,
  1264. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1265. int y, enum AVPixelFormat target, int hasAlpha)
  1266. {
  1267. int i;
  1268. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1269. int j, A1, A2;
  1270. int Y1 = 1 << 18;
  1271. int Y2 = 1 << 18;
  1272. int U = 1 << 18;
  1273. int V = 1 << 18;
  1274. const void *r, *g, *b;
  1275. for (j = 0; j < lumFilterSize; j++) {
  1276. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1277. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1278. }
  1279. for (j = 0; j < chrFilterSize; j++) {
  1280. U += chrUSrc[j][i] * chrFilter[j];
  1281. V += chrVSrc[j][i] * chrFilter[j];
  1282. }
  1283. Y1 >>= 19;
  1284. Y2 >>= 19;
  1285. U >>= 19;
  1286. V >>= 19;
  1287. if (hasAlpha) {
  1288. A1 = 1 << 18;
  1289. A2 = 1 << 18;
  1290. for (j = 0; j < lumFilterSize; j++) {
  1291. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1292. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1293. }
  1294. A1 >>= 19;
  1295. A2 >>= 19;
  1296. if ((A1 | A2) & 0x100) {
  1297. A1 = av_clip_uint8(A1);
  1298. A2 = av_clip_uint8(A2);
  1299. }
  1300. }
  1301. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1302. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1303. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1304. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1305. r, g, b, y, target, hasAlpha);
  1306. }
  1307. }
  1308. static av_always_inline void
  1309. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1310. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1311. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1312. int yalpha, int uvalpha, int y,
  1313. enum AVPixelFormat target, int hasAlpha)
  1314. {
  1315. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1316. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1317. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1318. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1319. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1320. int yalpha1 = 4096 - yalpha;
  1321. int uvalpha1 = 4096 - uvalpha;
  1322. int i;
  1323. av_assert2(yalpha <= 4096U);
  1324. av_assert2(uvalpha <= 4096U);
  1325. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1326. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1327. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1328. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1329. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1330. int A1, A2;
  1331. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1332. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1333. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1334. if (hasAlpha) {
  1335. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1336. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1337. A1 = av_clip_uint8(A1);
  1338. A2 = av_clip_uint8(A2);
  1339. }
  1340. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1341. r, g, b, y, target, hasAlpha);
  1342. }
  1343. }
  1344. static av_always_inline void
  1345. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1346. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1347. const int16_t *abuf0, uint8_t *dest, int dstW,
  1348. int uvalpha, int y, enum AVPixelFormat target,
  1349. int hasAlpha)
  1350. {
  1351. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1352. int i;
  1353. if (uvalpha < 2048) {
  1354. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1355. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1356. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1357. int U = (ubuf0[i] + 64) >> 7;
  1358. int V = (vbuf0[i] + 64) >> 7;
  1359. int A1, A2;
  1360. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1361. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1362. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1363. if (hasAlpha) {
  1364. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1365. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1366. A1 = av_clip_uint8(A1);
  1367. A2 = av_clip_uint8(A2);
  1368. }
  1369. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1370. r, g, b, y, target, hasAlpha);
  1371. }
  1372. } else {
  1373. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1374. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1375. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1376. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1377. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1378. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1379. int A1, A2;
  1380. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1381. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1382. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1383. if (hasAlpha) {
  1384. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1385. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1386. A1 = av_clip_uint8(A1);
  1387. A2 = av_clip_uint8(A2);
  1388. }
  1389. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1390. r, g, b, y, target, hasAlpha);
  1391. }
  1392. }
  1393. }
  1394. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1395. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1396. const int16_t **lumSrc, int lumFilterSize, \
  1397. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1398. const int16_t **chrVSrc, int chrFilterSize, \
  1399. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1400. int y) \
  1401. { \
  1402. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1403. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1404. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1405. }
  1406. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1407. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1408. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1409. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1410. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1411. int yalpha, int uvalpha, int y) \
  1412. { \
  1413. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1414. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1415. }
  1416. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1417. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1418. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1419. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1420. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1421. int uvalpha, int y) \
  1422. { \
  1423. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1424. dstW, uvalpha, y, fmt, hasAlpha); \
  1425. }
  1426. #if CONFIG_SMALL
  1427. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1428. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1429. #else
  1430. #if CONFIG_SWSCALE_ALPHA
  1431. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1432. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1433. #endif
  1434. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1435. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1436. #endif
  1437. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1438. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1439. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1440. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1441. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1442. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1443. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1444. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1445. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1446. uint8_t *dest, int i, int Y, int A, int U, int V,
  1447. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1448. {
  1449. int R, G, B;
  1450. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1451. Y -= c->yuv2rgb_y_offset;
  1452. Y *= c->yuv2rgb_y_coeff;
  1453. Y += 1 << 21;
  1454. R = Y + V*c->yuv2rgb_v2r_coeff;
  1455. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1456. B = Y + U*c->yuv2rgb_u2b_coeff;
  1457. if ((R | G | B) & 0xC0000000) {
  1458. R = av_clip_uintp2(R, 30);
  1459. G = av_clip_uintp2(G, 30);
  1460. B = av_clip_uintp2(B, 30);
  1461. }
  1462. switch(target) {
  1463. case AV_PIX_FMT_ARGB:
  1464. dest[0] = hasAlpha ? A : 255;
  1465. dest[1] = R >> 22;
  1466. dest[2] = G >> 22;
  1467. dest[3] = B >> 22;
  1468. break;
  1469. case AV_PIX_FMT_RGB24:
  1470. dest[0] = R >> 22;
  1471. dest[1] = G >> 22;
  1472. dest[2] = B >> 22;
  1473. break;
  1474. case AV_PIX_FMT_RGBA:
  1475. dest[0] = R >> 22;
  1476. dest[1] = G >> 22;
  1477. dest[2] = B >> 22;
  1478. dest[3] = hasAlpha ? A : 255;
  1479. break;
  1480. case AV_PIX_FMT_ABGR:
  1481. dest[0] = hasAlpha ? A : 255;
  1482. dest[1] = B >> 22;
  1483. dest[2] = G >> 22;
  1484. dest[3] = R >> 22;
  1485. break;
  1486. case AV_PIX_FMT_BGR24:
  1487. dest[0] = B >> 22;
  1488. dest[1] = G >> 22;
  1489. dest[2] = R >> 22;
  1490. break;
  1491. case AV_PIX_FMT_BGRA:
  1492. dest[0] = B >> 22;
  1493. dest[1] = G >> 22;
  1494. dest[2] = R >> 22;
  1495. dest[3] = hasAlpha ? A : 255;
  1496. break;
  1497. case AV_PIX_FMT_BGR4_BYTE:
  1498. case AV_PIX_FMT_RGB4_BYTE:
  1499. case AV_PIX_FMT_BGR8:
  1500. case AV_PIX_FMT_RGB8:
  1501. {
  1502. int r,g,b;
  1503. switch (c->dither) {
  1504. default:
  1505. case SWS_DITHER_AUTO:
  1506. case SWS_DITHER_ED:
  1507. R >>= 22;
  1508. G >>= 22;
  1509. B >>= 22;
  1510. 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;
  1511. 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;
  1512. 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;
  1513. c->dither_error[0][i] = err[0];
  1514. c->dither_error[1][i] = err[1];
  1515. c->dither_error[2][i] = err[2];
  1516. r = R >> (isrgb8 ? 5 : 7);
  1517. g = G >> (isrgb8 ? 5 : 6);
  1518. b = B >> (isrgb8 ? 6 : 7);
  1519. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1520. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1521. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1522. err[0] = R - r*(isrgb8 ? 36 : 255);
  1523. err[1] = G - g*(isrgb8 ? 36 : 85);
  1524. err[2] = B - b*(isrgb8 ? 85 : 255);
  1525. break;
  1526. case SWS_DITHER_A_DITHER:
  1527. if (isrgb8) {
  1528. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1529. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1530. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1531. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1532. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1533. r = av_clip_uintp2(r, 3);
  1534. g = av_clip_uintp2(g, 3);
  1535. b = av_clip_uintp2(b, 2);
  1536. } else {
  1537. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1538. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1539. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1540. r = av_clip_uintp2(r, 1);
  1541. g = av_clip_uintp2(g, 2);
  1542. b = av_clip_uintp2(b, 1);
  1543. }
  1544. break;
  1545. case SWS_DITHER_X_DITHER:
  1546. if (isrgb8) {
  1547. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1548. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1549. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1550. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1551. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1552. r = av_clip_uintp2(r, 3);
  1553. g = av_clip_uintp2(g, 3);
  1554. b = av_clip_uintp2(b, 2);
  1555. } else {
  1556. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1557. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1558. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1559. r = av_clip_uintp2(r, 1);
  1560. g = av_clip_uintp2(g, 2);
  1561. b = av_clip_uintp2(b, 1);
  1562. }
  1563. break;
  1564. }
  1565. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1566. dest[0] = r + 2*g + 8*b;
  1567. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1568. dest[0] = b + 2*g + 8*r;
  1569. } else if(target == AV_PIX_FMT_BGR8) {
  1570. dest[0] = r + 8*g + 64*b;
  1571. } else if(target == AV_PIX_FMT_RGB8) {
  1572. dest[0] = b + 4*g + 32*r;
  1573. } else
  1574. av_assert2(0);
  1575. break;}
  1576. }
  1577. }
  1578. static av_always_inline void
  1579. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1580. const int16_t **lumSrc, int lumFilterSize,
  1581. const int16_t *chrFilter, const int16_t **chrUSrc,
  1582. const int16_t **chrVSrc, int chrFilterSize,
  1583. const int16_t **alpSrc, uint8_t *dest,
  1584. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1585. {
  1586. int i;
  1587. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1588. int err[4] = {0};
  1589. int A = 0; //init to silence warning
  1590. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1591. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1592. step = 1;
  1593. for (i = 0; i < dstW; i++) {
  1594. int j;
  1595. int Y = 1<<9;
  1596. int U = (1<<9)-(128 << 19);
  1597. int V = (1<<9)-(128 << 19);
  1598. for (j = 0; j < lumFilterSize; j++) {
  1599. Y += lumSrc[j][i] * lumFilter[j];
  1600. }
  1601. for (j = 0; j < chrFilterSize; j++) {
  1602. U += chrUSrc[j][i] * chrFilter[j];
  1603. V += chrVSrc[j][i] * chrFilter[j];
  1604. }
  1605. Y >>= 10;
  1606. U >>= 10;
  1607. V >>= 10;
  1608. if (hasAlpha) {
  1609. A = 1 << 18;
  1610. for (j = 0; j < lumFilterSize; j++) {
  1611. A += alpSrc[j][i] * lumFilter[j];
  1612. }
  1613. A >>= 19;
  1614. if (A & 0x100)
  1615. A = av_clip_uint8(A);
  1616. }
  1617. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1618. dest += step;
  1619. }
  1620. c->dither_error[0][i] = err[0];
  1621. c->dither_error[1][i] = err[1];
  1622. c->dither_error[2][i] = err[2];
  1623. }
  1624. static av_always_inline void
  1625. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1626. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1627. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1628. int yalpha, int uvalpha, int y,
  1629. enum AVPixelFormat target, int hasAlpha)
  1630. {
  1631. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1632. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1633. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1634. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1635. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1636. int yalpha1 = 4096 - yalpha;
  1637. int uvalpha1 = 4096 - uvalpha;
  1638. int i;
  1639. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1640. int err[4] = {0};
  1641. int A = 0; // init to silcene warning
  1642. av_assert2(yalpha <= 4096U);
  1643. av_assert2(uvalpha <= 4096U);
  1644. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1645. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1646. step = 1;
  1647. for (i = 0; i < dstW; i++) {
  1648. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1649. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1650. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1651. if (hasAlpha) {
  1652. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1653. if (A & 0x100)
  1654. A = av_clip_uint8(A);
  1655. }
  1656. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1657. dest += step;
  1658. }
  1659. c->dither_error[0][i] = err[0];
  1660. c->dither_error[1][i] = err[1];
  1661. c->dither_error[2][i] = err[2];
  1662. }
  1663. static av_always_inline void
  1664. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1665. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1666. const int16_t *abuf0, uint8_t *dest, int dstW,
  1667. int uvalpha, int y, enum AVPixelFormat target,
  1668. int hasAlpha)
  1669. {
  1670. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1671. int i;
  1672. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1673. int err[4] = {0};
  1674. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1675. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1676. step = 1;
  1677. if (uvalpha < 2048) {
  1678. int A = 0; //init to silence warning
  1679. for (i = 0; i < dstW; i++) {
  1680. int Y = buf0[i] << 2;
  1681. int U = (ubuf0[i] - (128<<7)) * 4;
  1682. int V = (vbuf0[i] - (128<<7)) * 4;
  1683. if (hasAlpha) {
  1684. A = (abuf0[i] + 64) >> 7;
  1685. if (A & 0x100)
  1686. A = av_clip_uint8(A);
  1687. }
  1688. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1689. dest += step;
  1690. }
  1691. } else {
  1692. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1693. int A = 0; //init to silence warning
  1694. for (i = 0; i < dstW; i++) {
  1695. int Y = buf0[i] << 2;
  1696. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
  1697. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
  1698. if (hasAlpha) {
  1699. A = (abuf0[i] + 64) >> 7;
  1700. if (A & 0x100)
  1701. A = av_clip_uint8(A);
  1702. }
  1703. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1704. dest += step;
  1705. }
  1706. }
  1707. c->dither_error[0][i] = err[0];
  1708. c->dither_error[1][i] = err[1];
  1709. c->dither_error[2][i] = err[2];
  1710. }
  1711. #if CONFIG_SMALL
  1712. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1713. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1714. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1715. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1716. #else
  1717. #if CONFIG_SWSCALE_ALPHA
  1718. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1719. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1720. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1721. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1722. #endif
  1723. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1724. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1725. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1726. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1727. #endif
  1728. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1729. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1730. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  1731. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  1732. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  1733. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  1734. static void
  1735. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1736. const int16_t **lumSrc, int lumFilterSize,
  1737. const int16_t *chrFilter, const int16_t **chrUSrc,
  1738. const int16_t **chrVSrc, int chrFilterSize,
  1739. const int16_t **alpSrc, uint8_t **dest,
  1740. int dstW, int y)
  1741. {
  1742. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1743. int i;
  1744. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1745. uint16_t **dest16 = (uint16_t**)dest;
  1746. int SH = 22 + 8 - desc->comp[0].depth;
  1747. int A = 0; // init to silence warning
  1748. for (i = 0; i < dstW; i++) {
  1749. int j;
  1750. int Y = 1 << 9;
  1751. int U = (1 << 9) - (128 << 19);
  1752. int V = (1 << 9) - (128 << 19);
  1753. int R, G, B;
  1754. for (j = 0; j < lumFilterSize; j++)
  1755. Y += lumSrc[j][i] * lumFilter[j];
  1756. for (j = 0; j < chrFilterSize; j++) {
  1757. U += chrUSrc[j][i] * chrFilter[j];
  1758. V += chrVSrc[j][i] * chrFilter[j];
  1759. }
  1760. Y >>= 10;
  1761. U >>= 10;
  1762. V >>= 10;
  1763. if (hasAlpha) {
  1764. A = 1 << 18;
  1765. for (j = 0; j < lumFilterSize; j++)
  1766. A += alpSrc[j][i] * lumFilter[j];
  1767. if (A & 0xF8000000)
  1768. A = av_clip_uintp2(A, 27);
  1769. }
  1770. Y -= c->yuv2rgb_y_offset;
  1771. Y *= c->yuv2rgb_y_coeff;
  1772. Y += 1 << (SH-1);
  1773. R = Y + V * c->yuv2rgb_v2r_coeff;
  1774. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1775. B = Y + U * c->yuv2rgb_u2b_coeff;
  1776. if ((R | G | B) & 0xC0000000) {
  1777. R = av_clip_uintp2(R, 30);
  1778. G = av_clip_uintp2(G, 30);
  1779. B = av_clip_uintp2(B, 30);
  1780. }
  1781. if (SH != 22) {
  1782. dest16[0][i] = G >> SH;
  1783. dest16[1][i] = B >> SH;
  1784. dest16[2][i] = R >> SH;
  1785. if (hasAlpha)
  1786. dest16[3][i] = A >> (SH - 3);
  1787. } else {
  1788. dest[0][i] = G >> 22;
  1789. dest[1][i] = B >> 22;
  1790. dest[2][i] = R >> 22;
  1791. if (hasAlpha)
  1792. dest[3][i] = A >> 19;
  1793. }
  1794. }
  1795. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1796. for (i = 0; i < dstW; i++) {
  1797. dest16[0][i] = av_bswap16(dest16[0][i]);
  1798. dest16[1][i] = av_bswap16(dest16[1][i]);
  1799. dest16[2][i] = av_bswap16(dest16[2][i]);
  1800. if (hasAlpha)
  1801. dest16[3][i] = av_bswap16(dest16[3][i]);
  1802. }
  1803. }
  1804. }
  1805. static void
  1806. yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1807. const int16_t **lumSrcx, int lumFilterSize,
  1808. const int16_t *chrFilter, const int16_t **chrUSrcx,
  1809. const int16_t **chrVSrcx, int chrFilterSize,
  1810. const int16_t **alpSrcx, uint8_t **dest,
  1811. int dstW, int y)
  1812. {
  1813. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1814. int i;
  1815. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  1816. uint16_t **dest16 = (uint16_t**)dest;
  1817. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  1818. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  1819. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  1820. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  1821. for (i = 0; i < dstW; i++) {
  1822. int j;
  1823. int Y = -0x40000000;
  1824. int U = -(128 << 23);
  1825. int V = -(128 << 23);
  1826. int R, G, B, A;
  1827. for (j = 0; j < lumFilterSize; j++)
  1828. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1829. for (j = 0; j < chrFilterSize; j++) {
  1830. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1831. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1832. }
  1833. Y >>= 14;
  1834. Y += 0x10000;
  1835. U >>= 14;
  1836. V >>= 14;
  1837. if (hasAlpha) {
  1838. A = -0x40000000;
  1839. for (j = 0; j < lumFilterSize; j++)
  1840. A += alpSrc[j][i] * lumFilter[j];
  1841. A >>= 1;
  1842. A += 0x20002000;
  1843. }
  1844. Y -= c->yuv2rgb_y_offset;
  1845. Y *= c->yuv2rgb_y_coeff;
  1846. Y += 1 << 13;
  1847. R = V * c->yuv2rgb_v2r_coeff;
  1848. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1849. B = U * c->yuv2rgb_u2b_coeff;
  1850. R = av_clip_uintp2(Y + R, 30);
  1851. G = av_clip_uintp2(Y + G, 30);
  1852. B = av_clip_uintp2(Y + B, 30);
  1853. dest16[0][i] = G >> 14;
  1854. dest16[1][i] = B >> 14;
  1855. dest16[2][i] = R >> 14;
  1856. if (hasAlpha)
  1857. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  1858. }
  1859. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1860. for (i = 0; i < dstW; i++) {
  1861. dest16[0][i] = av_bswap16(dest16[0][i]);
  1862. dest16[1][i] = av_bswap16(dest16[1][i]);
  1863. dest16[2][i] = av_bswap16(dest16[2][i]);
  1864. if (hasAlpha)
  1865. dest16[3][i] = av_bswap16(dest16[3][i]);
  1866. }
  1867. }
  1868. }
  1869. static void
  1870. yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
  1871. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1872. const int16_t *abuf0, uint8_t *dest, int dstW,
  1873. int uvalpha, int y)
  1874. {
  1875. int hasAlpha = !!abuf0;
  1876. int i;
  1877. for (i = 0; i < dstW; i++) {
  1878. int Y = (buf0[i] + 64) >> 7;
  1879. int A;
  1880. Y = av_clip_uint8(Y);
  1881. if (hasAlpha) {
  1882. A = (abuf0[i] + 64) >> 7;
  1883. if (A & 0x100)
  1884. A = av_clip_uint8(A);
  1885. }
  1886. dest[i * 2 ] = Y;
  1887. dest[i * 2 + 1] = hasAlpha ? A : 255;
  1888. }
  1889. }
  1890. static void
  1891. yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
  1892. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1893. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1894. int yalpha, int uvalpha, int y)
  1895. {
  1896. int hasAlpha = abuf && abuf[0] && abuf[1];
  1897. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1898. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1899. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1900. int yalpha1 = 4096 - yalpha;
  1901. int i;
  1902. av_assert2(yalpha <= 4096U);
  1903. for (i = 0; i < dstW; i++) {
  1904. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  1905. int A;
  1906. Y = av_clip_uint8(Y);
  1907. if (hasAlpha) {
  1908. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  1909. A = av_clip_uint8(A);
  1910. }
  1911. dest[i * 2 ] = Y;
  1912. dest[i * 2 + 1] = hasAlpha ? A : 255;
  1913. }
  1914. }
  1915. static void
  1916. yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
  1917. const int16_t **lumSrc, int lumFilterSize,
  1918. const int16_t *chrFilter, const int16_t **chrUSrc,
  1919. const int16_t **chrVSrc, int chrFilterSize,
  1920. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  1921. {
  1922. int hasAlpha = !!alpSrc;
  1923. int i;
  1924. for (i = 0; i < dstW; i++) {
  1925. int j;
  1926. int Y = 1 << 18, A = 1 << 18;
  1927. for (j = 0; j < lumFilterSize; j++)
  1928. Y += lumSrc[j][i] * lumFilter[j];
  1929. Y >>= 19;
  1930. if (Y & 0x100)
  1931. Y = av_clip_uint8(Y);
  1932. if (hasAlpha) {
  1933. for (j = 0; j < lumFilterSize; j++)
  1934. A += alpSrc[j][i] * lumFilter[j];
  1935. A >>= 19;
  1936. if (A & 0x100)
  1937. A = av_clip_uint8(A);
  1938. }
  1939. dest[2 * i ] = Y;
  1940. dest[2 * i + 1] = hasAlpha ? A : 255;
  1941. }
  1942. }
  1943. static void
  1944. yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
  1945. const int16_t **_lumSrc, int lumFilterSize,
  1946. const int16_t *chrFilter, const int16_t **_chrUSrc,
  1947. const int16_t **_chrVSrc, int chrFilterSize,
  1948. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
  1949. {
  1950. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  1951. **chrUSrc = (const int32_t **) _chrUSrc,
  1952. **chrVSrc = (const int32_t **) _chrVSrc,
  1953. **alpSrc = (const int32_t **) _alpSrc;
  1954. int hasAlpha = !!alpSrc;
  1955. int i;
  1956. for (i = 0; i < dstW; i++) {
  1957. int Y = 1 << 14, U = 1 << 14;
  1958. int V = 1 << 14, A = 1 << 14;
  1959. int j;
  1960. Y -= 0x40000000;
  1961. U -= 0x40000000;
  1962. V -= 0x40000000;
  1963. A -= 0x40000000;
  1964. for (j = 0; j < lumFilterSize; j++)
  1965. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1966. for (j = 0; j < chrFilterSize; j++)
  1967. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1968. for (j = 0; j < chrFilterSize; j++)
  1969. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1970. if (hasAlpha)
  1971. for (j = 0; j < lumFilterSize; j++)
  1972. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1973. Y = 0x8000 + av_clip_int16(Y >> 15);
  1974. U = 0x8000 + av_clip_int16(U >> 15);
  1975. V = 0x8000 + av_clip_int16(V >> 15);
  1976. A = 0x8000 + av_clip_int16(A >> 15);
  1977. AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
  1978. AV_WL16(dest + 8 * i + 2, Y);
  1979. AV_WL16(dest + 8 * i + 4, U);
  1980. AV_WL16(dest + 8 * i + 6, V);
  1981. }
  1982. }
  1983. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1984. yuv2planar1_fn *yuv2plane1,
  1985. yuv2planarX_fn *yuv2planeX,
  1986. yuv2interleavedX_fn *yuv2nv12cX,
  1987. yuv2packed1_fn *yuv2packed1,
  1988. yuv2packed2_fn *yuv2packed2,
  1989. yuv2packedX_fn *yuv2packedX,
  1990. yuv2anyX_fn *yuv2anyX)
  1991. {
  1992. enum AVPixelFormat dstFormat = c->dstFormat;
  1993. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  1994. if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
  1995. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  1996. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  1997. *yuv2nv12cX = yuv2p010cX_c;
  1998. } else if (is16BPS(dstFormat)) {
  1999. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2000. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2001. } else if (isNBPS(dstFormat)) {
  2002. if (desc->comp[0].depth == 9) {
  2003. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2004. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2005. } else if (desc->comp[0].depth == 10) {
  2006. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2007. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2008. } else if (desc->comp[0].depth == 12) {
  2009. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2010. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2011. } else if (desc->comp[0].depth == 14) {
  2012. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2013. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2014. } else
  2015. av_assert0(0);
  2016. } else {
  2017. *yuv2plane1 = yuv2plane1_8_c;
  2018. *yuv2planeX = yuv2planeX_8_c;
  2019. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  2020. *yuv2nv12cX = yuv2nv12cX_c;
  2021. }
  2022. if(c->flags & SWS_FULL_CHR_H_INT) {
  2023. switch (dstFormat) {
  2024. case AV_PIX_FMT_RGBA:
  2025. #if CONFIG_SMALL
  2026. *yuv2packedX = yuv2rgba32_full_X_c;
  2027. *yuv2packed2 = yuv2rgba32_full_2_c;
  2028. *yuv2packed1 = yuv2rgba32_full_1_c;
  2029. #else
  2030. #if CONFIG_SWSCALE_ALPHA
  2031. if (c->needAlpha) {
  2032. *yuv2packedX = yuv2rgba32_full_X_c;
  2033. *yuv2packed2 = yuv2rgba32_full_2_c;
  2034. *yuv2packed1 = yuv2rgba32_full_1_c;
  2035. } else
  2036. #endif /* CONFIG_SWSCALE_ALPHA */
  2037. {
  2038. *yuv2packedX = yuv2rgbx32_full_X_c;
  2039. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2040. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2041. }
  2042. #endif /* !CONFIG_SMALL */
  2043. break;
  2044. case AV_PIX_FMT_ARGB:
  2045. #if CONFIG_SMALL
  2046. *yuv2packedX = yuv2argb32_full_X_c;
  2047. *yuv2packed2 = yuv2argb32_full_2_c;
  2048. *yuv2packed1 = yuv2argb32_full_1_c;
  2049. #else
  2050. #if CONFIG_SWSCALE_ALPHA
  2051. if (c->needAlpha) {
  2052. *yuv2packedX = yuv2argb32_full_X_c;
  2053. *yuv2packed2 = yuv2argb32_full_2_c;
  2054. *yuv2packed1 = yuv2argb32_full_1_c;
  2055. } else
  2056. #endif /* CONFIG_SWSCALE_ALPHA */
  2057. {
  2058. *yuv2packedX = yuv2xrgb32_full_X_c;
  2059. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2060. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2061. }
  2062. #endif /* !CONFIG_SMALL */
  2063. break;
  2064. case AV_PIX_FMT_BGRA:
  2065. #if CONFIG_SMALL
  2066. *yuv2packedX = yuv2bgra32_full_X_c;
  2067. *yuv2packed2 = yuv2bgra32_full_2_c;
  2068. *yuv2packed1 = yuv2bgra32_full_1_c;
  2069. #else
  2070. #if CONFIG_SWSCALE_ALPHA
  2071. if (c->needAlpha) {
  2072. *yuv2packedX = yuv2bgra32_full_X_c;
  2073. *yuv2packed2 = yuv2bgra32_full_2_c;
  2074. *yuv2packed1 = yuv2bgra32_full_1_c;
  2075. } else
  2076. #endif /* CONFIG_SWSCALE_ALPHA */
  2077. {
  2078. *yuv2packedX = yuv2bgrx32_full_X_c;
  2079. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2080. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2081. }
  2082. #endif /* !CONFIG_SMALL */
  2083. break;
  2084. case AV_PIX_FMT_ABGR:
  2085. #if CONFIG_SMALL
  2086. *yuv2packedX = yuv2abgr32_full_X_c;
  2087. *yuv2packed2 = yuv2abgr32_full_2_c;
  2088. *yuv2packed1 = yuv2abgr32_full_1_c;
  2089. #else
  2090. #if CONFIG_SWSCALE_ALPHA
  2091. if (c->needAlpha) {
  2092. *yuv2packedX = yuv2abgr32_full_X_c;
  2093. *yuv2packed2 = yuv2abgr32_full_2_c;
  2094. *yuv2packed1 = yuv2abgr32_full_1_c;
  2095. } else
  2096. #endif /* CONFIG_SWSCALE_ALPHA */
  2097. {
  2098. *yuv2packedX = yuv2xbgr32_full_X_c;
  2099. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2100. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2101. }
  2102. #endif /* !CONFIG_SMALL */
  2103. break;
  2104. case AV_PIX_FMT_RGBA64LE:
  2105. #if CONFIG_SWSCALE_ALPHA
  2106. if (c->needAlpha) {
  2107. *yuv2packedX = yuv2rgba64le_full_X_c;
  2108. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2109. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2110. } else
  2111. #endif /* CONFIG_SWSCALE_ALPHA */
  2112. {
  2113. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2114. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2115. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2116. }
  2117. break;
  2118. case AV_PIX_FMT_RGBA64BE:
  2119. #if CONFIG_SWSCALE_ALPHA
  2120. if (c->needAlpha) {
  2121. *yuv2packedX = yuv2rgba64be_full_X_c;
  2122. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2123. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2124. } else
  2125. #endif /* CONFIG_SWSCALE_ALPHA */
  2126. {
  2127. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2128. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2129. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2130. }
  2131. break;
  2132. case AV_PIX_FMT_BGRA64LE:
  2133. #if CONFIG_SWSCALE_ALPHA
  2134. if (c->needAlpha) {
  2135. *yuv2packedX = yuv2bgra64le_full_X_c;
  2136. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2137. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2138. } else
  2139. #endif /* CONFIG_SWSCALE_ALPHA */
  2140. {
  2141. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2142. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2143. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2144. }
  2145. break;
  2146. case AV_PIX_FMT_BGRA64BE:
  2147. #if CONFIG_SWSCALE_ALPHA
  2148. if (c->needAlpha) {
  2149. *yuv2packedX = yuv2bgra64be_full_X_c;
  2150. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2151. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2152. } else
  2153. #endif /* CONFIG_SWSCALE_ALPHA */
  2154. {
  2155. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2156. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2157. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2158. }
  2159. break;
  2160. case AV_PIX_FMT_RGB24:
  2161. *yuv2packedX = yuv2rgb24_full_X_c;
  2162. *yuv2packed2 = yuv2rgb24_full_2_c;
  2163. *yuv2packed1 = yuv2rgb24_full_1_c;
  2164. break;
  2165. case AV_PIX_FMT_BGR24:
  2166. *yuv2packedX = yuv2bgr24_full_X_c;
  2167. *yuv2packed2 = yuv2bgr24_full_2_c;
  2168. *yuv2packed1 = yuv2bgr24_full_1_c;
  2169. break;
  2170. case AV_PIX_FMT_RGB48LE:
  2171. *yuv2packedX = yuv2rgb48le_full_X_c;
  2172. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2173. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2174. break;
  2175. case AV_PIX_FMT_BGR48LE:
  2176. *yuv2packedX = yuv2bgr48le_full_X_c;
  2177. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2178. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2179. break;
  2180. case AV_PIX_FMT_RGB48BE:
  2181. *yuv2packedX = yuv2rgb48be_full_X_c;
  2182. *yuv2packed2 = yuv2rgb48be_full_2_c;
  2183. *yuv2packed1 = yuv2rgb48be_full_1_c;
  2184. break;
  2185. case AV_PIX_FMT_BGR48BE:
  2186. *yuv2packedX = yuv2bgr48be_full_X_c;
  2187. *yuv2packed2 = yuv2bgr48be_full_2_c;
  2188. *yuv2packed1 = yuv2bgr48be_full_1_c;
  2189. break;
  2190. case AV_PIX_FMT_BGR4_BYTE:
  2191. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  2192. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  2193. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  2194. break;
  2195. case AV_PIX_FMT_RGB4_BYTE:
  2196. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  2197. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  2198. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  2199. break;
  2200. case AV_PIX_FMT_BGR8:
  2201. *yuv2packedX = yuv2bgr8_full_X_c;
  2202. *yuv2packed2 = yuv2bgr8_full_2_c;
  2203. *yuv2packed1 = yuv2bgr8_full_1_c;
  2204. break;
  2205. case AV_PIX_FMT_RGB8:
  2206. *yuv2packedX = yuv2rgb8_full_X_c;
  2207. *yuv2packed2 = yuv2rgb8_full_2_c;
  2208. *yuv2packed1 = yuv2rgb8_full_1_c;
  2209. break;
  2210. case AV_PIX_FMT_GBRP:
  2211. case AV_PIX_FMT_GBRP9BE:
  2212. case AV_PIX_FMT_GBRP9LE:
  2213. case AV_PIX_FMT_GBRP10BE:
  2214. case AV_PIX_FMT_GBRP10LE:
  2215. case AV_PIX_FMT_GBRP12BE:
  2216. case AV_PIX_FMT_GBRP12LE:
  2217. case AV_PIX_FMT_GBRP14BE:
  2218. case AV_PIX_FMT_GBRP14LE:
  2219. case AV_PIX_FMT_GBRAP:
  2220. case AV_PIX_FMT_GBRAP10BE:
  2221. case AV_PIX_FMT_GBRAP10LE:
  2222. case AV_PIX_FMT_GBRAP12BE:
  2223. case AV_PIX_FMT_GBRAP12LE:
  2224. *yuv2anyX = yuv2gbrp_full_X_c;
  2225. break;
  2226. case AV_PIX_FMT_GBRP16BE:
  2227. case AV_PIX_FMT_GBRP16LE:
  2228. case AV_PIX_FMT_GBRAP16BE:
  2229. case AV_PIX_FMT_GBRAP16LE:
  2230. *yuv2anyX = yuv2gbrp16_full_X_c;
  2231. break;
  2232. }
  2233. if (!*yuv2packedX && !*yuv2anyX)
  2234. goto YUV_PACKED;
  2235. } else {
  2236. YUV_PACKED:
  2237. switch (dstFormat) {
  2238. case AV_PIX_FMT_RGBA64LE:
  2239. #if CONFIG_SWSCALE_ALPHA
  2240. if (c->needAlpha) {
  2241. *yuv2packed1 = yuv2rgba64le_1_c;
  2242. *yuv2packed2 = yuv2rgba64le_2_c;
  2243. *yuv2packedX = yuv2rgba64le_X_c;
  2244. } else
  2245. #endif /* CONFIG_SWSCALE_ALPHA */
  2246. {
  2247. *yuv2packed1 = yuv2rgbx64le_1_c;
  2248. *yuv2packed2 = yuv2rgbx64le_2_c;
  2249. *yuv2packedX = yuv2rgbx64le_X_c;
  2250. }
  2251. break;
  2252. case AV_PIX_FMT_RGBA64BE:
  2253. #if CONFIG_SWSCALE_ALPHA
  2254. if (c->needAlpha) {
  2255. *yuv2packed1 = yuv2rgba64be_1_c;
  2256. *yuv2packed2 = yuv2rgba64be_2_c;
  2257. *yuv2packedX = yuv2rgba64be_X_c;
  2258. } else
  2259. #endif /* CONFIG_SWSCALE_ALPHA */
  2260. {
  2261. *yuv2packed1 = yuv2rgbx64be_1_c;
  2262. *yuv2packed2 = yuv2rgbx64be_2_c;
  2263. *yuv2packedX = yuv2rgbx64be_X_c;
  2264. }
  2265. break;
  2266. case AV_PIX_FMT_BGRA64LE:
  2267. #if CONFIG_SWSCALE_ALPHA
  2268. if (c->needAlpha) {
  2269. *yuv2packed1 = yuv2bgra64le_1_c;
  2270. *yuv2packed2 = yuv2bgra64le_2_c;
  2271. *yuv2packedX = yuv2bgra64le_X_c;
  2272. } else
  2273. #endif /* CONFIG_SWSCALE_ALPHA */
  2274. {
  2275. *yuv2packed1 = yuv2bgrx64le_1_c;
  2276. *yuv2packed2 = yuv2bgrx64le_2_c;
  2277. *yuv2packedX = yuv2bgrx64le_X_c;
  2278. }
  2279. break;
  2280. case AV_PIX_FMT_BGRA64BE:
  2281. #if CONFIG_SWSCALE_ALPHA
  2282. if (c->needAlpha) {
  2283. *yuv2packed1 = yuv2bgra64be_1_c;
  2284. *yuv2packed2 = yuv2bgra64be_2_c;
  2285. *yuv2packedX = yuv2bgra64be_X_c;
  2286. } else
  2287. #endif /* CONFIG_SWSCALE_ALPHA */
  2288. {
  2289. *yuv2packed1 = yuv2bgrx64be_1_c;
  2290. *yuv2packed2 = yuv2bgrx64be_2_c;
  2291. *yuv2packedX = yuv2bgrx64be_X_c;
  2292. }
  2293. break;
  2294. case AV_PIX_FMT_RGB48LE:
  2295. *yuv2packed1 = yuv2rgb48le_1_c;
  2296. *yuv2packed2 = yuv2rgb48le_2_c;
  2297. *yuv2packedX = yuv2rgb48le_X_c;
  2298. break;
  2299. case AV_PIX_FMT_RGB48BE:
  2300. *yuv2packed1 = yuv2rgb48be_1_c;
  2301. *yuv2packed2 = yuv2rgb48be_2_c;
  2302. *yuv2packedX = yuv2rgb48be_X_c;
  2303. break;
  2304. case AV_PIX_FMT_BGR48LE:
  2305. *yuv2packed1 = yuv2bgr48le_1_c;
  2306. *yuv2packed2 = yuv2bgr48le_2_c;
  2307. *yuv2packedX = yuv2bgr48le_X_c;
  2308. break;
  2309. case AV_PIX_FMT_BGR48BE:
  2310. *yuv2packed1 = yuv2bgr48be_1_c;
  2311. *yuv2packed2 = yuv2bgr48be_2_c;
  2312. *yuv2packedX = yuv2bgr48be_X_c;
  2313. break;
  2314. case AV_PIX_FMT_RGB32:
  2315. case AV_PIX_FMT_BGR32:
  2316. #if CONFIG_SMALL
  2317. *yuv2packed1 = yuv2rgb32_1_c;
  2318. *yuv2packed2 = yuv2rgb32_2_c;
  2319. *yuv2packedX = yuv2rgb32_X_c;
  2320. #else
  2321. #if CONFIG_SWSCALE_ALPHA
  2322. if (c->needAlpha) {
  2323. *yuv2packed1 = yuv2rgba32_1_c;
  2324. *yuv2packed2 = yuv2rgba32_2_c;
  2325. *yuv2packedX = yuv2rgba32_X_c;
  2326. } else
  2327. #endif /* CONFIG_SWSCALE_ALPHA */
  2328. {
  2329. *yuv2packed1 = yuv2rgbx32_1_c;
  2330. *yuv2packed2 = yuv2rgbx32_2_c;
  2331. *yuv2packedX = yuv2rgbx32_X_c;
  2332. }
  2333. #endif /* !CONFIG_SMALL */
  2334. break;
  2335. case AV_PIX_FMT_RGB32_1:
  2336. case AV_PIX_FMT_BGR32_1:
  2337. #if CONFIG_SMALL
  2338. *yuv2packed1 = yuv2rgb32_1_1_c;
  2339. *yuv2packed2 = yuv2rgb32_1_2_c;
  2340. *yuv2packedX = yuv2rgb32_1_X_c;
  2341. #else
  2342. #if CONFIG_SWSCALE_ALPHA
  2343. if (c->needAlpha) {
  2344. *yuv2packed1 = yuv2rgba32_1_1_c;
  2345. *yuv2packed2 = yuv2rgba32_1_2_c;
  2346. *yuv2packedX = yuv2rgba32_1_X_c;
  2347. } else
  2348. #endif /* CONFIG_SWSCALE_ALPHA */
  2349. {
  2350. *yuv2packed1 = yuv2rgbx32_1_1_c;
  2351. *yuv2packed2 = yuv2rgbx32_1_2_c;
  2352. *yuv2packedX = yuv2rgbx32_1_X_c;
  2353. }
  2354. #endif /* !CONFIG_SMALL */
  2355. break;
  2356. case AV_PIX_FMT_RGB24:
  2357. *yuv2packed1 = yuv2rgb24_1_c;
  2358. *yuv2packed2 = yuv2rgb24_2_c;
  2359. *yuv2packedX = yuv2rgb24_X_c;
  2360. break;
  2361. case AV_PIX_FMT_BGR24:
  2362. *yuv2packed1 = yuv2bgr24_1_c;
  2363. *yuv2packed2 = yuv2bgr24_2_c;
  2364. *yuv2packedX = yuv2bgr24_X_c;
  2365. break;
  2366. case AV_PIX_FMT_RGB565LE:
  2367. case AV_PIX_FMT_RGB565BE:
  2368. case AV_PIX_FMT_BGR565LE:
  2369. case AV_PIX_FMT_BGR565BE:
  2370. *yuv2packed1 = yuv2rgb16_1_c;
  2371. *yuv2packed2 = yuv2rgb16_2_c;
  2372. *yuv2packedX = yuv2rgb16_X_c;
  2373. break;
  2374. case AV_PIX_FMT_RGB555LE:
  2375. case AV_PIX_FMT_RGB555BE:
  2376. case AV_PIX_FMT_BGR555LE:
  2377. case AV_PIX_FMT_BGR555BE:
  2378. *yuv2packed1 = yuv2rgb15_1_c;
  2379. *yuv2packed2 = yuv2rgb15_2_c;
  2380. *yuv2packedX = yuv2rgb15_X_c;
  2381. break;
  2382. case AV_PIX_FMT_RGB444LE:
  2383. case AV_PIX_FMT_RGB444BE:
  2384. case AV_PIX_FMT_BGR444LE:
  2385. case AV_PIX_FMT_BGR444BE:
  2386. *yuv2packed1 = yuv2rgb12_1_c;
  2387. *yuv2packed2 = yuv2rgb12_2_c;
  2388. *yuv2packedX = yuv2rgb12_X_c;
  2389. break;
  2390. case AV_PIX_FMT_RGB8:
  2391. case AV_PIX_FMT_BGR8:
  2392. *yuv2packed1 = yuv2rgb8_1_c;
  2393. *yuv2packed2 = yuv2rgb8_2_c;
  2394. *yuv2packedX = yuv2rgb8_X_c;
  2395. break;
  2396. case AV_PIX_FMT_RGB4:
  2397. case AV_PIX_FMT_BGR4:
  2398. *yuv2packed1 = yuv2rgb4_1_c;
  2399. *yuv2packed2 = yuv2rgb4_2_c;
  2400. *yuv2packedX = yuv2rgb4_X_c;
  2401. break;
  2402. case AV_PIX_FMT_RGB4_BYTE:
  2403. case AV_PIX_FMT_BGR4_BYTE:
  2404. *yuv2packed1 = yuv2rgb4b_1_c;
  2405. *yuv2packed2 = yuv2rgb4b_2_c;
  2406. *yuv2packedX = yuv2rgb4b_X_c;
  2407. break;
  2408. }
  2409. }
  2410. switch (dstFormat) {
  2411. case AV_PIX_FMT_MONOWHITE:
  2412. *yuv2packed1 = yuv2monowhite_1_c;
  2413. *yuv2packed2 = yuv2monowhite_2_c;
  2414. *yuv2packedX = yuv2monowhite_X_c;
  2415. break;
  2416. case AV_PIX_FMT_MONOBLACK:
  2417. *yuv2packed1 = yuv2monoblack_1_c;
  2418. *yuv2packed2 = yuv2monoblack_2_c;
  2419. *yuv2packedX = yuv2monoblack_X_c;
  2420. break;
  2421. case AV_PIX_FMT_YUYV422:
  2422. *yuv2packed1 = yuv2yuyv422_1_c;
  2423. *yuv2packed2 = yuv2yuyv422_2_c;
  2424. *yuv2packedX = yuv2yuyv422_X_c;
  2425. break;
  2426. case AV_PIX_FMT_YVYU422:
  2427. *yuv2packed1 = yuv2yvyu422_1_c;
  2428. *yuv2packed2 = yuv2yvyu422_2_c;
  2429. *yuv2packedX = yuv2yvyu422_X_c;
  2430. break;
  2431. case AV_PIX_FMT_UYVY422:
  2432. *yuv2packed1 = yuv2uyvy422_1_c;
  2433. *yuv2packed2 = yuv2uyvy422_2_c;
  2434. *yuv2packedX = yuv2uyvy422_X_c;
  2435. break;
  2436. case AV_PIX_FMT_YA8:
  2437. *yuv2packed1 = yuv2ya8_1_c;
  2438. *yuv2packed2 = yuv2ya8_2_c;
  2439. *yuv2packedX = yuv2ya8_X_c;
  2440. break;
  2441. case AV_PIX_FMT_AYUV64LE:
  2442. *yuv2packedX = yuv2ayuv64le_X_c;
  2443. break;
  2444. }
  2445. }