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.

1159 lines
45KB

  1. /*
  2. Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
  3. AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. /**
  17. * @file postprocess.c
  18. * postprocessing.
  19. */
  20. /*
  21. C MMX MMX2 3DNow AltiVec
  22. isVertDC Ec Ec Ec
  23. isVertMinMaxOk Ec Ec Ec
  24. doVertLowPass E e e Ec
  25. doVertDefFilter Ec Ec e e Ec
  26. isHorizDC Ec Ec Ec
  27. isHorizMinMaxOk a E Ec
  28. doHorizLowPass E e e Ec
  29. doHorizDefFilter Ec Ec e e Ec
  30. do_a_deblock Ec E Ec E
  31. deRing E e e* Ecp
  32. Vertical RKAlgo1 E a a
  33. Horizontal RKAlgo1 a a
  34. Vertical X1# a E E
  35. Horizontal X1# a E E
  36. LinIpolDeinterlace e E E*
  37. CubicIpolDeinterlace a e e*
  38. LinBlendDeinterlace e E E*
  39. MedianDeinterlace# E Ec Ec
  40. TempDeNoiser# E e e Ec
  41. * i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work
  42. # more or less selfinvented filters so the exactness isnt too meaningfull
  43. E = Exact implementation
  44. e = allmost exact implementation (slightly different rounding,...)
  45. a = alternative / approximate impl
  46. c = checked against the other implementations (-vo md5)
  47. p = partially optimized, still some work to do
  48. */
  49. /*
  50. TODO:
  51. reduce the time wasted on the mem transfer
  52. unroll stuff if instructions depend too much on the prior one
  53. move YScale thing to the end instead of fixing QP
  54. write a faster and higher quality deblocking filter :)
  55. make the mainloop more flexible (variable number of blocks at once
  56. (the if/else stuff per block is slowing things down)
  57. compare the quality & speed of all filters
  58. split this huge file
  59. optimize c versions
  60. try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
  61. ...
  62. */
  63. //Changelog: use the Subversion log
  64. #include "config.h"
  65. #include <inttypes.h>
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <string.h>
  69. #ifdef HAVE_MALLOC_H
  70. #include <malloc.h>
  71. #endif
  72. //#undef HAVE_MMX2
  73. //#define HAVE_3DNOW
  74. //#undef HAVE_MMX
  75. //#undef ARCH_X86
  76. //#define DEBUG_BRIGHTNESS
  77. #ifdef USE_FASTMEMCPY
  78. #include "fastmemcpy.h"
  79. #endif
  80. #include "postprocess.h"
  81. #include "postprocess_internal.h"
  82. #include "mangle.h" //FIXME should be supressed
  83. #ifdef HAVE_ALTIVEC_H
  84. #include <altivec.h>
  85. #endif
  86. #ifndef HAVE_MEMALIGN
  87. #define memalign(a,b) malloc(b)
  88. #endif
  89. #define MIN(a,b) ((a) > (b) ? (b) : (a))
  90. #define MAX(a,b) ((a) < (b) ? (b) : (a))
  91. #define ABS(a) ((a) > 0 ? (a) : (-(a)))
  92. #define SIGN(a) ((a) > 0 ? 1 : -1)
  93. #define GET_MODE_BUFFER_SIZE 500
  94. #define OPTIONS_ARRAY_SIZE 10
  95. #define BLOCK_SIZE 8
  96. #define TEMP_STRIDE 8
  97. //#define NUM_BLOCKS_AT_ONCE 16 //not used yet
  98. #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
  99. # define attribute_used __attribute__((used))
  100. # define always_inline __attribute__((always_inline)) inline
  101. #else
  102. # define attribute_used
  103. # define always_inline inline
  104. #endif
  105. #if defined(ARCH_X86) || defined(ARCH_X86_64)
  106. static uint64_t __attribute__((aligned(8))) attribute_used w05= 0x0005000500050005LL;
  107. static uint64_t __attribute__((aligned(8))) attribute_used w04= 0x0004000400040004LL;
  108. static uint64_t __attribute__((aligned(8))) attribute_used w20= 0x0020002000200020LL;
  109. static uint64_t __attribute__((aligned(8))) attribute_used b00= 0x0000000000000000LL;
  110. static uint64_t __attribute__((aligned(8))) attribute_used b01= 0x0101010101010101LL;
  111. static uint64_t __attribute__((aligned(8))) attribute_used b02= 0x0202020202020202LL;
  112. static uint64_t __attribute__((aligned(8))) attribute_used b08= 0x0808080808080808LL;
  113. static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL;
  114. #endif
  115. static uint8_t clip_table[3*256];
  116. static uint8_t * const clip_tab= clip_table + 256;
  117. static const int verbose= 0;
  118. static const int attribute_used deringThreshold= 20;
  119. static struct PPFilter filters[]=
  120. {
  121. {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
  122. {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
  123. /* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER},
  124. {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/
  125. {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER},
  126. {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER},
  127. {"ha", "ahdeblock", 1, 1, 3, H_A_DEBLOCK},
  128. {"va", "avdeblock", 1, 2, 4, V_A_DEBLOCK},
  129. {"dr", "dering", 1, 5, 6, DERING},
  130. {"al", "autolevels", 0, 1, 2, LEVEL_FIX},
  131. {"lb", "linblenddeint", 1, 1, 4, LINEAR_BLEND_DEINT_FILTER},
  132. {"li", "linipoldeint", 1, 1, 4, LINEAR_IPOL_DEINT_FILTER},
  133. {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER},
  134. {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER},
  135. {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER},
  136. {"l5", "lowpass5", 1, 1, 4, LOWPASS5_DEINT_FILTER},
  137. {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER},
  138. {"fq", "forcequant", 1, 0, 0, FORCE_QUANT},
  139. {NULL, NULL,0,0,0,0} //End Marker
  140. };
  141. static const char *replaceTable[]=
  142. {
  143. "default", "hdeblock:a,vdeblock:a,dering:a",
  144. "de", "hdeblock:a,vdeblock:a,dering:a",
  145. "fast", "x1hdeblock:a,x1vdeblock:a,dering:a",
  146. "fa", "x1hdeblock:a,x1vdeblock:a,dering:a",
  147. "ac", "ha:a:128:7,va:a,dering:a",
  148. NULL //End Marker
  149. };
  150. #if defined(ARCH_X86) || defined(ARCH_X86_64)
  151. static inline void prefetchnta(void *p)
  152. {
  153. asm volatile( "prefetchnta (%0)\n\t"
  154. : : "r" (p)
  155. );
  156. }
  157. static inline void prefetcht0(void *p)
  158. {
  159. asm volatile( "prefetcht0 (%0)\n\t"
  160. : : "r" (p)
  161. );
  162. }
  163. static inline void prefetcht1(void *p)
  164. {
  165. asm volatile( "prefetcht1 (%0)\n\t"
  166. : : "r" (p)
  167. );
  168. }
  169. static inline void prefetcht2(void *p)
  170. {
  171. asm volatile( "prefetcht2 (%0)\n\t"
  172. : : "r" (p)
  173. );
  174. }
  175. #endif
  176. // The horizontal Functions exist only in C cuz the MMX code is faster with vertical filters and transposing
  177. /**
  178. * Check if the given 8x8 Block is mostly "flat"
  179. */
  180. static inline int isHorizDC_C(uint8_t src[], int stride, PPContext *c)
  181. {
  182. int numEq= 0;
  183. int y;
  184. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  185. const int dcThreshold= dcOffset*2 + 1;
  186. for(y=0; y<BLOCK_SIZE; y++)
  187. {
  188. if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++;
  189. if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++;
  190. if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++;
  191. if(((unsigned)(src[3] - src[4] + dcOffset)) < dcThreshold) numEq++;
  192. if(((unsigned)(src[4] - src[5] + dcOffset)) < dcThreshold) numEq++;
  193. if(((unsigned)(src[5] - src[6] + dcOffset)) < dcThreshold) numEq++;
  194. if(((unsigned)(src[6] - src[7] + dcOffset)) < dcThreshold) numEq++;
  195. src+= stride;
  196. }
  197. return numEq > c->ppMode.flatnessThreshold;
  198. }
  199. /**
  200. * Check if the middle 8x8 Block in the given 8x16 block is flat
  201. */
  202. static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){
  203. int numEq= 0;
  204. int y;
  205. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  206. const int dcThreshold= dcOffset*2 + 1;
  207. src+= stride*4; // src points to begin of the 8x8 Block
  208. for(y=0; y<BLOCK_SIZE-1; y++)
  209. {
  210. if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++;
  211. if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++;
  212. if(((unsigned)(src[2] - src[2+stride] + dcOffset)) < dcThreshold) numEq++;
  213. if(((unsigned)(src[3] - src[3+stride] + dcOffset)) < dcThreshold) numEq++;
  214. if(((unsigned)(src[4] - src[4+stride] + dcOffset)) < dcThreshold) numEq++;
  215. if(((unsigned)(src[5] - src[5+stride] + dcOffset)) < dcThreshold) numEq++;
  216. if(((unsigned)(src[6] - src[6+stride] + dcOffset)) < dcThreshold) numEq++;
  217. if(((unsigned)(src[7] - src[7+stride] + dcOffset)) < dcThreshold) numEq++;
  218. src+= stride;
  219. }
  220. return numEq > c->ppMode.flatnessThreshold;
  221. }
  222. static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
  223. {
  224. int i;
  225. #if 1
  226. for(i=0; i<2; i++){
  227. if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
  228. src += stride;
  229. if((unsigned)(src[2] - src[7] + 2*QP) > 4*QP) return 0;
  230. src += stride;
  231. if((unsigned)(src[4] - src[1] + 2*QP) > 4*QP) return 0;
  232. src += stride;
  233. if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
  234. src += stride;
  235. }
  236. #else
  237. for(i=0; i<8; i++){
  238. if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0;
  239. src += stride;
  240. }
  241. #endif
  242. return 1;
  243. }
  244. static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
  245. {
  246. #if 1
  247. #if 1
  248. int x;
  249. src+= stride*4;
  250. for(x=0; x<BLOCK_SIZE; x+=4)
  251. {
  252. if((unsigned)(src[ x + 0*stride] - src[ x + 5*stride] + 2*QP) > 4*QP) return 0;
  253. if((unsigned)(src[1+x + 2*stride] - src[1+x + 7*stride] + 2*QP) > 4*QP) return 0;
  254. if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
  255. if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
  256. }
  257. #else
  258. int x;
  259. src+= stride*3;
  260. for(x=0; x<BLOCK_SIZE; x++)
  261. {
  262. if((unsigned)(src[x + stride] - src[x + (stride<<3)] + 2*QP) > 4*QP) return 0;
  263. }
  264. #endif
  265. return 1;
  266. #else
  267. int x;
  268. src+= stride*4;
  269. for(x=0; x<BLOCK_SIZE; x++)
  270. {
  271. int min=255;
  272. int max=0;
  273. int y;
  274. for(y=0; y<8; y++){
  275. int v= src[x + y*stride];
  276. if(v>max) max=v;
  277. if(v<min) min=v;
  278. }
  279. if(max-min > 2*QP) return 0;
  280. }
  281. return 1;
  282. #endif
  283. }
  284. static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c){
  285. if( isHorizDC_C(src, stride, c) ){
  286. if( isHorizMinMaxOk_C(src, stride, c->QP) )
  287. return 1;
  288. else
  289. return 0;
  290. }else{
  291. return 2;
  292. }
  293. }
  294. static inline int vertClassify_C(uint8_t src[], int stride, PPContext *c){
  295. if( isVertDC_C(src, stride, c) ){
  296. if( isVertMinMaxOk_C(src, stride, c->QP) )
  297. return 1;
  298. else
  299. return 0;
  300. }else{
  301. return 2;
  302. }
  303. }
  304. static inline void doHorizDefFilter_C(uint8_t dst[], int stride, PPContext *c)
  305. {
  306. int y;
  307. for(y=0; y<BLOCK_SIZE; y++)
  308. {
  309. const int middleEnergy= 5*(dst[4] - dst[3]) + 2*(dst[2] - dst[5]);
  310. if(ABS(middleEnergy) < 8*c->QP)
  311. {
  312. const int q=(dst[3] - dst[4])/2;
  313. const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
  314. const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
  315. int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
  316. d= MAX(d, 0);
  317. d= (5*d + 32) >> 6;
  318. d*= SIGN(-middleEnergy);
  319. if(q>0)
  320. {
  321. d= d<0 ? 0 : d;
  322. d= d>q ? q : d;
  323. }
  324. else
  325. {
  326. d= d>0 ? 0 : d;
  327. d= d<q ? q : d;
  328. }
  329. dst[3]-= d;
  330. dst[4]+= d;
  331. }
  332. dst+= stride;
  333. }
  334. }
  335. /**
  336. * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
  337. * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
  338. */
  339. static inline void doHorizLowPass_C(uint8_t dst[], int stride, PPContext *c)
  340. {
  341. int y;
  342. for(y=0; y<BLOCK_SIZE; y++)
  343. {
  344. const int first= ABS(dst[-1] - dst[0]) < c->QP ? dst[-1] : dst[0];
  345. const int last= ABS(dst[8] - dst[7]) < c->QP ? dst[8] : dst[7];
  346. int sums[10];
  347. sums[0] = 4*first + dst[0] + dst[1] + dst[2] + 4;
  348. sums[1] = sums[0] - first + dst[3];
  349. sums[2] = sums[1] - first + dst[4];
  350. sums[3] = sums[2] - first + dst[5];
  351. sums[4] = sums[3] - first + dst[6];
  352. sums[5] = sums[4] - dst[0] + dst[7];
  353. sums[6] = sums[5] - dst[1] + last;
  354. sums[7] = sums[6] - dst[2] + last;
  355. sums[8] = sums[7] - dst[3] + last;
  356. sums[9] = sums[8] - dst[4] + last;
  357. dst[0]= (sums[0] + sums[2] + 2*dst[0])>>4;
  358. dst[1]= (sums[1] + sums[3] + 2*dst[1])>>4;
  359. dst[2]= (sums[2] + sums[4] + 2*dst[2])>>4;
  360. dst[3]= (sums[3] + sums[5] + 2*dst[3])>>4;
  361. dst[4]= (sums[4] + sums[6] + 2*dst[4])>>4;
  362. dst[5]= (sums[5] + sums[7] + 2*dst[5])>>4;
  363. dst[6]= (sums[6] + sums[8] + 2*dst[6])>>4;
  364. dst[7]= (sums[7] + sums[9] + 2*dst[7])>>4;
  365. dst+= stride;
  366. }
  367. }
  368. /**
  369. * Experimental Filter 1 (Horizontal)
  370. * will not damage linear gradients
  371. * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
  372. * can only smooth blocks at the expected locations (it cant smooth them if they did move)
  373. * MMX2 version does correct clipping C version doesnt
  374. * not identical with the vertical one
  375. */
  376. static inline void horizX1Filter(uint8_t *src, int stride, int QP)
  377. {
  378. int y;
  379. static uint64_t *lut= NULL;
  380. if(lut==NULL)
  381. {
  382. int i;
  383. lut= (uint64_t*)memalign(8, 256*8);
  384. for(i=0; i<256; i++)
  385. {
  386. int v= i < 128 ? 2*i : 2*(i-256);
  387. /*
  388. //Simulate 112242211 9-Tap filter
  389. uint64_t a= (v/16) & 0xFF;
  390. uint64_t b= (v/8) & 0xFF;
  391. uint64_t c= (v/4) & 0xFF;
  392. uint64_t d= (3*v/8) & 0xFF;
  393. */
  394. //Simulate piecewise linear interpolation
  395. uint64_t a= (v/16) & 0xFF;
  396. uint64_t b= (v*3/16) & 0xFF;
  397. uint64_t c= (v*5/16) & 0xFF;
  398. uint64_t d= (7*v/16) & 0xFF;
  399. uint64_t A= (0x100 - a)&0xFF;
  400. uint64_t B= (0x100 - b)&0xFF;
  401. uint64_t C= (0x100 - c)&0xFF;
  402. uint64_t D= (0x100 - c)&0xFF;
  403. lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |
  404. (D<<24) | (C<<16) | (B<<8) | (A);
  405. //lut[i] = (v<<32) | (v<<24);
  406. }
  407. }
  408. for(y=0; y<BLOCK_SIZE; y++)
  409. {
  410. int a= src[1] - src[2];
  411. int b= src[3] - src[4];
  412. int c= src[5] - src[6];
  413. int d= MAX(ABS(b) - (ABS(a) + ABS(c))/2, 0);
  414. if(d < QP)
  415. {
  416. int v = d * SIGN(-b);
  417. src[1] +=v/8;
  418. src[2] +=v/4;
  419. src[3] +=3*v/8;
  420. src[4] -=3*v/8;
  421. src[5] -=v/4;
  422. src[6] -=v/8;
  423. }
  424. src+=stride;
  425. }
  426. }
  427. /**
  428. * accurate deblock filter
  429. */
  430. static always_inline void do_a_deblock_C(uint8_t *src, int step, int stride, PPContext *c){
  431. int y;
  432. const int QP= c->QP;
  433. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  434. const int dcThreshold= dcOffset*2 + 1;
  435. //START_TIMER
  436. src+= step*4; // src points to begin of the 8x8 Block
  437. for(y=0; y<8; y++){
  438. int numEq= 0;
  439. if(((unsigned)(src[-1*step] - src[0*step] + dcOffset)) < dcThreshold) numEq++;
  440. if(((unsigned)(src[ 0*step] - src[1*step] + dcOffset)) < dcThreshold) numEq++;
  441. if(((unsigned)(src[ 1*step] - src[2*step] + dcOffset)) < dcThreshold) numEq++;
  442. if(((unsigned)(src[ 2*step] - src[3*step] + dcOffset)) < dcThreshold) numEq++;
  443. if(((unsigned)(src[ 3*step] - src[4*step] + dcOffset)) < dcThreshold) numEq++;
  444. if(((unsigned)(src[ 4*step] - src[5*step] + dcOffset)) < dcThreshold) numEq++;
  445. if(((unsigned)(src[ 5*step] - src[6*step] + dcOffset)) < dcThreshold) numEq++;
  446. if(((unsigned)(src[ 6*step] - src[7*step] + dcOffset)) < dcThreshold) numEq++;
  447. if(((unsigned)(src[ 7*step] - src[8*step] + dcOffset)) < dcThreshold) numEq++;
  448. if(numEq > c->ppMode.flatnessThreshold){
  449. int min, max, x;
  450. if(src[0] > src[step]){
  451. max= src[0];
  452. min= src[step];
  453. }else{
  454. max= src[step];
  455. min= src[0];
  456. }
  457. for(x=2; x<8; x+=2){
  458. if(src[x*step] > src[(x+1)*step]){
  459. if(src[x *step] > max) max= src[ x *step];
  460. if(src[(x+1)*step] < min) min= src[(x+1)*step];
  461. }else{
  462. if(src[(x+1)*step] > max) max= src[(x+1)*step];
  463. if(src[ x *step] < min) min= src[ x *step];
  464. }
  465. }
  466. if(max-min < 2*QP){
  467. const int first= ABS(src[-1*step] - src[0]) < QP ? src[-1*step] : src[0];
  468. const int last= ABS(src[8*step] - src[7*step]) < QP ? src[8*step] : src[7*step];
  469. int sums[10];
  470. sums[0] = 4*first + src[0*step] + src[1*step] + src[2*step] + 4;
  471. sums[1] = sums[0] - first + src[3*step];
  472. sums[2] = sums[1] - first + src[4*step];
  473. sums[3] = sums[2] - first + src[5*step];
  474. sums[4] = sums[3] - first + src[6*step];
  475. sums[5] = sums[4] - src[0*step] + src[7*step];
  476. sums[6] = sums[5] - src[1*step] + last;
  477. sums[7] = sums[6] - src[2*step] + last;
  478. sums[8] = sums[7] - src[3*step] + last;
  479. sums[9] = sums[8] - src[4*step] + last;
  480. src[0*step]= (sums[0] + sums[2] + 2*src[0*step])>>4;
  481. src[1*step]= (sums[1] + sums[3] + 2*src[1*step])>>4;
  482. src[2*step]= (sums[2] + sums[4] + 2*src[2*step])>>4;
  483. src[3*step]= (sums[3] + sums[5] + 2*src[3*step])>>4;
  484. src[4*step]= (sums[4] + sums[6] + 2*src[4*step])>>4;
  485. src[5*step]= (sums[5] + sums[7] + 2*src[5*step])>>4;
  486. src[6*step]= (sums[6] + sums[8] + 2*src[6*step])>>4;
  487. src[7*step]= (sums[7] + sums[9] + 2*src[7*step])>>4;
  488. }
  489. }else{
  490. const int middleEnergy= 5*(src[4*step] - src[3*step]) + 2*(src[2*step] - src[5*step]);
  491. if(ABS(middleEnergy) < 8*QP)
  492. {
  493. const int q=(src[3*step] - src[4*step])/2;
  494. const int leftEnergy= 5*(src[2*step] - src[1*step]) + 2*(src[0*step] - src[3*step]);
  495. const int rightEnergy= 5*(src[6*step] - src[5*step]) + 2*(src[4*step] - src[7*step]);
  496. int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
  497. d= MAX(d, 0);
  498. d= (5*d + 32) >> 6;
  499. d*= SIGN(-middleEnergy);
  500. if(q>0)
  501. {
  502. d= d<0 ? 0 : d;
  503. d= d>q ? q : d;
  504. }
  505. else
  506. {
  507. d= d>0 ? 0 : d;
  508. d= d<q ? q : d;
  509. }
  510. src[3*step]-= d;
  511. src[4*step]+= d;
  512. }
  513. }
  514. src += stride;
  515. }
  516. /*if(step==16){
  517. STOP_TIMER("step16")
  518. }else{
  519. STOP_TIMER("stepX")
  520. }*/
  521. }
  522. //Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
  523. //Plain C versions
  524. #if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
  525. #define COMPILE_C
  526. #endif
  527. #ifdef ARCH_POWERPC
  528. #ifdef HAVE_ALTIVEC
  529. #define COMPILE_ALTIVEC
  530. #endif //HAVE_ALTIVEC
  531. #endif //ARCH_POWERPC
  532. #if defined(ARCH_X86) || defined(ARCH_X86_64)
  533. #if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
  534. #define COMPILE_MMX
  535. #endif
  536. #if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
  537. #define COMPILE_MMX2
  538. #endif
  539. #if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
  540. #define COMPILE_3DNOW
  541. #endif
  542. #endif //ARCH_X86
  543. #undef HAVE_MMX
  544. #undef HAVE_MMX2
  545. #undef HAVE_3DNOW
  546. #undef HAVE_ALTIVEC
  547. #ifdef COMPILE_C
  548. #undef HAVE_MMX
  549. #undef HAVE_MMX2
  550. #undef HAVE_3DNOW
  551. #define RENAME(a) a ## _C
  552. #include "postprocess_template.c"
  553. #endif
  554. #ifdef ARCH_POWERPC
  555. #ifdef COMPILE_ALTIVEC
  556. #undef RENAME
  557. #define HAVE_ALTIVEC
  558. #define RENAME(a) a ## _altivec
  559. #include "postprocess_altivec_template.c"
  560. #include "postprocess_template.c"
  561. #endif
  562. #endif //ARCH_POWERPC
  563. //MMX versions
  564. #ifdef COMPILE_MMX
  565. #undef RENAME
  566. #define HAVE_MMX
  567. #undef HAVE_MMX2
  568. #undef HAVE_3DNOW
  569. #define RENAME(a) a ## _MMX
  570. #include "postprocess_template.c"
  571. #endif
  572. //MMX2 versions
  573. #ifdef COMPILE_MMX2
  574. #undef RENAME
  575. #define HAVE_MMX
  576. #define HAVE_MMX2
  577. #undef HAVE_3DNOW
  578. #define RENAME(a) a ## _MMX2
  579. #include "postprocess_template.c"
  580. #endif
  581. //3DNOW versions
  582. #ifdef COMPILE_3DNOW
  583. #undef RENAME
  584. #define HAVE_MMX
  585. #undef HAVE_MMX2
  586. #define HAVE_3DNOW
  587. #define RENAME(a) a ## _3DNow
  588. #include "postprocess_template.c"
  589. #endif
  590. // minor note: the HAVE_xyz is messed up after that line so dont use it
  591. static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  592. QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
  593. {
  594. PPContext *c= (PPContext *)vc;
  595. PPMode *ppMode= (PPMode *)vm;
  596. c->ppMode= *ppMode; //FIXME
  597. // useing ifs here as they are faster than function pointers allthough the
  598. // difference wouldnt be messureable here but its much better because
  599. // someone might exchange the cpu whithout restarting mplayer ;)
  600. #ifdef RUNTIME_CPUDETECT
  601. #if defined(ARCH_X86) || defined(ARCH_X86_64)
  602. // ordered per speed fasterst first
  603. if(c->cpuCaps & PP_CPU_CAPS_MMX2)
  604. postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  605. else if(c->cpuCaps & PP_CPU_CAPS_3DNOW)
  606. postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  607. else if(c->cpuCaps & PP_CPU_CAPS_MMX)
  608. postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  609. else
  610. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  611. #else
  612. #ifdef ARCH_POWERPC
  613. #ifdef HAVE_ALTIVEC
  614. if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
  615. postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  616. else
  617. #endif
  618. #endif
  619. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  620. #endif
  621. #else //RUNTIME_CPUDETECT
  622. #ifdef HAVE_MMX2
  623. postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  624. #elif defined (HAVE_3DNOW)
  625. postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  626. #elif defined (HAVE_MMX)
  627. postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  628. #elif defined (HAVE_ALTIVEC)
  629. postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  630. #else
  631. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  632. #endif
  633. #endif //!RUNTIME_CPUDETECT
  634. }
  635. //static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  636. // QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode);
  637. /* -pp Command line Help
  638. */
  639. char *pp_help=
  640. "Available postprocessing filters:\n"
  641. "Filters Options\n"
  642. "short long name short long option Description\n"
  643. "* * a autoq CPU power dependent enabler\n"
  644. " c chrom chrominance filtering enabled\n"
  645. " y nochrom chrominance filtering disabled\n"
  646. " n noluma luma filtering disabled\n"
  647. "hb hdeblock (2 threshold) horizontal deblocking filter\n"
  648. " 1. difference factor: default=32, higher -> more deblocking\n"
  649. " 2. flatness threshold: default=39, lower -> more deblocking\n"
  650. " the h & v deblocking filters share these\n"
  651. " so you can't set different thresholds for h / v\n"
  652. "vb vdeblock (2 threshold) vertical deblocking filter\n"
  653. "ha hadeblock (2 threshold) horizontal deblocking filter\n"
  654. "va vadeblock (2 threshold) vertical deblocking filter\n"
  655. "h1 x1hdeblock experimental h deblock filter 1\n"
  656. "v1 x1vdeblock experimental v deblock filter 1\n"
  657. "dr dering deringing filter\n"
  658. "al autolevels automatic brightness / contrast\n"
  659. " f fullyrange stretch luminance to (0..255)\n"
  660. "lb linblenddeint linear blend deinterlacer\n"
  661. "li linipoldeint linear interpolating deinterlace\n"
  662. "ci cubicipoldeint cubic interpolating deinterlacer\n"
  663. "md mediandeint median deinterlacer\n"
  664. "fd ffmpegdeint ffmpeg deinterlacer\n"
  665. "l5 lowpass5 FIR lowpass deinterlacer\n"
  666. "de default hb:a,vb:a,dr:a\n"
  667. "fa fast h1:a,v1:a,dr:a\n"
  668. "ac ha:a:128:7,va:a,dr:a\n"
  669. "tn tmpnoise (3 threshold) temporal noise reducer\n"
  670. " 1. <= 2. <= 3. larger -> stronger filtering\n"
  671. "fq forceQuant <quantizer> force quantizer\n"
  672. "Usage:\n"
  673. "<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n"
  674. "long form example:\n"
  675. "vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n"
  676. "short form example:\n"
  677. "vb:a/hb:a/lb de,-vb\n"
  678. "more examples:\n"
  679. "tn:64:128:256\n"
  680. "\n"
  681. ;
  682. pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
  683. {
  684. char temp[GET_MODE_BUFFER_SIZE];
  685. char *p= temp;
  686. const char *filterDelimiters= ",/";
  687. const char *optionDelimiters= ":";
  688. struct PPMode *ppMode;
  689. char *filterToken;
  690. ppMode= memalign(8, sizeof(PPMode));
  691. ppMode->lumMode= 0;
  692. ppMode->chromMode= 0;
  693. ppMode->maxTmpNoise[0]= 700;
  694. ppMode->maxTmpNoise[1]= 1500;
  695. ppMode->maxTmpNoise[2]= 3000;
  696. ppMode->maxAllowedY= 234;
  697. ppMode->minAllowedY= 16;
  698. ppMode->baseDcDiff= 256/8;
  699. ppMode->flatnessThreshold= 56-16-1;
  700. ppMode->maxClippedThreshold= 0.01;
  701. ppMode->error=0;
  702. strncpy(temp, name, GET_MODE_BUFFER_SIZE);
  703. if(verbose>1) printf("pp: %s\n", name);
  704. for(;;){
  705. char *filterName;
  706. int q= 1000000; //PP_QUALITY_MAX;
  707. int chrom=-1;
  708. int luma=-1;
  709. char *option;
  710. char *options[OPTIONS_ARRAY_SIZE];
  711. int i;
  712. int filterNameOk=0;
  713. int numOfUnknownOptions=0;
  714. int enable=1; //does the user want us to enabled or disabled the filter
  715. filterToken= strtok(p, filterDelimiters);
  716. if(filterToken == NULL) break;
  717. p+= strlen(filterToken) + 1; // p points to next filterToken
  718. filterName= strtok(filterToken, optionDelimiters);
  719. if(verbose>1) printf("pp: %s::%s\n", filterToken, filterName);
  720. if(*filterName == '-')
  721. {
  722. enable=0;
  723. filterName++;
  724. }
  725. for(;;){ //for all options
  726. option= strtok(NULL, optionDelimiters);
  727. if(option == NULL) break;
  728. if(verbose>1) printf("pp: option: %s\n", option);
  729. if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
  730. else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
  731. else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
  732. else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0;
  733. else
  734. {
  735. options[numOfUnknownOptions] = option;
  736. numOfUnknownOptions++;
  737. }
  738. if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
  739. }
  740. options[numOfUnknownOptions] = NULL;
  741. /* replace stuff from the replace Table */
  742. for(i=0; replaceTable[2*i]!=NULL; i++)
  743. {
  744. if(!strcmp(replaceTable[2*i], filterName))
  745. {
  746. int newlen= strlen(replaceTable[2*i + 1]);
  747. int plen;
  748. int spaceLeft;
  749. if(p==NULL) p= temp, *p=0; //last filter
  750. else p--, *p=','; //not last filter
  751. plen= strlen(p);
  752. spaceLeft= p - temp + plen;
  753. if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE)
  754. {
  755. ppMode->error++;
  756. break;
  757. }
  758. memmove(p + newlen, p, plen+1);
  759. memcpy(p, replaceTable[2*i + 1], newlen);
  760. filterNameOk=1;
  761. }
  762. }
  763. for(i=0; filters[i].shortName!=NULL; i++)
  764. {
  765. // printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
  766. if( !strcmp(filters[i].longName, filterName)
  767. || !strcmp(filters[i].shortName, filterName))
  768. {
  769. ppMode->lumMode &= ~filters[i].mask;
  770. ppMode->chromMode &= ~filters[i].mask;
  771. filterNameOk=1;
  772. if(!enable) break; // user wants to disable it
  773. if(q >= filters[i].minLumQuality && luma)
  774. ppMode->lumMode|= filters[i].mask;
  775. if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
  776. if(q >= filters[i].minChromQuality)
  777. ppMode->chromMode|= filters[i].mask;
  778. if(filters[i].mask == LEVEL_FIX)
  779. {
  780. int o;
  781. ppMode->minAllowedY= 16;
  782. ppMode->maxAllowedY= 234;
  783. for(o=0; options[o]!=NULL; o++)
  784. {
  785. if( !strcmp(options[o],"fullyrange")
  786. ||!strcmp(options[o],"f"))
  787. {
  788. ppMode->minAllowedY= 0;
  789. ppMode->maxAllowedY= 255;
  790. numOfUnknownOptions--;
  791. }
  792. }
  793. }
  794. else if(filters[i].mask == TEMP_NOISE_FILTER)
  795. {
  796. int o;
  797. int numOfNoises=0;
  798. for(o=0; options[o]!=NULL; o++)
  799. {
  800. char *tail;
  801. ppMode->maxTmpNoise[numOfNoises]=
  802. strtol(options[o], &tail, 0);
  803. if(tail!=options[o])
  804. {
  805. numOfNoises++;
  806. numOfUnknownOptions--;
  807. if(numOfNoises >= 3) break;
  808. }
  809. }
  810. }
  811. else if(filters[i].mask == V_DEBLOCK || filters[i].mask == H_DEBLOCK
  812. || filters[i].mask == V_A_DEBLOCK || filters[i].mask == H_A_DEBLOCK)
  813. {
  814. int o;
  815. for(o=0; options[o]!=NULL && o<2; o++)
  816. {
  817. char *tail;
  818. int val= strtol(options[o], &tail, 0);
  819. if(tail==options[o]) break;
  820. numOfUnknownOptions--;
  821. if(o==0) ppMode->baseDcDiff= val;
  822. else ppMode->flatnessThreshold= val;
  823. }
  824. }
  825. else if(filters[i].mask == FORCE_QUANT)
  826. {
  827. int o;
  828. ppMode->forcedQuant= 15;
  829. for(o=0; options[o]!=NULL && o<1; o++)
  830. {
  831. char *tail;
  832. int val= strtol(options[o], &tail, 0);
  833. if(tail==options[o]) break;
  834. numOfUnknownOptions--;
  835. ppMode->forcedQuant= val;
  836. }
  837. }
  838. }
  839. }
  840. if(!filterNameOk) ppMode->error++;
  841. ppMode->error += numOfUnknownOptions;
  842. }
  843. if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
  844. if(ppMode->error)
  845. {
  846. fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
  847. free(ppMode);
  848. return NULL;
  849. }
  850. return ppMode;
  851. }
  852. void pp_free_mode(pp_mode_t *mode){
  853. if(mode) free(mode);
  854. }
  855. static void reallocAlign(void **p, int alignment, int size){
  856. if(*p) free(*p);
  857. *p= memalign(alignment, size);
  858. memset(*p, 0, size);
  859. }
  860. static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){
  861. int mbWidth = (width+15)>>4;
  862. int mbHeight= (height+15)>>4;
  863. int i;
  864. c->stride= stride;
  865. c->qpStride= qpStride;
  866. reallocAlign((void **)&c->tempDst, 8, stride*24);
  867. reallocAlign((void **)&c->tempSrc, 8, stride*24);
  868. reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
  869. reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
  870. for(i=0; i<256; i++)
  871. c->yHistogram[i]= width*height/64*15/256;
  872. for(i=0; i<3; i++)
  873. {
  874. //Note:the +17*1024 is just there so i dont have to worry about r/w over te end
  875. reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
  876. reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
  877. }
  878. reallocAlign((void **)&c->deintTemp, 8, 2*width+32);
  879. reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
  880. reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
  881. reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
  882. }
  883. static void global_init(void){
  884. int i;
  885. memset(clip_table, 0, 256);
  886. for(i=256; i<512; i++)
  887. clip_table[i]= i;
  888. memset(clip_table+512, 0, 256);
  889. }
  890. pp_context_t *pp_get_context(int width, int height, int cpuCaps){
  891. PPContext *c= memalign(32, sizeof(PPContext));
  892. int stride= (width+15)&(~15); //assumed / will realloc if needed
  893. int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
  894. global_init();
  895. memset(c, 0, sizeof(PPContext));
  896. c->cpuCaps= cpuCaps;
  897. if(cpuCaps&PP_FORMAT){
  898. c->hChromaSubSample= cpuCaps&0x3;
  899. c->vChromaSubSample= (cpuCaps>>4)&0x3;
  900. }else{
  901. c->hChromaSubSample= 1;
  902. c->vChromaSubSample= 1;
  903. }
  904. reallocBuffers(c, width, height, stride, qpStride);
  905. c->frameNum=-1;
  906. return c;
  907. }
  908. void pp_free_context(void *vc){
  909. PPContext *c = (PPContext*)vc;
  910. int i;
  911. for(i=0; i<3; i++) free(c->tempBlured[i]);
  912. for(i=0; i<3; i++) free(c->tempBluredPast[i]);
  913. free(c->tempBlocks);
  914. free(c->yHistogram);
  915. free(c->tempDst);
  916. free(c->tempSrc);
  917. free(c->deintTemp);
  918. free(c->stdQPTable);
  919. free(c->nonBQPTable);
  920. free(c->forcedQPTable);
  921. memset(c, 0, sizeof(PPContext));
  922. free(c);
  923. }
  924. void pp_postprocess(uint8_t * src[3], int srcStride[3],
  925. uint8_t * dst[3], int dstStride[3],
  926. int width, int height,
  927. QP_STORE_T *QP_store, int QPStride,
  928. pp_mode_t *vm, void *vc, int pict_type)
  929. {
  930. int mbWidth = (width+15)>>4;
  931. int mbHeight= (height+15)>>4;
  932. PPMode *mode = (PPMode*)vm;
  933. PPContext *c = (PPContext*)vc;
  934. int minStride= MAX(ABS(srcStride[0]), ABS(dstStride[0]));
  935. int absQPStride = ABS(QPStride);
  936. // c->stride and c->QPStride are always positive
  937. if(c->stride < minStride || c->qpStride < absQPStride)
  938. reallocBuffers(c, width, height,
  939. MAX(minStride, c->stride),
  940. MAX(c->qpStride, absQPStride));
  941. if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
  942. {
  943. int i;
  944. QP_store= c->forcedQPTable;
  945. absQPStride = QPStride = 0;
  946. if(mode->lumMode & FORCE_QUANT)
  947. for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
  948. else
  949. for(i=0; i<mbWidth; i++) QP_store[i]= 1;
  950. }
  951. //printf("pict_type:%d\n", pict_type);
  952. if(pict_type & PP_PICT_TYPE_QP2){
  953. int i;
  954. const int count= mbHeight * absQPStride;
  955. for(i=0; i<(count>>2); i++){
  956. ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
  957. }
  958. for(i<<=2; i<count; i++){
  959. c->stdQPTable[i] = QP_store[i]>>1;
  960. }
  961. QP_store= c->stdQPTable;
  962. QPStride= absQPStride;
  963. }
  964. if(0){
  965. int x,y;
  966. for(y=0; y<mbHeight; y++){
  967. for(x=0; x<mbWidth; x++){
  968. printf("%2d ", QP_store[x + y*QPStride]);
  969. }
  970. printf("\n");
  971. }
  972. printf("\n");
  973. }
  974. if((pict_type&7)!=3)
  975. {
  976. if (QPStride >= 0) {
  977. int i;
  978. const int count= mbHeight * QPStride;
  979. for(i=0; i<(count>>2); i++){
  980. ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x3F3F3F3F;
  981. }
  982. for(i<<=2; i<count; i++){
  983. c->nonBQPTable[i] = QP_store[i] & 0x3F;
  984. }
  985. } else {
  986. int i,j;
  987. for(i=0; i<mbHeight; i++) {
  988. for(j=0; j<absQPStride; j++) {
  989. c->nonBQPTable[i*absQPStride+j] = QP_store[i*QPStride+j] & 0x3F;
  990. }
  991. }
  992. }
  993. }
  994. if(verbose>2)
  995. {
  996. printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
  997. }
  998. postProcess(src[0], srcStride[0], dst[0], dstStride[0],
  999. width, height, QP_store, QPStride, 0, mode, c);
  1000. width = (width )>>c->hChromaSubSample;
  1001. height = (height)>>c->vChromaSubSample;
  1002. if(mode->chromMode)
  1003. {
  1004. postProcess(src[1], srcStride[1], dst[1], dstStride[1],
  1005. width, height, QP_store, QPStride, 1, mode, c);
  1006. postProcess(src[2], srcStride[2], dst[2], dstStride[2],
  1007. width, height, QP_store, QPStride, 2, mode, c);
  1008. }
  1009. else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2])
  1010. {
  1011. linecpy(dst[1], src[1], height, srcStride[1]);
  1012. linecpy(dst[2], src[2], height, srcStride[2]);
  1013. }
  1014. else
  1015. {
  1016. int y;
  1017. for(y=0; y<height; y++)
  1018. {
  1019. memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
  1020. memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);
  1021. }
  1022. }
  1023. }