swscale.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608
  1. /*
  2. * Copyright (C) 2001-2003 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. /*
  21. supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR32_1, BGR24, BGR16, BGR15, RGB32, RGB32_1, RGB24, Y8/Y800, YVU9/IF09, PAL8
  22. supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
  23. {BGR,RGB}{1,4,8,15,16} support dithering
  24. unscaled special converters (YV12=I420=IYUV, Y800=Y8)
  25. YV12 -> {BGR,RGB}{1,4,8,12,15,16,24,32}
  26. x -> x
  27. YUV9 -> YV12
  28. YUV9/YV12 -> Y800
  29. Y800 -> YUV9/YV12
  30. BGR24 -> BGR32 & RGB24 -> RGB32
  31. BGR32 -> BGR24 & RGB32 -> RGB24
  32. BGR15 -> BGR16
  33. */
  34. /*
  35. tested special converters (most are tested actually, but I did not write it down ...)
  36. YV12 -> BGR12/BGR16
  37. YV12 -> YV12
  38. BGR15 -> BGR16
  39. BGR16 -> BGR16
  40. YVU9 -> YV12
  41. untested special converters
  42. YV12/I420 -> BGR15/BGR24/BGR32 (it is the yuv2rgb stuff, so it should be OK)
  43. YV12/I420 -> YV12/I420
  44. YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format
  45. BGR24 -> BGR32 & RGB24 -> RGB32
  46. BGR32 -> BGR24 & RGB32 -> RGB24
  47. BGR24 -> YV12
  48. */
  49. #include <inttypes.h>
  50. #include <string.h>
  51. #include <math.h>
  52. #include <stdio.h>
  53. #include "config.h"
  54. #include <assert.h>
  55. #include "swscale.h"
  56. #include "swscale_internal.h"
  57. #include "rgb2rgb.h"
  58. #include "libavutil/avassert.h"
  59. #include "libavutil/intreadwrite.h"
  60. #include "libavutil/cpu.h"
  61. #include "libavutil/avutil.h"
  62. #include "libavutil/mathematics.h"
  63. #include "libavutil/bswap.h"
  64. #include "libavutil/pixdesc.h"
  65. #define RGB2YUV_SHIFT 15
  66. #define BY ( (int)(0.114*219/255*(1<<RGB2YUV_SHIFT)+0.5))
  67. #define BV (-(int)(0.081*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  68. #define BU ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  69. #define GY ( (int)(0.587*219/255*(1<<RGB2YUV_SHIFT)+0.5))
  70. #define GV (-(int)(0.419*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  71. #define GU (-(int)(0.331*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  72. #define RY ( (int)(0.299*219/255*(1<<RGB2YUV_SHIFT)+0.5))
  73. #define RV ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  74. #define RU (-(int)(0.169*224/255*(1<<RGB2YUV_SHIFT)+0.5))
  75. static const double rgb2yuv_table[8][9]={
  76. {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5}, //ITU709
  77. {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5}, //ITU709
  78. {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
  79. {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
  80. {0.59 , 0.11 , 0.30 , -0.331, 0.5, -0.169, -0.421, -0.079, 0.5}, //FCC
  81. {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
  82. {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
  83. {0.701 , 0.087 , 0.212 , -0.384, 0.5, -0.116, -0.445, -0.055, 0.5}, //SMPTE 240M
  84. };
  85. /*
  86. NOTES
  87. Special versions: fast Y 1:1 scaling (no interpolation in y direction)
  88. TODO
  89. more intelligent misalignment avoidance for the horizontal scaler
  90. write special vertical cubic upscale version
  91. optimize C code (YV12 / minmax)
  92. add support for packed pixel YUV input & output
  93. add support for Y8 output
  94. optimize BGR24 & BGR32
  95. add BGR4 output support
  96. write special BGR->BGR scaler
  97. */
  98. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={
  99. { 1, 3, 1, 3, 1, 3, 1, 3, },
  100. { 2, 0, 2, 0, 2, 0, 2, 0, },
  101. };
  102. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8)[2][8]={
  103. { 6, 2, 6, 2, 6, 2, 6, 2, },
  104. { 0, 4, 0, 4, 0, 4, 0, 4, },
  105. };
  106. DECLARE_ALIGNED(8, const uint8_t, dither_4x4_16)[4][8]={
  107. { 8, 4, 11, 7, 8, 4, 11, 7, },
  108. { 2, 14, 1, 13, 2, 14, 1, 13, },
  109. { 10, 6, 9, 5, 10, 6, 9, 5, },
  110. { 0, 12, 3, 15, 0, 12, 3, 15, },
  111. };
  112. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[8][8]={
  113. { 17, 9, 23, 15, 16, 8, 22, 14, },
  114. { 5, 29, 3, 27, 4, 28, 2, 26, },
  115. { 21, 13, 19, 11, 20, 12, 18, 10, },
  116. { 0, 24, 6, 30, 1, 25, 7, 31, },
  117. { 16, 8, 22, 14, 17, 9, 23, 15, },
  118. { 4, 28, 2, 26, 5, 29, 3, 27, },
  119. { 20, 12, 18, 10, 21, 13, 19, 11, },
  120. { 1, 25, 7, 31, 0, 24, 6, 30, },
  121. };
  122. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[8][8]={
  123. { 0, 55, 14, 68, 3, 58, 17, 72, },
  124. { 37, 18, 50, 32, 40, 22, 54, 35, },
  125. { 9, 64, 5, 59, 13, 67, 8, 63, },
  126. { 46, 27, 41, 23, 49, 31, 44, 26, },
  127. { 2, 57, 16, 71, 1, 56, 15, 70, },
  128. { 39, 21, 52, 34, 38, 19, 51, 33, },
  129. { 11, 66, 7, 62, 10, 65, 6, 60, },
  130. { 48, 30, 43, 25, 47, 29, 42, 24, },
  131. };
  132. #if 1
  133. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  134. {117, 62, 158, 103, 113, 58, 155, 100, },
  135. { 34, 199, 21, 186, 31, 196, 17, 182, },
  136. {144, 89, 131, 76, 141, 86, 127, 72, },
  137. { 0, 165, 41, 206, 10, 175, 52, 217, },
  138. {110, 55, 151, 96, 120, 65, 162, 107, },
  139. { 28, 193, 14, 179, 38, 203, 24, 189, },
  140. {138, 83, 124, 69, 148, 93, 134, 79, },
  141. { 7, 172, 48, 213, 3, 168, 45, 210, },
  142. };
  143. #elif 1
  144. // tries to correct a gamma of 1.5
  145. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  146. { 0, 143, 18, 200, 2, 156, 25, 215, },
  147. { 78, 28, 125, 64, 89, 36, 138, 74, },
  148. { 10, 180, 3, 161, 16, 195, 8, 175, },
  149. {109, 51, 93, 38, 121, 60, 105, 47, },
  150. { 1, 152, 23, 210, 0, 147, 20, 205, },
  151. { 85, 33, 134, 71, 81, 30, 130, 67, },
  152. { 14, 190, 6, 171, 12, 185, 5, 166, },
  153. {117, 57, 101, 44, 113, 54, 97, 41, },
  154. };
  155. #elif 1
  156. // tries to correct a gamma of 2.0
  157. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  158. { 0, 124, 8, 193, 0, 140, 12, 213, },
  159. { 55, 14, 104, 42, 66, 19, 119, 52, },
  160. { 3, 168, 1, 145, 6, 187, 3, 162, },
  161. { 86, 31, 70, 21, 99, 39, 82, 28, },
  162. { 0, 134, 11, 206, 0, 129, 9, 200, },
  163. { 62, 17, 114, 48, 58, 16, 109, 45, },
  164. { 5, 181, 2, 157, 4, 175, 1, 151, },
  165. { 95, 36, 78, 26, 90, 34, 74, 24, },
  166. };
  167. #else
  168. // tries to correct a gamma of 2.5
  169. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  170. { 0, 107, 3, 187, 0, 125, 6, 212, },
  171. { 39, 7, 86, 28, 49, 11, 102, 36, },
  172. { 1, 158, 0, 131, 3, 180, 1, 151, },
  173. { 68, 19, 52, 12, 81, 25, 64, 17, },
  174. { 0, 119, 5, 203, 0, 113, 4, 195, },
  175. { 45, 9, 96, 33, 42, 8, 91, 30, },
  176. { 2, 172, 1, 144, 2, 165, 0, 137, },
  177. { 77, 23, 60, 15, 72, 21, 56, 14, },
  178. };
  179. #endif
  180. DECLARE_ALIGNED(8, const uint8_t, dithers)[8][8][8]={
  181. {
  182. { 0, 1, 0, 1, 0, 1, 0, 1,},
  183. { 1, 0, 1, 0, 1, 0, 1, 0,},
  184. { 0, 1, 0, 1, 0, 1, 0, 1,},
  185. { 1, 0, 1, 0, 1, 0, 1, 0,},
  186. { 0, 1, 0, 1, 0, 1, 0, 1,},
  187. { 1, 0, 1, 0, 1, 0, 1, 0,},
  188. { 0, 1, 0, 1, 0, 1, 0, 1,},
  189. { 1, 0, 1, 0, 1, 0, 1, 0,},
  190. },{
  191. { 1, 2, 1, 2, 1, 2, 1, 2,},
  192. { 3, 0, 3, 0, 3, 0, 3, 0,},
  193. { 1, 2, 1, 2, 1, 2, 1, 2,},
  194. { 3, 0, 3, 0, 3, 0, 3, 0,},
  195. { 1, 2, 1, 2, 1, 2, 1, 2,},
  196. { 3, 0, 3, 0, 3, 0, 3, 0,},
  197. { 1, 2, 1, 2, 1, 2, 1, 2,},
  198. { 3, 0, 3, 0, 3, 0, 3, 0,},
  199. },{
  200. { 2, 4, 3, 5, 2, 4, 3, 5,},
  201. { 6, 0, 7, 1, 6, 0, 7, 1,},
  202. { 3, 5, 2, 4, 3, 5, 2, 4,},
  203. { 7, 1, 6, 0, 7, 1, 6, 0,},
  204. { 2, 4, 3, 5, 2, 4, 3, 5,},
  205. { 6, 0, 7, 1, 6, 0, 7, 1,},
  206. { 3, 5, 2, 4, 3, 5, 2, 4,},
  207. { 7, 1, 6, 0, 7, 1, 6, 0,},
  208. },{
  209. { 4, 8, 7, 11, 4, 8, 7, 11,},
  210. { 12, 0, 15, 3, 12, 0, 15, 3,},
  211. { 6, 10, 5, 9, 6, 10, 5, 9,},
  212. { 14, 2, 13, 1, 14, 2, 13, 1,},
  213. { 4, 8, 7, 11, 4, 8, 7, 11,},
  214. { 12, 0, 15, 3, 12, 0, 15, 3,},
  215. { 6, 10, 5, 9, 6, 10, 5, 9,},
  216. { 14, 2, 13, 1, 14, 2, 13, 1,},
  217. },{
  218. { 9, 17, 15, 23, 8, 16, 14, 22,},
  219. { 25, 1, 31, 7, 24, 0, 30, 6,},
  220. { 13, 21, 11, 19, 12, 20, 10, 18,},
  221. { 29, 5, 27, 3, 28, 4, 26, 2,},
  222. { 8, 16, 14, 22, 9, 17, 15, 23,},
  223. { 24, 0, 30, 6, 25, 1, 31, 7,},
  224. { 12, 20, 10, 18, 13, 21, 11, 19,},
  225. { 28, 4, 26, 2, 29, 5, 27, 3,},
  226. },{
  227. { 18, 34, 30, 46, 17, 33, 29, 45,},
  228. { 50, 2, 62, 14, 49, 1, 61, 13,},
  229. { 26, 42, 22, 38, 25, 41, 21, 37,},
  230. { 58, 10, 54, 6, 57, 9, 53, 5,},
  231. { 16, 32, 28, 44, 19, 35, 31, 47,},
  232. { 48, 0, 60, 12, 51, 3, 63, 15,},
  233. { 24, 40, 20, 36, 27, 43, 23, 39,},
  234. { 56, 8, 52, 4, 59, 11, 55, 7,},
  235. },{
  236. { 18, 34, 30, 46, 17, 33, 29, 45,},
  237. { 50, 2, 62, 14, 49, 1, 61, 13,},
  238. { 26, 42, 22, 38, 25, 41, 21, 37,},
  239. { 58, 10, 54, 6, 57, 9, 53, 5,},
  240. { 16, 32, 28, 44, 19, 35, 31, 47,},
  241. { 48, 0, 60, 12, 51, 3, 63, 15,},
  242. { 24, 40, 20, 36, 27, 43, 23, 39,},
  243. { 56, 8, 52, 4, 59, 11, 55, 7,},
  244. },{
  245. { 36, 68, 60, 92, 34, 66, 58, 90,},
  246. { 100, 4,124, 28, 98, 2,122, 26,},
  247. { 52, 84, 44, 76, 50, 82, 42, 74,},
  248. { 116, 20,108, 12,114, 18,106, 10,},
  249. { 32, 64, 56, 88, 38, 70, 62, 94,},
  250. { 96, 0,120, 24,102, 6,126, 30,},
  251. { 48, 80, 40, 72, 54, 86, 46, 78,},
  252. { 112, 16,104, 8,118, 22,110, 14,},
  253. }};
  254. static const uint8_t flat64[8]={64,64,64,64,64,64,64,64};
  255. const uint16_t dither_scale[15][16]={
  256. { 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,},
  257. { 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,},
  258. { 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,},
  259. { 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,},
  260. { 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,},
  261. { 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,},
  262. { 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,},
  263. { 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,},
  264. { 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,},
  265. { 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,},
  266. { 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,},
  267. { 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,},
  268. { 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,},
  269. { 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,},
  270. { 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,},
  271. };
  272. static av_always_inline void
  273. yuv2yuvX16_c_template(const int16_t *lumFilter, const int16_t **lumSrc,
  274. int lumFilterSize, const int16_t *chrFilter,
  275. const int16_t **chrUSrc, const int16_t **chrVSrc,
  276. int chrFilterSize, const int16_t **alpSrc,
  277. uint16_t *dest, uint16_t *uDest, uint16_t *vDest,
  278. uint16_t *aDest, int dstW, int chrDstW,
  279. int big_endian, int output_bits)
  280. {
  281. //FIXME Optimize (just quickly written not optimized..)
  282. int i;
  283. int shift = 11 + 16 - output_bits;
  284. #define output_pixel(pos, val) \
  285. if (big_endian) { \
  286. if (output_bits == 16) { \
  287. AV_WB16(pos, av_clip_uint16(val >> shift)); \
  288. } else { \
  289. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  290. } \
  291. } else { \
  292. if (output_bits == 16) { \
  293. AV_WL16(pos, av_clip_uint16(val >> shift)); \
  294. } else { \
  295. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  296. } \
  297. }
  298. for (i = 0; i < dstW; i++) {
  299. int val = 1 << (26-output_bits);
  300. int j;
  301. for (j = 0; j < lumFilterSize; j++)
  302. val += lumSrc[j][i] * lumFilter[j];
  303. output_pixel(&dest[i], val);
  304. }
  305. if (uDest) {
  306. for (i = 0; i < chrDstW; i++) {
  307. int u = 1 << (26-output_bits);
  308. int v = 1 << (26-output_bits);
  309. int j;
  310. for (j = 0; j < chrFilterSize; j++) {
  311. u += chrUSrc[j][i] * chrFilter[j];
  312. v += chrVSrc[j][i] * chrFilter[j];
  313. }
  314. output_pixel(&uDest[i], u);
  315. output_pixel(&vDest[i], v);
  316. }
  317. }
  318. if (CONFIG_SWSCALE_ALPHA && aDest) {
  319. for (i = 0; i < dstW; i++) {
  320. int val = 1 << (26-output_bits);
  321. int j;
  322. for (j = 0; j < lumFilterSize; j++)
  323. val += alpSrc[j][i] * lumFilter[j];
  324. output_pixel(&aDest[i], val);
  325. }
  326. }
  327. #undef output_pixel
  328. }
  329. #define yuv2NBPS(bits, BE_LE, is_be) \
  330. static void yuv2yuvX ## bits ## BE_LE ## _c(SwsContext *c, const int16_t *lumFilter, \
  331. const int16_t **lumSrc, int lumFilterSize, \
  332. const int16_t *chrFilter, const int16_t **chrUSrc, \
  333. const int16_t **chrVSrc, \
  334. int chrFilterSize, const int16_t **alpSrc, \
  335. uint8_t *_dest, uint8_t *_uDest, uint8_t *_vDest, \
  336. uint8_t *_aDest, int dstW, int chrDstW) \
  337. { \
  338. uint16_t *dest = (uint16_t *) _dest, *uDest = (uint16_t *) _uDest, \
  339. *vDest = (uint16_t *) _vDest, *aDest = (uint16_t *) _aDest; \
  340. yuv2yuvX16_c_template(lumFilter, lumSrc, lumFilterSize, \
  341. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  342. alpSrc, \
  343. dest, uDest, vDest, aDest, \
  344. dstW, chrDstW, is_be, bits); \
  345. }
  346. yuv2NBPS( 9, BE, 1);
  347. yuv2NBPS( 9, LE, 0);
  348. yuv2NBPS(10, BE, 1);
  349. yuv2NBPS(10, LE, 0);
  350. yuv2NBPS(16, BE, 1);
  351. yuv2NBPS(16, LE, 0);
  352. static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
  353. const int16_t **lumSrc, int lumFilterSize,
  354. const int16_t *chrFilter, const int16_t **chrUSrc,
  355. const int16_t **chrVSrc,
  356. int chrFilterSize, const int16_t **alpSrc,
  357. uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
  358. uint8_t *aDest, int dstW, int chrDstW,
  359. const uint8_t *lumDither, const uint8_t *chrDither)
  360. {
  361. //FIXME Optimize (just quickly written not optimized..)
  362. int i;
  363. for (i=0; i<dstW; i++) {
  364. int val = lumDither[i&7] << 12;
  365. int j;
  366. for (j=0; j<lumFilterSize; j++)
  367. val += lumSrc[j][i] * lumFilter[j];
  368. dest[i]= av_clip_uint8(val>>19);
  369. }
  370. if (uDest)
  371. for (i=0; i<chrDstW; i++) {
  372. int u = chrDither[i&7] << 12;
  373. int v = chrDither[(i+3)&7] << 12;
  374. int j;
  375. for (j=0; j<chrFilterSize; j++) {
  376. u += chrUSrc[j][i] * chrFilter[j];
  377. v += chrVSrc[j][i] * chrFilter[j];
  378. }
  379. uDest[i]= av_clip_uint8(u>>19);
  380. vDest[i]= av_clip_uint8(v>>19);
  381. }
  382. if (CONFIG_SWSCALE_ALPHA && aDest)
  383. for (i=0; i<dstW; i++) {
  384. int val = lumDither[i&7] << 12;
  385. int j;
  386. for (j=0; j<lumFilterSize; j++)
  387. val += alpSrc[j][i] * lumFilter[j];
  388. aDest[i]= av_clip_uint8(val>>19);
  389. }
  390. }
  391. static void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
  392. const int16_t *chrUSrc, const int16_t *chrVSrc,
  393. const int16_t *alpSrc,
  394. uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
  395. uint8_t *aDest, int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither)
  396. {
  397. int i;
  398. for (i=0; i<dstW; i++) {
  399. int val= (lumSrc[i]+lumDither[i&7])>>7;
  400. dest[i]= av_clip_uint8(val);
  401. }
  402. if (uDest)
  403. for (i=0; i<chrDstW; i++) {
  404. int u=(chrUSrc[i]+chrDither[i&7])>>7;
  405. int v=(chrVSrc[i]+chrDither[(i+3)&7])>>7;
  406. uDest[i]= av_clip_uint8(u);
  407. vDest[i]= av_clip_uint8(v);
  408. }
  409. if (CONFIG_SWSCALE_ALPHA && aDest)
  410. for (i=0; i<dstW; i++) {
  411. int val= (alpSrc[i]+lumDither[i&7])>>7;
  412. aDest[i]= av_clip_uint8(val);
  413. }
  414. }
  415. static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
  416. const int16_t **lumSrc, int lumFilterSize,
  417. const int16_t *chrFilter, const int16_t **chrUSrc,
  418. const int16_t **chrVSrc, int chrFilterSize,
  419. const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest,
  420. uint8_t *vDest, uint8_t *aDest,
  421. int dstW, int chrDstW,
  422. const uint8_t *lumDither, const uint8_t *chrDither)
  423. {
  424. enum PixelFormat dstFormat = c->dstFormat;
  425. //FIXME Optimize (just quickly written not optimized..)
  426. int i;
  427. for (i=0; i<dstW; i++) {
  428. int val = lumDither[i&7]<<12;
  429. int j;
  430. for (j=0; j<lumFilterSize; j++)
  431. val += lumSrc[j][i] * lumFilter[j];
  432. dest[i]= av_clip_uint8(val>>19);
  433. }
  434. if (!uDest)
  435. return;
  436. if (dstFormat == PIX_FMT_NV12)
  437. for (i=0; i<chrDstW; i++) {
  438. int u = chrDither[i&7]<<12;
  439. int v = chrDither[(i+3)&7]<<12;
  440. int j;
  441. for (j=0; j<chrFilterSize; j++) {
  442. u += chrUSrc[j][i] * chrFilter[j];
  443. v += chrVSrc[j][i] * chrFilter[j];
  444. }
  445. uDest[2*i]= av_clip_uint8(u>>19);
  446. uDest[2*i+1]= av_clip_uint8(v>>19);
  447. }
  448. else
  449. for (i=0; i<chrDstW; i++) {
  450. int u = chrDither[i&7]<<12;
  451. int v = chrDither[(i+3)&7]<<12;
  452. int j;
  453. for (j=0; j<chrFilterSize; j++) {
  454. u += chrUSrc[j][i] * chrFilter[j];
  455. v += chrVSrc[j][i] * chrFilter[j];
  456. }
  457. uDest[2*i]= av_clip_uint8(v>>19);
  458. uDest[2*i+1]= av_clip_uint8(u>>19);
  459. }
  460. }
  461. #define output_pixel(pos, val) \
  462. if (target == PIX_FMT_GRAY16BE) { \
  463. AV_WB16(pos, val); \
  464. } else { \
  465. AV_WL16(pos, val); \
  466. }
  467. static av_always_inline void
  468. yuv2gray16_X_c_template(SwsContext *c, const int16_t *lumFilter,
  469. const int16_t **lumSrc, int lumFilterSize,
  470. const int16_t *chrFilter, const int16_t **chrUSrc,
  471. const int16_t **chrVSrc, int chrFilterSize,
  472. const int16_t **alpSrc, uint8_t *dest, int dstW,
  473. int y, enum PixelFormat target)
  474. {
  475. int i;
  476. for (i = 0; i < (dstW >> 1); i++) {
  477. int j;
  478. int Y1 = 1 << 18;
  479. int Y2 = 1 << 18;
  480. const int i2 = 2 * i;
  481. for (j = 0; j < lumFilterSize; j++) {
  482. Y1 += lumSrc[j][i2] * lumFilter[j];
  483. Y2 += lumSrc[j][i2+1] * lumFilter[j];
  484. }
  485. Y1 >>= 11;
  486. Y2 >>= 11;
  487. if ((Y1 | Y2) & 0x10000) {
  488. Y1 = av_clip_uint16(Y1);
  489. Y2 = av_clip_uint16(Y2);
  490. }
  491. output_pixel(&dest[2 * i2 + 0], Y1);
  492. output_pixel(&dest[2 * i2 + 2], Y2);
  493. }
  494. }
  495. static av_always_inline void
  496. yuv2gray16_2_c_template(SwsContext *c, const uint16_t *buf0,
  497. const uint16_t *buf1, const uint16_t *ubuf0,
  498. const uint16_t *ubuf1, const uint16_t *vbuf0,
  499. const uint16_t *vbuf1, const uint16_t *abuf0,
  500. const uint16_t *abuf1, uint8_t *dest, int dstW,
  501. int yalpha, int uvalpha, int y,
  502. enum PixelFormat target)
  503. {
  504. int yalpha1 = 4095 - yalpha; \
  505. int i;
  506. for (i = 0; i < (dstW >> 1); i++) {
  507. const int i2 = 2 * i;
  508. int Y1 = (buf0[i2 ] * yalpha1 + buf1[i2 ] * yalpha) >> 11;
  509. int Y2 = (buf0[i2+1] * yalpha1 + buf1[i2+1] * yalpha) >> 11;
  510. output_pixel(&dest[2 * i2 + 0], Y1);
  511. output_pixel(&dest[2 * i2 + 2], Y2);
  512. }
  513. }
  514. static av_always_inline void
  515. yuv2gray16_1_c_template(SwsContext *c, const uint16_t *buf0,
  516. const uint16_t *ubuf0, const uint16_t *ubuf1,
  517. const uint16_t *vbuf0, const uint16_t *vbuf1,
  518. const uint16_t *abuf0, uint8_t *dest, int dstW,
  519. int uvalpha, enum PixelFormat dstFormat,
  520. int flags, int y, enum PixelFormat target)
  521. {
  522. int i;
  523. for (i = 0; i < (dstW >> 1); i++) {
  524. const int i2 = 2 * i;
  525. int Y1 = buf0[i2 ] << 1;
  526. int Y2 = buf0[i2+1] << 1;
  527. output_pixel(&dest[2 * i2 + 0], Y1);
  528. output_pixel(&dest[2 * i2 + 2], Y2);
  529. }
  530. }
  531. #undef output_pixel
  532. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  533. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  534. const int16_t **lumSrc, int lumFilterSize, \
  535. const int16_t *chrFilter, const int16_t **chrUSrc, \
  536. const int16_t **chrVSrc, int chrFilterSize, \
  537. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  538. int y) \
  539. { \
  540. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  541. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  542. alpSrc, dest, dstW, y, fmt); \
  543. } \
  544. \
  545. static void name ## ext ## _2_c(SwsContext *c, const uint16_t *buf0, \
  546. const uint16_t *buf1, const uint16_t *ubuf0, \
  547. const uint16_t *ubuf1, const uint16_t *vbuf0, \
  548. const uint16_t *vbuf1, const uint16_t *abuf0, \
  549. const uint16_t *abuf1, uint8_t *dest, int dstW, \
  550. int yalpha, int uvalpha, int y) \
  551. { \
  552. name ## base ## _2_c_template(c, buf0, buf1, ubuf0, ubuf1, \
  553. vbuf0, vbuf1, abuf0, abuf1, \
  554. dest, dstW, yalpha, uvalpha, y, fmt); \
  555. } \
  556. \
  557. static void name ## ext ## _1_c(SwsContext *c, const uint16_t *buf0, \
  558. const uint16_t *ubuf0, const uint16_t *ubuf1, \
  559. const uint16_t *vbuf0, const uint16_t *vbuf1, \
  560. const uint16_t *abuf0, uint8_t *dest, int dstW, \
  561. int uvalpha, enum PixelFormat dstFormat, \
  562. int flags, int y) \
  563. { \
  564. name ## base ## _1_c_template(c, buf0, ubuf0, ubuf1, vbuf0, \
  565. vbuf1, abuf0, dest, dstW, uvalpha, \
  566. dstFormat, flags, y, fmt); \
  567. }
  568. YUV2PACKEDWRAPPER(yuv2gray16,, LE, PIX_FMT_GRAY16LE);
  569. YUV2PACKEDWRAPPER(yuv2gray16,, BE, PIX_FMT_GRAY16BE);
  570. #define output_pixel(pos, acc) \
  571. if (target == PIX_FMT_MONOBLACK) { \
  572. pos = acc; \
  573. } else { \
  574. pos = ~acc; \
  575. }
  576. static av_always_inline void
  577. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  578. const int16_t **lumSrc, int lumFilterSize,
  579. const int16_t *chrFilter, const int16_t **chrUSrc,
  580. const int16_t **chrVSrc, int chrFilterSize,
  581. const int16_t **alpSrc, uint8_t *dest, int dstW,
  582. int y, enum PixelFormat target)
  583. {
  584. const uint8_t * const d128=dither_8x8_220[y&7];
  585. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  586. int i;
  587. int acc = 0;
  588. for (i = 0; i < dstW - 1; i += 2) {
  589. int j;
  590. int Y1 = 1 << 18;
  591. int Y2 = 1 << 18;
  592. for (j = 0; j < lumFilterSize; j++) {
  593. Y1 += lumSrc[j][i] * lumFilter[j];
  594. Y2 += lumSrc[j][i+1] * lumFilter[j];
  595. }
  596. Y1 >>= 19;
  597. Y2 >>= 19;
  598. if ((Y1 | Y2) & 0x100) {
  599. Y1 = av_clip_uint8(Y1);
  600. Y2 = av_clip_uint8(Y2);
  601. }
  602. acc += acc + g[Y1 + d128[(i + 0) & 7]];
  603. acc += acc + g[Y2 + d128[(i + 1) & 7]];
  604. if ((i & 7) == 6) {
  605. output_pixel(*dest++, acc);
  606. }
  607. }
  608. }
  609. static av_always_inline void
  610. yuv2mono_2_c_template(SwsContext *c, const uint16_t *buf0,
  611. const uint16_t *buf1, const uint16_t *ubuf0,
  612. const uint16_t *ubuf1, const uint16_t *vbuf0,
  613. const uint16_t *vbuf1, const uint16_t *abuf0,
  614. const uint16_t *abuf1, uint8_t *dest, int dstW,
  615. int yalpha, int uvalpha, int y,
  616. enum PixelFormat target)
  617. {
  618. const uint8_t * const d128 = dither_8x8_220[y & 7];
  619. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  620. int yalpha1 = 4095 - yalpha;
  621. int i;
  622. for (i = 0; i < dstW - 7; i += 8) {
  623. int acc = g[((buf0[i ] * yalpha1 + buf1[i ] * yalpha) >> 19) + d128[0]];
  624. acc += acc + g[((buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19) + d128[1]];
  625. acc += acc + g[((buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19) + d128[2]];
  626. acc += acc + g[((buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19) + d128[3]];
  627. acc += acc + g[((buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19) + d128[4]];
  628. acc += acc + g[((buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19) + d128[5]];
  629. acc += acc + g[((buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19) + d128[6]];
  630. acc += acc + g[((buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19) + d128[7]];
  631. output_pixel(*dest++, acc);
  632. }
  633. }
  634. static av_always_inline void
  635. yuv2mono_1_c_template(SwsContext *c, const uint16_t *buf0,
  636. const uint16_t *ubuf0, const uint16_t *ubuf1,
  637. const uint16_t *vbuf0, const uint16_t *vbuf1,
  638. const uint16_t *abuf0, uint8_t *dest, int dstW,
  639. int uvalpha, enum PixelFormat dstFormat,
  640. int flags, int y, enum PixelFormat target)
  641. {
  642. const uint8_t * const d128 = dither_8x8_220[y & 7];
  643. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  644. int i;
  645. for (i = 0; i < dstW - 7; i += 8) {
  646. int acc = g[(buf0[i ] >> 7) + d128[0]];
  647. acc += acc + g[(buf0[i + 1] >> 7) + d128[1]];
  648. acc += acc + g[(buf0[i + 2] >> 7) + d128[2]];
  649. acc += acc + g[(buf0[i + 3] >> 7) + d128[3]];
  650. acc += acc + g[(buf0[i + 4] >> 7) + d128[4]];
  651. acc += acc + g[(buf0[i + 5] >> 7) + d128[5]];
  652. acc += acc + g[(buf0[i + 6] >> 7) + d128[6]];
  653. acc += acc + g[(buf0[i + 7] >> 7) + d128[7]];
  654. output_pixel(*dest++, acc);
  655. }
  656. }
  657. #undef output_pixel
  658. YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE);
  659. YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK);
  660. #define output_pixels(pos, Y1, U, Y2, V) \
  661. if (target == PIX_FMT_YUYV422) { \
  662. dest[pos + 0] = Y1; \
  663. dest[pos + 1] = U; \
  664. dest[pos + 2] = Y2; \
  665. dest[pos + 3] = V; \
  666. } else { \
  667. dest[pos + 0] = U; \
  668. dest[pos + 1] = Y1; \
  669. dest[pos + 2] = V; \
  670. dest[pos + 3] = Y2; \
  671. }
  672. static av_always_inline void
  673. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  674. const int16_t **lumSrc, int lumFilterSize,
  675. const int16_t *chrFilter, const int16_t **chrUSrc,
  676. const int16_t **chrVSrc, int chrFilterSize,
  677. const int16_t **alpSrc, uint8_t *dest, int dstW,
  678. int y, enum PixelFormat target)
  679. {
  680. int i;
  681. for (i = 0; i < (dstW >> 1); i++) {
  682. int j;
  683. int Y1 = 1 << 18;
  684. int Y2 = 1 << 18;
  685. int U = 1 << 18;
  686. int V = 1 << 18;
  687. for (j = 0; j < lumFilterSize; j++) {
  688. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  689. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  690. }
  691. for (j = 0; j < chrFilterSize; j++) {
  692. U += chrUSrc[j][i] * chrFilter[j];
  693. V += chrVSrc[j][i] * chrFilter[j];
  694. }
  695. Y1 >>= 19;
  696. Y2 >>= 19;
  697. U >>= 19;
  698. V >>= 19;
  699. if ((Y1 | Y2 | U | V) & 0x100) {
  700. Y1 = av_clip_uint8(Y1);
  701. Y2 = av_clip_uint8(Y2);
  702. U = av_clip_uint8(U);
  703. V = av_clip_uint8(V);
  704. }
  705. output_pixels(4*i, Y1, U, Y2, V);
  706. }
  707. }
  708. static av_always_inline void
  709. yuv2422_2_c_template(SwsContext *c, const uint16_t *buf0,
  710. const uint16_t *buf1, const uint16_t *ubuf0,
  711. const uint16_t *ubuf1, const uint16_t *vbuf0,
  712. const uint16_t *vbuf1, const uint16_t *abuf0,
  713. const uint16_t *abuf1, uint8_t *dest, int dstW,
  714. int yalpha, int uvalpha, int y,
  715. enum PixelFormat target)
  716. {
  717. int yalpha1 = 4095 - yalpha;
  718. int uvalpha1 = 4095 - uvalpha;
  719. int i;
  720. for (i = 0; i < (dstW >> 1); i++) {
  721. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  722. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  723. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  724. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  725. output_pixels(i * 4, Y1, U, Y2, V);
  726. }
  727. }
  728. static av_always_inline void
  729. yuv2422_1_c_template(SwsContext *c, const uint16_t *buf0,
  730. const uint16_t *ubuf0, const uint16_t *ubuf1,
  731. const uint16_t *vbuf0, const uint16_t *vbuf1,
  732. const uint16_t *abuf0, uint8_t *dest, int dstW,
  733. int uvalpha, enum PixelFormat dstFormat,
  734. int flags, int y, enum PixelFormat target)
  735. {
  736. int i;
  737. if (uvalpha < 2048) {
  738. for (i = 0; i < (dstW >> 1); i++) {
  739. int Y1 = buf0[i * 2] >> 7;
  740. int Y2 = buf0[i * 2 + 1] >> 7;
  741. int U = ubuf1[i] >> 7;
  742. int V = vbuf1[i] >> 7;
  743. output_pixels(i * 4, Y1, U, Y2, V);
  744. }
  745. } else {
  746. for (i = 0; i < (dstW >> 1); i++) {
  747. int Y1 = buf0[i * 2] >> 7;
  748. int Y2 = buf0[i * 2 + 1] >> 7;
  749. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  750. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  751. output_pixels(i * 4, Y1, U, Y2, V);
  752. }
  753. }
  754. }
  755. #undef output_pixels
  756. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422);
  757. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422);
  758. #define r_b ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? r : b)
  759. #define b_r ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? b : r)
  760. static av_always_inline void
  761. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  762. const int16_t **lumSrc, int lumFilterSize,
  763. const int16_t *chrFilter, const int16_t **chrUSrc,
  764. const int16_t **chrVSrc, int chrFilterSize,
  765. const int16_t **alpSrc, uint8_t *dest, int dstW,
  766. int y, enum PixelFormat target)
  767. {
  768. int i;
  769. for (i = 0; i < (dstW >> 1); i++) {
  770. int j;
  771. int Y1 = 1 << 18;
  772. int Y2 = 1 << 18;
  773. int U = 1 << 18;
  774. int V = 1 << 18;
  775. const uint8_t *r, *g, *b;
  776. for (j = 0; j < lumFilterSize; j++) {
  777. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  778. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  779. }
  780. for (j = 0; j < chrFilterSize; j++) {
  781. U += chrUSrc[j][i] * chrFilter[j];
  782. V += chrVSrc[j][i] * chrFilter[j];
  783. }
  784. Y1 >>= 19;
  785. Y2 >>= 19;
  786. U >>= 19;
  787. V >>= 19;
  788. if ((Y1 | Y2 | U | V) & 0x100) {
  789. Y1 = av_clip_uint8(Y1);
  790. Y2 = av_clip_uint8(Y2);
  791. U = av_clip_uint8(U);
  792. V = av_clip_uint8(V);
  793. }
  794. /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
  795. r = (const uint8_t *) c->table_rV[V];
  796. g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]);
  797. b = (const uint8_t *) c->table_bU[U];
  798. dest[ 0] = dest[ 1] = r_b[Y1];
  799. dest[ 2] = dest[ 3] = g[Y1];
  800. dest[ 4] = dest[ 5] = b_r[Y1];
  801. dest[ 6] = dest[ 7] = r_b[Y2];
  802. dest[ 8] = dest[ 9] = g[Y2];
  803. dest[10] = dest[11] = b_r[Y2];
  804. dest += 12;
  805. }
  806. }
  807. static av_always_inline void
  808. yuv2rgb48_2_c_template(SwsContext *c, const uint16_t *buf0,
  809. const uint16_t *buf1, const uint16_t *ubuf0,
  810. const uint16_t *ubuf1, const uint16_t *vbuf0,
  811. const uint16_t *vbuf1, const uint16_t *abuf0,
  812. const uint16_t *abuf1, uint8_t *dest, int dstW,
  813. int yalpha, int uvalpha, int y,
  814. enum PixelFormat target)
  815. {
  816. int yalpha1 = 4095 - yalpha;
  817. int uvalpha1 = 4095 - uvalpha;
  818. int i;
  819. for (i = 0; i < (dstW >> 1); i++) {
  820. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  821. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  822. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  823. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  824. const uint8_t *r = (const uint8_t *) c->table_rV[V],
  825. *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
  826. *b = (const uint8_t *) c->table_bU[U];
  827. dest[ 0] = dest[ 1] = r_b[Y1];
  828. dest[ 2] = dest[ 3] = g[Y1];
  829. dest[ 4] = dest[ 5] = b_r[Y1];
  830. dest[ 6] = dest[ 7] = r_b[Y2];
  831. dest[ 8] = dest[ 9] = g[Y2];
  832. dest[10] = dest[11] = b_r[Y2];
  833. dest += 12;
  834. }
  835. }
  836. static av_always_inline void
  837. yuv2rgb48_1_c_template(SwsContext *c, const uint16_t *buf0,
  838. const uint16_t *ubuf0, const uint16_t *ubuf1,
  839. const uint16_t *vbuf0, const uint16_t *vbuf1,
  840. const uint16_t *abuf0, uint8_t *dest, int dstW,
  841. int uvalpha, enum PixelFormat dstFormat,
  842. int flags, int y, enum PixelFormat target)
  843. {
  844. int i;
  845. if (uvalpha < 2048) {
  846. for (i = 0; i < (dstW >> 1); i++) {
  847. int Y1 = buf0[i * 2] >> 7;
  848. int Y2 = buf0[i * 2 + 1] >> 7;
  849. int U = ubuf1[i] >> 7;
  850. int V = vbuf1[i] >> 7;
  851. const uint8_t *r = (const uint8_t *) c->table_rV[V],
  852. *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
  853. *b = (const uint8_t *) c->table_bU[U];
  854. dest[ 0] = dest[ 1] = r_b[Y1];
  855. dest[ 2] = dest[ 3] = g[Y1];
  856. dest[ 4] = dest[ 5] = b_r[Y1];
  857. dest[ 6] = dest[ 7] = r_b[Y2];
  858. dest[ 8] = dest[ 9] = g[Y2];
  859. dest[10] = dest[11] = b_r[Y2];
  860. dest += 12;
  861. }
  862. } else {
  863. for (i = 0; i < (dstW >> 1); i++) {
  864. int Y1 = buf0[i * 2] >> 7;
  865. int Y2 = buf0[i * 2 + 1] >> 7;
  866. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  867. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  868. const uint8_t *r = (const uint8_t *) c->table_rV[V],
  869. *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
  870. *b = (const uint8_t *) c->table_bU[U];
  871. dest[ 0] = dest[ 1] = r_b[Y1];
  872. dest[ 2] = dest[ 3] = g[Y1];
  873. dest[ 4] = dest[ 5] = b_r[Y1];
  874. dest[ 6] = dest[ 7] = r_b[Y2];
  875. dest[ 8] = dest[ 9] = g[Y2];
  876. dest[10] = dest[11] = b_r[Y2];
  877. dest += 12;
  878. }
  879. }
  880. }
  881. #undef r_b
  882. #undef b_r
  883. YUV2PACKEDWRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE);
  884. //YUV2PACKEDWRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE);
  885. YUV2PACKEDWRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE);
  886. //YUV2PACKEDWRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE);
  887. #define YSCALE_YUV_2_RGBX_C(type,alpha) \
  888. for (i=0; i<(dstW>>1); i++) {\
  889. int j;\
  890. int Y1 = 1<<18;\
  891. int Y2 = 1<<18;\
  892. int U = 1<<18;\
  893. int V = 1<<18;\
  894. int av_unused A1, A2;\
  895. type av_unused *r, *b, *g;\
  896. const int i2= 2*i;\
  897. \
  898. for (j=0; j<lumFilterSize; j++) {\
  899. Y1 += lumSrc[j][i2] * lumFilter[j];\
  900. Y2 += lumSrc[j][i2+1] * lumFilter[j];\
  901. }\
  902. for (j=0; j<chrFilterSize; j++) {\
  903. U += chrUSrc[j][i] * chrFilter[j];\
  904. V += chrVSrc[j][i] * chrFilter[j];\
  905. }\
  906. Y1>>=19;\
  907. Y2>>=19;\
  908. U >>=19;\
  909. V >>=19;\
  910. if ((Y1|Y2|U|V)&0x100) {\
  911. Y1 = av_clip_uint8(Y1); \
  912. Y2 = av_clip_uint8(Y2); \
  913. U = av_clip_uint8(U); \
  914. V = av_clip_uint8(V); \
  915. }\
  916. if (alpha) {\
  917. A1 = 1<<18;\
  918. A2 = 1<<18;\
  919. for (j=0; j<lumFilterSize; j++) {\
  920. A1 += alpSrc[j][i2 ] * lumFilter[j];\
  921. A2 += alpSrc[j][i2+1] * lumFilter[j];\
  922. }\
  923. A1>>=19;\
  924. A2>>=19;\
  925. if ((A1|A2)&0x100) {\
  926. A1 = av_clip_uint8(A1); \
  927. A2 = av_clip_uint8(A2); \
  928. }\
  929. }\
  930. /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\
  931. r = (type *)c->table_rV[V]; \
  932. g = (type *)(c->table_gU[U] + c->table_gV[V]); \
  933. b = (type *)c->table_bU[U];
  934. #define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \
  935. for (i=0; i<dstW; i++) {\
  936. int j;\
  937. int Y = 1<<9;\
  938. int U = (1<<9)-(128<<19);\
  939. int V = (1<<9)-(128<<19);\
  940. int av_unused A;\
  941. int R,G,B;\
  942. \
  943. for (j=0; j<lumFilterSize; j++) {\
  944. Y += lumSrc[j][i ] * lumFilter[j];\
  945. }\
  946. for (j=0; j<chrFilterSize; j++) {\
  947. U += chrUSrc[j][i] * chrFilter[j];\
  948. V += chrVSrc[j][i] * chrFilter[j];\
  949. }\
  950. Y >>=10;\
  951. U >>=10;\
  952. V >>=10;\
  953. if (alpha) {\
  954. A = rnd>>3;\
  955. for (j=0; j<lumFilterSize; j++)\
  956. A += alpSrc[j][i ] * lumFilter[j];\
  957. A >>=19;\
  958. if (A&0x100)\
  959. A = av_clip_uint8(A);\
  960. }\
  961. Y-= c->yuv2rgb_y_offset;\
  962. Y*= c->yuv2rgb_y_coeff;\
  963. Y+= rnd;\
  964. R= Y + V*c->yuv2rgb_v2r_coeff;\
  965. G= Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;\
  966. B= Y + U*c->yuv2rgb_u2b_coeff;\
  967. if ((R|G|B)&(0xC0000000)) {\
  968. R = av_clip_uintp2(R, 30); \
  969. G = av_clip_uintp2(G, 30); \
  970. B = av_clip_uintp2(B, 30); \
  971. }
  972. #define YSCALE_YUV_2_RGB2_C(type,alpha) \
  973. for (i=0; i<(dstW>>1); i++) { \
  974. const int i2= 2*i; \
  975. int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \
  976. int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19; \
  977. int U= (ubuf0[i]*uvalpha1+ubuf1[i]*uvalpha)>>19; \
  978. int V= (vbuf0[i]*uvalpha1+vbuf1[i]*uvalpha)>>19; \
  979. type av_unused *r, *b, *g; \
  980. int av_unused A1, A2; \
  981. if (alpha) {\
  982. A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \
  983. A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \
  984. }\
  985. r = (type *)c->table_rV[V];\
  986. g = (type *)(c->table_gU[U] + c->table_gV[V]);\
  987. b = (type *)c->table_bU[U];
  988. #define YSCALE_YUV_2_RGB1_C(type,alpha) \
  989. for (i=0; i<(dstW>>1); i++) {\
  990. const int i2= 2*i;\
  991. int Y1= buf0[i2 ]>>7;\
  992. int Y2= buf0[i2+1]>>7;\
  993. int U= (ubuf1[i])>>7;\
  994. int V= (vbuf1[i])>>7;\
  995. type av_unused *r, *b, *g;\
  996. int av_unused A1, A2;\
  997. if (alpha) {\
  998. A1= abuf0[i2 ]>>7;\
  999. A2= abuf0[i2+1]>>7;\
  1000. }\
  1001. r = (type *)c->table_rV[V];\
  1002. g = (type *)(c->table_gU[U] + c->table_gV[V]);\
  1003. b = (type *)c->table_bU[U];
  1004. #define YSCALE_YUV_2_RGB1B_C(type,alpha) \
  1005. for (i=0; i<(dstW>>1); i++) {\
  1006. const int i2= 2*i;\
  1007. int Y1= buf0[i2 ]>>7;\
  1008. int Y2= buf0[i2+1]>>7;\
  1009. int U= (ubuf0[i] + ubuf1[i])>>8;\
  1010. int V= (vbuf0[i] + vbuf1[i])>>8;\
  1011. type av_unused *r, *b, *g;\
  1012. int av_unused A1, A2;\
  1013. if (alpha) {\
  1014. A1= abuf0[i2 ]>>7;\
  1015. A2= abuf0[i2+1]>>7;\
  1016. }\
  1017. r = (type *)c->table_rV[V];\
  1018. g = (type *)(c->table_gU[U] + c->table_gV[V]);\
  1019. b = (type *)c->table_bU[U];
  1020. #define YSCALE_YUV_2_ANYRGB_C(func)\
  1021. switch(c->dstFormat) {\
  1022. case PIX_FMT_RGBA:\
  1023. case PIX_FMT_BGRA:\
  1024. if (CONFIG_SMALL) {\
  1025. int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
  1026. func(uint32_t,needAlpha)\
  1027. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? (A1<<24) : 0);\
  1028. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? (A2<<24) : 0);\
  1029. }\
  1030. } else {\
  1031. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
  1032. func(uint32_t,1)\
  1033. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (A1<<24);\
  1034. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (A2<<24);\
  1035. }\
  1036. } else {\
  1037. func(uint32_t,0)\
  1038. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
  1039. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
  1040. }\
  1041. }\
  1042. }\
  1043. break;\
  1044. case PIX_FMT_ARGB:\
  1045. case PIX_FMT_ABGR:\
  1046. if (CONFIG_SMALL) {\
  1047. int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
  1048. func(uint32_t,needAlpha)\
  1049. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? A1 : 0);\
  1050. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? A2 : 0);\
  1051. }\
  1052. } else {\
  1053. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
  1054. func(uint32_t,1)\
  1055. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + A1;\
  1056. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + A2;\
  1057. }\
  1058. } else {\
  1059. func(uint32_t,0)\
  1060. ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
  1061. ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
  1062. }\
  1063. }\
  1064. } \
  1065. break;\
  1066. case PIX_FMT_RGB24:\
  1067. func(uint8_t,0)\
  1068. ((uint8_t*)dest)[0]= r[Y1];\
  1069. ((uint8_t*)dest)[1]= g[Y1];\
  1070. ((uint8_t*)dest)[2]= b[Y1];\
  1071. ((uint8_t*)dest)[3]= r[Y2];\
  1072. ((uint8_t*)dest)[4]= g[Y2];\
  1073. ((uint8_t*)dest)[5]= b[Y2];\
  1074. dest+=6;\
  1075. }\
  1076. break;\
  1077. case PIX_FMT_BGR24:\
  1078. func(uint8_t,0)\
  1079. ((uint8_t*)dest)[0]= b[Y1];\
  1080. ((uint8_t*)dest)[1]= g[Y1];\
  1081. ((uint8_t*)dest)[2]= r[Y1];\
  1082. ((uint8_t*)dest)[3]= b[Y2];\
  1083. ((uint8_t*)dest)[4]= g[Y2];\
  1084. ((uint8_t*)dest)[5]= r[Y2];\
  1085. dest+=6;\
  1086. }\
  1087. break;\
  1088. case PIX_FMT_RGB565:\
  1089. case PIX_FMT_BGR565:\
  1090. {\
  1091. const int dr1= dither_2x2_8[y&1 ][0];\
  1092. const int dg1= dither_2x2_4[y&1 ][0];\
  1093. const int db1= dither_2x2_8[(y&1)^1][0];\
  1094. const int dr2= dither_2x2_8[y&1 ][1];\
  1095. const int dg2= dither_2x2_4[y&1 ][1];\
  1096. const int db2= dither_2x2_8[(y&1)^1][1];\
  1097. func(uint16_t,0)\
  1098. ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
  1099. ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
  1100. }\
  1101. }\
  1102. break;\
  1103. case PIX_FMT_RGB555:\
  1104. case PIX_FMT_BGR555:\
  1105. {\
  1106. const int dr1= dither_2x2_8[y&1 ][0];\
  1107. const int dg1= dither_2x2_8[y&1 ][1];\
  1108. const int db1= dither_2x2_8[(y&1)^1][0];\
  1109. const int dr2= dither_2x2_8[y&1 ][1];\
  1110. const int dg2= dither_2x2_8[y&1 ][0];\
  1111. const int db2= dither_2x2_8[(y&1)^1][1];\
  1112. func(uint16_t,0)\
  1113. ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
  1114. ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
  1115. }\
  1116. }\
  1117. break;\
  1118. case PIX_FMT_RGB444:\
  1119. case PIX_FMT_BGR444:\
  1120. {\
  1121. const int dr1= dither_4x4_16[y&3 ][0];\
  1122. const int dg1= dither_4x4_16[y&3 ][1];\
  1123. const int db1= dither_4x4_16[(y&3)^3][0];\
  1124. const int dr2= dither_4x4_16[y&3 ][1];\
  1125. const int dg2= dither_4x4_16[y&3 ][0];\
  1126. const int db2= dither_4x4_16[(y&3)^3][1];\
  1127. func(uint16_t,0)\
  1128. ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
  1129. ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
  1130. }\
  1131. }\
  1132. break;\
  1133. case PIX_FMT_RGB8:\
  1134. case PIX_FMT_BGR8:\
  1135. {\
  1136. const uint8_t * const d64= dither_8x8_73[y&7];\
  1137. const uint8_t * const d32= dither_8x8_32[y&7];\
  1138. func(uint8_t,0)\
  1139. ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\
  1140. ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\
  1141. }\
  1142. }\
  1143. break;\
  1144. case PIX_FMT_RGB4:\
  1145. case PIX_FMT_BGR4:\
  1146. {\
  1147. const uint8_t * const d64= dither_8x8_73 [y&7];\
  1148. const uint8_t * const d128=dither_8x8_220[y&7];\
  1149. func(uint8_t,0)\
  1150. ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\
  1151. + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\
  1152. }\
  1153. }\
  1154. break;\
  1155. case PIX_FMT_RGB4_BYTE:\
  1156. case PIX_FMT_BGR4_BYTE:\
  1157. {\
  1158. const uint8_t * const d64= dither_8x8_73 [y&7];\
  1159. const uint8_t * const d128=dither_8x8_220[y&7];\
  1160. func(uint8_t,0)\
  1161. ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
  1162. ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\
  1163. }\
  1164. }\
  1165. break;\
  1166. }
  1167. static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,
  1168. const int16_t **lumSrc, int lumFilterSize,
  1169. const int16_t *chrFilter, const int16_t **chrUSrc,
  1170. const int16_t **chrVSrc, int chrFilterSize,
  1171. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  1172. {
  1173. int i;
  1174. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C)
  1175. }
  1176. static void yuv2rgbX_c_full(SwsContext *c, const int16_t *lumFilter,
  1177. const int16_t **lumSrc, int lumFilterSize,
  1178. const int16_t *chrFilter, const int16_t **chrUSrc,
  1179. const int16_t **chrVSrc, int chrFilterSize,
  1180. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  1181. {
  1182. int i;
  1183. int step= c->dstFormatBpp/8;
  1184. int aidx= 3;
  1185. switch(c->dstFormat) {
  1186. case PIX_FMT_ARGB:
  1187. dest++;
  1188. aidx= 0;
  1189. case PIX_FMT_RGB24:
  1190. aidx--;
  1191. case PIX_FMT_RGBA:
  1192. if (CONFIG_SMALL) {
  1193. int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
  1194. YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
  1195. dest[aidx]= needAlpha ? A : 255;
  1196. dest[0]= R>>22;
  1197. dest[1]= G>>22;
  1198. dest[2]= B>>22;
  1199. dest+= step;
  1200. }
  1201. } else {
  1202. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1203. YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
  1204. dest[aidx]= A;
  1205. dest[0]= R>>22;
  1206. dest[1]= G>>22;
  1207. dest[2]= B>>22;
  1208. dest+= step;
  1209. }
  1210. } else {
  1211. YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
  1212. dest[aidx]= 255;
  1213. dest[0]= R>>22;
  1214. dest[1]= G>>22;
  1215. dest[2]= B>>22;
  1216. dest+= step;
  1217. }
  1218. }
  1219. }
  1220. break;
  1221. case PIX_FMT_ABGR:
  1222. dest++;
  1223. aidx= 0;
  1224. case PIX_FMT_BGR24:
  1225. aidx--;
  1226. case PIX_FMT_BGRA:
  1227. if (CONFIG_SMALL) {
  1228. int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
  1229. YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
  1230. dest[aidx]= needAlpha ? A : 255;
  1231. dest[0]= B>>22;
  1232. dest[1]= G>>22;
  1233. dest[2]= R>>22;
  1234. dest+= step;
  1235. }
  1236. } else {
  1237. if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
  1238. YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
  1239. dest[aidx]= A;
  1240. dest[0]= B>>22;
  1241. dest[1]= G>>22;
  1242. dest[2]= R>>22;
  1243. dest+= step;
  1244. }
  1245. } else {
  1246. YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
  1247. dest[aidx]= 255;
  1248. dest[0]= B>>22;
  1249. dest[1]= G>>22;
  1250. dest[2]= R>>22;
  1251. dest+= step;
  1252. }
  1253. }
  1254. }
  1255. break;
  1256. default:
  1257. assert(0);
  1258. }
  1259. }
  1260. /**
  1261. * vertical bilinear scale YV12 to RGB
  1262. */
  1263. static void yuv2packed2_c(SwsContext *c, const uint16_t *buf0,
  1264. const uint16_t *buf1, const uint16_t *ubuf0,
  1265. const uint16_t *ubuf1, const uint16_t *vbuf0,
  1266. const uint16_t *vbuf1, const uint16_t *abuf0,
  1267. const uint16_t *abuf1, uint8_t *dest, int dstW,
  1268. int yalpha, int uvalpha, int y)
  1269. {
  1270. int yalpha1=4095- yalpha;
  1271. int uvalpha1=4095-uvalpha;
  1272. int i;
  1273. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C)
  1274. }
  1275. /**
  1276. * YV12 to RGB without scaling or interpolating
  1277. */
  1278. static void yuv2packed1_c(SwsContext *c, const uint16_t *buf0,
  1279. const uint16_t *ubuf0, const uint16_t *ubuf1,
  1280. const uint16_t *vbuf0, const uint16_t *vbuf1,
  1281. const uint16_t *abuf0, uint8_t *dest, int dstW,
  1282. int uvalpha, enum PixelFormat dstFormat,
  1283. int flags, int y)
  1284. {
  1285. int i;
  1286. if (uvalpha < 2048) {
  1287. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C)
  1288. } else {
  1289. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C)
  1290. }
  1291. }
  1292. static av_always_inline void fillPlane(uint8_t* plane, int stride,
  1293. int width, int height,
  1294. int y, uint8_t val)
  1295. {
  1296. int i;
  1297. uint8_t *ptr = plane + stride*y;
  1298. for (i=0; i<height; i++) {
  1299. memset(ptr, val, width);
  1300. ptr += stride;
  1301. }
  1302. }
  1303. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  1304. #define r ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? b_r : r_b)
  1305. #define b ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? r_b : b_r)
  1306. static av_always_inline void
  1307. rgb48ToY_c_template(int16_t *dst, const uint16_t *src, int width,
  1308. enum PixelFormat origin)
  1309. {
  1310. int i;
  1311. for (i = 0; i < width; i++) {
  1312. int r_b = input_pixel(&src[i*3+0]);
  1313. int g = input_pixel(&src[i*3+1]);
  1314. int b_r = input_pixel(&src[i*3+2]);
  1315. dst[i] = (RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);
  1316. }
  1317. }
  1318. static av_always_inline void
  1319. rgb48ToUV_c_template(int16_t *dstU, int16_t *dstV,
  1320. const uint16_t *src1, const uint16_t *src2,
  1321. int width, enum PixelFormat origin)
  1322. {
  1323. int i;
  1324. assert(src1==src2);
  1325. for (i = 0; i < width; i++) {
  1326. int r_b = input_pixel(&src1[i*3+0]);
  1327. int g = input_pixel(&src1[i*3+1]);
  1328. int b_r = input_pixel(&src1[i*3+2]);
  1329. dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);
  1330. dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1+8)) + (1<<(RGB2YUV_SHIFT-7+8))) >> (RGB2YUV_SHIFT-6+8);
  1331. }
  1332. }
  1333. static av_always_inline void
  1334. rgb48ToUV_half_c_template(int16_t *dstU, int16_t *dstV,
  1335. const uint16_t *src1, const uint16_t *src2,
  1336. int width, enum PixelFormat origin)
  1337. {
  1338. int i;
  1339. assert(src1==src2);
  1340. for (i = 0; i < width; i++) {
  1341. int r_b = (input_pixel(&src1[6*i + 0])) + (input_pixel(&src1[6*i + 3]));
  1342. int g = (input_pixel(&src1[6*i + 1])) + (input_pixel(&src1[6*i + 4]));
  1343. int b_r = (input_pixel(&src1[6*i + 2])) + (input_pixel(&src1[6*i + 5]));
  1344. dstU[i]= (RU*r + GU*g + BU*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);
  1345. dstV[i]= (RV*r + GV*g + BV*b + (256U<<(RGB2YUV_SHIFT+8)) + (1<<(RGB2YUV_SHIFT-6+8))) >> (RGB2YUV_SHIFT-5+8);
  1346. }
  1347. }
  1348. #undef r
  1349. #undef b
  1350. #undef input_pixel
  1351. #define rgb48funcs(pattern, BE_LE, origin) \
  1352. static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *dst, const uint8_t *src, \
  1353. int width, uint32_t *unused) \
  1354. { \
  1355. rgb48ToY_c_template(dst, src, width, origin); \
  1356. } \
  1357. \
  1358. static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  1359. const uint8_t *src1, const uint8_t *src2, \
  1360. int width, uint32_t *unused) \
  1361. { \
  1362. rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
  1363. } \
  1364. \
  1365. static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
  1366. const uint8_t *src1, const uint8_t *src2, \
  1367. int width, uint32_t *unused) \
  1368. { \
  1369. rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
  1370. }
  1371. rgb48funcs(rgb, LE, PIX_FMT_RGB48LE);
  1372. rgb48funcs(rgb, BE, PIX_FMT_RGB48BE);
  1373. rgb48funcs(bgr, LE, PIX_FMT_BGR48LE);
  1374. rgb48funcs(bgr, BE, PIX_FMT_BGR48BE);
  1375. #define input_pixel(i) ((origin == PIX_FMT_RGBA || origin == PIX_FMT_BGRA || \
  1376. origin == PIX_FMT_ARGB || origin == PIX_FMT_ABGR) ? AV_RN32A(&src[(i)*4]) : \
  1377. (isBE(origin) ? AV_RB16(&src[(i)*2]) : AV_RL16(&src[(i)*2])))
  1378. static av_always_inline void
  1379. rgb16_32ToY_c_template(int16_t *dst, const uint8_t *src,
  1380. int width, enum PixelFormat origin,
  1381. int shr, int shg, int shb, int shp,
  1382. int maskr, int maskg, int maskb,
  1383. int rsh, int gsh, int bsh, int S)
  1384. {
  1385. const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh,
  1386. rnd = (32<<((S)-1)) + (1<<(S-7));
  1387. int i;
  1388. for (i = 0; i < width; i++) {
  1389. int px = input_pixel(i) >> shp;
  1390. int b = (px & maskb) >> shb;
  1391. int g = (px & maskg) >> shg;
  1392. int r = (px & maskr) >> shr;
  1393. dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
  1394. }
  1395. }
  1396. static av_always_inline void
  1397. rgb16_32ToUV_c_template(int16_t *dstU, int16_t *dstV,
  1398. const uint8_t *src, int width,
  1399. enum PixelFormat origin,
  1400. int shr, int shg, int shb, int shp,
  1401. int maskr, int maskg, int maskb,
  1402. int rsh, int gsh, int bsh, int S)
  1403. {
  1404. const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
  1405. rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
  1406. rnd = (256<<((S)-1)) + (1<<(S-7));
  1407. int i;
  1408. for (i = 0; i < width; i++) {
  1409. int px = input_pixel(i) >> shp;
  1410. int b = (px & maskb) >> shb;
  1411. int g = (px & maskg) >> shg;
  1412. int r = (px & maskr) >> shr;
  1413. dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
  1414. dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
  1415. }
  1416. }
  1417. static av_always_inline void
  1418. rgb16_32ToUV_half_c_template(int16_t *dstU, int16_t *dstV,
  1419. const uint8_t *src, int width,
  1420. enum PixelFormat origin,
  1421. int shr, int shg, int shb, int shp,
  1422. int maskr, int maskg, int maskb,
  1423. int rsh, int gsh, int bsh, int S)
  1424. {
  1425. const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
  1426. rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
  1427. rnd = (256U<<(S)) + (1<<(S-6)), maskgx = ~(maskr | maskb);
  1428. int i;
  1429. maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1;
  1430. for (i = 0; i < width; i++) {
  1431. int px0 = input_pixel(2 * i + 0) >> shp;
  1432. int px1 = input_pixel(2 * i + 1) >> shp;
  1433. int b, r, g = (px0 & maskgx) + (px1 & maskgx);
  1434. int rb = px0 + px1 - g;
  1435. b = (rb & maskb) >> shb;
  1436. if (shp || origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE ||
  1437. origin == PIX_FMT_RGB565LE || origin == PIX_FMT_RGB565BE) {
  1438. g >>= shg;
  1439. } else {
  1440. g = (g & maskg) >> shg;
  1441. }
  1442. r = (rb & maskr) >> shr;
  1443. dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
  1444. dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
  1445. }
  1446. }
  1447. #undef input_pixel
  1448. #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
  1449. maskg, maskb, rsh, gsh, bsh, S) \
  1450. static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \
  1451. int width, uint32_t *unused) \
  1452. { \
  1453. rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \
  1454. maskr, maskg, maskb, rsh, gsh, bsh, S); \
  1455. } \
  1456. \
  1457. static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  1458. const uint8_t *src, const uint8_t *dummy, \
  1459. int width, uint32_t *unused) \
  1460. { \
  1461. rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
  1462. maskr, maskg, maskb, rsh, gsh, bsh, S); \
  1463. } \
  1464. \
  1465. static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
  1466. const uint8_t *src, const uint8_t *dummy, \
  1467. int width, uint32_t *unused) \
  1468. { \
  1469. rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
  1470. maskr, maskg, maskb, rsh, gsh, bsh, S); \
  1471. }
  1472. rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8);
  1473. rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8);
  1474. rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8);
  1475. rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8);
  1476. rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8);
  1477. rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7);
  1478. rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8);
  1479. rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7);
  1480. rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8);
  1481. rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7);
  1482. rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8);
  1483. rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7);
  1484. static void abgrToA_c(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  1485. {
  1486. int i;
  1487. for (i=0; i<width; i++) {
  1488. dst[i]= src[4*i]<<6;
  1489. }
  1490. }
  1491. static void rgbaToA_c(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  1492. {
  1493. int i;
  1494. for (i=0; i<width; i++) {
  1495. dst[i]= src[4*i+3]<<6;
  1496. }
  1497. }
  1498. static void palToA_c(int16_t *dst, const uint8_t *src, int width, uint32_t *pal)
  1499. {
  1500. int i;
  1501. for (i=0; i<width; i++) {
  1502. int d= src[i];
  1503. dst[i]= (pal[d] >> 24)<<6;
  1504. }
  1505. }
  1506. static void palToY_c(int16_t *dst, const uint8_t *src, long width, uint32_t *pal)
  1507. {
  1508. int i;
  1509. for (i=0; i<width; i++) {
  1510. int d= src[i];
  1511. dst[i]= (pal[d] & 0xFF)<<6;
  1512. }
  1513. }
  1514. static void palToUV_c(uint16_t *dstU, int16_t *dstV,
  1515. const uint8_t *src1, const uint8_t *src2,
  1516. int width, uint32_t *pal)
  1517. {
  1518. int i;
  1519. assert(src1 == src2);
  1520. for (i=0; i<width; i++) {
  1521. int p= pal[src1[i]];
  1522. dstU[i]= (uint8_t)(p>> 8)<<6;
  1523. dstV[i]= (uint8_t)(p>>16)<<6;
  1524. }
  1525. }
  1526. static void monowhite2Y_c(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  1527. {
  1528. int i, j;
  1529. for (i=0; i<width/8; i++) {
  1530. int d= ~src[i];
  1531. for(j=0; j<8; j++)
  1532. dst[8*i+j]= ((d>>(7-j))&1)*16383;
  1533. }
  1534. if(width&7){
  1535. int d= ~src[i];
  1536. for(j=0; j<(width&7); j++)
  1537. dst[8*i+j]= ((d>>(7-j))&1)*16383;
  1538. }
  1539. }
  1540. static void monoblack2Y_c(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
  1541. {
  1542. int i, j;
  1543. for (i=0; i<width/8; i++) {
  1544. int d= src[i];
  1545. for(j=0; j<8; j++)
  1546. dst[8*i+j]= ((d>>(7-j))&1)*16383;
  1547. }
  1548. if(width&7){
  1549. int d= src[i];
  1550. for(j=0; j<(width&7); j++)
  1551. dst[8*i+j]= ((d>>(7-j))&1)*16383;
  1552. }
  1553. }
  1554. //FIXME yuy2* can read up to 7 samples too much
  1555. static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
  1556. uint32_t *unused)
  1557. {
  1558. int i;
  1559. for (i=0; i<width; i++)
  1560. dst[i]= src[2*i];
  1561. }
  1562. static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  1563. const uint8_t *src2, int width, uint32_t *unused)
  1564. {
  1565. int i;
  1566. for (i=0; i<width; i++) {
  1567. dstU[i]= src1[4*i + 1];
  1568. dstV[i]= src1[4*i + 3];
  1569. }
  1570. assert(src1 == src2);
  1571. }
  1572. static void LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  1573. const uint8_t *src2, int width, uint32_t *unused)
  1574. {
  1575. int i;
  1576. for (i=0; i<width; i++) {
  1577. dstU[i]= src1[2*i + 1];
  1578. dstV[i]= src2[2*i + 1];
  1579. }
  1580. }
  1581. /* This is almost identical to the previous, end exists only because
  1582. * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
  1583. static void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
  1584. uint32_t *unused)
  1585. {
  1586. int i;
  1587. for (i=0; i<width; i++)
  1588. dst[i]= src[2*i+1];
  1589. }
  1590. static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  1591. const uint8_t *src2, int width, uint32_t *unused)
  1592. {
  1593. int i;
  1594. for (i=0; i<width; i++) {
  1595. dstU[i]= src1[4*i + 0];
  1596. dstV[i]= src1[4*i + 2];
  1597. }
  1598. assert(src1 == src2);
  1599. }
  1600. static void BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  1601. const uint8_t *src2, int width, uint32_t *unused)
  1602. {
  1603. int i;
  1604. for (i=0; i<width; i++) {
  1605. dstU[i]= src1[2*i];
  1606. dstV[i]= src2[2*i];
  1607. }
  1608. }
  1609. static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
  1610. const uint8_t *src, int width)
  1611. {
  1612. int i;
  1613. for (i = 0; i < width; i++) {
  1614. dst1[i] = src[2*i+0];
  1615. dst2[i] = src[2*i+1];
  1616. }
  1617. }
  1618. static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
  1619. const uint8_t *src1, const uint8_t *src2,
  1620. int width, uint32_t *unused)
  1621. {
  1622. nvXXtoUV_c(dstU, dstV, src1, width);
  1623. }
  1624. static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
  1625. const uint8_t *src1, const uint8_t *src2,
  1626. int width, uint32_t *unused)
  1627. {
  1628. nvXXtoUV_c(dstV, dstU, src1, width);
  1629. }
  1630. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  1631. // FIXME Maybe dither instead.
  1632. static av_always_inline void
  1633. yuv9_OR_10ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
  1634. const uint8_t *_srcU, const uint8_t *_srcV,
  1635. int width, enum PixelFormat origin, int depth)
  1636. {
  1637. int i;
  1638. const uint16_t *srcU = (const uint16_t *) _srcU;
  1639. const uint16_t *srcV = (const uint16_t *) _srcV;
  1640. for (i = 0; i < width; i++) {
  1641. dstU[i] = input_pixel(&srcU[i]) >> (depth - 8);
  1642. dstV[i] = input_pixel(&srcV[i]) >> (depth - 8);
  1643. }
  1644. }
  1645. static av_always_inline void
  1646. yuv9_or_10ToY_c_template(uint8_t *dstY, const uint8_t *_srcY,
  1647. int width, enum PixelFormat origin, int depth)
  1648. {
  1649. int i;
  1650. const uint16_t *srcY = (const uint16_t*)_srcY;
  1651. for (i = 0; i < width; i++)
  1652. dstY[i] = input_pixel(&srcY[i]) >> (depth - 8);
  1653. }
  1654. #undef input_pixel
  1655. #define YUV_NBPS(depth, BE_LE, origin) \
  1656. static void BE_LE ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  1657. const uint8_t *srcU, const uint8_t *srcV, \
  1658. int width, uint32_t *unused) \
  1659. { \
  1660. yuv9_OR_10ToUV_c_template(dstU, dstV, srcU, srcV, width, origin, depth); \
  1661. } \
  1662. static void BE_LE ## depth ## ToY_c(uint8_t *dstY, const uint8_t *srcY, \
  1663. int width, uint32_t *unused) \
  1664. { \
  1665. yuv9_or_10ToY_c_template(dstY, srcY, width, origin, depth); \
  1666. }
  1667. YUV_NBPS( 9, LE, PIX_FMT_YUV420P9LE);
  1668. YUV_NBPS( 9, BE, PIX_FMT_YUV420P9BE);
  1669. YUV_NBPS(10, LE, PIX_FMT_YUV420P10LE);
  1670. YUV_NBPS(10, BE, PIX_FMT_YUV420P10BE);
  1671. static void bgr24ToY_c(int16_t *dst, const uint8_t *src,
  1672. int width, uint32_t *unused)
  1673. {
  1674. int i;
  1675. for (i=0; i<width; i++) {
  1676. int b= src[i*3+0];
  1677. int g= src[i*3+1];
  1678. int r= src[i*3+2];
  1679. dst[i]= ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  1680. }
  1681. }
  1682. static void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
  1683. const uint8_t *src2, int width, uint32_t *unused)
  1684. {
  1685. int i;
  1686. for (i=0; i<width; i++) {
  1687. int b= src1[3*i + 0];
  1688. int g= src1[3*i + 1];
  1689. int r= src1[3*i + 2];
  1690. dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  1691. dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  1692. }
  1693. assert(src1 == src2);
  1694. }
  1695. static void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
  1696. const uint8_t *src2, int width, uint32_t *unused)
  1697. {
  1698. int i;
  1699. for (i=0; i<width; i++) {
  1700. int b= src1[6*i + 0] + src1[6*i + 3];
  1701. int g= src1[6*i + 1] + src1[6*i + 4];
  1702. int r= src1[6*i + 2] + src1[6*i + 5];
  1703. dstU[i]= (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  1704. dstV[i]= (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  1705. }
  1706. assert(src1 == src2);
  1707. }
  1708. static void rgb24ToY_c(int16_t *dst, const uint8_t *src, int width,
  1709. uint32_t *unused)
  1710. {
  1711. int i;
  1712. for (i=0; i<width; i++) {
  1713. int r= src[i*3+0];
  1714. int g= src[i*3+1];
  1715. int b= src[i*3+2];
  1716. dst[i]= ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  1717. }
  1718. }
  1719. static void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
  1720. const uint8_t *src2, int width, uint32_t *unused)
  1721. {
  1722. int i;
  1723. assert(src1==src2);
  1724. for (i=0; i<width; i++) {
  1725. int r= src1[3*i + 0];
  1726. int g= src1[3*i + 1];
  1727. int b= src1[3*i + 2];
  1728. dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  1729. dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  1730. }
  1731. }
  1732. static void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
  1733. const uint8_t *src2, int width, uint32_t *unused)
  1734. {
  1735. int i;
  1736. assert(src1==src2);
  1737. for (i=0; i<width; i++) {
  1738. int r= src1[6*i + 0] + src1[6*i + 3];
  1739. int g= src1[6*i + 1] + src1[6*i + 4];
  1740. int b= src1[6*i + 2] + src1[6*i + 5];
  1741. dstU[i]= (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  1742. dstV[i]= (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  1743. }
  1744. }
  1745. // bilinear / bicubic scaling
  1746. static void hScale_c(int16_t *dst, int dstW, const uint8_t *src,
  1747. int srcW, int xInc,
  1748. const int16_t *filter, const int16_t *filterPos,
  1749. int filterSize)
  1750. {
  1751. int i;
  1752. for (i=0; i<dstW; i++) {
  1753. int j;
  1754. int srcPos= filterPos[i];
  1755. int val=0;
  1756. for (j=0; j<filterSize; j++) {
  1757. val += ((int)src[srcPos + j])*filter[filterSize*i + j];
  1758. }
  1759. //filter += hFilterSize;
  1760. dst[i] = FFMIN(val>>7, (1<<15)-1); // the cubic equation does overflow ...
  1761. //dst[i] = val>>7;
  1762. }
  1763. }
  1764. static inline void hScale16_c(int16_t *dst, int dstW, const uint16_t *src, int srcW, int xInc,
  1765. const int16_t *filter, const int16_t *filterPos, long filterSize, int shift)
  1766. {
  1767. int i, j;
  1768. for (i=0; i<dstW; i++) {
  1769. int srcPos= filterPos[i];
  1770. int val=0;
  1771. for (j=0; j<filterSize; j++) {
  1772. val += ((int)src[srcPos + j])*filter[filterSize*i + j];
  1773. }
  1774. dst[i] = FFMIN(val>>shift, (1<<15)-1); // the cubic equation does overflow ...
  1775. }
  1776. }
  1777. static inline void hScale16X_c(int16_t *dst, int dstW, const uint16_t *src, int srcW, int xInc,
  1778. const int16_t *filter, const int16_t *filterPos, long filterSize, int shift)
  1779. {
  1780. int i, j;
  1781. for (i=0; i<dstW; i++) {
  1782. int srcPos= filterPos[i];
  1783. int val=0;
  1784. for (j=0; j<filterSize; j++) {
  1785. val += ((int)av_bswap16(src[srcPos + j]))*filter[filterSize*i + j];
  1786. }
  1787. dst[i] = FFMIN(val>>shift, (1<<15)-1); // the cubic equation does overflow ...
  1788. }
  1789. }
  1790. //FIXME all pal and rgb srcFormats could do this convertion as well
  1791. //FIXME all scalers more complex than bilinear could do half of this transform
  1792. static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
  1793. {
  1794. int i;
  1795. for (i = 0; i < width; i++) {
  1796. dstU[i] = (FFMIN(dstU[i],30775)*4663 - 9289992)>>12; //-264
  1797. dstV[i] = (FFMIN(dstV[i],30775)*4663 - 9289992)>>12; //-264
  1798. }
  1799. }
  1800. static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width)
  1801. {
  1802. int i;
  1803. for (i = 0; i < width; i++) {
  1804. dstU[i] = (dstU[i]*1799 + 4081085)>>11; //1469
  1805. dstV[i] = (dstV[i]*1799 + 4081085)>>11; //1469
  1806. }
  1807. }
  1808. static void lumRangeToJpeg_c(int16_t *dst, int width)
  1809. {
  1810. int i;
  1811. for (i = 0; i < width; i++)
  1812. dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14;
  1813. }
  1814. static void lumRangeFromJpeg_c(int16_t *dst, int width)
  1815. {
  1816. int i;
  1817. for (i = 0; i < width; i++)
  1818. dst[i] = (dst[i]*14071 + 33561947)>>14;
  1819. }
  1820. static void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
  1821. const uint8_t *src, int srcW, int xInc)
  1822. {
  1823. int i;
  1824. unsigned int xpos=0;
  1825. for (i=0;i<dstWidth;i++) {
  1826. register unsigned int xx=xpos>>16;
  1827. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  1828. dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
  1829. xpos+=xInc;
  1830. }
  1831. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
  1832. dst[i] = src[srcW-1]*128;
  1833. }
  1834. // *** horizontal scale Y line to temp buffer
  1835. static av_always_inline void hyscale(SwsContext *c, uint16_t *dst, int dstWidth,
  1836. const uint8_t *src, int srcW, int xInc,
  1837. const int16_t *hLumFilter,
  1838. const int16_t *hLumFilterPos, int hLumFilterSize,
  1839. uint8_t *formatConvBuffer,
  1840. uint32_t *pal, int isAlpha)
  1841. {
  1842. void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
  1843. void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
  1844. if (toYV12) {
  1845. toYV12(formatConvBuffer, src, srcW, pal);
  1846. src= formatConvBuffer;
  1847. }
  1848. if (c->hScale16) {
  1849. int shift= isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8 ? 13 : av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
  1850. c->hScale16(dst, dstWidth, (const uint16_t*)src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize, shift);
  1851. } else if (!c->hyscale_fast) {
  1852. c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
  1853. } else { // fast bilinear upscale / crap downscale
  1854. c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
  1855. }
  1856. if (convertRange)
  1857. convertRange(dst, dstWidth);
  1858. }
  1859. static void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
  1860. int dstWidth, const uint8_t *src1,
  1861. const uint8_t *src2, int srcW, int xInc)
  1862. {
  1863. int i;
  1864. unsigned int xpos=0;
  1865. for (i=0;i<dstWidth;i++) {
  1866. register unsigned int xx=xpos>>16;
  1867. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  1868. dst1[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
  1869. dst2[i]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
  1870. xpos+=xInc;
  1871. }
  1872. for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
  1873. dst1[i] = src1[srcW-1]*128;
  1874. dst2[i] = src2[srcW-1]*128;
  1875. }
  1876. }
  1877. static av_always_inline void hcscale(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
  1878. const uint8_t *src1, const uint8_t *src2,
  1879. int srcW, int xInc, const int16_t *hChrFilter,
  1880. const int16_t *hChrFilterPos, int hChrFilterSize,
  1881. uint8_t *formatConvBuffer, uint32_t *pal)
  1882. {
  1883. if (c->chrToYV12) {
  1884. uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW*2+78, 16);
  1885. c->chrToYV12(formatConvBuffer, buf2, src1, src2, srcW, pal);
  1886. src1= formatConvBuffer;
  1887. src2= buf2;
  1888. }
  1889. if (c->hScale16) {
  1890. int shift= isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8 ? 13 : av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
  1891. c->hScale16(dst1, dstWidth, (const uint16_t*)src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize, shift);
  1892. c->hScale16(dst2, dstWidth, (const uint16_t*)src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize, shift);
  1893. } else if (!c->hcscale_fast) {
  1894. c->hScale(dst1, dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  1895. c->hScale(dst2, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  1896. } else { // fast bilinear upscale / crap downscale
  1897. c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
  1898. }
  1899. if (c->chrConvertRange)
  1900. c->chrConvertRange(dst1, dst2, dstWidth);
  1901. }
  1902. static av_always_inline void
  1903. find_c_packed_planar_out_funcs(SwsContext *c,
  1904. yuv2planar1_fn *yuv2yuv1, yuv2planarX_fn *yuv2yuvX,
  1905. yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2,
  1906. yuv2packedX_fn *yuv2packedX)
  1907. {
  1908. enum PixelFormat dstFormat = c->dstFormat;
  1909. if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) {
  1910. *yuv2yuvX = yuv2nv12X_c;
  1911. } else if (is16BPS(dstFormat)) {
  1912. *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX16BE_c : yuv2yuvX16LE_c;
  1913. } else if (is9_OR_10BPS(dstFormat)) {
  1914. if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) {
  1915. *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX9BE_c : yuv2yuvX9LE_c;
  1916. } else {
  1917. *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX10BE_c : yuv2yuvX10LE_c;
  1918. }
  1919. } else {
  1920. *yuv2yuv1 = yuv2yuv1_c;
  1921. *yuv2yuvX = yuv2yuvX_c;
  1922. }
  1923. if(c->flags & SWS_FULL_CHR_H_INT) {
  1924. *yuv2packedX = yuv2rgbX_c_full;
  1925. } else {
  1926. switch (dstFormat) {
  1927. case PIX_FMT_GRAY16BE:
  1928. *yuv2packed1 = yuv2gray16BE_1_c;
  1929. *yuv2packed2 = yuv2gray16BE_2_c;
  1930. *yuv2packedX = yuv2gray16BE_X_c;
  1931. break;
  1932. case PIX_FMT_GRAY16LE:
  1933. *yuv2packed1 = yuv2gray16LE_1_c;
  1934. *yuv2packed2 = yuv2gray16LE_2_c;
  1935. *yuv2packedX = yuv2gray16LE_X_c;
  1936. break;
  1937. case PIX_FMT_MONOWHITE:
  1938. *yuv2packed1 = yuv2monowhite_1_c;
  1939. *yuv2packed2 = yuv2monowhite_2_c;
  1940. *yuv2packedX = yuv2monowhite_X_c;
  1941. break;
  1942. case PIX_FMT_MONOBLACK:
  1943. *yuv2packed1 = yuv2monoblack_1_c;
  1944. *yuv2packed2 = yuv2monoblack_2_c;
  1945. *yuv2packedX = yuv2monoblack_X_c;
  1946. break;
  1947. case PIX_FMT_YUYV422:
  1948. *yuv2packed1 = yuv2yuyv422_1_c;
  1949. *yuv2packed2 = yuv2yuyv422_2_c;
  1950. *yuv2packedX = yuv2yuyv422_X_c;
  1951. break;
  1952. case PIX_FMT_UYVY422:
  1953. *yuv2packed1 = yuv2uyvy422_1_c;
  1954. *yuv2packed2 = yuv2uyvy422_2_c;
  1955. *yuv2packedX = yuv2uyvy422_X_c;
  1956. break;
  1957. case PIX_FMT_RGB48LE:
  1958. //*yuv2packed1 = yuv2rgb48le_1_c;
  1959. //*yuv2packed2 = yuv2rgb48le_2_c;
  1960. //*yuv2packedX = yuv2rgb48le_X_c;
  1961. //break;
  1962. case PIX_FMT_RGB48BE:
  1963. *yuv2packed1 = yuv2rgb48be_1_c;
  1964. *yuv2packed2 = yuv2rgb48be_2_c;
  1965. *yuv2packedX = yuv2rgb48be_X_c;
  1966. break;
  1967. case PIX_FMT_BGR48LE:
  1968. //*yuv2packed1 = yuv2bgr48le_1_c;
  1969. //*yuv2packed2 = yuv2bgr48le_2_c;
  1970. //*yuv2packedX = yuv2bgr48le_X_c;
  1971. //break;
  1972. case PIX_FMT_BGR48BE:
  1973. *yuv2packed1 = yuv2bgr48be_1_c;
  1974. *yuv2packed2 = yuv2bgr48be_2_c;
  1975. *yuv2packedX = yuv2bgr48be_X_c;
  1976. break;
  1977. default:
  1978. *yuv2packed1 = yuv2packed1_c;
  1979. *yuv2packed2 = yuv2packed2_c;
  1980. *yuv2packedX = yuv2packedX_c;
  1981. break;
  1982. }
  1983. }
  1984. }
  1985. #define DEBUG_SWSCALE_BUFFERS 0
  1986. #define DEBUG_BUFFERS(...) if (DEBUG_SWSCALE_BUFFERS) av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
  1987. static int swScale(SwsContext *c, const uint8_t* src[],
  1988. int srcStride[], int srcSliceY,
  1989. int srcSliceH, uint8_t* dst[], int dstStride[])
  1990. {
  1991. /* load a few things into local vars to make the code more readable? and faster */
  1992. const int srcW= c->srcW;
  1993. const int dstW= c->dstW;
  1994. const int dstH= c->dstH;
  1995. const int chrDstW= c->chrDstW;
  1996. const int chrSrcW= c->chrSrcW;
  1997. const int lumXInc= c->lumXInc;
  1998. const int chrXInc= c->chrXInc;
  1999. const enum PixelFormat dstFormat= c->dstFormat;
  2000. const int flags= c->flags;
  2001. int16_t *vLumFilterPos= c->vLumFilterPos;
  2002. int16_t *vChrFilterPos= c->vChrFilterPos;
  2003. int16_t *hLumFilterPos= c->hLumFilterPos;
  2004. int16_t *hChrFilterPos= c->hChrFilterPos;
  2005. int16_t *vLumFilter= c->vLumFilter;
  2006. int16_t *vChrFilter= c->vChrFilter;
  2007. int16_t *hLumFilter= c->hLumFilter;
  2008. int16_t *hChrFilter= c->hChrFilter;
  2009. int32_t *lumMmxFilter= c->lumMmxFilter;
  2010. int32_t *chrMmxFilter= c->chrMmxFilter;
  2011. int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
  2012. const int vLumFilterSize= c->vLumFilterSize;
  2013. const int vChrFilterSize= c->vChrFilterSize;
  2014. const int hLumFilterSize= c->hLumFilterSize;
  2015. const int hChrFilterSize= c->hChrFilterSize;
  2016. int16_t **lumPixBuf= c->lumPixBuf;
  2017. int16_t **chrUPixBuf= c->chrUPixBuf;
  2018. int16_t **chrVPixBuf= c->chrVPixBuf;
  2019. int16_t **alpPixBuf= c->alpPixBuf;
  2020. const int vLumBufSize= c->vLumBufSize;
  2021. const int vChrBufSize= c->vChrBufSize;
  2022. uint8_t *formatConvBuffer= c->formatConvBuffer;
  2023. const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;
  2024. const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
  2025. int lastDstY;
  2026. uint32_t *pal=c->pal_yuv;
  2027. int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat);
  2028. yuv2planar1_fn yuv2yuv1 = c->yuv2yuv1;
  2029. yuv2planarX_fn yuv2yuvX = c->yuv2yuvX;
  2030. yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
  2031. yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
  2032. yuv2packedX_fn yuv2packedX = c->yuv2packedX;
  2033. /* vars which will change and which we need to store back in the context */
  2034. int dstY= c->dstY;
  2035. int lumBufIndex= c->lumBufIndex;
  2036. int chrBufIndex= c->chrBufIndex;
  2037. int lastInLumBuf= c->lastInLumBuf;
  2038. int lastInChrBuf= c->lastInChrBuf;
  2039. if (isPacked(c->srcFormat)) {
  2040. src[0]=
  2041. src[1]=
  2042. src[2]=
  2043. src[3]= src[0];
  2044. srcStride[0]=
  2045. srcStride[1]=
  2046. srcStride[2]=
  2047. srcStride[3]= srcStride[0];
  2048. }
  2049. srcStride[1]<<= c->vChrDrop;
  2050. srcStride[2]<<= c->vChrDrop;
  2051. DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
  2052. src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3],
  2053. dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]);
  2054. DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
  2055. srcSliceY, srcSliceH, dstY, dstH);
  2056. DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
  2057. vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
  2058. if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) {
  2059. static int warnedAlready=0; //FIXME move this into the context perhaps
  2060. if (flags & SWS_PRINT_INFO && !warnedAlready) {
  2061. av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n"
  2062. " ->cannot do aligned memory accesses anymore\n");
  2063. warnedAlready=1;
  2064. }
  2065. }
  2066. /* Note the user might start scaling the picture in the middle so this
  2067. will not get executed. This is not really intended but works
  2068. currently, so people might do it. */
  2069. if (srcSliceY ==0) {
  2070. lumBufIndex=-1;
  2071. chrBufIndex=-1;
  2072. dstY=0;
  2073. lastInLumBuf= -1;
  2074. lastInChrBuf= -1;
  2075. }
  2076. lastDstY= dstY;
  2077. for (;dstY < dstH; dstY++) {
  2078. unsigned char *dest =dst[0]+dstStride[0]*dstY;
  2079. const int chrDstY= dstY>>c->chrDstVSubSample;
  2080. unsigned char *uDest=dst[1]+dstStride[1]*chrDstY;
  2081. unsigned char *vDest=dst[2]+dstStride[2]*chrDstY;
  2082. unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL;
  2083. const uint8_t *lumDither= should_dither ? dithers[7][dstY &7] : flat64;
  2084. const uint8_t *chrDither= should_dither ? dithers[7][chrDstY&7] : flat64;
  2085. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  2086. const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)];
  2087. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  2088. int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input
  2089. int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input
  2090. int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input
  2091. int enough_lines;
  2092. //handle holes (FAST_BILINEAR & weird filters)
  2093. if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1;
  2094. if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1;
  2095. assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
  2096. assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
  2097. DEBUG_BUFFERS("dstY: %d\n", dstY);
  2098. DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
  2099. firstLumSrcY, lastLumSrcY, lastInLumBuf);
  2100. DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
  2101. firstChrSrcY, lastChrSrcY, lastInChrBuf);
  2102. // Do we have enough lines in this slice to output the dstY line
  2103. enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample);
  2104. if (!enough_lines) {
  2105. lastLumSrcY = srcSliceY + srcSliceH - 1;
  2106. lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
  2107. DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
  2108. lastLumSrcY, lastChrSrcY);
  2109. }
  2110. //Do horizontal scaling
  2111. while(lastInLumBuf < lastLumSrcY) {
  2112. const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
  2113. const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3];
  2114. lumBufIndex++;
  2115. assert(lumBufIndex < 2*vLumBufSize);
  2116. assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);
  2117. assert(lastInLumBuf + 1 - srcSliceY >= 0);
  2118. hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc,
  2119. hLumFilter, hLumFilterPos, hLumFilterSize,
  2120. formatConvBuffer,
  2121. pal, 0);
  2122. if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
  2123. hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW,
  2124. lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
  2125. formatConvBuffer,
  2126. pal, 1);
  2127. lastInLumBuf++;
  2128. DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n",
  2129. lumBufIndex, lastInLumBuf);
  2130. }
  2131. while(lastInChrBuf < lastChrSrcY) {
  2132. const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
  2133. const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2];
  2134. chrBufIndex++;
  2135. assert(chrBufIndex < 2*vChrBufSize);
  2136. assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
  2137. assert(lastInChrBuf + 1 - chrSrcSliceY >= 0);
  2138. //FIXME replace parameters through context struct (some at least)
  2139. if (c->needs_hcscale)
  2140. hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
  2141. chrDstW, src1, src2, chrSrcW, chrXInc,
  2142. hChrFilter, hChrFilterPos, hChrFilterSize,
  2143. formatConvBuffer, pal);
  2144. lastInChrBuf++;
  2145. DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n",
  2146. chrBufIndex, lastInChrBuf);
  2147. }
  2148. //wrap buf index around to stay inside the ring buffer
  2149. if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize;
  2150. if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize;
  2151. if (!enough_lines)
  2152. break; //we can't output a dstY line so let's try with the next slice
  2153. #if HAVE_MMX
  2154. updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);
  2155. #endif
  2156. if (dstY >= dstH-2) {
  2157. // hmm looks like we can't use MMX here without overwriting this array's tail
  2158. find_c_packed_planar_out_funcs(c, &yuv2yuv1, &yuv2yuvX,
  2159. &yuv2packed1, &yuv2packed2,
  2160. &yuv2packedX);
  2161. }
  2162. {
  2163. const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  2164. const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  2165. const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  2166. const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
  2167. if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like
  2168. const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
  2169. if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
  2170. if (c->yuv2yuv1 && vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12
  2171. const int16_t *lumBuf = lumSrcPtr[0];
  2172. const int16_t *chrUBuf= chrUSrcPtr[0];
  2173. const int16_t *chrVBuf= chrVSrcPtr[0];
  2174. const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL;
  2175. yuv2yuv1(c, lumBuf, chrUBuf, chrVBuf, alpBuf, dest,
  2176. uDest, vDest, aDest, dstW, chrDstW, lumDither, chrDither);
  2177. } else { //General YV12
  2178. yuv2yuvX(c,
  2179. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  2180. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr,
  2181. chrVSrcPtr, vChrFilterSize,
  2182. alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW, lumDither, chrDither);
  2183. }
  2184. } else {
  2185. assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
  2186. assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);
  2187. if (c->yuv2packed1 && vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB
  2188. int chrAlpha= vChrFilter[2*dstY+1];
  2189. yuv2packed1(c, *lumSrcPtr, *chrUSrcPtr, *(chrUSrcPtr+1),
  2190. *chrVSrcPtr, *(chrVSrcPtr+1),
  2191. alpPixBuf ? *alpSrcPtr : NULL,
  2192. dest, dstW, chrAlpha, dstFormat, flags, dstY);
  2193. } else if (c->yuv2packed2 && vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB
  2194. int lumAlpha= vLumFilter[2*dstY+1];
  2195. int chrAlpha= vChrFilter[2*dstY+1];
  2196. lumMmxFilter[2]=
  2197. lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001;
  2198. chrMmxFilter[2]=
  2199. chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001;
  2200. yuv2packed2(c, *lumSrcPtr, *(lumSrcPtr+1), *chrUSrcPtr, *(chrUSrcPtr+1),
  2201. *chrVSrcPtr, *(chrVSrcPtr+1),
  2202. alpPixBuf ? *alpSrcPtr : NULL, alpPixBuf ? *(alpSrcPtr+1) : NULL,
  2203. dest, dstW, lumAlpha, chrAlpha, dstY);
  2204. } else { //general RGB
  2205. yuv2packedX(c,
  2206. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  2207. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  2208. alpSrcPtr, dest, dstW, dstY);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf)
  2214. fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255);
  2215. #if HAVE_MMX2
  2216. if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)
  2217. __asm__ volatile("sfence":::"memory");
  2218. #endif
  2219. emms_c();
  2220. /* store changed local vars back in the context */
  2221. c->dstY= dstY;
  2222. c->lumBufIndex= lumBufIndex;
  2223. c->chrBufIndex= chrBufIndex;
  2224. c->lastInLumBuf= lastInLumBuf;
  2225. c->lastInChrBuf= lastInChrBuf;
  2226. return dstY - lastDstY;
  2227. }
  2228. static av_cold void sws_init_swScale_c(SwsContext *c)
  2229. {
  2230. enum PixelFormat srcFormat = c->srcFormat;
  2231. find_c_packed_planar_out_funcs(c, &c->yuv2yuv1, &c->yuv2yuvX,
  2232. &c->yuv2packed1, &c->yuv2packed2,
  2233. &c->yuv2packedX);
  2234. c->hScale = hScale_c;
  2235. if (c->flags & SWS_FAST_BILINEAR) {
  2236. c->hyscale_fast = hyscale_fast_c;
  2237. c->hcscale_fast = hcscale_fast_c;
  2238. }
  2239. c->chrToYV12 = NULL;
  2240. switch(srcFormat) {
  2241. case PIX_FMT_YUYV422 : c->chrToYV12 = yuy2ToUV_c; break;
  2242. case PIX_FMT_UYVY422 : c->chrToYV12 = uyvyToUV_c; break;
  2243. case PIX_FMT_NV12 : c->chrToYV12 = nv12ToUV_c; break;
  2244. case PIX_FMT_NV21 : c->chrToYV12 = nv21ToUV_c; break;
  2245. case PIX_FMT_RGB8 :
  2246. case PIX_FMT_BGR8 :
  2247. case PIX_FMT_PAL8 :
  2248. case PIX_FMT_BGR4_BYTE:
  2249. case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break;
  2250. case PIX_FMT_GRAY16BE :
  2251. case PIX_FMT_YUV444P9BE:
  2252. case PIX_FMT_YUV420P9BE:
  2253. case PIX_FMT_YUV444P10BE:
  2254. case PIX_FMT_YUV422P10BE:
  2255. case PIX_FMT_YUV420P10BE:
  2256. case PIX_FMT_YUV420P16BE:
  2257. case PIX_FMT_YUV422P16BE:
  2258. case PIX_FMT_YUV444P16BE: c->hScale16= HAVE_BIGENDIAN ? hScale16_c : hScale16X_c; break;
  2259. case PIX_FMT_GRAY16LE :
  2260. case PIX_FMT_YUV444P9LE:
  2261. case PIX_FMT_YUV420P9LE:
  2262. case PIX_FMT_YUV422P10LE:
  2263. case PIX_FMT_YUV420P10LE:
  2264. case PIX_FMT_YUV444P10LE:
  2265. case PIX_FMT_YUV420P16LE:
  2266. case PIX_FMT_YUV422P16LE:
  2267. case PIX_FMT_YUV444P16LE: c->hScale16= HAVE_BIGENDIAN ? hScale16X_c : hScale16_c; break;
  2268. }
  2269. if (c->chrSrcHSubSample) {
  2270. switch(srcFormat) {
  2271. case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_half_c; break;
  2272. case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_half_c; break;
  2273. case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_half_c; break;
  2274. case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_half_c; break;
  2275. case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half_c; break;
  2276. case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_half_c; break;
  2277. case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_half_c; break;
  2278. case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_half_c; break;
  2279. case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_half_c; break;
  2280. case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_half_c; break;
  2281. case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_half_c; break;
  2282. case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half_c; break;
  2283. case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_half_c; break;
  2284. case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_half_c; break;
  2285. case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_half_c; break;
  2286. case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_half_c; break;
  2287. case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_half_c; break;
  2288. case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_half_c; break;
  2289. }
  2290. } else {
  2291. switch(srcFormat) {
  2292. case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_c; break;
  2293. case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_c; break;
  2294. case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_c; break;
  2295. case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_c; break;
  2296. case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_c; break;
  2297. case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_c; break;
  2298. case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_c; break;
  2299. case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_c; break;
  2300. case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_c; break;
  2301. case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_c; break;
  2302. case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_c; break;
  2303. case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_c; break;
  2304. case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_c; break;
  2305. case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_c; break;
  2306. case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_c; break;
  2307. case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_c; break;
  2308. case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_c; break;
  2309. case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_c; break;
  2310. }
  2311. }
  2312. c->lumToYV12 = NULL;
  2313. c->alpToYV12 = NULL;
  2314. switch (srcFormat) {
  2315. case PIX_FMT_YUYV422 :
  2316. case PIX_FMT_GRAY8A :
  2317. c->lumToYV12 = yuy2ToY_c; break;
  2318. case PIX_FMT_UYVY422 :
  2319. c->lumToYV12 = uyvyToY_c; break;
  2320. case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break;
  2321. case PIX_FMT_BGR565LE : c->lumToYV12 = bgr16leToY_c; break;
  2322. case PIX_FMT_BGR565BE : c->lumToYV12 = bgr16beToY_c; break;
  2323. case PIX_FMT_BGR555LE : c->lumToYV12 = bgr15leToY_c; break;
  2324. case PIX_FMT_BGR555BE : c->lumToYV12 = bgr15beToY_c; break;
  2325. case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break;
  2326. case PIX_FMT_RGB565LE : c->lumToYV12 = rgb16leToY_c; break;
  2327. case PIX_FMT_RGB565BE : c->lumToYV12 = rgb16beToY_c; break;
  2328. case PIX_FMT_RGB555LE : c->lumToYV12 = rgb15leToY_c; break;
  2329. case PIX_FMT_RGB555BE : c->lumToYV12 = rgb15beToY_c; break;
  2330. case PIX_FMT_RGB8 :
  2331. case PIX_FMT_BGR8 :
  2332. case PIX_FMT_PAL8 :
  2333. case PIX_FMT_BGR4_BYTE:
  2334. case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY_c; break;
  2335. case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y_c; break;
  2336. case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y_c; break;
  2337. case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY_c; break;
  2338. case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY_c; break;
  2339. case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY_c; break;
  2340. case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY_c; break;
  2341. case PIX_FMT_RGB48BE: c->lumToYV12 = rgb48BEToY_c; break;
  2342. case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48LEToY_c; break;
  2343. case PIX_FMT_BGR48BE: c->lumToYV12 = bgr48BEToY_c; break;
  2344. case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48LEToY_c; break;
  2345. }
  2346. if (c->alpPixBuf) {
  2347. switch (srcFormat) {
  2348. case PIX_FMT_BGRA:
  2349. case PIX_FMT_RGBA: c->alpToYV12 = rgbaToA_c; break;
  2350. case PIX_FMT_ABGR:
  2351. case PIX_FMT_ARGB: c->alpToYV12 = abgrToA_c; break;
  2352. case PIX_FMT_Y400A: c->alpToYV12 = uyvyToY_c; break;
  2353. case PIX_FMT_PAL8 : c->alpToYV12 = palToA_c; break;
  2354. }
  2355. }
  2356. if(isAnyRGB(c->srcFormat) || c->srcFormat == PIX_FMT_PAL8)
  2357. c->hScale16= hScale16_c;
  2358. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
  2359. if (c->srcRange) {
  2360. c->lumConvertRange = lumRangeFromJpeg_c;
  2361. c->chrConvertRange = chrRangeFromJpeg_c;
  2362. } else {
  2363. c->lumConvertRange = lumRangeToJpeg_c;
  2364. c->chrConvertRange = chrRangeToJpeg_c;
  2365. }
  2366. }
  2367. if (!(isGray(srcFormat) || isGray(c->dstFormat) ||
  2368. srcFormat == PIX_FMT_MONOBLACK || srcFormat == PIX_FMT_MONOWHITE))
  2369. c->needs_hcscale = 1;
  2370. }
  2371. SwsFunc ff_getSwsFunc(SwsContext *c)
  2372. {
  2373. sws_init_swScale_c(c);
  2374. if (HAVE_MMX)
  2375. ff_sws_init_swScale_mmx(c);
  2376. if (HAVE_ALTIVEC)
  2377. ff_sws_init_swScale_altivec(c);
  2378. return swScale;
  2379. }