postprocess.c 37 KB

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