output.c 54 KB

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