input.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. /*
  2. * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <math.h>
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include "libavutil/bswap.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/avassert.h"
  26. #include "config.h"
  27. #include "swscale_internal.h"
  28. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  29. #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? b_r : r_b)
  30. #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? r_b : b_r)
  31. static av_always_inline void
  32. rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
  33. enum AVPixelFormat origin, int32_t *rgb2yuv)
  34. {
  35. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  36. int i;
  37. for (i = 0; i < width; i++) {
  38. unsigned int r_b = input_pixel(&src[i*4+0]);
  39. unsigned int g = input_pixel(&src[i*4+1]);
  40. unsigned int b_r = input_pixel(&src[i*4+2]);
  41. dst[i] = (ry*r + gy*g + by*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  42. }
  43. }
  44. static av_always_inline void
  45. rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
  46. const uint16_t *src1, const uint16_t *src2,
  47. int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
  48. {
  49. int i;
  50. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  51. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  52. av_assert1(src1==src2);
  53. for (i = 0; i < width; i++) {
  54. int r_b = input_pixel(&src1[i*4+0]);
  55. int g = input_pixel(&src1[i*4+1]);
  56. int b_r = input_pixel(&src1[i*4+2]);
  57. dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  58. dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  59. }
  60. }
  61. static av_always_inline void
  62. rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
  63. const uint16_t *src1, const uint16_t *src2,
  64. int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
  65. {
  66. int i;
  67. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  68. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  69. av_assert1(src1==src2);
  70. for (i = 0; i < width; i++) {
  71. unsigned r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
  72. unsigned g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
  73. unsigned b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
  74. dstU[i]= (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  75. dstV[i]= (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  76. }
  77. }
  78. #define rgb64funcs(pattern, BE_LE, origin) \
  79. static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
  80. int width, uint32_t *rgb2yuv) \
  81. { \
  82. const uint16_t *src = (const uint16_t *) _src; \
  83. uint16_t *dst = (uint16_t *) _dst; \
  84. rgb64ToY_c_template(dst, src, width, origin, rgb2yuv); \
  85. } \
  86. \
  87. static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
  88. const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
  89. int width, uint32_t *rgb2yuv) \
  90. { \
  91. const uint16_t *src1 = (const uint16_t *) _src1, \
  92. *src2 = (const uint16_t *) _src2; \
  93. uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
  94. rgb64ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
  95. } \
  96. \
  97. static void pattern ## 64 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
  98. const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
  99. int width, uint32_t *rgb2yuv) \
  100. { \
  101. const uint16_t *src1 = (const uint16_t *) _src1, \
  102. *src2 = (const uint16_t *) _src2; \
  103. uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
  104. rgb64ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
  105. }
  106. rgb64funcs(rgb, LE, AV_PIX_FMT_RGBA64LE)
  107. rgb64funcs(rgb, BE, AV_PIX_FMT_RGBA64BE)
  108. rgb64funcs(bgr, LE, AV_PIX_FMT_BGRA64LE)
  109. rgb64funcs(bgr, BE, AV_PIX_FMT_BGRA64BE)
  110. static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
  111. const uint16_t *src, int width,
  112. enum AVPixelFormat origin,
  113. int32_t *rgb2yuv)
  114. {
  115. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  116. int i;
  117. for (i = 0; i < width; i++) {
  118. unsigned int r_b = input_pixel(&src[i * 3 + 0]);
  119. unsigned int g = input_pixel(&src[i * 3 + 1]);
  120. unsigned int b_r = input_pixel(&src[i * 3 + 2]);
  121. dst[i] = (ry*r + gy*g + by*b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  122. }
  123. }
  124. static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
  125. uint16_t *dstV,
  126. const uint16_t *src1,
  127. const uint16_t *src2,
  128. int width,
  129. enum AVPixelFormat origin,
  130. int32_t *rgb2yuv)
  131. {
  132. int i;
  133. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  134. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  135. av_assert1(src1 == src2);
  136. for (i = 0; i < width; i++) {
  137. unsigned r_b = input_pixel(&src1[i * 3 + 0]);
  138. unsigned g = input_pixel(&src1[i * 3 + 1]);
  139. unsigned b_r = input_pixel(&src1[i * 3 + 2]);
  140. dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  141. dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  142. }
  143. }
  144. static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
  145. uint16_t *dstV,
  146. const uint16_t *src1,
  147. const uint16_t *src2,
  148. int width,
  149. enum AVPixelFormat origin,
  150. int32_t *rgb2yuv)
  151. {
  152. int i;
  153. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  154. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  155. av_assert1(src1 == src2);
  156. for (i = 0; i < width; i++) {
  157. unsigned r_b = (input_pixel(&src1[6 * i + 0]) +
  158. input_pixel(&src1[6 * i + 3]) + 1) >> 1;
  159. unsigned g = (input_pixel(&src1[6 * i + 1]) +
  160. input_pixel(&src1[6 * i + 4]) + 1) >> 1;
  161. unsigned b_r = (input_pixel(&src1[6 * i + 2]) +
  162. input_pixel(&src1[6 * i + 5]) + 1) >> 1;
  163. dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  164. dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  165. }
  166. }
  167. #undef r
  168. #undef b
  169. #undef input_pixel
  170. #define rgb48funcs(pattern, BE_LE, origin) \
  171. static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
  172. const uint8_t *_src, \
  173. const uint8_t *unused0, const uint8_t *unused1,\
  174. int width, \
  175. uint32_t *rgb2yuv) \
  176. { \
  177. const uint16_t *src = (const uint16_t *)_src; \
  178. uint16_t *dst = (uint16_t *)_dst; \
  179. rgb48ToY_c_template(dst, src, width, origin, rgb2yuv); \
  180. } \
  181. \
  182. static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
  183. uint8_t *_dstV, \
  184. const uint8_t *unused0, \
  185. const uint8_t *_src1, \
  186. const uint8_t *_src2, \
  187. int width, \
  188. uint32_t *rgb2yuv) \
  189. { \
  190. const uint16_t *src1 = (const uint16_t *)_src1, \
  191. *src2 = (const uint16_t *)_src2; \
  192. uint16_t *dstU = (uint16_t *)_dstU, \
  193. *dstV = (uint16_t *)_dstV; \
  194. rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
  195. } \
  196. \
  197. static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
  198. uint8_t *_dstV, \
  199. const uint8_t *unused0, \
  200. const uint8_t *_src1, \
  201. const uint8_t *_src2, \
  202. int width, \
  203. uint32_t *rgb2yuv) \
  204. { \
  205. const uint16_t *src1 = (const uint16_t *)_src1, \
  206. *src2 = (const uint16_t *)_src2; \
  207. uint16_t *dstU = (uint16_t *)_dstU, \
  208. *dstV = (uint16_t *)_dstV; \
  209. rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin, rgb2yuv); \
  210. }
  211. rgb48funcs(rgb, LE, AV_PIX_FMT_RGB48LE)
  212. rgb48funcs(rgb, BE, AV_PIX_FMT_RGB48BE)
  213. rgb48funcs(bgr, LE, AV_PIX_FMT_BGR48LE)
  214. rgb48funcs(bgr, BE, AV_PIX_FMT_BGR48BE)
  215. #define input_pixel(i) ((origin == AV_PIX_FMT_RGBA || \
  216. origin == AV_PIX_FMT_BGRA || \
  217. origin == AV_PIX_FMT_ARGB || \
  218. origin == AV_PIX_FMT_ABGR) \
  219. ? AV_RN32A(&src[(i) * 4]) \
  220. : ((origin == AV_PIX_FMT_X2RGB10LE || \
  221. origin == AV_PIX_FMT_X2BGR10LE) \
  222. ? AV_RL32(&src[(i) * 4]) \
  223. : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \
  224. : AV_RL16(&src[(i) * 2]))))
  225. static av_always_inline void rgb16_32ToY_c_template(int16_t *dst,
  226. const uint8_t *src,
  227. int width,
  228. enum AVPixelFormat origin,
  229. int shr, int shg,
  230. int shb, int shp,
  231. int maskr, int maskg,
  232. int maskb, int rsh,
  233. int gsh, int bsh, int S,
  234. int32_t *rgb2yuv)
  235. {
  236. const int ry = rgb2yuv[RY_IDX]<<rsh, gy = rgb2yuv[GY_IDX]<<gsh, by = rgb2yuv[BY_IDX]<<bsh;
  237. const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
  238. int i;
  239. for (i = 0; i < width; i++) {
  240. int px = input_pixel(i) >> shp;
  241. int b = (px & maskb) >> shb;
  242. int g = (px & maskg) >> shg;
  243. int r = (px & maskr) >> shr;
  244. dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
  245. }
  246. }
  247. static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
  248. int16_t *dstV,
  249. const uint8_t *src,
  250. int width,
  251. enum AVPixelFormat origin,
  252. int shr, int shg,
  253. int shb, int shp,
  254. int maskr, int maskg,
  255. int maskb, int rsh,
  256. int gsh, int bsh, int S,
  257. int32_t *rgb2yuv)
  258. {
  259. const int ru = rgb2yuv[RU_IDX] * (1 << rsh), gu = rgb2yuv[GU_IDX] * (1 << gsh), bu = rgb2yuv[BU_IDX] * (1 << bsh),
  260. rv = rgb2yuv[RV_IDX] * (1 << rsh), gv = rgb2yuv[GV_IDX] * (1 << gsh), bv = rgb2yuv[BV_IDX] * (1 << bsh);
  261. const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7));
  262. int i;
  263. for (i = 0; i < width; i++) {
  264. int px = input_pixel(i) >> shp;
  265. int b = (px & maskb) >> shb;
  266. int g = (px & maskg) >> shg;
  267. int r = (px & maskr) >> shr;
  268. dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
  269. dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
  270. }
  271. }
  272. static av_always_inline void rgb16_32ToUV_half_c_template(int16_t *dstU,
  273. int16_t *dstV,
  274. const uint8_t *src,
  275. int width,
  276. enum AVPixelFormat origin,
  277. int shr, int shg,
  278. int shb, int shp,
  279. int maskr, int maskg,
  280. int maskb, int rsh,
  281. int gsh, int bsh, int S,
  282. int32_t *rgb2yuv)
  283. {
  284. const int ru = rgb2yuv[RU_IDX] * (1 << rsh), gu = rgb2yuv[GU_IDX] * (1 << gsh), bu = rgb2yuv[BU_IDX] * (1 << bsh),
  285. rv = rgb2yuv[RV_IDX] * (1 << rsh), gv = rgb2yuv[GV_IDX] * (1 << gsh), bv = rgb2yuv[BV_IDX] * (1 << bsh),
  286. maskgx = ~(maskr | maskb);
  287. const unsigned rnd = (256U<<(S)) + (1<<(S-6));
  288. int i;
  289. maskr |= maskr << 1;
  290. maskb |= maskb << 1;
  291. maskg |= maskg << 1;
  292. for (i = 0; i < width; i++) {
  293. unsigned px0 = input_pixel(2 * i + 0) >> shp;
  294. unsigned px1 = input_pixel(2 * i + 1) >> shp;
  295. int b, r, g = (px0 & maskgx) + (px1 & maskgx);
  296. int rb = px0 + px1 - g;
  297. b = (rb & maskb) >> shb;
  298. if (shp ||
  299. origin == AV_PIX_FMT_BGR565LE || origin == AV_PIX_FMT_BGR565BE ||
  300. origin == AV_PIX_FMT_RGB565LE || origin == AV_PIX_FMT_RGB565BE) {
  301. g >>= shg;
  302. } else {
  303. g = (g & maskg) >> shg;
  304. }
  305. r = (rb & maskr) >> shr;
  306. dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
  307. dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
  308. }
  309. }
  310. #undef input_pixel
  311. #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
  312. maskg, maskb, rsh, gsh, bsh, S) \
  313. static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
  314. int width, uint32_t *tab) \
  315. { \
  316. rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
  317. maskr, maskg, maskb, rsh, gsh, bsh, S, tab); \
  318. } \
  319. \
  320. static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  321. const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
  322. int width, uint32_t *tab) \
  323. { \
  324. rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
  325. shr, shg, shb, shp, \
  326. maskr, maskg, maskb, rsh, gsh, bsh, S, tab);\
  327. } \
  328. \
  329. static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
  330. const uint8_t *unused0, const uint8_t *src, \
  331. const uint8_t *dummy, \
  332. int width, uint32_t *tab) \
  333. { \
  334. rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
  335. shr, shg, shb, shp, \
  336. maskr, maskg, maskb, \
  337. rsh, gsh, bsh, S, tab); \
  338. }
  339. rgb16_32_wrapper(AV_PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
  340. rgb16_32_wrapper(AV_PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
  341. rgb16_32_wrapper(AV_PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
  342. rgb16_32_wrapper(AV_PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
  343. rgb16_32_wrapper(AV_PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
  344. rgb16_32_wrapper(AV_PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
  345. rgb16_32_wrapper(AV_PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
  346. rgb16_32_wrapper(AV_PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
  347. rgb16_32_wrapper(AV_PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
  348. rgb16_32_wrapper(AV_PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
  349. rgb16_32_wrapper(AV_PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
  350. rgb16_32_wrapper(AV_PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
  351. rgb16_32_wrapper(AV_PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
  352. rgb16_32_wrapper(AV_PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
  353. rgb16_32_wrapper(AV_PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
  354. rgb16_32_wrapper(AV_PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
  355. rgb16_32_wrapper(AV_PIX_FMT_X2RGB10LE, rgb30le, 16, 6, 0, 0, 0x3FF00000, 0xFFC00, 0x3FF, 0, 0, 4, RGB2YUV_SHIFT + 6)
  356. rgb16_32_wrapper(AV_PIX_FMT_X2BGR10LE, bgr30le, 0, 6, 16, 0, 0x3FF, 0xFFC00, 0x3FF00000, 4, 0, 0, RGB2YUV_SHIFT + 6)
  357. static void gbr24pToUV_half_c(uint8_t *_dstU, uint8_t *_dstV,
  358. const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
  359. int width, uint32_t *rgb2yuv)
  360. {
  361. uint16_t *dstU = (uint16_t *)_dstU;
  362. uint16_t *dstV = (uint16_t *)_dstV;
  363. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  364. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  365. int i;
  366. for (i = 0; i < width; i++) {
  367. unsigned int g = gsrc[2*i] + gsrc[2*i+1];
  368. unsigned int b = bsrc[2*i] + bsrc[2*i+1];
  369. unsigned int r = rsrc[2*i] + rsrc[2*i+1];
  370. dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
  371. dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
  372. }
  373. }
  374. static void rgba64leToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
  375. const uint8_t *unused2, int width, uint32_t *unused)
  376. {
  377. int16_t *dst = (int16_t *)_dst;
  378. const uint16_t *src = (const uint16_t *)_src;
  379. int i;
  380. for (i = 0; i < width; i++)
  381. dst[i] = AV_RL16(src + 4 * i + 3);
  382. }
  383. static void rgba64beToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
  384. const uint8_t *unused2, int width, uint32_t *unused)
  385. {
  386. int16_t *dst = (int16_t *)_dst;
  387. const uint16_t *src = (const uint16_t *)_src;
  388. int i;
  389. for (i = 0; i < width; i++)
  390. dst[i] = AV_RB16(src + 4 * i + 3);
  391. }
  392. static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  393. {
  394. int16_t *dst = (int16_t *)_dst;
  395. int i;
  396. for (i=0; i<width; i++) {
  397. dst[i]= src[4*i]<<6 | src[4*i]>>2;
  398. }
  399. }
  400. static void rgbaToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  401. {
  402. int16_t *dst = (int16_t *)_dst;
  403. int i;
  404. for (i=0; i<width; i++) {
  405. dst[i]= src[4*i+3]<<6 | src[4*i+3]>>2;
  406. }
  407. }
  408. static void palToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
  409. {
  410. int16_t *dst = (int16_t *)_dst;
  411. int i;
  412. for (i=0; i<width; i++) {
  413. int d= src[i];
  414. dst[i]= (pal[d] >> 24)<<6 | pal[d]>>26;
  415. }
  416. }
  417. static void palToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
  418. {
  419. int16_t *dst = (int16_t *)_dst;
  420. int i;
  421. for (i = 0; i < width; i++) {
  422. int d = src[i];
  423. dst[i] = (pal[d] & 0xFF)<<6;
  424. }
  425. }
  426. static void palToUV_c(uint8_t *_dstU, uint8_t *_dstV,
  427. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  428. int width, uint32_t *pal)
  429. {
  430. uint16_t *dstU = (uint16_t *)_dstU;
  431. int16_t *dstV = (int16_t *)_dstV;
  432. int i;
  433. av_assert1(src1 == src2);
  434. for (i = 0; i < width; i++) {
  435. int p = pal[src1[i]];
  436. dstU[i] = (uint8_t)(p>> 8)<<6;
  437. dstV[i] = (uint8_t)(p>>16)<<6;
  438. }
  439. }
  440. static void monowhite2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  441. {
  442. int16_t *dst = (int16_t *)_dst;
  443. int i, j;
  444. width = (width + 7) >> 3;
  445. for (i = 0; i < width; i++) {
  446. int d = ~src[i];
  447. for (j = 0; j < 8; j++)
  448. dst[8*i+j]= ((d>>(7-j))&1) * 16383;
  449. }
  450. if(width&7){
  451. int d= ~src[i];
  452. for (j = 0; j < (width&7); j++)
  453. dst[8*i+j]= ((d>>(7-j))&1) * 16383;
  454. }
  455. }
  456. static void monoblack2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  457. {
  458. int16_t *dst = (int16_t *)_dst;
  459. int i, j;
  460. width = (width + 7) >> 3;
  461. for (i = 0; i < width; i++) {
  462. int d = src[i];
  463. for (j = 0; j < 8; j++)
  464. dst[8*i+j]= ((d>>(7-j))&1) * 16383;
  465. }
  466. if(width&7){
  467. int d = src[i];
  468. for (j = 0; j < (width&7); j++)
  469. dst[8*i+j] = ((d>>(7-j))&1) * 16383;
  470. }
  471. }
  472. static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  473. uint32_t *unused)
  474. {
  475. int i;
  476. for (i = 0; i < width; i++)
  477. dst[i] = src[2 * i];
  478. }
  479. static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
  480. const uint8_t *src2, int width, uint32_t *unused)
  481. {
  482. int i;
  483. for (i = 0; i < width; i++) {
  484. dstU[i] = src1[4 * i + 1];
  485. dstV[i] = src1[4 * i + 3];
  486. }
  487. av_assert1(src1 == src2);
  488. }
  489. static void yvy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
  490. const uint8_t *src2, int width, uint32_t *unused)
  491. {
  492. int i;
  493. for (i = 0; i < width; i++) {
  494. dstV[i] = src1[4 * i + 1];
  495. dstU[i] = src1[4 * i + 3];
  496. }
  497. av_assert1(src1 == src2);
  498. }
  499. static void y210le_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src,
  500. const uint8_t *unused1, int width, uint32_t *unused2)
  501. {
  502. int i;
  503. for (i = 0; i < width; i++) {
  504. AV_WN16(dstU + i * 2, AV_RL16(src + i * 8 + 2) >> 6);
  505. AV_WN16(dstV + i * 2, AV_RL16(src + i * 8 + 6) >> 6);
  506. }
  507. }
  508. static void y210le_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0,
  509. const uint8_t *unused1, int width, uint32_t *unused2)
  510. {
  511. int i;
  512. for (i = 0; i < width; i++)
  513. AV_WN16(dst + i * 2, AV_RL16(src + i * 4) >> 6);
  514. }
  515. static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
  516. uint32_t *unused)
  517. {
  518. int i;
  519. const uint16_t *src = (const uint16_t *)_src;
  520. uint16_t *dst = (uint16_t *)_dst;
  521. for (i = 0; i < width; i++)
  522. dst[i] = av_bswap16(src[i]);
  523. }
  524. static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
  525. const uint8_t *_src2, int width, uint32_t *unused)
  526. {
  527. int i;
  528. const uint16_t *src1 = (const uint16_t *)_src1,
  529. *src2 = (const uint16_t *)_src2;
  530. uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
  531. for (i = 0; i < width; i++) {
  532. dstU[i] = av_bswap16(src1[i]);
  533. dstV[i] = av_bswap16(src2[i]);
  534. }
  535. }
  536. static void read_ya16le_gray_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  537. uint32_t *unused)
  538. {
  539. int i;
  540. for (i = 0; i < width; i++)
  541. AV_WN16(dst + i * 2, AV_RL16(src + i * 4));
  542. }
  543. static void read_ya16le_alpha_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  544. uint32_t *unused)
  545. {
  546. int i;
  547. for (i = 0; i < width; i++)
  548. AV_WN16(dst + i * 2, AV_RL16(src + i * 4 + 2));
  549. }
  550. static void read_ya16be_gray_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  551. uint32_t *unused)
  552. {
  553. int i;
  554. for (i = 0; i < width; i++)
  555. AV_WN16(dst + i * 2, AV_RB16(src + i * 4));
  556. }
  557. static void read_ya16be_alpha_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  558. uint32_t *unused)
  559. {
  560. int i;
  561. for (i = 0; i < width; i++)
  562. AV_WN16(dst + i * 2, AV_RB16(src + i * 4 + 2));
  563. }
  564. static void read_ayuv64le_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
  565. uint32_t *unused2)
  566. {
  567. int i;
  568. for (i = 0; i < width; i++)
  569. AV_WN16(dst + i * 2, AV_RL16(src + i * 8 + 2));
  570. }
  571. static void read_ayuv64le_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src,
  572. const uint8_t *unused1, int width, uint32_t *unused2)
  573. {
  574. int i;
  575. for (i = 0; i < width; i++) {
  576. AV_WN16(dstU + i * 2, AV_RL16(src + i * 8 + 4));
  577. AV_WN16(dstV + i * 2, AV_RL16(src + i * 8 + 6));
  578. }
  579. }
  580. static void read_ayuv64le_A_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
  581. uint32_t *unused2)
  582. {
  583. int i;
  584. for (i = 0; i < width; i++)
  585. AV_WN16(dst + i * 2, AV_RL16(src + i * 8));
  586. }
  587. /* This is almost identical to the previous, end exists only because
  588. * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
  589. static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  590. uint32_t *unused)
  591. {
  592. int i;
  593. for (i = 0; i < width; i++)
  594. dst[i] = src[2 * i + 1];
  595. }
  596. static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
  597. const uint8_t *src2, int width, uint32_t *unused)
  598. {
  599. int i;
  600. for (i = 0; i < width; i++) {
  601. dstU[i] = src1[4 * i + 0];
  602. dstV[i] = src1[4 * i + 2];
  603. }
  604. av_assert1(src1 == src2);
  605. }
  606. static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
  607. const uint8_t *src, int width)
  608. {
  609. int i;
  610. for (i = 0; i < width; i++) {
  611. dst1[i] = src[2 * i + 0];
  612. dst2[i] = src[2 * i + 1];
  613. }
  614. }
  615. static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
  616. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  617. int width, uint32_t *unused)
  618. {
  619. nvXXtoUV_c(dstU, dstV, src1, width);
  620. }
  621. static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
  622. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  623. int width, uint32_t *unused)
  624. {
  625. nvXXtoUV_c(dstV, dstU, src1, width);
  626. }
  627. static void p010LEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
  628. const uint8_t *unused2, int width, uint32_t *unused)
  629. {
  630. int i;
  631. for (i = 0; i < width; i++) {
  632. AV_WN16(dst + i * 2, AV_RL16(src + i * 2) >> 6);
  633. }
  634. }
  635. static void p010BEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
  636. const uint8_t *unused2, int width, uint32_t *unused)
  637. {
  638. int i;
  639. for (i = 0; i < width; i++) {
  640. AV_WN16(dst + i * 2, AV_RB16(src + i * 2) >> 6);
  641. }
  642. }
  643. static void p010LEToUV_c(uint8_t *dstU, uint8_t *dstV,
  644. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  645. int width, uint32_t *unused)
  646. {
  647. int i;
  648. for (i = 0; i < width; i++) {
  649. AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0) >> 6);
  650. AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2) >> 6);
  651. }
  652. }
  653. static void p010BEToUV_c(uint8_t *dstU, uint8_t *dstV,
  654. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  655. int width, uint32_t *unused)
  656. {
  657. int i;
  658. for (i = 0; i < width; i++) {
  659. AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0) >> 6);
  660. AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2) >> 6);
  661. }
  662. }
  663. static void p016LEToUV_c(uint8_t *dstU, uint8_t *dstV,
  664. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  665. int width, uint32_t *unused)
  666. {
  667. int i;
  668. for (i = 0; i < width; i++) {
  669. AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0));
  670. AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2));
  671. }
  672. }
  673. static void p016BEToUV_c(uint8_t *dstU, uint8_t *dstV,
  674. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  675. int width, uint32_t *unused)
  676. {
  677. int i;
  678. for (i = 0; i < width; i++) {
  679. AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0));
  680. AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2));
  681. }
  682. }
  683. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  684. static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  685. int width, uint32_t *rgb2yuv)
  686. {
  687. int16_t *dst = (int16_t *)_dst;
  688. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  689. int i;
  690. for (i = 0; i < width; i++) {
  691. int b = src[i * 3 + 0];
  692. int g = src[i * 3 + 1];
  693. int r = src[i * 3 + 2];
  694. dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  695. }
  696. }
  697. static void bgr24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  698. const uint8_t *src2, int width, uint32_t *rgb2yuv)
  699. {
  700. int16_t *dstU = (int16_t *)_dstU;
  701. int16_t *dstV = (int16_t *)_dstV;
  702. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  703. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  704. int i;
  705. for (i = 0; i < width; i++) {
  706. int b = src1[3 * i + 0];
  707. int g = src1[3 * i + 1];
  708. int r = src1[3 * i + 2];
  709. dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  710. dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  711. }
  712. av_assert1(src1 == src2);
  713. }
  714. static void bgr24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  715. const uint8_t *src2, int width, uint32_t *rgb2yuv)
  716. {
  717. int16_t *dstU = (int16_t *)_dstU;
  718. int16_t *dstV = (int16_t *)_dstV;
  719. int i;
  720. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  721. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  722. for (i = 0; i < width; i++) {
  723. int b = src1[6 * i + 0] + src1[6 * i + 3];
  724. int g = src1[6 * i + 1] + src1[6 * i + 4];
  725. int r = src1[6 * i + 2] + src1[6 * i + 5];
  726. dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  727. dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  728. }
  729. av_assert1(src1 == src2);
  730. }
  731. static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  732. uint32_t *rgb2yuv)
  733. {
  734. int16_t *dst = (int16_t *)_dst;
  735. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  736. int i;
  737. for (i = 0; i < width; i++) {
  738. int r = src[i * 3 + 0];
  739. int g = src[i * 3 + 1];
  740. int b = src[i * 3 + 2];
  741. dst[i] = ((ry*r + gy*g + by*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  742. }
  743. }
  744. static void rgb24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  745. const uint8_t *src2, int width, uint32_t *rgb2yuv)
  746. {
  747. int16_t *dstU = (int16_t *)_dstU;
  748. int16_t *dstV = (int16_t *)_dstV;
  749. int i;
  750. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  751. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  752. av_assert1(src1 == src2);
  753. for (i = 0; i < width; i++) {
  754. int r = src1[3 * i + 0];
  755. int g = src1[3 * i + 1];
  756. int b = src1[3 * i + 2];
  757. dstU[i] = (ru*r + gu*g + bu*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  758. dstV[i] = (rv*r + gv*g + bv*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  759. }
  760. }
  761. static void rgb24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  762. const uint8_t *src2, int width, uint32_t *rgb2yuv)
  763. {
  764. int16_t *dstU = (int16_t *)_dstU;
  765. int16_t *dstV = (int16_t *)_dstV;
  766. int i;
  767. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  768. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  769. av_assert1(src1 == src2);
  770. for (i = 0; i < width; i++) {
  771. int r = src1[6 * i + 0] + src1[6 * i + 3];
  772. int g = src1[6 * i + 1] + src1[6 * i + 4];
  773. int b = src1[6 * i + 2] + src1[6 * i + 5];
  774. dstU[i] = (ru*r + gu*g + bu*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  775. dstV[i] = (rv*r + gv*g + bv*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  776. }
  777. }
  778. static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv)
  779. {
  780. uint16_t *dst = (uint16_t *)_dst;
  781. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  782. int i;
  783. for (i = 0; i < width; i++) {
  784. int g = src[0][i];
  785. int b = src[1][i];
  786. int r = src[2][i];
  787. dst[i] = (ry*r + gy*g + by*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  788. }
  789. }
  790. static void planar_rgb_to_a(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *unused)
  791. {
  792. uint16_t *dst = (uint16_t *)_dst;
  793. int i;
  794. for (i = 0; i < width; i++)
  795. dst[i] = src[3][i] << 6;
  796. }
  797. static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv)
  798. {
  799. uint16_t *dstU = (uint16_t *)_dstU;
  800. uint16_t *dstV = (uint16_t *)_dstV;
  801. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  802. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  803. int i;
  804. for (i = 0; i < width; i++) {
  805. int g = src[0][i];
  806. int b = src[1][i];
  807. int r = src[2][i];
  808. dstU[i] = (ru*r + gu*g + bu*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  809. dstV[i] = (rv*r + gv*g + bv*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  810. }
  811. }
  812. #define rdpx(src) \
  813. (is_be ? AV_RB16(src) : AV_RL16(src))
  814. static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
  815. int width, int bpc, int is_be, int32_t *rgb2yuv)
  816. {
  817. int i;
  818. const uint16_t **src = (const uint16_t **)_src;
  819. uint16_t *dst = (uint16_t *)_dst;
  820. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  821. int shift = bpc < 16 ? bpc : 14;
  822. for (i = 0; i < width; i++) {
  823. int g = rdpx(src[0] + i);
  824. int b = rdpx(src[1] + i);
  825. int r = rdpx(src[2] + i);
  826. dst[i] = (ry*r + gy*g + by*b + (16 << (RGB2YUV_SHIFT + bpc - 8)) + (1 << (RGB2YUV_SHIFT + shift - 15))) >> (RGB2YUV_SHIFT + shift - 14);
  827. }
  828. }
  829. static av_always_inline void planar_rgb16_to_a(uint8_t *_dst, const uint8_t *_src[4],
  830. int width, int bpc, int is_be, int32_t *rgb2yuv)
  831. {
  832. int i;
  833. const uint16_t **src = (const uint16_t **)_src;
  834. uint16_t *dst = (uint16_t *)_dst;
  835. int shift = bpc < 16 ? bpc : 14;
  836. for (i = 0; i < width; i++) {
  837. dst[i] = rdpx(src[3] + i) << (14 - shift);
  838. }
  839. }
  840. static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
  841. const uint8_t *_src[4], int width,
  842. int bpc, int is_be, int32_t *rgb2yuv)
  843. {
  844. int i;
  845. const uint16_t **src = (const uint16_t **)_src;
  846. uint16_t *dstU = (uint16_t *)_dstU;
  847. uint16_t *dstV = (uint16_t *)_dstV;
  848. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  849. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  850. int shift = bpc < 16 ? bpc : 14;
  851. for (i = 0; i < width; i++) {
  852. int g = rdpx(src[0] + i);
  853. int b = rdpx(src[1] + i);
  854. int r = rdpx(src[2] + i);
  855. dstU[i] = (ru*r + gu*g + bu*b + (128 << (RGB2YUV_SHIFT + bpc - 8)) + (1 << (RGB2YUV_SHIFT + shift - 15))) >> (RGB2YUV_SHIFT + shift - 14);
  856. dstV[i] = (rv*r + gv*g + bv*b + (128 << (RGB2YUV_SHIFT + bpc - 8)) + (1 << (RGB2YUV_SHIFT + shift - 15))) >> (RGB2YUV_SHIFT + shift - 14);
  857. }
  858. }
  859. #undef rdpx
  860. #define rdpx(src) (is_be ? av_int2float(AV_RB32(src)): av_int2float(AV_RL32(src)))
  861. static av_always_inline void planar_rgbf32_to_a(uint8_t *_dst, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
  862. {
  863. int i;
  864. const float **src = (const float **)_src;
  865. uint16_t *dst = (uint16_t *)_dst;
  866. for (i = 0; i < width; i++) {
  867. dst[i] = lrintf(av_clipf(65535.0f * rdpx(src[3] + i), 0.0f, 65535.0f));
  868. }
  869. }
  870. static av_always_inline void planar_rgbf32_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
  871. {
  872. int i;
  873. const float **src = (const float **)_src;
  874. uint16_t *dstU = (uint16_t *)_dstU;
  875. uint16_t *dstV = (uint16_t *)_dstV;
  876. int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
  877. int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
  878. for (i = 0; i < width; i++) {
  879. int g = lrintf(av_clipf(65535.0f * rdpx(src[0] + i), 0.0f, 65535.0f));
  880. int b = lrintf(av_clipf(65535.0f * rdpx(src[1] + i), 0.0f, 65535.0f));
  881. int r = lrintf(av_clipf(65535.0f * rdpx(src[2] + i), 0.0f, 65535.0f));
  882. dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  883. dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  884. }
  885. }
  886. static av_always_inline void planar_rgbf32_to_y(uint8_t *_dst, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
  887. {
  888. int i;
  889. const float **src = (const float **)_src;
  890. uint16_t *dst = (uint16_t *)_dst;
  891. int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
  892. for (i = 0; i < width; i++) {
  893. int g = lrintf(av_clipf(65535.0f * rdpx(src[0] + i), 0.0f, 65535.0f));
  894. int b = lrintf(av_clipf(65535.0f * rdpx(src[1] + i), 0.0f, 65535.0f));
  895. int r = lrintf(av_clipf(65535.0f * rdpx(src[2] + i), 0.0f, 65535.0f));
  896. dst[i] = (ry*r + gy*g + by*b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  897. }
  898. }
  899. static av_always_inline void grayf32ToY16_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
  900. const uint8_t *unused2, int width, int is_be, uint32_t *unused)
  901. {
  902. int i;
  903. const float *src = (const float *)_src;
  904. uint16_t *dst = (uint16_t *)_dst;
  905. for (i = 0; i < width; ++i){
  906. dst[i] = lrintf(av_clipf(65535.0f * rdpx(src + i), 0.0f, 65535.0f));
  907. }
  908. }
  909. #undef rdpx
  910. #define rgb9plus_planar_funcs_endian(nbits, endian_name, endian) \
  911. static void planar_rgb##nbits##endian_name##_to_y(uint8_t *dst, const uint8_t *src[4], \
  912. int w, int32_t *rgb2yuv) \
  913. { \
  914. planar_rgb16_to_y(dst, src, w, nbits, endian, rgb2yuv); \
  915. } \
  916. static void planar_rgb##nbits##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV, \
  917. const uint8_t *src[4], int w, int32_t *rgb2yuv) \
  918. { \
  919. planar_rgb16_to_uv(dstU, dstV, src, w, nbits, endian, rgb2yuv); \
  920. } \
  921. #define rgb9plus_planar_transparency_funcs(nbits) \
  922. static void planar_rgb##nbits##le_to_a(uint8_t *dst, const uint8_t *src[4], \
  923. int w, int32_t *rgb2yuv) \
  924. { \
  925. planar_rgb16_to_a(dst, src, w, nbits, 0, rgb2yuv); \
  926. } \
  927. static void planar_rgb##nbits##be_to_a(uint8_t *dst, const uint8_t *src[4], \
  928. int w, int32_t *rgb2yuv) \
  929. { \
  930. planar_rgb16_to_a(dst, src, w, nbits, 1, rgb2yuv); \
  931. }
  932. #define rgb9plus_planar_funcs(nbits) \
  933. rgb9plus_planar_funcs_endian(nbits, le, 0) \
  934. rgb9plus_planar_funcs_endian(nbits, be, 1)
  935. rgb9plus_planar_funcs(9)
  936. rgb9plus_planar_funcs(10)
  937. rgb9plus_planar_funcs(12)
  938. rgb9plus_planar_funcs(14)
  939. rgb9plus_planar_funcs(16)
  940. rgb9plus_planar_transparency_funcs(10)
  941. rgb9plus_planar_transparency_funcs(12)
  942. rgb9plus_planar_transparency_funcs(16)
  943. #define rgbf32_planar_funcs_endian(endian_name, endian) \
  944. static void planar_rgbf32##endian_name##_to_y(uint8_t *dst, const uint8_t *src[4], \
  945. int w, int32_t *rgb2yuv) \
  946. { \
  947. planar_rgbf32_to_y(dst, src, w, endian, rgb2yuv); \
  948. } \
  949. static void planar_rgbf32##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV, \
  950. const uint8_t *src[4], int w, int32_t *rgb2yuv) \
  951. { \
  952. planar_rgbf32_to_uv(dstU, dstV, src, w, endian, rgb2yuv); \
  953. } \
  954. static void planar_rgbf32##endian_name##_to_a(uint8_t *dst, const uint8_t *src[4], \
  955. int w, int32_t *rgb2yuv) \
  956. { \
  957. planar_rgbf32_to_a(dst, src, w, endian, rgb2yuv); \
  958. } \
  959. static void grayf32##endian_name##ToY16_c(uint8_t *dst, const uint8_t *src, \
  960. const uint8_t *unused1, const uint8_t *unused2, \
  961. int width, uint32_t *unused) \
  962. { \
  963. grayf32ToY16_c(dst, src, unused1, unused2, width, endian, unused); \
  964. }
  965. rgbf32_planar_funcs_endian(le, 0)
  966. rgbf32_planar_funcs_endian(be, 1)
  967. av_cold void ff_sws_init_input_funcs(SwsContext *c)
  968. {
  969. enum AVPixelFormat srcFormat = c->srcFormat;
  970. c->chrToYV12 = NULL;
  971. switch (srcFormat) {
  972. case AV_PIX_FMT_YUYV422:
  973. c->chrToYV12 = yuy2ToUV_c;
  974. break;
  975. case AV_PIX_FMT_YVYU422:
  976. c->chrToYV12 = yvy2ToUV_c;
  977. break;
  978. case AV_PIX_FMT_UYVY422:
  979. c->chrToYV12 = uyvyToUV_c;
  980. break;
  981. case AV_PIX_FMT_NV12:
  982. case AV_PIX_FMT_NV24:
  983. c->chrToYV12 = nv12ToUV_c;
  984. break;
  985. case AV_PIX_FMT_NV21:
  986. case AV_PIX_FMT_NV42:
  987. c->chrToYV12 = nv21ToUV_c;
  988. break;
  989. case AV_PIX_FMT_RGB8:
  990. case AV_PIX_FMT_BGR8:
  991. case AV_PIX_FMT_PAL8:
  992. case AV_PIX_FMT_BGR4_BYTE:
  993. case AV_PIX_FMT_RGB4_BYTE:
  994. c->chrToYV12 = palToUV_c;
  995. break;
  996. case AV_PIX_FMT_GBRP9LE:
  997. c->readChrPlanar = planar_rgb9le_to_uv;
  998. break;
  999. case AV_PIX_FMT_GBRAP10LE:
  1000. case AV_PIX_FMT_GBRP10LE:
  1001. c->readChrPlanar = planar_rgb10le_to_uv;
  1002. break;
  1003. case AV_PIX_FMT_GBRAP12LE:
  1004. case AV_PIX_FMT_GBRP12LE:
  1005. c->readChrPlanar = planar_rgb12le_to_uv;
  1006. break;
  1007. case AV_PIX_FMT_GBRP14LE:
  1008. c->readChrPlanar = planar_rgb14le_to_uv;
  1009. break;
  1010. case AV_PIX_FMT_GBRAP16LE:
  1011. case AV_PIX_FMT_GBRP16LE:
  1012. c->readChrPlanar = planar_rgb16le_to_uv;
  1013. break;
  1014. case AV_PIX_FMT_GBRAPF32LE:
  1015. case AV_PIX_FMT_GBRPF32LE:
  1016. c->readChrPlanar = planar_rgbf32le_to_uv;
  1017. break;
  1018. case AV_PIX_FMT_GBRP9BE:
  1019. c->readChrPlanar = planar_rgb9be_to_uv;
  1020. break;
  1021. case AV_PIX_FMT_GBRAP10BE:
  1022. case AV_PIX_FMT_GBRP10BE:
  1023. c->readChrPlanar = planar_rgb10be_to_uv;
  1024. break;
  1025. case AV_PIX_FMT_GBRAP12BE:
  1026. case AV_PIX_FMT_GBRP12BE:
  1027. c->readChrPlanar = planar_rgb12be_to_uv;
  1028. break;
  1029. case AV_PIX_FMT_GBRP14BE:
  1030. c->readChrPlanar = planar_rgb14be_to_uv;
  1031. break;
  1032. case AV_PIX_FMT_GBRAP16BE:
  1033. case AV_PIX_FMT_GBRP16BE:
  1034. c->readChrPlanar = planar_rgb16be_to_uv;
  1035. break;
  1036. case AV_PIX_FMT_GBRAPF32BE:
  1037. case AV_PIX_FMT_GBRPF32BE:
  1038. c->readChrPlanar = planar_rgbf32be_to_uv;
  1039. break;
  1040. case AV_PIX_FMT_GBRAP:
  1041. case AV_PIX_FMT_GBRP:
  1042. c->readChrPlanar = planar_rgb_to_uv;
  1043. break;
  1044. #if HAVE_BIGENDIAN
  1045. case AV_PIX_FMT_YUV420P9LE:
  1046. case AV_PIX_FMT_YUV422P9LE:
  1047. case AV_PIX_FMT_YUV444P9LE:
  1048. case AV_PIX_FMT_YUV420P10LE:
  1049. case AV_PIX_FMT_YUV422P10LE:
  1050. case AV_PIX_FMT_YUV440P10LE:
  1051. case AV_PIX_FMT_YUV444P10LE:
  1052. case AV_PIX_FMT_YUV420P12LE:
  1053. case AV_PIX_FMT_YUV422P12LE:
  1054. case AV_PIX_FMT_YUV440P12LE:
  1055. case AV_PIX_FMT_YUV444P12LE:
  1056. case AV_PIX_FMT_YUV420P14LE:
  1057. case AV_PIX_FMT_YUV422P14LE:
  1058. case AV_PIX_FMT_YUV444P14LE:
  1059. case AV_PIX_FMT_YUV420P16LE:
  1060. case AV_PIX_FMT_YUV422P16LE:
  1061. case AV_PIX_FMT_YUV444P16LE:
  1062. case AV_PIX_FMT_YUVA420P9LE:
  1063. case AV_PIX_FMT_YUVA422P9LE:
  1064. case AV_PIX_FMT_YUVA444P9LE:
  1065. case AV_PIX_FMT_YUVA420P10LE:
  1066. case AV_PIX_FMT_YUVA422P10LE:
  1067. case AV_PIX_FMT_YUVA444P10LE:
  1068. case AV_PIX_FMT_YUVA422P12LE:
  1069. case AV_PIX_FMT_YUVA444P12LE:
  1070. case AV_PIX_FMT_YUVA420P16LE:
  1071. case AV_PIX_FMT_YUVA422P16LE:
  1072. case AV_PIX_FMT_YUVA444P16LE:
  1073. c->chrToYV12 = bswap16UV_c;
  1074. break;
  1075. #else
  1076. case AV_PIX_FMT_YUV420P9BE:
  1077. case AV_PIX_FMT_YUV422P9BE:
  1078. case AV_PIX_FMT_YUV444P9BE:
  1079. case AV_PIX_FMT_YUV420P10BE:
  1080. case AV_PIX_FMT_YUV422P10BE:
  1081. case AV_PIX_FMT_YUV440P10BE:
  1082. case AV_PIX_FMT_YUV444P10BE:
  1083. case AV_PIX_FMT_YUV420P12BE:
  1084. case AV_PIX_FMT_YUV422P12BE:
  1085. case AV_PIX_FMT_YUV440P12BE:
  1086. case AV_PIX_FMT_YUV444P12BE:
  1087. case AV_PIX_FMT_YUV420P14BE:
  1088. case AV_PIX_FMT_YUV422P14BE:
  1089. case AV_PIX_FMT_YUV444P14BE:
  1090. case AV_PIX_FMT_YUV420P16BE:
  1091. case AV_PIX_FMT_YUV422P16BE:
  1092. case AV_PIX_FMT_YUV444P16BE:
  1093. case AV_PIX_FMT_YUVA420P9BE:
  1094. case AV_PIX_FMT_YUVA422P9BE:
  1095. case AV_PIX_FMT_YUVA444P9BE:
  1096. case AV_PIX_FMT_YUVA420P10BE:
  1097. case AV_PIX_FMT_YUVA422P10BE:
  1098. case AV_PIX_FMT_YUVA444P10BE:
  1099. case AV_PIX_FMT_YUVA422P12BE:
  1100. case AV_PIX_FMT_YUVA444P12BE:
  1101. case AV_PIX_FMT_YUVA420P16BE:
  1102. case AV_PIX_FMT_YUVA422P16BE:
  1103. case AV_PIX_FMT_YUVA444P16BE:
  1104. c->chrToYV12 = bswap16UV_c;
  1105. break;
  1106. #endif
  1107. case AV_PIX_FMT_AYUV64LE:
  1108. c->chrToYV12 = read_ayuv64le_UV_c;
  1109. break;
  1110. case AV_PIX_FMT_P010LE:
  1111. case AV_PIX_FMT_P210LE:
  1112. case AV_PIX_FMT_P410LE:
  1113. c->chrToYV12 = p010LEToUV_c;
  1114. break;
  1115. case AV_PIX_FMT_P010BE:
  1116. case AV_PIX_FMT_P210BE:
  1117. case AV_PIX_FMT_P410BE:
  1118. c->chrToYV12 = p010BEToUV_c;
  1119. break;
  1120. case AV_PIX_FMT_P016LE:
  1121. case AV_PIX_FMT_P216LE:
  1122. case AV_PIX_FMT_P416LE:
  1123. c->chrToYV12 = p016LEToUV_c;
  1124. break;
  1125. case AV_PIX_FMT_P016BE:
  1126. case AV_PIX_FMT_P216BE:
  1127. case AV_PIX_FMT_P416BE:
  1128. c->chrToYV12 = p016BEToUV_c;
  1129. break;
  1130. case AV_PIX_FMT_Y210LE:
  1131. c->chrToYV12 = y210le_UV_c;
  1132. break;
  1133. }
  1134. if (c->chrSrcHSubSample) {
  1135. switch (srcFormat) {
  1136. case AV_PIX_FMT_RGBA64BE:
  1137. c->chrToYV12 = rgb64BEToUV_half_c;
  1138. break;
  1139. case AV_PIX_FMT_RGBA64LE:
  1140. c->chrToYV12 = rgb64LEToUV_half_c;
  1141. break;
  1142. case AV_PIX_FMT_BGRA64BE:
  1143. c->chrToYV12 = bgr64BEToUV_half_c;
  1144. break;
  1145. case AV_PIX_FMT_BGRA64LE:
  1146. c->chrToYV12 = bgr64LEToUV_half_c;
  1147. break;
  1148. case AV_PIX_FMT_RGB48BE:
  1149. c->chrToYV12 = rgb48BEToUV_half_c;
  1150. break;
  1151. case AV_PIX_FMT_RGB48LE:
  1152. c->chrToYV12 = rgb48LEToUV_half_c;
  1153. break;
  1154. case AV_PIX_FMT_BGR48BE:
  1155. c->chrToYV12 = bgr48BEToUV_half_c;
  1156. break;
  1157. case AV_PIX_FMT_BGR48LE:
  1158. c->chrToYV12 = bgr48LEToUV_half_c;
  1159. break;
  1160. case AV_PIX_FMT_RGB32:
  1161. c->chrToYV12 = bgr32ToUV_half_c;
  1162. break;
  1163. case AV_PIX_FMT_RGB32_1:
  1164. c->chrToYV12 = bgr321ToUV_half_c;
  1165. break;
  1166. case AV_PIX_FMT_BGR24:
  1167. c->chrToYV12 = bgr24ToUV_half_c;
  1168. break;
  1169. case AV_PIX_FMT_BGR565LE:
  1170. c->chrToYV12 = bgr16leToUV_half_c;
  1171. break;
  1172. case AV_PIX_FMT_BGR565BE:
  1173. c->chrToYV12 = bgr16beToUV_half_c;
  1174. break;
  1175. case AV_PIX_FMT_BGR555LE:
  1176. c->chrToYV12 = bgr15leToUV_half_c;
  1177. break;
  1178. case AV_PIX_FMT_BGR555BE:
  1179. c->chrToYV12 = bgr15beToUV_half_c;
  1180. break;
  1181. case AV_PIX_FMT_GBRAP:
  1182. case AV_PIX_FMT_GBRP:
  1183. c->chrToYV12 = gbr24pToUV_half_c;
  1184. break;
  1185. case AV_PIX_FMT_BGR444LE:
  1186. c->chrToYV12 = bgr12leToUV_half_c;
  1187. break;
  1188. case AV_PIX_FMT_BGR444BE:
  1189. c->chrToYV12 = bgr12beToUV_half_c;
  1190. break;
  1191. case AV_PIX_FMT_BGR32:
  1192. c->chrToYV12 = rgb32ToUV_half_c;
  1193. break;
  1194. case AV_PIX_FMT_BGR32_1:
  1195. c->chrToYV12 = rgb321ToUV_half_c;
  1196. break;
  1197. case AV_PIX_FMT_RGB24:
  1198. c->chrToYV12 = rgb24ToUV_half_c;
  1199. break;
  1200. case AV_PIX_FMT_RGB565LE:
  1201. c->chrToYV12 = rgb16leToUV_half_c;
  1202. break;
  1203. case AV_PIX_FMT_RGB565BE:
  1204. c->chrToYV12 = rgb16beToUV_half_c;
  1205. break;
  1206. case AV_PIX_FMT_RGB555LE:
  1207. c->chrToYV12 = rgb15leToUV_half_c;
  1208. break;
  1209. case AV_PIX_FMT_RGB555BE:
  1210. c->chrToYV12 = rgb15beToUV_half_c;
  1211. break;
  1212. case AV_PIX_FMT_RGB444LE:
  1213. c->chrToYV12 = rgb12leToUV_half_c;
  1214. break;
  1215. case AV_PIX_FMT_RGB444BE:
  1216. c->chrToYV12 = rgb12beToUV_half_c;
  1217. break;
  1218. case AV_PIX_FMT_X2RGB10LE:
  1219. c->chrToYV12 = rgb30leToUV_half_c;
  1220. break;
  1221. case AV_PIX_FMT_X2BGR10LE:
  1222. c->chrToYV12 = bgr30leToUV_half_c;
  1223. break;
  1224. }
  1225. } else {
  1226. switch (srcFormat) {
  1227. case AV_PIX_FMT_RGBA64BE:
  1228. c->chrToYV12 = rgb64BEToUV_c;
  1229. break;
  1230. case AV_PIX_FMT_RGBA64LE:
  1231. c->chrToYV12 = rgb64LEToUV_c;
  1232. break;
  1233. case AV_PIX_FMT_BGRA64BE:
  1234. c->chrToYV12 = bgr64BEToUV_c;
  1235. break;
  1236. case AV_PIX_FMT_BGRA64LE:
  1237. c->chrToYV12 = bgr64LEToUV_c;
  1238. break;
  1239. case AV_PIX_FMT_RGB48BE:
  1240. c->chrToYV12 = rgb48BEToUV_c;
  1241. break;
  1242. case AV_PIX_FMT_RGB48LE:
  1243. c->chrToYV12 = rgb48LEToUV_c;
  1244. break;
  1245. case AV_PIX_FMT_BGR48BE:
  1246. c->chrToYV12 = bgr48BEToUV_c;
  1247. break;
  1248. case AV_PIX_FMT_BGR48LE:
  1249. c->chrToYV12 = bgr48LEToUV_c;
  1250. break;
  1251. case AV_PIX_FMT_RGB32:
  1252. c->chrToYV12 = bgr32ToUV_c;
  1253. break;
  1254. case AV_PIX_FMT_RGB32_1:
  1255. c->chrToYV12 = bgr321ToUV_c;
  1256. break;
  1257. case AV_PIX_FMT_BGR24:
  1258. c->chrToYV12 = bgr24ToUV_c;
  1259. break;
  1260. case AV_PIX_FMT_BGR565LE:
  1261. c->chrToYV12 = bgr16leToUV_c;
  1262. break;
  1263. case AV_PIX_FMT_BGR565BE:
  1264. c->chrToYV12 = bgr16beToUV_c;
  1265. break;
  1266. case AV_PIX_FMT_BGR555LE:
  1267. c->chrToYV12 = bgr15leToUV_c;
  1268. break;
  1269. case AV_PIX_FMT_BGR555BE:
  1270. c->chrToYV12 = bgr15beToUV_c;
  1271. break;
  1272. case AV_PIX_FMT_BGR444LE:
  1273. c->chrToYV12 = bgr12leToUV_c;
  1274. break;
  1275. case AV_PIX_FMT_BGR444BE:
  1276. c->chrToYV12 = bgr12beToUV_c;
  1277. break;
  1278. case AV_PIX_FMT_BGR32:
  1279. c->chrToYV12 = rgb32ToUV_c;
  1280. break;
  1281. case AV_PIX_FMT_BGR32_1:
  1282. c->chrToYV12 = rgb321ToUV_c;
  1283. break;
  1284. case AV_PIX_FMT_RGB24:
  1285. c->chrToYV12 = rgb24ToUV_c;
  1286. break;
  1287. case AV_PIX_FMT_RGB565LE:
  1288. c->chrToYV12 = rgb16leToUV_c;
  1289. break;
  1290. case AV_PIX_FMT_RGB565BE:
  1291. c->chrToYV12 = rgb16beToUV_c;
  1292. break;
  1293. case AV_PIX_FMT_RGB555LE:
  1294. c->chrToYV12 = rgb15leToUV_c;
  1295. break;
  1296. case AV_PIX_FMT_RGB555BE:
  1297. c->chrToYV12 = rgb15beToUV_c;
  1298. break;
  1299. case AV_PIX_FMT_RGB444LE:
  1300. c->chrToYV12 = rgb12leToUV_c;
  1301. break;
  1302. case AV_PIX_FMT_RGB444BE:
  1303. c->chrToYV12 = rgb12beToUV_c;
  1304. break;
  1305. case AV_PIX_FMT_X2RGB10LE:
  1306. c->chrToYV12 = rgb30leToUV_c;
  1307. break;
  1308. case AV_PIX_FMT_X2BGR10LE:
  1309. c->chrToYV12 = bgr30leToUV_c;
  1310. break;
  1311. }
  1312. }
  1313. c->lumToYV12 = NULL;
  1314. c->alpToYV12 = NULL;
  1315. switch (srcFormat) {
  1316. case AV_PIX_FMT_GBRP9LE:
  1317. c->readLumPlanar = planar_rgb9le_to_y;
  1318. break;
  1319. case AV_PIX_FMT_GBRAP10LE:
  1320. c->readAlpPlanar = planar_rgb10le_to_a;
  1321. case AV_PIX_FMT_GBRP10LE:
  1322. c->readLumPlanar = planar_rgb10le_to_y;
  1323. break;
  1324. case AV_PIX_FMT_GBRAP12LE:
  1325. c->readAlpPlanar = planar_rgb12le_to_a;
  1326. case AV_PIX_FMT_GBRP12LE:
  1327. c->readLumPlanar = planar_rgb12le_to_y;
  1328. break;
  1329. case AV_PIX_FMT_GBRP14LE:
  1330. c->readLumPlanar = planar_rgb14le_to_y;
  1331. break;
  1332. case AV_PIX_FMT_GBRAP16LE:
  1333. c->readAlpPlanar = planar_rgb16le_to_a;
  1334. case AV_PIX_FMT_GBRP16LE:
  1335. c->readLumPlanar = planar_rgb16le_to_y;
  1336. break;
  1337. case AV_PIX_FMT_GBRAPF32LE:
  1338. c->readAlpPlanar = planar_rgbf32le_to_a;
  1339. case AV_PIX_FMT_GBRPF32LE:
  1340. c->readLumPlanar = planar_rgbf32le_to_y;
  1341. break;
  1342. case AV_PIX_FMT_GBRP9BE:
  1343. c->readLumPlanar = planar_rgb9be_to_y;
  1344. break;
  1345. case AV_PIX_FMT_GBRAP10BE:
  1346. c->readAlpPlanar = planar_rgb10be_to_a;
  1347. case AV_PIX_FMT_GBRP10BE:
  1348. c->readLumPlanar = planar_rgb10be_to_y;
  1349. break;
  1350. case AV_PIX_FMT_GBRAP12BE:
  1351. c->readAlpPlanar = planar_rgb12be_to_a;
  1352. case AV_PIX_FMT_GBRP12BE:
  1353. c->readLumPlanar = planar_rgb12be_to_y;
  1354. break;
  1355. case AV_PIX_FMT_GBRP14BE:
  1356. c->readLumPlanar = planar_rgb14be_to_y;
  1357. break;
  1358. case AV_PIX_FMT_GBRAP16BE:
  1359. c->readAlpPlanar = planar_rgb16be_to_a;
  1360. case AV_PIX_FMT_GBRP16BE:
  1361. c->readLumPlanar = planar_rgb16be_to_y;
  1362. break;
  1363. case AV_PIX_FMT_GBRAPF32BE:
  1364. c->readAlpPlanar = planar_rgbf32be_to_a;
  1365. case AV_PIX_FMT_GBRPF32BE:
  1366. c->readLumPlanar = planar_rgbf32be_to_y;
  1367. break;
  1368. case AV_PIX_FMT_GBRAP:
  1369. c->readAlpPlanar = planar_rgb_to_a;
  1370. case AV_PIX_FMT_GBRP:
  1371. c->readLumPlanar = planar_rgb_to_y;
  1372. break;
  1373. #if HAVE_BIGENDIAN
  1374. case AV_PIX_FMT_YUV420P9LE:
  1375. case AV_PIX_FMT_YUV422P9LE:
  1376. case AV_PIX_FMT_YUV444P9LE:
  1377. case AV_PIX_FMT_YUV420P10LE:
  1378. case AV_PIX_FMT_YUV422P10LE:
  1379. case AV_PIX_FMT_YUV440P10LE:
  1380. case AV_PIX_FMT_YUV444P10LE:
  1381. case AV_PIX_FMT_YUV420P12LE:
  1382. case AV_PIX_FMT_YUV422P12LE:
  1383. case AV_PIX_FMT_YUV440P12LE:
  1384. case AV_PIX_FMT_YUV444P12LE:
  1385. case AV_PIX_FMT_YUV420P14LE:
  1386. case AV_PIX_FMT_YUV422P14LE:
  1387. case AV_PIX_FMT_YUV444P14LE:
  1388. case AV_PIX_FMT_YUV420P16LE:
  1389. case AV_PIX_FMT_YUV422P16LE:
  1390. case AV_PIX_FMT_YUV444P16LE:
  1391. case AV_PIX_FMT_GRAY9LE:
  1392. case AV_PIX_FMT_GRAY10LE:
  1393. case AV_PIX_FMT_GRAY12LE:
  1394. case AV_PIX_FMT_GRAY14LE:
  1395. case AV_PIX_FMT_GRAY16LE:
  1396. case AV_PIX_FMT_P016LE:
  1397. case AV_PIX_FMT_P216LE:
  1398. case AV_PIX_FMT_P416LE:
  1399. c->lumToYV12 = bswap16Y_c;
  1400. break;
  1401. case AV_PIX_FMT_YUVA420P9LE:
  1402. case AV_PIX_FMT_YUVA422P9LE:
  1403. case AV_PIX_FMT_YUVA444P9LE:
  1404. case AV_PIX_FMT_YUVA420P10LE:
  1405. case AV_PIX_FMT_YUVA422P10LE:
  1406. case AV_PIX_FMT_YUVA444P10LE:
  1407. case AV_PIX_FMT_YUVA422P12LE:
  1408. case AV_PIX_FMT_YUVA444P12LE:
  1409. case AV_PIX_FMT_YUVA420P16LE:
  1410. case AV_PIX_FMT_YUVA422P16LE:
  1411. case AV_PIX_FMT_YUVA444P16LE:
  1412. c->lumToYV12 = bswap16Y_c;
  1413. c->alpToYV12 = bswap16Y_c;
  1414. break;
  1415. #else
  1416. case AV_PIX_FMT_YUV420P9BE:
  1417. case AV_PIX_FMT_YUV422P9BE:
  1418. case AV_PIX_FMT_YUV444P9BE:
  1419. case AV_PIX_FMT_YUV420P10BE:
  1420. case AV_PIX_FMT_YUV422P10BE:
  1421. case AV_PIX_FMT_YUV440P10BE:
  1422. case AV_PIX_FMT_YUV444P10BE:
  1423. case AV_PIX_FMT_YUV420P12BE:
  1424. case AV_PIX_FMT_YUV422P12BE:
  1425. case AV_PIX_FMT_YUV440P12BE:
  1426. case AV_PIX_FMT_YUV444P12BE:
  1427. case AV_PIX_FMT_YUV420P14BE:
  1428. case AV_PIX_FMT_YUV422P14BE:
  1429. case AV_PIX_FMT_YUV444P14BE:
  1430. case AV_PIX_FMT_YUV420P16BE:
  1431. case AV_PIX_FMT_YUV422P16BE:
  1432. case AV_PIX_FMT_YUV444P16BE:
  1433. case AV_PIX_FMT_GRAY9BE:
  1434. case AV_PIX_FMT_GRAY10BE:
  1435. case AV_PIX_FMT_GRAY12BE:
  1436. case AV_PIX_FMT_GRAY14BE:
  1437. case AV_PIX_FMT_GRAY16BE:
  1438. case AV_PIX_FMT_P016BE:
  1439. case AV_PIX_FMT_P216BE:
  1440. case AV_PIX_FMT_P416BE:
  1441. c->lumToYV12 = bswap16Y_c;
  1442. break;
  1443. case AV_PIX_FMT_YUVA420P9BE:
  1444. case AV_PIX_FMT_YUVA422P9BE:
  1445. case AV_PIX_FMT_YUVA444P9BE:
  1446. case AV_PIX_FMT_YUVA420P10BE:
  1447. case AV_PIX_FMT_YUVA422P10BE:
  1448. case AV_PIX_FMT_YUVA444P10BE:
  1449. case AV_PIX_FMT_YUVA422P12BE:
  1450. case AV_PIX_FMT_YUVA444P12BE:
  1451. case AV_PIX_FMT_YUVA420P16BE:
  1452. case AV_PIX_FMT_YUVA422P16BE:
  1453. case AV_PIX_FMT_YUVA444P16BE:
  1454. c->lumToYV12 = bswap16Y_c;
  1455. c->alpToYV12 = bswap16Y_c;
  1456. break;
  1457. #endif
  1458. case AV_PIX_FMT_YA16LE:
  1459. c->lumToYV12 = read_ya16le_gray_c;
  1460. break;
  1461. case AV_PIX_FMT_YA16BE:
  1462. c->lumToYV12 = read_ya16be_gray_c;
  1463. break;
  1464. case AV_PIX_FMT_AYUV64LE:
  1465. c->lumToYV12 = read_ayuv64le_Y_c;
  1466. break;
  1467. case AV_PIX_FMT_YUYV422:
  1468. case AV_PIX_FMT_YVYU422:
  1469. case AV_PIX_FMT_YA8:
  1470. c->lumToYV12 = yuy2ToY_c;
  1471. break;
  1472. case AV_PIX_FMT_UYVY422:
  1473. c->lumToYV12 = uyvyToY_c;
  1474. break;
  1475. case AV_PIX_FMT_BGR24:
  1476. c->lumToYV12 = bgr24ToY_c;
  1477. break;
  1478. case AV_PIX_FMT_BGR565LE:
  1479. c->lumToYV12 = bgr16leToY_c;
  1480. break;
  1481. case AV_PIX_FMT_BGR565BE:
  1482. c->lumToYV12 = bgr16beToY_c;
  1483. break;
  1484. case AV_PIX_FMT_BGR555LE:
  1485. c->lumToYV12 = bgr15leToY_c;
  1486. break;
  1487. case AV_PIX_FMT_BGR555BE:
  1488. c->lumToYV12 = bgr15beToY_c;
  1489. break;
  1490. case AV_PIX_FMT_BGR444LE:
  1491. c->lumToYV12 = bgr12leToY_c;
  1492. break;
  1493. case AV_PIX_FMT_BGR444BE:
  1494. c->lumToYV12 = bgr12beToY_c;
  1495. break;
  1496. case AV_PIX_FMT_RGB24:
  1497. c->lumToYV12 = rgb24ToY_c;
  1498. break;
  1499. case AV_PIX_FMT_RGB565LE:
  1500. c->lumToYV12 = rgb16leToY_c;
  1501. break;
  1502. case AV_PIX_FMT_RGB565BE:
  1503. c->lumToYV12 = rgb16beToY_c;
  1504. break;
  1505. case AV_PIX_FMT_RGB555LE:
  1506. c->lumToYV12 = rgb15leToY_c;
  1507. break;
  1508. case AV_PIX_FMT_RGB555BE:
  1509. c->lumToYV12 = rgb15beToY_c;
  1510. break;
  1511. case AV_PIX_FMT_RGB444LE:
  1512. c->lumToYV12 = rgb12leToY_c;
  1513. break;
  1514. case AV_PIX_FMT_RGB444BE:
  1515. c->lumToYV12 = rgb12beToY_c;
  1516. break;
  1517. case AV_PIX_FMT_RGB8:
  1518. case AV_PIX_FMT_BGR8:
  1519. case AV_PIX_FMT_PAL8:
  1520. case AV_PIX_FMT_BGR4_BYTE:
  1521. case AV_PIX_FMT_RGB4_BYTE:
  1522. c->lumToYV12 = palToY_c;
  1523. break;
  1524. case AV_PIX_FMT_MONOBLACK:
  1525. c->lumToYV12 = monoblack2Y_c;
  1526. break;
  1527. case AV_PIX_FMT_MONOWHITE:
  1528. c->lumToYV12 = monowhite2Y_c;
  1529. break;
  1530. case AV_PIX_FMT_RGB32:
  1531. c->lumToYV12 = bgr32ToY_c;
  1532. break;
  1533. case AV_PIX_FMT_RGB32_1:
  1534. c->lumToYV12 = bgr321ToY_c;
  1535. break;
  1536. case AV_PIX_FMT_BGR32:
  1537. c->lumToYV12 = rgb32ToY_c;
  1538. break;
  1539. case AV_PIX_FMT_BGR32_1:
  1540. c->lumToYV12 = rgb321ToY_c;
  1541. break;
  1542. case AV_PIX_FMT_RGB48BE:
  1543. c->lumToYV12 = rgb48BEToY_c;
  1544. break;
  1545. case AV_PIX_FMT_RGB48LE:
  1546. c->lumToYV12 = rgb48LEToY_c;
  1547. break;
  1548. case AV_PIX_FMT_BGR48BE:
  1549. c->lumToYV12 = bgr48BEToY_c;
  1550. break;
  1551. case AV_PIX_FMT_BGR48LE:
  1552. c->lumToYV12 = bgr48LEToY_c;
  1553. break;
  1554. case AV_PIX_FMT_RGBA64BE:
  1555. c->lumToYV12 = rgb64BEToY_c;
  1556. break;
  1557. case AV_PIX_FMT_RGBA64LE:
  1558. c->lumToYV12 = rgb64LEToY_c;
  1559. break;
  1560. case AV_PIX_FMT_BGRA64BE:
  1561. c->lumToYV12 = bgr64BEToY_c;
  1562. break;
  1563. case AV_PIX_FMT_BGRA64LE:
  1564. c->lumToYV12 = bgr64LEToY_c;
  1565. break;
  1566. case AV_PIX_FMT_P010LE:
  1567. case AV_PIX_FMT_P210LE:
  1568. case AV_PIX_FMT_P410LE:
  1569. c->lumToYV12 = p010LEToY_c;
  1570. break;
  1571. case AV_PIX_FMT_P010BE:
  1572. case AV_PIX_FMT_P210BE:
  1573. case AV_PIX_FMT_P410BE:
  1574. c->lumToYV12 = p010BEToY_c;
  1575. break;
  1576. case AV_PIX_FMT_GRAYF32LE:
  1577. c->lumToYV12 = grayf32leToY16_c;
  1578. break;
  1579. case AV_PIX_FMT_GRAYF32BE:
  1580. c->lumToYV12 = grayf32beToY16_c;
  1581. break;
  1582. case AV_PIX_FMT_Y210LE:
  1583. c->lumToYV12 = y210le_Y_c;
  1584. break;
  1585. case AV_PIX_FMT_X2RGB10LE:
  1586. c->lumToYV12 = rgb30leToY_c;
  1587. break;
  1588. case AV_PIX_FMT_X2BGR10LE:
  1589. c->lumToYV12 = bgr30leToY_c;
  1590. break;
  1591. }
  1592. if (c->needAlpha) {
  1593. if (is16BPS(srcFormat) || isNBPS(srcFormat)) {
  1594. if (HAVE_BIGENDIAN == !isBE(srcFormat) && !c->readAlpPlanar)
  1595. c->alpToYV12 = bswap16Y_c;
  1596. }
  1597. switch (srcFormat) {
  1598. case AV_PIX_FMT_BGRA64LE:
  1599. case AV_PIX_FMT_RGBA64LE: c->alpToYV12 = rgba64leToA_c; break;
  1600. case AV_PIX_FMT_BGRA64BE:
  1601. case AV_PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64beToA_c; break;
  1602. case AV_PIX_FMT_BGRA:
  1603. case AV_PIX_FMT_RGBA:
  1604. c->alpToYV12 = rgbaToA_c;
  1605. break;
  1606. case AV_PIX_FMT_ABGR:
  1607. case AV_PIX_FMT_ARGB:
  1608. c->alpToYV12 = abgrToA_c;
  1609. break;
  1610. case AV_PIX_FMT_YA8:
  1611. c->alpToYV12 = uyvyToY_c;
  1612. break;
  1613. case AV_PIX_FMT_YA16LE:
  1614. c->alpToYV12 = read_ya16le_alpha_c;
  1615. break;
  1616. case AV_PIX_FMT_YA16BE:
  1617. c->alpToYV12 = read_ya16be_alpha_c;
  1618. break;
  1619. case AV_PIX_FMT_AYUV64LE:
  1620. c->alpToYV12 = read_ayuv64le_A_c;
  1621. break;
  1622. case AV_PIX_FMT_PAL8 :
  1623. c->alpToYV12 = palToA_c;
  1624. break;
  1625. }
  1626. }
  1627. }