output.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  1. /*
  2. * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <math.h>
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/bswap.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/mathematics.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale.h"
  35. #include "swscale_internal.h"
  36. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
  37. { 1, 3, 1, 3, 1, 3, 1, 3, },
  38. { 2, 0, 2, 0, 2, 0, 2, 0, },
  39. { 1, 3, 1, 3, 1, 3, 1, 3, },
  40. };
  41. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
  42. { 6, 2, 6, 2, 6, 2, 6, 2, },
  43. { 0, 4, 0, 4, 0, 4, 0, 4, },
  44. { 6, 2, 6, 2, 6, 2, 6, 2, },
  45. };
  46. DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
  47. { 8, 4, 11, 7, 8, 4, 11, 7, },
  48. { 2, 14, 1, 13, 2, 14, 1, 13, },
  49. { 10, 6, 9, 5, 10, 6, 9, 5, },
  50. { 0, 12, 3, 15, 0, 12, 3, 15, },
  51. { 8, 4, 11, 7, 8, 4, 11, 7, },
  52. };
  53. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
  54. { 17, 9, 23, 15, 16, 8, 22, 14, },
  55. { 5, 29, 3, 27, 4, 28, 2, 26, },
  56. { 21, 13, 19, 11, 20, 12, 18, 10, },
  57. { 0, 24, 6, 30, 1, 25, 7, 31, },
  58. { 16, 8, 22, 14, 17, 9, 23, 15, },
  59. { 4, 28, 2, 26, 5, 29, 3, 27, },
  60. { 20, 12, 18, 10, 21, 13, 19, 11, },
  61. { 1, 25, 7, 31, 0, 24, 6, 30, },
  62. { 17, 9, 23, 15, 16, 8, 22, 14, },
  63. };
  64. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
  65. { 0, 55, 14, 68, 3, 58, 17, 72, },
  66. { 37, 18, 50, 32, 40, 22, 54, 35, },
  67. { 9, 64, 5, 59, 13, 67, 8, 63, },
  68. { 46, 27, 41, 23, 49, 31, 44, 26, },
  69. { 2, 57, 16, 71, 1, 56, 15, 70, },
  70. { 39, 21, 52, 34, 38, 19, 51, 33, },
  71. { 11, 66, 7, 62, 10, 65, 6, 60, },
  72. { 48, 30, 43, 25, 47, 29, 42, 24, },
  73. { 0, 55, 14, 68, 3, 58, 17, 72, },
  74. };
  75. #if 1
  76. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  77. {117, 62, 158, 103, 113, 58, 155, 100, },
  78. { 34, 199, 21, 186, 31, 196, 17, 182, },
  79. {144, 89, 131, 76, 141, 86, 127, 72, },
  80. { 0, 165, 41, 206, 10, 175, 52, 217, },
  81. {110, 55, 151, 96, 120, 65, 162, 107, },
  82. { 28, 193, 14, 179, 38, 203, 24, 189, },
  83. {138, 83, 124, 69, 148, 93, 134, 79, },
  84. { 7, 172, 48, 213, 3, 168, 45, 210, },
  85. {117, 62, 158, 103, 113, 58, 155, 100, },
  86. };
  87. #elif 1
  88. // tries to correct a gamma of 1.5
  89. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  90. { 0, 143, 18, 200, 2, 156, 25, 215, },
  91. { 78, 28, 125, 64, 89, 36, 138, 74, },
  92. { 10, 180, 3, 161, 16, 195, 8, 175, },
  93. {109, 51, 93, 38, 121, 60, 105, 47, },
  94. { 1, 152, 23, 210, 0, 147, 20, 205, },
  95. { 85, 33, 134, 71, 81, 30, 130, 67, },
  96. { 14, 190, 6, 171, 12, 185, 5, 166, },
  97. {117, 57, 101, 44, 113, 54, 97, 41, },
  98. { 0, 143, 18, 200, 2, 156, 25, 215, },
  99. };
  100. #elif 1
  101. // tries to correct a gamma of 2.0
  102. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  103. { 0, 124, 8, 193, 0, 140, 12, 213, },
  104. { 55, 14, 104, 42, 66, 19, 119, 52, },
  105. { 3, 168, 1, 145, 6, 187, 3, 162, },
  106. { 86, 31, 70, 21, 99, 39, 82, 28, },
  107. { 0, 134, 11, 206, 0, 129, 9, 200, },
  108. { 62, 17, 114, 48, 58, 16, 109, 45, },
  109. { 5, 181, 2, 157, 4, 175, 1, 151, },
  110. { 95, 36, 78, 26, 90, 34, 74, 24, },
  111. { 0, 124, 8, 193, 0, 140, 12, 213, },
  112. };
  113. #else
  114. // tries to correct a gamma of 2.5
  115. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  116. { 0, 107, 3, 187, 0, 125, 6, 212, },
  117. { 39, 7, 86, 28, 49, 11, 102, 36, },
  118. { 1, 158, 0, 131, 3, 180, 1, 151, },
  119. { 68, 19, 52, 12, 81, 25, 64, 17, },
  120. { 0, 119, 5, 203, 0, 113, 4, 195, },
  121. { 45, 9, 96, 33, 42, 8, 91, 30, },
  122. { 2, 172, 1, 144, 2, 165, 0, 137, },
  123. { 77, 23, 60, 15, 72, 21, 56, 14, },
  124. { 0, 107, 3, 187, 0, 125, 6, 212, },
  125. };
  126. #endif
  127. #define output_pixel(pos, val, bias, signedness) \
  128. if (big_endian) { \
  129. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  130. } else { \
  131. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  132. }
  133. static av_always_inline void
  134. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  135. int big_endian, int output_bits)
  136. {
  137. int i;
  138. int shift = 3;
  139. av_assert0(output_bits == 16);
  140. for (i = 0; i < dstW; i++) {
  141. int val = src[i] + (1 << (shift - 1));
  142. output_pixel(&dest[i], val, 0, uint);
  143. }
  144. }
  145. static av_always_inline void
  146. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  147. const int32_t **src, uint16_t *dest, int dstW,
  148. int big_endian, int output_bits)
  149. {
  150. int i;
  151. int shift = 15;
  152. av_assert0(output_bits == 16);
  153. for (i = 0; i < dstW; i++) {
  154. int val = 1 << (shift - 1);
  155. int j;
  156. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  157. * filters (or anything with negative coeffs, the range can be slightly
  158. * wider in both directions. To account for this overflow, we subtract
  159. * a constant so it always fits in the signed range (assuming a
  160. * reasonable filterSize), and re-add that at the end. */
  161. val -= 0x40000000;
  162. for (j = 0; j < filterSize; j++)
  163. val += src[j][i] * (unsigned)filter[j];
  164. output_pixel(&dest[i], val, 0x8000, int);
  165. }
  166. }
  167. #undef output_pixel
  168. #define output_pixel(pos, val) \
  169. if (big_endian) { \
  170. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  171. } else { \
  172. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  173. }
  174. static av_always_inline void
  175. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  176. int big_endian, int output_bits)
  177. {
  178. int i;
  179. int shift = 15 - output_bits;
  180. for (i = 0; i < dstW; i++) {
  181. int val = src[i] + (1 << (shift - 1));
  182. output_pixel(&dest[i], val);
  183. }
  184. }
  185. static av_always_inline void
  186. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  187. const int16_t **src, uint16_t *dest, int dstW,
  188. int big_endian, int output_bits)
  189. {
  190. int i;
  191. int shift = 11 + 16 - output_bits;
  192. for (i = 0; i < dstW; i++) {
  193. int val = 1 << (shift - 1);
  194. int j;
  195. for (j = 0; j < filterSize; j++)
  196. val += src[j][i] * filter[j];
  197. output_pixel(&dest[i], val);
  198. }
  199. }
  200. #undef output_pixel
  201. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  202. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  203. uint8_t *dest, int dstW, \
  204. const uint8_t *dither, int offset)\
  205. { \
  206. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  207. (uint16_t *) dest, dstW, is_be, bits); \
  208. }\
  209. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  210. const int16_t **src, uint8_t *dest, int dstW, \
  211. const uint8_t *dither, int offset)\
  212. { \
  213. yuv2planeX_## template_size ## _c_template(filter, \
  214. filterSize, (const typeX_t **) src, \
  215. (uint16_t *) dest, dstW, is_be, bits); \
  216. }
  217. yuv2NBPS( 9, BE, 1, 10, int16_t)
  218. yuv2NBPS( 9, LE, 0, 10, int16_t)
  219. yuv2NBPS(10, BE, 1, 10, int16_t)
  220. yuv2NBPS(10, LE, 0, 10, int16_t)
  221. yuv2NBPS(12, BE, 1, 10, int16_t)
  222. yuv2NBPS(12, LE, 0, 10, int16_t)
  223. yuv2NBPS(14, BE, 1, 10, int16_t)
  224. yuv2NBPS(14, LE, 0, 10, int16_t)
  225. yuv2NBPS(16, BE, 1, 16, int32_t)
  226. yuv2NBPS(16, LE, 0, 16, int32_t)
  227. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  228. const int16_t **src, uint8_t *dest, int dstW,
  229. const uint8_t *dither, int offset)
  230. {
  231. int i;
  232. for (i=0; i<dstW; i++) {
  233. int val = dither[(i + offset) & 7] << 12;
  234. int j;
  235. for (j=0; j<filterSize; j++)
  236. val += src[j][i] * filter[j];
  237. dest[i]= av_clip_uint8(val>>19);
  238. }
  239. }
  240. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  241. const uint8_t *dither, int offset)
  242. {
  243. int i;
  244. for (i=0; i<dstW; i++) {
  245. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  246. dest[i]= av_clip_uint8(val);
  247. }
  248. }
  249. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  250. const int16_t **chrUSrc, const int16_t **chrVSrc,
  251. uint8_t *dest, int chrDstW)
  252. {
  253. enum AVPixelFormat dstFormat = c->dstFormat;
  254. const uint8_t *chrDither = c->chrDither8;
  255. int i;
  256. if (dstFormat == AV_PIX_FMT_NV12)
  257. for (i=0; i<chrDstW; i++) {
  258. int u = chrDither[i & 7] << 12;
  259. int v = chrDither[(i + 3) & 7] << 12;
  260. int j;
  261. for (j=0; j<chrFilterSize; j++) {
  262. u += chrUSrc[j][i] * chrFilter[j];
  263. v += chrVSrc[j][i] * chrFilter[j];
  264. }
  265. dest[2*i]= av_clip_uint8(u>>19);
  266. dest[2*i+1]= av_clip_uint8(v>>19);
  267. }
  268. else
  269. for (i=0; i<chrDstW; i++) {
  270. int u = chrDither[i & 7] << 12;
  271. int v = chrDither[(i + 3) & 7] << 12;
  272. int j;
  273. for (j=0; j<chrFilterSize; j++) {
  274. u += chrUSrc[j][i] * chrFilter[j];
  275. v += chrVSrc[j][i] * chrFilter[j];
  276. }
  277. dest[2*i]= av_clip_uint8(v>>19);
  278. dest[2*i+1]= av_clip_uint8(u>>19);
  279. }
  280. }
  281. #define accumulate_bit(acc, val) \
  282. acc <<= 1; \
  283. acc |= (val) >= (128 + 110)
  284. #define output_pixel(pos, acc) \
  285. if (target == AV_PIX_FMT_MONOBLACK) { \
  286. pos = acc; \
  287. } else { \
  288. pos = ~acc; \
  289. }
  290. static av_always_inline void
  291. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  292. const int16_t **lumSrc, int lumFilterSize,
  293. const int16_t *chrFilter, const int16_t **chrUSrc,
  294. const int16_t **chrVSrc, int chrFilterSize,
  295. const int16_t **alpSrc, uint8_t *dest, int dstW,
  296. int y, enum AVPixelFormat target)
  297. {
  298. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  299. int i;
  300. unsigned acc = 0;
  301. int err = 0;
  302. for (i = 0; i < dstW; i += 2) {
  303. int j;
  304. int Y1 = 1 << 18;
  305. int Y2 = 1 << 18;
  306. for (j = 0; j < lumFilterSize; j++) {
  307. Y1 += lumSrc[j][i] * lumFilter[j];
  308. Y2 += lumSrc[j][i+1] * lumFilter[j];
  309. }
  310. Y1 >>= 19;
  311. Y2 >>= 19;
  312. if ((Y1 | Y2) & 0x100) {
  313. Y1 = av_clip_uint8(Y1);
  314. Y2 = av_clip_uint8(Y2);
  315. }
  316. if (c->dither == SWS_DITHER_ED) {
  317. Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  318. c->dither_error[0][i] = err;
  319. acc = 2*acc + (Y1 >= 128);
  320. Y1 -= 220*(acc&1);
  321. err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
  322. c->dither_error[0][i+1] = Y1;
  323. acc = 2*acc + (err >= 128);
  324. err -= 220*(acc&1);
  325. } else {
  326. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  327. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  328. }
  329. if ((i & 7) == 6) {
  330. output_pixel(*dest++, acc);
  331. }
  332. }
  333. c->dither_error[0][i] = err;
  334. if (i & 6) {
  335. output_pixel(*dest, acc);
  336. }
  337. }
  338. static av_always_inline void
  339. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  340. const int16_t *ubuf[2], const int16_t *vbuf[2],
  341. const int16_t *abuf[2], uint8_t *dest, int dstW,
  342. int yalpha, int uvalpha, int y,
  343. enum AVPixelFormat target)
  344. {
  345. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  346. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  347. int yalpha1 = 4096 - yalpha;
  348. int i;
  349. if (c->dither == SWS_DITHER_ED) {
  350. int err = 0;
  351. int acc = 0;
  352. for (i = 0; i < dstW; i +=2) {
  353. int Y;
  354. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  355. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  356. c->dither_error[0][i] = err;
  357. acc = 2*acc + (Y >= 128);
  358. Y -= 220*(acc&1);
  359. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  360. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  361. c->dither_error[0][i+1] = Y;
  362. acc = 2*acc + (err >= 128);
  363. err -= 220*(acc&1);
  364. if ((i & 7) == 6)
  365. output_pixel(*dest++, acc);
  366. }
  367. c->dither_error[0][i] = err;
  368. } else {
  369. for (i = 0; i < dstW; i += 8) {
  370. int Y, acc = 0;
  371. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  372. accumulate_bit(acc, Y + d128[0]);
  373. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  374. accumulate_bit(acc, Y + d128[1]);
  375. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  376. accumulate_bit(acc, Y + d128[2]);
  377. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  378. accumulate_bit(acc, Y + d128[3]);
  379. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  380. accumulate_bit(acc, Y + d128[4]);
  381. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  382. accumulate_bit(acc, Y + d128[5]);
  383. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  384. accumulate_bit(acc, Y + d128[6]);
  385. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  386. accumulate_bit(acc, Y + d128[7]);
  387. output_pixel(*dest++, acc);
  388. }
  389. }
  390. }
  391. static av_always_inline void
  392. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  393. const int16_t *ubuf[2], const int16_t *vbuf[2],
  394. const int16_t *abuf0, uint8_t *dest, int dstW,
  395. int uvalpha, int y, enum AVPixelFormat target)
  396. {
  397. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  398. int i;
  399. if (c->dither == SWS_DITHER_ED) {
  400. int err = 0;
  401. int acc = 0;
  402. for (i = 0; i < dstW; i +=2) {
  403. int Y;
  404. Y = ((buf0[i + 0] + 64) >> 7);
  405. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  406. c->dither_error[0][i] = err;
  407. acc = 2*acc + (Y >= 128);
  408. Y -= 220*(acc&1);
  409. err = ((buf0[i + 1] + 64) >> 7);
  410. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  411. c->dither_error[0][i+1] = Y;
  412. acc = 2*acc + (err >= 128);
  413. err -= 220*(acc&1);
  414. if ((i & 7) == 6)
  415. output_pixel(*dest++, acc);
  416. }
  417. c->dither_error[0][i] = err;
  418. } else {
  419. for (i = 0; i < dstW; i += 8) {
  420. int acc = 0;
  421. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  422. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  423. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  424. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  425. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  426. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  427. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  428. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  429. output_pixel(*dest++, acc);
  430. }
  431. }
  432. }
  433. #undef output_pixel
  434. #undef accumulate_bit
  435. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  436. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  437. const int16_t **lumSrc, int lumFilterSize, \
  438. const int16_t *chrFilter, const int16_t **chrUSrc, \
  439. const int16_t **chrVSrc, int chrFilterSize, \
  440. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  441. int y) \
  442. { \
  443. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  444. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  445. alpSrc, dest, dstW, y, fmt); \
  446. } \
  447. \
  448. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  449. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  450. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  451. int yalpha, int uvalpha, int y) \
  452. { \
  453. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  454. dest, dstW, yalpha, uvalpha, y, fmt); \
  455. } \
  456. \
  457. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  458. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  459. const int16_t *abuf0, uint8_t *dest, int dstW, \
  460. int uvalpha, int y) \
  461. { \
  462. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  463. abuf0, dest, dstW, uvalpha, \
  464. y, fmt); \
  465. }
  466. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  467. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  468. #define output_pixels(pos, Y1, U, Y2, V) \
  469. if (target == AV_PIX_FMT_YUYV422) { \
  470. dest[pos + 0] = Y1; \
  471. dest[pos + 1] = U; \
  472. dest[pos + 2] = Y2; \
  473. dest[pos + 3] = V; \
  474. } else if (target == AV_PIX_FMT_YVYU422) { \
  475. dest[pos + 0] = Y1; \
  476. dest[pos + 1] = V; \
  477. dest[pos + 2] = Y2; \
  478. dest[pos + 3] = U; \
  479. } else { /* AV_PIX_FMT_UYVY422 */ \
  480. dest[pos + 0] = U; \
  481. dest[pos + 1] = Y1; \
  482. dest[pos + 2] = V; \
  483. dest[pos + 3] = Y2; \
  484. }
  485. static av_always_inline void
  486. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  487. const int16_t **lumSrc, int lumFilterSize,
  488. const int16_t *chrFilter, const int16_t **chrUSrc,
  489. const int16_t **chrVSrc, int chrFilterSize,
  490. const int16_t **alpSrc, uint8_t *dest, int dstW,
  491. int y, enum AVPixelFormat target)
  492. {
  493. int i;
  494. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  495. int j;
  496. int Y1 = 1 << 18;
  497. int Y2 = 1 << 18;
  498. int U = 1 << 18;
  499. int V = 1 << 18;
  500. for (j = 0; j < lumFilterSize; j++) {
  501. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  502. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  503. }
  504. for (j = 0; j < chrFilterSize; j++) {
  505. U += chrUSrc[j][i] * chrFilter[j];
  506. V += chrVSrc[j][i] * chrFilter[j];
  507. }
  508. Y1 >>= 19;
  509. Y2 >>= 19;
  510. U >>= 19;
  511. V >>= 19;
  512. if ((Y1 | Y2 | U | V) & 0x100) {
  513. Y1 = av_clip_uint8(Y1);
  514. Y2 = av_clip_uint8(Y2);
  515. U = av_clip_uint8(U);
  516. V = av_clip_uint8(V);
  517. }
  518. output_pixels(4*i, Y1, U, Y2, V);
  519. }
  520. }
  521. static av_always_inline void
  522. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  523. const int16_t *ubuf[2], const int16_t *vbuf[2],
  524. const int16_t *abuf[2], uint8_t *dest, int dstW,
  525. int yalpha, int uvalpha, int y,
  526. enum AVPixelFormat target)
  527. {
  528. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  529. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  530. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  531. int yalpha1 = 4096 - yalpha;
  532. int uvalpha1 = 4096 - uvalpha;
  533. int i;
  534. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  535. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  536. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  537. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  538. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  539. if ((Y1 | Y2 | U | V) & 0x100) {
  540. Y1 = av_clip_uint8(Y1);
  541. Y2 = av_clip_uint8(Y2);
  542. U = av_clip_uint8(U);
  543. V = av_clip_uint8(V);
  544. }
  545. output_pixels(i * 4, Y1, U, Y2, V);
  546. }
  547. }
  548. static av_always_inline void
  549. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  550. const int16_t *ubuf[2], const int16_t *vbuf[2],
  551. const int16_t *abuf0, uint8_t *dest, int dstW,
  552. int uvalpha, int y, enum AVPixelFormat target)
  553. {
  554. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  555. int i;
  556. if (uvalpha < 2048) {
  557. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  558. int Y1 = (buf0[i * 2 ]+64) >> 7;
  559. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  560. int U = (ubuf0[i] +64) >> 7;
  561. int V = (vbuf0[i] +64) >> 7;
  562. if ((Y1 | Y2 | U | V) & 0x100) {
  563. Y1 = av_clip_uint8(Y1);
  564. Y2 = av_clip_uint8(Y2);
  565. U = av_clip_uint8(U);
  566. V = av_clip_uint8(V);
  567. }
  568. Y1 = av_clip_uint8(Y1);
  569. Y2 = av_clip_uint8(Y2);
  570. U = av_clip_uint8(U);
  571. V = av_clip_uint8(V);
  572. output_pixels(i * 4, Y1, U, Y2, V);
  573. }
  574. } else {
  575. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  576. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  577. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  578. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  579. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  580. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  581. if ((Y1 | Y2 | U | V) & 0x100) {
  582. Y1 = av_clip_uint8(Y1);
  583. Y2 = av_clip_uint8(Y2);
  584. U = av_clip_uint8(U);
  585. V = av_clip_uint8(V);
  586. }
  587. Y1 = av_clip_uint8(Y1);
  588. Y2 = av_clip_uint8(Y2);
  589. U = av_clip_uint8(U);
  590. V = av_clip_uint8(V);
  591. output_pixels(i * 4, Y1, U, Y2, V);
  592. }
  593. }
  594. }
  595. #undef output_pixels
  596. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  597. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  598. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  599. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
  600. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
  601. #define output_pixel(pos, val) \
  602. if (isBE(target)) { \
  603. AV_WB16(pos, val); \
  604. } else { \
  605. AV_WL16(pos, val); \
  606. }
  607. static av_always_inline void
  608. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  609. const int32_t **lumSrc, int lumFilterSize,
  610. const int16_t *chrFilter, const int32_t **chrUSrc,
  611. const int32_t **chrVSrc, int chrFilterSize,
  612. const int32_t **alpSrc, uint16_t *dest, int dstW,
  613. int y, enum AVPixelFormat target, int hasAlpha)
  614. {
  615. int i;
  616. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  617. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  618. int j;
  619. int Y1 = -0x40000000;
  620. int Y2 = -0x40000000;
  621. int U = -128 << 23; // 19
  622. int V = -128 << 23;
  623. int R, G, B;
  624. for (j = 0; j < lumFilterSize; j++) {
  625. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  626. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  627. }
  628. for (j = 0; j < chrFilterSize; j++) {;
  629. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  630. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  631. }
  632. if (hasAlpha) {
  633. A1 = -0x40000000;
  634. A2 = -0x40000000;
  635. for (j = 0; j < lumFilterSize; j++) {
  636. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  637. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  638. }
  639. A1 >>= 1;
  640. A1 += 0x20002000;
  641. A2 >>= 1;
  642. A2 += 0x20002000;
  643. }
  644. // 8bit: 12+15=27; 16-bit: 12+19=31
  645. Y1 >>= 14; // 10
  646. Y1 += 0x10000;
  647. Y2 >>= 14;
  648. Y2 += 0x10000;
  649. U >>= 14;
  650. V >>= 14;
  651. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  652. Y1 -= c->yuv2rgb_y_offset;
  653. Y2 -= c->yuv2rgb_y_offset;
  654. Y1 *= c->yuv2rgb_y_coeff;
  655. Y2 *= c->yuv2rgb_y_coeff;
  656. Y1 += 1 << 13; // 21
  657. Y2 += 1 << 13;
  658. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  659. R = V * c->yuv2rgb_v2r_coeff;
  660. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  661. B = U * c->yuv2rgb_u2b_coeff;
  662. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  663. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  664. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  665. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  666. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  667. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  668. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  669. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  670. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  671. dest += 8;
  672. }
  673. }
  674. static av_always_inline void
  675. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  676. const int32_t *ubuf[2], const int32_t *vbuf[2],
  677. const int32_t *abuf[2], uint16_t *dest, int dstW,
  678. int yalpha, int uvalpha, int y,
  679. enum AVPixelFormat target, int hasAlpha)
  680. {
  681. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  682. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  683. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  684. *abuf0 = hasAlpha ? abuf[0] : NULL,
  685. *abuf1 = hasAlpha ? abuf[1] : NULL;
  686. int yalpha1 = 4096 - yalpha;
  687. int uvalpha1 = 4096 - uvalpha;
  688. int i;
  689. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  690. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  691. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  692. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  693. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  694. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  695. int R, G, B;
  696. Y1 -= c->yuv2rgb_y_offset;
  697. Y2 -= c->yuv2rgb_y_offset;
  698. Y1 *= c->yuv2rgb_y_coeff;
  699. Y2 *= c->yuv2rgb_y_coeff;
  700. Y1 += 1 << 13;
  701. Y2 += 1 << 13;
  702. R = V * c->yuv2rgb_v2r_coeff;
  703. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  704. B = U * c->yuv2rgb_u2b_coeff;
  705. if (hasAlpha) {
  706. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  707. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  708. A1 += 1 << 13;
  709. A2 += 1 << 13;
  710. }
  711. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  712. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  713. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  714. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  715. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  716. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  717. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  718. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  719. dest += 8;
  720. }
  721. }
  722. static av_always_inline void
  723. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  724. const int32_t *ubuf[2], const int32_t *vbuf[2],
  725. const int32_t *abuf0, uint16_t *dest, int dstW,
  726. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
  727. {
  728. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  729. int i;
  730. int A1 = 0xffff<<14, A2= 0xffff<<14;
  731. if (uvalpha < 2048) {
  732. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  733. int Y1 = (buf0[i * 2] ) >> 2;
  734. int Y2 = (buf0[i * 2 + 1]) >> 2;
  735. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  736. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  737. int R, G, B;
  738. Y1 -= c->yuv2rgb_y_offset;
  739. Y2 -= c->yuv2rgb_y_offset;
  740. Y1 *= c->yuv2rgb_y_coeff;
  741. Y2 *= c->yuv2rgb_y_coeff;
  742. Y1 += 1 << 13;
  743. Y2 += 1 << 13;
  744. if (hasAlpha) {
  745. A1 = abuf0[i * 2 ] << 11;
  746. A2 = abuf0[i * 2 + 1] << 11;
  747. A1 += 1 << 13;
  748. A2 += 1 << 13;
  749. }
  750. R = V * c->yuv2rgb_v2r_coeff;
  751. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  752. B = U * c->yuv2rgb_u2b_coeff;
  753. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  754. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  755. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  756. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  757. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  758. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  759. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  760. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  761. dest += 8;
  762. }
  763. } else {
  764. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  765. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  766. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  767. int Y1 = (buf0[i * 2] ) >> 2;
  768. int Y2 = (buf0[i * 2 + 1]) >> 2;
  769. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  770. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  771. int R, G, B;
  772. Y1 -= c->yuv2rgb_y_offset;
  773. Y2 -= c->yuv2rgb_y_offset;
  774. Y1 *= c->yuv2rgb_y_coeff;
  775. Y2 *= c->yuv2rgb_y_coeff;
  776. Y1 += 1 << 13;
  777. Y2 += 1 << 13;
  778. if (hasAlpha) {
  779. A1 = abuf0[i * 2 ] << 11;
  780. A2 = abuf0[i * 2 + 1] << 11;
  781. A1 += 1 << 13;
  782. A2 += 1 << 13;
  783. }
  784. R = V * c->yuv2rgb_v2r_coeff;
  785. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  786. B = U * c->yuv2rgb_u2b_coeff;
  787. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  788. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  789. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  790. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  791. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  792. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  793. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  794. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  795. dest += 8;
  796. }
  797. }
  798. }
  799. static av_always_inline void
  800. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  801. const int32_t **lumSrc, int lumFilterSize,
  802. const int16_t *chrFilter, const int32_t **chrUSrc,
  803. const int32_t **chrVSrc, int chrFilterSize,
  804. const int32_t **alpSrc, uint16_t *dest, int dstW,
  805. int y, enum AVPixelFormat target, int hasAlpha)
  806. {
  807. int i;
  808. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  809. int j;
  810. int Y1 = -0x40000000;
  811. int Y2 = -0x40000000;
  812. int U = -128 << 23; // 19
  813. int V = -128 << 23;
  814. int R, G, B;
  815. for (j = 0; j < lumFilterSize; j++) {
  816. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  817. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  818. }
  819. for (j = 0; j < chrFilterSize; j++) {;
  820. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  821. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  822. }
  823. // 8bit: 12+15=27; 16-bit: 12+19=31
  824. Y1 >>= 14; // 10
  825. Y1 += 0x10000;
  826. Y2 >>= 14;
  827. Y2 += 0x10000;
  828. U >>= 14;
  829. V >>= 14;
  830. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  831. Y1 -= c->yuv2rgb_y_offset;
  832. Y2 -= c->yuv2rgb_y_offset;
  833. Y1 *= c->yuv2rgb_y_coeff;
  834. Y2 *= c->yuv2rgb_y_coeff;
  835. Y1 += 1 << 13; // 21
  836. Y2 += 1 << 13;
  837. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  838. R = V * c->yuv2rgb_v2r_coeff;
  839. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  840. B = U * c->yuv2rgb_u2b_coeff;
  841. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  842. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  843. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  844. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  845. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  846. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  847. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  848. dest += 6;
  849. }
  850. }
  851. static av_always_inline void
  852. yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
  853. const int32_t *ubuf[2], const int32_t *vbuf[2],
  854. const int32_t *abuf[2], uint16_t *dest, int dstW,
  855. int yalpha, int uvalpha, int y,
  856. enum AVPixelFormat target, int hasAlpha)
  857. {
  858. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  859. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  860. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  861. int yalpha1 = 4096 - yalpha;
  862. int uvalpha1 = 4096 - uvalpha;
  863. int i;
  864. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  865. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  866. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  867. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  868. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  869. int R, G, B;
  870. Y1 -= c->yuv2rgb_y_offset;
  871. Y2 -= c->yuv2rgb_y_offset;
  872. Y1 *= c->yuv2rgb_y_coeff;
  873. Y2 *= c->yuv2rgb_y_coeff;
  874. Y1 += 1 << 13;
  875. Y2 += 1 << 13;
  876. R = V * c->yuv2rgb_v2r_coeff;
  877. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  878. B = U * c->yuv2rgb_u2b_coeff;
  879. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  880. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  881. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  882. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  883. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  884. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  885. dest += 6;
  886. }
  887. }
  888. static av_always_inline void
  889. yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
  890. const int32_t *ubuf[2], const int32_t *vbuf[2],
  891. const int32_t *abuf0, uint16_t *dest, int dstW,
  892. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
  893. {
  894. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  895. int i;
  896. if (uvalpha < 2048) {
  897. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  898. int Y1 = (buf0[i * 2] ) >> 2;
  899. int Y2 = (buf0[i * 2 + 1]) >> 2;
  900. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  901. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  902. int R, G, B;
  903. Y1 -= c->yuv2rgb_y_offset;
  904. Y2 -= c->yuv2rgb_y_offset;
  905. Y1 *= c->yuv2rgb_y_coeff;
  906. Y2 *= c->yuv2rgb_y_coeff;
  907. Y1 += 1 << 13;
  908. Y2 += 1 << 13;
  909. R = V * c->yuv2rgb_v2r_coeff;
  910. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  911. B = U * c->yuv2rgb_u2b_coeff;
  912. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  913. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  914. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  915. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  916. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  917. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  918. dest += 6;
  919. }
  920. } else {
  921. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  922. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  923. int Y1 = (buf0[i * 2] ) >> 2;
  924. int Y2 = (buf0[i * 2 + 1]) >> 2;
  925. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  926. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  927. int R, G, B;
  928. Y1 -= c->yuv2rgb_y_offset;
  929. Y2 -= c->yuv2rgb_y_offset;
  930. Y1 *= c->yuv2rgb_y_coeff;
  931. Y2 *= c->yuv2rgb_y_coeff;
  932. Y1 += 1 << 13;
  933. Y2 += 1 << 13;
  934. R = V * c->yuv2rgb_v2r_coeff;
  935. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  936. B = U * c->yuv2rgb_u2b_coeff;
  937. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  938. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  939. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  940. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  941. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  942. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  943. dest += 6;
  944. }
  945. }
  946. }
  947. #undef output_pixel
  948. #undef r_b
  949. #undef b_r
  950. #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha) \
  951. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  952. const int16_t **_lumSrc, int lumFilterSize, \
  953. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  954. const int16_t **_chrVSrc, int chrFilterSize, \
  955. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  956. int y) \
  957. { \
  958. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  959. **chrUSrc = (const int32_t **) _chrUSrc, \
  960. **chrVSrc = (const int32_t **) _chrVSrc, \
  961. **alpSrc = (const int32_t **) _alpSrc; \
  962. uint16_t *dest = (uint16_t *) _dest; \
  963. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  964. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  965. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  966. } \
  967. \
  968. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  969. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  970. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  971. int yalpha, int uvalpha, int y) \
  972. { \
  973. const int32_t **buf = (const int32_t **) _buf, \
  974. **ubuf = (const int32_t **) _ubuf, \
  975. **vbuf = (const int32_t **) _vbuf, \
  976. **abuf = (const int32_t **) _abuf; \
  977. uint16_t *dest = (uint16_t *) _dest; \
  978. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  979. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  980. } \
  981. \
  982. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  983. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  984. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  985. int uvalpha, int y) \
  986. { \
  987. const int32_t *buf0 = (const int32_t *) _buf0, \
  988. **ubuf = (const int32_t **) _ubuf, \
  989. **vbuf = (const int32_t **) _vbuf, \
  990. *abuf0 = (const int32_t *) _abuf0; \
  991. uint16_t *dest = (uint16_t *) _dest; \
  992. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  993. dstW, uvalpha, y, fmt, hasAlpha); \
  994. }
  995. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE, 0)
  996. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE, 0)
  997. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE, 0)
  998. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE, 0)
  999. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1)
  1000. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1)
  1001. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0)
  1002. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0)
  1003. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1)
  1004. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1)
  1005. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0)
  1006. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0)
  1007. /*
  1008. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1009. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1010. * things like endianness conversion and shifting. The caller takes care of
  1011. * setting the correct offset in these tables from the chroma (U/V) values.
  1012. * This function then uses the luminance (Y1/Y2) values to write out the
  1013. * correct RGB values into the destination buffer.
  1014. */
  1015. static av_always_inline void
  1016. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1017. unsigned A1, unsigned A2,
  1018. const void *_r, const void *_g, const void *_b, int y,
  1019. enum AVPixelFormat target, int hasAlpha)
  1020. {
  1021. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1022. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1023. uint32_t *dest = (uint32_t *) _dest;
  1024. const uint32_t *r = (const uint32_t *) _r;
  1025. const uint32_t *g = (const uint32_t *) _g;
  1026. const uint32_t *b = (const uint32_t *) _b;
  1027. #if CONFIG_SMALL
  1028. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1029. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1030. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1031. #else
  1032. if (hasAlpha) {
  1033. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1034. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1035. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1036. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1037. } else {
  1038. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1039. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1040. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1041. #endif
  1042. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1043. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1044. }
  1045. #endif
  1046. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1047. uint8_t *dest = (uint8_t *) _dest;
  1048. const uint8_t *r = (const uint8_t *) _r;
  1049. const uint8_t *g = (const uint8_t *) _g;
  1050. const uint8_t *b = (const uint8_t *) _b;
  1051. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1052. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1053. dest[i * 6 + 0] = r_b[Y1];
  1054. dest[i * 6 + 1] = g[Y1];
  1055. dest[i * 6 + 2] = b_r[Y1];
  1056. dest[i * 6 + 3] = r_b[Y2];
  1057. dest[i * 6 + 4] = g[Y2];
  1058. dest[i * 6 + 5] = b_r[Y2];
  1059. #undef r_b
  1060. #undef b_r
  1061. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1062. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1063. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1064. uint16_t *dest = (uint16_t *) _dest;
  1065. const uint16_t *r = (const uint16_t *) _r;
  1066. const uint16_t *g = (const uint16_t *) _g;
  1067. const uint16_t *b = (const uint16_t *) _b;
  1068. int dr1, dg1, db1, dr2, dg2, db2;
  1069. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1070. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1071. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1072. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1073. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1074. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1075. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1076. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1077. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1078. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1079. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1080. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1081. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1082. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1083. } else {
  1084. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1085. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1086. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1087. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1088. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1089. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1090. }
  1091. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1092. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1093. } else /* 8/4-bit */ {
  1094. uint8_t *dest = (uint8_t *) _dest;
  1095. const uint8_t *r = (const uint8_t *) _r;
  1096. const uint8_t *g = (const uint8_t *) _g;
  1097. const uint8_t *b = (const uint8_t *) _b;
  1098. int dr1, dg1, db1, dr2, dg2, db2;
  1099. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1100. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1101. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1102. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1103. db1 = d64[(i * 2 + 0) & 7];
  1104. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1105. db2 = d64[(i * 2 + 1) & 7];
  1106. } else {
  1107. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1108. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1109. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1110. dg1 = d64[(i * 2 + 0) & 7];
  1111. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1112. dg2 = d64[(i * 2 + 1) & 7];
  1113. }
  1114. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1115. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1116. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1117. } else {
  1118. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1119. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1120. }
  1121. }
  1122. }
  1123. static av_always_inline void
  1124. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1125. const int16_t **lumSrc, int lumFilterSize,
  1126. const int16_t *chrFilter, const int16_t **chrUSrc,
  1127. const int16_t **chrVSrc, int chrFilterSize,
  1128. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1129. int y, enum AVPixelFormat target, int hasAlpha)
  1130. {
  1131. int i;
  1132. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1133. int j, A1, A2;
  1134. int Y1 = 1 << 18;
  1135. int Y2 = 1 << 18;
  1136. int U = 1 << 18;
  1137. int V = 1 << 18;
  1138. const void *r, *g, *b;
  1139. for (j = 0; j < lumFilterSize; j++) {
  1140. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1141. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1142. }
  1143. for (j = 0; j < chrFilterSize; j++) {
  1144. U += chrUSrc[j][i] * chrFilter[j];
  1145. V += chrVSrc[j][i] * chrFilter[j];
  1146. }
  1147. Y1 >>= 19;
  1148. Y2 >>= 19;
  1149. U >>= 19;
  1150. V >>= 19;
  1151. if (hasAlpha) {
  1152. A1 = 1 << 18;
  1153. A2 = 1 << 18;
  1154. for (j = 0; j < lumFilterSize; j++) {
  1155. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1156. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1157. }
  1158. A1 >>= 19;
  1159. A2 >>= 19;
  1160. if ((A1 | A2) & 0x100) {
  1161. A1 = av_clip_uint8(A1);
  1162. A2 = av_clip_uint8(A2);
  1163. }
  1164. }
  1165. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1166. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1167. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1168. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1169. r, g, b, y, target, hasAlpha);
  1170. }
  1171. }
  1172. static av_always_inline void
  1173. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1174. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1175. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1176. int yalpha, int uvalpha, int y,
  1177. enum AVPixelFormat target, int hasAlpha)
  1178. {
  1179. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1180. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1181. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1182. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1183. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1184. int yalpha1 = 4096 - yalpha;
  1185. int uvalpha1 = 4096 - uvalpha;
  1186. int i;
  1187. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1188. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1189. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1190. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1191. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1192. int A1, A2;
  1193. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1194. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1195. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1196. if (hasAlpha) {
  1197. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1198. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1199. A1 = av_clip_uint8(A1);
  1200. A2 = av_clip_uint8(A2);
  1201. }
  1202. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1203. r, g, b, y, target, hasAlpha);
  1204. }
  1205. }
  1206. static av_always_inline void
  1207. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1208. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1209. const int16_t *abuf0, uint8_t *dest, int dstW,
  1210. int uvalpha, int y, enum AVPixelFormat target,
  1211. int hasAlpha)
  1212. {
  1213. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1214. int i;
  1215. if (uvalpha < 2048) {
  1216. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1217. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1218. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1219. int U = (ubuf0[i] + 64) >> 7;
  1220. int V = (vbuf0[i] + 64) >> 7;
  1221. int A1, A2;
  1222. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1223. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1224. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1225. if (hasAlpha) {
  1226. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1227. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1228. A1 = av_clip_uint8(A1);
  1229. A2 = av_clip_uint8(A2);
  1230. }
  1231. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1232. r, g, b, y, target, hasAlpha);
  1233. }
  1234. } else {
  1235. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1236. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1237. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1238. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1239. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1240. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1241. int A1, A2;
  1242. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1243. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1244. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1245. if (hasAlpha) {
  1246. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1247. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1248. A1 = av_clip_uint8(A1);
  1249. A2 = av_clip_uint8(A2);
  1250. }
  1251. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1252. r, g, b, y, target, hasAlpha);
  1253. }
  1254. }
  1255. }
  1256. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1257. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1258. const int16_t **lumSrc, int lumFilterSize, \
  1259. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1260. const int16_t **chrVSrc, int chrFilterSize, \
  1261. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1262. int y) \
  1263. { \
  1264. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1265. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1266. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1267. }
  1268. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1269. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1270. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1271. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1272. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1273. int yalpha, int uvalpha, int y) \
  1274. { \
  1275. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1276. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1277. }
  1278. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1279. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1280. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1281. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1282. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1283. int uvalpha, int y) \
  1284. { \
  1285. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1286. dstW, uvalpha, y, fmt, hasAlpha); \
  1287. }
  1288. #if CONFIG_SMALL
  1289. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1290. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1291. #else
  1292. #if CONFIG_SWSCALE_ALPHA
  1293. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1294. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1295. #endif
  1296. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1297. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1298. #endif
  1299. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1300. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1301. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1302. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1303. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1304. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1305. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1306. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1307. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1308. uint8_t *dest, int i, int Y, int A, int U, int V,
  1309. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1310. {
  1311. int R, G, B;
  1312. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1313. Y -= c->yuv2rgb_y_offset;
  1314. Y *= c->yuv2rgb_y_coeff;
  1315. Y += 1 << 21;
  1316. R = Y + V*c->yuv2rgb_v2r_coeff;
  1317. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1318. B = Y + U*c->yuv2rgb_u2b_coeff;
  1319. if ((R | G | B) & 0xC0000000) {
  1320. R = av_clip_uintp2(R, 30);
  1321. G = av_clip_uintp2(G, 30);
  1322. B = av_clip_uintp2(B, 30);
  1323. }
  1324. switch(target) {
  1325. case AV_PIX_FMT_ARGB:
  1326. dest[0] = hasAlpha ? A : 255;
  1327. dest[1] = R >> 22;
  1328. dest[2] = G >> 22;
  1329. dest[3] = B >> 22;
  1330. break;
  1331. case AV_PIX_FMT_RGB24:
  1332. dest[0] = R >> 22;
  1333. dest[1] = G >> 22;
  1334. dest[2] = B >> 22;
  1335. break;
  1336. case AV_PIX_FMT_RGBA:
  1337. dest[0] = R >> 22;
  1338. dest[1] = G >> 22;
  1339. dest[2] = B >> 22;
  1340. dest[3] = hasAlpha ? A : 255;
  1341. break;
  1342. case AV_PIX_FMT_ABGR:
  1343. dest[0] = hasAlpha ? A : 255;
  1344. dest[1] = B >> 22;
  1345. dest[2] = G >> 22;
  1346. dest[3] = R >> 22;
  1347. break;
  1348. case AV_PIX_FMT_BGR24:
  1349. dest[0] = B >> 22;
  1350. dest[1] = G >> 22;
  1351. dest[2] = R >> 22;
  1352. break;
  1353. case AV_PIX_FMT_BGRA:
  1354. dest[0] = B >> 22;
  1355. dest[1] = G >> 22;
  1356. dest[2] = R >> 22;
  1357. dest[3] = hasAlpha ? A : 255;
  1358. break;
  1359. case AV_PIX_FMT_BGR4_BYTE:
  1360. case AV_PIX_FMT_RGB4_BYTE:
  1361. case AV_PIX_FMT_BGR8:
  1362. case AV_PIX_FMT_RGB8:
  1363. {
  1364. int r,g,b;
  1365. switch (c->dither) {
  1366. default:
  1367. case SWS_DITHER_AUTO:
  1368. case SWS_DITHER_ED:
  1369. R >>= 22;
  1370. G >>= 22;
  1371. B >>= 22;
  1372. R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
  1373. G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
  1374. B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
  1375. c->dither_error[0][i] = err[0];
  1376. c->dither_error[1][i] = err[1];
  1377. c->dither_error[2][i] = err[2];
  1378. r = R >> (isrgb8 ? 5 : 7);
  1379. g = G >> (isrgb8 ? 5 : 6);
  1380. b = B >> (isrgb8 ? 6 : 7);
  1381. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1382. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1383. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1384. err[0] = R - r*(isrgb8 ? 36 : 255);
  1385. err[1] = G - g*(isrgb8 ? 36 : 85);
  1386. err[2] = B - b*(isrgb8 ? 85 : 255);
  1387. break;
  1388. case SWS_DITHER_A_DITHER:
  1389. if (isrgb8) {
  1390. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1391. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1392. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1393. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1394. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1395. r = av_clip(r, 0, 7);
  1396. g = av_clip(g, 0, 7);
  1397. b = av_clip(b, 0, 3);
  1398. } else {
  1399. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1400. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1401. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1402. r = av_clip(r, 0, 1);
  1403. g = av_clip(g, 0, 3);
  1404. b = av_clip(b, 0, 1);
  1405. }
  1406. break;
  1407. case SWS_DITHER_X_DITHER:
  1408. if (isrgb8) {
  1409. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1410. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1411. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1412. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1413. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1414. r = av_clip(r, 0, 7);
  1415. g = av_clip(g, 0, 7);
  1416. b = av_clip(b, 0, 3);
  1417. } else {
  1418. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1419. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1420. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1421. r = av_clip(r, 0, 1);
  1422. g = av_clip(g, 0, 3);
  1423. b = av_clip(b, 0, 1);
  1424. }
  1425. break;
  1426. }
  1427. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1428. dest[0] = r + 2*g + 8*b;
  1429. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1430. dest[0] = b + 2*g + 8*r;
  1431. } else if(target == AV_PIX_FMT_BGR8) {
  1432. dest[0] = r + 8*g + 64*b;
  1433. } else if(target == AV_PIX_FMT_RGB8) {
  1434. dest[0] = b + 4*g + 32*r;
  1435. } else
  1436. av_assert2(0);
  1437. break;}
  1438. }
  1439. }
  1440. static av_always_inline void
  1441. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1442. const int16_t **lumSrc, int lumFilterSize,
  1443. const int16_t *chrFilter, const int16_t **chrUSrc,
  1444. const int16_t **chrVSrc, int chrFilterSize,
  1445. const int16_t **alpSrc, uint8_t *dest,
  1446. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1447. {
  1448. int i;
  1449. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1450. int err[4] = {0};
  1451. int A = 0; //init to silence warning
  1452. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1453. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1454. step = 1;
  1455. for (i = 0; i < dstW; i++) {
  1456. int j;
  1457. int Y = 1<<9;
  1458. int U = (1<<9)-(128 << 19);
  1459. int V = (1<<9)-(128 << 19);
  1460. for (j = 0; j < lumFilterSize; j++) {
  1461. Y += lumSrc[j][i] * lumFilter[j];
  1462. }
  1463. for (j = 0; j < chrFilterSize; j++) {
  1464. U += chrUSrc[j][i] * chrFilter[j];
  1465. V += chrVSrc[j][i] * chrFilter[j];
  1466. }
  1467. Y >>= 10;
  1468. U >>= 10;
  1469. V >>= 10;
  1470. if (hasAlpha) {
  1471. A = 1 << 18;
  1472. for (j = 0; j < lumFilterSize; j++) {
  1473. A += alpSrc[j][i] * lumFilter[j];
  1474. }
  1475. A >>= 19;
  1476. if (A & 0x100)
  1477. A = av_clip_uint8(A);
  1478. }
  1479. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1480. dest += step;
  1481. }
  1482. c->dither_error[0][i] = err[0];
  1483. c->dither_error[1][i] = err[1];
  1484. c->dither_error[2][i] = err[2];
  1485. }
  1486. static av_always_inline void
  1487. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1488. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1489. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1490. int yalpha, int uvalpha, int y,
  1491. enum AVPixelFormat target, int hasAlpha)
  1492. {
  1493. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1494. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1495. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1496. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1497. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1498. int yalpha1 = 4096 - yalpha;
  1499. int uvalpha1 = 4096 - uvalpha;
  1500. int i;
  1501. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1502. int err[4] = {0};
  1503. int A = 0; // init to silcene warning
  1504. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1505. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1506. step = 1;
  1507. for (i = 0; i < dstW; i++) {
  1508. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1509. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1510. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1511. if (hasAlpha) {
  1512. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1513. if (A & 0x100)
  1514. A = av_clip_uint8(A);
  1515. }
  1516. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1517. dest += step;
  1518. }
  1519. c->dither_error[0][i] = err[0];
  1520. c->dither_error[1][i] = err[1];
  1521. c->dither_error[2][i] = err[2];
  1522. }
  1523. static av_always_inline void
  1524. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1525. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1526. const int16_t *abuf0, uint8_t *dest, int dstW,
  1527. int uvalpha, int y, enum AVPixelFormat target,
  1528. int hasAlpha)
  1529. {
  1530. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1531. int i;
  1532. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1533. int err[4] = {0};
  1534. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1535. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1536. step = 1;
  1537. if (uvalpha < 2048) {
  1538. int A = 0; //init to silence warning
  1539. for (i = 0; i < dstW; i++) {
  1540. int Y = buf0[i] << 2;
  1541. int U = (ubuf0[i] - (128<<7)) << 2;
  1542. int V = (vbuf0[i] - (128<<7)) << 2;
  1543. if (hasAlpha) {
  1544. A = (abuf0[i] + 64) >> 7;
  1545. if (A & 0x100)
  1546. A = av_clip_uint8(A);
  1547. }
  1548. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1549. dest += step;
  1550. }
  1551. } else {
  1552. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1553. int A = 0; //init to silence warning
  1554. for (i = 0; i < dstW; i++) {
  1555. int Y = buf0[i] << 2;
  1556. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
  1557. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
  1558. if (hasAlpha) {
  1559. A = (abuf0[i] + 64) >> 7;
  1560. if (A & 0x100)
  1561. A = av_clip_uint8(A);
  1562. }
  1563. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1564. dest += step;
  1565. }
  1566. }
  1567. c->dither_error[0][i] = err[0];
  1568. c->dither_error[1][i] = err[1];
  1569. c->dither_error[2][i] = err[2];
  1570. }
  1571. #if CONFIG_SMALL
  1572. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1573. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1574. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1575. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1576. #else
  1577. #if CONFIG_SWSCALE_ALPHA
  1578. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1579. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1580. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1581. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1582. #endif
  1583. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1584. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1585. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1586. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1587. #endif
  1588. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1589. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1590. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  1591. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  1592. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  1593. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  1594. static void
  1595. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1596. const int16_t **lumSrc, int lumFilterSize,
  1597. const int16_t *chrFilter, const int16_t **chrUSrc,
  1598. const int16_t **chrVSrc, int chrFilterSize,
  1599. const int16_t **alpSrc, uint8_t **dest,
  1600. int dstW, int y)
  1601. {
  1602. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1603. int i;
  1604. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1605. uint16_t **dest16 = (uint16_t**)dest;
  1606. int SH = 22 + 7 - desc->comp[0].depth_minus1;
  1607. int A = 0; // init to silence warning
  1608. for (i = 0; i < dstW; i++) {
  1609. int j;
  1610. int Y = 1 << 9;
  1611. int U = (1 << 9) - (128 << 19);
  1612. int V = (1 << 9) - (128 << 19);
  1613. int R, G, B;
  1614. for (j = 0; j < lumFilterSize; j++)
  1615. Y += lumSrc[j][i] * lumFilter[j];
  1616. for (j = 0; j < chrFilterSize; j++) {
  1617. U += chrUSrc[j][i] * chrFilter[j];
  1618. V += chrVSrc[j][i] * chrFilter[j];
  1619. }
  1620. Y >>= 10;
  1621. U >>= 10;
  1622. V >>= 10;
  1623. if (hasAlpha) {
  1624. A = 1 << 18;
  1625. for (j = 0; j < lumFilterSize; j++)
  1626. A += alpSrc[j][i] * lumFilter[j];
  1627. A >>= 19;
  1628. if (A & 0x100)
  1629. A = av_clip_uint8(A);
  1630. }
  1631. Y -= c->yuv2rgb_y_offset;
  1632. Y *= c->yuv2rgb_y_coeff;
  1633. Y += 1 << 21;
  1634. R = Y + V * c->yuv2rgb_v2r_coeff;
  1635. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1636. B = Y + U * c->yuv2rgb_u2b_coeff;
  1637. if ((R | G | B) & 0xC0000000) {
  1638. R = av_clip_uintp2(R, 30);
  1639. G = av_clip_uintp2(G, 30);
  1640. B = av_clip_uintp2(B, 30);
  1641. }
  1642. if (SH != 22) {
  1643. dest16[0][i] = G >> SH;
  1644. dest16[1][i] = B >> SH;
  1645. dest16[2][i] = R >> SH;
  1646. if (hasAlpha)
  1647. dest16[3][i] = A;
  1648. } else {
  1649. dest[0][i] = G >> 22;
  1650. dest[1][i] = B >> 22;
  1651. dest[2][i] = R >> 22;
  1652. if (hasAlpha)
  1653. dest[3][i] = A;
  1654. }
  1655. }
  1656. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1657. for (i = 0; i < dstW; i++) {
  1658. dest16[0][i] = av_bswap16(dest16[0][i]);
  1659. dest16[1][i] = av_bswap16(dest16[1][i]);
  1660. dest16[2][i] = av_bswap16(dest16[2][i]);
  1661. if (hasAlpha)
  1662. dest16[3][i] = av_bswap16(dest16[3][i]);
  1663. }
  1664. }
  1665. }
  1666. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1667. yuv2planar1_fn *yuv2plane1,
  1668. yuv2planarX_fn *yuv2planeX,
  1669. yuv2interleavedX_fn *yuv2nv12cX,
  1670. yuv2packed1_fn *yuv2packed1,
  1671. yuv2packed2_fn *yuv2packed2,
  1672. yuv2packedX_fn *yuv2packedX,
  1673. yuv2anyX_fn *yuv2anyX)
  1674. {
  1675. enum AVPixelFormat dstFormat = c->dstFormat;
  1676. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  1677. if (is16BPS(dstFormat)) {
  1678. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1679. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1680. } else if (is9_OR_10BPS(dstFormat)) {
  1681. if (desc->comp[0].depth_minus1 == 8) {
  1682. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1683. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1684. } else if (desc->comp[0].depth_minus1 == 9) {
  1685. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1686. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1687. } else if (desc->comp[0].depth_minus1 == 11) {
  1688. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  1689. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  1690. } else if (desc->comp[0].depth_minus1 == 13) {
  1691. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  1692. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  1693. } else
  1694. av_assert0(0);
  1695. } else {
  1696. *yuv2plane1 = yuv2plane1_8_c;
  1697. *yuv2planeX = yuv2planeX_8_c;
  1698. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  1699. *yuv2nv12cX = yuv2nv12cX_c;
  1700. }
  1701. if(c->flags & SWS_FULL_CHR_H_INT) {
  1702. switch (dstFormat) {
  1703. case AV_PIX_FMT_RGBA:
  1704. #if CONFIG_SMALL
  1705. *yuv2packedX = yuv2rgba32_full_X_c;
  1706. *yuv2packed2 = yuv2rgba32_full_2_c;
  1707. *yuv2packed1 = yuv2rgba32_full_1_c;
  1708. #else
  1709. #if CONFIG_SWSCALE_ALPHA
  1710. if (c->alpPixBuf) {
  1711. *yuv2packedX = yuv2rgba32_full_X_c;
  1712. *yuv2packed2 = yuv2rgba32_full_2_c;
  1713. *yuv2packed1 = yuv2rgba32_full_1_c;
  1714. } else
  1715. #endif /* CONFIG_SWSCALE_ALPHA */
  1716. {
  1717. *yuv2packedX = yuv2rgbx32_full_X_c;
  1718. *yuv2packed2 = yuv2rgbx32_full_2_c;
  1719. *yuv2packed1 = yuv2rgbx32_full_1_c;
  1720. }
  1721. #endif /* !CONFIG_SMALL */
  1722. break;
  1723. case AV_PIX_FMT_ARGB:
  1724. #if CONFIG_SMALL
  1725. *yuv2packedX = yuv2argb32_full_X_c;
  1726. *yuv2packed2 = yuv2argb32_full_2_c;
  1727. *yuv2packed1 = yuv2argb32_full_1_c;
  1728. #else
  1729. #if CONFIG_SWSCALE_ALPHA
  1730. if (c->alpPixBuf) {
  1731. *yuv2packedX = yuv2argb32_full_X_c;
  1732. *yuv2packed2 = yuv2argb32_full_2_c;
  1733. *yuv2packed1 = yuv2argb32_full_1_c;
  1734. } else
  1735. #endif /* CONFIG_SWSCALE_ALPHA */
  1736. {
  1737. *yuv2packedX = yuv2xrgb32_full_X_c;
  1738. *yuv2packed2 = yuv2xrgb32_full_2_c;
  1739. *yuv2packed1 = yuv2xrgb32_full_1_c;
  1740. }
  1741. #endif /* !CONFIG_SMALL */
  1742. break;
  1743. case AV_PIX_FMT_BGRA:
  1744. #if CONFIG_SMALL
  1745. *yuv2packedX = yuv2bgra32_full_X_c;
  1746. *yuv2packed2 = yuv2bgra32_full_2_c;
  1747. *yuv2packed1 = yuv2bgra32_full_1_c;
  1748. #else
  1749. #if CONFIG_SWSCALE_ALPHA
  1750. if (c->alpPixBuf) {
  1751. *yuv2packedX = yuv2bgra32_full_X_c;
  1752. *yuv2packed2 = yuv2bgra32_full_2_c;
  1753. *yuv2packed1 = yuv2bgra32_full_1_c;
  1754. } else
  1755. #endif /* CONFIG_SWSCALE_ALPHA */
  1756. {
  1757. *yuv2packedX = yuv2bgrx32_full_X_c;
  1758. *yuv2packed2 = yuv2bgrx32_full_2_c;
  1759. *yuv2packed1 = yuv2bgrx32_full_1_c;
  1760. }
  1761. #endif /* !CONFIG_SMALL */
  1762. break;
  1763. case AV_PIX_FMT_ABGR:
  1764. #if CONFIG_SMALL
  1765. *yuv2packedX = yuv2abgr32_full_X_c;
  1766. *yuv2packed2 = yuv2abgr32_full_2_c;
  1767. *yuv2packed1 = yuv2abgr32_full_1_c;
  1768. #else
  1769. #if CONFIG_SWSCALE_ALPHA
  1770. if (c->alpPixBuf) {
  1771. *yuv2packedX = yuv2abgr32_full_X_c;
  1772. *yuv2packed2 = yuv2abgr32_full_2_c;
  1773. *yuv2packed1 = yuv2abgr32_full_1_c;
  1774. } else
  1775. #endif /* CONFIG_SWSCALE_ALPHA */
  1776. {
  1777. *yuv2packedX = yuv2xbgr32_full_X_c;
  1778. *yuv2packed2 = yuv2xbgr32_full_2_c;
  1779. *yuv2packed1 = yuv2xbgr32_full_1_c;
  1780. }
  1781. #endif /* !CONFIG_SMALL */
  1782. break;
  1783. case AV_PIX_FMT_RGB24:
  1784. *yuv2packedX = yuv2rgb24_full_X_c;
  1785. *yuv2packed2 = yuv2rgb24_full_2_c;
  1786. *yuv2packed1 = yuv2rgb24_full_1_c;
  1787. break;
  1788. case AV_PIX_FMT_BGR24:
  1789. *yuv2packedX = yuv2bgr24_full_X_c;
  1790. *yuv2packed2 = yuv2bgr24_full_2_c;
  1791. *yuv2packed1 = yuv2bgr24_full_1_c;
  1792. break;
  1793. case AV_PIX_FMT_BGR4_BYTE:
  1794. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  1795. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  1796. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  1797. break;
  1798. case AV_PIX_FMT_RGB4_BYTE:
  1799. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  1800. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  1801. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  1802. break;
  1803. case AV_PIX_FMT_BGR8:
  1804. *yuv2packedX = yuv2bgr8_full_X_c;
  1805. *yuv2packed2 = yuv2bgr8_full_2_c;
  1806. *yuv2packed1 = yuv2bgr8_full_1_c;
  1807. break;
  1808. case AV_PIX_FMT_RGB8:
  1809. *yuv2packedX = yuv2rgb8_full_X_c;
  1810. *yuv2packed2 = yuv2rgb8_full_2_c;
  1811. *yuv2packed1 = yuv2rgb8_full_1_c;
  1812. break;
  1813. case AV_PIX_FMT_GBRP:
  1814. case AV_PIX_FMT_GBRP9BE:
  1815. case AV_PIX_FMT_GBRP9LE:
  1816. case AV_PIX_FMT_GBRP10BE:
  1817. case AV_PIX_FMT_GBRP10LE:
  1818. case AV_PIX_FMT_GBRP12BE:
  1819. case AV_PIX_FMT_GBRP12LE:
  1820. case AV_PIX_FMT_GBRP14BE:
  1821. case AV_PIX_FMT_GBRP14LE:
  1822. case AV_PIX_FMT_GBRP16BE:
  1823. case AV_PIX_FMT_GBRP16LE:
  1824. case AV_PIX_FMT_GBRAP:
  1825. *yuv2anyX = yuv2gbrp_full_X_c;
  1826. break;
  1827. }
  1828. if (!*yuv2packedX && !*yuv2anyX)
  1829. goto YUV_PACKED;
  1830. } else {
  1831. YUV_PACKED:
  1832. switch (dstFormat) {
  1833. case AV_PIX_FMT_RGBA64LE:
  1834. #if CONFIG_SWSCALE_ALPHA
  1835. if (c->alpPixBuf) {
  1836. *yuv2packed1 = yuv2rgba64le_1_c;
  1837. *yuv2packed2 = yuv2rgba64le_2_c;
  1838. *yuv2packedX = yuv2rgba64le_X_c;
  1839. } else
  1840. #endif /* CONFIG_SWSCALE_ALPHA */
  1841. {
  1842. *yuv2packed1 = yuv2rgbx64le_1_c;
  1843. *yuv2packed2 = yuv2rgbx64le_2_c;
  1844. *yuv2packedX = yuv2rgbx64le_X_c;
  1845. }
  1846. break;
  1847. case AV_PIX_FMT_RGBA64BE:
  1848. #if CONFIG_SWSCALE_ALPHA
  1849. if (c->alpPixBuf) {
  1850. *yuv2packed1 = yuv2rgba64be_1_c;
  1851. *yuv2packed2 = yuv2rgba64be_2_c;
  1852. *yuv2packedX = yuv2rgba64be_X_c;
  1853. } else
  1854. #endif /* CONFIG_SWSCALE_ALPHA */
  1855. {
  1856. *yuv2packed1 = yuv2rgbx64be_1_c;
  1857. *yuv2packed2 = yuv2rgbx64be_2_c;
  1858. *yuv2packedX = yuv2rgbx64be_X_c;
  1859. }
  1860. break;
  1861. case AV_PIX_FMT_BGRA64LE:
  1862. #if CONFIG_SWSCALE_ALPHA
  1863. if (c->alpPixBuf) {
  1864. *yuv2packed1 = yuv2bgra64le_1_c;
  1865. *yuv2packed2 = yuv2bgra64le_2_c;
  1866. *yuv2packedX = yuv2bgra64le_X_c;
  1867. } else
  1868. #endif /* CONFIG_SWSCALE_ALPHA */
  1869. {
  1870. *yuv2packed1 = yuv2bgrx64le_1_c;
  1871. *yuv2packed2 = yuv2bgrx64le_2_c;
  1872. *yuv2packedX = yuv2bgrx64le_X_c;
  1873. }
  1874. break;
  1875. case AV_PIX_FMT_BGRA64BE:
  1876. #if CONFIG_SWSCALE_ALPHA
  1877. if (c->alpPixBuf) {
  1878. *yuv2packed1 = yuv2bgra64be_1_c;
  1879. *yuv2packed2 = yuv2bgra64be_2_c;
  1880. *yuv2packedX = yuv2bgra64be_X_c;
  1881. } else
  1882. #endif /* CONFIG_SWSCALE_ALPHA */
  1883. {
  1884. *yuv2packed1 = yuv2bgrx64be_1_c;
  1885. *yuv2packed2 = yuv2bgrx64be_2_c;
  1886. *yuv2packedX = yuv2bgrx64be_X_c;
  1887. }
  1888. break;
  1889. case AV_PIX_FMT_RGB48LE:
  1890. *yuv2packed1 = yuv2rgb48le_1_c;
  1891. *yuv2packed2 = yuv2rgb48le_2_c;
  1892. *yuv2packedX = yuv2rgb48le_X_c;
  1893. break;
  1894. case AV_PIX_FMT_RGB48BE:
  1895. *yuv2packed1 = yuv2rgb48be_1_c;
  1896. *yuv2packed2 = yuv2rgb48be_2_c;
  1897. *yuv2packedX = yuv2rgb48be_X_c;
  1898. break;
  1899. case AV_PIX_FMT_BGR48LE:
  1900. *yuv2packed1 = yuv2bgr48le_1_c;
  1901. *yuv2packed2 = yuv2bgr48le_2_c;
  1902. *yuv2packedX = yuv2bgr48le_X_c;
  1903. break;
  1904. case AV_PIX_FMT_BGR48BE:
  1905. *yuv2packed1 = yuv2bgr48be_1_c;
  1906. *yuv2packed2 = yuv2bgr48be_2_c;
  1907. *yuv2packedX = yuv2bgr48be_X_c;
  1908. break;
  1909. case AV_PIX_FMT_RGB32:
  1910. case AV_PIX_FMT_BGR32:
  1911. #if CONFIG_SMALL
  1912. *yuv2packed1 = yuv2rgb32_1_c;
  1913. *yuv2packed2 = yuv2rgb32_2_c;
  1914. *yuv2packedX = yuv2rgb32_X_c;
  1915. #else
  1916. #if CONFIG_SWSCALE_ALPHA
  1917. if (c->alpPixBuf) {
  1918. *yuv2packed1 = yuv2rgba32_1_c;
  1919. *yuv2packed2 = yuv2rgba32_2_c;
  1920. *yuv2packedX = yuv2rgba32_X_c;
  1921. } else
  1922. #endif /* CONFIG_SWSCALE_ALPHA */
  1923. {
  1924. *yuv2packed1 = yuv2rgbx32_1_c;
  1925. *yuv2packed2 = yuv2rgbx32_2_c;
  1926. *yuv2packedX = yuv2rgbx32_X_c;
  1927. }
  1928. #endif /* !CONFIG_SMALL */
  1929. break;
  1930. case AV_PIX_FMT_RGB32_1:
  1931. case AV_PIX_FMT_BGR32_1:
  1932. #if CONFIG_SMALL
  1933. *yuv2packed1 = yuv2rgb32_1_1_c;
  1934. *yuv2packed2 = yuv2rgb32_1_2_c;
  1935. *yuv2packedX = yuv2rgb32_1_X_c;
  1936. #else
  1937. #if CONFIG_SWSCALE_ALPHA
  1938. if (c->alpPixBuf) {
  1939. *yuv2packed1 = yuv2rgba32_1_1_c;
  1940. *yuv2packed2 = yuv2rgba32_1_2_c;
  1941. *yuv2packedX = yuv2rgba32_1_X_c;
  1942. } else
  1943. #endif /* CONFIG_SWSCALE_ALPHA */
  1944. {
  1945. *yuv2packed1 = yuv2rgbx32_1_1_c;
  1946. *yuv2packed2 = yuv2rgbx32_1_2_c;
  1947. *yuv2packedX = yuv2rgbx32_1_X_c;
  1948. }
  1949. #endif /* !CONFIG_SMALL */
  1950. break;
  1951. case AV_PIX_FMT_RGB24:
  1952. *yuv2packed1 = yuv2rgb24_1_c;
  1953. *yuv2packed2 = yuv2rgb24_2_c;
  1954. *yuv2packedX = yuv2rgb24_X_c;
  1955. break;
  1956. case AV_PIX_FMT_BGR24:
  1957. *yuv2packed1 = yuv2bgr24_1_c;
  1958. *yuv2packed2 = yuv2bgr24_2_c;
  1959. *yuv2packedX = yuv2bgr24_X_c;
  1960. break;
  1961. case AV_PIX_FMT_RGB565LE:
  1962. case AV_PIX_FMT_RGB565BE:
  1963. case AV_PIX_FMT_BGR565LE:
  1964. case AV_PIX_FMT_BGR565BE:
  1965. *yuv2packed1 = yuv2rgb16_1_c;
  1966. *yuv2packed2 = yuv2rgb16_2_c;
  1967. *yuv2packedX = yuv2rgb16_X_c;
  1968. break;
  1969. case AV_PIX_FMT_RGB555LE:
  1970. case AV_PIX_FMT_RGB555BE:
  1971. case AV_PIX_FMT_BGR555LE:
  1972. case AV_PIX_FMT_BGR555BE:
  1973. *yuv2packed1 = yuv2rgb15_1_c;
  1974. *yuv2packed2 = yuv2rgb15_2_c;
  1975. *yuv2packedX = yuv2rgb15_X_c;
  1976. break;
  1977. case AV_PIX_FMT_RGB444LE:
  1978. case AV_PIX_FMT_RGB444BE:
  1979. case AV_PIX_FMT_BGR444LE:
  1980. case AV_PIX_FMT_BGR444BE:
  1981. *yuv2packed1 = yuv2rgb12_1_c;
  1982. *yuv2packed2 = yuv2rgb12_2_c;
  1983. *yuv2packedX = yuv2rgb12_X_c;
  1984. break;
  1985. case AV_PIX_FMT_RGB8:
  1986. case AV_PIX_FMT_BGR8:
  1987. *yuv2packed1 = yuv2rgb8_1_c;
  1988. *yuv2packed2 = yuv2rgb8_2_c;
  1989. *yuv2packedX = yuv2rgb8_X_c;
  1990. break;
  1991. case AV_PIX_FMT_RGB4:
  1992. case AV_PIX_FMT_BGR4:
  1993. *yuv2packed1 = yuv2rgb4_1_c;
  1994. *yuv2packed2 = yuv2rgb4_2_c;
  1995. *yuv2packedX = yuv2rgb4_X_c;
  1996. break;
  1997. case AV_PIX_FMT_RGB4_BYTE:
  1998. case AV_PIX_FMT_BGR4_BYTE:
  1999. *yuv2packed1 = yuv2rgb4b_1_c;
  2000. *yuv2packed2 = yuv2rgb4b_2_c;
  2001. *yuv2packedX = yuv2rgb4b_X_c;
  2002. break;
  2003. }
  2004. }
  2005. switch (dstFormat) {
  2006. case AV_PIX_FMT_MONOWHITE:
  2007. *yuv2packed1 = yuv2monowhite_1_c;
  2008. *yuv2packed2 = yuv2monowhite_2_c;
  2009. *yuv2packedX = yuv2monowhite_X_c;
  2010. break;
  2011. case AV_PIX_FMT_MONOBLACK:
  2012. *yuv2packed1 = yuv2monoblack_1_c;
  2013. *yuv2packed2 = yuv2monoblack_2_c;
  2014. *yuv2packedX = yuv2monoblack_X_c;
  2015. break;
  2016. case AV_PIX_FMT_YUYV422:
  2017. *yuv2packed1 = yuv2yuyv422_1_c;
  2018. *yuv2packed2 = yuv2yuyv422_2_c;
  2019. *yuv2packedX = yuv2yuyv422_X_c;
  2020. break;
  2021. case AV_PIX_FMT_YVYU422:
  2022. *yuv2packed1 = yuv2yvyu422_1_c;
  2023. *yuv2packed2 = yuv2yvyu422_2_c;
  2024. *yuv2packedX = yuv2yvyu422_X_c;
  2025. break;
  2026. case AV_PIX_FMT_UYVY422:
  2027. *yuv2packed1 = yuv2uyvy422_1_c;
  2028. *yuv2packed2 = yuv2uyvy422_2_c;
  2029. *yuv2packedX = yuv2uyvy422_X_c;
  2030. break;
  2031. }
  2032. }