output.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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(16, BE, 1, 16, int32_t)
  223. yuv2NBPS(16, LE, 0, 16, int32_t)
  224. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  225. const int16_t **src, uint8_t *dest, int dstW,
  226. const uint8_t *dither, int offset)
  227. {
  228. int i;
  229. for (i=0; i<dstW; i++) {
  230. int val = dither[(i + offset) & 7] << 12;
  231. int j;
  232. for (j=0; j<filterSize; j++)
  233. val += src[j][i] * filter[j];
  234. dest[i]= av_clip_uint8(val>>19);
  235. }
  236. }
  237. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  238. const uint8_t *dither, int offset)
  239. {
  240. int i;
  241. for (i=0; i<dstW; i++) {
  242. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  243. dest[i]= av_clip_uint8(val);
  244. }
  245. }
  246. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  247. const int16_t **chrUSrc, const int16_t **chrVSrc,
  248. uint8_t *dest, int chrDstW)
  249. {
  250. enum PixelFormat dstFormat = c->dstFormat;
  251. const uint8_t *chrDither = c->chrDither8;
  252. int i;
  253. if (dstFormat == PIX_FMT_NV12)
  254. for (i=0; i<chrDstW; i++) {
  255. int u = chrDither[i & 7] << 12;
  256. int v = chrDither[(i + 3) & 7] << 12;
  257. int j;
  258. for (j=0; j<chrFilterSize; j++) {
  259. u += chrUSrc[j][i] * chrFilter[j];
  260. v += chrVSrc[j][i] * chrFilter[j];
  261. }
  262. dest[2*i]= av_clip_uint8(u>>19);
  263. dest[2*i+1]= av_clip_uint8(v>>19);
  264. }
  265. else
  266. for (i=0; i<chrDstW; i++) {
  267. int u = chrDither[i & 7] << 12;
  268. int v = chrDither[(i + 3) & 7] << 12;
  269. int j;
  270. for (j=0; j<chrFilterSize; j++) {
  271. u += chrUSrc[j][i] * chrFilter[j];
  272. v += chrVSrc[j][i] * chrFilter[j];
  273. }
  274. dest[2*i]= av_clip_uint8(v>>19);
  275. dest[2*i+1]= av_clip_uint8(u>>19);
  276. }
  277. }
  278. #define accumulate_bit(acc, val) \
  279. acc <<= 1; \
  280. acc |= (val) >= (128 + 110)
  281. #define output_pixel(pos, acc) \
  282. if (target == PIX_FMT_MONOBLACK) { \
  283. pos = acc; \
  284. } else { \
  285. pos = ~acc; \
  286. }
  287. static av_always_inline void
  288. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  289. const int16_t **lumSrc, int lumFilterSize,
  290. const int16_t *chrFilter, const int16_t **chrUSrc,
  291. const int16_t **chrVSrc, int chrFilterSize,
  292. const int16_t **alpSrc, uint8_t *dest, int dstW,
  293. int y, enum PixelFormat target)
  294. {
  295. const uint8_t * const d128=dither_8x8_220[y&7];
  296. int i;
  297. unsigned acc = 0;
  298. for (i = 0; i < dstW; i += 2) {
  299. int j;
  300. int Y1 = 1 << 18;
  301. int Y2 = 1 << 18;
  302. for (j = 0; j < lumFilterSize; j++) {
  303. Y1 += lumSrc[j][i] * lumFilter[j];
  304. Y2 += lumSrc[j][i+1] * lumFilter[j];
  305. }
  306. Y1 >>= 19;
  307. Y2 >>= 19;
  308. if ((Y1 | Y2) & 0x100) {
  309. Y1 = av_clip_uint8(Y1);
  310. Y2 = av_clip_uint8(Y2);
  311. }
  312. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  313. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  314. if ((i & 7) == 6) {
  315. output_pixel(*dest++, acc);
  316. }
  317. }
  318. if (i & 6) {
  319. output_pixel(*dest, acc);
  320. }
  321. }
  322. static av_always_inline void
  323. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  324. const int16_t *ubuf[2], const int16_t *vbuf[2],
  325. const int16_t *abuf[2], uint8_t *dest, int dstW,
  326. int yalpha, int uvalpha, int y,
  327. enum PixelFormat target)
  328. {
  329. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  330. const uint8_t * const d128 = dither_8x8_220[y & 7];
  331. int yalpha1 = 4096 - yalpha;
  332. int i;
  333. for (i = 0; i < dstW; i += 8) {
  334. int Y, acc = 0;
  335. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  336. accumulate_bit(acc, Y + d128[0]);
  337. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  338. accumulate_bit(acc, Y + d128[1]);
  339. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  340. accumulate_bit(acc, Y + d128[2]);
  341. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  342. accumulate_bit(acc, Y + d128[3]);
  343. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  344. accumulate_bit(acc, Y + d128[4]);
  345. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  346. accumulate_bit(acc, Y + d128[5]);
  347. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  348. accumulate_bit(acc, Y + d128[6]);
  349. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  350. accumulate_bit(acc, Y + d128[7]);
  351. output_pixel(*dest++, acc);
  352. }
  353. }
  354. static av_always_inline void
  355. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  356. const int16_t *ubuf[2], const int16_t *vbuf[2],
  357. const int16_t *abuf0, uint8_t *dest, int dstW,
  358. int uvalpha, int y, enum PixelFormat target)
  359. {
  360. const uint8_t * const d128 = dither_8x8_220[y & 7];
  361. int i;
  362. for (i = 0; i < dstW; i += 8) {
  363. int acc = 0;
  364. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  365. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  366. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  367. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  368. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  369. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  370. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  371. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  372. output_pixel(*dest++, acc);
  373. }
  374. }
  375. #undef output_pixel
  376. #undef accumulate_bit
  377. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  378. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  379. const int16_t **lumSrc, int lumFilterSize, \
  380. const int16_t *chrFilter, const int16_t **chrUSrc, \
  381. const int16_t **chrVSrc, int chrFilterSize, \
  382. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  383. int y) \
  384. { \
  385. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  386. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  387. alpSrc, dest, dstW, y, fmt); \
  388. } \
  389. \
  390. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  391. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  392. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  393. int yalpha, int uvalpha, int y) \
  394. { \
  395. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  396. dest, dstW, yalpha, uvalpha, y, fmt); \
  397. } \
  398. \
  399. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  400. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  401. const int16_t *abuf0, uint8_t *dest, int dstW, \
  402. int uvalpha, int y) \
  403. { \
  404. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  405. abuf0, dest, dstW, uvalpha, \
  406. y, fmt); \
  407. }
  408. YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE)
  409. YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK)
  410. #define output_pixels(pos, Y1, U, Y2, V) \
  411. if (target == PIX_FMT_YUYV422) { \
  412. dest[pos + 0] = Y1; \
  413. dest[pos + 1] = U; \
  414. dest[pos + 2] = Y2; \
  415. dest[pos + 3] = V; \
  416. } else { \
  417. dest[pos + 0] = U; \
  418. dest[pos + 1] = Y1; \
  419. dest[pos + 2] = V; \
  420. dest[pos + 3] = Y2; \
  421. }
  422. static av_always_inline void
  423. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  424. const int16_t **lumSrc, int lumFilterSize,
  425. const int16_t *chrFilter, const int16_t **chrUSrc,
  426. const int16_t **chrVSrc, int chrFilterSize,
  427. const int16_t **alpSrc, uint8_t *dest, int dstW,
  428. int y, enum PixelFormat target)
  429. {
  430. int i;
  431. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  432. int j;
  433. int Y1 = 1 << 18;
  434. int Y2 = 1 << 18;
  435. int U = 1 << 18;
  436. int V = 1 << 18;
  437. for (j = 0; j < lumFilterSize; j++) {
  438. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  439. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  440. }
  441. for (j = 0; j < chrFilterSize; j++) {
  442. U += chrUSrc[j][i] * chrFilter[j];
  443. V += chrVSrc[j][i] * chrFilter[j];
  444. }
  445. Y1 >>= 19;
  446. Y2 >>= 19;
  447. U >>= 19;
  448. V >>= 19;
  449. if ((Y1 | Y2 | U | V) & 0x100) {
  450. Y1 = av_clip_uint8(Y1);
  451. Y2 = av_clip_uint8(Y2);
  452. U = av_clip_uint8(U);
  453. V = av_clip_uint8(V);
  454. }
  455. output_pixels(4*i, Y1, U, Y2, V);
  456. }
  457. }
  458. static av_always_inline void
  459. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  460. const int16_t *ubuf[2], const int16_t *vbuf[2],
  461. const int16_t *abuf[2], uint8_t *dest, int dstW,
  462. int yalpha, int uvalpha, int y,
  463. enum PixelFormat target)
  464. {
  465. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  466. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  467. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  468. int yalpha1 = 4096 - yalpha;
  469. int uvalpha1 = 4096 - uvalpha;
  470. int i;
  471. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  472. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  473. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  474. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  475. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  476. if ((Y1 | Y2 | U | V) & 0x100) {
  477. Y1 = av_clip_uint8(Y1);
  478. Y2 = av_clip_uint8(Y2);
  479. U = av_clip_uint8(U);
  480. V = av_clip_uint8(V);
  481. }
  482. output_pixels(i * 4, Y1, U, Y2, V);
  483. }
  484. }
  485. static av_always_inline void
  486. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  487. const int16_t *ubuf[2], const int16_t *vbuf[2],
  488. const int16_t *abuf0, uint8_t *dest, int dstW,
  489. int uvalpha, int y, enum PixelFormat target)
  490. {
  491. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  492. int i;
  493. if (uvalpha < 2048) {
  494. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  495. int Y1 = (buf0[i * 2 ]+64) >> 7;
  496. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  497. int U = (ubuf0[i] +64) >> 7;
  498. int V = (vbuf0[i] +64) >> 7;
  499. if ((Y1 | Y2 | U | V) & 0x100) {
  500. Y1 = av_clip_uint8(Y1);
  501. Y2 = av_clip_uint8(Y2);
  502. U = av_clip_uint8(U);
  503. V = av_clip_uint8(V);
  504. }
  505. Y1 = av_clip_uint8(Y1);
  506. Y2 = av_clip_uint8(Y2);
  507. U = av_clip_uint8(U);
  508. V = av_clip_uint8(V);
  509. output_pixels(i * 4, Y1, U, Y2, V);
  510. }
  511. } else {
  512. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  513. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  514. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  515. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  516. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  517. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  518. if ((Y1 | Y2 | U | V) & 0x100) {
  519. Y1 = av_clip_uint8(Y1);
  520. Y2 = av_clip_uint8(Y2);
  521. U = av_clip_uint8(U);
  522. V = av_clip_uint8(V);
  523. }
  524. Y1 = av_clip_uint8(Y1);
  525. Y2 = av_clip_uint8(Y2);
  526. U = av_clip_uint8(U);
  527. V = av_clip_uint8(V);
  528. output_pixels(i * 4, Y1, U, Y2, V);
  529. }
  530. }
  531. }
  532. #undef output_pixels
  533. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422)
  534. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422)
  535. #define R_B ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? R : B)
  536. #define B_R ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? B : R)
  537. #define output_pixel(pos, val) \
  538. if (isBE(target)) { \
  539. AV_WB16(pos, val); \
  540. } else { \
  541. AV_WL16(pos, val); \
  542. }
  543. static av_always_inline void
  544. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  545. const int32_t **lumSrc, int lumFilterSize,
  546. const int16_t *chrFilter, const int32_t **chrUSrc,
  547. const int32_t **chrVSrc, int chrFilterSize,
  548. const int32_t **alpSrc, uint16_t *dest, int dstW,
  549. int y, enum PixelFormat target)
  550. {
  551. int i;
  552. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  553. int j;
  554. int Y1 = -0x40000000;
  555. int Y2 = -0x40000000;
  556. int U = -128 << 23; // 19
  557. int V = -128 << 23;
  558. int R, G, B;
  559. for (j = 0; j < lumFilterSize; j++) {
  560. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  561. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  562. }
  563. for (j = 0; j < chrFilterSize; j++) {;
  564. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  565. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  566. }
  567. // 8bit: 12+15=27; 16-bit: 12+19=31
  568. Y1 >>= 14; // 10
  569. Y1 += 0x10000;
  570. Y2 >>= 14;
  571. Y2 += 0x10000;
  572. U >>= 14;
  573. V >>= 14;
  574. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  575. Y1 -= c->yuv2rgb_y_offset;
  576. Y2 -= c->yuv2rgb_y_offset;
  577. Y1 *= c->yuv2rgb_y_coeff;
  578. Y2 *= c->yuv2rgb_y_coeff;
  579. Y1 += 1 << 13; // 21
  580. Y2 += 1 << 13;
  581. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  582. R = V * c->yuv2rgb_v2r_coeff;
  583. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  584. B = U * c->yuv2rgb_u2b_coeff;
  585. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  586. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  587. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  588. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  589. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  590. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  591. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  592. dest += 6;
  593. }
  594. }
  595. static av_always_inline void
  596. yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
  597. const int32_t *ubuf[2], const int32_t *vbuf[2],
  598. const int32_t *abuf[2], uint16_t *dest, int dstW,
  599. int yalpha, int uvalpha, int y,
  600. enum PixelFormat target)
  601. {
  602. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  603. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  604. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  605. int yalpha1 = 4096 - yalpha;
  606. int uvalpha1 = 4096 - uvalpha;
  607. int i;
  608. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  609. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  610. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  611. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  612. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  613. int R, G, B;
  614. Y1 -= c->yuv2rgb_y_offset;
  615. Y2 -= c->yuv2rgb_y_offset;
  616. Y1 *= c->yuv2rgb_y_coeff;
  617. Y2 *= c->yuv2rgb_y_coeff;
  618. Y1 += 1 << 13;
  619. Y2 += 1 << 13;
  620. R = V * c->yuv2rgb_v2r_coeff;
  621. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  622. B = U * c->yuv2rgb_u2b_coeff;
  623. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  624. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  625. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  626. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  627. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  628. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  629. dest += 6;
  630. }
  631. }
  632. static av_always_inline void
  633. yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
  634. const int32_t *ubuf[2], const int32_t *vbuf[2],
  635. const int32_t *abuf0, uint16_t *dest, int dstW,
  636. int uvalpha, int y, enum PixelFormat target)
  637. {
  638. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  639. int i;
  640. if (uvalpha < 2048) {
  641. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  642. int Y1 = (buf0[i * 2] ) >> 2;
  643. int Y2 = (buf0[i * 2 + 1]) >> 2;
  644. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  645. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  646. int R, G, B;
  647. Y1 -= c->yuv2rgb_y_offset;
  648. Y2 -= c->yuv2rgb_y_offset;
  649. Y1 *= c->yuv2rgb_y_coeff;
  650. Y2 *= c->yuv2rgb_y_coeff;
  651. Y1 += 1 << 13;
  652. Y2 += 1 << 13;
  653. R = V * c->yuv2rgb_v2r_coeff;
  654. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  655. B = U * c->yuv2rgb_u2b_coeff;
  656. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  657. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  658. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  659. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  660. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  661. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  662. dest += 6;
  663. }
  664. } else {
  665. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  666. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  667. int Y1 = (buf0[i * 2] ) >> 2;
  668. int Y2 = (buf0[i * 2 + 1]) >> 2;
  669. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  670. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  671. int R, G, B;
  672. Y1 -= c->yuv2rgb_y_offset;
  673. Y2 -= c->yuv2rgb_y_offset;
  674. Y1 *= c->yuv2rgb_y_coeff;
  675. Y2 *= c->yuv2rgb_y_coeff;
  676. Y1 += 1 << 13;
  677. Y2 += 1 << 13;
  678. R = V * c->yuv2rgb_v2r_coeff;
  679. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  680. B = U * c->yuv2rgb_u2b_coeff;
  681. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  682. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  683. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  684. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  685. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  686. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  687. dest += 6;
  688. }
  689. }
  690. }
  691. #undef output_pixel
  692. #undef r_b
  693. #undef b_r
  694. #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
  695. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  696. const int16_t **_lumSrc, int lumFilterSize, \
  697. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  698. const int16_t **_chrVSrc, int chrFilterSize, \
  699. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  700. int y) \
  701. { \
  702. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  703. **chrUSrc = (const int32_t **) _chrUSrc, \
  704. **chrVSrc = (const int32_t **) _chrVSrc, \
  705. **alpSrc = (const int32_t **) _alpSrc; \
  706. uint16_t *dest = (uint16_t *) _dest; \
  707. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  708. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  709. alpSrc, dest, dstW, y, fmt); \
  710. } \
  711. \
  712. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  713. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  714. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  715. int yalpha, int uvalpha, int y) \
  716. { \
  717. const int32_t **buf = (const int32_t **) _buf, \
  718. **ubuf = (const int32_t **) _ubuf, \
  719. **vbuf = (const int32_t **) _vbuf, \
  720. **abuf = (const int32_t **) _abuf; \
  721. uint16_t *dest = (uint16_t *) _dest; \
  722. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  723. dest, dstW, yalpha, uvalpha, y, fmt); \
  724. } \
  725. \
  726. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  727. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  728. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  729. int uvalpha, int y) \
  730. { \
  731. const int32_t *buf0 = (const int32_t *) _buf0, \
  732. **ubuf = (const int32_t **) _ubuf, \
  733. **vbuf = (const int32_t **) _vbuf, \
  734. *abuf0 = (const int32_t *) _abuf0; \
  735. uint16_t *dest = (uint16_t *) _dest; \
  736. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  737. dstW, uvalpha, y, fmt); \
  738. }
  739. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE)
  740. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE)
  741. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE)
  742. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE)
  743. /*
  744. * Write out 2 RGB pixels in the target pixel format. This function takes a
  745. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  746. * things like endianness conversion and shifting. The caller takes care of
  747. * setting the correct offset in these tables from the chroma (U/V) values.
  748. * This function then uses the luminance (Y1/Y2) values to write out the
  749. * correct RGB values into the destination buffer.
  750. */
  751. static av_always_inline void
  752. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  753. unsigned A1, unsigned A2,
  754. const void *_r, const void *_g, const void *_b, int y,
  755. enum PixelFormat target, int hasAlpha)
  756. {
  757. if (target == PIX_FMT_ARGB || target == PIX_FMT_RGBA ||
  758. target == PIX_FMT_ABGR || target == PIX_FMT_BGRA) {
  759. uint32_t *dest = (uint32_t *) _dest;
  760. const uint32_t *r = (const uint32_t *) _r;
  761. const uint32_t *g = (const uint32_t *) _g;
  762. const uint32_t *b = (const uint32_t *) _b;
  763. #if CONFIG_SMALL
  764. int sh = hasAlpha ? ((target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  765. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  766. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  767. #else
  768. if (hasAlpha) {
  769. int sh = (target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24;
  770. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  771. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  772. } else {
  773. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  774. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  775. }
  776. #endif
  777. } else if (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) {
  778. uint8_t *dest = (uint8_t *) _dest;
  779. const uint8_t *r = (const uint8_t *) _r;
  780. const uint8_t *g = (const uint8_t *) _g;
  781. const uint8_t *b = (const uint8_t *) _b;
  782. #define r_b ((target == PIX_FMT_RGB24) ? r : b)
  783. #define b_r ((target == PIX_FMT_RGB24) ? b : r)
  784. dest[i * 6 + 0] = r_b[Y1];
  785. dest[i * 6 + 1] = g[Y1];
  786. dest[i * 6 + 2] = b_r[Y1];
  787. dest[i * 6 + 3] = r_b[Y2];
  788. dest[i * 6 + 4] = g[Y2];
  789. dest[i * 6 + 5] = b_r[Y2];
  790. #undef r_b
  791. #undef b_r
  792. } else if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565 ||
  793. target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555 ||
  794. target == PIX_FMT_RGB444 || target == PIX_FMT_BGR444) {
  795. uint16_t *dest = (uint16_t *) _dest;
  796. const uint16_t *r = (const uint16_t *) _r;
  797. const uint16_t *g = (const uint16_t *) _g;
  798. const uint16_t *b = (const uint16_t *) _b;
  799. int dr1, dg1, db1, dr2, dg2, db2;
  800. if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565) {
  801. dr1 = dither_2x2_8[ y & 1 ][0];
  802. dg1 = dither_2x2_4[ y & 1 ][0];
  803. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  804. dr2 = dither_2x2_8[ y & 1 ][1];
  805. dg2 = dither_2x2_4[ y & 1 ][1];
  806. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  807. } else if (target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555) {
  808. dr1 = dither_2x2_8[ y & 1 ][0];
  809. dg1 = dither_2x2_8[ y & 1 ][1];
  810. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  811. dr2 = dither_2x2_8[ y & 1 ][1];
  812. dg2 = dither_2x2_8[ y & 1 ][0];
  813. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  814. } else {
  815. dr1 = dither_4x4_16[ y & 3 ][0];
  816. dg1 = dither_4x4_16[ y & 3 ][1];
  817. db1 = dither_4x4_16[(y & 3) ^ 3][0];
  818. dr2 = dither_4x4_16[ y & 3 ][1];
  819. dg2 = dither_4x4_16[ y & 3 ][0];
  820. db2 = dither_4x4_16[(y & 3) ^ 3][1];
  821. }
  822. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  823. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  824. } else /* 8/4-bit */ {
  825. uint8_t *dest = (uint8_t *) _dest;
  826. const uint8_t *r = (const uint8_t *) _r;
  827. const uint8_t *g = (const uint8_t *) _g;
  828. const uint8_t *b = (const uint8_t *) _b;
  829. int dr1, dg1, db1, dr2, dg2, db2;
  830. if (target == PIX_FMT_RGB8 || target == PIX_FMT_BGR8) {
  831. const uint8_t * const d64 = dither_8x8_73[y & 7];
  832. const uint8_t * const d32 = dither_8x8_32[y & 7];
  833. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  834. db1 = d64[(i * 2 + 0) & 7];
  835. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  836. db2 = d64[(i * 2 + 1) & 7];
  837. } else {
  838. const uint8_t * const d64 = dither_8x8_73 [y & 7];
  839. const uint8_t * const d128 = dither_8x8_220[y & 7];
  840. dr1 = db1 = d128[(i * 2 + 0) & 7];
  841. dg1 = d64[(i * 2 + 0) & 7];
  842. dr2 = db2 = d128[(i * 2 + 1) & 7];
  843. dg2 = d64[(i * 2 + 1) & 7];
  844. }
  845. if (target == PIX_FMT_RGB4 || target == PIX_FMT_BGR4) {
  846. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  847. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  848. } else {
  849. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  850. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  851. }
  852. }
  853. }
  854. static av_always_inline void
  855. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  856. const int16_t **lumSrc, int lumFilterSize,
  857. const int16_t *chrFilter, const int16_t **chrUSrc,
  858. const int16_t **chrVSrc, int chrFilterSize,
  859. const int16_t **alpSrc, uint8_t *dest, int dstW,
  860. int y, enum PixelFormat target, int hasAlpha)
  861. {
  862. int i;
  863. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  864. int j, A1, A2;
  865. int Y1 = 1 << 18;
  866. int Y2 = 1 << 18;
  867. int U = 1 << 18;
  868. int V = 1 << 18;
  869. const void *r, *g, *b;
  870. for (j = 0; j < lumFilterSize; j++) {
  871. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  872. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  873. }
  874. for (j = 0; j < chrFilterSize; j++) {
  875. U += chrUSrc[j][i] * chrFilter[j];
  876. V += chrVSrc[j][i] * chrFilter[j];
  877. }
  878. Y1 >>= 19;
  879. Y2 >>= 19;
  880. U >>= 19;
  881. V >>= 19;
  882. if (hasAlpha) {
  883. A1 = 1 << 18;
  884. A2 = 1 << 18;
  885. for (j = 0; j < lumFilterSize; j++) {
  886. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  887. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  888. }
  889. A1 >>= 19;
  890. A2 >>= 19;
  891. if ((A1 | A2) & 0x100) {
  892. A1 = av_clip_uint8(A1);
  893. A2 = av_clip_uint8(A2);
  894. }
  895. }
  896. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  897. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  898. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  899. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  900. r, g, b, y, target, hasAlpha);
  901. }
  902. }
  903. static av_always_inline void
  904. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  905. const int16_t *ubuf[2], const int16_t *vbuf[2],
  906. const int16_t *abuf[2], uint8_t *dest, int dstW,
  907. int yalpha, int uvalpha, int y,
  908. enum PixelFormat target, int hasAlpha)
  909. {
  910. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  911. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  912. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  913. *abuf0 = hasAlpha ? abuf[0] : NULL,
  914. *abuf1 = hasAlpha ? abuf[1] : NULL;
  915. int yalpha1 = 4096 - yalpha;
  916. int uvalpha1 = 4096 - uvalpha;
  917. int i;
  918. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  919. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  920. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  921. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  922. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  923. int A1, A2;
  924. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  925. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  926. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  927. if (hasAlpha) {
  928. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  929. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  930. A1 = av_clip_uint8(A1);
  931. A2 = av_clip_uint8(A2);
  932. }
  933. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  934. r, g, b, y, target, hasAlpha);
  935. }
  936. }
  937. static av_always_inline void
  938. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  939. const int16_t *ubuf[2], const int16_t *vbuf[2],
  940. const int16_t *abuf0, uint8_t *dest, int dstW,
  941. int uvalpha, int y, enum PixelFormat target,
  942. int hasAlpha)
  943. {
  944. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  945. int i;
  946. if (uvalpha < 2048) {
  947. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  948. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  949. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  950. int U = (ubuf0[i] + 64) >> 7;
  951. int V = (vbuf0[i] + 64) >> 7;
  952. int A1, A2;
  953. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  954. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  955. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  956. if (hasAlpha) {
  957. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  958. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  959. A1 = av_clip_uint8(A1);
  960. A2 = av_clip_uint8(A2);
  961. }
  962. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  963. r, g, b, y, target, hasAlpha);
  964. }
  965. } else {
  966. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  967. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  968. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  969. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  970. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  971. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  972. int A1, A2;
  973. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  974. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  975. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  976. if (hasAlpha) {
  977. A1 = (abuf0[i * 2 ] + 64) >> 7;
  978. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  979. A1 = av_clip_uint8(A1);
  980. A2 = av_clip_uint8(A2);
  981. }
  982. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  983. r, g, b, y, target, hasAlpha);
  984. }
  985. }
  986. }
  987. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  988. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  989. const int16_t **lumSrc, int lumFilterSize, \
  990. const int16_t *chrFilter, const int16_t **chrUSrc, \
  991. const int16_t **chrVSrc, int chrFilterSize, \
  992. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  993. int y) \
  994. { \
  995. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  996. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  997. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  998. }
  999. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1000. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1001. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1002. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1003. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1004. int yalpha, int uvalpha, int y) \
  1005. { \
  1006. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1007. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1008. } \
  1009. \
  1010. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1011. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1012. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1013. int uvalpha, int y) \
  1014. { \
  1015. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1016. dstW, uvalpha, y, fmt, hasAlpha); \
  1017. }
  1018. #if CONFIG_SMALL
  1019. YUV2RGBWRAPPER(yuv2rgb,, 32_1, PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1020. YUV2RGBWRAPPER(yuv2rgb,, 32, PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1021. #else
  1022. #if CONFIG_SWSCALE_ALPHA
  1023. YUV2RGBWRAPPER(yuv2rgb,, a32_1, PIX_FMT_RGB32_1, 1)
  1024. YUV2RGBWRAPPER(yuv2rgb,, a32, PIX_FMT_RGB32, 1)
  1025. #endif
  1026. YUV2RGBWRAPPER(yuv2rgb,, x32_1, PIX_FMT_RGB32_1, 0)
  1027. YUV2RGBWRAPPER(yuv2rgb,, x32, PIX_FMT_RGB32, 0)
  1028. #endif
  1029. YUV2RGBWRAPPER(yuv2, rgb, rgb24, PIX_FMT_RGB24, 0)
  1030. YUV2RGBWRAPPER(yuv2, rgb, bgr24, PIX_FMT_BGR24, 0)
  1031. YUV2RGBWRAPPER(yuv2rgb,, 16, PIX_FMT_RGB565, 0)
  1032. YUV2RGBWRAPPER(yuv2rgb,, 15, PIX_FMT_RGB555, 0)
  1033. YUV2RGBWRAPPER(yuv2rgb,, 12, PIX_FMT_RGB444, 0)
  1034. YUV2RGBWRAPPER(yuv2rgb,, 8, PIX_FMT_RGB8, 0)
  1035. YUV2RGBWRAPPER(yuv2rgb,, 4, PIX_FMT_RGB4, 0)
  1036. YUV2RGBWRAPPER(yuv2rgb,, 4b, PIX_FMT_RGB4_BYTE, 0)
  1037. static av_always_inline void
  1038. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1039. const int16_t **lumSrc, int lumFilterSize,
  1040. const int16_t *chrFilter, const int16_t **chrUSrc,
  1041. const int16_t **chrVSrc, int chrFilterSize,
  1042. const int16_t **alpSrc, uint8_t *dest,
  1043. int dstW, int y, enum PixelFormat target, int hasAlpha)
  1044. {
  1045. int i;
  1046. int step = (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) ? 3 : 4;
  1047. for (i = 0; i < dstW; i++) {
  1048. int j;
  1049. int Y = 1<<9;
  1050. int U = (1<<9)-(128 << 19);
  1051. int V = (1<<9)-(128 << 19);
  1052. int R, G, B, A;
  1053. for (j = 0; j < lumFilterSize; j++) {
  1054. Y += lumSrc[j][i] * lumFilter[j];
  1055. }
  1056. for (j = 0; j < chrFilterSize; j++) {
  1057. U += chrUSrc[j][i] * chrFilter[j];
  1058. V += chrVSrc[j][i] * chrFilter[j];
  1059. }
  1060. Y >>= 10;
  1061. U >>= 10;
  1062. V >>= 10;
  1063. if (hasAlpha) {
  1064. A = 1 << 18;
  1065. for (j = 0; j < lumFilterSize; j++) {
  1066. A += alpSrc[j][i] * lumFilter[j];
  1067. }
  1068. A >>= 19;
  1069. if (A & 0x100)
  1070. A = av_clip_uint8(A);
  1071. }
  1072. Y -= c->yuv2rgb_y_offset;
  1073. Y *= c->yuv2rgb_y_coeff;
  1074. Y += 1 << 21;
  1075. R = Y + V*c->yuv2rgb_v2r_coeff;
  1076. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1077. B = Y + U*c->yuv2rgb_u2b_coeff;
  1078. if ((R | G | B) & 0xC0000000) {
  1079. R = av_clip_uintp2(R, 30);
  1080. G = av_clip_uintp2(G, 30);
  1081. B = av_clip_uintp2(B, 30);
  1082. }
  1083. switch(target) {
  1084. case PIX_FMT_ARGB:
  1085. dest[0] = hasAlpha ? A : 255;
  1086. dest[1] = R >> 22;
  1087. dest[2] = G >> 22;
  1088. dest[3] = B >> 22;
  1089. break;
  1090. case PIX_FMT_RGB24:
  1091. dest[0] = R >> 22;
  1092. dest[1] = G >> 22;
  1093. dest[2] = B >> 22;
  1094. break;
  1095. case PIX_FMT_RGBA:
  1096. dest[0] = R >> 22;
  1097. dest[1] = G >> 22;
  1098. dest[2] = B >> 22;
  1099. dest[3] = hasAlpha ? A : 255;
  1100. break;
  1101. case PIX_FMT_ABGR:
  1102. dest[0] = hasAlpha ? A : 255;
  1103. dest[1] = B >> 22;
  1104. dest[2] = G >> 22;
  1105. dest[3] = R >> 22;
  1106. break;
  1107. case PIX_FMT_BGR24:
  1108. dest[0] = B >> 22;
  1109. dest[1] = G >> 22;
  1110. dest[2] = R >> 22;
  1111. break;
  1112. case PIX_FMT_BGRA:
  1113. dest[0] = B >> 22;
  1114. dest[1] = G >> 22;
  1115. dest[2] = R >> 22;
  1116. dest[3] = hasAlpha ? A : 255;
  1117. break;
  1118. }
  1119. dest += step;
  1120. }
  1121. }
  1122. #if CONFIG_SMALL
  1123. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1124. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1125. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1126. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1127. #else
  1128. #if CONFIG_SWSCALE_ALPHA
  1129. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, 1)
  1130. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, 1)
  1131. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, 1)
  1132. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, 1)
  1133. #endif
  1134. YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, PIX_FMT_BGRA, 0)
  1135. YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, PIX_FMT_ABGR, 0)
  1136. YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, PIX_FMT_RGBA, 0)
  1137. YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, PIX_FMT_ARGB, 0)
  1138. #endif
  1139. YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, PIX_FMT_BGR24, 0)
  1140. YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, PIX_FMT_RGB24, 0)
  1141. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1142. yuv2planar1_fn *yuv2plane1,
  1143. yuv2planarX_fn *yuv2planeX,
  1144. yuv2interleavedX_fn *yuv2nv12cX,
  1145. yuv2packed1_fn *yuv2packed1,
  1146. yuv2packed2_fn *yuv2packed2,
  1147. yuv2packedX_fn *yuv2packedX)
  1148. {
  1149. enum PixelFormat dstFormat = c->dstFormat;
  1150. if (is16BPS(dstFormat)) {
  1151. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1152. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1153. } else if (is9_OR_10BPS(dstFormat)) {
  1154. if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) {
  1155. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1156. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1157. } else {
  1158. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1159. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1160. }
  1161. } else {
  1162. *yuv2plane1 = yuv2plane1_8_c;
  1163. *yuv2planeX = yuv2planeX_8_c;
  1164. if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)
  1165. *yuv2nv12cX = yuv2nv12cX_c;
  1166. }
  1167. if(c->flags & SWS_FULL_CHR_H_INT) {
  1168. switch (dstFormat) {
  1169. case PIX_FMT_RGBA:
  1170. #if CONFIG_SMALL
  1171. *yuv2packedX = yuv2rgba32_full_X_c;
  1172. #else
  1173. #if CONFIG_SWSCALE_ALPHA
  1174. if (c->alpPixBuf) {
  1175. *yuv2packedX = yuv2rgba32_full_X_c;
  1176. } else
  1177. #endif /* CONFIG_SWSCALE_ALPHA */
  1178. {
  1179. *yuv2packedX = yuv2rgbx32_full_X_c;
  1180. }
  1181. #endif /* !CONFIG_SMALL */
  1182. break;
  1183. case PIX_FMT_ARGB:
  1184. #if CONFIG_SMALL
  1185. *yuv2packedX = yuv2argb32_full_X_c;
  1186. #else
  1187. #if CONFIG_SWSCALE_ALPHA
  1188. if (c->alpPixBuf) {
  1189. *yuv2packedX = yuv2argb32_full_X_c;
  1190. } else
  1191. #endif /* CONFIG_SWSCALE_ALPHA */
  1192. {
  1193. *yuv2packedX = yuv2xrgb32_full_X_c;
  1194. }
  1195. #endif /* !CONFIG_SMALL */
  1196. break;
  1197. case PIX_FMT_BGRA:
  1198. #if CONFIG_SMALL
  1199. *yuv2packedX = yuv2bgra32_full_X_c;
  1200. #else
  1201. #if CONFIG_SWSCALE_ALPHA
  1202. if (c->alpPixBuf) {
  1203. *yuv2packedX = yuv2bgra32_full_X_c;
  1204. } else
  1205. #endif /* CONFIG_SWSCALE_ALPHA */
  1206. {
  1207. *yuv2packedX = yuv2bgrx32_full_X_c;
  1208. }
  1209. #endif /* !CONFIG_SMALL */
  1210. break;
  1211. case PIX_FMT_ABGR:
  1212. #if CONFIG_SMALL
  1213. *yuv2packedX = yuv2abgr32_full_X_c;
  1214. #else
  1215. #if CONFIG_SWSCALE_ALPHA
  1216. if (c->alpPixBuf) {
  1217. *yuv2packedX = yuv2abgr32_full_X_c;
  1218. } else
  1219. #endif /* CONFIG_SWSCALE_ALPHA */
  1220. {
  1221. *yuv2packedX = yuv2xbgr32_full_X_c;
  1222. }
  1223. #endif /* !CONFIG_SMALL */
  1224. break;
  1225. case PIX_FMT_RGB24:
  1226. *yuv2packedX = yuv2rgb24_full_X_c;
  1227. break;
  1228. case PIX_FMT_BGR24:
  1229. *yuv2packedX = yuv2bgr24_full_X_c;
  1230. break;
  1231. }
  1232. if(!*yuv2packedX)
  1233. goto YUV_PACKED;
  1234. } else {
  1235. YUV_PACKED:
  1236. switch (dstFormat) {
  1237. case PIX_FMT_RGB48LE:
  1238. *yuv2packed1 = yuv2rgb48le_1_c;
  1239. *yuv2packed2 = yuv2rgb48le_2_c;
  1240. *yuv2packedX = yuv2rgb48le_X_c;
  1241. break;
  1242. case PIX_FMT_RGB48BE:
  1243. *yuv2packed1 = yuv2rgb48be_1_c;
  1244. *yuv2packed2 = yuv2rgb48be_2_c;
  1245. *yuv2packedX = yuv2rgb48be_X_c;
  1246. break;
  1247. case PIX_FMT_BGR48LE:
  1248. *yuv2packed1 = yuv2bgr48le_1_c;
  1249. *yuv2packed2 = yuv2bgr48le_2_c;
  1250. *yuv2packedX = yuv2bgr48le_X_c;
  1251. break;
  1252. case PIX_FMT_BGR48BE:
  1253. *yuv2packed1 = yuv2bgr48be_1_c;
  1254. *yuv2packed2 = yuv2bgr48be_2_c;
  1255. *yuv2packedX = yuv2bgr48be_X_c;
  1256. break;
  1257. case PIX_FMT_RGB32:
  1258. case PIX_FMT_BGR32:
  1259. #if CONFIG_SMALL
  1260. *yuv2packed1 = yuv2rgb32_1_c;
  1261. *yuv2packed2 = yuv2rgb32_2_c;
  1262. *yuv2packedX = yuv2rgb32_X_c;
  1263. #else
  1264. #if CONFIG_SWSCALE_ALPHA
  1265. if (c->alpPixBuf) {
  1266. *yuv2packed1 = yuv2rgba32_1_c;
  1267. *yuv2packed2 = yuv2rgba32_2_c;
  1268. *yuv2packedX = yuv2rgba32_X_c;
  1269. } else
  1270. #endif /* CONFIG_SWSCALE_ALPHA */
  1271. {
  1272. *yuv2packed1 = yuv2rgbx32_1_c;
  1273. *yuv2packed2 = yuv2rgbx32_2_c;
  1274. *yuv2packedX = yuv2rgbx32_X_c;
  1275. }
  1276. #endif /* !CONFIG_SMALL */
  1277. break;
  1278. case PIX_FMT_RGB32_1:
  1279. case PIX_FMT_BGR32_1:
  1280. #if CONFIG_SMALL
  1281. *yuv2packed1 = yuv2rgb32_1_1_c;
  1282. *yuv2packed2 = yuv2rgb32_1_2_c;
  1283. *yuv2packedX = yuv2rgb32_1_X_c;
  1284. #else
  1285. #if CONFIG_SWSCALE_ALPHA
  1286. if (c->alpPixBuf) {
  1287. *yuv2packed1 = yuv2rgba32_1_1_c;
  1288. *yuv2packed2 = yuv2rgba32_1_2_c;
  1289. *yuv2packedX = yuv2rgba32_1_X_c;
  1290. } else
  1291. #endif /* CONFIG_SWSCALE_ALPHA */
  1292. {
  1293. *yuv2packed1 = yuv2rgbx32_1_1_c;
  1294. *yuv2packed2 = yuv2rgbx32_1_2_c;
  1295. *yuv2packedX = yuv2rgbx32_1_X_c;
  1296. }
  1297. #endif /* !CONFIG_SMALL */
  1298. break;
  1299. case PIX_FMT_RGB24:
  1300. *yuv2packed1 = yuv2rgb24_1_c;
  1301. *yuv2packed2 = yuv2rgb24_2_c;
  1302. *yuv2packedX = yuv2rgb24_X_c;
  1303. break;
  1304. case PIX_FMT_BGR24:
  1305. *yuv2packed1 = yuv2bgr24_1_c;
  1306. *yuv2packed2 = yuv2bgr24_2_c;
  1307. *yuv2packedX = yuv2bgr24_X_c;
  1308. break;
  1309. case PIX_FMT_RGB565LE:
  1310. case PIX_FMT_RGB565BE:
  1311. case PIX_FMT_BGR565LE:
  1312. case PIX_FMT_BGR565BE:
  1313. *yuv2packed1 = yuv2rgb16_1_c;
  1314. *yuv2packed2 = yuv2rgb16_2_c;
  1315. *yuv2packedX = yuv2rgb16_X_c;
  1316. break;
  1317. case PIX_FMT_RGB555LE:
  1318. case PIX_FMT_RGB555BE:
  1319. case PIX_FMT_BGR555LE:
  1320. case PIX_FMT_BGR555BE:
  1321. *yuv2packed1 = yuv2rgb15_1_c;
  1322. *yuv2packed2 = yuv2rgb15_2_c;
  1323. *yuv2packedX = yuv2rgb15_X_c;
  1324. break;
  1325. case PIX_FMT_RGB444LE:
  1326. case PIX_FMT_RGB444BE:
  1327. case PIX_FMT_BGR444LE:
  1328. case PIX_FMT_BGR444BE:
  1329. *yuv2packed1 = yuv2rgb12_1_c;
  1330. *yuv2packed2 = yuv2rgb12_2_c;
  1331. *yuv2packedX = yuv2rgb12_X_c;
  1332. break;
  1333. case PIX_FMT_RGB8:
  1334. case PIX_FMT_BGR8:
  1335. *yuv2packed1 = yuv2rgb8_1_c;
  1336. *yuv2packed2 = yuv2rgb8_2_c;
  1337. *yuv2packedX = yuv2rgb8_X_c;
  1338. break;
  1339. case PIX_FMT_RGB4:
  1340. case PIX_FMT_BGR4:
  1341. *yuv2packed1 = yuv2rgb4_1_c;
  1342. *yuv2packed2 = yuv2rgb4_2_c;
  1343. *yuv2packedX = yuv2rgb4_X_c;
  1344. break;
  1345. case PIX_FMT_RGB4_BYTE:
  1346. case PIX_FMT_BGR4_BYTE:
  1347. *yuv2packed1 = yuv2rgb4b_1_c;
  1348. *yuv2packed2 = yuv2rgb4b_2_c;
  1349. *yuv2packedX = yuv2rgb4b_X_c;
  1350. break;
  1351. }
  1352. }
  1353. switch (dstFormat) {
  1354. case PIX_FMT_MONOWHITE:
  1355. *yuv2packed1 = yuv2monowhite_1_c;
  1356. *yuv2packed2 = yuv2monowhite_2_c;
  1357. *yuv2packedX = yuv2monowhite_X_c;
  1358. break;
  1359. case PIX_FMT_MONOBLACK:
  1360. *yuv2packed1 = yuv2monoblack_1_c;
  1361. *yuv2packed2 = yuv2monoblack_2_c;
  1362. *yuv2packedX = yuv2monoblack_X_c;
  1363. break;
  1364. case PIX_FMT_YUYV422:
  1365. *yuv2packed1 = yuv2yuyv422_1_c;
  1366. *yuv2packed2 = yuv2yuyv422_2_c;
  1367. *yuv2packedX = yuv2yuyv422_X_c;
  1368. break;
  1369. case PIX_FMT_UYVY422:
  1370. *yuv2packed1 = yuv2uyvy422_1_c;
  1371. *yuv2packed2 = yuv2uyvy422_2_c;
  1372. *yuv2packedX = yuv2uyvy422_X_c;
  1373. break;
  1374. }
  1375. }