output.c 99 KB

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