You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

946 lines
39KB

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