postprocess.c 37 KB

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