input.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /*
  2. * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <assert.h>
  21. #include <math.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/bswap.h"
  27. #include "libavutil/cpu.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "libavutil/avassert.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale.h"
  35. #include "swscale_internal.h"
  36. #define RGB2YUV_SHIFT 15
  37. #define BY ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  38. #define BV (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  39. #define BU ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  40. #define GY ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  41. #define GV (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  42. #define GU (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  43. #define RY ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  44. #define RV ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  45. #define RU (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
  46. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  47. #define r ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? b_r : r_b)
  48. #define b ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? r_b : b_r)
  49. static av_always_inline void
  50. rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
  51. enum PixelFormat origin)
  52. {
  53. int i;
  54. for (i = 0; i < width; i++) {
  55. unsigned int r_b = input_pixel(&src[i*4+0]);
  56. unsigned int g = input_pixel(&src[i*4+1]);
  57. unsigned int b_r = input_pixel(&src[i*4+2]);
  58. dst[i] = (RY*r + GY*g + BY*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  59. }
  60. }
  61. static av_always_inline void
  62. rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
  63. const uint16_t *src1, const uint16_t *src2,
  64. int width, enum PixelFormat origin)
  65. {
  66. int i;
  67. av_assert1(src1==src2);
  68. for (i = 0; i < width; i++) {
  69. int r_b = input_pixel(&src1[i*4+0]);
  70. int g = input_pixel(&src1[i*4+1]);
  71. int b_r = input_pixel(&src1[i*4+2]);
  72. dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  73. dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  74. }
  75. }
  76. static av_always_inline void
  77. rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
  78. const uint16_t *src1, const uint16_t *src2,
  79. int width, enum PixelFormat origin)
  80. {
  81. int i;
  82. av_assert1(src1==src2);
  83. for (i = 0; i < width; i++) {
  84. int r_b = (input_pixel(&src1[8 * i + 0]) + input_pixel(&src1[8 * i + 4]) + 1) >> 1;
  85. int g = (input_pixel(&src1[8 * i + 1]) + input_pixel(&src1[8 * i + 5]) + 1) >> 1;
  86. int b_r = (input_pixel(&src1[8 * i + 2]) + input_pixel(&src1[8 * i + 6]) + 1) >> 1;
  87. dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  88. dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
  89. }
  90. }
  91. #define rgb64funcs(pattern, BE_LE, origin) \
  92. static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
  93. int width, uint32_t *unused) \
  94. { \
  95. const uint16_t *src = (const uint16_t *) _src; \
  96. uint16_t *dst = (uint16_t *) _dst; \
  97. rgb64ToY_c_template(dst, src, width, origin); \
  98. } \
  99. \
  100. static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
  101. const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
  102. int width, uint32_t *unused) \
  103. { \
  104. const uint16_t *src1 = (const uint16_t *) _src1, \
  105. *src2 = (const uint16_t *) _src2; \
  106. uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
  107. rgb64ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
  108. } \
  109. \
  110. static void pattern ## 64 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
  111. const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
  112. int width, uint32_t *unused) \
  113. { \
  114. const uint16_t *src1 = (const uint16_t *) _src1, \
  115. *src2 = (const uint16_t *) _src2; \
  116. uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
  117. rgb64ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
  118. }
  119. rgb64funcs(rgb, LE, PIX_FMT_RGBA64LE)
  120. rgb64funcs(rgb, BE, PIX_FMT_RGBA64BE)
  121. static av_always_inline void rgb48ToY_c_template(uint16_t *dst,
  122. const uint16_t *src, int width,
  123. enum PixelFormat origin)
  124. {
  125. int i;
  126. for (i = 0; i < width; i++) {
  127. unsigned int r_b = input_pixel(&src[i * 3 + 0]);
  128. unsigned int g = input_pixel(&src[i * 3 + 1]);
  129. unsigned int b_r = input_pixel(&src[i * 3 + 2]);
  130. dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  131. }
  132. }
  133. static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
  134. uint16_t *dstV,
  135. const uint16_t *src1,
  136. const uint16_t *src2,
  137. int width,
  138. enum PixelFormat origin)
  139. {
  140. int i;
  141. av_assert1(src1 == src2);
  142. for (i = 0; i < width; i++) {
  143. int r_b = input_pixel(&src1[i * 3 + 0]);
  144. int g = input_pixel(&src1[i * 3 + 1]);
  145. int b_r = input_pixel(&src1[i * 3 + 2]);
  146. dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  147. dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  148. }
  149. }
  150. static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
  151. uint16_t *dstV,
  152. const uint16_t *src1,
  153. const uint16_t *src2,
  154. int width,
  155. enum PixelFormat origin)
  156. {
  157. int i;
  158. av_assert1(src1 == src2);
  159. for (i = 0; i < width; i++) {
  160. int r_b = (input_pixel(&src1[6 * i + 0]) +
  161. input_pixel(&src1[6 * i + 3]) + 1) >> 1;
  162. int g = (input_pixel(&src1[6 * i + 1]) +
  163. input_pixel(&src1[6 * i + 4]) + 1) >> 1;
  164. int b_r = (input_pixel(&src1[6 * i + 2]) +
  165. input_pixel(&src1[6 * i + 5]) + 1) >> 1;
  166. dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  167. dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
  168. }
  169. }
  170. #undef r
  171. #undef b
  172. #undef input_pixel
  173. #define rgb48funcs(pattern, BE_LE, origin) \
  174. static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \
  175. const uint8_t *_src, \
  176. const uint8_t *unused0, const uint8_t *unused1,\
  177. int width, \
  178. uint32_t *unused) \
  179. { \
  180. const uint16_t *src = (const uint16_t *)_src; \
  181. uint16_t *dst = (uint16_t *)_dst; \
  182. rgb48ToY_c_template(dst, src, width, origin); \
  183. } \
  184. \
  185. static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \
  186. uint8_t *_dstV, \
  187. const uint8_t *unused0, \
  188. const uint8_t *_src1, \
  189. const uint8_t *_src2, \
  190. int width, \
  191. uint32_t *unused) \
  192. { \
  193. const uint16_t *src1 = (const uint16_t *)_src1, \
  194. *src2 = (const uint16_t *)_src2; \
  195. uint16_t *dstU = (uint16_t *)_dstU, \
  196. *dstV = (uint16_t *)_dstV; \
  197. rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
  198. } \
  199. \
  200. static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \
  201. uint8_t *_dstV, \
  202. const uint8_t *unused0, \
  203. const uint8_t *_src1, \
  204. const uint8_t *_src2, \
  205. int width, \
  206. uint32_t *unused) \
  207. { \
  208. const uint16_t *src1 = (const uint16_t *)_src1, \
  209. *src2 = (const uint16_t *)_src2; \
  210. uint16_t *dstU = (uint16_t *)_dstU, \
  211. *dstV = (uint16_t *)_dstV; \
  212. rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
  213. }
  214. rgb48funcs(rgb, LE, PIX_FMT_RGB48LE)
  215. rgb48funcs(rgb, BE, PIX_FMT_RGB48BE)
  216. rgb48funcs(bgr, LE, PIX_FMT_BGR48LE)
  217. rgb48funcs(bgr, BE, PIX_FMT_BGR48BE)
  218. #define input_pixel(i) ((origin == PIX_FMT_RGBA || \
  219. origin == PIX_FMT_BGRA || \
  220. origin == PIX_FMT_ARGB || \
  221. origin == PIX_FMT_ABGR) \
  222. ? AV_RN32A(&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 PixelFormat 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. {
  235. const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh;
  236. const unsigned rnd = (32<<((S)-1)) + (1<<(S-7));
  237. int i;
  238. for (i = 0; i < width; i++) {
  239. int px = input_pixel(i) >> shp;
  240. int b = (px & maskb) >> shb;
  241. int g = (px & maskg) >> shg;
  242. int r = (px & maskr) >> shr;
  243. dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
  244. }
  245. }
  246. static av_always_inline void rgb16_32ToUV_c_template(int16_t *dstU,
  247. int16_t *dstV,
  248. const uint8_t *src,
  249. int width,
  250. enum PixelFormat origin,
  251. int shr, int shg,
  252. int shb, int shp,
  253. int maskr, int maskg,
  254. int maskb, int rsh,
  255. int gsh, int bsh, int S)
  256. {
  257. const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
  258. rv = RV << rsh, gv = GV << gsh, bv = BV << bsh;
  259. const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7));
  260. int i;
  261. for (i = 0; i < width; i++) {
  262. int px = input_pixel(i) >> shp;
  263. int b = (px & maskb) >> shb;
  264. int g = (px & maskg) >> shg;
  265. int r = (px & maskr) >> shr;
  266. dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
  267. dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
  268. }
  269. }
  270. static av_always_inline void rgb16_32ToUV_half_c_template(int16_t *dstU,
  271. int16_t *dstV,
  272. const uint8_t *src,
  273. int width,
  274. enum PixelFormat origin,
  275. int shr, int shg,
  276. int shb, int shp,
  277. int maskr, int maskg,
  278. int maskb, int rsh,
  279. int gsh, int bsh, int S)
  280. {
  281. const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
  282. rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
  283. maskgx = ~(maskr | maskb);
  284. const unsigned rnd = (256U<<(S)) + (1<<(S-6));
  285. int i;
  286. maskr |= maskr << 1;
  287. maskb |= maskb << 1;
  288. maskg |= maskg << 1;
  289. for (i = 0; i < width; i++) {
  290. int px0 = input_pixel(2 * i + 0) >> shp;
  291. int px1 = input_pixel(2 * i + 1) >> shp;
  292. int b, r, g = (px0 & maskgx) + (px1 & maskgx);
  293. int rb = px0 + px1 - g;
  294. b = (rb & maskb) >> shb;
  295. if (shp ||
  296. origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE ||
  297. origin == PIX_FMT_RGB565LE || origin == PIX_FMT_RGB565BE) {
  298. g >>= shg;
  299. } else {
  300. g = (g & maskg) >> shg;
  301. }
  302. r = (rb & maskr) >> shr;
  303. dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
  304. dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
  305. }
  306. }
  307. #undef input_pixel
  308. #define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
  309. maskg, maskb, rsh, gsh, bsh, S) \
  310. static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
  311. int width, uint32_t *unused) \
  312. { \
  313. rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, shr, shg, shb, shp, \
  314. maskr, maskg, maskb, rsh, gsh, bsh, S); \
  315. } \
  316. \
  317. static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  318. const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
  319. int width, uint32_t *unused) \
  320. { \
  321. rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
  322. shr, shg, shb, shp, \
  323. maskr, maskg, maskb, rsh, gsh, bsh, S); \
  324. } \
  325. \
  326. static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
  327. const uint8_t *unused0, const uint8_t *src, \
  328. const uint8_t *dummy, \
  329. int width, uint32_t *unused) \
  330. { \
  331. rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
  332. shr, shg, shb, shp, \
  333. maskr, maskg, maskb, \
  334. rsh, gsh, bsh, S); \
  335. }
  336. rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
  337. rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8)
  338. rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
  339. rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8)
  340. rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
  341. rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
  342. rgb16_32_wrapper(PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
  343. rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
  344. rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
  345. rgb16_32_wrapper(PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
  346. rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8)
  347. rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7)
  348. rgb16_32_wrapper(PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4)
  349. rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8)
  350. rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7)
  351. rgb16_32_wrapper(PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4)
  352. static void gbr24pToUV_half_c(uint8_t *_dstU, uint8_t *_dstV,
  353. const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
  354. int width, uint32_t *unused)
  355. {
  356. uint16_t *dstU = (uint16_t *)_dstU;
  357. uint16_t *dstV = (uint16_t *)_dstV;
  358. int i;
  359. for (i = 0; i < width; i++) {
  360. unsigned int g = gsrc[2*i] + gsrc[2*i+1];
  361. unsigned int b = bsrc[2*i] + bsrc[2*i+1];
  362. unsigned int r = rsrc[2*i] + rsrc[2*i+1];
  363. dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
  364. dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
  365. }
  366. }
  367. static void rgba64ToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
  368. const uint8_t *unused2, int width, uint32_t *unused)
  369. {
  370. int16_t *dst = (int16_t *)_dst;
  371. const uint16_t *src = (const uint16_t *)_src;
  372. int i;
  373. for (i = 0; i < width; i++)
  374. dst[i] = src[4 * i + 3];
  375. }
  376. static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  377. {
  378. int16_t *dst = (int16_t *)_dst;
  379. int i;
  380. for (i=0; i<width; i++) {
  381. dst[i]= src[4*i]<<6;
  382. }
  383. }
  384. static void rgbaToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  385. {
  386. int16_t *dst = (int16_t *)_dst;
  387. int i;
  388. for (i=0; i<width; i++) {
  389. dst[i]= src[4*i+3]<<6;
  390. }
  391. }
  392. static void palToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
  393. {
  394. int16_t *dst = (int16_t *)_dst;
  395. int i;
  396. for (i=0; i<width; i++) {
  397. int d= src[i];
  398. dst[i]= (pal[d] >> 24)<<6;
  399. }
  400. }
  401. static void palToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
  402. {
  403. int16_t *dst = (int16_t *)_dst;
  404. int i;
  405. for (i = 0; i < width; i++) {
  406. int d = src[i];
  407. dst[i] = (pal[d] & 0xFF)<<6;
  408. }
  409. }
  410. static void palToUV_c(uint8_t *_dstU, uint8_t *_dstV,
  411. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  412. int width, uint32_t *pal)
  413. {
  414. uint16_t *dstU = (uint16_t *)_dstU;
  415. int16_t *dstV = (int16_t *)_dstV;
  416. int i;
  417. av_assert1(src1 == src2);
  418. for (i = 0; i < width; i++) {
  419. int p = pal[src1[i]];
  420. dstU[i] = (uint8_t)(p>> 8)<<6;
  421. dstV[i] = (uint8_t)(p>>16)<<6;
  422. }
  423. }
  424. static void monowhite2Y_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
  425. {
  426. int16_t *dst = (int16_t *)_dst;
  427. int i, j;
  428. width = (width + 7) >> 3;
  429. for (i = 0; i < width; i++) {
  430. int d = ~src[i];
  431. for (j = 0; j < 8; j++)
  432. dst[8*i+j]= ((d>>(7-j))&1) * 16383;
  433. }
  434. if(width&7){
  435. int d= ~src[i];
  436. for (j = 0; j < (width&7); j++)
  437. dst[8*i+j]= ((d>>(7-j))&1) * 16383;
  438. }
  439. }
  440. static void monoblack2Y_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 yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  457. uint32_t *unused)
  458. {
  459. int i;
  460. for (i = 0; i < width; i++)
  461. dst[i] = src[2 * i];
  462. }
  463. static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
  464. const uint8_t *src2, int width, uint32_t *unused)
  465. {
  466. int i;
  467. for (i = 0; i < width; i++) {
  468. dstU[i] = src1[4 * i + 1];
  469. dstV[i] = src1[4 * i + 3];
  470. }
  471. av_assert1(src1 == src2);
  472. }
  473. static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
  474. uint32_t *unused)
  475. {
  476. int i;
  477. const uint16_t *src = (const uint16_t *)_src;
  478. uint16_t *dst = (uint16_t *)_dst;
  479. for (i = 0; i < width; i++)
  480. dst[i] = av_bswap16(src[i]);
  481. }
  482. static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
  483. const uint8_t *_src2, int width, uint32_t *unused)
  484. {
  485. int i;
  486. const uint16_t *src1 = (const uint16_t *)_src1,
  487. *src2 = (const uint16_t *)_src2;
  488. uint16_t *dstU = (uint16_t *)_dstU, *dstV = (uint16_t *)_dstV;
  489. for (i = 0; i < width; i++) {
  490. dstU[i] = av_bswap16(src1[i]);
  491. dstV[i] = av_bswap16(src2[i]);
  492. }
  493. }
  494. /* This is almost identical to the previous, end exists only because
  495. * yuy2ToY/UV)(dst, src + 1, ...) would have 100% unaligned accesses. */
  496. static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  497. uint32_t *unused)
  498. {
  499. int i;
  500. for (i = 0; i < width; i++)
  501. dst[i] = src[2 * i + 1];
  502. }
  503. static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
  504. const uint8_t *src2, int width, uint32_t *unused)
  505. {
  506. int i;
  507. for (i = 0; i < width; i++) {
  508. dstU[i] = src1[4 * i + 0];
  509. dstV[i] = src1[4 * i + 2];
  510. }
  511. av_assert1(src1 == src2);
  512. }
  513. static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
  514. const uint8_t *src, int width)
  515. {
  516. int i;
  517. for (i = 0; i < width; i++) {
  518. dst1[i] = src[2 * i + 0];
  519. dst2[i] = src[2 * i + 1];
  520. }
  521. }
  522. static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
  523. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  524. int width, uint32_t *unused)
  525. {
  526. nvXXtoUV_c(dstU, dstV, src1, width);
  527. }
  528. static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
  529. const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
  530. int width, uint32_t *unused)
  531. {
  532. nvXXtoUV_c(dstV, dstU, src1, width);
  533. }
  534. #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
  535. static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
  536. int width, uint32_t *unused)
  537. {
  538. int16_t *dst = (int16_t *)_dst;
  539. int i;
  540. for (i = 0; i < width; i++) {
  541. int b = src[i * 3 + 0];
  542. int g = src[i * 3 + 1];
  543. int r = src[i * 3 + 2];
  544. dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  545. }
  546. }
  547. static void bgr24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  548. const uint8_t *src2, int width, uint32_t *unused)
  549. {
  550. int16_t *dstU = (int16_t *)_dstU;
  551. int16_t *dstV = (int16_t *)_dstV;
  552. int i;
  553. for (i = 0; i < width; i++) {
  554. int b = src1[3 * i + 0];
  555. int g = src1[3 * i + 1];
  556. int r = src1[3 * i + 2];
  557. dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  558. dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  559. }
  560. av_assert1(src1 == src2);
  561. }
  562. static void bgr24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  563. const uint8_t *src2, int width, uint32_t *unused)
  564. {
  565. int16_t *dstU = (int16_t *)_dstU;
  566. int16_t *dstV = (int16_t *)_dstV;
  567. int i;
  568. for (i = 0; i < width; i++) {
  569. int b = src1[6 * i + 0] + src1[6 * i + 3];
  570. int g = src1[6 * i + 1] + src1[6 * i + 4];
  571. int r = src1[6 * i + 2] + src1[6 * i + 5];
  572. dstU[i] = (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  573. dstV[i] = (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  574. }
  575. av_assert1(src1 == src2);
  576. }
  577. static void rgb24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
  578. uint32_t *unused)
  579. {
  580. int16_t *dst = (int16_t *)_dst;
  581. int i;
  582. for (i = 0; i < width; i++) {
  583. int r = src[i * 3 + 0];
  584. int g = src[i * 3 + 1];
  585. int b = src[i * 3 + 2];
  586. dst[i] = ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
  587. }
  588. }
  589. static void rgb24ToUV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  590. const uint8_t *src2, int width, uint32_t *unused)
  591. {
  592. int16_t *dstU = (int16_t *)_dstU;
  593. int16_t *dstV = (int16_t *)_dstV;
  594. int i;
  595. av_assert1(src1 == src2);
  596. for (i = 0; i < width; i++) {
  597. int r = src1[3 * i + 0];
  598. int g = src1[3 * i + 1];
  599. int b = src1[3 * i + 2];
  600. dstU[i] = (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  601. dstV[i] = (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
  602. }
  603. }
  604. static void rgb24ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *src1,
  605. const uint8_t *src2, int width, uint32_t *unused)
  606. {
  607. int16_t *dstU = (int16_t *)_dstU;
  608. int16_t *dstV = (int16_t *)_dstV;
  609. int i;
  610. av_assert1(src1 == src2);
  611. for (i = 0; i < width; i++) {
  612. int r = src1[6 * i + 0] + src1[6 * i + 3];
  613. int g = src1[6 * i + 1] + src1[6 * i + 4];
  614. int b = src1[6 * i + 2] + src1[6 * i + 5];
  615. dstU[i] = (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  616. dstV[i] = (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
  617. }
  618. }
  619. static void planar_rgb_to_y(uint8_t *_dst, const uint8_t *src[4], int width)
  620. {
  621. uint16_t *dst = (uint16_t *)_dst;
  622. int i;
  623. for (i = 0; i < width; i++) {
  624. int g = src[0][i];
  625. int b = src[1][i];
  626. int r = src[2][i];
  627. dst[i] = (RY*r + GY*g + BY*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  628. }
  629. }
  630. static void planar_rgb_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], int width)
  631. {
  632. uint16_t *dstU = (uint16_t *)_dstU;
  633. uint16_t *dstV = (uint16_t *)_dstV;
  634. int i;
  635. for (i = 0; i < width; i++) {
  636. int g = src[0][i];
  637. int b = src[1][i];
  638. int r = src[2][i];
  639. dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  640. dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
  641. }
  642. }
  643. #define rdpx(src) \
  644. is_be ? AV_RB16(src) : AV_RL16(src)
  645. static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
  646. int width, int bpc, int is_be)
  647. {
  648. int i;
  649. const uint16_t **src = (const uint16_t **)_src;
  650. uint16_t *dst = (uint16_t *)_dst;
  651. for (i = 0; i < width; i++) {
  652. int g = rdpx(src[0] + i);
  653. int b = rdpx(src[1] + i);
  654. int r = rdpx(src[2] + i);
  655. dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
  656. }
  657. }
  658. static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  659. {
  660. planar_rgb16_to_y(dst, src, w, 9, 0);
  661. }
  662. static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  663. {
  664. planar_rgb16_to_y(dst, src, w, 9, 1);
  665. }
  666. static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  667. {
  668. planar_rgb16_to_y(dst, src, w, 10, 0);
  669. }
  670. static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  671. {
  672. planar_rgb16_to_y(dst, src, w, 10, 1);
  673. }
  674. static void planar_rgb12le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  675. {
  676. planar_rgb16_to_y(dst, src, w, 12, 0);
  677. }
  678. static void planar_rgb12be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  679. {
  680. planar_rgb16_to_y(dst, src, w, 12, 1);
  681. }
  682. static void planar_rgb14le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  683. {
  684. planar_rgb16_to_y(dst, src, w, 14, 0);
  685. }
  686. static void planar_rgb14be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  687. {
  688. planar_rgb16_to_y(dst, src, w, 14, 1);
  689. }
  690. static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  691. {
  692. planar_rgb16_to_y(dst, src, w, 16, 0);
  693. }
  694. static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
  695. {
  696. planar_rgb16_to_y(dst, src, w, 16, 1);
  697. }
  698. static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
  699. const uint8_t *_src[4], int width,
  700. int bpc, int is_be)
  701. {
  702. int i;
  703. const uint16_t **src = (const uint16_t **)_src;
  704. uint16_t *dstU = (uint16_t *)_dstU;
  705. uint16_t *dstV = (uint16_t *)_dstV;
  706. for (i = 0; i < width; i++) {
  707. int g = rdpx(src[0] + i);
  708. int b = rdpx(src[1] + i);
  709. int r = rdpx(src[2] + i);
  710. dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
  711. dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
  712. }
  713. }
  714. #undef rdpx
  715. static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
  716. const uint8_t *src[4], int w)
  717. {
  718. planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
  719. }
  720. static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
  721. const uint8_t *src[4], int w)
  722. {
  723. planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
  724. }
  725. static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
  726. const uint8_t *src[4], int w)
  727. {
  728. planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
  729. }
  730. static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
  731. const uint8_t *src[4], int w)
  732. {
  733. planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
  734. }
  735. static void planar_rgb12le_to_uv(uint8_t *dstU, uint8_t *dstV,
  736. const uint8_t *src[4], int w)
  737. {
  738. planar_rgb16_to_uv(dstU, dstV, src, w, 12, 0);
  739. }
  740. static void planar_rgb12be_to_uv(uint8_t *dstU, uint8_t *dstV,
  741. const uint8_t *src[4], int w)
  742. {
  743. planar_rgb16_to_uv(dstU, dstV, src, w, 12, 1);
  744. }
  745. static void planar_rgb14le_to_uv(uint8_t *dstU, uint8_t *dstV,
  746. const uint8_t *src[4], int w)
  747. {
  748. planar_rgb16_to_uv(dstU, dstV, src, w, 14, 0);
  749. }
  750. static void planar_rgb14be_to_uv(uint8_t *dstU, uint8_t *dstV,
  751. const uint8_t *src[4], int w)
  752. {
  753. planar_rgb16_to_uv(dstU, dstV, src, w, 14, 1);
  754. }
  755. static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
  756. const uint8_t *src[4], int w)
  757. {
  758. planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
  759. }
  760. static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
  761. const uint8_t *src[4], int w)
  762. {
  763. planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
  764. }
  765. av_cold void ff_sws_init_input_funcs(SwsContext *c)
  766. {
  767. enum PixelFormat srcFormat = c->srcFormat;
  768. c->chrToYV12 = NULL;
  769. switch (srcFormat) {
  770. case PIX_FMT_YUYV422:
  771. c->chrToYV12 = yuy2ToUV_c;
  772. break;
  773. case PIX_FMT_UYVY422:
  774. c->chrToYV12 = uyvyToUV_c;
  775. break;
  776. case PIX_FMT_NV12:
  777. c->chrToYV12 = nv12ToUV_c;
  778. break;
  779. case PIX_FMT_NV21:
  780. c->chrToYV12 = nv21ToUV_c;
  781. break;
  782. case PIX_FMT_RGB8:
  783. case PIX_FMT_BGR8:
  784. case PIX_FMT_PAL8:
  785. case PIX_FMT_BGR4_BYTE:
  786. case PIX_FMT_RGB4_BYTE:
  787. c->chrToYV12 = palToUV_c;
  788. break;
  789. case PIX_FMT_GBRP9LE:
  790. c->readChrPlanar = planar_rgb9le_to_uv;
  791. break;
  792. case PIX_FMT_GBRP10LE:
  793. c->readChrPlanar = planar_rgb10le_to_uv;
  794. break;
  795. case PIX_FMT_GBRP12LE:
  796. c->readChrPlanar = planar_rgb12le_to_uv;
  797. break;
  798. case PIX_FMT_GBRP14LE:
  799. c->readChrPlanar = planar_rgb14le_to_uv;
  800. break;
  801. case PIX_FMT_GBRP16LE:
  802. c->readChrPlanar = planar_rgb16le_to_uv;
  803. break;
  804. case PIX_FMT_GBRP9BE:
  805. c->readChrPlanar = planar_rgb9be_to_uv;
  806. break;
  807. case PIX_FMT_GBRP10BE:
  808. c->readChrPlanar = planar_rgb10be_to_uv;
  809. break;
  810. case PIX_FMT_GBRP12BE:
  811. c->readChrPlanar = planar_rgb12be_to_uv;
  812. break;
  813. case PIX_FMT_GBRP14BE:
  814. c->readChrPlanar = planar_rgb14be_to_uv;
  815. break;
  816. case PIX_FMT_GBRP16BE:
  817. c->readChrPlanar = planar_rgb16be_to_uv;
  818. break;
  819. case PIX_FMT_GBRP:
  820. c->readChrPlanar = planar_rgb_to_uv;
  821. break;
  822. #if HAVE_BIGENDIAN
  823. case PIX_FMT_YUV444P9LE:
  824. case PIX_FMT_YUV422P9LE:
  825. case PIX_FMT_YUV420P9LE:
  826. case PIX_FMT_YUV422P10LE:
  827. case PIX_FMT_YUV444P10LE:
  828. case PIX_FMT_YUV420P10LE:
  829. case PIX_FMT_YUV422P12LE:
  830. case PIX_FMT_YUV444P12LE:
  831. case PIX_FMT_YUV420P12LE:
  832. case PIX_FMT_YUV422P14LE:
  833. case PIX_FMT_YUV444P14LE:
  834. case PIX_FMT_YUV420P14LE:
  835. case PIX_FMT_YUV420P16LE:
  836. case PIX_FMT_YUV422P16LE:
  837. case PIX_FMT_YUV444P16LE:
  838. c->chrToYV12 = bswap16UV_c;
  839. break;
  840. #else
  841. case PIX_FMT_YUV444P9BE:
  842. case PIX_FMT_YUV422P9BE:
  843. case PIX_FMT_YUV420P9BE:
  844. case PIX_FMT_YUV444P10BE:
  845. case PIX_FMT_YUV422P10BE:
  846. case PIX_FMT_YUV420P10BE:
  847. case PIX_FMT_YUV444P12BE:
  848. case PIX_FMT_YUV422P12BE:
  849. case PIX_FMT_YUV420P12BE:
  850. case PIX_FMT_YUV444P14BE:
  851. case PIX_FMT_YUV422P14BE:
  852. case PIX_FMT_YUV420P14BE:
  853. case PIX_FMT_YUV420P16BE:
  854. case PIX_FMT_YUV422P16BE:
  855. case PIX_FMT_YUV444P16BE:
  856. c->chrToYV12 = bswap16UV_c;
  857. break;
  858. #endif
  859. }
  860. if (c->chrSrcHSubSample) {
  861. switch (srcFormat) {
  862. case PIX_FMT_RGBA64BE:
  863. c->chrToYV12 = rgb64BEToUV_half_c;
  864. break;
  865. case PIX_FMT_RGBA64LE:
  866. c->chrToYV12 = rgb64LEToUV_half_c;
  867. break;
  868. case PIX_FMT_RGB48BE:
  869. c->chrToYV12 = rgb48BEToUV_half_c;
  870. break;
  871. case PIX_FMT_RGB48LE:
  872. c->chrToYV12 = rgb48LEToUV_half_c;
  873. break;
  874. case PIX_FMT_BGR48BE:
  875. c->chrToYV12 = bgr48BEToUV_half_c;
  876. break;
  877. case PIX_FMT_BGR48LE:
  878. c->chrToYV12 = bgr48LEToUV_half_c;
  879. break;
  880. case PIX_FMT_RGB32:
  881. c->chrToYV12 = bgr32ToUV_half_c;
  882. break;
  883. case PIX_FMT_RGB32_1:
  884. c->chrToYV12 = bgr321ToUV_half_c;
  885. break;
  886. case PIX_FMT_BGR24:
  887. c->chrToYV12 = bgr24ToUV_half_c;
  888. break;
  889. case PIX_FMT_BGR565LE:
  890. c->chrToYV12 = bgr16leToUV_half_c;
  891. break;
  892. case PIX_FMT_BGR565BE:
  893. c->chrToYV12 = bgr16beToUV_half_c;
  894. break;
  895. case PIX_FMT_BGR555LE:
  896. c->chrToYV12 = bgr15leToUV_half_c;
  897. break;
  898. case PIX_FMT_BGR555BE:
  899. c->chrToYV12 = bgr15beToUV_half_c;
  900. break;
  901. case PIX_FMT_GBR24P :
  902. c->chrToYV12 = gbr24pToUV_half_c;
  903. break;
  904. case PIX_FMT_BGR444LE:
  905. c->chrToYV12 = bgr12leToUV_half_c;
  906. break;
  907. case PIX_FMT_BGR444BE:
  908. c->chrToYV12 = bgr12beToUV_half_c;
  909. break;
  910. case PIX_FMT_BGR32:
  911. c->chrToYV12 = rgb32ToUV_half_c;
  912. break;
  913. case PIX_FMT_BGR32_1:
  914. c->chrToYV12 = rgb321ToUV_half_c;
  915. break;
  916. case PIX_FMT_RGB24:
  917. c->chrToYV12 = rgb24ToUV_half_c;
  918. break;
  919. case PIX_FMT_RGB565LE:
  920. c->chrToYV12 = rgb16leToUV_half_c;
  921. break;
  922. case PIX_FMT_RGB565BE:
  923. c->chrToYV12 = rgb16beToUV_half_c;
  924. break;
  925. case PIX_FMT_RGB555LE:
  926. c->chrToYV12 = rgb15leToUV_half_c;
  927. break;
  928. case PIX_FMT_RGB555BE:
  929. c->chrToYV12 = rgb15beToUV_half_c;
  930. break;
  931. case PIX_FMT_RGB444LE:
  932. c->chrToYV12 = rgb12leToUV_half_c;
  933. break;
  934. case PIX_FMT_RGB444BE:
  935. c->chrToYV12 = rgb12beToUV_half_c;
  936. break;
  937. }
  938. } else {
  939. switch (srcFormat) {
  940. case PIX_FMT_RGBA64BE:
  941. c->chrToYV12 = rgb64BEToUV_c;
  942. break;
  943. case PIX_FMT_RGBA64LE:
  944. c->chrToYV12 = rgb64LEToUV_c;
  945. break;
  946. case PIX_FMT_RGB48BE:
  947. c->chrToYV12 = rgb48BEToUV_c;
  948. break;
  949. case PIX_FMT_RGB48LE:
  950. c->chrToYV12 = rgb48LEToUV_c;
  951. break;
  952. case PIX_FMT_BGR48BE:
  953. c->chrToYV12 = bgr48BEToUV_c;
  954. break;
  955. case PIX_FMT_BGR48LE:
  956. c->chrToYV12 = bgr48LEToUV_c;
  957. break;
  958. case PIX_FMT_RGB32:
  959. c->chrToYV12 = bgr32ToUV_c;
  960. break;
  961. case PIX_FMT_RGB32_1:
  962. c->chrToYV12 = bgr321ToUV_c;
  963. break;
  964. case PIX_FMT_BGR24:
  965. c->chrToYV12 = bgr24ToUV_c;
  966. break;
  967. case PIX_FMT_BGR565LE:
  968. c->chrToYV12 = bgr16leToUV_c;
  969. break;
  970. case PIX_FMT_BGR565BE:
  971. c->chrToYV12 = bgr16beToUV_c;
  972. break;
  973. case PIX_FMT_BGR555LE:
  974. c->chrToYV12 = bgr15leToUV_c;
  975. break;
  976. case PIX_FMT_BGR555BE:
  977. c->chrToYV12 = bgr15beToUV_c;
  978. break;
  979. case PIX_FMT_BGR444LE:
  980. c->chrToYV12 = bgr12leToUV_c;
  981. break;
  982. case PIX_FMT_BGR444BE:
  983. c->chrToYV12 = bgr12beToUV_c;
  984. break;
  985. case PIX_FMT_BGR32:
  986. c->chrToYV12 = rgb32ToUV_c;
  987. break;
  988. case PIX_FMT_BGR32_1:
  989. c->chrToYV12 = rgb321ToUV_c;
  990. break;
  991. case PIX_FMT_RGB24:
  992. c->chrToYV12 = rgb24ToUV_c;
  993. break;
  994. case PIX_FMT_RGB565LE:
  995. c->chrToYV12 = rgb16leToUV_c;
  996. break;
  997. case PIX_FMT_RGB565BE:
  998. c->chrToYV12 = rgb16beToUV_c;
  999. break;
  1000. case PIX_FMT_RGB555LE:
  1001. c->chrToYV12 = rgb15leToUV_c;
  1002. break;
  1003. case PIX_FMT_RGB555BE:
  1004. c->chrToYV12 = rgb15beToUV_c;
  1005. break;
  1006. case PIX_FMT_RGB444LE:
  1007. c->chrToYV12 = rgb12leToUV_c;
  1008. break;
  1009. case PIX_FMT_RGB444BE:
  1010. c->chrToYV12 = rgb12beToUV_c;
  1011. break;
  1012. }
  1013. }
  1014. c->lumToYV12 = NULL;
  1015. c->alpToYV12 = NULL;
  1016. switch (srcFormat) {
  1017. case PIX_FMT_GBRP9LE:
  1018. c->readLumPlanar = planar_rgb9le_to_y;
  1019. break;
  1020. case PIX_FMT_GBRP10LE:
  1021. c->readLumPlanar = planar_rgb10le_to_y;
  1022. break;
  1023. case PIX_FMT_GBRP12LE:
  1024. c->readLumPlanar = planar_rgb12le_to_y;
  1025. break;
  1026. case PIX_FMT_GBRP14LE:
  1027. c->readLumPlanar = planar_rgb14le_to_y;
  1028. break;
  1029. case PIX_FMT_GBRP16LE:
  1030. c->readLumPlanar = planar_rgb16le_to_y;
  1031. break;
  1032. case PIX_FMT_GBRP9BE:
  1033. c->readLumPlanar = planar_rgb9be_to_y;
  1034. break;
  1035. case PIX_FMT_GBRP10BE:
  1036. c->readLumPlanar = planar_rgb10be_to_y;
  1037. break;
  1038. case PIX_FMT_GBRP12BE:
  1039. c->readLumPlanar = planar_rgb12be_to_y;
  1040. break;
  1041. case PIX_FMT_GBRP14BE:
  1042. c->readLumPlanar = planar_rgb14be_to_y;
  1043. break;
  1044. case PIX_FMT_GBRP16BE:
  1045. c->readLumPlanar = planar_rgb16be_to_y;
  1046. break;
  1047. case PIX_FMT_GBRP:
  1048. c->readLumPlanar = planar_rgb_to_y;
  1049. break;
  1050. #if HAVE_BIGENDIAN
  1051. case PIX_FMT_YUV444P9LE:
  1052. case PIX_FMT_YUV422P9LE:
  1053. case PIX_FMT_YUV420P9LE:
  1054. case PIX_FMT_YUV444P10LE:
  1055. case PIX_FMT_YUV422P10LE:
  1056. case PIX_FMT_YUV420P10LE:
  1057. case PIX_FMT_YUV444P12LE:
  1058. case PIX_FMT_YUV422P12LE:
  1059. case PIX_FMT_YUV420P12LE:
  1060. case PIX_FMT_YUV444P14LE:
  1061. case PIX_FMT_YUV422P14LE:
  1062. case PIX_FMT_YUV420P14LE:
  1063. case PIX_FMT_YUV420P16LE:
  1064. case PIX_FMT_YUV422P16LE:
  1065. case PIX_FMT_YUV444P16LE:
  1066. case PIX_FMT_GRAY16LE:
  1067. c->lumToYV12 = bswap16Y_c;
  1068. break;
  1069. #else
  1070. case PIX_FMT_YUV444P9BE:
  1071. case PIX_FMT_YUV422P9BE:
  1072. case PIX_FMT_YUV420P9BE:
  1073. case PIX_FMT_YUV444P10BE:
  1074. case PIX_FMT_YUV422P10BE:
  1075. case PIX_FMT_YUV420P10BE:
  1076. case PIX_FMT_YUV444P12BE:
  1077. case PIX_FMT_YUV422P12BE:
  1078. case PIX_FMT_YUV420P12BE:
  1079. case PIX_FMT_YUV444P14BE:
  1080. case PIX_FMT_YUV422P14BE:
  1081. case PIX_FMT_YUV420P14BE:
  1082. case PIX_FMT_YUV420P16BE:
  1083. case PIX_FMT_YUV422P16BE:
  1084. case PIX_FMT_YUV444P16BE:
  1085. case PIX_FMT_GRAY16BE:
  1086. c->lumToYV12 = bswap16Y_c;
  1087. break;
  1088. #endif
  1089. case PIX_FMT_YUYV422:
  1090. case PIX_FMT_Y400A:
  1091. c->lumToYV12 = yuy2ToY_c;
  1092. break;
  1093. case PIX_FMT_UYVY422:
  1094. c->lumToYV12 = uyvyToY_c;
  1095. break;
  1096. case PIX_FMT_BGR24:
  1097. c->lumToYV12 = bgr24ToY_c;
  1098. break;
  1099. case PIX_FMT_BGR565LE:
  1100. c->lumToYV12 = bgr16leToY_c;
  1101. break;
  1102. case PIX_FMT_BGR565BE:
  1103. c->lumToYV12 = bgr16beToY_c;
  1104. break;
  1105. case PIX_FMT_BGR555LE:
  1106. c->lumToYV12 = bgr15leToY_c;
  1107. break;
  1108. case PIX_FMT_BGR555BE:
  1109. c->lumToYV12 = bgr15beToY_c;
  1110. break;
  1111. case PIX_FMT_BGR444LE:
  1112. c->lumToYV12 = bgr12leToY_c;
  1113. break;
  1114. case PIX_FMT_BGR444BE:
  1115. c->lumToYV12 = bgr12beToY_c;
  1116. break;
  1117. case PIX_FMT_RGB24:
  1118. c->lumToYV12 = rgb24ToY_c;
  1119. break;
  1120. case PIX_FMT_RGB565LE:
  1121. c->lumToYV12 = rgb16leToY_c;
  1122. break;
  1123. case PIX_FMT_RGB565BE:
  1124. c->lumToYV12 = rgb16beToY_c;
  1125. break;
  1126. case PIX_FMT_RGB555LE:
  1127. c->lumToYV12 = rgb15leToY_c;
  1128. break;
  1129. case PIX_FMT_RGB555BE:
  1130. c->lumToYV12 = rgb15beToY_c;
  1131. break;
  1132. case PIX_FMT_RGB444LE:
  1133. c->lumToYV12 = rgb12leToY_c;
  1134. break;
  1135. case PIX_FMT_RGB444BE:
  1136. c->lumToYV12 = rgb12beToY_c;
  1137. break;
  1138. case PIX_FMT_RGB8:
  1139. case PIX_FMT_BGR8:
  1140. case PIX_FMT_PAL8:
  1141. case PIX_FMT_BGR4_BYTE:
  1142. case PIX_FMT_RGB4_BYTE:
  1143. c->lumToYV12 = palToY_c;
  1144. break;
  1145. case PIX_FMT_MONOBLACK:
  1146. c->lumToYV12 = monoblack2Y_c;
  1147. break;
  1148. case PIX_FMT_MONOWHITE:
  1149. c->lumToYV12 = monowhite2Y_c;
  1150. break;
  1151. case PIX_FMT_RGB32:
  1152. c->lumToYV12 = bgr32ToY_c;
  1153. break;
  1154. case PIX_FMT_RGB32_1:
  1155. c->lumToYV12 = bgr321ToY_c;
  1156. break;
  1157. case PIX_FMT_BGR32:
  1158. c->lumToYV12 = rgb32ToY_c;
  1159. break;
  1160. case PIX_FMT_BGR32_1:
  1161. c->lumToYV12 = rgb321ToY_c;
  1162. break;
  1163. case PIX_FMT_RGB48BE:
  1164. c->lumToYV12 = rgb48BEToY_c;
  1165. break;
  1166. case PIX_FMT_RGB48LE:
  1167. c->lumToYV12 = rgb48LEToY_c;
  1168. break;
  1169. case PIX_FMT_BGR48BE:
  1170. c->lumToYV12 = bgr48BEToY_c;
  1171. break;
  1172. case PIX_FMT_BGR48LE:
  1173. c->lumToYV12 = bgr48LEToY_c;
  1174. break;
  1175. case PIX_FMT_RGBA64BE:
  1176. c->lumToYV12 = rgb64BEToY_c;
  1177. break;
  1178. case PIX_FMT_RGBA64LE:
  1179. c->lumToYV12 = rgb64LEToY_c;
  1180. break;
  1181. }
  1182. if (c->alpPixBuf) {
  1183. switch (srcFormat) {
  1184. case PIX_FMT_RGBA64LE:
  1185. case PIX_FMT_RGBA64BE: c->alpToYV12 = rgba64ToA_c; break;
  1186. case PIX_FMT_BGRA:
  1187. case PIX_FMT_RGBA:
  1188. c->alpToYV12 = rgbaToA_c;
  1189. break;
  1190. case PIX_FMT_ABGR:
  1191. case PIX_FMT_ARGB:
  1192. c->alpToYV12 = abgrToA_c;
  1193. break;
  1194. case PIX_FMT_Y400A:
  1195. c->alpToYV12 = uyvyToY_c;
  1196. break;
  1197. case PIX_FMT_PAL8 :
  1198. c->alpToYV12 = palToA_c;
  1199. break;
  1200. }
  1201. }
  1202. }