swscale_template.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. static inline void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
  21. const int16_t **lumSrc, int lumFilterSize,
  22. const int16_t *chrFilter, const int16_t **chrUSrc,
  23. const int16_t **chrVSrc,
  24. int chrFilterSize, const int16_t **alpSrc,
  25. uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
  26. uint8_t *aDest, int dstW, int chrDstW)
  27. {
  28. yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
  29. chrFilter, chrUSrc, chrVSrc, chrFilterSize,
  30. alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW);
  31. }
  32. static inline void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
  33. const int16_t **lumSrc, int lumFilterSize,
  34. const int16_t *chrFilter, const int16_t **chrUSrc,
  35. const int16_t **chrVSrc,
  36. int chrFilterSize, uint8_t *dest, uint8_t *uDest,
  37. int dstW, int chrDstW, enum PixelFormat dstFormat)
  38. {
  39. yuv2nv12XinC(lumFilter, lumSrc, lumFilterSize,
  40. chrFilter, chrUSrc, chrVSrc, chrFilterSize,
  41. dest, uDest, dstW, chrDstW, dstFormat);
  42. }
  43. static inline void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
  44. const int16_t *chrUSrc, const int16_t *chrVSrc,
  45. const int16_t *alpSrc,
  46. uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
  47. uint8_t *aDest, int dstW, int chrDstW)
  48. {
  49. int i;
  50. for (i=0; i<dstW; i++) {
  51. int val= (lumSrc[i]+64)>>7;
  52. dest[i]= av_clip_uint8(val);
  53. }
  54. if (uDest)
  55. for (i=0; i<chrDstW; i++) {
  56. int u=(chrUSrc[i]+64)>>7;
  57. int v=(chrVSrc[i]+64)>>7;
  58. uDest[i]= av_clip_uint8(u);
  59. vDest[i]= av_clip_uint8(v);
  60. }
  61. if (CONFIG_SWSCALE_ALPHA && aDest)
  62. for (i=0; i<dstW; i++) {
  63. int val= (alpSrc[i]+64)>>7;
  64. aDest[i]= av_clip_uint8(val);
  65. }
  66. }
  67. /**
  68. * vertical scale YV12 to RGB
  69. */
  70. static inline void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,
  71. const int16_t **lumSrc, int lumFilterSize,
  72. const int16_t *chrFilter, const int16_t **chrUSrc,
  73. const int16_t **chrVSrc,
  74. int chrFilterSize, const int16_t **alpSrc,
  75. uint8_t *dest, int dstW, int dstY)
  76. {
  77. yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize,
  78. chrFilter, chrUSrc, chrVSrc, chrFilterSize,
  79. alpSrc, dest, dstW, dstY);
  80. }
  81. /**
  82. * vertical bilinear scale YV12 to RGB
  83. */
  84. static inline void yuv2packed2_c(SwsContext *c, const uint16_t *buf0,
  85. const uint16_t *buf1, const uint16_t *ubuf0,
  86. const uint16_t *ubuf1, const uint16_t *vbuf0,
  87. const uint16_t *vbuf1, const uint16_t *abuf0,
  88. const uint16_t *abuf1, uint8_t *dest, int dstW,
  89. int yalpha, int uvalpha, int y)
  90. {
  91. int yalpha1=4095- yalpha;
  92. int uvalpha1=4095-uvalpha;
  93. int i;
  94. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C(void,0), YSCALE_YUV_2_GRAY16_2_C, YSCALE_YUV_2_MONO2_C)
  95. }
  96. /**
  97. * YV12 to RGB without scaling or interpolating
  98. */
  99. static inline void yuv2packed1_c(SwsContext *c, const uint16_t *buf0,
  100. const uint16_t *ubuf0, const uint16_t *ubuf1,
  101. const uint16_t *vbuf0, const uint16_t *vbuf1,
  102. const uint16_t *abuf0, uint8_t *dest, int dstW,
  103. int uvalpha, enum PixelFormat dstFormat,
  104. int flags, int y)
  105. {
  106. const int yalpha1=0;
  107. int i;
  108. const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
  109. const int yalpha= 4096; //FIXME ...
  110. if (uvalpha < 2048) {
  111. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C)
  112. } else {
  113. YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C)
  114. }
  115. }
  116. //FIXME yuy2* can read up to 7 samples too much
  117. static inline void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
  118. uint32_t *unused)
  119. {
  120. int i;
  121. for (i=0; i<width; i++)
  122. dst[i]= src[2*i];
  123. }
  124. static inline void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  125. const uint8_t *src2, int width, uint32_t *unused)
  126. {
  127. int i;
  128. for (i=0; i<width; i++) {
  129. dstU[i]= src1[4*i + 1];
  130. dstV[i]= src1[4*i + 3];
  131. }
  132. assert(src1 == src2);
  133. }
  134. static inline void LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  135. const uint8_t *src2, int width, uint32_t *unused)
  136. {
  137. int i;
  138. // FIXME I don't think this code is right for YUV444/422, since then h is not subsampled so
  139. // we need to skip each second pixel. Same for BEToUV.
  140. for (i=0; i<width; i++) {
  141. dstU[i]= src1[2*i + 1];
  142. dstV[i]= src2[2*i + 1];
  143. }
  144. }
  145. /* This is almost identical to the previous, end exists only because
  146. * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
  147. static inline void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
  148. uint32_t *unused)
  149. {
  150. int i;
  151. for (i=0; i<width; i++)
  152. dst[i]= src[2*i+1];
  153. }
  154. static inline void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  155. const uint8_t *src2, int width, uint32_t *unused)
  156. {
  157. int i;
  158. for (i=0; i<width; i++) {
  159. dstU[i]= src1[4*i + 0];
  160. dstV[i]= src1[4*i + 2];
  161. }
  162. assert(src1 == src2);
  163. }
  164. static inline void BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  165. const uint8_t *src2, int width, uint32_t *unused)
  166. {
  167. int i;
  168. for (i=0; i<width; i++) {
  169. dstU[i]= src1[2*i];
  170. dstV[i]= src2[2*i];
  171. }
  172. }
  173. static inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
  174. const uint8_t *src, int width)
  175. {
  176. int i;
  177. for (i = 0; i < width; i++) {
  178. dst1[i] = src[2*i+0];
  179. dst2[i] = src[2*i+1];
  180. }
  181. }
  182. static inline void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
  183. const uint8_t *src1, const uint8_t *src2,
  184. int width, uint32_t *unused)
  185. {
  186. nvXXtoUV_c(dstU, dstV, src1, width);
  187. }
  188. static inline void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
  189. const uint8_t *src1, const uint8_t *src2,
  190. int width, uint32_t *unused)
  191. {
  192. nvXXtoUV_c(dstV, dstU, src1, width);
  193. }
  194. // FIXME Maybe dither instead.
  195. #define YUV_NBPS(depth, endianness, rfunc) \
  196. static inline void endianness ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
  197. const uint8_t *_srcU, const uint8_t *_srcV, \
  198. int width, uint32_t *unused) \
  199. { \
  200. int i; \
  201. const uint16_t *srcU = (const uint16_t*)_srcU; \
  202. const uint16_t *srcV = (const uint16_t*)_srcV; \
  203. for (i = 0; i < width; i++) { \
  204. dstU[i] = rfunc(&srcU[i])>>(depth-8); \
  205. dstV[i] = rfunc(&srcV[i])>>(depth-8); \
  206. } \
  207. } \
  208. \
  209. static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint8_t *_srcY, int width, uint32_t *unused) \
  210. { \
  211. int i; \
  212. const uint16_t *srcY = (const uint16_t*)_srcY; \
  213. for (i = 0; i < width; i++) \
  214. dstY[i] = rfunc(&srcY[i])>>(depth-8); \
  215. } \
  216. YUV_NBPS( 9, LE, AV_RL16)
  217. YUV_NBPS( 9, BE, AV_RB16)
  218. YUV_NBPS(10, LE, AV_RL16)
  219. YUV_NBPS(10, BE, AV_RB16)
  220. static inline void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
  221. int width, uint32_t *unused)
  222. {
  223. int i;
  224. for (i=0; i<width; i++) {
  225. int b= src[i*3+0];
  226. int g= src[i*3+1];
  227. int r= src[i*3+2];
  228. dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
  229. }
  230. }
  231. static inline void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  232. const uint8_t *src2, int width, uint32_t *unused)
  233. {
  234. int i;
  235. for (i=0; i<width; i++) {
  236. int b= src1[3*i + 0];
  237. int g= src1[3*i + 1];
  238. int r= src1[3*i + 2];
  239. dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
  240. dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
  241. }
  242. assert(src1 == src2);
  243. }
  244. static inline void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  245. const uint8_t *src2, int width, uint32_t *unused)
  246. {
  247. int i;
  248. for (i=0; i<width; i++) {
  249. int b= src1[6*i + 0] + src1[6*i + 3];
  250. int g= src1[6*i + 1] + src1[6*i + 4];
  251. int r= src1[6*i + 2] + src1[6*i + 5];
  252. dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
  253. dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
  254. }
  255. assert(src1 == src2);
  256. }
  257. static inline void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width,
  258. uint32_t *unused)
  259. {
  260. int i;
  261. for (i=0; i<width; i++) {
  262. int r= src[i*3+0];
  263. int g= src[i*3+1];
  264. int b= src[i*3+2];
  265. dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
  266. }
  267. }
  268. static inline void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  269. const uint8_t *src2, int width, uint32_t *unused)
  270. {
  271. int i;
  272. assert(src1==src2);
  273. for (i=0; i<width; i++) {
  274. int r= src1[3*i + 0];
  275. int g= src1[3*i + 1];
  276. int b= src1[3*i + 2];
  277. dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
  278. dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
  279. }
  280. }
  281. static inline void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
  282. const uint8_t *src2, int width, uint32_t *unused)
  283. {
  284. int i;
  285. assert(src1==src2);
  286. for (i=0; i<width; i++) {
  287. int r= src1[6*i + 0] + src1[6*i + 3];
  288. int g= src1[6*i + 1] + src1[6*i + 4];
  289. int b= src1[6*i + 2] + src1[6*i + 5];
  290. dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
  291. dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
  292. }
  293. }
  294. // bilinear / bicubic scaling
  295. static inline void hScale_c(int16_t *dst, int dstW, const uint8_t *src,
  296. int srcW, int xInc,
  297. const int16_t *filter, const int16_t *filterPos,
  298. int filterSize)
  299. {
  300. int i;
  301. for (i=0; i<dstW; i++) {
  302. int j;
  303. int srcPos= filterPos[i];
  304. int val=0;
  305. for (j=0; j<filterSize; j++) {
  306. val += ((int)src[srcPos + j])*filter[filterSize*i + j];
  307. }
  308. //filter += hFilterSize;
  309. dst[i] = FFMIN(val>>7, (1<<15)-1); // the cubic equation does overflow ...
  310. //dst[i] = val>>7;
  311. }
  312. }
  313. //FIXME all pal and rgb srcFormats could do this convertion as well
  314. //FIXME all scalers more complex than bilinear could do half of this transform
  315. static void chrRangeToJpeg_c(uint16_t *dstU, uint16_t *dstV, int width)
  316. {
  317. int i;
  318. for (i = 0; i < width; i++) {
  319. dstU[i] = (FFMIN(dstU[i],30775)*4663 - 9289992)>>12; //-264
  320. dstV[i] = (FFMIN(dstV[i],30775)*4663 - 9289992)>>12; //-264
  321. }
  322. }
  323. static void chrRangeFromJpeg_c(uint16_t *dstU, uint16_t *dstV, int width)
  324. {
  325. int i;
  326. for (i = 0; i < width; i++) {
  327. dstU[i] = (dstU[i]*1799 + 4081085)>>11; //1469
  328. dstV[i] = (dstV[i]*1799 + 4081085)>>11; //1469
  329. }
  330. }
  331. static void lumRangeToJpeg_c(uint16_t *dst, int width)
  332. {
  333. int i;
  334. for (i = 0; i < width; i++)
  335. dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14;
  336. }
  337. static void lumRangeFromJpeg_c(uint16_t *dst, int width)
  338. {
  339. int i;
  340. for (i = 0; i < width; i++)
  341. dst[i] = (dst[i]*14071 + 33561947)>>14;
  342. }
  343. static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
  344. const uint8_t *src, int srcW, int xInc)
  345. {
  346. int i;
  347. unsigned int xpos=0;
  348. for (i=0;i<dstWidth;i++) {
  349. register unsigned int xx=xpos>>16;
  350. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  351. dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
  352. xpos+=xInc;
  353. }
  354. }
  355. // *** horizontal scale Y line to temp buffer
  356. static inline void hyscale_c(SwsContext *c, uint16_t *dst, int dstWidth,
  357. const uint8_t *src, int srcW, int xInc,
  358. const int16_t *hLumFilter,
  359. const int16_t *hLumFilterPos, int hLumFilterSize,
  360. uint8_t *formatConvBuffer,
  361. uint32_t *pal, int isAlpha)
  362. {
  363. void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
  364. void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
  365. src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset;
  366. if (toYV12) {
  367. toYV12(formatConvBuffer, src, srcW, pal);
  368. src= formatConvBuffer;
  369. }
  370. if (!c->hyscale_fast) {
  371. c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
  372. } else { // fast bilinear upscale / crap downscale
  373. c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
  374. }
  375. if (convertRange)
  376. convertRange(dst, dstWidth);
  377. }
  378. static inline void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
  379. int dstWidth, const uint8_t *src1,
  380. const uint8_t *src2, int srcW, int xInc)
  381. {
  382. int i;
  383. unsigned int xpos=0;
  384. for (i=0;i<dstWidth;i++) {
  385. register unsigned int xx=xpos>>16;
  386. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  387. dst1[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
  388. dst2[i]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
  389. xpos+=xInc;
  390. }
  391. }
  392. inline static void hcscale_c(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
  393. const uint8_t *src1, const uint8_t *src2,
  394. int srcW, int xInc, const int16_t *hChrFilter,
  395. const int16_t *hChrFilterPos, int hChrFilterSize,
  396. uint8_t *formatConvBuffer, uint32_t *pal)
  397. {
  398. src1 += c->chrSrcOffset;
  399. src2 += c->chrSrcOffset;
  400. if (c->chrToYV12) {
  401. uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW, 16);
  402. c->chrToYV12(formatConvBuffer, buf2, src1, src2, srcW, pal);
  403. src1= formatConvBuffer;
  404. src2= buf2;
  405. }
  406. if (!c->hcscale_fast) {
  407. c->hScale(dst1, dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  408. c->hScale(dst2, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
  409. } else { // fast bilinear upscale / crap downscale
  410. c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
  411. }
  412. if (c->chrConvertRange)
  413. c->chrConvertRange(dst1, dst2, dstWidth);
  414. }
  415. #define DEBUG_SWSCALE_BUFFERS 0
  416. #define DEBUG_BUFFERS(...) if (DEBUG_SWSCALE_BUFFERS) av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
  417. static int swScale_c(SwsContext *c, const uint8_t* src[], int srcStride[],
  418. int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[])
  419. {
  420. /* load a few things into local vars to make the code more readable? and faster */
  421. const int srcW= c->srcW;
  422. const int dstW= c->dstW;
  423. const int dstH= c->dstH;
  424. const int chrDstW= c->chrDstW;
  425. const int chrSrcW= c->chrSrcW;
  426. const int lumXInc= c->lumXInc;
  427. const int chrXInc= c->chrXInc;
  428. const enum PixelFormat dstFormat= c->dstFormat;
  429. const int flags= c->flags;
  430. int16_t *vLumFilterPos= c->vLumFilterPos;
  431. int16_t *vChrFilterPos= c->vChrFilterPos;
  432. int16_t *hLumFilterPos= c->hLumFilterPos;
  433. int16_t *hChrFilterPos= c->hChrFilterPos;
  434. int16_t *vLumFilter= c->vLumFilter;
  435. int16_t *vChrFilter= c->vChrFilter;
  436. int16_t *hLumFilter= c->hLumFilter;
  437. int16_t *hChrFilter= c->hChrFilter;
  438. int32_t *lumMmxFilter= c->lumMmxFilter;
  439. int32_t *chrMmxFilter= c->chrMmxFilter;
  440. int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
  441. const int vLumFilterSize= c->vLumFilterSize;
  442. const int vChrFilterSize= c->vChrFilterSize;
  443. const int hLumFilterSize= c->hLumFilterSize;
  444. const int hChrFilterSize= c->hChrFilterSize;
  445. int16_t **lumPixBuf= c->lumPixBuf;
  446. int16_t **chrUPixBuf= c->chrUPixBuf;
  447. int16_t **chrVPixBuf= c->chrVPixBuf;
  448. int16_t **alpPixBuf= c->alpPixBuf;
  449. const int vLumBufSize= c->vLumBufSize;
  450. const int vChrBufSize= c->vChrBufSize;
  451. uint8_t *formatConvBuffer= c->formatConvBuffer;
  452. const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;
  453. const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
  454. int lastDstY;
  455. uint32_t *pal=c->pal_yuv;
  456. /* vars which will change and which we need to store back in the context */
  457. int dstY= c->dstY;
  458. int lumBufIndex= c->lumBufIndex;
  459. int chrBufIndex= c->chrBufIndex;
  460. int lastInLumBuf= c->lastInLumBuf;
  461. int lastInChrBuf= c->lastInChrBuf;
  462. if (isPacked(c->srcFormat)) {
  463. src[0]=
  464. src[1]=
  465. src[2]=
  466. src[3]= src[0];
  467. srcStride[0]=
  468. srcStride[1]=
  469. srcStride[2]=
  470. srcStride[3]= srcStride[0];
  471. }
  472. srcStride[1]<<= c->vChrDrop;
  473. srcStride[2]<<= c->vChrDrop;
  474. DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
  475. src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3],
  476. dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]);
  477. DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
  478. srcSliceY, srcSliceH, dstY, dstH);
  479. DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
  480. vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
  481. if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) {
  482. static int warnedAlready=0; //FIXME move this into the context perhaps
  483. if (flags & SWS_PRINT_INFO && !warnedAlready) {
  484. av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n"
  485. " ->cannot do aligned memory accesses anymore\n");
  486. warnedAlready=1;
  487. }
  488. }
  489. /* Note the user might start scaling the picture in the middle so this
  490. will not get executed. This is not really intended but works
  491. currently, so people might do it. */
  492. if (srcSliceY ==0) {
  493. lumBufIndex=-1;
  494. chrBufIndex=-1;
  495. dstY=0;
  496. lastInLumBuf= -1;
  497. lastInChrBuf= -1;
  498. }
  499. lastDstY= dstY;
  500. for (;dstY < dstH; dstY++) {
  501. unsigned char *dest =dst[0]+dstStride[0]*dstY;
  502. const int chrDstY= dstY>>c->chrDstVSubSample;
  503. unsigned char *uDest=dst[1]+dstStride[1]*chrDstY;
  504. unsigned char *vDest=dst[2]+dstStride[2]*chrDstY;
  505. unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL;
  506. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  507. const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)];
  508. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  509. int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input
  510. int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input
  511. int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input
  512. int enough_lines;
  513. //handle holes (FAST_BILINEAR & weird filters)
  514. if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1;
  515. if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1;
  516. assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
  517. assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
  518. DEBUG_BUFFERS("dstY: %d\n", dstY);
  519. DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
  520. firstLumSrcY, lastLumSrcY, lastInLumBuf);
  521. DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
  522. firstChrSrcY, lastChrSrcY, lastInChrBuf);
  523. // Do we have enough lines in this slice to output the dstY line
  524. enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample);
  525. if (!enough_lines) {
  526. lastLumSrcY = srcSliceY + srcSliceH - 1;
  527. lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
  528. DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
  529. lastLumSrcY, lastChrSrcY);
  530. }
  531. //Do horizontal scaling
  532. while(lastInLumBuf < lastLumSrcY) {
  533. const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
  534. const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3];
  535. lumBufIndex++;
  536. assert(lumBufIndex < 2*vLumBufSize);
  537. assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);
  538. assert(lastInLumBuf + 1 - srcSliceY >= 0);
  539. hyscale_c(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc,
  540. hLumFilter, hLumFilterPos, hLumFilterSize,
  541. formatConvBuffer,
  542. pal, 0);
  543. if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
  544. hyscale_c(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW,
  545. lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
  546. formatConvBuffer,
  547. pal, 1);
  548. lastInLumBuf++;
  549. DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n",
  550. lumBufIndex, lastInLumBuf);
  551. }
  552. while(lastInChrBuf < lastChrSrcY) {
  553. const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
  554. const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2];
  555. chrBufIndex++;
  556. assert(chrBufIndex < 2*vChrBufSize);
  557. assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
  558. assert(lastInChrBuf + 1 - chrSrcSliceY >= 0);
  559. //FIXME replace parameters through context struct (some at least)
  560. if (c->needs_hcscale)
  561. hcscale_c(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
  562. chrDstW, src1, src2, chrSrcW, chrXInc,
  563. hChrFilter, hChrFilterPos, hChrFilterSize,
  564. formatConvBuffer, pal);
  565. lastInChrBuf++;
  566. DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n",
  567. chrBufIndex, lastInChrBuf);
  568. }
  569. //wrap buf index around to stay inside the ring buffer
  570. if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize;
  571. if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize;
  572. if (!enough_lines)
  573. break; //we can't output a dstY line so let's try with the next slice
  574. #if HAVE_MMX
  575. updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);
  576. #endif
  577. if (dstY < dstH-2) {
  578. const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  579. const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  580. const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  581. const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
  582. if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) {
  583. const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
  584. if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi
  585. c->yuv2nv12X(c,
  586. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  587. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  588. dest, uDest, dstW, chrDstW, dstFormat);
  589. } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like
  590. const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
  591. if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
  592. if (is16BPS(dstFormat) || is9_OR_10BPS(dstFormat)) {
  593. yuv2yuvX16inC(vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  594. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr,
  595. chrVSrcPtr, vChrFilterSize,
  596. alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest,
  597. (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW,
  598. dstFormat);
  599. } else if (vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12
  600. const int16_t *lumBuf = lumSrcPtr[0];
  601. const int16_t *chrUBuf= chrUSrcPtr[0];
  602. const int16_t *chrVBuf= chrVSrcPtr[0];
  603. const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL;
  604. c->yuv2yuv1(c, lumBuf, chrUBuf, chrVBuf, alpBuf, dest,
  605. uDest, vDest, aDest, dstW, chrDstW);
  606. } else { //General YV12
  607. c->yuv2yuvX(c,
  608. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  609. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr,
  610. chrVSrcPtr, vChrFilterSize,
  611. alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW);
  612. }
  613. } else {
  614. assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
  615. assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);
  616. if (vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB
  617. int chrAlpha= vChrFilter[2*dstY+1];
  618. if(flags & SWS_FULL_CHR_H_INT) {
  619. yuv2rgbXinC_full(c, //FIXME write a packed1_full function
  620. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  621. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr,
  622. chrVSrcPtr, vChrFilterSize,
  623. alpSrcPtr, dest, dstW, dstY);
  624. } else {
  625. c->yuv2packed1(c, *lumSrcPtr, *chrUSrcPtr, *(chrUSrcPtr+1),
  626. *chrVSrcPtr, *(chrVSrcPtr+1),
  627. alpPixBuf ? *alpSrcPtr : NULL,
  628. dest, dstW, chrAlpha, dstFormat, flags, dstY);
  629. }
  630. } else if (vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB
  631. int lumAlpha= vLumFilter[2*dstY+1];
  632. int chrAlpha= vChrFilter[2*dstY+1];
  633. lumMmxFilter[2]=
  634. lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001;
  635. chrMmxFilter[2]=
  636. chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001;
  637. if(flags & SWS_FULL_CHR_H_INT) {
  638. yuv2rgbXinC_full(c, //FIXME write a packed2_full function
  639. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  640. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  641. alpSrcPtr, dest, dstW, dstY);
  642. } else {
  643. c->yuv2packed2(c, *lumSrcPtr, *(lumSrcPtr+1), *chrUSrcPtr, *(chrUSrcPtr+1),
  644. *chrVSrcPtr, *(chrVSrcPtr+1),
  645. alpPixBuf ? *alpSrcPtr : NULL, alpPixBuf ? *(alpSrcPtr+1) : NULL,
  646. dest, dstW, lumAlpha, chrAlpha, dstY);
  647. }
  648. } else { //general RGB
  649. if(flags & SWS_FULL_CHR_H_INT) {
  650. yuv2rgbXinC_full(c,
  651. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  652. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  653. alpSrcPtr, dest, dstW, dstY);
  654. } else {
  655. c->yuv2packedX(c,
  656. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  657. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  658. alpSrcPtr, dest, dstW, dstY);
  659. }
  660. }
  661. }
  662. } else { // hmm looks like we can't use MMX here without overwriting this array's tail
  663. const int16_t **lumSrcPtr= (const int16_t **)lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  664. const int16_t **chrUSrcPtr= (const int16_t **)chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  665. const int16_t **chrVSrcPtr= (const int16_t **)chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  666. const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
  667. if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) {
  668. const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
  669. if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi
  670. yuv2nv12XinC(
  671. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  672. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  673. dest, uDest, dstW, chrDstW, dstFormat);
  674. } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12
  675. const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
  676. if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
  677. if (is16BPS(dstFormat) || is9_OR_10BPS(dstFormat)) {
  678. yuv2yuvX16inC(
  679. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  680. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  681. alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW,
  682. dstFormat);
  683. } else {
  684. yuv2yuvXinC(
  685. vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize,
  686. vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  687. alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW);
  688. }
  689. } else {
  690. assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2);
  691. assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);
  692. if(flags & SWS_FULL_CHR_H_INT) {
  693. yuv2rgbXinC_full(c,
  694. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  695. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  696. alpSrcPtr, dest, dstW, dstY);
  697. } else {
  698. yuv2packedXinC(c,
  699. vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
  700. vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
  701. alpSrcPtr, dest, dstW, dstY);
  702. }
  703. }
  704. }
  705. }
  706. if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf)
  707. fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255);
  708. #if HAVE_MMX2
  709. if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)
  710. __asm__ volatile("sfence":::"memory");
  711. #endif
  712. emms_c();
  713. /* store changed local vars back in the context */
  714. c->dstY= dstY;
  715. c->lumBufIndex= lumBufIndex;
  716. c->chrBufIndex= chrBufIndex;
  717. c->lastInLumBuf= lastInLumBuf;
  718. c->lastInChrBuf= lastInChrBuf;
  719. return dstY - lastDstY;
  720. }
  721. static void sws_init_swScale_c(SwsContext *c)
  722. {
  723. enum PixelFormat srcFormat = c->srcFormat;
  724. c->yuv2nv12X = yuv2nv12X_c;
  725. c->yuv2yuv1 = yuv2yuv1_c;
  726. c->yuv2yuvX = yuv2yuvX_c;
  727. c->yuv2packed1 = yuv2packed1_c;
  728. c->yuv2packed2 = yuv2packed2_c;
  729. c->yuv2packedX = yuv2packedX_c;
  730. c->hScale = hScale_c;
  731. if (c->flags & SWS_FAST_BILINEAR)
  732. {
  733. c->hyscale_fast = hyscale_fast_c;
  734. c->hcscale_fast = hcscale_fast_c;
  735. }
  736. c->chrToYV12 = NULL;
  737. switch(srcFormat) {
  738. case PIX_FMT_YUYV422 : c->chrToYV12 = yuy2ToUV_c; break;
  739. case PIX_FMT_UYVY422 : c->chrToYV12 = uyvyToUV_c; break;
  740. case PIX_FMT_NV12 : c->chrToYV12 = nv12ToUV_c; break;
  741. case PIX_FMT_NV21 : c->chrToYV12 = nv21ToUV_c; break;
  742. case PIX_FMT_RGB8 :
  743. case PIX_FMT_BGR8 :
  744. case PIX_FMT_PAL8 :
  745. case PIX_FMT_BGR4_BYTE:
  746. case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV; break;
  747. case PIX_FMT_YUV420P9BE: c->chrToYV12 = BE9ToUV_c; break;
  748. case PIX_FMT_YUV420P9LE: c->chrToYV12 = LE9ToUV_c; break;
  749. case PIX_FMT_YUV420P10BE: c->chrToYV12 = BE10ToUV_c; break;
  750. case PIX_FMT_YUV420P10LE: c->chrToYV12 = LE10ToUV_c; break;
  751. case PIX_FMT_YUV420P16BE:
  752. case PIX_FMT_YUV422P16BE:
  753. case PIX_FMT_YUV444P16BE: c->chrToYV12 = BEToUV_c; break;
  754. case PIX_FMT_YUV420P16LE:
  755. case PIX_FMT_YUV422P16LE:
  756. case PIX_FMT_YUV444P16LE: c->chrToYV12 = LEToUV_c; break;
  757. }
  758. if (c->chrSrcHSubSample) {
  759. switch(srcFormat) {
  760. case PIX_FMT_RGB48BE:
  761. case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break;
  762. case PIX_FMT_BGR48BE:
  763. case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV_half; break;
  764. case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half; break;
  765. case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV_half; break;
  766. case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_half_c; break;
  767. case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV_half; break;
  768. case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV_half; break;
  769. case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half; break;
  770. case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV_half; break;
  771. case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_half_c; break;
  772. case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV_half; break;
  773. case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV_half; break;
  774. }
  775. } else {
  776. switch(srcFormat) {
  777. case PIX_FMT_RGB48BE:
  778. case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break;
  779. case PIX_FMT_BGR48BE:
  780. case PIX_FMT_BGR48LE: c->chrToYV12 = bgr48ToUV; break;
  781. case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV; break;
  782. case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV; break;
  783. case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_c; break;
  784. case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV; break;
  785. case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV; break;
  786. case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV; break;
  787. case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV; break;
  788. case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_c; break;
  789. case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV; break;
  790. case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV; break;
  791. }
  792. }
  793. c->lumToYV12 = NULL;
  794. c->alpToYV12 = NULL;
  795. switch (srcFormat) {
  796. case PIX_FMT_YUV420P9BE: c->lumToYV12 = BE9ToY_c; break;
  797. case PIX_FMT_YUV420P9LE: c->lumToYV12 = LE9ToY_c; break;
  798. case PIX_FMT_YUV420P10BE: c->lumToYV12 = BE10ToY_c; break;
  799. case PIX_FMT_YUV420P10LE: c->lumToYV12 = LE10ToY_c; break;
  800. case PIX_FMT_YUYV422 :
  801. case PIX_FMT_YUV420P16BE:
  802. case PIX_FMT_YUV422P16BE:
  803. case PIX_FMT_YUV444P16BE:
  804. case PIX_FMT_Y400A :
  805. case PIX_FMT_GRAY16BE : c->lumToYV12 = yuy2ToY_c; break;
  806. case PIX_FMT_UYVY422 :
  807. case PIX_FMT_YUV420P16LE:
  808. case PIX_FMT_YUV422P16LE:
  809. case PIX_FMT_YUV444P16LE:
  810. case PIX_FMT_GRAY16LE : c->lumToYV12 = uyvyToY_c; break;
  811. case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break;
  812. case PIX_FMT_BGR565 : c->lumToYV12 = bgr16ToY; break;
  813. case PIX_FMT_BGR555 : c->lumToYV12 = bgr15ToY; break;
  814. case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break;
  815. case PIX_FMT_RGB565 : c->lumToYV12 = rgb16ToY; break;
  816. case PIX_FMT_RGB555 : c->lumToYV12 = rgb15ToY; break;
  817. case PIX_FMT_RGB8 :
  818. case PIX_FMT_BGR8 :
  819. case PIX_FMT_PAL8 :
  820. case PIX_FMT_BGR4_BYTE:
  821. case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY; break;
  822. case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y; break;
  823. case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y; break;
  824. case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY; break;
  825. case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY; break;
  826. case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY; break;
  827. case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY; break;
  828. case PIX_FMT_RGB48BE:
  829. case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48ToY; break;
  830. case PIX_FMT_BGR48BE:
  831. case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48ToY; break;
  832. }
  833. if (c->alpPixBuf) {
  834. switch (srcFormat) {
  835. case PIX_FMT_RGB32 :
  836. case PIX_FMT_RGB32_1:
  837. case PIX_FMT_BGR32 :
  838. case PIX_FMT_BGR32_1: c->alpToYV12 = abgrToA; break;
  839. case PIX_FMT_Y400A : c->alpToYV12 = yuy2ToY_c; break;
  840. }
  841. }
  842. switch (srcFormat) {
  843. case PIX_FMT_Y400A :
  844. c->alpSrcOffset = 1;
  845. break;
  846. case PIX_FMT_RGB32 :
  847. case PIX_FMT_BGR32 :
  848. c->alpSrcOffset = 3;
  849. break;
  850. case PIX_FMT_RGB48LE:
  851. case PIX_FMT_BGR48LE:
  852. c->lumSrcOffset = 1;
  853. c->chrSrcOffset = 1;
  854. c->alpSrcOffset = 1;
  855. break;
  856. }
  857. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
  858. if (c->srcRange) {
  859. c->lumConvertRange = lumRangeFromJpeg_c;
  860. c->chrConvertRange = chrRangeFromJpeg_c;
  861. } else {
  862. c->lumConvertRange = lumRangeToJpeg_c;
  863. c->chrConvertRange = chrRangeToJpeg_c;
  864. }
  865. }
  866. if (!(isGray(srcFormat) || isGray(c->dstFormat) ||
  867. srcFormat == PIX_FMT_MONOBLACK || srcFormat == PIX_FMT_MONOWHITE))
  868. c->needs_hcscale = 1;
  869. }