output.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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 <assert.h>
  21. #include <math.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "libavutil/attributes.h"
  26. #include "libavutil/avutil.h"
  27. #include "libavutil/avassert.h"
  28. #include "libavutil/bswap.h"
  29. #include "libavutil/cpu.h"
  30. #include "libavutil/intreadwrite.h"
  31. #include "libavutil/mathematics.h"
  32. #include "libavutil/pixdesc.h"
  33. #include "config.h"
  34. #include "rgb2rgb.h"
  35. #include "swscale.h"
  36. #include "swscale_internal.h"
  37. DECLARE_ALIGNED(8, const uint8_t, dither_2x2_4)[][8]={
  38. { 1, 3, 1, 3, 1, 3, 1, 3, },
  39. { 2, 0, 2, 0, 2, 0, 2, 0, },
  40. { 1, 3, 1, 3, 1, 3, 1, 3, },
  41. };
  42. DECLARE_ALIGNED(8, const uint8_t, dither_2x2_8)[][8]={
  43. { 6, 2, 6, 2, 6, 2, 6, 2, },
  44. { 0, 4, 0, 4, 0, 4, 0, 4, },
  45. { 6, 2, 6, 2, 6, 2, 6, 2, },
  46. };
  47. DECLARE_ALIGNED(8, const uint8_t, dither_4x4_16)[][8]={
  48. { 8, 4, 11, 7, 8, 4, 11, 7, },
  49. { 2, 14, 1, 13, 2, 14, 1, 13, },
  50. { 10, 6, 9, 5, 10, 6, 9, 5, },
  51. { 0, 12, 3, 15, 0, 12, 3, 15, },
  52. { 8, 4, 11, 7, 8, 4, 11, 7, },
  53. };
  54. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[][8]={
  55. { 17, 9, 23, 15, 16, 8, 22, 14, },
  56. { 5, 29, 3, 27, 4, 28, 2, 26, },
  57. { 21, 13, 19, 11, 20, 12, 18, 10, },
  58. { 0, 24, 6, 30, 1, 25, 7, 31, },
  59. { 16, 8, 22, 14, 17, 9, 23, 15, },
  60. { 4, 28, 2, 26, 5, 29, 3, 27, },
  61. { 20, 12, 18, 10, 21, 13, 19, 11, },
  62. { 1, 25, 7, 31, 0, 24, 6, 30, },
  63. { 17, 9, 23, 15, 16, 8, 22, 14, },
  64. };
  65. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[][8]={
  66. { 0, 55, 14, 68, 3, 58, 17, 72, },
  67. { 37, 18, 50, 32, 40, 22, 54, 35, },
  68. { 9, 64, 5, 59, 13, 67, 8, 63, },
  69. { 46, 27, 41, 23, 49, 31, 44, 26, },
  70. { 2, 57, 16, 71, 1, 56, 15, 70, },
  71. { 39, 21, 52, 34, 38, 19, 51, 33, },
  72. { 11, 66, 7, 62, 10, 65, 6, 60, },
  73. { 48, 30, 43, 25, 47, 29, 42, 24, },
  74. { 0, 55, 14, 68, 3, 58, 17, 72, },
  75. };
  76. #if 1
  77. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
  78. {117, 62, 158, 103, 113, 58, 155, 100, },
  79. { 34, 199, 21, 186, 31, 196, 17, 182, },
  80. {144, 89, 131, 76, 141, 86, 127, 72, },
  81. { 0, 165, 41, 206, 10, 175, 52, 217, },
  82. {110, 55, 151, 96, 120, 65, 162, 107, },
  83. { 28, 193, 14, 179, 38, 203, 24, 189, },
  84. {138, 83, 124, 69, 148, 93, 134, 79, },
  85. { 7, 172, 48, 213, 3, 168, 45, 210, },
  86. {117, 62, 158, 103, 113, 58, 155, 100, },
  87. };
  88. #elif 1
  89. // tries to correct a gamma of 1.5
  90. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
  91. { 0, 143, 18, 200, 2, 156, 25, 215, },
  92. { 78, 28, 125, 64, 89, 36, 138, 74, },
  93. { 10, 180, 3, 161, 16, 195, 8, 175, },
  94. {109, 51, 93, 38, 121, 60, 105, 47, },
  95. { 1, 152, 23, 210, 0, 147, 20, 205, },
  96. { 85, 33, 134, 71, 81, 30, 130, 67, },
  97. { 14, 190, 6, 171, 12, 185, 5, 166, },
  98. {117, 57, 101, 44, 113, 54, 97, 41, },
  99. { 0, 143, 18, 200, 2, 156, 25, 215, },
  100. };
  101. #elif 1
  102. // tries to correct a gamma of 2.0
  103. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
  104. { 0, 124, 8, 193, 0, 140, 12, 213, },
  105. { 55, 14, 104, 42, 66, 19, 119, 52, },
  106. { 3, 168, 1, 145, 6, 187, 3, 162, },
  107. { 86, 31, 70, 21, 99, 39, 82, 28, },
  108. { 0, 134, 11, 206, 0, 129, 9, 200, },
  109. { 62, 17, 114, 48, 58, 16, 109, 45, },
  110. { 5, 181, 2, 157, 4, 175, 1, 151, },
  111. { 95, 36, 78, 26, 90, 34, 74, 24, },
  112. { 0, 124, 8, 193, 0, 140, 12, 213, },
  113. };
  114. #else
  115. // tries to correct a gamma of 2.5
  116. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
  117. { 0, 107, 3, 187, 0, 125, 6, 212, },
  118. { 39, 7, 86, 28, 49, 11, 102, 36, },
  119. { 1, 158, 0, 131, 3, 180, 1, 151, },
  120. { 68, 19, 52, 12, 81, 25, 64, 17, },
  121. { 0, 119, 5, 203, 0, 113, 4, 195, },
  122. { 45, 9, 96, 33, 42, 8, 91, 30, },
  123. { 2, 172, 1, 144, 2, 165, 0, 137, },
  124. { 77, 23, 60, 15, 72, 21, 56, 14, },
  125. { 0, 107, 3, 187, 0, 125, 6, 212, },
  126. };
  127. #endif
  128. #define output_pixel(pos, val, bias, signedness) \
  129. if (big_endian) { \
  130. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  131. } else { \
  132. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  133. }
  134. static av_always_inline void
  135. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  136. int big_endian, int output_bits)
  137. {
  138. int i;
  139. int shift = 3;
  140. av_assert0(output_bits == 16);
  141. for (i = 0; i < dstW; i++) {
  142. int val = src[i] + (1 << (shift - 1));
  143. output_pixel(&dest[i], val, 0, uint);
  144. }
  145. }
  146. static av_always_inline void
  147. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  148. const int32_t **src, uint16_t *dest, int dstW,
  149. int big_endian, int output_bits)
  150. {
  151. int i;
  152. int shift = 15;
  153. av_assert0(output_bits == 16);
  154. for (i = 0; i < dstW; i++) {
  155. int val = 1 << (shift - 1);
  156. int j;
  157. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  158. * filters (or anything with negative coeffs, the range can be slightly
  159. * wider in both directions. To account for this overflow, we subtract
  160. * a constant so it always fits in the signed range (assuming a
  161. * reasonable filterSize), and re-add that at the end. */
  162. val -= 0x40000000;
  163. for (j = 0; j < filterSize; j++)
  164. val += src[j][i] * (unsigned)filter[j];
  165. output_pixel(&dest[i], val, 0x8000, int);
  166. }
  167. }
  168. #undef output_pixel
  169. #define output_pixel(pos, val) \
  170. if (big_endian) { \
  171. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  172. } else { \
  173. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  174. }
  175. static av_always_inline void
  176. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  177. int big_endian, int output_bits)
  178. {
  179. int i;
  180. int shift = 15 - output_bits;
  181. for (i = 0; i < dstW; i++) {
  182. int val = src[i] + (1 << (shift - 1));
  183. output_pixel(&dest[i], val);
  184. }
  185. }
  186. static av_always_inline void
  187. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  188. const int16_t **src, uint16_t *dest, int dstW,
  189. int big_endian, int output_bits)
  190. {
  191. int i;
  192. int shift = 11 + 16 - output_bits;
  193. for (i = 0; i < dstW; i++) {
  194. int val = 1 << (shift - 1);
  195. int j;
  196. for (j = 0; j < filterSize; j++)
  197. val += src[j][i] * filter[j];
  198. output_pixel(&dest[i], val);
  199. }
  200. }
  201. #undef output_pixel
  202. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  203. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  204. uint8_t *dest, int dstW, \
  205. const uint8_t *dither, int offset)\
  206. { \
  207. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  208. (uint16_t *) dest, dstW, is_be, bits); \
  209. }\
  210. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  211. const int16_t **src, uint8_t *dest, int dstW, \
  212. const uint8_t *dither, int offset)\
  213. { \
  214. yuv2planeX_## template_size ## _c_template(filter, \
  215. filterSize, (const typeX_t **) src, \
  216. (uint16_t *) dest, dstW, is_be, bits); \
  217. }
  218. yuv2NBPS( 9, BE, 1, 10, int16_t)
  219. yuv2NBPS( 9, LE, 0, 10, int16_t)
  220. yuv2NBPS(10, BE, 1, 10, int16_t)
  221. yuv2NBPS(10, LE, 0, 10, int16_t)
  222. yuv2NBPS(12, BE, 1, 10, int16_t)
  223. yuv2NBPS(12, LE, 0, 10, int16_t)
  224. yuv2NBPS(14, BE, 1, 10, int16_t)
  225. yuv2NBPS(14, LE, 0, 10, int16_t)
  226. yuv2NBPS(16, BE, 1, 16, int32_t)
  227. yuv2NBPS(16, LE, 0, 16, int32_t)
  228. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  229. const int16_t **src, uint8_t *dest, int dstW,
  230. const uint8_t *dither, int offset)
  231. {
  232. int i;
  233. for (i=0; i<dstW; i++) {
  234. int val = dither[(i + offset) & 7] << 12;
  235. int j;
  236. for (j=0; j<filterSize; j++)
  237. val += src[j][i] * filter[j];
  238. dest[i]= av_clip_uint8(val>>19);
  239. }
  240. }
  241. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  242. const uint8_t *dither, int offset)
  243. {
  244. int i;
  245. for (i=0; i<dstW; i++) {
  246. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  247. dest[i]= av_clip_uint8(val);
  248. }
  249. }
  250. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  251. const int16_t **chrUSrc, const int16_t **chrVSrc,
  252. uint8_t *dest, int chrDstW)
  253. {
  254. enum AVPixelFormat dstFormat = c->dstFormat;
  255. const uint8_t *chrDither = c->chrDither8;
  256. int i;
  257. if (dstFormat == AV_PIX_FMT_NV12)
  258. for (i=0; i<chrDstW; i++) {
  259. int u = chrDither[i & 7] << 12;
  260. int v = chrDither[(i + 3) & 7] << 12;
  261. int j;
  262. for (j=0; j<chrFilterSize; j++) {
  263. u += chrUSrc[j][i] * chrFilter[j];
  264. v += chrVSrc[j][i] * chrFilter[j];
  265. }
  266. dest[2*i]= av_clip_uint8(u>>19);
  267. dest[2*i+1]= av_clip_uint8(v>>19);
  268. }
  269. else
  270. for (i=0; i<chrDstW; i++) {
  271. int u = chrDither[i & 7] << 12;
  272. int v = chrDither[(i + 3) & 7] << 12;
  273. int j;
  274. for (j=0; j<chrFilterSize; j++) {
  275. u += chrUSrc[j][i] * chrFilter[j];
  276. v += chrVSrc[j][i] * chrFilter[j];
  277. }
  278. dest[2*i]= av_clip_uint8(v>>19);
  279. dest[2*i+1]= av_clip_uint8(u>>19);
  280. }
  281. }
  282. #define accumulate_bit(acc, val) \
  283. acc <<= 1; \
  284. acc |= (val) >= (128 + 110)
  285. #define output_pixel(pos, acc) \
  286. if (target == AV_PIX_FMT_MONOBLACK) { \
  287. pos = acc; \
  288. } else { \
  289. pos = ~acc; \
  290. }
  291. static av_always_inline void
  292. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  293. const int16_t **lumSrc, int lumFilterSize,
  294. const int16_t *chrFilter, const int16_t **chrUSrc,
  295. const int16_t **chrVSrc, int chrFilterSize,
  296. const int16_t **alpSrc, uint8_t *dest, int dstW,
  297. int y, enum AVPixelFormat target)
  298. {
  299. const uint8_t * const d128=dither_8x8_220[y&7];
  300. int i;
  301. unsigned acc = 0;
  302. for (i = 0; i < dstW; i += 2) {
  303. int j;
  304. int Y1 = 1 << 18;
  305. int Y2 = 1 << 18;
  306. for (j = 0; j < lumFilterSize; j++) {
  307. Y1 += lumSrc[j][i] * lumFilter[j];
  308. Y2 += lumSrc[j][i+1] * lumFilter[j];
  309. }
  310. Y1 >>= 19;
  311. Y2 >>= 19;
  312. if ((Y1 | Y2) & 0x100) {
  313. Y1 = av_clip_uint8(Y1);
  314. Y2 = av_clip_uint8(Y2);
  315. }
  316. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  317. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  318. if ((i & 7) == 6) {
  319. output_pixel(*dest++, acc);
  320. }
  321. }
  322. if (i & 6) {
  323. output_pixel(*dest, acc);
  324. }
  325. }
  326. static av_always_inline void
  327. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  328. const int16_t *ubuf[2], const int16_t *vbuf[2],
  329. const int16_t *abuf[2], uint8_t *dest, int dstW,
  330. int yalpha, int uvalpha, int y,
  331. enum AVPixelFormat target)
  332. {
  333. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  334. const uint8_t * const d128 = dither_8x8_220[y & 7];
  335. int yalpha1 = 4096 - yalpha;
  336. int i;
  337. for (i = 0; i < dstW; i += 8) {
  338. int Y, acc = 0;
  339. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  340. accumulate_bit(acc, Y + d128[0]);
  341. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  342. accumulate_bit(acc, Y + d128[1]);
  343. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  344. accumulate_bit(acc, Y + d128[2]);
  345. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  346. accumulate_bit(acc, Y + d128[3]);
  347. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  348. accumulate_bit(acc, Y + d128[4]);
  349. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  350. accumulate_bit(acc, Y + d128[5]);
  351. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  352. accumulate_bit(acc, Y + d128[6]);
  353. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  354. accumulate_bit(acc, Y + d128[7]);
  355. output_pixel(*dest++, acc);
  356. }
  357. }
  358. static av_always_inline void
  359. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  360. const int16_t *ubuf[2], const int16_t *vbuf[2],
  361. const int16_t *abuf0, uint8_t *dest, int dstW,
  362. int uvalpha, int y, enum AVPixelFormat target)
  363. {
  364. const uint8_t * const d128 = dither_8x8_220[y & 7];
  365. int i;
  366. for (i = 0; i < dstW; i += 8) {
  367. int acc = 0;
  368. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  369. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  370. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  371. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  372. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  373. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  374. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  375. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  376. output_pixel(*dest++, acc);
  377. }
  378. }
  379. #undef output_pixel
  380. #undef accumulate_bit
  381. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  382. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  383. const int16_t **lumSrc, int lumFilterSize, \
  384. const int16_t *chrFilter, const int16_t **chrUSrc, \
  385. const int16_t **chrVSrc, int chrFilterSize, \
  386. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  387. int y) \
  388. { \
  389. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  390. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  391. alpSrc, dest, dstW, y, fmt); \
  392. } \
  393. \
  394. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  395. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  396. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  397. int yalpha, int uvalpha, int y) \
  398. { \
  399. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  400. dest, dstW, yalpha, uvalpha, y, fmt); \
  401. } \
  402. \
  403. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  404. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  405. const int16_t *abuf0, uint8_t *dest, int dstW, \
  406. int uvalpha, int y) \
  407. { \
  408. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  409. abuf0, dest, dstW, uvalpha, \
  410. y, fmt); \
  411. }
  412. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  413. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  414. #define output_pixels(pos, Y1, U, Y2, V) \
  415. if (target == AV_PIX_FMT_YUYV422) { \
  416. dest[pos + 0] = Y1; \
  417. dest[pos + 1] = U; \
  418. dest[pos + 2] = Y2; \
  419. dest[pos + 3] = V; \
  420. } else { \
  421. dest[pos + 0] = U; \
  422. dest[pos + 1] = Y1; \
  423. dest[pos + 2] = V; \
  424. dest[pos + 3] = Y2; \
  425. }
  426. static av_always_inline void
  427. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  428. const int16_t **lumSrc, int lumFilterSize,
  429. const int16_t *chrFilter, const int16_t **chrUSrc,
  430. const int16_t **chrVSrc, int chrFilterSize,
  431. const int16_t **alpSrc, uint8_t *dest, int dstW,
  432. int y, enum AVPixelFormat target)
  433. {
  434. int i;
  435. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  436. int j;
  437. int Y1 = 1 << 18;
  438. int Y2 = 1 << 18;
  439. int U = 1 << 18;
  440. int V = 1 << 18;
  441. for (j = 0; j < lumFilterSize; j++) {
  442. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  443. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  444. }
  445. for (j = 0; j < chrFilterSize; j++) {
  446. U += chrUSrc[j][i] * chrFilter[j];
  447. V += chrVSrc[j][i] * chrFilter[j];
  448. }
  449. Y1 >>= 19;
  450. Y2 >>= 19;
  451. U >>= 19;
  452. V >>= 19;
  453. if ((Y1 | Y2 | U | V) & 0x100) {
  454. Y1 = av_clip_uint8(Y1);
  455. Y2 = av_clip_uint8(Y2);
  456. U = av_clip_uint8(U);
  457. V = av_clip_uint8(V);
  458. }
  459. output_pixels(4*i, Y1, U, Y2, V);
  460. }
  461. }
  462. static av_always_inline void
  463. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  464. const int16_t *ubuf[2], const int16_t *vbuf[2],
  465. const int16_t *abuf[2], uint8_t *dest, int dstW,
  466. int yalpha, int uvalpha, int y,
  467. enum AVPixelFormat target)
  468. {
  469. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  470. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  471. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  472. int yalpha1 = 4096 - yalpha;
  473. int uvalpha1 = 4096 - uvalpha;
  474. int i;
  475. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  476. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  477. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  478. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  479. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  480. if ((Y1 | Y2 | U | V) & 0x100) {
  481. Y1 = av_clip_uint8(Y1);
  482. Y2 = av_clip_uint8(Y2);
  483. U = av_clip_uint8(U);
  484. V = av_clip_uint8(V);
  485. }
  486. output_pixels(i * 4, Y1, U, Y2, V);
  487. }
  488. }
  489. static av_always_inline void
  490. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  491. const int16_t *ubuf[2], const int16_t *vbuf[2],
  492. const int16_t *abuf0, uint8_t *dest, int dstW,
  493. int uvalpha, int y, enum AVPixelFormat target)
  494. {
  495. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  496. int i;
  497. if (uvalpha < 2048) {
  498. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  499. int Y1 = (buf0[i * 2 ]+64) >> 7;
  500. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  501. int U = (ubuf0[i] +64) >> 7;
  502. int V = (vbuf0[i] +64) >> 7;
  503. if ((Y1 | Y2 | U | V) & 0x100) {
  504. Y1 = av_clip_uint8(Y1);
  505. Y2 = av_clip_uint8(Y2);
  506. U = av_clip_uint8(U);
  507. V = av_clip_uint8(V);
  508. }
  509. Y1 = av_clip_uint8(Y1);
  510. Y2 = av_clip_uint8(Y2);
  511. U = av_clip_uint8(U);
  512. V = av_clip_uint8(V);
  513. output_pixels(i * 4, Y1, U, Y2, V);
  514. }
  515. } else {
  516. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  517. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  518. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  519. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  520. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  521. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  522. if ((Y1 | Y2 | U | V) & 0x100) {
  523. Y1 = av_clip_uint8(Y1);
  524. Y2 = av_clip_uint8(Y2);
  525. U = av_clip_uint8(U);
  526. V = av_clip_uint8(V);
  527. }
  528. Y1 = av_clip_uint8(Y1);
  529. Y2 = av_clip_uint8(Y2);
  530. U = av_clip_uint8(U);
  531. V = av_clip_uint8(V);
  532. output_pixels(i * 4, Y1, U, Y2, V);
  533. }
  534. }
  535. }
  536. #undef output_pixels
  537. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  538. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  539. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? R : B)
  540. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? B : R)
  541. #define output_pixel(pos, val) \
  542. if (isBE(target)) { \
  543. AV_WB16(pos, val); \
  544. } else { \
  545. AV_WL16(pos, val); \
  546. }
  547. static av_always_inline void
  548. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  549. const int32_t **lumSrc, int lumFilterSize,
  550. const int16_t *chrFilter, const int32_t **chrUSrc,
  551. const int32_t **chrVSrc, int chrFilterSize,
  552. const int32_t **alpSrc, uint16_t *dest, int dstW,
  553. int y, enum AVPixelFormat target)
  554. {
  555. int i;
  556. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  557. int j;
  558. int Y1 = -0x40000000;
  559. int Y2 = -0x40000000;
  560. int U = -128 << 23; // 19
  561. int V = -128 << 23;
  562. int R, G, B;
  563. for (j = 0; j < lumFilterSize; j++) {
  564. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  565. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  566. }
  567. for (j = 0; j < chrFilterSize; j++) {;
  568. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  569. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  570. }
  571. // 8bit: 12+15=27; 16-bit: 12+19=31
  572. Y1 >>= 14; // 10
  573. Y1 += 0x10000;
  574. Y2 >>= 14;
  575. Y2 += 0x10000;
  576. U >>= 14;
  577. V >>= 14;
  578. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  579. Y1 -= c->yuv2rgb_y_offset;
  580. Y2 -= c->yuv2rgb_y_offset;
  581. Y1 *= c->yuv2rgb_y_coeff;
  582. Y2 *= c->yuv2rgb_y_coeff;
  583. Y1 += 1 << 13; // 21
  584. Y2 += 1 << 13;
  585. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  586. R = V * c->yuv2rgb_v2r_coeff;
  587. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  588. B = U * c->yuv2rgb_u2b_coeff;
  589. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  590. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  591. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  592. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  593. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  594. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  595. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  596. dest += 6;
  597. }
  598. }
  599. static av_always_inline void
  600. yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
  601. const int32_t *ubuf[2], const int32_t *vbuf[2],
  602. const int32_t *abuf[2], uint16_t *dest, int dstW,
  603. int yalpha, int uvalpha, int y,
  604. enum AVPixelFormat target)
  605. {
  606. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  607. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  608. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  609. int yalpha1 = 4096 - yalpha;
  610. int uvalpha1 = 4096 - uvalpha;
  611. int i;
  612. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  613. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  614. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  615. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  616. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  617. int R, G, B;
  618. Y1 -= c->yuv2rgb_y_offset;
  619. Y2 -= c->yuv2rgb_y_offset;
  620. Y1 *= c->yuv2rgb_y_coeff;
  621. Y2 *= c->yuv2rgb_y_coeff;
  622. Y1 += 1 << 13;
  623. Y2 += 1 << 13;
  624. R = V * c->yuv2rgb_v2r_coeff;
  625. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  626. B = U * c->yuv2rgb_u2b_coeff;
  627. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  628. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  629. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  630. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  631. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  632. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  633. dest += 6;
  634. }
  635. }
  636. static av_always_inline void
  637. yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
  638. const int32_t *ubuf[2], const int32_t *vbuf[2],
  639. const int32_t *abuf0, uint16_t *dest, int dstW,
  640. int uvalpha, int y, enum AVPixelFormat target)
  641. {
  642. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  643. int i;
  644. if (uvalpha < 2048) {
  645. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  646. int Y1 = (buf0[i * 2] ) >> 2;
  647. int Y2 = (buf0[i * 2 + 1]) >> 2;
  648. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  649. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  650. int R, G, B;
  651. Y1 -= c->yuv2rgb_y_offset;
  652. Y2 -= c->yuv2rgb_y_offset;
  653. Y1 *= c->yuv2rgb_y_coeff;
  654. Y2 *= c->yuv2rgb_y_coeff;
  655. Y1 += 1 << 13;
  656. Y2 += 1 << 13;
  657. R = V * c->yuv2rgb_v2r_coeff;
  658. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  659. B = U * c->yuv2rgb_u2b_coeff;
  660. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  661. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  662. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  663. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  664. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  665. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  666. dest += 6;
  667. }
  668. } else {
  669. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  670. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  671. int Y1 = (buf0[i * 2] ) >> 2;
  672. int Y2 = (buf0[i * 2 + 1]) >> 2;
  673. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  674. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  675. int R, G, B;
  676. Y1 -= c->yuv2rgb_y_offset;
  677. Y2 -= c->yuv2rgb_y_offset;
  678. Y1 *= c->yuv2rgb_y_coeff;
  679. Y2 *= c->yuv2rgb_y_coeff;
  680. Y1 += 1 << 13;
  681. Y2 += 1 << 13;
  682. R = V * c->yuv2rgb_v2r_coeff;
  683. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  684. B = U * c->yuv2rgb_u2b_coeff;
  685. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  686. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  687. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  688. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  689. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  690. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  691. dest += 6;
  692. }
  693. }
  694. }
  695. #undef output_pixel
  696. #undef r_b
  697. #undef b_r
  698. #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
  699. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  700. const int16_t **_lumSrc, int lumFilterSize, \
  701. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  702. const int16_t **_chrVSrc, int chrFilterSize, \
  703. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  704. int y) \
  705. { \
  706. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  707. **chrUSrc = (const int32_t **) _chrUSrc, \
  708. **chrVSrc = (const int32_t **) _chrVSrc, \
  709. **alpSrc = (const int32_t **) _alpSrc; \
  710. uint16_t *dest = (uint16_t *) _dest; \
  711. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  712. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  713. alpSrc, dest, dstW, y, fmt); \
  714. } \
  715. \
  716. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  717. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  718. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  719. int yalpha, int uvalpha, int y) \
  720. { \
  721. const int32_t **buf = (const int32_t **) _buf, \
  722. **ubuf = (const int32_t **) _ubuf, \
  723. **vbuf = (const int32_t **) _vbuf, \
  724. **abuf = (const int32_t **) _abuf; \
  725. uint16_t *dest = (uint16_t *) _dest; \
  726. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  727. dest, dstW, yalpha, uvalpha, y, fmt); \
  728. } \
  729. \
  730. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  731. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  732. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  733. int uvalpha, int y) \
  734. { \
  735. const int32_t *buf0 = (const int32_t *) _buf0, \
  736. **ubuf = (const int32_t **) _ubuf, \
  737. **vbuf = (const int32_t **) _vbuf, \
  738. *abuf0 = (const int32_t *) _abuf0; \
  739. uint16_t *dest = (uint16_t *) _dest; \
  740. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  741. dstW, uvalpha, y, fmt); \
  742. }
  743. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE)
  744. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE)
  745. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE)
  746. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE)
  747. /*
  748. * Write out 2 RGB pixels in the target pixel format. This function takes a
  749. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  750. * things like endianness conversion and shifting. The caller takes care of
  751. * setting the correct offset in these tables from the chroma (U/V) values.
  752. * This function then uses the luminance (Y1/Y2) values to write out the
  753. * correct RGB values into the destination buffer.
  754. */
  755. static av_always_inline void
  756. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  757. unsigned A1, unsigned A2,
  758. const void *_r, const void *_g, const void *_b, int y,
  759. enum AVPixelFormat target, int hasAlpha)
  760. {
  761. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  762. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  763. uint32_t *dest = (uint32_t *) _dest;
  764. const uint32_t *r = (const uint32_t *) _r;
  765. const uint32_t *g = (const uint32_t *) _g;
  766. const uint32_t *b = (const uint32_t *) _b;
  767. #if CONFIG_SMALL
  768. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  769. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  770. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  771. #else
  772. if (hasAlpha) {
  773. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  774. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  775. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  776. } else {
  777. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  778. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  779. }
  780. #endif
  781. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  782. uint8_t *dest = (uint8_t *) _dest;
  783. const uint8_t *r = (const uint8_t *) _r;
  784. const uint8_t *g = (const uint8_t *) _g;
  785. const uint8_t *b = (const uint8_t *) _b;
  786. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  787. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  788. dest[i * 6 + 0] = r_b[Y1];
  789. dest[i * 6 + 1] = g[Y1];
  790. dest[i * 6 + 2] = b_r[Y1];
  791. dest[i * 6 + 3] = r_b[Y2];
  792. dest[i * 6 + 4] = g[Y2];
  793. dest[i * 6 + 5] = b_r[Y2];
  794. #undef r_b
  795. #undef b_r
  796. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  797. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  798. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  799. uint16_t *dest = (uint16_t *) _dest;
  800. const uint16_t *r = (const uint16_t *) _r;
  801. const uint16_t *g = (const uint16_t *) _g;
  802. const uint16_t *b = (const uint16_t *) _b;
  803. int dr1, dg1, db1, dr2, dg2, db2;
  804. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  805. dr1 = dither_2x2_8[ y & 1 ][0];
  806. dg1 = dither_2x2_4[ y & 1 ][0];
  807. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  808. dr2 = dither_2x2_8[ y & 1 ][1];
  809. dg2 = dither_2x2_4[ y & 1 ][1];
  810. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  811. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  812. dr1 = dither_2x2_8[ y & 1 ][0];
  813. dg1 = dither_2x2_8[ y & 1 ][1];
  814. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  815. dr2 = dither_2x2_8[ y & 1 ][1];
  816. dg2 = dither_2x2_8[ y & 1 ][0];
  817. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  818. } else {
  819. dr1 = dither_4x4_16[ y & 3 ][0];
  820. dg1 = dither_4x4_16[ y & 3 ][1];
  821. db1 = dither_4x4_16[(y & 3) ^ 3][0];
  822. dr2 = dither_4x4_16[ y & 3 ][1];
  823. dg2 = dither_4x4_16[ y & 3 ][0];
  824. db2 = dither_4x4_16[(y & 3) ^ 3][1];
  825. }
  826. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  827. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  828. } else /* 8/4-bit */ {
  829. uint8_t *dest = (uint8_t *) _dest;
  830. const uint8_t *r = (const uint8_t *) _r;
  831. const uint8_t *g = (const uint8_t *) _g;
  832. const uint8_t *b = (const uint8_t *) _b;
  833. int dr1, dg1, db1, dr2, dg2, db2;
  834. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  835. const uint8_t * const d64 = dither_8x8_73[y & 7];
  836. const uint8_t * const d32 = dither_8x8_32[y & 7];
  837. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  838. db1 = d64[(i * 2 + 0) & 7];
  839. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  840. db2 = d64[(i * 2 + 1) & 7];
  841. } else {
  842. const uint8_t * const d64 = dither_8x8_73 [y & 7];
  843. const uint8_t * const d128 = dither_8x8_220[y & 7];
  844. dr1 = db1 = d128[(i * 2 + 0) & 7];
  845. dg1 = d64[(i * 2 + 0) & 7];
  846. dr2 = db2 = d128[(i * 2 + 1) & 7];
  847. dg2 = d64[(i * 2 + 1) & 7];
  848. }
  849. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  850. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  851. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  852. } else {
  853. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  854. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  855. }
  856. }
  857. }
  858. static av_always_inline void
  859. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  860. const int16_t **lumSrc, int lumFilterSize,
  861. const int16_t *chrFilter, const int16_t **chrUSrc,
  862. const int16_t **chrVSrc, int chrFilterSize,
  863. const int16_t **alpSrc, uint8_t *dest, int dstW,
  864. int y, enum AVPixelFormat target, int hasAlpha)
  865. {
  866. int i;
  867. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  868. int j, A1, A2;
  869. int Y1 = 1 << 18;
  870. int Y2 = 1 << 18;
  871. int U = 1 << 18;
  872. int V = 1 << 18;
  873. const void *r, *g, *b;
  874. for (j = 0; j < lumFilterSize; j++) {
  875. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  876. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  877. }
  878. for (j = 0; j < chrFilterSize; j++) {
  879. U += chrUSrc[j][i] * chrFilter[j];
  880. V += chrVSrc[j][i] * chrFilter[j];
  881. }
  882. Y1 >>= 19;
  883. Y2 >>= 19;
  884. U >>= 19;
  885. V >>= 19;
  886. if (hasAlpha) {
  887. A1 = 1 << 18;
  888. A2 = 1 << 18;
  889. for (j = 0; j < lumFilterSize; j++) {
  890. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  891. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  892. }
  893. A1 >>= 19;
  894. A2 >>= 19;
  895. if ((A1 | A2) & 0x100) {
  896. A1 = av_clip_uint8(A1);
  897. A2 = av_clip_uint8(A2);
  898. }
  899. }
  900. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  901. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  902. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  903. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  904. r, g, b, y, target, hasAlpha);
  905. }
  906. }
  907. static av_always_inline void
  908. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  909. const int16_t *ubuf[2], const int16_t *vbuf[2],
  910. const int16_t *abuf[2], uint8_t *dest, int dstW,
  911. int yalpha, int uvalpha, int y,
  912. enum AVPixelFormat target, int hasAlpha)
  913. {
  914. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  915. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  916. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  917. *abuf0 = hasAlpha ? abuf[0] : NULL,
  918. *abuf1 = hasAlpha ? abuf[1] : NULL;
  919. int yalpha1 = 4096 - yalpha;
  920. int uvalpha1 = 4096 - uvalpha;
  921. int i;
  922. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  923. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  924. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  925. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  926. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  927. int A1, A2;
  928. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  929. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  930. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  931. if (hasAlpha) {
  932. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  933. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  934. A1 = av_clip_uint8(A1);
  935. A2 = av_clip_uint8(A2);
  936. }
  937. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  938. r, g, b, y, target, hasAlpha);
  939. }
  940. }
  941. static av_always_inline void
  942. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  943. const int16_t *ubuf[2], const int16_t *vbuf[2],
  944. const int16_t *abuf0, uint8_t *dest, int dstW,
  945. int uvalpha, int y, enum AVPixelFormat target,
  946. int hasAlpha)
  947. {
  948. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  949. int i;
  950. if (uvalpha < 2048) {
  951. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  952. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  953. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  954. int U = (ubuf0[i] + 64) >> 7;
  955. int V = (vbuf0[i] + 64) >> 7;
  956. int A1, A2;
  957. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  958. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  959. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  960. if (hasAlpha) {
  961. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  962. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  963. A1 = av_clip_uint8(A1);
  964. A2 = av_clip_uint8(A2);
  965. }
  966. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  967. r, g, b, y, target, hasAlpha);
  968. }
  969. } else {
  970. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  971. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  972. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  973. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  974. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  975. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  976. int A1, A2;
  977. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  978. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  979. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  980. if (hasAlpha) {
  981. A1 = (abuf0[i * 2 ] + 64) >> 7;
  982. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  983. A1 = av_clip_uint8(A1);
  984. A2 = av_clip_uint8(A2);
  985. }
  986. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  987. r, g, b, y, target, hasAlpha);
  988. }
  989. }
  990. }
  991. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  992. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  993. const int16_t **lumSrc, int lumFilterSize, \
  994. const int16_t *chrFilter, const int16_t **chrUSrc, \
  995. const int16_t **chrVSrc, int chrFilterSize, \
  996. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  997. int y) \
  998. { \
  999. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1000. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1001. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1002. }
  1003. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1004. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1005. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1006. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1007. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1008. int yalpha, int uvalpha, int y) \
  1009. { \
  1010. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1011. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1012. } \
  1013. \
  1014. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1015. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1016. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1017. int uvalpha, int y) \
  1018. { \
  1019. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1020. dstW, uvalpha, y, fmt, hasAlpha); \
  1021. }
  1022. #if CONFIG_SMALL
  1023. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1024. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1025. #else
  1026. #if CONFIG_SWSCALE_ALPHA
  1027. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1028. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1029. #endif
  1030. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1031. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1032. #endif
  1033. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1034. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1035. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1036. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1037. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1038. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1039. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1040. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1041. static av_always_inline void
  1042. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1043. const int16_t **lumSrc, int lumFilterSize,
  1044. const int16_t *chrFilter, const int16_t **chrUSrc,
  1045. const int16_t **chrVSrc, int chrFilterSize,
  1046. const int16_t **alpSrc, uint8_t *dest,
  1047. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1048. {
  1049. int i;
  1050. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1051. for (i = 0; i < dstW; i++) {
  1052. int j;
  1053. int Y = 1<<9;
  1054. int U = (1<<9)-(128 << 19);
  1055. int V = (1<<9)-(128 << 19);
  1056. int R, G, B, A;
  1057. for (j = 0; j < lumFilterSize; j++) {
  1058. Y += lumSrc[j][i] * lumFilter[j];
  1059. }
  1060. for (j = 0; j < chrFilterSize; j++) {
  1061. U += chrUSrc[j][i] * chrFilter[j];
  1062. V += chrVSrc[j][i] * chrFilter[j];
  1063. }
  1064. Y >>= 10;
  1065. U >>= 10;
  1066. V >>= 10;
  1067. if (hasAlpha) {
  1068. A = 1 << 18;
  1069. for (j = 0; j < lumFilterSize; j++) {
  1070. A += alpSrc[j][i] * lumFilter[j];
  1071. }
  1072. A >>= 19;
  1073. if (A & 0x100)
  1074. A = av_clip_uint8(A);
  1075. }
  1076. Y -= c->yuv2rgb_y_offset;
  1077. Y *= c->yuv2rgb_y_coeff;
  1078. Y += 1 << 21;
  1079. R = Y + V*c->yuv2rgb_v2r_coeff;
  1080. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1081. B = Y + U*c->yuv2rgb_u2b_coeff;
  1082. if ((R | G | B) & 0xC0000000) {
  1083. R = av_clip_uintp2(R, 30);
  1084. G = av_clip_uintp2(G, 30);
  1085. B = av_clip_uintp2(B, 30);
  1086. }
  1087. switch(target) {
  1088. case AV_PIX_FMT_ARGB:
  1089. dest[0] = hasAlpha ? A : 255;
  1090. dest[1] = R >> 22;
  1091. dest[2] = G >> 22;
  1092. dest[3] = B >> 22;
  1093. break;
  1094. case AV_PIX_FMT_RGB24:
  1095. dest[0] = R >> 22;
  1096. dest[1] = G >> 22;
  1097. dest[2] = B >> 22;
  1098. break;
  1099. case AV_PIX_FMT_RGBA:
  1100. dest[0] = R >> 22;
  1101. dest[1] = G >> 22;
  1102. dest[2] = B >> 22;
  1103. dest[3] = hasAlpha ? A : 255;
  1104. break;
  1105. case AV_PIX_FMT_ABGR:
  1106. dest[0] = hasAlpha ? A : 255;
  1107. dest[1] = B >> 22;
  1108. dest[2] = G >> 22;
  1109. dest[3] = R >> 22;
  1110. break;
  1111. case AV_PIX_FMT_BGR24:
  1112. dest[0] = B >> 22;
  1113. dest[1] = G >> 22;
  1114. dest[2] = R >> 22;
  1115. break;
  1116. case AV_PIX_FMT_BGRA:
  1117. dest[0] = B >> 22;
  1118. dest[1] = G >> 22;
  1119. dest[2] = R >> 22;
  1120. dest[3] = hasAlpha ? A : 255;
  1121. break;
  1122. }
  1123. dest += step;
  1124. }
  1125. }
  1126. #if CONFIG_SMALL
  1127. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1128. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1129. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1130. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1131. #else
  1132. #if CONFIG_SWSCALE_ALPHA
  1133. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1134. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1135. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1136. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1137. #endif
  1138. YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1139. YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1140. YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1141. YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1142. #endif
  1143. YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1144. YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1145. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1146. yuv2planar1_fn *yuv2plane1,
  1147. yuv2planarX_fn *yuv2planeX,
  1148. yuv2interleavedX_fn *yuv2nv12cX,
  1149. yuv2packed1_fn *yuv2packed1,
  1150. yuv2packed2_fn *yuv2packed2,
  1151. yuv2packedX_fn *yuv2packedX)
  1152. {
  1153. enum AVPixelFormat dstFormat = c->dstFormat;
  1154. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  1155. if (is16BPS(dstFormat)) {
  1156. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1157. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1158. } else if (is9_OR_10BPS(dstFormat)) {
  1159. if (desc->comp[0].depth_minus1 == 8) {
  1160. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1161. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1162. } else if (desc->comp[0].depth_minus1 == 9) {
  1163. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1164. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1165. } else if (desc->comp[0].depth_minus1 == 11) {
  1166. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  1167. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  1168. } else if (desc->comp[0].depth_minus1 == 13) {
  1169. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  1170. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  1171. } else
  1172. av_assert0(0);
  1173. } else {
  1174. *yuv2plane1 = yuv2plane1_8_c;
  1175. *yuv2planeX = yuv2planeX_8_c;
  1176. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  1177. *yuv2nv12cX = yuv2nv12cX_c;
  1178. }
  1179. if(c->flags & SWS_FULL_CHR_H_INT) {
  1180. switch (dstFormat) {
  1181. case AV_PIX_FMT_RGBA:
  1182. #if CONFIG_SMALL
  1183. *yuv2packedX = yuv2rgba32_full_X_c;
  1184. #else
  1185. #if CONFIG_SWSCALE_ALPHA
  1186. if (c->alpPixBuf) {
  1187. *yuv2packedX = yuv2rgba32_full_X_c;
  1188. } else
  1189. #endif /* CONFIG_SWSCALE_ALPHA */
  1190. {
  1191. *yuv2packedX = yuv2rgbx32_full_X_c;
  1192. }
  1193. #endif /* !CONFIG_SMALL */
  1194. break;
  1195. case AV_PIX_FMT_ARGB:
  1196. #if CONFIG_SMALL
  1197. *yuv2packedX = yuv2argb32_full_X_c;
  1198. #else
  1199. #if CONFIG_SWSCALE_ALPHA
  1200. if (c->alpPixBuf) {
  1201. *yuv2packedX = yuv2argb32_full_X_c;
  1202. } else
  1203. #endif /* CONFIG_SWSCALE_ALPHA */
  1204. {
  1205. *yuv2packedX = yuv2xrgb32_full_X_c;
  1206. }
  1207. #endif /* !CONFIG_SMALL */
  1208. break;
  1209. case AV_PIX_FMT_BGRA:
  1210. #if CONFIG_SMALL
  1211. *yuv2packedX = yuv2bgra32_full_X_c;
  1212. #else
  1213. #if CONFIG_SWSCALE_ALPHA
  1214. if (c->alpPixBuf) {
  1215. *yuv2packedX = yuv2bgra32_full_X_c;
  1216. } else
  1217. #endif /* CONFIG_SWSCALE_ALPHA */
  1218. {
  1219. *yuv2packedX = yuv2bgrx32_full_X_c;
  1220. }
  1221. #endif /* !CONFIG_SMALL */
  1222. break;
  1223. case AV_PIX_FMT_ABGR:
  1224. #if CONFIG_SMALL
  1225. *yuv2packedX = yuv2abgr32_full_X_c;
  1226. #else
  1227. #if CONFIG_SWSCALE_ALPHA
  1228. if (c->alpPixBuf) {
  1229. *yuv2packedX = yuv2abgr32_full_X_c;
  1230. } else
  1231. #endif /* CONFIG_SWSCALE_ALPHA */
  1232. {
  1233. *yuv2packedX = yuv2xbgr32_full_X_c;
  1234. }
  1235. #endif /* !CONFIG_SMALL */
  1236. break;
  1237. case AV_PIX_FMT_RGB24:
  1238. *yuv2packedX = yuv2rgb24_full_X_c;
  1239. break;
  1240. case AV_PIX_FMT_BGR24:
  1241. *yuv2packedX = yuv2bgr24_full_X_c;
  1242. break;
  1243. }
  1244. if(!*yuv2packedX)
  1245. goto YUV_PACKED;
  1246. } else {
  1247. YUV_PACKED:
  1248. switch (dstFormat) {
  1249. case AV_PIX_FMT_RGB48LE:
  1250. *yuv2packed1 = yuv2rgb48le_1_c;
  1251. *yuv2packed2 = yuv2rgb48le_2_c;
  1252. *yuv2packedX = yuv2rgb48le_X_c;
  1253. break;
  1254. case AV_PIX_FMT_RGB48BE:
  1255. *yuv2packed1 = yuv2rgb48be_1_c;
  1256. *yuv2packed2 = yuv2rgb48be_2_c;
  1257. *yuv2packedX = yuv2rgb48be_X_c;
  1258. break;
  1259. case AV_PIX_FMT_BGR48LE:
  1260. *yuv2packed1 = yuv2bgr48le_1_c;
  1261. *yuv2packed2 = yuv2bgr48le_2_c;
  1262. *yuv2packedX = yuv2bgr48le_X_c;
  1263. break;
  1264. case AV_PIX_FMT_BGR48BE:
  1265. *yuv2packed1 = yuv2bgr48be_1_c;
  1266. *yuv2packed2 = yuv2bgr48be_2_c;
  1267. *yuv2packedX = yuv2bgr48be_X_c;
  1268. break;
  1269. case AV_PIX_FMT_RGB32:
  1270. case AV_PIX_FMT_BGR32:
  1271. #if CONFIG_SMALL
  1272. *yuv2packed1 = yuv2rgb32_1_c;
  1273. *yuv2packed2 = yuv2rgb32_2_c;
  1274. *yuv2packedX = yuv2rgb32_X_c;
  1275. #else
  1276. #if CONFIG_SWSCALE_ALPHA
  1277. if (c->alpPixBuf) {
  1278. *yuv2packed1 = yuv2rgba32_1_c;
  1279. *yuv2packed2 = yuv2rgba32_2_c;
  1280. *yuv2packedX = yuv2rgba32_X_c;
  1281. } else
  1282. #endif /* CONFIG_SWSCALE_ALPHA */
  1283. {
  1284. *yuv2packed1 = yuv2rgbx32_1_c;
  1285. *yuv2packed2 = yuv2rgbx32_2_c;
  1286. *yuv2packedX = yuv2rgbx32_X_c;
  1287. }
  1288. #endif /* !CONFIG_SMALL */
  1289. break;
  1290. case AV_PIX_FMT_RGB32_1:
  1291. case AV_PIX_FMT_BGR32_1:
  1292. #if CONFIG_SMALL
  1293. *yuv2packed1 = yuv2rgb32_1_1_c;
  1294. *yuv2packed2 = yuv2rgb32_1_2_c;
  1295. *yuv2packedX = yuv2rgb32_1_X_c;
  1296. #else
  1297. #if CONFIG_SWSCALE_ALPHA
  1298. if (c->alpPixBuf) {
  1299. *yuv2packed1 = yuv2rgba32_1_1_c;
  1300. *yuv2packed2 = yuv2rgba32_1_2_c;
  1301. *yuv2packedX = yuv2rgba32_1_X_c;
  1302. } else
  1303. #endif /* CONFIG_SWSCALE_ALPHA */
  1304. {
  1305. *yuv2packed1 = yuv2rgbx32_1_1_c;
  1306. *yuv2packed2 = yuv2rgbx32_1_2_c;
  1307. *yuv2packedX = yuv2rgbx32_1_X_c;
  1308. }
  1309. #endif /* !CONFIG_SMALL */
  1310. break;
  1311. case AV_PIX_FMT_RGB24:
  1312. *yuv2packed1 = yuv2rgb24_1_c;
  1313. *yuv2packed2 = yuv2rgb24_2_c;
  1314. *yuv2packedX = yuv2rgb24_X_c;
  1315. break;
  1316. case AV_PIX_FMT_BGR24:
  1317. *yuv2packed1 = yuv2bgr24_1_c;
  1318. *yuv2packed2 = yuv2bgr24_2_c;
  1319. *yuv2packedX = yuv2bgr24_X_c;
  1320. break;
  1321. case AV_PIX_FMT_RGB565LE:
  1322. case AV_PIX_FMT_RGB565BE:
  1323. case AV_PIX_FMT_BGR565LE:
  1324. case AV_PIX_FMT_BGR565BE:
  1325. *yuv2packed1 = yuv2rgb16_1_c;
  1326. *yuv2packed2 = yuv2rgb16_2_c;
  1327. *yuv2packedX = yuv2rgb16_X_c;
  1328. break;
  1329. case AV_PIX_FMT_RGB555LE:
  1330. case AV_PIX_FMT_RGB555BE:
  1331. case AV_PIX_FMT_BGR555LE:
  1332. case AV_PIX_FMT_BGR555BE:
  1333. *yuv2packed1 = yuv2rgb15_1_c;
  1334. *yuv2packed2 = yuv2rgb15_2_c;
  1335. *yuv2packedX = yuv2rgb15_X_c;
  1336. break;
  1337. case AV_PIX_FMT_RGB444LE:
  1338. case AV_PIX_FMT_RGB444BE:
  1339. case AV_PIX_FMT_BGR444LE:
  1340. case AV_PIX_FMT_BGR444BE:
  1341. *yuv2packed1 = yuv2rgb12_1_c;
  1342. *yuv2packed2 = yuv2rgb12_2_c;
  1343. *yuv2packedX = yuv2rgb12_X_c;
  1344. break;
  1345. case AV_PIX_FMT_RGB8:
  1346. case AV_PIX_FMT_BGR8:
  1347. *yuv2packed1 = yuv2rgb8_1_c;
  1348. *yuv2packed2 = yuv2rgb8_2_c;
  1349. *yuv2packedX = yuv2rgb8_X_c;
  1350. break;
  1351. case AV_PIX_FMT_RGB4:
  1352. case AV_PIX_FMT_BGR4:
  1353. *yuv2packed1 = yuv2rgb4_1_c;
  1354. *yuv2packed2 = yuv2rgb4_2_c;
  1355. *yuv2packedX = yuv2rgb4_X_c;
  1356. break;
  1357. case AV_PIX_FMT_RGB4_BYTE:
  1358. case AV_PIX_FMT_BGR4_BYTE:
  1359. *yuv2packed1 = yuv2rgb4b_1_c;
  1360. *yuv2packed2 = yuv2rgb4b_2_c;
  1361. *yuv2packedX = yuv2rgb4b_X_c;
  1362. break;
  1363. }
  1364. }
  1365. switch (dstFormat) {
  1366. case AV_PIX_FMT_MONOWHITE:
  1367. *yuv2packed1 = yuv2monowhite_1_c;
  1368. *yuv2packed2 = yuv2monowhite_2_c;
  1369. *yuv2packedX = yuv2monowhite_X_c;
  1370. break;
  1371. case AV_PIX_FMT_MONOBLACK:
  1372. *yuv2packed1 = yuv2monoblack_1_c;
  1373. *yuv2packed2 = yuv2monoblack_2_c;
  1374. *yuv2packedX = yuv2monoblack_X_c;
  1375. break;
  1376. case AV_PIX_FMT_YUYV422:
  1377. *yuv2packed1 = yuv2yuyv422_1_c;
  1378. *yuv2packed2 = yuv2yuyv422_2_c;
  1379. *yuv2packedX = yuv2yuyv422_X_c;
  1380. break;
  1381. case AV_PIX_FMT_UYVY422:
  1382. *yuv2packed1 = yuv2uyvy422_1_c;
  1383. *yuv2packed2 = yuv2uyvy422_2_c;
  1384. *yuv2packedX = yuv2uyvy422_X_c;
  1385. break;
  1386. }
  1387. }